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

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

GUITools: Add GPLv3 header to all .VRS files

File size: 6.2 KB
Line 
1/* REXX Function Library for master.passwd management */
2
3/*
4Copyright (C) 2007-2017 Herwig Bauernfeind for bww bitwise works GmbH.
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21/* Currently implemented functions: */
22/* _MasterPasswdRead() */
23/* _MasterPasswdWrite() */
24/* _PasswordDBReWrite() */
25/* _MasterPasswdFindUser() */
26/* _MasterPasswdCreate() */
27
28/*:VRX _MasterpasswdRead
29*/
30_MasterpasswdRead:
31 IF options.!debug == 1 THEN say '_MasterpasswdRead() started'
32 /* Read complete master.passwd */
33 I = 0
34
35 do until lines(samba.!masterpasswd) = 0
36 userline = strip(linein(samba.!masterpasswd))
37
38 /* Skip comments */
39 if left(userline,1) = "#" then iterate
40 if left(userline,1) = ";" then iterate
41
42 /* parse fields into stem variables */
43 I = I + 1
44 parse var userline username.I':'password.I':'uid.I':'gid.I':'LoginClass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
45
46 Status.I =""
47 do J = 1 to I - 1
48 if translate(Username.J) = translate(Username.I) then do
49 status.I = "DUPLICATE"
50 leave
51 end
52 end
53 end
54 ok = stream(samba.!masterpasswd,'c','close')
55 drop userline
56
57 /* set "stem roots" properly */
58 username.0 = I
59 password.0 = I
60 uid.0 = I
61 gid.0 = I
62 loginclass.0= I
63 pwchange.0 = I
64 deact.0 = I
65 gecos.0 = I
66 home.0 = I
67 shell.0 = I
68
69 /* also smbpasswd stems */
70 lmhash. = ''
71 nthash. = ''
72 flags. = ''
73 lct. = ''
74 lmhash.0 = I
75 nthash.0 = I
76 flags.0 = I
77 lct.0 = I
78
79 /* smbusermap stem */
80 MapTo. = ''
81 MapTo.0 = I
82
83 /* our private stem */
84 status.0 = I
85 IF options.!debug == 1 THEN say '_MasterpasswdRead() done, read 'username.0' users'
86return
87
88/*:VRX _MasterpasswdWrite
89*/
90_MasterpasswdWrite:
91 IF options.!debug == 1 THEN say "_MasterpasswdWrite() started"
92
93 newmasterpasswd = TempDir'master.passwd'
94 ok = SysFileDelete(newmasterpasswd)
95 call lineout newmasterpasswd, '# Created by Samba GUI Tools 'date('E')' 'time()
96 call lineout newmasterpasswd, '# syntax:'
97 call lineout newmasterpasswd, '# username:passwd:UID:GID:login-class:chg pw x sec:deact x sec:GECOS:home:shell'
98 do I = 1 to username.0
99 select
100 when Status.I = "DUPLICATE" & settings.!FixErrors then iterate
101 when Status.I = "UID MISMATCH" then do
102 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
103 end
104 when Status.I = "UNIX MISSING" & settings.!FixErrors then do
105 call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
106 end
107 otherwise call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I
108 end
109 end
110 ok = stream(newmasterpasswd,'c','close')
111 ok = VRCopyFile( samba.!masterpasswd, samba.!masterpasswd'.bak' )
112 ok = VRCopyFile( newmasterpasswd, samba.!masterpasswd )
113 ok = SysFileDelete(newmasterpasswd)
114 IF options.!debug == 1 THEN say "_MasterpasswdWrite() done"
115return
116
117/*:VRX */
118_PasswordDbRewrite:
119 IF options.!debug == 1 then say time()' _PasswordDBRewrite() started'
120
121 /* Reset any old rc from pwd_mkdb.exe */
122 pwd_mkdbrc = 0
123
124 /* delete old .db.tmp files */
125 ok = SysFileDelete(UnixETC'\pwd.db.tmp')
126 ok = SysFileDelete(UnixETC'\spwd.db.tmp')
127
128 /* create backups of old .db files */
129 ok = VRCopyFile( UnixETC'\pwd.db', UnixETC'\pwd.db.bak' )
130 ok = VRCopyFile( UnixETC'\spwd.db', UnixETC'\spwd.db.bak' )
131
132 /* delete old .db files */
133 ok = SysFileDelete(UnixETC'\pwd.db')
134 ok = SysFileDelete(UnixETC'\spwd.db')
135
136 /* Create new password db */
137 address cmd samba.!pwd_mkdb' -d 'unixetc' 'samba.!masterpasswd' 2>'samba.!error
138 pwd_mkdbrc = rc
139 if \VRFileExists(samba.!pwddb) | pwd_mkdbrc <> 0 then do
140 call _SambaShowError
141 end
142 IF options.!debug == 1 then say time()" _PasswordDBRewrite() done ("pwd_mkdbrc")"
143return
144
145_MasterPasswdFindUser: procedure expose username.
146 IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'arg(1)'") started'
147 FindUser = arg(1)
148 Idx = 0
149 do I = 1 to username.0
150 if translate(username.I) = translate(FindUser) then do
151 Idx = I
152 leave
153 end
154 end
155 IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'FindUser'") done, returning 'Idx
156return idx
157
158/*:VRX _MasterPasswdCreate */
159_MasterPasswdCreate:
160 IF options.!debug == 1 THEN say '_MasterPasswdCreate() started.'
161 call lineout samba.!masterpasswd, '# Created by Samba GUI Tools 'date('E')' 'time()
162 call lineout samba.!masterpasswd, '# syntax:'
163 call lineout samba.!masterpasswd, '# username:passwd:UID:GID:login-class:chg pw x sec:deact x sec:GECOS:home:shell'
164 call lineout samba.!masterpasswd, 'root:*:0:512::0:0:root:/nonexistent:/usr/sbin/nologin'
165 call lineout samba.!masterpasswd, 'guest:*:65534:65534::0:0:guest:/nonexistent:/usr/sbin/nologin'
166 ok = stream(samba.!masterpasswd,'c','close')
167 IF options.!debug == 1 THEN say '_MasterPasswdCreate() done.'
168return
Note: See TracBrowser for help on using the repository browser.