source: branches/guitools-2.0/shared/sambainit.vrs

Last change on this file was 564, checked in by Herwig Bauernfeind, 14 years ago

GUI-Tools: New SambaInit.VRS

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