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

Last change on this file since 277 was 277, checked in by Herwig Bauernfeind, 16 years ago

Updates in the shared code for the GUI tools

File size: 14.0 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 smbpasswd.exe!"
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 pdbedit.exe!"
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 net.exe!"
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 testparm.exe!"
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 smbtree.exe!"
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 smbstatus.exe!"
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 smbcontrol.exe!"
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 smbclient.exe!"
124 IF options.!debug == 1 THEN say ' smbclient.exe = "'samba.!smbclientexe'"'
125
126 /* pwd_mkdb */
127 samba.!pwd_mkdb = SysSearchPath("PATH","pwd_mkdb.exe")
128 if samba.!pwd_mkdb = "" then do /* in current directory? */
129 ok = SysFileTree('.\pwd_mkdb.exe', exist.,'FO')
130 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
131 end
132 if samba.!pwd_mkdb = "" then do /* in usr/sbin directory? */
133 ok = SysFileTree(UnixRoot'\usr\sbin\pwd_mkdb.exe', exist.,'FO')
134 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
135 end
136 if samba.!pwd_mkdb = "" then do /* tools directory? */
137 ok = SysFileTree(samba.!tools'\pwd_mkdb.exe', exist.,'FO')
138 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
139 end
140 if samba.!pwd_mkdb = "" then do /* in smbd directory? */
141 ok = SysFileTree(samba.!bin'\pwd_mkdb.exe', exist.,'FO')
142 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
143 end
144 if samba.!pwd_mkdb = "" then do /* in SMB_SBIN ? */
145 samba.!pwd_mkdb = SysSearchPath("SMB_SBIN","pwd_mkdb.exe")
146 end
147
148 if samba.!pwd_mkdb = "" then call _ErrorBinaryNotFound " could not find pwd_mkdb.exe!"
149 IF options.!debug == 1 THEN say ' pwd_mkdb.exe = "'samba.!pwd_mkdb'"'
150
151 /* logfiles */
152 samba.!log = value('SMB_LOGS',,'OS2ENVIRONMENT')
153 if samba.!log = "" then do /* new default */
154 ok = SysFileTree(etc'\samba\logs',exist.,'DO')
155 if exist.0 > 0 then samba.!log = etc'\samba\logs'
156 end
157 if samba.!log = "" then do /* old default */
158 ok = SysFileTree(samba.!bin'\logs\log.smbd*',exist.,'FO')
159 if exist.0 > 0 then samba.!log = samba.!bin'\logs'
160 end
161 if samba.!log = "" then do /* LOGFILES */
162 samba.!log = value('LOGFILES',,'OS2ENVIRONMENT')
163 end
164
165 if samba.!log = "" then call _ErrorDataFileNotFound " could not find logfiles!"
166 IF options.!debug == 1 THEN say ' Samba logfiles = "'samba.!log'"'
167
168 /* smb.conf */
169 samba.!smbconf = ETC'\samba\smb.conf'
170 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
171 IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"'
172
173 /* find all datafiles - their locations are fixed */
174
175 /* the password files - we'll create them if they don't exist */
176 samba.!masterpasswd = unixetc'\master.passwd'
177 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound " could not find master.passwd!"
178 IF options.!debug == 1 THEN say ' master.passwd = "'samba.!masterpasswd'"'
179
180 samba.!pwddb = unixetc'\pwd.db'
181 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound " could not find pwd.db!"
182 IF options.!debug == 1 THEN say ' pwd.db = "'samba.!pwddb'"'
183
184 samba.!spwddb = unixetc'\spwd.db'
185 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find spwd.db!"
186 IF options.!debug == 1 THEN say ' spwd.db = "'samba.!spwddb'"'
187
188 samba.!group = unixetc'\group'
189 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound " could not find "samba.!group"!"
190 IF options.!debug == 1 THEN say ' group = "'samba.!group'"'
191
192 samba.!printcap = unixetc'\printcap'
193 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find printcap!"
194 IF options.!debug == 1 THEN say ' printcap = "'samba.!printcap'"'
195
196 /* Create this directory tree if it does not exist */
197 ok = SysMkDir(etc'\samba')
198 ok = SysMkDir(etc'\samba\private')
199 ok = SysMkDir(etc'\samba\pid')
200 ok = SysMkDir(etc'\samba\logs')
201 ok = SysMkDir(etc'\samba\lock')
202 ok = SysMkDir(etc'\samba\spool')
203 ok = SysMkDir(etc'\samba\drivers')
204
205 /* use temporary smbpasswd created by pdbedit */
206 samba.!smbpasswd = TempDir'smbpasswd'
207 IF options.!debug == 1 THEN say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
208
209 /* Check if winbindd daemon exists */
210 HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
211
212 /* Messages from Samba will go here */
213 samba.!error = SysTempFileName(TempDir'smb_err.???')
214 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
215 /* Use of this file is deprecated */
216 ErrorFile = Tempdir'smbutil.error'
217
218 IF options.!debug == 1 then do
219 if ErrorState then say " One or more basic Samba setup errors detected!"
220 else say " No basic Samba setup errors detected!"
221 end
222 IF options.!debug == 1 THEN say '_SambaInit() done, Errorstate = 'Errorstate
223return
224
225/*:VRX */
226_SambaFinish:
227 /* Do some very basic housekeeping when leaving */
228 ok = stream(samba.!msg,'c','close')
229 ok = stream(samba.!error,'c','close')
230 ok = SysFileDelete(samba.!msg)
231 ok = SysFileDelete(samba.!error)
232return
233
234/*:VRX */
235_ErrorBinaryNotFound:
236 /* Set error status variable and show a short message - incomplete! */
237 msg = arg(1)
238 say "ERROR: "msg
239 id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
240 ErrorState = (1|ErrorState)
241return
242
243/*:VRX */
244_ErrorDataFileNotFound:
245 /* Set error status variable and show a short message - incomplete! */
246 msg = arg(1)
247 say "ERROR: "msg
248 DataErrorState = (1|DataErrorState)
249return
250
251/*:VRX */
252_SambaExtendSearchPath:
253 IF options.!debug == 1 THEN say '_SambaExtendSearchPath() started'
254 /* Add binary and tools path to the PATH variable */
255 old_path = value('PATH',, 'OS2ENVIRONMENT')
256 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
257 if samba.!bin = samba.!tools then new_path = samba.!bin';'
258 else new_path = samba.!bin';'samba.!tools';'
259 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
260 drop new_path
261 end
262 drop old_path
263
264 /* Add binary and tools path to the BEGINLIBPATH variable */
265 old_beginlibpath = SysQueryExtLibPath("B")
266 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
267 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
268 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
269 ok = SysSetExtLibPath( new_beginlibpath, "B")
270 drop new_beginlibpath
271 end
272 drop old_beginlibpath
273 IF options.!debug == 1 THEN say '_SambaExtendSearchPath() done'
274return
275
276/*:VRX */
277_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options.
278 IF options.!debug == 1 THEN say '_SambaRunning() started'
279
280 /* Checks whether any Samba daemon is currently running */
281
282 /* Parameters: none or "ALL"
283
284 Returns: 1 = at least one Samba daemon is running
285 1 = Parameter "ALL" all Samba daemons are running
286 0 = no Samba daemon is running
287 0 = Parameter "ALL" not all Samba daemons are running
288
289 Stems: running. stores which daemon is running
290 pids. stores pids of running daemons
291 */
292 restype = arg(1)
293 running. = 0
294 pids. = ""
295
296 ok = PRProcessList(proc)
297
298 do I = 1 to proc.0
299 CurProc = VRParseFileName(proc.i.name,'NE')
300 if CurProc = "SMBD.EXE" then do
301 running.!smbd = 1
302 pids.!smbd = pids.!smbd||proc.i.pid||' '
303 end
304 if CurProc = "NMBD.EXE" then do
305 running.!nmbd = 1
306 pids.!nmbd = pids.!nmbd||proc.i.pid||' '
307 end
308 if CurProc = "WINBINDD.EXE" then do
309 running.!winb = 1
310 pids.!winb = pids.!winb||proc.i.pid||' '
311 end
312 end
313
314 if restype = "ALL" then do
315 runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
316 end
317 else do
318 runres = (running.!smbd | running.!nmbd |running.!winb)
319 end
320 IF options.!debug == 1 THEN say '_SambaRunning() done'
321return runres
322
323/*:VRX */
324_PasswordDbRewrite:
325 IF options.!debug == 1 THEN say "_PasswordDBRewrite() started"
326
327 /* Reset any old rc from pwd_mkdb.exe */
328 pwd_mkdbrc = 0
329
330 /* delete old .db.tmp files */
331 ok = SysFileDelete(UnixETC'\pwd.db.tmp')
332 ok = SysFileDelete(UnixETC'\spwd.db.tmp')
333
334 /* create backups of old .db files */
335 ok = VRCopyFile( UnixETC'\pwd.db', UnixETC'\pwd.db.bak' )
336 ok = VRCopyFile( UnixETC'\spwd.db', UnixETC'\spwd.db.bak' )
337
338 /* delete old .db files */
339 ok = SysFileDelete(UnixETC'\pwd.db')
340 ok = SysFileDelete(UnixETC'\spwd.db')
341
342 /* Create new password db */
343 address cmd samba.!pwd_mkdb' -d 'unixetc' 'samba.!masterpasswd' 2>'samba.!error
344 pwd_mkdbrc = rc
345 if \VRFileExists(samba.!pwddb) | pwd_mkdbrc <> 0 then do
346 call _SambaShowError
347 end
348 IF options.!debug == 1 THEN say "_PasswordDBRewrite() done ("pwd_mkdbrc")"
349return
Note: See TracBrowser for help on using the repository browser.