#------------------------------------------------------------------------------ # /etc/rc.d/rc455.samba - start samba __FLI4LVER__ # # Creation : 21.08.2000 fm # Last Update: $Id$ #------------------------------------------------------------------------------ # smb_set smb_set () { if [ "$2" ]; then eval $1="'$2'" else eval $1="'$3'" fi } if [ "$OPT_SAMBA" = "yes" ] then begin_script SAMBA "configuring samba on $HOSTNAME ..." #-------------------------------------------------------------------------- # configuring parameters from config.txt: #-------------------------------------------------------------------------- interface='' sambahosts='' start_samba='false' smbconffile='/etc/smb.conf' msgcmdinfo=log_info lpqbin='/usr/bin/lpq' lprbin='/usr/bin/lpr' lprmbin='/usr/bin/lprm' sambanetsendbin='/bin/samba-netsend' smbdbin='/usr/sbin/smbd' nmbdbin='/usr/sbin/nmbd' if [ "$LOCALE" = "de" ] then message="fli4l-samba-server auf $HOSTNAME ist nun gestartet..." else message="fli4l-samba-server on $HOSTNAME is up now..." fi idx='1' idy='0' mkdir -p /var/lock/samba >/var/lock/samba/STATUS..LCK >/etc/smbpasswd #------------------------------------------------------------------ # prepare log files: #------------------------------------------------------------------ data_mount=`cat /proc/mounts | grep ' /data ' | grep ' rw'` case "$data_mount" in minix | ext2 | ext3) : ${SAMBA_LOGDIR:='/data'} ;; *) : ${SAMBA_LOGDIR:='/var/log'} ;; esac mkdir -p "$SAMBA_LOGDIR" if [ ! -d "$SAMBA_LOGDIR" ]; then log_error "failed to create samba log dir '$SAMBA_LOGDIR', disabling logging" SAMBA_LOGDIR='/var/log' SAMBA_LOG='no' fi #------------------------------------------------------------------ # disable logging: #------------------------------------------------------------------ if [ "$SAMBA_LOG" = "no" ] then ln -sf /dev/null "$SAMBA_LOGDIR"/log.smbd ln -sf /dev/null "$SAMBA_LOGDIR"/log.nmbd fi if [ ! -f "$smbconffile" ] then #---------------------------------------------------------------------- # configuring interfaces and networks for samba: #---------------------------------------------------------------------- for idx in `seq 1 $IP_NET_N` do eval iptmp='$IP_NET_'$idx'' eval ethx='$IP_NET_'$idx'_DEV' ipaddr=`echo $iptmp | sed -e 's/\/.*//'` if [ "$ipaddr" = dhcp ]; then log_info "IP_NET_$idx is a dhcp client interface, don't configuring samba for it..." continue fi if [ "$ipaddr" != "0.0.0.0" -a -n "$ipaddr" ] then eval net='$IP_NET_'$idx'' netmask=`netcalc netmask $net` network=`netcalc network $net` interface="$interface $ipaddr/$netmask" sambahosts="$sambahosts $network/$netmask" fi done if [ "$OPT_PPP" = "yes" ] then eval network='$PPP_NETWORK' eval netmask='$PPP_NETMASK' if route | grep -q $network then interface="$interface $PPP_IPADDR/$netmask" sambahosts="$sambahosts $network/$netmask" fi fi if [ -n "$SAMBA_TRUSTED_NETS" ] then for i in $SAMBA_TRUSTED_NETS do network=`netcalc network $i` netmask=`netcalc netmask $i` var=$network/$netmask if ! echo "$sambahosts" | grep -q $var then sambahosts="$sambahosts $var" fi done fi if [ -z "$interface" ] then start_samba='false' log_error "no interfaces available - samba will be not activated!" sleep 5 else start_samba='true' log_info "samba on $HOSTNAME will be activated for interface(s):" log_info "$interface" log_info "samba on $HOSTNAME will be activated for network(s):" log_info "$sambahosts" fi wins_support='no' wins_proxy='no' wins_server='' if [ "$OPT_NMBD" = "yes" ] then if [ "$NMBD_MASTERBROWSER" = "yes" ] then oslevel='255' localmaster='yes' preferredmaster='yes' announce='' sync='' [ 0"$NMBD_REMOTE_ANNOUNCE_N" -eq 0 ] || for idx in `seq 1 $NMBD_REMOTE_ANNOUNCE_N`; do eval network='$NMBD_REMOTE_ANNOUNCE_'$idx'_NETWORK' eval netmask='$NMBD_REMOTE_ANNOUNCE_'$idx'_NETMASK' broadcast=`netcalc broadcast $network $netmask` eval workgroup='$NMBD_REMOTE_ANNOUNCE_'$idx'_WORKGROUP' announce="$announce $broadcast/$workgroup" sync="$sync $broadcast" done if [ "$NMBD_DOMAIN_MASTERBROWSER" = "yes" ] then domainmaster='yes' else domainmaster='no' fi else oslevel='0' localmaster='no' preferredmaster='no' domainmaster='no' fi #------------------------------------------------------------------ # create wins options: #------------------------------------------------------------------ if [ "$NMBD_WINSSERVER" = "yes" ] then wins_support='yes' log_info "samba on $HOSTNAME will act as an WINS-Server" else if [ -n "$NMBD_EXTWINSIP" ] then wins_server="$NMBD_EXTWINSIP" wins_proxy='yes' log_info "external WINS-Server for $HOSTNAME is:" log_info "$wins_server" log_info "samba on $HOSTNAME will act as an WINS-Proxy of:" log_info "$wins_server" fi fi else oslevel='0' localmaster='no' preferredmaster='no' domainmaster='no' fi #---------------------------------------------------------------------- # create global config, could be overwritten with shares: #---------------------------------------------------------------------- cat <"$smbconffile" #---------------------------------------------------------------------------- # $smbconffile # automatically created by rc455.samba #---------------------------------------------------------------------------- [global] workgroup = $SAMBA_WORKGROUP serverstring = samba-server on $HOSTNAME interfaces = $interface bind interfaces only = yes os level = $oslevel local master = $localmaster preferred master = $preferredmaster domain master = $domainmaster wins support = $wins_support wins server = $wins_server wins proxy = $wins_proxy dns proxy = no time server = yes hosts allow = localhost $sambahosts guest account = nobody keep alive = 30 browseable = yes public = yes security = share printing = bsd printcap name = /etc/printcap load printers = no socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192 case sensitive = no default case = lower preserve case = yes short preserve case = yes dos filetimes = yes dos filetime resolution = yes deadtime = 5 dfree command = /usr/bin/dfree remote announce = $announce remote browse sync = $sync encrypt passwords = yes delete readonly = yes message command = sh -c 'rm %s' & # # potential new options suggested by babel # # Unknown parameter encountered: "acl check permission" # acl check permission = no acl map full control = no allow trusted domains = no auth methods = guest csc policy = disable enable privileges = no force unknown acl user = yes nt acl support = no null passwords = yes passdb backend = smbpasswd unix charset = ASCII client schannel = no server schannel = no client signing = disabled client use spnego = no guest only = yes idmap uid = 5000-5050 idmap gid = 5000-5050 # Unknown parameter encountered: "idmap backup" # idmap backup = tdb EOF #---------------------------------------------------------------------- # create share for fli4l root directory: #---------------------------------------------------------------------- if [ -n "$SAMBA_ADMINIP" ] then rootavailable='yes' rootbrowseable='yes' adminip="$SAMBA_ADMINIP" log_info "root-directory on $HOSTNAME will be accessable for network(s):" log_info "$adminip" cat <>"$smbconffile" [root] comment = root-filesystem on $HOSTNAME browseable = $rootbrowseable available = $rootavailable read only = no path = / hosts allow = $adminip force user = root dont descend = proc EOF fi #---------------------------------------------------------------------- # create share(s)for samba fileserver: #---------------------------------------------------------------------- log_info " configuring shares" cat <>"$smbconffile" #---------------------------------------------------------------------------- # create share(s)for samba fileserver: # automatically created by rc455.samba #---------------------------------------------------------------------------- EOF [ 0"$SAMBA_SHARE_N" -eq 0 ] || for idx in `seq 1 $SAMBA_SHARE_N`; do eval name='$SAMBA_SHARE_'$idx'_NAME' eval write='$SAMBA_SHARE_'$idx'_RW' eval browse='$SAMBA_SHARE_'$idx'_BROWSE' eval path='$SAMBA_SHARE_'$idx'_PATH' eval hosts='$SAMBA_SHARE_'$idx'_NET' if [ ! -d "$path" ] then mkdir -p $path if [ -d $path ] then log_info " directory $path for share $name on $HOSTNAME created" cy else log_error "cannot create directory $path for share $name on $HOSTNAME!" log_error "check OPT_MOUNT and SAMBA_SHARE_PATH!" fi else log_info " directory for share $name on $HOSTNAME already exists" fi if [ "$hosts" != '' ] # which net will be allowed to access the share? then # net is defined hosts1=$hosts # net in SAMBA_SHARE_NET_X will be allowed log_info " share $name on $HOSTNAME will be accessable for network(s):" log_info " $hosts1" else # net is not defined hosts1=$sambahosts # net in IP_ETH_X_NETWORK/$IP_ETH_X_NETMASK will be allowed log_info " share $name on $HOSTNAME will be accessable for network(s):" log_info " $hosts1" fi cat <>"$smbconffile" [$name] comment = share $name on $HOSTNAME browseable = $browse available = yes writeable = $write path = $path hosts allow = $hosts1 force user = root EOF done #---------------------------------------------------------------------------- # create share(s) for cdrom(s): #---------------------------------------------------------------------------- [ 0"$SAMBA_CDROM_N" -eq 0 ] || for idx in `seq 1 $SAMBA_CDROM_N`; do eval dev='$SAMBA_CDROM_'$idx'_DEV' eval hosts='$SAMBA_CDROM_'$idx'_NET' path='' if [ "$hosts" != '' ] # which net will be allowed to access the share? then # net is defined hosts1=$hosts # net in SAMBA_CDROM_NET_X will be allowed log_info " cdrom$idx on $HOSTNAME will be accessable for network(s):" log_info " $hosts1" else # net is not defined hosts1=$sambahosts # net in IP_ETH_X_NETWORK/$IP_ETH_X_NETMASK will be allowed log_info " cdrom$idx on $HOSTNAME will be accessable for network(s):" log_info " $hosts1" fi if cat /proc/mounts | grep -q $dev then # found mounted cdrom$idx log_info " cdrom$idx already mounted" path=`cat /proc/mounts | grep /dev/$dev | cut -d" " -f2` # cut mountpath for sharing log_info " path for cdrom$idx is $path" exec=false else # cdrom$idx not mounted log_error " cdrom$idx not mounted" path=/mnt/cdrom$idx log_error " path for cdrom$idx is $path" exec=true if [ ! -d /mnt/cdrom$idx ] then mkdir -p /mnt/cdrom$idx fi fi cat <>"$smbconffile" [cdrom$idx] comment = cdrom$idx on $HOSTNAME at device $dev read only = yes hosts allow = $hosts1 path = $path EOF if [ "$exec" = "true" ] then cat <>"$smbconffile" root preexec = /bin/mount -t iso9660 /dev/$dev /mnt/cdrom$idx -o ro root postexec = /bin/umount /dev/$dev EOF fi done #---------------------------------------------------------------------- # configuring printer share(s): #---------------------------------------------------------------------- if [ "$OPT_LPD" = "yes" -a "$do_printing" = "yes" ] then if [ "$OPT_LPD_PARPORT" = "yes" ] then #---------------------------------------------------------- # create share(s) for local parallel printer(s): #---------------------------------------------------------- [ 0"$LPD_PARPORT_N" -eq 0 ] || for idx in `seq 1 $LPD_PARPORT_N`; do eval lpname='$SAMBA_LPD_PARPORT_'$idx'_NAME' eval lpnet='$SAMBA_LPD_PARPORT_'$idx'_NET' eval port='$LPD_PARPORT_'$idx'_IO' smb_set name "$lpname" "pr$idx" smb_set lpnet1 "$lpnet" "$sambahosts" log_info "printer pr$idx on $HOSTNAME at port $port will be accessable for network(s):" log_info "$lpnet1" cat <>"$smbconffile" [$name] comment = local printer pr$idx on $HOSTNAME at port $port browseable = yes printable = yes print command = $lprbin -h -r -Ppr$idx %s lprm command = $lprmbin -Ppr$idx %j lpq command = $lpqbin -Ppr$idx create mode = 0700 printer = pr$idx path = /var/spool/lp/pr$idx hosts allow = $lpnet1 EOF done fi if [ "$OPT_LPD_USBPORT" = "yes" ] then #---------------------------------------------------------- # create share(s) for local usb printer(s): #---------------------------------------------------------- [ 0"$LPD_USBPORT_N" -eq 0 ] || for idx in `seq 1 $LPD_USBPORT_N`; do eval lpname='$SAMBA_LPD_USBPORT_'$idx'_NAME' eval lpnet='$SAMBA_LPD_USBPORT_'$idx'_NET' smb_set name "$lpname" "usbpr$idx" smb_set lpnet1 "$lpnet" "$sambahosts" log_info "printer usbpr$idx on $HOSTNAME will be accessable for network(s):" log_info "$lpnet1" cat <>"$smbconffile" [$name] comment = local printer usbpr$idx on $HOSTNAME browseable = yes printable = yes print command = $lprbin -h -r -Pusbpr$idx %s lprm command = $lprmbin -Pusbpr$idx %j lpq command = $lpqbin -Pusbpr$idx create mode = 0700 printer = usbpr$idx path = /var/spool/lp/usbpr$idx hosts allow = $lpnet1 EOF done fi if [ "$OPT_LPD_REMOTE" = "yes" ] then #---------------------------------------------------------- # create share(s) for remote printer(s): #---------------------------------------------------------- [ 0"$LPD_REMOTE_N" -eq 0 ] || for idx in `seq 1 $LPD_REMOTE_N`; do eval lpname='$SAMBA_LPD_REMOTE_'$idx'_NAME' eval lpnet='$SAMBA_LPD_REMOTE_'$idx'_NET' eval ip='$LPD_REMOTE_'$idx'_IP' eval remotequeuename='$LPD_REMOTE_'$idx'_QUEUENAME' smb_set name "$lpname" "repr$idx" smb_set lpnet1 "$lpnet" "$sambahosts" log_info "printer repr$idx on $HOSTNAME for ip $ip will be accessable for network(s):" log_info "$lpnet1" cat <>"$smbconffile" [$name] comment = remote printer repr$idx on $HOSTNAME for ip $ip queue $remotequeuename browseable = yes printable = yes print command = $lprbin -h -r -Prepr$idx %s lprm command = $lprmbin -Prepr$idx %j lpq command = $lpqbin -Prepr$idx create mode = 0700 printer = repr$idx path = /var/spool/lp/repr$idx hosts allow = $lpnet1 EOF done fi if [ "$OPT_LPD_SMBREMOTE" = "yes" ] then #---------------------------------------------------------- # create share(s) for remote smb printer(s): #---------------------------------------------------------- [ 0"$LPD_SMBREMOTE_N" -eq 0 ] || for idx in `seq 1 $LPD_SMBREMOTE_N`; do eval lpname='$SAMBA_LPD_SMBREMOTE_'$idx'_NAME' eval lpnet='$SAMBA_LPD_SMBREMOTE_'$idx'_NET' eval server='$LPD_SMBREMOTE_'$idx'_SERVER' eval service='$LPD_SMBREMOTE_'$idx'_SERVICE' smb_set name "$lpname" "smbrepr$idx" smb_set lpnet1 "$lpnet" "$sambahosts" log_info "printer smbrepr$idx on $HOSTNAME for winprinter $service will be accessable for network(s):" log_info "$lpnet1" cat <>"$smbconffile" [$name] comment = smb remote printer smbrepr$idx on $HOSTNAME for smb server $server winprinter $service browseable = yes printable = yes print command = $lprbin -h -r -Psmbrepr$idx %s; rm %s lprm command = $lprmbin -Psmbrepr$idx %j lpq command = $lpqbin -Psmbrepr$idx create mode = 0700 printer = smbrepr$idx path = /var/spool/lp/smbrepr$idx hosts allow = $lpnet1 EOF done fi fi #---------------------------------------------------------------------- # starting nmbd and smbd, if configured from fli4l: #---------------------------------------------------------------------- if [ "$start_samba" = "true" ] then if [ -f "$nmbdbin" ] then begin_script SAMBA "starting netbios nameserver on $HOSTNAME ..." "$nmbdbin" -D -l "$nmblog" if [ $? -ne 0 ] then log_error "cannot start nmbd on $HOSTNAME!" log_error "check OPT_NMBD and if HOSTNAME of fli4l exists under HOST_x in base.txt!" fi end_script fi if [ -f "$smbdbin" ] then begin_script SAMBA "starting samba on $HOSTNAME ..." "$smbdbin" -D -l "$smblog" if [ $? -ne 0 ] then log_error "cannot start samba on $HOSTNAME!" log_error "check OPT_SAMBA!" fi end_script fi #------------------------------------------------------------------ # load smbfs.o, nls-files are already loaded by rc010.nls #------------------------------------------------------------------ [ "$SAMBA_TOOLS" = yes ] && do_modprobe smbfs #------------------------------------------------------------------ # show samba start message: #------------------------------------------------------------------ if [ -f "$sambanetsendbin" ] then "$sambanetsendbin" "all" "$message" & fi fi else # --------------------------------------------------------------------- # starting nmbd and smbd, if configured by individual smb.conf: #---------------------------------------------------------------------- if [ -f "$nmbdbin" ] then begin_script SAMBA "starting netbios nameserver on $HOSTNAME ..." "$nmbdbin" -D -l "$nmblog" if [ $? -ne 0 ] then log_error "cannot start nmbd on $HOSTNAME!" log_error "check OPT_NMBD and if HOSTNAME of fli4l exists under HOST_x in base.txt!" fi end_script fi if [ -f "$smbdbin" ] then begin_script SAMBA "starting samba on $HOSTNAME ..." "$smbdbin" -D -l "$smblog" if [ $? -ne 0 ] then log_error "cannot start samba on $HOSTNAME!" log_error "check OPT_SAMBA and your smb.conf!" fi end_script fi fi end_script fi