source: trunk/guitools/shared/cltinit.vrs@ 1023

Last change on this file since 1023 was 1023, checked in by Herwig Bauernfeind, 8 years ago

GUITools: Add GPLv3 header to all .VRS files

File size: 11.8 KB
Line 
1/* Perform basic Samba Client init stuff */
2
3/* Samba Client Initialization
4Copyright (C) 2007-2017 Herwig Bauernfeind for bww bitwise works GmbH.
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/*:VRX */
21_CltInit:
22 IF options.!debug == 1 THEN say time()' _CltInit() started'
23 IF options.!debug == 1 THEN say ' Checking Samba Client setup...'
24
25 /* debuglevel when executing Samba binaries */
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
42
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 */
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"
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
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
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
113 if samba.!smbclientexe = "" then call _ErrorBinaryNotFound " could not find smbclient.exe!"
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'
120 if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!"
121 IF options.!debug == 1 THEN say ' net.exe = "'samba.!netexe'"'
122
123 /* testparm.exe */
124 samba.!testparmexe = samba.!bin'\testparm.exe'
125 if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!"
126 IF options.!debug == 1 THEN say ' testparm.exe = "'samba.!testparmexe'"'
127
128 /* smbtree.exe */
129 samba.!smbtreeexe = samba.!bin'\smbtree.exe'
130 if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!"
131 IF options.!debug == 1 THEN say ' smbtree.exe = "'samba.!smbtreeexe'"'
132
133 /* nmblookup.exe */
134 samba.!nmblookupexe = samba.!bin'\nmblookup.exe'
135 if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound " could not find nmblookup.exe!"
136 IF options.!debug == 1 THEN say ' nmblookup.exe = "'samba.!nmblookupexe'"'
137
138 /* smbspool.exe */
139 samba.!smbspoolexe = samba.!bin'\smbspool.exe'
140 if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound " could not find smbspool.exe!"
141 IF options.!debug == 1 THEN say ' smbspool.exe = "'samba.!smbspoolexe'"'
142
143 /* rpcclient.exe */
144 samba.!rpcclientexe = samba.!bin'\rpcclient.exe'
145 if \VRFileExists(samba.!rpcclientexe) then call _ErrorBinaryNotFound " could not find rpcclient.exe!"
146 IF options.!debug == 1 THEN say ' rpcclient.exe = "'samba.!rpcclientexe'"'
147
148 /* smb.conf */
149 samba.!smbconf = ETC'\samba\smb.conf'
150 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
151 IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"'
152
153 /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */
154 /* before reading from it */
155 samba.!shadowsmbconf = TempDir||'smb.conf'
156
157 /* lmhosts */
158 samba.!lmhosts = ETC'\samba\lmhosts'
159 if \VRFileExists(samba.!lmhosts) then call _ErrorDataFileNotFound samba.!lmhosts' is not present.'
160 IF options.!debug == 1 THEN say ' Samba lmhosts = "'samba.!lmhosts'"'
161
162 /* FIXME: Needs to be changed for Samba 3.3+ */
163 /* upcase table files - several utilities need these */
164 if (\VRFileExists(samba.!bin'\lib\upcase.dat')) |,
165 (\VRFileExists(samba.!bin'\lib\lowcase.dat')) |,
166 (\VRFileExists(samba.!bin'\lib\valid.dat')) then call _ErrorDataFileNotFound 'upcase table files not present.'
167
168 /* the password files - we'll create them if they don't exist */
169 samba.!masterpasswd = unixetc'\master.passwd'
170 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!'
171 IF options.!debug == 1 then say ' master.passwd = "'samba.!masterpasswd'"'
172
173 samba.!pwddb = unixetc'\pwd.db'
174 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!'
175 IF options.!debug == 1 then say ' pwd.db = "'samba.!pwddb'"'
176
177 samba.!spwddb = unixetc'\spwd.db'
178 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!'
179 IF options.!debug == 1 then say ' spwd.db = "'samba.!spwddb'"'
180
181 samba.!group = unixetc'\group'
182 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!'
183 IF options.!debug == 1 then say ' group = "'samba.!group'"'
184
185 samba.!printcap = unixetc'\printcap'
186 if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!'
187 IF options.!debug == 1 then say ' printcap = "'samba.!printcap'"'
188
189 /* Create these directories to make sure they do exist */
190 ok = SysMkDir(unixetc)
191 ok = SysMkDir(etc'\samba')
192 ok = SysMkDir(etc'\samba\pid')
193 ok = SysMkDir(etc'\samba\lock')
194 /* This EA makes the testparm warning about browsing go away. */
195 /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */
196 ok = SysPutEA(etc||'\samba\lock',"MODE", "FEFF0400ED410000"x)
197
198 /* Messages from Samba will go here */
199 samba.!error = SysTempFileName(TempDir'smb_err.???')
200 IF options.!debug == 1 THEN say ' samba.!error = "'samba.!error'"'
201 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
202 IF options.!debug == 1 THEN say ' samba.!msg = "'samba.!msg'"'
203 /* Use of this file is deprecated */
204 ErrorFile = Tempdir'smbutil.error'
205
206 IF options.!debug == 1 then do
207 if ErrorState then say " One or more basic Samba Client setup errors detected!"
208 else say " No basic Samba Client setup errors detected!"
209 end
210 IF options.!debug == 1 THEN say time()' _CltInit() done, Errorstate = 'Errorstate
211return
212
213/*:VRX */
214_SambaFinish:
215 /* Do some basic housekeeping when leaving */
216 ok = SysFileTree(TempDir'smb_???.???', garbage., 'FO')
217 do I = 1 to garbage.0
218 ok = stream(garbage.I,'c','close')
219 ok = SysFileDelete(garbage.I)
220 end
221return
222
223/*:VRX */
224_ErrorBinaryNotFound:
225 /* Set error status variable and show a short message - incomplete! */
226 msg = arg(1)
227 say "ERROR: "msg
228 id = VRMessage( VRWindow(), msg, "Samba Client Installation", "E" )
229 ErrorState = (1|ErrorState)
230return
231
232/*:VRX */
233_ErrorDataFileNotFound:
234 /* Set error status variable and show a short message - incomplete! */
235 msg = arg(1)
236 say "ERROR: "msg
237 DataErrorState = (1|DataErrorState)
238return
239
240/*:VRX */
241_SambaExtendSearchPath:
242 IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() started'
243 /* Add binary and tools path to the PATH variable */
244 old_path = value('PATH',, 'OS2ENVIRONMENT')
245 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
246 if samba.!bin = samba.!tools then new_path = samba.!bin';'
247 else new_path = samba.!bin';'samba.!tools';'
248 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
249 drop new_path
250 end
251 drop old_path
252
253 /* Add binary and tools path to the BEGINLIBPATH variable */
254 old_beginlibpath = SysQueryExtLibPath("B")
255 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
256 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
257 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
258 ok = SysSetExtLibPath( new_beginlibpath, "B")
259 drop new_beginlibpath
260 end
261 drop old_beginlibpath
262
263 /* Set LIBPATHSTRICT (this is an option - disabled by default) */
264 /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
265
266 IF options.!debug == 1 THEN say time()' _SambaExtendSearchPath() done'
267return
Note: See TracBrowser for help on using the repository browser.