File: smbadduser.in

package info (click to toggle)
samba 2:3.2.5-4lenny15
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 124,704 kB
  • ctags: 69,181
  • sloc: ansic: 564,153; xml: 219,271; sh: 11,039; perl: 4,458; makefile: 4,301; python: 1,975; cpp: 1,224; exp: 1,147; yacc: 881; awk: 557; csh: 58; sed: 45
file content (79 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/csh
#
# smbadduser - Written by Mike Zakharoff
#

prefix=@prefix@
exec_prefix=@exec_prefix@
LIBDIR=@libdir@
PRIVATEDIR=@privatedir@
CONFIGDIR=@configdir@

unalias *
set path = ($path /usr/bin)

set smbpasswd = $PRIVATEDIR/smbpasswd
set user_map  = $CONFIGDIR/smbusers

#
# Set to site specific passwd command
#
set passwd    = "getent passwd"
#set passwd    = "niscat passwd.org_dir"
#set passwd    = "ypcat passwd"

set line = "----------------------------------------------------------"
if ($#argv == 0) then
	echo $line
	echo "Written: Mike Zakharoff email: michael.j.zakharoff@boeing.com"
	echo ""
	echo "   1) Updates $smbpasswd"
	echo "   2) Updates $user_map"
	echo "   3) Executes smbpasswd for each new user"
	echo ""
	echo "smbadduser unixid:ntid unixid:ntid ..."
	echo ""
	echo "Example: smbadduser zak:zakharoffm johns:smithj"
	echo $line
	exit 1
endif

touch $smbpasswd $user_map
set new  = ()
foreach one ($argv)
	echo $one | grep ':' >& /dev/null
	if ($status != 0) then
		echo "ERROR: Must use unixid:ntid like -> zak:zakharoffm"
		continue
	endif
	set unix = `echo $one | awk -F: '{print $1}'`
	set ntid = `echo $one | awk -F: '{print $2}'`

	set usr = `eval $passwd | awk -F: '$1==USR {print $1}' USR=$unix`
	if ($#usr != 1) then
		echo "ERROR: $unix Not in passwd database SKIPPING..."
		continue
	endif
        set tmp = `cat $smbpasswd | awk -F: '$1==USR {print $1}' USR=$unix`
	if ($#tmp != 0) then
		echo "ERROR: $unix is already in $smbpasswd SKIPPING..."
		continue
	endif

	echo "Adding: $unix to $smbpasswd"
	/usr/bin/smbpasswd -a -n $unix
	if ($unix != $ntid) then
		echo "Adding: {$unix = $ntid} to $user_map"
		echo "$unix = $ntid" >> $user_map
	endif
	set new = ($new $unix)
end

#
# Enter password for new users
#
foreach one ($new)
	echo $line
	echo "ENTER password for $one"
	smbpasswd $one
end