source: trunk/guitools/shared/sambainit.vrs

Last change on this file was 1055, checked in by Herwig Bauernfeind, 7 years ago

Unify debug formatting

File size: 18.3 KB
Line 
1/* Perform basic Samba init stuff */
2
3/* Samba Server 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
21/*:VRX */
22_SambaInit:
23 IF options.!debug == 1 then say time()' _SambaInit() started'
24 IF options.!debug == 1 then say ' Checking Samba setup...'
25
26 /* debuglevel when executing Samba binaries */
27 debuglevel = ' --debuglevel=0'
28
29 /* Error status and file variables */
30 ErrorState = 0 /* _ErrorBinaryNotFound() changes this variable */
31 DataErrorState = 0 /* _ErrorDataFileNotFound() changes this variable */
32
33 /* Evaluate environment */
34 ETC = value('ETC',,'OS2ENVIRONMENT')
35 IF options.!debug == 1 then say ' ETC = "'ETC'"'
36
37 UnixRoot = value("UNIXROOT",,'OS2ENVIRONMENT')
38 if UnixRoot = "" then do
39 UnixRoot = left(ETC,length(ETC)-4)
40 say ' WARNING! Setting missing UNIXROOT variable to "'UnixRoot'".'
41 ok = value("UNIXROOT",UnixRoot,'OS2ENVIRONMENT')
42 end
43
44 IF options.!debug == 1 then say ' UnixRoot = "'UnixRoot'"'
45
46 unixetc = UnixRoot'\etc'
47 IF options.!debug == 1 then say ' Unixetc = "'unixetc'"'
48
49 /* Find all executables */
50
51 /* Get the path to this file */
52 samba.!tools = VRParseFilename(VRGet("Application", "Program"),'DP')
53 if samba.!tools = '' then do
54 parse source . . script
55 samba.!tools = VRParseFilename(script,'DP')
56 end
57 IF options.!debug == 1 then say ' Samba tools = "'samba.!tools'"'
58 say ' Changing into "'directory(samba.!tools)'"'
59
60 /* smbd.exe */
61 samba.!smbd = ""
62 if samba.!smbd = "" then do /* USER\Samba\ServerPath */
63 call charout , " Is Samba ServerPath stored in OS2.INI? "
64 samba.!bin = strip(VRGetIni( "Samba", "ServerPath2", "USER" ),'T','00'x)
65 if samba.!bin <> "" then do
66 say 'Yes, found "'samba.!bin'"'
67 if VRFileExists(samba.!bin"\smbd.exe") then do
68 samba.!smbd = samba.!bin"\smbd.exe"
69 say ' Found "'samba.!smbd'".'
70 end
71 end
72 else say 'No, possibly manual installation.'
73 end
74 if samba.!smbd = "" then do /* wellknown locations */
75 WellKnown = SysBootdrive()"\ecs\system\samba;"SysBootdrive()"\samba"
76 Programs = value("PROGRAMS",,'OS2ENVIRONMENT')
77 if Programs <> "" then WellKnown = Wellknown';'Programs'\samba'
78 Tools = value("TOOLS",,'OS2ENVIRONMENT')
79 if Tools <> "" then WellKnown = Wellknown';'Tools'\samba'
80 call charout , " Are binaries in wellknown locations? "
81 ok = VRFindFile("smbd.exe",WellKnown)
82 if ok <> "" then say "Yes."; else say "No."
83 if ok <> "" then samba.!smbd = ok
84 drop Wellknown Tools Programs
85 end
86 if samba.!smbd = "" then do /* in current directory? */
87 call charout , " Are binaries in current directory? "
88 ok = SysFileTree('.\smbd.exe', exist.,'FO')
89 if exist.0 = 1 then say "Yes."; else say "No."
90 if exist.0 = 1 then samba.!smbd = exist.1
91 end
92 if samba.!smbd = "" then do /* RPM/YUM/FHS tree */
93 call charout , " Are binaries in RPM/YUM/FHS tree? "
94 ok = SysFileTree(UnixRoot'\usr\bin\smbd.exe', exist.,'FO')
95 if exist.0 = 1 then say "Yes."; else say "No."
96 if exist.0 = 1 then samba.!smbd = exist.1
97 end
98 if samba.!smbd = "" then do /* in parent directory? */
99 call charout , " Are binaries in parent directory? "
100 ok = SysFileTree('..\smbd.exe', exist.,'FO')
101 if exist.0 = 1 then say "Yes."; else say "No."
102 if exist.0 = 1 then samba.!smbd = exist.1
103 end
104 if samba.!smbd = "" then do /* in ..\BIN directory? */
105 call charout , " Are binaries in ..\BIN directory? "
106 ok = SysFileTree('..\bin\smbd.exe', exist.,'FO')
107 if exist.0 = 1 then say "Yes."; else say "No."
108 if exist.0 = 1 then samba.!smbd = exist.1
109 end
110 if samba.!smbd = "" then do /* in SMB_EXE ? */
111 call charout , " Are binaries in SMB_EXE path? "
112 samba.!smbd = SysSearchPath("SMB_EXE","SMBD.EXE")
113 if samba.!smbd = "" then say "No."; else say "Yes."
114 end
115 if samba.!smbd = "" then do /* in PATH ? */
116 call charout , " Are binaries in PATH? "
117 samba.!smbd = SysSearchPath("PATH","SMBD.EXE")
118 if samba.!smbd = "" then say "No."; else say "Yes."
119 end
120
121 if samba.!smbd = "" then call _ErrorBinaryNotFound 'Could not find "\smbd.exe"!'
122
123 samba.!bin = VRParseFileName(samba.!smbd,'DP')
124 IF options.!debug == 1 then say ' Samba binaries = "'samba.!bin'"'
125 IF options.!debug == 1 then say ' Samba smbd.exe = "'samba.!smbd'"'
126
127 /* smb.cmd */
128 samba.!smbcmd = samba.!tools'\smb.cmd'
129 if \VRFileExists(samba.!smbcmd) then do
130 samba.!smbcmd = samba.!bin'\smb.cmd'
131 if \VRFileExists(samba.!smbcmd) then call _ErrorBinaryNotFound 'Could not find "\smb.cmd"!'
132 end
133 IF options.!debug == 1 then say ' smb.cmd = "'samba.!smbcmd'"'
134
135 /* smbpasswd.exe */
136 samba.!smbpasswdexe = samba.!bin'\smbpasswd.exe'
137 if \VRFileExists(samba.!smbpasswdexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbpasswdexe'"!'
138 IF options.!debug == 1 then say ' smbpasswd.exe = "'samba.!smbpasswdexe'"'
139
140 /* pdbedit.exe */
141 samba.!pdbeditexe = samba.!bin'\pdbedit.exe'
142 if \VRFileExists(samba.!pdbeditexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!pdbeditexe'"!'
143 IF options.!debug == 1 then say ' pdbedit.exe = "'samba.!pdbeditexe'"'
144
145 /* net.exe */
146 samba.!netexe = samba.!bin'\net.exe'
147 if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!netexe'"!'
148 IF options.!debug == 1 then say ' net.exe = "'samba.!netexe'"'
149
150 /* testparm.exe */
151 samba.!testparmexe = samba.!bin'\testparm.exe'
152 if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!testparmexe'"!'
153 IF options.!debug == 1 then say ' testparm.exe = "'samba.!testparmexe'"'
154
155 /* smbtree.exe */
156 samba.!smbtreeexe = samba.!bin'\smbtree.exe'
157 if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbtreeexe'"!'
158 IF options.!debug == 1 then say ' smbtree.exe = "'samba.!smbtreeexe'"'
159
160 /* smbstatus.exe */
161 samba.!smbstatusexe = samba.!bin'\smbstatus.exe'
162 if \VRFileExists(samba.!smbstatusexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbstatusexe'"!'
163 IF options.!debug == 1 then say ' smbstatus.exe = "'samba.!smbstatusexe'"'
164
165 /* smbcontrol.exe */
166 samba.!smbcontrolexe = samba.!bin'\smbcontrol.exe'
167 if \VRFileExists(samba.!smbcontrolexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbcontrolexe'"!'
168 IF options.!debug == 1 then say ' smbcontrol.exe = "'samba.!smbcontrolexe'"'
169
170 /* smbclient.exe */
171 samba.!smbclientexe = samba.!bin'\smbclient.exe'
172 if \VRFileExists(samba.!smbclientexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbclientexe'"!'
173 IF options.!debug == 1 then say ' smbclient.exe = "'samba.!smbclientexe'"'
174
175 /* nmblookup.exe */
176 samba.!nmblookupexe = samba.!bin'\nmblookup.exe'
177 if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!nmblookupexe'"!'
178 IF options.!debug == 1 then say ' nmblookup.exe = "'samba.!nmblookupexe'"'
179
180 /* smbspool.exe */
181 samba.!smbspoolexe = samba.!bin'\smbspool.exe'
182 if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound 'Could not find "\smbspool.exe"!'
183 IF options.!debug == 1 THEN say ' smbspool.exe = "'samba.!smbspoolexe'"'
184
185 /* rpcclient.exe */
186 samba.!rpcclientexe = samba.!bin'\rpcclient.exe'
187 if \VRFileExists(samba.!rpcclientexe) then call _ErrorBinaryNotFound 'Could not find "\rpcclient.exe"!'
188 IF options.!debug == 1 THEN say ' rpcclient.exe = "'samba.!rpcclientexe'"'
189
190 /* smbcacls.exe */
191 samba.!smbcaclsexe = samba.!bin'\smbcacls.exe'
192 if \VRFileExists(samba.!smbcaclsexe) then call _ErrorBinaryNotFound 'Could not find "\smbcacls.exe"!'
193 IF options.!debug == 1 THEN say ' smbcacls.exe = "'samba.!smbcaclsexe'"'
194
195 /* pwd_mkdb */
196 samba.!pwd_mkdb = SysSearchPath("PATH","pwd_mkdb.exe")
197 if samba.!pwd_mkdb = "" then do /* in current directory? */
198 ok = SysFileTree('.\pwd_mkdb.exe', exist.,'FO')
199 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
200 end
201 if samba.!pwd_mkdb = "" then do /* in usr/sbin directory? */
202 ok = SysFileTree(UnixRoot'\usr\sbin\pwd_mkdb.exe', exist.,'FO')
203 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
204 end
205 if samba.!pwd_mkdb = "" then do /* tools directory? */
206 ok = SysFileTree(samba.!tools'\pwd_mkdb.exe', exist.,'FO')
207 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
208 end
209 if samba.!pwd_mkdb = "" then do /* in smbd directory? */
210 ok = SysFileTree(samba.!bin'\pwd_mkdb.exe', exist.,'FO')
211 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
212 end
213 if samba.!pwd_mkdb = "" then do /* in SMB_SBIN ? */
214 samba.!pwd_mkdb = SysSearchPath("SMB_SBIN","pwd_mkdb.exe")
215 end
216
217 if samba.!pwd_mkdb = "" then call _ErrorBinaryNotFound 'Could not find "'samba.!pwd_mkdb'"!'
218 IF options.!debug == 1 then say ' pwd_mkdb.exe = "'samba.!pwd_mkdb'"'
219
220 /* logfiles */
221 samba.!log = value('SMB_LOGS',,'OS2ENVIRONMENT')
222 if samba.!log = "" then do /* new default */
223 ok = SysFileTree(etc'\samba\log',exist.,'DO')
224 if exist.0 > 0 then samba.!log = etc'\samba\log'
225 end
226 if samba.!log = "" then do /* old default */
227 ok = SysFileTree(samba.!bin'\logs\log.smbd*',exist.,'FO')
228 if exist.0 > 0 then samba.!log = samba.!bin'\logs'
229 end
230 if samba.!log = "" then do /* LOGFILES */
231 samba.!log = value('LOGFILES',,'OS2ENVIRONMENT')
232 end
233
234 if samba.!log = "" then call _ErrorDataFileNotFound 'Could not find logfiles!'
235 IF options.!debug == 1 then say ' Samba logfiles = "'samba.!log'"'
236
237 /* smb.conf */
238 samba.!smbconf = ETC'\samba\smb.conf'
239 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
240 IF options.!debug == 1 then say ' Samba smb.conf = "'samba.!smbconf'"'
241
242 /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */
243 /* before reading from it */
244 samba.!shadowsmbconf = TempDir||'smb.conf'
245
246 /* find all datafiles - their locations are fixed */
247
248 /* the password files - we'll create them if they don't exist */
249 samba.!masterpasswd = unixetc'\master.passwd'
250 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!'
251 IF options.!debug == 1 then say ' master.passwd = "'samba.!masterpasswd'"'
252
253 samba.!pwddb = unixetc'\pwd.db'
254 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!'
255 IF options.!debug == 1 then say ' pwd.db = "'samba.!pwddb'"'
256
257 samba.!spwddb = unixetc'\spwd.db'
258 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!'
259 IF options.!debug == 1 then say ' spwd.db = "'samba.!spwddb'"'
260
261 samba.!group = unixetc'\group'
262 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!'
263 IF options.!debug == 1 then say ' group = "'samba.!group'"'
264
265 samba.!printcap = unixetc'\printcap'
266 if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!'
267 IF options.!debug == 1 then say ' printcap = "'samba.!printcap'"'
268
269 /* Create these directories to make sure they do exist */
270 ok = SysMkDir(unixetc)
271 ok = SysMkDir(etc'\samba')
272 ok = SysMkDir(etc'\samba\private')
273 ok = SysMkDir(etc'\samba\pid')
274 ok = SysMkDir(etc'\samba\log')
275 ok = SysMkDir(etc'\samba\lock')
276 ok = SysMkDir(etc'\samba\spool')
277 ok = SysMkDir(etc'\samba\drivers')
278 /* This EA makes the testparm warning about browsing go away. */
279 /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */
280 ok = SysPutEA(ETC||'\samba\lock',"MODE", "FEFF0400ED410000"x)
281
282 /* use temporary smbpasswd created by pdbedit */
283 samba.!smbpasswd = TempDir'smbpasswd'
284 IF options.!debug == 1 then say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
285
286 /* Check if winbindd daemon exists */
287 HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
288
289 /* Do we have a minimum of free temporary space? */
290 if _ChkTempFreeSpace < 262144 then call _ErrorDataFileNotFound 'Free space on "'TempDir'" exhausted!'
291
292 /* Messages from Samba will go here */
293 samba.!error = SysTempFileName(TempDir'smb_err.???')
294 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
295 /* Use of this file is deprecated */
296 ErrorFile = Tempdir'smbutil.error'
297
298 IF options.!debug == 1 then do
299 if ErrorState then say " One or more basic Samba setup errors detected!"
300 else say " No basic Samba setup errors detected!"
301 end
302 IF options.!debug == 1 then say time()' _SambaInit() done, Errorstate = 'Errorstate
303return
304
305/*:VRX */
306_SambaFinish:
307 IF options.!debug == 1 then say time()' _SambaFinish() started.'
308 /* Do some very basic housekeeping when leaving */
309 ok = stream(samba.!msg,'c','close')
310 ok = stream(samba.!error,'c','close')
311 ok = SysFileDelete(samba.!msg)
312 ok = SysFileDelete(samba.!error)
313 IF options.!debug == 1 then say time()' _SambaFinish() done.'
314return
315
316/*:VRX */
317_ErrorBinaryNotFound:
318 IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() started.'
319 /* Set error status variable and show a short message - incomplete! */
320 msg = arg(1)
321 say "ERROR: "msg
322 id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
323 ErrorState = (1|ErrorState)
324 IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() done, Errorstate = 'Errorstate
325return
326
327/*:VRX */
328_ErrorDataFileNotFound:
329 IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() started.'
330 /* Set error status variable and show a short message - incomplete! */
331 msg = arg(1)
332 say "ERROR: "msg
333 DataErrorState = (1|DataErrorState)
334 IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() done, Errorstate = 'Errorstate
335return
336
337/*:VRX */
338_SambaExtendSearchPath:
339 IF options.!debug == 1 then say time()' _SambaExtendSearchPath() started'
340 /* Add binary and tools path to the PATH variable */
341 old_path = value('PATH',, 'OS2ENVIRONMENT')
342 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
343 if samba.!bin = samba.!tools then new_path = samba.!bin';'
344 else new_path = samba.!bin';'samba.!tools';'
345 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
346 drop new_path
347 end
348 drop old_path
349
350 /* Add binary and tools path to the DPATH variable */
351 old_dpath = value('DPATH',, 'OS2ENVIRONMENT')
352 if pos(translate(samba.!bin';'),translate(old_dpath)) = 0 then do
353 if samba.!bin = samba.!tools then new_dpath = samba.!bin';'
354 else new_dpath = samba.!bin';'samba.!tools';'
355 ok = value('DPATH', new_dpath || old_dpath, 'OS2ENVIRONMENT')
356 drop new_dpath
357 end
358 drop old_dpath
359
360 /* Add binary and tools path to the BEGINLIBPATH variable */
361 old_beginlibpath = SysQueryExtLibPath("B")
362 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
363 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
364 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
365 ok = SysSetExtLibPath( new_beginlibpath, "B")
366 drop new_beginlibpath
367 end
368 drop old_beginlibpath
369
370 /* Set LIBPATHSTRICT (this is an option - disabled by default) */
371 /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
372
373 IF options.!debug == 1 then say time()' _SambaExtendSearchPath() done'
374return
375
376/*:VRX */
377_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options. samba.
378 IF options.!debug == 1 then say time()' _SambaRunning() started'
379
380 /* Checks whether any Samba daemon is currently running */
381
382 /* Parameters: none or "ALL"
383
384 Returns: 1 = at least one Samba daemon is running
385 1 = Parameter "ALL" all Samba daemons are running
386 0 = no Samba daemon is running
387 0 = Parameter "ALL" not all Samba daemons are running
388
389 Stems: running. stores which daemon is running
390 pids. stores pids of running daemons
391 */
392 restype = arg(1)
393 running. = 0
394 pids. = ""
395
396 ok = PRProcessList(proc)
397
398 do I = 1 to proc.0
399 CurProc = VRParseFileName(proc.i.name,'NE')
400 if CurProc = "SMBD.EXE" then do
401 running.!smbd = 1
402 pids.!smbd = pids.!smbd||proc.i.pid||' '
403 end
404 if CurProc = "NMBD.EXE" then do
405 running.!nmbd = 1
406 pids.!nmbd = pids.!nmbd||proc.i.pid||' '
407 end
408 if CurProc = "WINBINDD.EXE" then do
409 running.!winb = 1
410 pids.!winb = pids.!winb||proc.i.pid||' '
411 end
412 end
413
414 if restype = "ALL" then do
415 runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
416 end
417 else do
418 runres = (running.!smbd | running.!nmbd |running.!winb)
419 end
420 IF options.!debug == 1 then say time()' _SambaRunning() done'
421return runres
Note: See TracBrowser for help on using the repository browser.