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