/* Perform basic Samba init stuff */ /*:VRX */ _SambaInit: IF options.!debug == 1 then say time()' _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 /* USER\Samba\ServerPath */ call charout , " Is Samba ServerPath stored in OS2.INI? " samba.!bin = strip(VRGetIni( "Samba", "ServerPath2", "USER" ),'T','00'x) if samba.!bin <> "" then do say 'Yes, found "'samba.!bin'"' if VRFileExists(samba.!bin"\smbd.exe") then do samba.!smbd = samba.!bin"\smbd.exe" say ' Found "'samba.!smbd'".' end end else say 'No, possibly manual installation.' end if samba.!smbd = "" then do /* wellknown locations */ WellKnown = SysBootdrive()"\ecs\system\samba;"SysBootdrive()"\samba" Programs = value("PROGRAMS",,'OS2ENVIRONMENT') if Programs <> "" then WellKnown = Wellknown';'Programs'\samba' Tools = value("TOOLS",,'OS2ENVIRONMENT') if Tools <> "" then WellKnown = Wellknown';'Tools'\samba' call charout , " Are binaries in wellknown locations? " ok = VRFindFile("smbd.exe",WellKnown) if ok <> "" then say "Yes."; else say "No." if ok <> "" then samba.!smbd = ok drop Wellknown Tools Programs end if samba.!smbd = "" then do /* in current directory? */ call charout , " Are binaries in current directory? " ok = SysFileTree('.\smbd.exe', exist.,'FO') if exist.0 = 1 then say "Yes."; else say "No." if exist.0 = 1 then samba.!smbd = exist.1 end if samba.!smbd = "" then do /* RPM/YUM/FHS tree */ call charout , " Are binaries in RPM/YUM/FHS tree? " ok = SysFileTree(UnixRoot'\usr\bin\smbd.exe', exist.,'FO') if exist.0 = 1 then say "Yes."; else say "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') if exist.0 = 1 then say "Yes."; else say "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') if exist.0 = 1 then say "Yes."; else say "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'"' IF options.!debug == 1 then say ' Samba smbd.exe = "'samba.!smbd'"' /* 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 "'samba.!smbpasswdexe'"!' 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 "'samba.!pdbeditexe'"!' 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 "'samba.!netexe'"!' 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 "'samba.!testparmexe'"!' 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 "'samba.!smbtreeexe'"!' 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 "'samba.!smbstatusexe'"!' 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 "'samba.!smbcontrolexe'"!' 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 "'samba.!smbclientexe'"!' IF options.!debug == 1 then say ' smbclient.exe = "'samba.!smbclientexe'"' /* nmblookup.exe */ samba.!nmblookupexe = samba.!bin'\nmblookup.exe' if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!nmblookupexe'"!' IF options.!debug == 1 then say ' nmblookup.exe = "'samba.!nmblookupexe'"' /* 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 "'samba.!pwd_mkdb'"!' 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\log' 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'"' /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */ /* before reading from it */ samba.!shadowsmbconf = TempDir||'smb.conf' /* 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 "'samba.!masterpasswd'"!' 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 "'samba.!pwddb'"!' 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 "'samba.!spwddb'"!' 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.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!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') /* This EA makes the testparm warning about browsing go away. */ /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */ ok = SysPutEA(ETC||'\samba\lock',"MODE", "FEFF0400ED410000"x) /* 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') <> "") /* Do we have a minimum of free temporary space? */ if _ChkTempFreeSpace < 262144 then call _ErrorDataFileNotFound 'Free space on "'TempDir'" exhausted!' /* 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 time()' _SambaInit() done, Errorstate = 'Errorstate return /*:VRX */ _SambaFinish: IF options.!debug == 1 then say time()' _SambaFinish() started.' /* 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) IF options.!debug == 1 then say time()' _SambaFinish() done.' return /*:VRX */ _ErrorBinaryNotFound: IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() started.' /* 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) IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() done, Errorstate = 'Errorstate return /*:VRX */ _ErrorDataFileNotFound: IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() started.' /* Set error status variable and show a short message - incomplete! */ msg = arg(1) say "ERROR: "msg DataErrorState = (1|DataErrorState) IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() done, Errorstate = 'Errorstate return /*:VRX */ _SambaExtendSearchPath: IF options.!debug == 1 then say time()' _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 DPATH variable */ old_dpath = value('DPATH',, 'OS2ENVIRONMENT') if pos(translate(samba.!bin';'),translate(old_dpath)) = 0 then do if samba.!bin = samba.!tools then new_dpath = samba.!bin';' else new_dpath = samba.!bin';'samba.!tools';' ok = value('DPATH', new_dpath || old_dpath, 'OS2ENVIRONMENT') drop new_dpath end drop old_dpath /* 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 /* Set LIBPATHSTRICT (this is an option - disabled by default) */ /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */ IF options.!debug == 1 then say time()' _SambaExtendSearchPath() done' return /*:VRX */ _SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options. samba. IF options.!debug == 1 then say time()' _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 time()' _SambaRunning() done' return runres