source: trunk/guitools/shared/sambainit.vrs @ 908

Last change on this file since 908 was 908, checked in by Herwig Bauernfeind, 5 years ago

GUITools: SMBMon (TDB Check page), shared library updates

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