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

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

Updated error checking in SambaInit.vrs

File size: 12.3 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 ErrorFile = Tempdir'smbutil.error'
13 ErrorState = 0 /* _ErrorBinaryNotFound() changes this variable */
14 DataErrorState = 0 /* _ErrorDataFileNotFound() changes this variable */
15
16 /* Evaluate environment */
17 ETC = value('ETC',,'OS2ENVIRONMENT')
18 IF options.!debug == 1 THEN say ' ETC = "'ETC'"'
19
20 UnixRoot = value("UNIXROOT",,'OS2ENVIRONMENT')
21 if UnixRoot = "" then do
22 UnixRoot = left(ETC,length(ETC)-4)
23 say ' WARNING! Setting missing UNIXROOT variable to "'UnixRoot'".'
24 ok = value("UNIXROOT",UnixRoot,'OS2ENVIRONMENT')
25 end
26
27 IF options.!debug == 1 THEN say ' UnixRoot = "'UnixRoot'"'
28
29 /* if kLIBCPathrewriterInstalled() then do
30 unixetc = kLIBCpathRewriter("/etc")
31 end
32 else */
33 unixetc = UnixRoot'\etc'
34 IF options.!debug == 1 THEN say ' Unixetc = "'unixetc'"'
35
36 /* Samba needs TMPDIR for several purposes - if it is absent Samba crashes */
37 if translate(value('TMPDIR',,'OS2ENVIRONMENT'),'\','/') = '' then do
38 Msg.Title = VRGet("Main", "Caption")
39 Msg.Text = "Environment variable TMPDIR is missing - expect to see Samba crashes!"
40 Msg.Type = "E"
41 call _ShowMsg
42 end
43
44 /* find all executables */
45
46 /* get the path to this file */
47 samba.!tools = VRParseFilename(VRGet("Application", "Program"),'DP')
48 if samba.!tools = '' then do
49 parse source . . script
50 samba.!tools = VRParseFilename(script,'DP')
51 end
52 IF options.!debug == 1 THEN say ' Samba tools = "'samba.!tools'"'
53 say ' Changing into "'directory(samba.!tools)'"'
54
55 /* smbd.exe */
56 samba.!smbd = ""
57 if samba.!smbd = "" then do /* in current directory? */
58 call charout , " Are binaries in current directory? "
59 ok = SysFileTree('.\smbd.exe', exist.,'FO')
60 say exist.0' (1 = Yes, 0 = No)'
61 if exist.0 = 1 then samba.!smbd = exist.1
62 end
63 if samba.!smbd = "" then do /* in parent directory? */
64 call charout , " Are binaries in parent directory? "
65 ok = SysFileTree('..\smbd.exe', exist.,'FO')
66 say exist.0' (1 = Yes, 0 = No)'
67 if exist.0 = 1 then samba.!smbd = exist.1
68 end
69 if samba.!smbd = "" then do /* in ..\BIN directory? */
70 call charout , " Are binaries in ..\BIN directory? "
71 ok = SysFileTree('..\bin\smbd.exe', exist.,'FO')
72 say exist.0' (1 = Yes, 0 = No)'
73 if exist.0 = 1 then samba.!smbd = exist.1
74 end
75 if samba.!smbd = "" then do /* in SMB_EXE ? */
76 call charout , " Are binaries in SMB_EXE path? "
77 samba.!smbd = SysSearchPath("SMB_EXE","SMBD.EXE")
78 if samba.!smbd = "" then say "No."; else say "Yes."
79 end
80 if samba.!smbd = "" then do /* in PATH ? */
81 call charout , " Are binaries in PATH? "
82 samba.!smbd = SysSearchPath("PATH","SMBD.EXE")
83 if samba.!smbd = "" then say "No."; else say "Yes."
84 end
85
86 if samba.!smbd = "" then call _ErrorBinaryNotFound " could not find smbd.exe!"
87
88 samba.!bin = VRParseFileName(samba.!smbd,'DP')
89 IF options.!debug == 1 THEN say ' Samba binaries = "'samba.!bin'"'
90
91 /* smb.cmd */
92 samba.!smbcmd = samba.!tools'\smb.cmd'
93 if \VRFileExists(samba.!smbcmd) then do
94 samba.!smbcmd = samba.!bin'\smb.cmd'
95 if \VRFileExists(samba.!smbcmd) then call _ErrorBinaryNotFound " could not find smb.cmd!"
96 end
97 IF options.!debug == 1 THEN say ' smb.cmd = "'samba.!smbcmd'"'
98
99 /* smbpasswd.exe */
100 samba.!smbpasswdexe = samba.!bin'\smbpasswd.exe'
101 if \VRFileExists(samba.!smbpasswdexe) then call _ErrorBinaryNotFound " could not find smbpasswd.exe!"
102 IF options.!debug == 1 THEN say ' smbpasswd.exe = "'samba.!smbpasswdexe'"'
103
104 /* pdbedit.exe */
105 samba.!pdbeditexe = samba.!bin'\pdbedit.exe'
106 if \VRFileExists(samba.!pdbeditexe) then call _ErrorBinaryNotFound " could not find pdbedit.exe!"
107 IF options.!debug == 1 THEN say ' pdbedit.exe = "'samba.!pdbeditexe'"'
108
109 /* net.exe */
110 samba.!netexe = samba.!bin'\net.exe'
111 if \VRFileExists(samba.!netexe) then call _ErrorBinaryNotFound " could not find net.exe!"
112 IF options.!debug == 1 THEN say ' net.exe = "'samba.!netexe'"'
113
114 /* testparm.exe */
115 samba.!testparmexe = samba.!bin'\testparm.exe'
116 if \VRFileExists(samba.!testparmexe) then call _ErrorBinaryNotFound " could not find testparm.exe!"
117 IF options.!debug == 1 THEN say ' testparm.exe = "'samba.!testparmexe'"'
118
119 /* smbtree.exe */
120 samba.!smbtreeexe = samba.!bin'\smbtree.exe'
121 if \VRFileExists(samba.!smbtreeexe) then call _ErrorBinaryNotFound " could not find smbtree.exe!"
122 IF options.!debug == 1 THEN say ' smbtree.exe = "'samba.!smbtreeexe'"'
123
124 /* smbstatus.exe */
125 samba.!smbstatusexe = samba.!bin'\smbstatus.exe'
126 if \VRFileExists(samba.!smbstatusexe) then call _ErrorBinaryNotFound " could not find smbstatus.exe!"
127 IF options.!debug == 1 THEN say ' smbstatus.exe = "'samba.!smbstatusexe'"'
128
129 /* smbcontrol.exe */
130 samba.!smbcontrolexe = samba.!bin'\smbcontrol.exe'
131 if \VRFileExists(samba.!smbcontrolexe) then call _ErrorBinaryNotFound " could not find smbcontrol.exe!"
132 IF options.!debug == 1 THEN say ' smbcontrol.exe = "'samba.!smbcontrolexe'"'
133
134 /* smbclient.exe */
135 samba.!smbclientexe = samba.!bin'\smbclient.exe'
136 if \VRFileExists(samba.!smbclientexe) then call _ErrorBinaryNotFound " could not find smbclient.exe!"
137 IF options.!debug == 1 THEN say ' smbclient.exe = "'samba.!smbclientexe'"'
138
139 /* pwd_mkdb */
140 samba.!pwd_mkdb = SysSearchPath("PATH","pwd_mkdb.exe")
141 if samba.!pwd_mkdb = "" then do /* in current directory? */
142 ok = SysFileTree('.\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 usr/sbin directory? */
146 ok = SysFileTree(UnixRoot'\usr\sbin\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 /* tools directory? */
150 ok = SysFileTree(samba.!tools'\pwd_mkdb.exe', exist.,'FO')
151 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
152 end
153 if samba.!pwd_mkdb = "" then do /* in smbd directory? */
154 ok = SysFileTree(samba.!bin'\pwd_mkdb.exe', exist.,'FO')
155 if exist.0 = 1 then samba.!pwd_mkdb = exist.1
156 end
157 if samba.!pwd_mkdb = "" then do /* in SMB_SBIN ? */
158 samba.!pwd_mkdb = SysSearchPath("SMB_SBIN","pwd_mkdb.exe")
159 end
160
161 if samba.!pwd_mkdb = "" then call _ErrorBinaryNotFound " could not find pwd_mkdb.exe!"
162 IF options.!debug == 1 THEN say ' pwd_mkdb.exe = "'samba.!pwd_mkdb'"'
163
164 /* logfiles */
165 samba.!log = value('SMB_LOGS',,'OS2ENVIRONMENT')
166 if samba.!log = "" then do /* new default */
167 ok = SysFileTree(etc'\samba\logs',exist.,'DO')
168 if exist.0 > 0 then samba.!log = etc'\samba\logs'
169 end
170 if samba.!log = "" then do /* old default */
171 ok = SysFileTree(samba.!bin'\logs\log.smbd*',exist.,'FO')
172 if exist.0 > 0 then samba.!log = samba.!bin'\logs'
173 end
174 if samba.!log = "" then do /* LOGFILES */
175 samba.!log = value('LOGFILES',,'OS2ENVIRONMENT')
176 end
177
178 if samba.!log = "" then call _ErrorDataFileNotFound " could not find logfiles!"
179 IF options.!debug == 1 THEN say ' Samba logfiles = "'samba.!log'"'
180
181 /* smb.conf */
182 samba.!smbconf = ETC'\samba\smb.conf'
183 if \VRFileExists(samba.!smbconf) then call _ErrorDataFileNotFound samba.!smbconf' is not present.'
184 IF options.!debug == 1 THEN say ' Samba smb.conf = "'samba.!smbconf'"'
185
186 /* find all datafiles - their locations are fixed */
187 /* the password files - we'll create them if they don't exist */
188 samba.!masterpasswd = unixetc'\master.passwd'
189 if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound " could not find master.passwd!"
190 IF options.!debug == 1 THEN say ' master.passwd = "'samba.!masterpasswd'"'
191
192 samba.!pwddb = unixetc'\pwd.db'
193 if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound " could not find pwd.db!"
194 IF options.!debug == 1 THEN say ' pwd.db = "'samba.!pwddb'"'
195
196 samba.!spwddb = unixetc'\spwd.db'
197 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find spwd.db!"
198 IF options.!debug == 1 THEN say ' spwd.db = "'samba.!spwddb'"'
199
200 samba.!group = unixetc'\group'
201 if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound " could not find "samba.!group"!"
202 IF options.!debug == 1 THEN say ' group = "'samba.!group'"'
203
204 samba.!printcap = unixetc'\printcap'
205 if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound " could not find printcap!"
206 IF options.!debug == 1 THEN say ' printcap = "'samba.!printcap'"'
207
208 /* Create this directory tree if it does not exist */
209 ok = SysMkDir(etc'\samba')
210 ok = SysMkDir(etc'\samba\private')
211 ok = SysMkDir(etc'\samba\pid')
212 ok = SysMkDir(etc'\samba\logs')
213 ok = SysMkDir(etc'\samba\lock')
214 ok = SysMkDir(etc'\samba\spool')
215 ok = SysMkDir(etc'\samba\drivers')
216
217 /* use temporary smbpasswd created by pdbedit */
218 samba.!smbpasswd = TempDir'smbpasswd'
219 IF options.!debug == 1 THEN say ' smbpasswd = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
220
221 /* Check if winbindd daemon exists */
222 HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
223
224 /* Messages from Samba will go here */
225 samba.!error = SysTempFileName(TempDir'smb_err.???')
226 samba.!msg = SysTempFileName(TempDir'smb_msg.???')
227
228 IF options.!debug == 1 then do
229 if ErrorState then say " One or more basic Samba setup errors detected!"
230 else say " No basic Samba setup errors detected!"
231 end
232 IF options.!debug == 1 THEN say '_SambaInit() done, Errorstate = 'Errorstate
233return
234
235/*:VRX */
236_SambaFinish:
237 /* Do some very basic housekeeping when leaving */
238 ok = stream(samba.!msg,'c','close')
239 ok = stream(samba.!error,'c','close')
240 ok = SysFileDelete(samba.!msg)
241 ok = SysFileDelete(samba.!error)
242return
243
244/*:VRX */
245_ErrorBinaryNotFound:
246 /* Set error status variable and show a short message - incomplete! */
247 msg = arg(1)
248 say "ERROR: "msg
249 id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
250 ErrorState = (1|ErrorState)
251return
252
253/*:VRX */
254_ErrorDataFileNotFound:
255 /* Set error status variable and show a short message - incomplete! */
256 msg = arg(1)
257 say "ERROR: "msg
258 DataErrorState = (1|DataErrorState)
259return
260
261/*:VRX */
262_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd
263 /* Checks whether any Samba daemon is currently running */
264
265 /* Parameters: none or "ALL"
266
267 Returns: 1 = at least one Samba daemon is running
268 1 = Parameter "ALL" all Samba daemons are running
269 0 = no Samba daemon is running
270 0 = Parameter "ALL" not all Samba daemons are running
271
272 Stems: running. stores which daemon is running
273 pids. stores pids of running daemons
274 */
275 restype = arg(1)
276 running. = 0
277 pids. = ""
278
279 ok = PRProcessList(proc)
280
281 do I = 1 to proc.0
282 CurProc = VRParseFileName(proc.i.name,'NE')
283 if CurProc = "SMBD.EXE" then do
284 running.!smbd = 1
285 pids.!smbd = pids.!smbd||proc.i.pid||' '
286 end
287 if CurProc = "NMBD.EXE" then do
288 running.!nmbd = 1
289 pids.!nmbd = pids.!nmbd||proc.i.pid||' '
290 end
291 if CurProc = "WINBINDD.EXE" then do
292 running.!winb = 1
293 pids.!winb = pids.!winb||proc.i.pid||' '
294 end
295 end
296
297 if restype = "ALL" then do
298 runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
299 end
300 else do
301 runres = (running.!smbd | running.!nmbd |running.!winb)
302 end
303return runres
Note: See TracBrowser for help on using the repository browser.