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