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

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

Create branch for GUI tools

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