/* Perform basic Samba init stuff */ /*:VRX */ _SambaInit: IF options.!debug == 1 THEN say '_SambaInit() started' IF options.!debug == 1 THEN say " Checking Samba setup..." /* debuglevel when executing Samba binaries */ debuglevel = ' --debuglevel=0' /* Error status and file variables */ ErrorState = 0 /* _ErrorBinaryNotFound() changes this variable */ DataErrorState = 0 /* _ErrorDataFileNotFound() changes this variable */ /* Evaluate environment */ ETC = value('ETC',,'OS2ENVIRONMENT') IF options.!debug == 1 THEN say ' ETC = "'ETC'"' UnixRoot = value("UNIXROOT",,'OS2ENVIRONMENT') if UnixRoot = "" then do UnixRoot = left(ETC,length(ETC)-4) say ' WARNING! Setting missing UNIXROOT variable to "'UnixRoot'".' ok = value("UNIXROOT",UnixRoot,'OS2ENVIRONMENT') end IF options.!debug == 1 THEN say ' UnixRoot = "'UnixRoot'"' unixetc = UnixRoot'\etc' IF options.!debug == 1 THEN say ' Unixetc = "'unixetc'"' /* Find all executables */ /* Get the path to this file */ samba.!tools = VRParseFilename(VRGet("Application", "Program"),'DP') if samba.!tools = '' then do parse source . . script samba.!tools = VRParseFilename(script,'DP') end IF options.!debug == 1 THEN say ' Samba tools = "'samba.!tools'"' say ' Changing into "'directory(samba.!tools)'"' /* smbd.exe */ samba.!smbd = "" if samba.!smbd = "" then do /* in current directory? */ call charout , " Are binaries in current directory? " ok = SysFileTree('.\smbd.exe', exist.,'FO') say exist.0' (1 = Yes, 0 = No)' if exist.0 = 1 then samba.!smbd = exist.1 end if samba.!smbd = "" then do /* in parent directory? */ call charout , " Are binaries in parent directory? " ok = SysFileTree('..\smbd.exe', exist.,'FO') say exist.0' (1 = Yes, 0 = No)' if exist.0 = 1 then samba.!smbd = exist.1 end if samba.!smbd = "" then do /* in ..\BIN directory? */ call charout , " Are binaries in ..\BIN directory? " ok = SysFileTree('..\bin\smbd.exe', exist.,'FO') say exist.0' (1 = Yes, 0 = No)' if exist.0 = 1 then samba.!smbd = exist.1 end if samba.!smbd = "" then do /* in SMB_EXE ? */ call charout , " Are binaries in SMB_EXE path? " samba.!smbd = SysSearchPath("SMB_EXE","SMBD.EXE") if samba.!smbd = "" then say "No."; else say "Yes." end if samba.!smbd = "" then do /* in PATH ? */ call charout , " Are binaries in PATH? " samba.!smbd = SysSearchPath("PATH","SMBD.EXE") if samba.!smbd = "" then say "No."; else say "Yes." end if samba.!smbd = "" then call _ErrorBinaryNotFound " could not find smbd.exe!" samba.!bin = VRParseFileName(samba.!smbd,'DP') IF options.!debug == 1 THEN say ' Samba binaries = "'samba.!bin'"' /* smb.cmd */ samba.!smbcmd = samba.!tools'\smb.cmd' if \VRFileExists(samba.!smbcmd) then do samba.!smbcmd = samba.!bin'\smb.cmd' if \VRFileExists(samba.!smbcmd) then call _ErrorBinaryNotFound " could not find smb.cmd!" end IF options.!debug == 1 THEN say ' smb.cmd = "'samba.!smbcmd'"' /* smbpasswd.exe */ samba.!smbpasswdexe = samba.!bin'\smbpasswd.exe' if \VRFileExists(samba.!smbpasswdexe) then call _ErrorBinaryNotFound " could not find smbpasswd.exe!" IF options.!debug == 1 THEN say ' smbpasswd.exe = "'samba.!smbpasswdexe'"' /* pdbedit.exe */ samba.!pdbeditexe = samba.!bin'\pdbedit.exe' if \VRFileExists(samba.!pdbeditexe) then call _ErrorBinaryNotFound " could not find pdbedit.exe!" IF options.!debug == 1 THEN say ' pdbedit.exe = "'samba.!pdbeditexe'"' /* net.exe */ samba.!netexe = samba.!bin'\net.exe' if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!" IF options.!debug == 1 THEN say ' net.exe = "'samba.!netexe'"' /* testparm.exe */ samba.!testparmexe = samba.!bin'\testparm.exe' if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!" IF options.!debug == 1 THEN say ' testparm.exe = "'samba.!testparmexe'"' /* smbtree.exe */ samba.!smbtreeexe = samba.!bin'\smbtree.exe' if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!" IF options.!debug == 1 THEN say ' smbtree.exe = "'samba.!smbtreeexe'"' /* smbstatus.exe */ samba.!smbstatusexe = samba.!bin'\smbstatus.exe' if \VRFileExists(samba.!smbstatusexe) then call _ErrorBinaryNotFound " could not find smbstatus.exe!" IF options.!debug == 1 THEN say ' smbstatus.exe = "'samba.!smbstatusexe'"' /* smbcontrol.exe */ samba.!smbcontrolexe = samba.!bin'\smbcontrol.exe' if \VRFileExists(samba.!smbcontrolexe) then call _ErrorBinaryNotFound " could not find smbcontrol.exe!" IF options.!debug == 1 THEN say ' smbcontrol.exe = "'samba.!smbcontrolexe'"' /* smbclient.exe */ samba.!smbclientexe = samba.!bin'\smbclient.exe' if \VRFileExists(samba.!smbclientexe) then call _ErrorBinaryNotFound " could not find smbclient.exe!" IF options.!debug == 1 THEN say ' smbclient.exe = "'samba.!smbclientexe'"' /* pwd_mkdb */ samba.!pwd_mkdb = SysSearchPath("PATH","pwd_mkdb.exe") if samba.!pwd_mkdb = "" then do /* in current directory? */ ok = SysFileTree('.\pwd_mkdb.exe', exist.,'FO') if exist.0 = 1 then samba.!pwd_mkdb = exist.1 end if samba.!pwd_mkdb = "" then do /* in usr/sbin directory? */ ok = SysFileTree(UnixRoot'\usr\sbin\pwd_mkdb.exe', exist.,'FO') if exist.0 = 1 then samba.!pwd_mkdb = exist.1 end if samba.!pwd_mkdb = "" then do /* tools directory? */ ok = SysFileTree(samba.!tools'\pwd_mkdb.exe', exist.,'FO') if exist.0 = 1 then samba.!pwd_mkdb = exist.1 end if samba.!pwd_mkdb = "" then do /* in smbd directory? */ ok = SysFileTree(samba.!bin'\pwd_mkdb.exe', exist.,'FO') if exist.0 = 1 then samba.!pwd_mkdb = exist.1 end if samba.!pwd_mkdb = "" then do /* in SMB_SBIN ? */ samba.!pwd_mkdb = SysSearchPath("SMB_SBIN","pwd_mkdb.exe") end if samba.!pwd_mkdb = "" then call _ErrorBinaryNotFound " could not find pwd_mkdb.exe!" IF options.!debug == 1 THEN say ' pwd_mkdb.exe = "'samba.!pwd_mkdb'"' /* logfiles */ samba.!log = value('SMB_LOGS',,'OS2ENVIRONMENT') if samba.!log = "" then do /* new default */ ok = SysFileTree(etc'\samba\log',exist.,'DO') if exist.0 > 0 then samba.!log = etc'\samba\logs' end if samba.!log = "" then do /* old default */ ok = SysFileTree(samba.!bin'\logs\log.smbd*',exist.,'FO') if exist.0 > 0 then samba.!log = samba.!bin'\logs' end if samba.!log = "" then do /* LOGFILES */ samba.!log = value('LOGFILES',,'OS2ENVIRONMENT') end if samba.!log = "" then call _ErrorDataFileNotFound " could not find logfiles!" IF options.!debug == 1 THEN say ' Samba logfiles = "'samba.!log'"' /* smb.conf */ samba.!smbconf = ETC'\samba\smb.conf' if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.' IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"' /* find all datafiles - their locations are fixed */ /* the password files - we'll create them if they don't exist */ samba.!masterpasswd = unixetc'\master.passwd' if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound " could not find master.passwd!" IF options.!debug == 1 THEN say ' master.passwd = "'samba.!masterpasswd'"' samba.!pwddb = unixetc'\pwd.db' if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound " could not find pwd.db!" IF options.!debug == 1 THEN say ' pwd.db = "'samba.!pwddb'"' samba.!spwddb = unixetc'\spwd.db' if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find spwd.db!" IF options.!debug == 1 THEN say ' spwd.db = "'samba.!spwddb'"' samba.!group = unixetc'\group' if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound " could not find "samba.!group"!" IF options.!debug == 1 THEN say ' group = "'samba.!group'"' samba.!printcap = unixetc'\printcap' if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find printcap!" IF options.!debug == 1 THEN say ' printcap = "'samba.!printcap'"' /* Create these directories to make sure they do exist */ ok = SysMkDir(unixetc) ok = SysMkDir(etc'\samba') ok = SysMkDir(etc'\samba\private') ok = SysMkDir(etc'\samba\pid') ok = SysMkDir(etc'\samba\log') ok = SysMkDir(etc'\samba\lock') ok = SysMkDir(etc'\samba\spool') ok = SysMkDir(etc'\samba\drivers') /* use temporary smbpasswd created by pdbedit */ samba.!smbpasswd = TempDir'smbpasswd' IF options.!debug == 1 THEN say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)' /* Check if winbindd daemon exists */ HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "") /* Messages from Samba will go here */ samba.!error = SysTempFileName(TempDir'smb_err.???') samba.!msg = SysTempFileName(TempDir'smb_msg.???') /* Use of this file is deprecated */ ErrorFile = Tempdir'smbutil.error' IF options.!debug == 1 then do if ErrorState then say " One or more basic Samba setup errors detected!" else say " No basic Samba setup errors detected!" end IF options.!debug == 1 THEN say '_SambaInit() done, Errorstate = 'Errorstate return /*:VRX */ _SambaFinish: /* Do some very basic housekeeping when leaving */ ok = stream(samba.!msg,'c','close') ok = stream(samba.!error,'c','close') ok = SysFileDelete(samba.!msg) ok = SysFileDelete(samba.!error) return /*:VRX */ _ErrorBinaryNotFound: /* Set error status variable and show a short message - incomplete! */ msg = arg(1) say "ERROR: "msg id = VRMessage( VRWindow(), msg, "Samba Installation", "E" ) ErrorState = (1|ErrorState) return /*:VRX */ _ErrorDataFileNotFound: /* Set error status variable and show a short message - incomplete! */ msg = arg(1) say "ERROR: "msg DataErrorState = (1|DataErrorState) return /*:VRX */ _SambaExtendSearchPath: IF options.!debug == 1 THEN say '_SambaExtendSearchPath() started' /* Add binary and tools path to the PATH variable */ old_path = value('PATH',, 'OS2ENVIRONMENT') if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do if samba.!bin = samba.!tools then new_path = samba.!bin';' else new_path = samba.!bin';'samba.!tools';' ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT') drop new_path end drop old_path /* Add binary and tools path to the BEGINLIBPATH variable */ old_beginlibpath = SysQueryExtLibPath("B") if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath ok = SysSetExtLibPath( new_beginlibpath, "B") drop new_beginlibpath end drop old_beginlibpath IF options.!debug == 1 THEN say '_SambaExtendSearchPath() done' return /*:VRX */ _SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options. IF options.!debug == 1 THEN say '_SambaRunning() started' /* Checks whether any Samba daemon is currently running */ /* Parameters: none or "ALL" Returns: 1 = at least one Samba daemon is running 1 = Parameter "ALL" all Samba daemons are running 0 = no Samba daemon is running 0 = Parameter "ALL" not all Samba daemons are running Stems: running. stores which daemon is running pids. stores pids of running daemons */ restype = arg(1) running. = 0 pids. = "" ok = PRProcessList(proc) do I = 1 to proc.0 CurProc = VRParseFileName(proc.i.name,'NE') if CurProc = "SMBD.EXE" then do running.!smbd = 1 pids.!smbd = pids.!smbd||proc.i.pid||' ' end if CurProc = "NMBD.EXE" then do running.!nmbd = 1 pids.!nmbd = pids.!nmbd||proc.i.pid||' ' end if CurProc = "WINBINDD.EXE" then do running.!winb = 1 pids.!winb = pids.!winb||proc.i.pid||' ' end end if restype = "ALL" then do runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd )) end else do runres = (running.!smbd | running.!nmbd |running.!winb) end IF options.!debug == 1 THEN say '_SambaRunning() done' return runres /*:VRX */ _PasswordDbRewrite: IF options.!debug == 1 THEN say "_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 "_PasswordDBRewrite() done ("pwd_mkdbrc")" return