| 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 "'directory(samba.!tools)'"'
|
|---|
| 41 |
|
|---|
| 42 | /* smbclient.exe */
|
|---|
| 43 | samba.!smbclientexe = ""
|
|---|
| 44 | if samba.!smbclientexe = "" then do /* in current directory? */
|
|---|
| 45 | call charout , " Are binaries in current directory? "
|
|---|
| 46 | ok = SysFileTree('.\smbclient.exe', exist.,'FO')
|
|---|
| 47 | say exist.0' (1 = Yes, 0 = No)'
|
|---|
| 48 | if exist.0 = 1 then samba.!smbclientexe = exist.1
|
|---|
| 49 | end
|
|---|
| 50 | if samba.!smbclientexe = "" then do /* in parent directory? */
|
|---|
| 51 | call charout , " Are binaries in parent directory? "
|
|---|
| 52 | ok = SysFileTree('..\smbclient.exe', exist.,'FO')
|
|---|
| 53 | say exist.0' (1 = Yes, 0 = No)'
|
|---|
| 54 | if exist.0 = 1 then samba.!smbclientexe = exist.1
|
|---|
| 55 | end
|
|---|
| 56 | if samba.!smbclientexe = "" then do /* in ..\BIN directory? */
|
|---|
| 57 | call charout , " Are binaries in ..\BIN directory? "
|
|---|
| 58 | ok = SysFileTree('..\bin\smbclient.exe', exist.,'FO')
|
|---|
| 59 | say exist.0' (1 = Yes, 0 = No)'
|
|---|
| 60 | if exist.0 = 1 then samba.!smbclientexe = exist.1
|
|---|
| 61 | end
|
|---|
| 62 | if samba.!smbclientexe = "" then do /* in SMB_EXE ? */
|
|---|
| 63 | call charout , " Are binaries in SMB_EXE path? "
|
|---|
| 64 | samba.!smbclientexe = SysSearchPath("SMB_EXE","smbclient.EXE")
|
|---|
| 65 | if samba.!smbclientexe = "" then say "No."; else say "Yes."
|
|---|
| 66 | end
|
|---|
| 67 | if samba.!smbclientexe = "" then do /* in PATH ? */
|
|---|
| 68 | call charout , " Are binaries in PATH? "
|
|---|
| 69 | samba.!smbclientexe = SysSearchPath("PATH","smbclient.EXE")
|
|---|
| 70 | if samba.!smbclientexe = "" then say "No."; else say "Yes."
|
|---|
| 71 | end
|
|---|
| 72 |
|
|---|
| 73 | if samba.!smbclientexe = "" then call _ErrorBinaryNotFound " could not find smbclient.exe!"
|
|---|
| 74 |
|
|---|
| 75 | samba.!bin = VRParseFileName(samba.!smbclientexe,'DP')
|
|---|
| 76 | IF options.!debug == 1 THEN say ' Samba binaries = "'samba.!bin'"'
|
|---|
| 77 |
|
|---|
| 78 | /* net.exe */
|
|---|
| 79 | samba.!netexe = samba.!bin'\net.exe'
|
|---|
| 80 | if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!"
|
|---|
| 81 | IF options.!debug == 1 THEN say ' net.exe = "'samba.!netexe'"'
|
|---|
| 82 |
|
|---|
| 83 | /* testparm.exe */
|
|---|
| 84 | samba.!testparmexe = samba.!bin'\testparm.exe'
|
|---|
| 85 | if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!"
|
|---|
| 86 | IF options.!debug == 1 THEN say ' testparm.exe = "'samba.!testparmexe'"'
|
|---|
| 87 |
|
|---|
| 88 | /* smbtree.exe */
|
|---|
| 89 | samba.!smbtreeexe = samba.!bin'\smbtree.exe'
|
|---|
| 90 | if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!"
|
|---|
| 91 | IF options.!debug == 1 THEN say ' smbtree.exe = "'samba.!smbtreeexe'"'
|
|---|
| 92 |
|
|---|
| 93 | /* nmblookup.exe */
|
|---|
| 94 | samba.!nmblookupexe = samba.!bin'\nmblookup.exe'
|
|---|
| 95 | if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound " could not find nmblookup.exe!"
|
|---|
| 96 | IF options.!debug == 1 THEN say ' nmblookup.exe = "'samba.!nmblookupexe'"'
|
|---|
| 97 |
|
|---|
| 98 | /* smbspool.exe */
|
|---|
| 99 | samba.!smbspoolexe = samba.!bin'\smbspool.exe'
|
|---|
| 100 | if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound " could not find smbspool.exe!"
|
|---|
| 101 | IF options.!debug == 1 THEN say ' smbspool.exe = "'samba.!smbspoolexe'"'
|
|---|
| 102 |
|
|---|
| 103 | /* smb.conf */
|
|---|
| 104 | samba.!smbconf = ETC'\samba\smb.conf'
|
|---|
| 105 | if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
|
|---|
| 106 | IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"'
|
|---|
| 107 |
|
|---|
| 108 | /* upcase table files - several utilities need these */
|
|---|
| 109 | if (\VRFileExists(samba.!bin'\lib\upcase.dat')) |,
|
|---|
| 110 | (\VRFileExists(samba.!bin'\lib\lowcase.dat')) |,
|
|---|
| 111 | (\VRFileExists(samba.!bin'\lib\valid.dat')) then call _ErrorDataFileNotFound 'upcase table files not present.'
|
|---|
| 112 |
|
|---|
| 113 | /* Create these directories to make sure they do exist */
|
|---|
| 114 | ok = SysMkDir(unixetc)
|
|---|
| 115 | ok = SysMkDir(etc'\samba')
|
|---|
| 116 | ok = SysMkDir(etc'\samba\lock')
|
|---|
| 117 |
|
|---|
| 118 | /* Messages from Samba will go here */
|
|---|
| 119 | samba.!error = SysTempFileName(TempDir'smb_err.???')
|
|---|
| 120 | IF options.!debug == 1 THEN say ' samba.!error = "'samba.!error'"'
|
|---|
| 121 | samba.!msg = SysTempFileName(TempDir'smb_msg.???')
|
|---|
| 122 | IF options.!debug == 1 THEN say ' samba.!msg = "'samba.!error'"'
|
|---|
| 123 | /* Use of this file is deprecated */
|
|---|
| 124 | ErrorFile = Tempdir'smbutil.error'
|
|---|
| 125 |
|
|---|
| 126 | IF options.!debug == 1 then do
|
|---|
| 127 | if ErrorState then say " One or more basic Samba Client setup errors detected!"
|
|---|
| 128 | else say " No basic Samba Client setup errors detected!"
|
|---|
| 129 | end
|
|---|
| 130 | IF options.!debug == 1 THEN say time()' _CltInit() done, Errorstate = 'Errorstate
|
|---|
| 131 | return
|
|---|
| 132 |
|
|---|
| 133 | /*:VRX */
|
|---|
| 134 | _SambaFinish:
|
|---|
| 135 | /* Do some basic housekeeping when leaving */
|
|---|
| 136 | ok = SysFileTree(TempDir'smb_???.???', garbage., 'FO')
|
|---|
| 137 | do I = 1 to garbage.0
|
|---|
| 138 | ok = stream(garbage.I,'c','close')
|
|---|
| 139 | ok = SysFileDelete(garbage.I)
|
|---|
| 140 | end
|
|---|
| 141 | return
|
|---|
| 142 |
|
|---|
| 143 | /*:VRX */
|
|---|
| 144 | _ErrorBinaryNotFound:
|
|---|
| 145 | /* Set error status variable and show a short message - incomplete! */
|
|---|
| 146 | msg = arg(1)
|
|---|
| 147 | say "ERROR: "msg
|
|---|
| 148 | id = VRMessage( VRWindow(), msg, "Samba Client Installation", "E" )
|
|---|
| 149 | ErrorState = (1|ErrorState)
|
|---|
| 150 | return
|
|---|
| 151 |
|
|---|
| 152 | /*:VRX */
|
|---|
| 153 | _ErrorDataFileNotFound:
|
|---|
| 154 | /* Set error status variable and show a short message - incomplete! */
|
|---|
| 155 | msg = arg(1)
|
|---|
| 156 | say "ERROR: "msg
|
|---|
| 157 | DataErrorState = (1|DataErrorState)
|
|---|
| 158 | return
|
|---|
| 159 |
|
|---|
| 160 | /*:VRX */
|
|---|
| 161 | _SambaExtendSearchPath:
|
|---|
| 162 | IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() started'
|
|---|
| 163 | /* Add binary and tools path to the PATH variable */
|
|---|
| 164 | old_path = value('PATH',, 'OS2ENVIRONMENT')
|
|---|
| 165 | if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
|
|---|
| 166 | if samba.!bin = samba.!tools then new_path = samba.!bin';'
|
|---|
| 167 | else new_path = samba.!bin';'samba.!tools';'
|
|---|
| 168 | ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
|
|---|
| 169 | drop new_path
|
|---|
| 170 | end
|
|---|
| 171 | drop old_path
|
|---|
| 172 |
|
|---|
| 173 | /* Add binary and tools path to the BEGINLIBPATH variable */
|
|---|
| 174 | old_beginlibpath = SysQueryExtLibPath("B")
|
|---|
| 175 | if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
|
|---|
| 176 | if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
|
|---|
| 177 | else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
|
|---|
| 178 | ok = SysSetExtLibPath( new_beginlibpath, "B")
|
|---|
| 179 | drop new_beginlibpath
|
|---|
| 180 | end
|
|---|
| 181 | drop old_beginlibpath
|
|---|
| 182 |
|
|---|
| 183 | /* Set LIBPATHSTRICT (this is an option - disabled by default) */
|
|---|
| 184 | /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
|
|---|
| 185 |
|
|---|
| 186 | IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() done'
|
|---|
| 187 | return
|
|---|