4 # name: mount.smb -- interface between mount and smbmount
5 # author: Ch. L. Spiel (cspiel@physik.tu-muenchen.de)
6 # $Id: mount.smb,v 1.1 1998/04/13 12:31:10 jht Exp $
8 # bash version: 1.14.7(1)
10 # smbmount version: 1.9.18p3
14 passwd_filename="smb-pass" # name of user smb-password file
15 lock_file="/var/lock/$myname"
16 log_file="/tmp/mount.smb.log"
18 PATH=/usr/local/samba/bin:/usr/bin:/bin
20 # check for an existing lock-file quickly(!)
21 if [ -e "$lock_file" ]; then
22 # exit, but don´t touch lock-file
25 # set up new lock-file
29 echo "logging of $myname started at `date`" > $log_file
30 chmod --silent 600 $log_file
31 echo "called with: $@" >> $log_file
32 exec >> $log_file 2>&1
36 # set default and initial values
37 verbose=false # be silent
38 fake=false # really do the mount
39 fmode="-f 600" # default file mode
40 dmode="-d 700" # default dir mode
42 #uid="-u `id | sed 's/^uid=\([0-9]*\).*$/\1/'`"
44 #gid="-g `id | sed 's/^.*gid=\([0-9]*\).*$/\1/'`"
52 # exitproc(int exit_code)
55 if [ -n "$lock_file" ]; then
56 # remove current lock-file
61 echo "$myname´s return value is $1." >> $log_file
62 echo "logging of $myname ended at `date`." >> $log_file
70 # set id and val on return
79 # split_passwdline(uline)
80 function split_passwdline
92 # get_homedir(username)
98 uline=`grep "^$1" /etc/passwd`
99 if [ -z "$uline" ]; then
100 echo "$myname: unknown user \"$1\""
104 split_passwdline $uline
105 if [ -z "$home_dir" ]; then
106 echo "$myname: user \"$1\" has no home directory"
120 uline=`grep "^$1" /etc/passwd`
121 if [ -z "$uline" ]; then
122 echo "$myname: unknown user \"$1\""
126 split_passwdline $uline
138 uline=`grep "^$1" /etc/passwd`
139 if [ -z "$uline" ]; then
140 echo "$myname: unknown user \"$1\""
144 split_passwdline $uline
150 # read_passwd_file(sharename)
151 function read_passwd_file
153 local pwd_filename pwd_entry temp_ifs share_name fmod
155 pwd_filename=`get_homedir $uuname`/$passwd_filename
156 # use uid and gid of user´s /etc/password entry
157 uid="-u `get_uid $uuname`"
158 gid="-g `get_gid $uuname`"
159 # check existence of password file
160 if [ ! -f "$pwd_filename" -o ! -r "$pwd_filename" ]; then
161 echo "$myname: cannot read from user password file \"$pwd_filename\""
164 # check file permissions
165 for f in $pwd_filename{,~,%,.BAK,.bak,.new,.old,.orig,.sav}; do
166 if [ ! -f $f ]; then continue; fi
167 /bin/ls -l $f | grep -q -- "^-r\(w\|-\)------"
169 echo "$myname: Found security hole: mode of file \"$f\""
170 echo "$myname: Password file must have permission 400 or 600."
171 echo "$myname: Please fix the file´s mode."
176 share_name="$1" # sharename in smb-format!
177 pwd_entry=`grep -v '^#' "$pwd_filename" | grep -i "^$share_name"`
178 if [ -z "$pwd_entry" ]; then
179 # try uni*-like sharename
180 share_name=`echo $share_name | sed -e 's,^//,,' -e 's,/,:/,'`
181 pwd_entry=`grep -v '^#' "$pwd_filename" | grep -i "^$share_name"`
183 if [ -z "$pwd_entry" ]; then
184 # sharename was not found in user´s password file
185 echo "$myname: cannot authentify share named \"$1\" via file \"$pwd_filename\""
189 # pwd_entry has the form:
190 # sharename username password
192 IFS=" " # <tab> and <space>
194 options="$options -U $val"
200 # process_options(opt1, opt2, ..., optN)
201 function process_options
206 temp_ifs="$IFS" # save current internal-field separator
207 IFS="=" # set new separator
208 split_arg $j # split argument into identifier and value
209 IFS="$temp_ifs" # reset old separator
212 options="$options -p $val"
215 options="$options -d $val"
218 options="$options -l $val"
221 options="$options -n $val"
224 options="$options -N"
227 options="$options -m $val"
230 options="$options -I $val"
233 options="$options -U $val"
236 options="$options -W $val"
239 options="$options -t $val"
242 options="$options -D $val"
245 # DO NOT USE THIS OPTION! It is a severe scurity hole.
249 # consult user´s smb-password file
250 uuname="$val" # uni* user name
251 read_passwd_file "$server_service"
323 echo "$myname: unrecognized option $id"
328 } # end of split_options
338 if [ "$verbose" != "false" ]; then
339 # show how we have been called
343 # some checks of the input parameters
344 if [ "$#" -lt 2 ]; then
345 echo "$myname: need at least service and mountpoint"
349 if `echo "$2" | grep -vq "^/"`; then
350 echo "$myname: mount point must be an absolut path"
356 if `echo "$1" | grep -q ":/"`; then
357 # non--standard format, i.e., server:/service
358 server_service=`echo "//$1" | sed -e "sx:/x/x"`
360 # standard format, i.e, //server/service
366 shift 2 # skip arguments: //server/service and /mnt-point
373 echo "usage: mount.smb service [password] mountpoint [options]"
380 echo "$myname: mount.smb-0.1.0"
384 shift # skip leading -o
385 temp_ifs="$IFS" # save current internal-field separator
386 IFS="," # set new separator
388 IFS="$temp_ifs" # reset old separator
389 break # mount places options at the end -> we are done
392 echo "$myname: unrecognized option $i"
406 # nmblookup server: is node up and running?
407 srv=`echo $server_service | sed 's,^//\(.*\)/.*$,\1,'` # server´s name
408 nmblookup "$srv" | grep -q "failed to find name"
409 if [ "$?" = 0 ]; then
410 echo "$myname: failed to find server \"$srv\"."
420 fs_options="$fmode $dmode $uid $gid" # all options concerning the mounted fs
421 if [ "$verbose" = "true" ]; then
422 # display what we would do. Do not show the password, only show "xxx".
423 echo -n "smbmount $server_service "
424 if [ -n "$password" ]; then # password is set
425 echo -n "xxx " # ... but we don´t show it ;-)
427 echo "-c \"mount $mntpt $fs_options\" $options"
429 # supress further messages
430 # exec > /dev/null 2>&1
434 if [ "$fake" != "true" ]; then
435 smbmount $server_service $password -c "mount $mntpt $fs_options" $options
436 echo "smbmount´s exit code was $?."