source: branches/guitools-1.0/shared/sambainit.vrs@ 408

Last change on this file since 408 was 408, checked in by Herwig Bauernfeind, 15 years ago

GUI-Tools: SSCC 0.9.5, SMBUsers 0.9.6 several fixes

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