/* REXX Function Library for master.passwd management */ /* Currently implemented functions: */ /* _MasterPasswdRead() */ /* _MasterPasswdWrite() */ /* _PasswordDBReWrite() */ /*:VRX _MasterpasswdRead */ _MasterpasswdRead: IF options.!debug == 1 THEN say '_MasterpasswdRead() started' /* Read complete master.passwd */ I = 0 do until lines(samba.!masterpasswd) = 0 userline = strip(linein(samba.!masterpasswd)) /* Skip comments */ if left(userline,1) = "#" then iterate if left(userline,1) = ";" then iterate /* parse fields into stem variables */ I = I + 1 parse var userline username.I':'password.I':'uid.I':'gid.I':'LoginClass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I Status.I ="" do J = 1 to I - 1 if translate(Username.J) = translate(Username.I) then do status.I = "DUPLICATE" leave end end end ok = stream(samba.!masterpasswd,'c','close') drop userline /* set "stem roots" properly */ username.0 = I password.0 = I uid.0 = I gid.0 = I loginclass.0= I pwchange.0 = I deact.0 = I gecos.0 = I home.0 = I shell.0 = I /* also smbpasswd stems */ lmhash. = '' nthash. = '' flags. = '' lct. = '' lmhash.0 = I nthash.0 = I flags.0 = I lct.0 = I /* smbusermap stem */ MapTo. = '' MapTo.0 = I /* our private stem */ status.0 = I IF options.!debug == 1 THEN say '_MasterpasswdRead() done, read 'username.0' users' return /*:VRX _MasterpasswdWrite */ _MasterpasswdWrite: IF options.!debug == 1 THEN say "_MasterpasswdWrite() started" newmasterpasswd = TempDir'master.passwd' ok = SysFileDelete(newmasterpasswd) call lineout newmasterpasswd, '# Created by Samba GUI Tools 'date('E')' 'time('')) call lineout newmasterpasswd, '# syntax:' call lineout newmasterpasswd, '# username:passwd:UID:GID:login-class:chg pw x sec:deact x sec:GECOS:home:shell' do I = 1 to username.0 select when Status.I = "DUPLICATE" & settings.!FixErrors then iterate when Status.I = "UID MISMATCH" then do 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 end when Status.I = "UNIX MISSING" & settings.!FixErrors then do call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I end otherwise call lineout newmasterpasswd, username.I':'password.I':'uid.I':'gid.I':'loginclass.I':'pwchange.I':'deact.I':'gecos.I':'home.I':'shell.I end end ok = stream(newmasterpasswd,'c','close') ok = VRCopyFile( samba.!masterpasswd, samba.!masterpasswd'.bak' ) ok = VRCopyFile( newmasterpasswd, samba.!masterpasswd ) ok = SysFileDelete(newmasterpasswd) IF options.!debug == 1 THEN say "_MasterpasswdWrite() done" return /*:VRX */ _PasswordDbRewrite: IF options.!debug == 1 then say time()' _PasswordDBRewrite() started' /* Reset any old rc from pwd_mkdb.exe */ pwd_mkdbrc = 0 /* delete old .db.tmp files */ ok = SysFileDelete(UnixETC'\pwd.db.tmp') ok = SysFileDelete(UnixETC'\spwd.db.tmp') /* create backups of old .db files */ ok = VRCopyFile( UnixETC'\pwd.db', UnixETC'\pwd.db.bak' ) ok = VRCopyFile( UnixETC'\spwd.db', UnixETC'\spwd.db.bak' ) /* delete old .db files */ ok = SysFileDelete(UnixETC'\pwd.db') ok = SysFileDelete(UnixETC'\spwd.db') /* Create new password db */ address cmd samba.!pwd_mkdb' -d 'unixetc' 'samba.!masterpasswd' 2>'samba.!error pwd_mkdbrc = rc if \VRFileExists(samba.!pwddb) | pwd_mkdbrc <> 0 then do call _SambaShowError end IF options.!debug == 1 then say time()" _PasswordDBRewrite() done ("pwd_mkdbrc")" return _MasterPasswdFindUser: procedure expose username. IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'arg(1)'") started' FindUser = arg(1) Idx = 0 do I = 1 to username.0 if translate(username.I) = translate(FindUser) then do Idx = I leave end end IF options.!debug == 1 THEN say '_MasterpasswdFindUser("'FindUser'") done, returning 'Idx return idx