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

Last change on this file since 990 was 990, checked in by Herwig Bauernfeind, 4 years ago

GUITools: All changes that have built over time.

File size: 16.7 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    /* complete shadow copy of smb.conf in temporary directory - should always be created on the fly */
211    /* before reading from it */
212    samba.!shadowsmbconf = TempDir||'smb.conf'
213
214    /* find all datafiles - their locations are fixed */
215   
216    /* the password files - we'll create them if they don't exist */
217    samba.!masterpasswd = unixetc'\master.passwd'
218    if \VRFileExists(samba.!masterpasswd) then call _ErrorDataFileNotFound 'Could not find "'samba.!masterpasswd'"!'
219    IF options.!debug == 1 then say '  master.passwd  = "'samba.!masterpasswd'"'
220
221    samba.!pwddb = unixetc'\pwd.db'
222    if \VRFileExists(samba.!pwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!pwddb'"!'
223    IF options.!debug == 1 then say '  pwd.db         = "'samba.!pwddb'"'
224
225    samba.!spwddb = unixetc'\spwd.db'
226    if \VRFileExists(samba.!spwddb) then call _ErrorDataFileNotFound 'Could not find "'samba.!spwddb'"!'
227    IF options.!debug == 1 then say '  spwd.db        = "'samba.!spwddb'"'
228
229    samba.!group = unixetc'\group'
230    if \VRFileExists(samba.!group) then call _ErrorDataFileNotFound 'Could not find "'samba.!group'"!'
231    IF options.!debug == 1 then say '  group          = "'samba.!group'"'
232
233    samba.!printcap = unixetc'\printcap'
234    if \VRFileExists(samba.!printcap) then call _ErrorDataFileNotFound 'Could not find "'samba.!printcap'"!'
235    IF options.!debug == 1 then say '  printcap       = "'samba.!printcap'"'
236
237    /* Create these directories to make sure they do exist */
238    ok = SysMkDir(unixetc)
239    ok = SysMkDir(etc'\samba')
240    ok = SysMkDir(etc'\samba\private')
241    ok = SysMkDir(etc'\samba\pid')
242    ok = SysMkDir(etc'\samba\log')     
243    ok = SysMkDir(etc'\samba\lock')     
244    ok = SysMkDir(etc'\samba\spool')
245    ok = SysMkDir(etc'\samba\drivers')
246    /* This EA makes the testparm warning about browsing go away. */
247    /* Note: The EA is NOT marked critical as it should be, neverthelesse this fix works */
248    ok = SysPutEA(ETC||'\samba\lock',"MODE", "FEFF0400ED410000"x)
249
250    /* use temporary smbpasswd created by pdbedit */
251    samba.!smbpasswd = TempDir'smbpasswd'
252    IF options.!debug == 1 then say '  smbpasswd      = "'samba.!smbpasswd'" (will be created by pdbedit on the fly!)'
253
254    /* Check if winbindd daemon exists */
255    HaveWinbindd = (stream(samba.!bin'\winbindd.exe', 'c', 'query exists') <> "")
256
257    /* Do we have a minimum of free temporary space? */
258    if _ChkTempFreeSpace < 262144 then call _ErrorDataFileNotFound 'Free space on "'TempDir'" exhausted!'
259
260    /* Messages from Samba will go here */
261    samba.!error = SysTempFileName(TempDir'smb_err.???')
262    samba.!msg   = SysTempFileName(TempDir'smb_msg.???')
263    /* Use of this file is deprecated */
264    ErrorFile  = Tempdir'smbutil.error'
265
266    IF options.!debug == 1 then do
267        if ErrorState then say "  One or more  basic Samba setup errors detected!"
268                      else say "  No basic Samba setup errors detected!"
269    end
270    IF options.!debug == 1 then say time()' _SambaInit() done, Errorstate = 'Errorstate
271return
272
273/*:VRX */
274_SambaFinish:
275    IF options.!debug == 1 then say time()' _SambaFinish() started.'
276    /* Do some very basic housekeeping when leaving */
277    ok = stream(samba.!msg,'c','close')
278    ok = stream(samba.!error,'c','close')
279    ok = SysFileDelete(samba.!msg)
280    ok = SysFileDelete(samba.!error)
281    IF options.!debug == 1 then say time()' _SambaFinish() done.'
282return
283
284/*:VRX */
285_ErrorBinaryNotFound:
286    IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() started.'
287    /* Set error status variable and show a short message - incomplete! */
288    msg = arg(1)
289    say "ERROR: "msg
290    id = VRMessage( VRWindow(), msg, "Samba Installation", "E" )
291    ErrorState = (1|ErrorState)
292    IF options.!debug == 1 then say time()' _ErrorBinaryNotFound() done, Errorstate = 'Errorstate
293return
294
295/*:VRX */
296_ErrorDataFileNotFound:
297    IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() started.'
298    /* Set error status variable and show a short message - incomplete! */
299    msg = arg(1)
300    say "ERROR: "msg
301    DataErrorState = (1|DataErrorState)
302    IF options.!debug == 1 then say time()' _ErrorDataFileNotFound() done, Errorstate = 'Errorstate
303return
304
305/*:VRX */
306_SambaExtendSearchPath:
307    IF options.!debug == 1 then say time()' _SambaExtendSearchPath() started'
308    /* Add binary and tools path to the PATH variable */
309    old_path = value('PATH',, 'OS2ENVIRONMENT')
310    if pos(translate(samba.!bin';'),translate(old_path)) = 0 then do
311        if samba.!bin = samba.!tools then new_path = samba.!bin';'
312        else new_path = samba.!bin';'samba.!tools';'
313        ok = value('PATH', new_path || old_path, 'OS2ENVIRONMENT')
314        drop new_path
315    end
316    drop old_path
317
318    /* Add binary and tools path to the DPATH variable */
319    old_dpath = value('DPATH',, 'OS2ENVIRONMENT')
320    if pos(translate(samba.!bin';'),translate(old_dpath)) = 0 then do
321        if samba.!bin = samba.!tools then new_dpath = samba.!bin';'
322        else new_dpath = samba.!bin';'samba.!tools';'
323        ok = value('DPATH', new_dpath || old_dpath, 'OS2ENVIRONMENT')
324        drop new_dpath
325    end
326    drop old_dpath
327   
328    /* Add binary and tools path to the BEGINLIBPATH variable */
329    old_beginlibpath = SysQueryExtLibPath("B")
330    if pos(translate(samba.!bin';'),translate(old_beginlibpath)) = 0 then do
331        if samba.!bin = samba.!tools then new_beginlibpath = samba.!bin';'old_beginlibpath
332        else new_beginlibpath = samba.!bin';'samba.!tools';'old_beginlibpath
333        ok = SysSetExtLibPath( new_beginlibpath, "B")
334        drop new_beginlibpath
335    end
336    drop old_beginlibpath
337
338    /* Set LIBPATHSTRICT (this is an option - disabled by default) */
339    /* ok = value('LIBPATHSTRICT','T', 'OS2ENVIRONMENT') */
340   
341    IF options.!debug == 1 then say time()' _SambaExtendSearchPath() done'
342return
343
344/*:VRX */
345_SambaRunning: procedure expose running. pids. TempDir HaveWinbindd options. samba.
346    IF options.!debug == 1 then say time()' _SambaRunning() started'
347
348    /* Checks whether any Samba daemon is currently running */
349       
350    /* Parameters: none or "ALL"
351       
352       Returns: 1 = at least one Samba daemon is running
353                1 = Parameter "ALL" all Samba daemons are running
354                0 = no Samba daemon is running
355                0 = Parameter "ALL" not all Samba daemons are running
356               
357       Stems: running. stores which daemon is running
358              pids.    stores pids of running daemons
359     */
360    restype = arg(1)
361    running. = 0
362    pids. = ""
363
364    ok = PRProcessList(proc)
365
366    do I = 1 to proc.0
367        CurProc = VRParseFileName(proc.i.name,'NE')
368        if CurProc = "SMBD.EXE" then do
369            running.!smbd = 1
370            pids.!smbd = pids.!smbd||proc.i.pid||' '
371        end
372        if CurProc = "NMBD.EXE" then do
373            running.!nmbd = 1
374            pids.!nmbd = pids.!nmbd||proc.i.pid||' '
375        end
376        if CurProc = "WINBINDD.EXE" then do
377            running.!winb = 1
378            pids.!winb = pids.!winb||proc.i.pid||' '
379        end
380    end
381   
382    if restype = "ALL" then do
383        runres = (running.!smbd & running.!nmbd & (running.!winb | \HaveWinbindd ))
384    end
385    else do
386        runres = (running.!smbd | running.!nmbd |running.!winb)
387    end
388    IF options.!debug == 1 then say time()' _SambaRunning() done'
389return runres
Note: See TracBrowser for help on using the repository browser.