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

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

GUI tools: smbusers Version 0.9.1

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\log',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 these directories to make sure they do exist */
197 ok = SysMkDir(unixetc)
198 ok = SysMkDir(etc'\samba')
199 ok = SysMkDir(etc'\samba\private')
200 ok = SysMkDir(etc'\samba\pid')
201 ok = SysMkDir(etc'\samba\log')
202 ok = SysMkDir(etc'\samba\lock')
203 ok = SysMkDir(etc'\samba\spool')
204 ok = SysMkDir(etc'\samba\drivers')
205
206 /* use temporary smbpasswd created by pdbedit */
207 samba.!smbpasswd = TempDir'smbpasswd'
208 IF options.!debug == 1 THEN say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
209
210 /* Check if winbindd daemon exists */
211 HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
212
213 /* Messages from Samba will go here */
214 samba.!error = SysTempFileName(TempDir'smb_err.???')
215 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
216 /* Use of this file is deprecated */
217 ErrorFile = Tempdir'smbutil.error'
218
219 IF options.!debug == 1 then do
220 if ErrorState then say " One or more basic Samba setup errors detected!"
221 else say " No basic Samba setup errors detected!"
222 end
223 IF options.!debug == 1 THEN say '_SambaInit() done, Errorstate = 'Errorstate
224return
225
226/*:VRX */
227_SambaFinish:
228 /* Do some very basic housekeeping when leaving */
229 ok = stream(samba.!msg,'c','close')
230 ok = stream(samba.!error,'c','close')
231 ok = SysFileDelete(samba.!msg)
232 ok = SysFileDelete(samba.!error)
233return
234
235/*:VRX */
236_ErrorBinaryNotFound:
237 /* Set error status variable and show a short message - incomplete! */
238 msg = arg(1)
239 say "ERROR: "msg
240 id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
241 ErrorState = (1|ErrorState)
242return
243
244/*:VRX */
245_ErrorDataFileNotFound:
246 /* Set error status variable and show a short message - incomplete! */
247 msg = arg(1)
248 say "ERROR: "msg
249 DataErrorState = (1|DataErrorState)
250return
251
252/*:VRX */
253_SambaExtendSearchPath:
254 IF options.!debug == 1 THEN say '_SambaExtendSearchPath() started'
255 /* Add binary and tools path to the PATH variable */
256 old_path = value('PATH',, 'OS2ENVIRONMENT')
257 if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
258 if samba.!bin = samba.!tools then new_path = samba.!bin';'
259 else new_path = samba.!bin';'samba.!tools';'
260 ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
261 drop new_path
262 end
263 drop old_path
264
265 /* Add binary and tools path to the BEGINLIBPATH variable */
266 old_beginlibpath = SysQueryExtLibPath("B")
267 if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
268 if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
269 else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
270 ok = SysSetExtLibPath( new_beginlibpath, "B")
271 drop new_beginlibpath
272 end
273 drop old_beginlibpath
274 IF options.!debug == 1 THEN say '_SambaExtendSearchPath() done'
275return
276
277/*:VRX */
278_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options.
279 IF options.!debug == 1 THEN say '_SambaRunning() started'
280
281 /* Checks whether any Samba daemon is currently running */
282
283 /* Parameters: none or "ALL"
284
285 Returns: 1 = at least one Samba daemon is running
286 1 = Parameter "ALL" all Samba daemons are running
287 0 = no Samba daemon is running
288 0 = Parameter "ALL" not all Samba daemons are running
289
290 Stems: running. stores which daemon is running
291 pids. stores pids of running daemons
292 */
293 restype = arg(1)
294 running. = 0
295 pids. = ""
296
297 ok = PRProcessList(proc)
298
299 do I = 1 to proc.0
300 CurProc = VRParseFileName(proc.i.name,'NE')
301 if CurProc = "SMBD.EXE" then do
302 running.!smbd = 1
303 pids.!smbd = pids.!smbd||proc.i.pid||' '
304 end
305 if CurProc = "NMBD.EXE" then do
306 running.!nmbd = 1
307 pids.!nmbd = pids.!nmbd||proc.i.pid||' '
308 end
309 if CurProc = "WINBINDD.EXE" then do
310 running.!winb = 1
311 pids.!winb = pids.!winb||proc.i.pid||' '
312 end
313 end
314
315 if restype = "ALL" then do
316 runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
317 end
318 else do
319 runres = (running.!smbd | running.!nmbd |running.!winb)
320 end
321 IF options.!debug == 1 THEN say '_SambaRunning() done'
322return runres
323
324/*:VRX */
325_PasswordDbRewrite:
326 IF options.!debug == 1 THEN say "_PasswordDBRewrite() started"
327
328 /* Reset any old rc from pwd_mkdb.exe */
329 pwd_mkdbrc = 0
330
331 /* delete old .db.tmp files */
332 ok = SysFileDelete(UnixETC'\pwd.db.tmp')
333 ok = SysFileDelete(UnixETC'\spwd.db.tmp')
334
335 /* create backups of old .db files */
336 ok = VRCopyFile( UnixETC'\pwd.db', UnixETC'\pwd.db.bak' )
337 ok = VRCopyFile( UnixETC'\spwd.db', UnixETC'\spwd.db.bak' )
338
339 /* delete old .db files */
340 ok = SysFileDelete(UnixETC'\pwd.db')
341 ok = SysFileDelete(UnixETC'\spwd.db')
342
343 /* Create new password db */
344 address cmd samba.!pwd_mkdb' -d 'unixetc' 'samba.!masterpasswd' 2>'samba.!error
345 pwd_mkdbrc = rc
346 if \VRFileExists(samba.!pwddb) | pwd_mkdbrc <> 0 then do
347 call _SambaShowError
348 end
349 IF options.!debug == 1 THEN say "_PasswordDBRewrite() done ("pwd_mkdbrc")"
350return
Note: See TracBrowser for help on using the repository browser.