source: trunk/guitools/shared/sambainit.vrs@ 1027

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

GUITools: Update CltInit and SambaInit in order to support ACLS browser

File size: 18.2 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
124 samba.!bin = VRParseFileName(samba.!smbd,'DP')
125 IF options.!debug == 1 then say ' Samba binaries = "'samba.!bin'"'
126 IF options.!debug == 1 then say ' Samba smbd.exe = "'samba.!smbd'"'
127
128 /* smb.cmd */
129 samba.!smbcmd = samba.!tools'\smb.cmd'
130 if \VRFileExists(samba.!smbcmd) then do
131 samba.!smbcmd = samba.!bin'\smb.cmd'
132 if \VRFileExists(samba.!smbcmd) then call _ErrorBinaryNotFound 'Could not find smb.cmd!'
133 end
134 IF options.!debug == 1 then say ' smb.cmd = "'samba.!smbcmd'"'
135
136 /* smbpasswd.exe */
137 samba.!smbpasswdexe = samba.!bin'\smbpasswd.exe'
138 if \VRFileExists(samba.!smbpasswdexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbpasswdexe'"!'
139 IF options.!debug == 1 then say ' smbpasswd.exe = "'samba.!smbpasswdexe'"'
140
141 /* pdbedit.exe */
142 samba.!pdbeditexe = samba.!bin'\pdbedit.exe'
143 if \VRFileExists(samba.!pdbeditexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!pdbeditexe'"!'
144 IF options.!debug == 1 then say ' pdbedit.exe = "'samba.!pdbeditexe'"'
145
146 /* net.exe */
147 samba.!netexe = samba.!bin'\net.exe'
148 if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!netexe'"!'
149 IF options.!debug == 1 then say ' net.exe = "'samba.!netexe'"'
150
151 /* testparm.exe */
152 samba.!testparmexe = samba.!bin'\testparm.exe'
153 if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!testparmexe'"!'
154 IF options.!debug == 1 then say ' testparm.exe = "'samba.!testparmexe'"'
155
156 /* smbtree.exe */
157 samba.!smbtreeexe = samba.!bin'\smbtree.exe'
158 if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbtreeexe'"!'
159 IF options.!debug == 1 then say ' smbtree.exe = "'samba.!smbtreeexe'"'
160
161 /* smbstatus.exe */
162 samba.!smbstatusexe = samba.!bin'\smbstatus.exe'
163 if \VRFileExists(samba.!smbstatusexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbstatusexe'"!'
164 IF options.!debug == 1 then say ' smbstatus.exe = "'samba.!smbstatusexe'"'
165
166 /* smbcontrol.exe */
167 samba.!smbcontrolexe = samba.!bin'\smbcontrol.exe'
168 if \VRFileExists(samba.!smbcontrolexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbcontrolexe'"!'
169 IF options.!debug == 1 then say ' smbcontrol.exe = "'samba.!smbcontrolexe'"'
170
171 /* smbclient.exe */
172 samba.!smbclientexe = samba.!bin'\smbclient.exe'
173 if \VRFileExists(samba.!smbclientexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!smbclientexe'"!'
174 IF options.!debug == 1 then say ' smbclient.exe = "'samba.!smbclientexe'"'
175
176 /* nmblookup.exe */
177 samba.!nmblookupexe = samba.!bin'\nmblookup.exe'
178 if \VRFileExists(samba.!nmblookupexe) then call _ErrorBinaryNotFound 'Could not find "'samba.!nmblookupexe'"!'
179 IF options.!debug == 1 then say ' nmblookup.exe = "'samba.!nmblookupexe'"'
180
181 /* smbspool.exe */
182 samba.!smbspoolexe = samba.!bin'\smbspool.exe'
183 if \VRFileExists(samba.!smbspoolexe) then call _ErrorBinaryNotFound " could not find smbspool.exe!"
184 IF options.!debug == 1 THEN say ' smbspool.exe = "'samba.!smbspoolexe'"'
185
186 /* rpcclient.exe */
187 samba.!rpcclientexe = samba.!bin'\rpcclient.exe'
188 if \VRFileExists(samba.!rpcclientexe) then call _ErrorBinaryNotFound " could not find rpcclient.exe!"
189 IF options.!debug == 1 THEN say ' rpcclient.exe = "'samba.!rpcclientexe'"'
190
191 /* smbcacls.exe */
192 samba.!smbcaclsexe = samba.!bin'\smbcacls.exe'
193 if \VRFileExists(samba.!smbcaclsexe) then call _ErrorBinaryNotFound " could not find smbcacls.exe!"
194 IF options.!debug == 1 THEN say ' smbcacls.exe = "'samba.!smbcaclsexe'"'
195
196 /* pwd_mkdb */
197 samba.!pwd_mkdb = SysSearchPath("PATH","pwd_mkdb.exe")
198 if samba.!pwd_mkdb = "" then do /* in current directory? */
199 ok = SysFileTree('.\pwd_mkdb.exe', exist.,'FO')
200 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
201 end
202 if samba.!pwd_mkdb = "" then do /* in usr/sbin directory? */
203 ok = SysFileTree(UnixRoot'\usr\sbin\pwd_mkdb.exe', exist.,'FO')
204 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
205 end
206 if samba.!pwd_mkdb = "" then do /* tools directory? */
207 ok = SysFileTree(samba.!tools'\pwd_mkdb.exe', exist.,'FO')
208 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
209 end
210 if samba.!pwd_mkdb = "" then do /* in smbd directory? */
211 ok = SysFileTree(samba.!bin'\pwd_mkdb.exe', exist.,'FO')
212 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
213 end
214 if samba.!pwd_mkdb = "" then do /* in SMB_SBIN ? */
215 samba.!pwd_mkdb = SysSearchPath("SMB_SBIN","pwd_mkdb.exe")
216 end
217
218 if samba.!pwd_mkdb = "" then call _ErrorBinaryNotFound 'Could not find "'samba.!pwd_mkdb'"!'
219 IF options.!debug == 1 then say ' pwd_mkdb.exe = "'samba.!pwd_mkdb'"'
220
221 /* logfiles */
222 samba.!log = value('SMB_LOGS',,'OS2ENVIRONMENT')
223 if samba.!log = "" then do /* new default */
224 ok = SysFileTree(etc'\samba\log',exist.,'DO')
225 if exist.0 > 0 then samba.!log = etc'\samba\log'
226 end
227 if samba.!log = "" then do /* old default */
228 ok = SysFileTree(samba.!bin'\logs\log.smbd*',exist.,'FO')
229 if exist.0 > 0 then samba.!log = samba.!bin'\logs'
230 end
231 if samba.!log = "" then do /* LOGFILES */
232 samba.!log = value('LOGFILES',,'OS2ENVIRONMENT')
233 end
234
235 if samba.!log = "" then call _ErrorDataFileNotFound 'Could not find logfiles!'
236 IF options.!debug == 1 then say ' Samba logfiles = "'samba.!log'"'
237
238 /* smb.conf */
239 samba.!smbconf = ETC'\samba\smb.conf'
240 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
241 IF options.!debug == 1 then say ' Samba smb.conf = "'samba.!smbconf'"'
242
243 /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */
244 /* before reading from it */
245 samba.!shadowsmbconf = TempDir||'smb.conf'
246
247 /* find all datafiles - their locations are fixed */
248
249 /* the password files - we'll create them if they don't exist */
250 samba.!masterpasswd = unixetc'\master.passwd'
251 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!'
252 IF options.!debug == 1 then say ' master.passwd = "'samba.!masterpasswd'"'
253
254 samba.!pwddb = unixetc'\pwd.db'
255 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!'
256 IF options.!debug == 1 then say ' pwd.db = "'samba.!pwddb'"'
257
258 samba.!spwddb = unixetc'\spwd.db'
259 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!'
260 IF options.!debug == 1 then say ' spwd.db = "'samba.!spwddb'"'
261
262 samba.!group = unixetc'\group'
263 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!'
264 IF options.!debug == 1 then say ' group = "'samba.!group'"'
265
266 samba.!printcap = unixetc'\printcap'
267 if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!'
268 IF options.!debug == 1 then say ' printcap = "'samba.!printcap'"'
269
270 /* Create these directories to make sure they do exist */
271 ok = SysMkDir(unixetc)
272 ok = SysMkDir(etc'\samba')
273 ok = SysMkDir(etc'\samba\private')
274 ok = SysMkDir(etc'\samba\pid')
275 ok = SysMkDir(etc'\samba\log')
276 ok = SysMkDir(etc'\samba\lock')
277 ok = SysMkDir(etc'\samba\spool')
278 ok = SysMkDir(etc'\samba\drivers')
279 /* This EA makes the testparm warning about browsing go away. */
280 /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */
281 ok = SysPutEA(ETC||'\samba\lock',"MODE", "FEFF0400ED410000"x)
282
283 /* use temporary smbpasswd created by pdbedit */
284 samba.!smbpasswd = TempDir'smbpasswd'
285 IF options.!debug == 1 then say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
286
287 /* Check if winbindd daemon exists */
288 HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
289
290 /* Do we have a minimum of free temporary space? */
291 if _ChkTempFreeSpace < 262144 then call _ErrorDataFileNotFound 'Free space on "'TempDir'" exhausted!'
292
293 /* Messages from Samba will go here */
294 samba.!error = SysTempFileName(TempDir'smb_err.???')
295 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
296 /* Use of this file is deprecated */
297 ErrorFile = Tempdir'smbutil.error'
298
299 IF options.!debug == 1 then do
300 if ErrorState then say " One or more basic Samba setup errors detected!"
301 else say " No basic Samba setup errors detected!"
302 end
303 IF options.!debug == 1 then say time()' _SambaInit() done, Errorstate = 'Errorstate
304return
305
306/*:VRX */
307_SambaFinish:
308 IF options.!debug == 1 then say time()' _SambaFinish() started.'
309 /* Do some very basic housekeeping when leaving */
310 ok = stream(samba.!msg,'c','close')
311 ok = stream(samba.!error,'c','close')
312 ok = SysFileDelete(samba.!msg)
313 ok = SysFileDelete(samba.!error)
314 IF options.!debug == 1 then say time()' _SambaFinish() done.'
315return
316
317/*:VRX */
318_ErrorBinaryNotFound:
319 IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() started.'
320 /* Set error status variable and show a short message - incomplete! */
321 msg = arg(1)
322 say "ERROR: "msg
323 id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
324 ErrorState = (1|ErrorState)
325 IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() done, Errorstate = 'Errorstate
326return
327
328/*:VRX */
329_ErrorDataFileNotFound:
330 IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() started.'
331 /* Set error status variable and show a short message - incomplete! */
332 msg = arg(1)
333 say "ERROR: "msg
334 DataErrorState = (1|DataErrorState)
335 IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() done, Errorstate = 'Errorstate
336return
337
338/*:VRX */
339_SambaExtendSearchPath:
340 IF options.!debug == 1 then say time()' _SambaExtendSearchPath() started'
341 /* Add binary and tools path to the PATH variable */
342 old_path = value('PATH',, 'OS2ENVIRONMENT')
343 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
344 if samba.!bin = samba.!tools then new_path = samba.!bin';'
345 else new_path = samba.!bin';'samba.!tools';'
346 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
347 drop new_path
348 end
349 drop old_path
350
351 /* Add binary and tools path to the DPATH variable */
352 old_dpath = value('DPATH',, 'OS2ENVIRONMENT')
353 if pos(translate(samba.!bin';'),translate(old_dpath)) = 0 then do
354 if samba.!bin = samba.!tools then new_dpath = samba.!bin';'
355 else new_dpath = samba.!bin';'samba.!tools';'
356 ok = value('DPATH', new_dpath || old_dpath, 'OS2ENVIRONMENT')
357 drop new_dpath
358 end
359 drop old_dpath
360
361 /* Add binary and tools path to the BEGINLIBPATH variable */
362 old_beginlibpath = SysQueryExtLibPath("B")
363 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
364 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
365 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
366 ok = SysSetExtLibPath( new_beginlibpath, "B")
367 drop new_beginlibpath
368 end
369 drop old_beginlibpath
370
371 /* Set LIBPATHSTRICT (this is an option - disabled by default) */
372 /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
373
374 IF options.!debug == 1 then say time()' _SambaExtendSearchPath() done'
375return
376
377/*:VRX */
378_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options. samba.
379 IF options.!debug == 1 then say time()' _SambaRunning() started'
380
381 /* Checks whether any Samba daemon is currently running */
382
383 /* Parameters: none or "ALL"
384
385 Returns: 1 = at least one Samba daemon is running
386 1 = Parameter "ALL" all Samba daemons are running
387 0 = no Samba daemon is running
388 0 = Parameter "ALL" not all Samba daemons are running
389
390 Stems: running. stores which daemon is running
391 pids. stores pids of running daemons
392 */
393 restype = arg(1)
394 running. = 0
395 pids. = ""
396
397 ok = PRProcessList(proc)
398
399 do I = 1 to proc.0
400 CurProc = VRParseFileName(proc.i.name,'NE')
401 if CurProc = "SMBD.EXE" then do
402 running.!smbd = 1
403 pids.!smbd = pids.!smbd||proc.i.pid||' '
404 end
405 if CurProc = "NMBD.EXE" then do
406 running.!nmbd = 1
407 pids.!nmbd = pids.!nmbd||proc.i.pid||' '
408 end
409 if CurProc = "WINBINDD.EXE" then do
410 running.!winb = 1
411 pids.!winb = pids.!winb||proc.i.pid||' '
412 end
413 end
414
415 if restype = "ALL" then do
416 runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
417 end
418 else do
419 runres = (running.!smbd | running.!nmbd |running.!winb)
420 end
421 IF options.!debug == 1 then say time()' _SambaRunning() done'
422return runres
Note: See TracBrowser for help on using the repository browser.