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