source: trunk/guitools/shared/masterpasswd.vrs@ 1022

Last change on this file since 1022 was 1022, checked in by Herwig Bauernfeind, 8 years ago

GUITools: masterpasswd.vrs: Fix _MasterPasswdCreate()

File size: 5.5 KB
Line 
1/* REXX Function Library for master.passwd management */
2
3/* Currently implemented functions: */
4/* _MasterPasswdRead() */
5/* _MasterPasswdWrite() */
6/* _PasswordDBReWrite() */
7/* _MasterPasswdFindUser() */
8/* _MasterPasswdCreate() */
9
10/*:VRX _MasterpasswdRead
11*/
12_MasterpasswdRead:
13 IF options.!debug == 1 THEN say '_MasterpasswdRead() started'
14 /* Read complete master.passwd */
15 I = 0
16
17 do until lines(samba.!masterpasswd) = 0
18 userline = strip(linein(samba.!masterpasswd))
19
20 /* Skip comments */
21 if left(userline,1) = "#" then iterate
22 if left(userline,1) = ";" then iterate
23
24 /* parse fields into stem variables */
25 I = I + 1
26 parse var userline username.I':'password.I':'uid.I':'gid.I':'LoginClass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
27
28 Status.I =""
29 do J = 1 to I - 1
30 if translate(Username.J) = translate(Username.I) then do
31 status.I = "DUPLICATE"
32 leave
33 end
34 end
35 end
36 ok = stream(samba.!masterpasswd,'c','close')
37 drop userline
38
39 /* set "stem roots" properly */
40 username.0 = I
41 password.0 = I
42 uid.0 = I
43 gid.0 = I
44 loginclass.0= I
45 pwchange.0 = I
46 deact.0 = I
47 gecos.0 = I
48 home.0 = I
49 shell.0 = I
50
51 /* also smbpasswd stems */
52 lmhash. = ''
53 nthash. = ''
54 flags. = ''
55 lct. = ''
56 lmhash.0 = I
57 nthash.0 = I
58 flags.0 = I
59 lct.0 = I
60
61 /* smbusermap stem */
62 MapTo. = ''
63 MapTo.0 = I
64
65 /* our private stem */
66 status.0 = I
67 IF options.!debug == 1 THEN say '_MasterpasswdRead() done, read 'username.0' users'
68return
69
70/*:VRX _MasterpasswdWrite
71*/
72_MasterpasswdWrite:
73 IF options.!debug == 1 THEN say "_MasterpasswdWrite() started"
74
75 newmasterpasswd = TempDir'master.passwd'
76 ok = SysFileDelete(newmasterpasswd)
77 call lineout newmasterpasswd, '# Created by Samba GUI Tools 'date('E')' 'time()
78 call lineout newmasterpasswd, '# syntax:'
79 call lineout newmasterpasswd, '# username:passwd:UID:GID:login-class:chg pw x sec:deact x sec:GECOS:home:shell'
80 do I = 1 to username.0
81 select
82 when Status.I = "DUPLICATE" & settings.!FixErrors then iterate
83 when Status.I = "UID MISMATCH" then do
84 call lineout newmasterpasswd, username.I':'password.I':'word(uid.I,1)':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
85 end
86 when Status.I = "UNIX MISSING" & settings.!FixErrors then do
87 call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
88 end
89 otherwise call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
90 end
91 end
92 ok = stream(newmasterpasswd,'c','close')
93 ok = VRCopyFile( samba.!masterpasswd, samba.!masterpasswd'.bak' )
94 ok = VRCopyFile( newmasterpasswd, samba.!masterpasswd )
95 ok = SysFileDelete(newmasterpasswd)
96 IF options.!debug == 1 THEN say "_MasterpasswdWrite() done"
97return
98
99/*:VRX */
100_PasswordDbRewrite:
101 IF options.!debug == 1 then say time()' _PasswordDBRewrite() started'
102
103 /* Reset any old rc from pwd_mkdb.exe */
104 pwd_mkdbrc = 0
105
106 /* delete old .db.tmp files */
107 ok = SysFileDelete(UnixETC'\pwd.db.tmp')
108 ok = SysFileDelete(UnixETC'\spwd.db.tmp')
109
110 /* create backups of old .db files */
111 ok = VRCopyFile( UnixETC'\pwd.db', UnixETC'\pwd.db.bak' )
112 ok = VRCopyFile( UnixETC'\spwd.db', UnixETC'\spwd.db.bak' )
113
114 /* delete old .db files */
115 ok = SysFileDelete(UnixETC'\pwd.db')
116 ok = SysFileDelete(UnixETC'\spwd.db')
117
118 /* Create new password db */
119 address cmd samba.!pwd_mkdb' -d 'unixetc' 'samba.!masterpasswd' 2>'samba.!error
120 pwd_mkdbrc = rc
121 if \VRFileExists(samba.!pwddb) | pwd_mkdbrc <> 0 then do
122 call _SambaShowError
123 end
124 IF options.!debug == 1 then say time()" _PasswordDBRewrite() done ("pwd_mkdbrc")"
125return
126
127_MasterPasswdFindUser: procedure expose username.
128 IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'arg(1)'") started'
129 FindUser = arg(1)
130 Idx = 0
131 do I = 1 to username.0
132 if translate(username.I) = translate(FindUser) then do
133 Idx = I
134 leave
135 end
136 end
137 IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'FindUser'") done, returning 'Idx
138return idx
139
140/*:VRX _MasterPasswdCreate */
141_MasterPasswdCreate:
142 IF options.!debug == 1 THEN say '_MasterPasswdCreate() started.'
143 call lineout samba.!masterpasswd, '# Created by Samba GUI Tools 'date('E')' 'time()
144 call lineout samba.!masterpasswd, '# syntax:'
145 call lineout samba.!masterpasswd, '# username:passwd:UID:GID:login-class:chg pw x sec:deact x sec:GECOS:home:shell'
146 call lineout samba.!masterpasswd, 'root:*:0:512::0:0:root:/nonexistent:/usr/sbin/nologin'
147 call lineout samba.!masterpasswd, 'guest:*:65534:65534::0:0:guest:/nonexistent:/usr/sbin/nologin'
148 ok = stream(samba.!masterpasswd,'c','close')
149 IF options.!debug == 1 THEN say '_MasterPasswdCreate() done.'
150return
Note: See TracBrowser for help on using the repository browser.