| 1 | /* Perform basic Samba Client init stuff */ | 
|---|
| 2 |  | 
|---|
| 3 | /*:VRX */ | 
|---|
| 4 | _CltInit: | 
|---|
| 5 | IF options.!debug == 1 THEN say time()' _CltInit() started' | 
|---|
| 6 | IF options.!debug == 1 THEN say '  Checking Samba Client setup...' | 
|---|
| 7 |  | 
|---|
| 8 | /* debuglevel when executing Samba binaries */ | 
|---|
| 9 | debuglevel = ' --debuglevel=0' | 
|---|
| 10 |  | 
|---|
| 11 | /* Error status and file variables */ | 
|---|
| 12 | ErrorState = 0 /* _ErrorBinaryNotFound() changes this variable */ | 
|---|
| 13 | DataErrorState = 0 /* _ErrorDataFileNotFound() changes this variable */ | 
|---|
| 14 |  | 
|---|
| 15 | /* Evaluate environment */ | 
|---|
| 16 | ETC      = value('ETC',,'OS2ENVIRONMENT') | 
|---|
| 17 | IF options.!debug == 1 THEN say '  ETC            = "'ETC'"' | 
|---|
| 18 |  | 
|---|
| 19 | UnixRoot = value("UNIXROOT",,'OS2ENVIRONMENT') | 
|---|
| 20 | if UnixRoot = "" then do | 
|---|
| 21 | UnixRoot = left(ETC,length(ETC)-4) | 
|---|
| 22 | say '  WARNING! Setting missing UNIXROOT variable to "'UnixRoot'".' | 
|---|
| 23 | ok = value("UNIXROOT",UnixRoot,'OS2ENVIRONMENT') | 
|---|
| 24 | end | 
|---|
| 25 |  | 
|---|
| 26 | IF options.!debug == 1 THEN say '  UnixRoot       = "'UnixRoot'"' | 
|---|
| 27 |  | 
|---|
| 28 | unixetc = UnixRoot'\etc' | 
|---|
| 29 | IF options.!debug == 1 THEN say '  Unixetc        = "'unixetc'"' | 
|---|
| 30 |  | 
|---|
| 31 | /* Find all executables */ | 
|---|
| 32 |  | 
|---|
| 33 | /* Get the path to this file */ | 
|---|
| 34 | samba.!tools = VRParseFilename(VRGet("Application", "Program"),'DP') | 
|---|
| 35 | if samba.!tools = '' then do | 
|---|
| 36 | parse source . . script | 
|---|
| 37 | samba.!tools = VRParseFilename(script,'DP') | 
|---|
| 38 | end | 
|---|
| 39 | IF options.!debug == 1 THEN say '  Samba tools    = "'samba.!tools'"' | 
|---|
| 40 | say '  Changing into tools "'directory(samba.!tools)'"' | 
|---|
| 41 |  | 
|---|
| 42 | /* smbclient.exe */ | 
|---|
| 43 | samba.!smbclientexe = "" | 
|---|
| 44 | if samba.!smbclientexe = "" then do /* wellknown locations */ | 
|---|
| 45 | WellKnown = sysBootdrive()"\ecs\system\samba;"sysBootdrive()"\samba" | 
|---|
| 46 | Programs = value("PROGRAMS",,'OS2ENVIRONMENT') | 
|---|
| 47 | if Programs <> "" then WellKnown = Wellknown';'Programs'\samba' | 
|---|
| 48 | Tools = value("TOOLS",,'OS2ENVIRONMENT') | 
|---|
| 49 | if Programs <> "" then WellKnown = Wellknown';'Tools'\samba' | 
|---|
| 50 | say Wellknown | 
|---|
| 51 | call charout , "  Are binaries in wellknown locations? " | 
|---|
| 52 | ok = VRFindFile("smbclient.exe",WellKnown) | 
|---|
| 53 | if ok <> "" then say "Yes."; else say "No." | 
|---|
| 54 | if ok <> "" then samba.!smbclientexe = ok | 
|---|
| 55 | drop Wellknown | 
|---|
| 56 | end | 
|---|
| 57 | if samba.!smbclientexe = "" then do /* in current directory? */ | 
|---|
| 58 | call charout , "  Are binaries in current directory? " | 
|---|
| 59 | ok = SysFileTree('.\smbclient.exe', exist.,'FO') | 
|---|
| 60 | if exist.0 = 1 then say "Yes."; else say "No." | 
|---|
| 61 | if exist.0 = 1 then samba.!smbclientexe = exist.1 | 
|---|
| 62 | end | 
|---|
| 63 | if samba.!smbclientexe = "" then do /* RPM/YUM/FHS tree */ | 
|---|
| 64 | call charout , "  Are binaries in RPM/YUM/FHS tree? " | 
|---|
| 65 | ok = SysFileTree(UnixRoot'\usr\bin\smbclient.exe', exist.,'FO') | 
|---|
| 66 | if exist.0 = 1 then say "Yes."; else say "No." | 
|---|
| 67 | if exist.0 = 1 then samba.!smbclientexe = exist.1 | 
|---|
| 68 | end | 
|---|
| 69 | if samba.!smbclientexe = "" then do /* in parent directory? */ | 
|---|
| 70 | call charout , "  Are binaries in parent directory? " | 
|---|
| 71 | ok = SysFileTree('..\smbclient.exe', exist.,'FO') | 
|---|
| 72 | if exist.0 = 1 then say "Yes."; else say "No." | 
|---|
| 73 | if exist.0 = 1 then samba.!smbclientexe = exist.1 | 
|---|
| 74 | end | 
|---|
| 75 | if samba.!smbclientexe = "" then do /* in ..\BIN directory? */ | 
|---|
| 76 | call charout , "  Are binaries in ..\BIN directory? " | 
|---|
| 77 | ok = SysFileTree('..\bin\smbclient.exe', exist.,'FO') | 
|---|
| 78 | if exist.0 = 1 then say "Yes."; else say "No." | 
|---|
| 79 | if exist.0 = 1 then samba.!smbclientexe = exist.1 | 
|---|
| 80 | end | 
|---|
| 81 | if samba.!smbclientexe = "" then do /* in SMB_EXE ? */ | 
|---|
| 82 | call charout , "  Are binaries in SMB_EXE path? " | 
|---|
| 83 | samba.!smbclientexe = SysSearchPath("SMB_EXE","smbclient.EXE") | 
|---|
| 84 | if samba.!smbclientexe = "" then say "No."; else say "Yes." | 
|---|
| 85 | end | 
|---|
| 86 | if samba.!smbclientexe = "" then do /* in PATH ? */ | 
|---|
| 87 | call charout , "  Are binaries in PATH? " | 
|---|
| 88 | samba.!smbclientexe = SysSearchPath("PATH","smbclient.EXE") | 
|---|
| 89 | if samba.!smbclientexe = "" then say "No."; else say "Yes." | 
|---|
| 90 | end | 
|---|
| 91 |  | 
|---|
| 92 | if samba.!smbclientexe = "" then call _ErrorBinaryNotFound " could not find smbclient.exe!" | 
|---|
| 93 |  | 
|---|
| 94 | samba.!bin = VRParseFileName(samba.!smbclientexe,'DP') | 
|---|
| 95 | IF options.!debug == 1 THEN say '  Samba binaries = "'samba.!bin'"' | 
|---|
| 96 |  | 
|---|
| 97 | /* net.exe */ | 
|---|
| 98 | samba.!netexe = samba.!bin'\net.exe' | 
|---|
| 99 | if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!" | 
|---|
| 100 | IF options.!debug == 1 THEN say '  net.exe        = "'samba.!netexe'"' | 
|---|
| 101 |  | 
|---|
| 102 | /* testparm.exe */ | 
|---|
| 103 | samba.!testparmexe = samba.!bin'\testparm.exe' | 
|---|
| 104 | if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!" | 
|---|
| 105 | IF options.!debug == 1 THEN say '  testparm.exe   = "'samba.!testparmexe'"' | 
|---|
| 106 |  | 
|---|
| 107 | /* smbtree.exe */ | 
|---|
| 108 | samba.!smbtreeexe = samba.!bin'\smbtree.exe' | 
|---|
| 109 | if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!" | 
|---|
| 110 | IF options.!debug == 1 THEN say '  smbtree.exe    = "'samba.!smbtreeexe'"' | 
|---|
| 111 |  | 
|---|
| 112 | /* nmblookup.exe */ | 
|---|
| 113 | samba.!nmblookupexe = samba.!bin'\nmblookup.exe' | 
|---|
| 114 | if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound " could not find nmblookup.exe!" | 
|---|
| 115 | IF options.!debug == 1 THEN say '  nmblookup.exe  = "'samba.!nmblookupexe'"' | 
|---|
| 116 |  | 
|---|
| 117 | /* smbspool.exe */ | 
|---|
| 118 | samba.!smbspoolexe = samba.!bin'\smbspool.exe' | 
|---|
| 119 | if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound " could not find smbspool.exe!" | 
|---|
| 120 | IF options.!debug == 1 THEN say '  smbspool.exe   = "'samba.!smbspoolexe'"' | 
|---|
| 121 |  | 
|---|
| 122 | /* rpcclient.exe */ | 
|---|
| 123 | samba.!rpcclientexe = samba.!bin'\rpcclient.exe' | 
|---|
| 124 | if \VRFileExists(samba.!rpcclientexe) then call _ErrorBinaryNotFound " could not find rpcclient.exe!" | 
|---|
| 125 | IF options.!debug == 1 THEN say '  rpcclient.exe  = "'samba.!rpcclientexe'"' | 
|---|
| 126 |  | 
|---|
| 127 | /* smb.conf */ | 
|---|
| 128 | samba.!smbconf = ETC'\samba\smb.conf' | 
|---|
| 129 | if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.' | 
|---|
| 130 | IF options.!debug == 1 THEN say '  Samba smb.conf = "'samba.!smbconf'"' | 
|---|
| 131 |  | 
|---|
| 132 | /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */ | 
|---|
| 133 | /* before reading from it */ | 
|---|
| 134 | samba.!shadowsmbconf = TempDir||'smb.conf' | 
|---|
| 135 |  | 
|---|
| 136 | /* lmhosts */ | 
|---|
| 137 | samba.!lmhosts = ETC'\samba\lmhosts' | 
|---|
| 138 | if \VRFileExists(samba.!lmhosts) then call _ErrorDataFileNotFound samba.!lmhosts' is not present.' | 
|---|
| 139 | IF options.!debug == 1 THEN say '  Samba lmhosts  = "'samba.!lmhosts'"' | 
|---|
| 140 |  | 
|---|
| 141 | /* FIXME: Needs to be changed for Samba 3.3+ */ | 
|---|
| 142 | /* upcase table files - several utilities need these */ | 
|---|
| 143 | if (\VRFileExists(samba.!bin'\lib\upcase.dat')) |, | 
|---|
| 144 | (\VRFileExists(samba.!bin'\lib\lowcase.dat')) |, | 
|---|
| 145 | (\VRFileExists(samba.!bin'\lib\valid.dat')) then call _ErrorDataFileNotFound 'upcase table files not present.' | 
|---|
| 146 |  | 
|---|
| 147 | /* the password files - we'll create them if they don't exist */ | 
|---|
| 148 | samba.!masterpasswd = unixetc'\master.passwd' | 
|---|
| 149 | if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!' | 
|---|
| 150 | IF options.!debug == 1 then say '  master.passwd  = "'samba.!masterpasswd'"' | 
|---|
| 151 |  | 
|---|
| 152 | samba.!pwddb = unixetc'\pwd.db' | 
|---|
| 153 | if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!' | 
|---|
| 154 | IF options.!debug == 1 then say '  pwd.db         = "'samba.!pwddb'"' | 
|---|
| 155 |  | 
|---|
| 156 | samba.!spwddb = unixetc'\spwd.db' | 
|---|
| 157 | if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!' | 
|---|
| 158 | IF options.!debug == 1 then say '  spwd.db        = "'samba.!spwddb'"' | 
|---|
| 159 |  | 
|---|
| 160 | samba.!group = unixetc'\group' | 
|---|
| 161 | if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!' | 
|---|
| 162 | IF options.!debug == 1 then say '  group          = "'samba.!group'"' | 
|---|
| 163 |  | 
|---|
| 164 | samba.!printcap = unixetc'\printcap' | 
|---|
| 165 | if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!' | 
|---|
| 166 | IF options.!debug == 1 then say '  printcap       = "'samba.!printcap'"' | 
|---|
| 167 |  | 
|---|
| 168 | /* Create these directories to make sure they do exist */ | 
|---|
| 169 | ok = SysMkDir(unixetc) | 
|---|
| 170 | ok = SysMkDir(etc'\samba') | 
|---|
| 171 | ok = SysMkDir(etc'\samba\pid') | 
|---|
| 172 | ok = SysMkDir(etc'\samba\lock') | 
|---|
| 173 | /* This EA makes the testparm warning about browsing go away. */ | 
|---|
| 174 | /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */ | 
|---|
| 175 | ok = SysPutEA(etc||'\samba\lock',"MODE", "FEFF0400ED410000"x) | 
|---|
| 176 |  | 
|---|
| 177 | /* Messages from Samba will go here */ | 
|---|
| 178 | samba.!error = SysTempFileName(TempDir'smb_err.???') | 
|---|
| 179 | IF options.!debug == 1 THEN say '  samba.!error   = "'samba.!error'"' | 
|---|
| 180 | samba.!msg   = SysTempFileName(TempDir'smb_msg.???') | 
|---|
| 181 | IF options.!debug == 1 THEN say '  samba.!msg     = "'samba.!msg'"' | 
|---|
| 182 | /* Use of this file is deprecated */ | 
|---|
| 183 | ErrorFile  = Tempdir'smbutil.error' | 
|---|
| 184 |  | 
|---|
| 185 | IF options.!debug == 1 then do | 
|---|
| 186 | if ErrorState then say "  One or more  basic Samba Client setup errors detected!" | 
|---|
| 187 | else say "  No basic Samba Client setup errors detected!" | 
|---|
| 188 | end | 
|---|
| 189 | IF options.!debug == 1 THEN say time()' _CltInit() done, Errorstate = 'Errorstate | 
|---|
| 190 | return | 
|---|
| 191 |  | 
|---|
| 192 | /*:VRX */ | 
|---|
| 193 | _SambaFinish: | 
|---|
| 194 | /* Do some basic housekeeping when leaving */ | 
|---|
| 195 | ok = SysFileTree(TempDir'smb_???.???', garbage., 'FO') | 
|---|
| 196 | do I = 1 to garbage.0 | 
|---|
| 197 | ok = stream(garbage.I,'c','close') | 
|---|
| 198 | ok = SysFileDelete(garbage.I) | 
|---|
| 199 | end | 
|---|
| 200 | return | 
|---|
| 201 |  | 
|---|
| 202 | /*:VRX */ | 
|---|
| 203 | _ErrorBinaryNotFound: | 
|---|
| 204 | /* Set error status variable and show a short message - incomplete! */ | 
|---|
| 205 | msg = arg(1) | 
|---|
| 206 | say "ERROR: "msg | 
|---|
| 207 | id = VRMessage( VRWindow(), msg, "Samba Client Installation", "E" ) | 
|---|
| 208 | ErrorState = (1|ErrorState) | 
|---|
| 209 | return | 
|---|
| 210 |  | 
|---|
| 211 | /*:VRX */ | 
|---|
| 212 | _ErrorDataFileNotFound: | 
|---|
| 213 | /* Set error status variable and show a short message - incomplete! */ | 
|---|
| 214 | msg = arg(1) | 
|---|
| 215 | say "ERROR: "msg | 
|---|
| 216 | DataErrorState = (1|DataErrorState) | 
|---|
| 217 | return | 
|---|
| 218 |  | 
|---|
| 219 | /*:VRX */ | 
|---|
| 220 | _SambaExtendSearchPath: | 
|---|
| 221 | IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() started' | 
|---|
| 222 | /* Add binary and tools path to the PATH variable */ | 
|---|
| 223 | old_path = value('PATH',, 'OS2ENVIRONMENT') | 
|---|
| 224 | if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do | 
|---|
| 225 | if samba.!bin = samba.!tools then new_path = samba.!bin';' | 
|---|
| 226 | else new_path = samba.!bin';'samba.!tools';' | 
|---|
| 227 | ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT') | 
|---|
| 228 | drop new_path | 
|---|
| 229 | end | 
|---|
| 230 | drop old_path | 
|---|
| 231 |  | 
|---|
| 232 | /* Add binary and tools path to the BEGINLIBPATH variable */ | 
|---|
| 233 | old_beginlibpath = SysQueryExtLibPath("B") | 
|---|
| 234 | if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do | 
|---|
| 235 | if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath | 
|---|
| 236 | else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath | 
|---|
| 237 | ok = SysSetExtLibPath( new_beginlibpath, "B") | 
|---|
| 238 | drop new_beginlibpath | 
|---|
| 239 | end | 
|---|
| 240 | drop old_beginlibpath | 
|---|
| 241 |  | 
|---|
| 242 | /* Set LIBPATHSTRICT (this is an option - disabled by default) */ | 
|---|
| 243 | /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */ | 
|---|
| 244 |  | 
|---|
| 245 | IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() done' | 
|---|
| 246 | return | 
|---|