Makefile: Added quoata changes for Linux from Thorvald Natvig
[kai/samba.git] / source3 / param / loadparm.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Parameter loading functions
5    Copyright (C) Karl Auer 1993,1997
6
7    Largely re-written by Andrew Tridgell, September 1994
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /*
25  *  Load parameters.
26  *
27  *  This module provides suitable callback functions for the params
28  *  module. It builds the internal table of service details which is
29  *  then used by the rest of the server.
30  *
31  * To add a parameter:
32  *
33  * 1) add it to the global or service structure definition
34  * 2) add it to the parm_table
35  * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
36  * 4) If it's a global then initialise it in init_globals. If a local
37  *    (ie. service) parameter then initialise it in the sDefault structure
38  *  
39  *
40  * Notes:
41  *   The configuration file is processed sequentially for speed. It is NOT
42  *   accessed randomly as happens in 'real' Windows. For this reason, there
43  *   is a fair bit of sequence-dependent code here - ie., code which assumes
44  *   that certain things happen before others. In particular, the code which
45  *   happens at the boundary between sections is delicately poised, so be
46  *   careful!
47  *
48  */
49
50 #include "includes.h"
51
52 BOOL bLoaded = False;
53
54 extern int DEBUGLEVEL;
55 extern pstring user_socket_options;
56 extern pstring myname;
57
58 #ifndef GLOBAL_NAME
59 #define GLOBAL_NAME "global"
60 #endif
61
62 #ifndef PRINTCAP_NAME
63 #ifdef AIX
64 #define PRINTCAP_NAME "/etc/qconfig"
65 #else
66 #define PRINTCAP_NAME "/etc/printcap"
67 #endif
68 #endif
69
70 #ifndef PRINTERS_NAME
71 #define PRINTERS_NAME "printers"
72 #endif
73
74 #ifndef HOMES_NAME
75 #define HOMES_NAME "homes"
76 #endif
77
78 /* some helpful bits */
79 #define pSERVICE(i) ServicePtrs[i]
80 #define iSERVICE(i) (*pSERVICE(i))
81 #define LP_SNUM_OK(iService) (((iService) >= 0) && ((iService) < iNumServices) && iSERVICE(iService).valid)
82 #define VALID(i) iSERVICE(i).valid
83
84 /* these are the types of parameter we have */
85 typedef enum
86 {
87   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
88   P_STRING,P_USTRING,P_GSTRING,P_UGSTRING
89 } parm_type;
90
91 typedef enum
92 {
93   P_LOCAL,P_GLOBAL,P_NONE
94 } parm_class;
95
96 int keepalive=0;
97 extern BOOL use_getwd_cache;
98
99 extern int extra_time_offset;
100 #ifdef KANJI
101 extern int coding_system;
102 #endif
103
104 /* 
105  * This structure describes global (ie., server-wide) parameters.
106  */
107 typedef struct
108 {
109   char *szPrintcapname;
110   char *szLockDir;
111   char *szRootdir;
112   char *szDefaultService;
113   char *szDfree;
114   char *szMsgCommand;
115   char *szHostsEquiv;
116   char *szServerString;
117   char *szAutoServices;
118   char *szPasswdProgram;
119   char *szPasswdChat;
120   char *szLogFile;
121   char *szConfigFile;
122   char *szSMBPasswdFile;
123   char *szPasswordServer;
124   char *szSocketOptions;
125   char *szValidChars;
126   char *szWorkGroup;
127   char *szDomainController;
128   char *szUsernameMap;
129   char *szCharacterSet;
130   char *szLogonScript;
131   char *szLogonPath;
132   char *szVetoFiles;
133   char *szSmbrun;
134   char *szWINSserver;
135   char *szInterfaces;
136   char *szRemoteAnnounce;
137   char *szSocketAddress;
138   char *szNISHomeMapName;
139   int max_log_size;
140   int mangled_stack;
141   int max_xmit;
142   int max_mux;
143   int max_packet;
144   int pwordlevel;
145   int deadtime;
146   int maxprotocol;
147   int security;
148   int printing;
149   int maxdisksize;
150   int lpqcachetime;
151   int syslog;
152   int os_level;
153   int max_ttl;
154   int ReadSize;
155   int shmem_size;
156   int shmem_hash_size;
157   int client_code_page;
158   BOOL bWINSsupport;
159   BOOL bWINSproxy;
160   BOOL bLocalMaster;
161   BOOL bPreferredMaster;
162   BOOL bDomainMaster;
163   BOOL bDomainLogons;
164   BOOL bEncryptPasswords;
165   BOOL bStripDot;
166   BOOL bNullPasswords;
167   BOOL bLoadPrinters;
168   BOOL bUseRhosts;
169   BOOL bReadRaw;
170   BOOL bWriteRaw;
171   BOOL bReadPrediction;
172   BOOL bReadbmpx;
173   BOOL bSyslogOnly;
174   BOOL bBrowseList;
175   BOOL bUnixRealname;
176   BOOL bNISHomeMap;
177 } global;
178
179 static global Globals;
180
181
182
183 /* 
184  * This structure describes a single service. 
185  */
186 typedef struct
187 {
188   BOOL valid;
189   char *szService;
190   char *szPath;
191   char *szUsername;
192   char *szGuestaccount;
193   char *szInvalidUsers;
194   char *szValidUsers;
195   char *szAdminUsers;
196   char *szCopy;
197   char *szInclude;
198   char *szPreExec;
199   char *szPostExec;
200   char *szRootPreExec;
201   char *szRootPostExec;
202   char *szPrintcommand;
203   char *szLpqcommand;
204   char *szLprmcommand;
205   char *szLppausecommand;
206   char *szLpresumecommand;
207   char *szPrintername;
208   char *szPrinterDriver;
209   char *szDontdescend;
210   char *szHostsallow;
211   char *szHostsdeny;
212   char *szMagicScript;
213   char *szMagicOutput;
214   char *szMangledMap;
215   char *comment;
216   char *force_user;
217   char *force_group;
218   char *readlist;
219   char *writelist;
220   char *volume;
221   int  iMinPrintSpace;
222   int  iCreate_mode;
223   int  iDir_mode;
224   int  iMaxConnections;
225   int  iDefaultCase;
226   BOOL bAlternatePerm;
227   BOOL bRevalidate;
228   BOOL bCaseSensitive;
229   BOOL bCasePreserve;
230   BOOL bShortCasePreserve;
231   BOOL bCaseMangle;
232   BOOL status;
233   BOOL bHideDotFiles;
234   BOOL bBrowseable;
235   BOOL bAvailable;
236   BOOL bRead_only;
237   BOOL bNo_set_dir;
238   BOOL bGuest_only;
239   BOOL bGuest_ok;
240   BOOL bPrint_ok;
241   BOOL bPostscript;
242   BOOL bMap_system;
243   BOOL bMap_hidden;
244   BOOL bMap_archive;
245   BOOL bLocking;
246   BOOL bStrictLocking;
247   BOOL bShareModes;
248   BOOL bOnlyUser;
249   BOOL bMangledNames;
250   BOOL bWidelinks;
251   BOOL bSyncAlways;
252   char magic_char;
253   BOOL *copymap;
254   BOOL bDeleteReadonly;
255   BOOL bFakeOplocks;
256   char dummy[3]; /* for alignment */
257 } service;
258
259
260 /* This is a default service used to prime a services structure */
261 static service sDefault = 
262 {
263   True,   /* valid */
264   NULL,    /* szService */
265   NULL,    /* szPath */
266   NULL,    /* szUsername */
267   NULL,    /* szGuestAccount */
268   NULL,    /* szInvalidUsers */
269   NULL,    /* szValidUsers */
270   NULL,    /* szAdminUsers */
271   NULL,    /* szCopy */
272   NULL,    /* szInclude */
273   NULL,    /* szPreExec */
274   NULL,    /* szPostExec */
275   NULL,    /* szRootPreExec */
276   NULL,    /* szRootPostExec */
277   NULL,    /* szPrintcommand */
278   NULL,    /* szLpqcommand */
279   NULL,    /* szLprmcommand */
280   NULL,    /* szLppausecommand */
281   NULL,    /* szLpresumecommand */
282   NULL,    /* szPrintername */
283   NULL,    /* szPrinterDriver */
284   NULL,    /* szDontdescend */
285   NULL,    /* szHostsallow */
286   NULL,    /* szHostsdeny */
287   NULL,    /* szMagicScript */
288   NULL,    /* szMagicOutput */
289   NULL,    /* szMangledMap */
290   NULL,    /* comment */
291   NULL,    /* force user */
292   NULL,    /* force group */
293   NULL,    /* readlist */
294   NULL,    /* writelist */
295   NULL,    /* volume */
296   0,       /* iMinPrintSpace */
297   0644,    /* iCreate_mode */
298   0755,    /* iDir_mode */
299   0,       /* iMaxConnections */
300   CASE_LOWER, /* iDefaultCase */
301   False,   /* bAlternatePerm */
302   False,   /* revalidate */
303   False,   /* case sensitive */
304   False,   /* case preserve */
305   False,   /* short case preserve */
306   False,  /* case mangle */
307   True,  /* status */
308   True,  /* bHideDotFiles */
309   True,  /* bBrowseable */
310   True,  /* bAvailable */
311   True,  /* bRead_only */
312   True,  /* bNo_set_dir */
313   False, /* bGuest_only */
314   False, /* bGuest_ok */
315   False, /* bPrint_ok */
316   False, /* bPostscript */
317   False, /* bMap_system */
318   False, /* bMap_hidden */
319   True,  /* bMap_archive */
320   True,  /* bLocking */
321   False,  /* bStrictLocking */
322   True,  /* bShareModes */
323   False, /* bOnlyUser */
324   True,  /* bMangledNames */
325   True,  /* bWidelinks */
326   False, /* bSyncAlways */
327   '~',   /* magic char */
328   NULL,  /* copymap */
329   False, /* bDeleteReadonly */
330   False, /* bFakeOplocks */
331   ""     /* dummy */
332 };
333
334
335
336 /* local variables */
337 static service **ServicePtrs = NULL;
338 static int iNumServices = 0;
339 static int iServiceIndex = 0;
340 static BOOL bInGlobalSection = True;
341 static BOOL bGlobalOnly = False;
342
343
344 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
345
346 /* prototypes for the special type handlers */
347 static BOOL handle_valid_chars(char *pszParmValue, char **ptr);
348 static BOOL handle_include(char *pszParmValue, char **ptr);
349 static BOOL handle_copy(char *pszParmValue, char **ptr);
350 static BOOL handle_protocol(char *pszParmValue,int *val);
351 static BOOL handle_security(char *pszParmValue,int *val);
352 static BOOL handle_case(char *pszParmValue,int *val);
353 static BOOL handle_printing(char *pszParmValue,int *val);
354 static BOOL handle_character_set(char *pszParmValue,int *val);
355 #ifdef KANJI
356 static BOOL handle_coding_system(char *pszParmValue,int *val);
357 #endif /* KANJI */
358
359 struct parm_struct
360 {
361   char *label;
362   parm_type type;
363   parm_class class;
364   void *ptr;
365   BOOL (*special)();
366 } parm_table[] =
367 {
368   {"debuglevel",       P_INTEGER, P_GLOBAL, &DEBUGLEVEL,                NULL},
369   {"log level",        P_INTEGER, P_GLOBAL, &DEBUGLEVEL,                NULL},
370   {"syslog",           P_INTEGER, P_GLOBAL, &Globals.syslog,            NULL},
371   {"syslog only",      P_BOOL,    P_GLOBAL, &Globals.bSyslogOnly,       NULL},
372   {"protocol",         P_INTEGER, P_GLOBAL, &Globals.maxprotocol,handle_protocol},
373   {"security",         P_INTEGER, P_GLOBAL, &Globals.security,handle_security},
374   {"printing",         P_INTEGER, P_GLOBAL, &Globals.printing,handle_printing},
375   {"max disk size",    P_INTEGER, P_GLOBAL, &Globals.maxdisksize,       NULL},
376   {"lpq cache time",   P_INTEGER, P_GLOBAL, &Globals.lpqcachetime,      NULL},
377   {"encrypt passwords",P_BOOL,    P_GLOBAL, &Globals.bEncryptPasswords, NULL},
378   {"getwd cache",      P_BOOL,    P_GLOBAL, &use_getwd_cache,           NULL},
379   {"read prediction",  P_BOOL,    P_GLOBAL, &Globals.bReadPrediction,   NULL},
380   {"read bmpx",        P_BOOL,    P_GLOBAL, &Globals.bReadbmpx,         NULL},
381   {"read raw",         P_BOOL,    P_GLOBAL, &Globals.bReadRaw,          NULL},
382   {"write raw",        P_BOOL,    P_GLOBAL, &Globals.bWriteRaw,         NULL},
383   {"use rhosts",       P_BOOL,    P_GLOBAL, &Globals.bUseRhosts,        NULL},
384   {"load printers",    P_BOOL,    P_GLOBAL, &Globals.bLoadPrinters,     NULL},
385   {"null passwords",   P_BOOL,    P_GLOBAL, &Globals.bNullPasswords,    NULL},
386   {"strip dot",        P_BOOL,    P_GLOBAL, &Globals.bStripDot,         NULL},
387   {"interfaces",       P_STRING,  P_GLOBAL, &Globals.szInterfaces,      NULL},
388   {"password server",  P_STRING,  P_GLOBAL, &Globals.szPasswordServer,  NULL},
389   {"socket options",   P_GSTRING, P_GLOBAL, user_socket_options,        NULL},
390   {"netbios name",     P_UGSTRING,P_GLOBAL, myname,                     NULL},
391   {"smbrun",           P_STRING,  P_GLOBAL, &Globals.szSmbrun,          NULL},
392   {"veto files",       P_STRING,  P_GLOBAL, &Globals.szVetoFiles,       NULL},
393   {"log file",         P_STRING,  P_GLOBAL, &Globals.szLogFile,         NULL},
394   {"config file",      P_STRING,  P_GLOBAL, &Globals.szConfigFile,      NULL},
395   {"smb passwd file",  P_STRING,  P_GLOBAL, &Globals.szSMBPasswdFile,   NULL},
396   {"hosts equiv",      P_STRING,  P_GLOBAL, &Globals.szHostsEquiv,      NULL},
397   {"preload",          P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
398   {"auto services",    P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
399   {"server string",    P_STRING,  P_GLOBAL, &Globals.szServerString,    NULL},
400   {"printcap name",    P_STRING,  P_GLOBAL, &Globals.szPrintcapname,    NULL},
401   {"printcap",         P_STRING,  P_GLOBAL, &Globals.szPrintcapname,    NULL},
402   {"lock dir",         P_STRING,  P_GLOBAL, &Globals.szLockDir,         NULL},
403   {"lock directory",   P_STRING,  P_GLOBAL, &Globals.szLockDir,         NULL},
404   {"root directory",   P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
405   {"root dir",         P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
406   {"root",             P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
407   {"default service",  P_STRING,  P_GLOBAL, &Globals.szDefaultService,  NULL},
408   {"default",          P_STRING,  P_GLOBAL, &Globals.szDefaultService,  NULL},
409   {"message command",  P_STRING,  P_GLOBAL, &Globals.szMsgCommand,      NULL},
410   {"dfree command",    P_STRING,  P_GLOBAL, &Globals.szDfree,           NULL},
411   {"passwd program",   P_STRING,  P_GLOBAL, &Globals.szPasswdProgram,   NULL},
412   {"passwd chat",      P_STRING,  P_GLOBAL, &Globals.szPasswdChat,      NULL},
413   {"valid chars",      P_STRING,  P_GLOBAL, &Globals.szValidChars,      handle_valid_chars},
414   {"workgroup",        P_USTRING, P_GLOBAL, &Globals.szWorkGroup,       NULL},
415   {"domain controller",P_STRING,  P_GLOBAL, &Globals.szDomainController,NULL},
416   {"username map",     P_STRING,  P_GLOBAL, &Globals.szUsernameMap,     NULL},
417   {"character set",    P_STRING,  P_GLOBAL, &Globals.szCharacterSet,    handle_character_set},
418   {"logon script",     P_STRING,  P_GLOBAL, &Globals.szLogonScript,     NULL},
419   {"logon path",       P_STRING,  P_GLOBAL, &Globals.szLogonPath,       NULL},
420   {"remote announce",  P_STRING,  P_GLOBAL, &Globals.szRemoteAnnounce,  NULL},
421   {"socket address",   P_STRING,  P_GLOBAL, &Globals.szSocketAddress,   NULL},
422   {"homedir map",      P_STRING,  P_GLOBAL, &Globals.szNISHomeMapName,  NULL},
423   {"max log size",     P_INTEGER, P_GLOBAL, &Globals.max_log_size,      NULL},
424   {"mangled stack",    P_INTEGER, P_GLOBAL, &Globals.mangled_stack,     NULL},
425   {"max mux",          P_INTEGER, P_GLOBAL, &Globals.max_mux,           NULL},
426   {"max xmit",         P_INTEGER, P_GLOBAL, &Globals.max_xmit,          NULL},
427   {"max packet",       P_INTEGER, P_GLOBAL, &Globals.max_packet,        NULL},
428   {"packet size",      P_INTEGER, P_GLOBAL, &Globals.max_packet,        NULL},
429   {"password level",   P_INTEGER, P_GLOBAL, &Globals.pwordlevel,        NULL},
430   {"keepalive",        P_INTEGER, P_GLOBAL, &keepalive,                 NULL},
431   {"deadtime",         P_INTEGER, P_GLOBAL, &Globals.deadtime,          NULL},
432   {"time offset",      P_INTEGER, P_GLOBAL, &extra_time_offset,         NULL},
433   {"read size",        P_INTEGER, P_GLOBAL, &Globals.ReadSize,          NULL},
434   {"shared mem size",  P_INTEGER, P_GLOBAL, &Globals.shmem_size,        NULL},
435   {"shared file entries",  P_INTEGER, P_GLOBAL, &Globals.shmem_hash_size, NULL},
436 #ifdef KANJI
437   {"coding system",    P_INTEGER, P_GLOBAL, &coding_system, handle_coding_system},
438 #endif /* KANJI */
439   {"client code page", P_INTEGER, P_GLOBAL, &Globals.client_code_page,  NULL},
440   {"os level",         P_INTEGER, P_GLOBAL, &Globals.os_level,          NULL},
441   {"max ttl",          P_INTEGER, P_GLOBAL, &Globals.max_ttl,           NULL},
442   {"wins support",     P_BOOL,    P_GLOBAL, &Globals.bWINSsupport,      NULL},
443   {"wins proxy",       P_BOOL,    P_GLOBAL, &Globals.bWINSproxy,        NULL},
444   {"wins server",      P_STRING,  P_GLOBAL, &Globals.szWINSserver,      NULL},
445   {"preferred master", P_BOOL,    P_GLOBAL, &Globals.bPreferredMaster,  NULL},
446   {"prefered master",  P_BOOL,    P_GLOBAL, &Globals.bPreferredMaster,  NULL},
447   {"local master",     P_BOOL,    P_GLOBAL, &Globals.bLocalMaster,      NULL},
448   {"domain master",    P_BOOL,    P_GLOBAL, &Globals.bDomainMaster,     NULL},
449   {"domain logons",    P_BOOL,    P_GLOBAL, &Globals.bDomainLogons,     NULL},
450   {"browse list",      P_BOOL,    P_GLOBAL, &Globals.bBrowseList,       NULL},
451   {"unix realname",    P_BOOL,    P_GLOBAL, &Globals.bUnixRealname,     NULL},
452   {"NIS homedir",      P_BOOL,    P_GLOBAL, &Globals.bNISHomeMap,       NULL},
453   {"-valid",           P_BOOL,    P_LOCAL,  &sDefault.valid,            NULL},
454   {"comment",          P_STRING,  P_LOCAL,  &sDefault.comment,          NULL},
455   {"copy",             P_STRING,  P_LOCAL,  &sDefault.szCopy,    handle_copy},
456   {"include",          P_STRING,  P_LOCAL,  &sDefault.szInclude, handle_include},
457   {"exec",             P_STRING,  P_LOCAL,  &sDefault.szPreExec,        NULL},
458   {"preexec",          P_STRING,  P_LOCAL,  &sDefault.szPreExec,        NULL},
459   {"postexec",         P_STRING,  P_LOCAL,  &sDefault.szPostExec,       NULL},
460   {"root preexec",     P_STRING,  P_LOCAL,  &sDefault.szRootPreExec,    NULL},
461   {"root postexec",    P_STRING,  P_LOCAL,  &sDefault.szRootPostExec,   NULL},
462   {"alternate permissions",P_BOOL,P_LOCAL,  &sDefault.bAlternatePerm,   NULL},
463   {"revalidate",       P_BOOL,    P_LOCAL,  &sDefault.bRevalidate,      NULL},
464   {"default case",     P_INTEGER, P_LOCAL,  &sDefault.iDefaultCase,   handle_case},
465   {"case sensitive",   P_BOOL,    P_LOCAL,  &sDefault.bCaseSensitive,   NULL},
466   {"casesignames",     P_BOOL,    P_LOCAL,  &sDefault.bCaseSensitive,   NULL},
467   {"preserve case",    P_BOOL,    P_LOCAL,  &sDefault.bCasePreserve,    NULL},
468   {"short preserve case",P_BOOL,  P_LOCAL,  &sDefault.bShortCasePreserve,NULL},
469   {"mangle case",      P_BOOL,    P_LOCAL,  &sDefault.bCaseMangle,      NULL},
470   {"mangling char",    P_CHAR,    P_LOCAL,  &sDefault.magic_char,       NULL},
471   {"browseable",       P_BOOL,    P_LOCAL,  &sDefault.bBrowseable,      NULL},
472   {"browsable",        P_BOOL,    P_LOCAL,  &sDefault.bBrowseable,      NULL},
473   {"available",        P_BOOL,    P_LOCAL,  &sDefault.bAvailable,       NULL},
474   {"path",             P_STRING,  P_LOCAL,  &sDefault.szPath,           NULL},
475   {"directory",        P_STRING,  P_LOCAL,  &sDefault.szPath,           NULL},
476   {"username",         P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
477   {"user",             P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
478   {"users",            P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
479   {"guest account",    P_STRING,  P_LOCAL,  &sDefault.szGuestaccount,   NULL},
480   {"invalid users",    P_STRING,  P_LOCAL,  &sDefault.szInvalidUsers,   NULL},
481   {"valid users",      P_STRING,  P_LOCAL,  &sDefault.szValidUsers,     NULL},
482   {"admin users",      P_STRING,  P_LOCAL,  &sDefault.szAdminUsers,     NULL},
483   {"read list",        P_STRING,  P_LOCAL,  &sDefault.readlist,         NULL},
484   {"write list",       P_STRING,  P_LOCAL,  &sDefault.writelist,        NULL},
485   {"volume",           P_STRING,  P_LOCAL,  &sDefault.volume,           NULL},
486   {"force user",       P_STRING,  P_LOCAL,  &sDefault.force_user,       NULL},
487   {"force group",      P_STRING,  P_LOCAL,  &sDefault.force_group,      NULL},
488   {"group",            P_STRING,  P_LOCAL,  &sDefault.force_group,      NULL},
489   {"read only",        P_BOOL,    P_LOCAL,  &sDefault.bRead_only,       NULL},
490   {"write ok",         P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
491   {"writeable",        P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
492   {"writable",         P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
493   {"max connections",  P_INTEGER, P_LOCAL,  &sDefault.iMaxConnections,  NULL},
494   {"min print space",  P_INTEGER, P_LOCAL,  &sDefault.iMinPrintSpace,   NULL},
495   {"create mask",      P_OCTAL,   P_LOCAL,  &sDefault.iCreate_mode,     NULL},
496   {"create mode",      P_OCTAL,   P_LOCAL,  &sDefault.iCreate_mode,     NULL},
497   {"directory mask",   P_OCTAL,   P_LOCAL,  &sDefault.iDir_mode,        NULL},
498   {"directory mode",   P_OCTAL,   P_LOCAL,  &sDefault.iDir_mode,        NULL},
499   {"set directory",    P_BOOLREV, P_LOCAL,  &sDefault.bNo_set_dir,      NULL},
500   {"status",           P_BOOL,    P_LOCAL,  &sDefault.status,           NULL},
501   {"hide dot files",   P_BOOL,    P_LOCAL,  &sDefault.bHideDotFiles,    NULL},
502   {"guest only",       P_BOOL,    P_LOCAL,  &sDefault.bGuest_only,      NULL},
503   {"only guest",       P_BOOL,    P_LOCAL,  &sDefault.bGuest_only,      NULL},
504   {"guest ok",         P_BOOL,    P_LOCAL,  &sDefault.bGuest_ok,        NULL},
505   {"public",           P_BOOL,    P_LOCAL,  &sDefault.bGuest_ok,        NULL},
506   {"print ok",         P_BOOL,    P_LOCAL,  &sDefault.bPrint_ok,        NULL},
507   {"printable",        P_BOOL,    P_LOCAL,  &sDefault.bPrint_ok,        NULL},
508   {"postscript",       P_BOOL,    P_LOCAL,  &sDefault.bPostscript,      NULL},
509   {"map system",       P_BOOL,    P_LOCAL,  &sDefault.bMap_system,      NULL},
510   {"map hidden",       P_BOOL,    P_LOCAL,  &sDefault.bMap_hidden,      NULL},
511   {"map archive",      P_BOOL,    P_LOCAL,  &sDefault.bMap_archive,     NULL},
512   {"locking",          P_BOOL,    P_LOCAL,  &sDefault.bLocking,         NULL},
513   {"strict locking",   P_BOOL,    P_LOCAL,  &sDefault.bStrictLocking,   NULL},
514   {"share modes",      P_BOOL,    P_LOCAL,  &sDefault.bShareModes,      NULL},
515   {"only user",        P_BOOL,    P_LOCAL,  &sDefault.bOnlyUser,        NULL},
516   {"wide links",       P_BOOL,    P_LOCAL,  &sDefault.bWidelinks,       NULL},
517   {"sync always",      P_BOOL,    P_LOCAL,  &sDefault.bSyncAlways,      NULL},
518   {"mangled names",    P_BOOL,    P_LOCAL,  &sDefault.bMangledNames,    NULL},
519   {"fake oplocks",     P_BOOL,    P_LOCAL,  &sDefault.bFakeOplocks,     NULL},
520   {"print command",    P_STRING,  P_LOCAL,  &sDefault.szPrintcommand,   NULL},
521   {"lpq command",      P_STRING,  P_LOCAL,  &sDefault.szLpqcommand,     NULL},
522   {"lprm command",     P_STRING,  P_LOCAL,  &sDefault.szLprmcommand,    NULL},
523   {"lppause command",  P_STRING,  P_LOCAL,  &sDefault.szLppausecommand, NULL},
524   {"lpresume command", P_STRING,  P_LOCAL,  &sDefault.szLpresumecommand,NULL},
525   {"printer",          P_STRING,  P_LOCAL,  &sDefault.szPrintername,    NULL},
526   {"printer name",     P_STRING,  P_LOCAL,  &sDefault.szPrintername,    NULL},
527   {"printer driver",   P_STRING,  P_LOCAL,  &sDefault.szPrinterDriver,  NULL},
528   {"hosts allow",      P_STRING,  P_LOCAL,  &sDefault.szHostsallow,     NULL},
529   {"allow hosts",      P_STRING,  P_LOCAL,  &sDefault.szHostsallow,     NULL},
530   {"hosts deny",       P_STRING,  P_LOCAL,  &sDefault.szHostsdeny,      NULL},
531   {"deny hosts",       P_STRING,  P_LOCAL,  &sDefault.szHostsdeny,      NULL},
532   {"dont descend",     P_STRING,  P_LOCAL,  &sDefault.szDontdescend,    NULL},
533   {"magic script",     P_STRING,  P_LOCAL,  &sDefault.szMagicScript,    NULL},
534   {"magic output",     P_STRING,  P_LOCAL,  &sDefault.szMagicOutput,    NULL},
535   {"mangled map",      P_STRING,  P_LOCAL,  &sDefault.szMangledMap,     NULL},
536   {"delete readonly",  P_BOOL,    P_LOCAL,  &sDefault.bDeleteReadonly,  NULL},
537
538   {NULL,               P_BOOL,    P_NONE,   NULL,                       NULL}
539 };
540
541
542
543 /***************************************************************************
544 Initialise the global parameter structure.
545 ***************************************************************************/
546 static void init_globals(void)
547 {
548   static BOOL done_init = False;
549   pstring s;
550
551   if (!done_init)
552     {
553       int i;
554       bzero((void *)&Globals,sizeof(Globals));
555
556       for (i = 0; parm_table[i].label; i++) 
557         if ((parm_table[i].type == P_STRING ||
558              parm_table[i].type == P_USTRING) && 
559             parm_table[i].ptr)
560           string_init(parm_table[i].ptr,"");
561
562       string_set(&sDefault.szGuestaccount, GUEST_ACCOUNT);
563       string_set(&sDefault.szPrinterDriver, "NULL");
564
565       done_init = True;
566     }
567
568
569   DEBUG(3,("Initialising global parameters\n"));
570
571 #ifdef SMB_PASSWD_FILE
572   string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
573 #endif
574   string_set(&Globals.szPasswdChat,"*old*password* %o\\n *new*password* %n\\n *new*password* %n\\n *changed*");
575   string_set(&Globals.szWorkGroup, WORKGROUP);
576 #ifdef SMB_PASSWD
577   string_set(&Globals.szPasswdProgram, SMB_PASSWD);
578 #else
579   string_set(&Globals.szPasswdProgram, "/bin/passwd");
580 #endif
581   string_set(&Globals.szPrintcapname, PRINTCAP_NAME);
582   string_set(&Globals.szLockDir, LOCKDIR);
583   string_set(&Globals.szRootdir, "/");
584   string_set(&Globals.szSmbrun, SMBRUN);
585   string_set(&Globals.szSocketAddress, "0.0.0.0");
586   sprintf(s,"Samba %s",VERSION);
587   string_set(&Globals.szServerString,s);
588   Globals.bLoadPrinters = True;
589   Globals.bUseRhosts = False;
590   Globals.max_packet = 65535;
591   Globals.mangled_stack = 50;
592   Globals.max_xmit = 65535;
593   Globals.max_mux = 2;
594   Globals.lpqcachetime = 10;
595   Globals.pwordlevel = 0;
596   Globals.deadtime = 0;
597   Globals.max_log_size = 5000;
598   Globals.maxprotocol = PROTOCOL_NT1;
599   Globals.security = SEC_SHARE;
600   Globals.bEncryptPasswords = False;
601   Globals.printing = DEFAULT_PRINTING;
602   Globals.bReadRaw = True;
603   Globals.bWriteRaw = True;
604   Globals.bReadPrediction = False;
605   Globals.bReadbmpx = True;
606   Globals.bNullPasswords = False;
607   Globals.bStripDot = False;
608   Globals.syslog = 1;
609   Globals.bSyslogOnly = False;
610   Globals.os_level = 0;
611   Globals.max_ttl = 60*60*4; /* 2 hours default */
612   Globals.ReadSize = 16*1024;
613   Globals.shmem_size = SHMEM_SIZE;
614   Globals.shmem_hash_size = SHMEM_HASH_SIZE;
615   Globals.bUnixRealname = False;
616 #if (defined(NETGROUP) && defined(AUTOMOUNT))
617   Globals.bNISHomeMap = False;
618   string_set(&Globals.szNISHomeMapName, "auto.home");
619 #endif
620 #ifdef KANJI
621   coding_system = interpret_coding_system (KANJI, SJIS_CODE);
622 #endif /* KANJI */
623   Globals.client_code_page = DEFAULT_CLIENT_CODE_PAGE;
624
625 /* these parameters are set to defaults that are more appropriate
626    for the increasing samba install base:
627
628    as a member of the workgroup, that will possibly become a
629    _local_ master browser (lm = True).  this is opposed to a forced
630    local master browser startup (pm = True).
631
632    doesn't provide WINS server service by default (wsupp = False),
633    and doesn't provide domain master browser services by default, either.
634
635 */
636
637   Globals.bPreferredMaster = False;
638   Globals.bLocalMaster = True;
639   Globals.bDomainMaster = False;
640   Globals.bDomainLogons = False;
641   Globals.bBrowseList = True;
642   Globals.bWINSsupport = False;
643   Globals.bWINSproxy = False;
644 }
645
646 /***************************************************************************
647 check if a string is initialised and if not then initialise it
648 ***************************************************************************/
649 static void string_initial(char **s,char *v)
650 {
651   if (!*s || !**s)
652     string_init(s,v);
653 }
654
655
656 /***************************************************************************
657 Initialise the sDefault parameter structure.
658 ***************************************************************************/
659 static void init_locals(void)
660 {
661   /* choose defaults depending on the type of printing */
662   switch (Globals.printing)
663     {
664     case PRINT_BSD:
665     case PRINT_AIX:
666     case PRINT_LPRNG:
667     case PRINT_PLP:
668       string_initial(&sDefault.szLpqcommand,"lpq -P%p");
669       string_initial(&sDefault.szLprmcommand,"lprm -P%p %j");
670       string_initial(&sDefault.szPrintcommand,"lpr -r -P%p %s");
671       break;
672
673     case PRINT_SYSV:
674     case PRINT_HPUX:
675       string_initial(&sDefault.szLpqcommand,"lpstat -o%p");
676       string_initial(&sDefault.szLprmcommand,"cancel %p-%j");
677       string_initial(&sDefault.szPrintcommand,"lp -c -d%p %s; rm %s");
678 #ifdef SVR4
679       string_initial(&sDefault.szLppausecommand,"lp -i %p-%j -H hold");
680       string_initial(&sDefault.szLpresumecommand,"lp -i %p-%j -H resume");
681 #endif
682       break;
683
684     case PRINT_QNX:
685       string_initial(&sDefault.szLpqcommand,"lpq -P%p");
686       string_initial(&sDefault.szLprmcommand,"lprm -P%p %j");
687       string_initial(&sDefault.szPrintcommand,"lp -r -P%p %s");
688       break;
689
690       
691     }
692 }
693
694
695 /******************************************************************* a
696 convenience routine to grab string parameters into a rotating buffer,
697 and run standard_sub_basic on them. The buffers can be written to by
698 callers without affecting the source string.
699 ********************************************************************/
700 char *lp_string(char *s)
701 {
702   static char *bufs[10];
703   static int buflen[10];
704   static int next = -1;  
705   char *ret;
706   int i;
707   int len = s?strlen(s):0;
708
709   if (next == -1) {
710     /* initialisation */
711     for (i=0;i<10;i++) {
712       bufs[i] = NULL;
713       buflen[i] = 0;
714     }
715     next = 0;
716   }
717
718   len = MAX(len+100,sizeof(pstring)); /* the +100 is for some
719                                          substitution room */
720
721   if (buflen[next] != len) {
722     buflen[next] = len;
723     if (bufs[next]) free(bufs[next]);
724     bufs[next] = (char *)malloc(len);
725     if (!bufs[next]) {
726       DEBUG(0,("out of memory in lp_string()"));
727       exit(1);
728     }
729   } 
730
731   ret = &bufs[next][0];
732   next = (next+1)%10;
733
734   if (!s) 
735     *ret = 0;
736   else
737     StrCpy(ret,s);
738
739   standard_sub_basic(ret);
740   return(ret);
741 }
742
743
744 /*
745    In this section all the functions that are used to access the 
746    parameters from the rest of the program are defined 
747 */
748
749 #define FN_GLOBAL_STRING(fn_name,ptr) \
750  char *fn_name(void) {return(lp_string(*(char **)(ptr) ? *(char **)(ptr) : ""));}
751 #define FN_GLOBAL_BOOL(fn_name,ptr) \
752  BOOL fn_name(void) {return(*(BOOL *)(ptr));}
753 #define FN_GLOBAL_CHAR(fn_name,ptr) \
754  char fn_name(void) {return(*(char *)(ptr));}
755 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
756  int fn_name(void) {return(*(int *)(ptr));}
757
758 #define FN_LOCAL_STRING(fn_name,val) \
759  char *fn_name(int i) {return(lp_string((LP_SNUM_OK(i)&&pSERVICE(i)->val)?pSERVICE(i)->val : sDefault.val));}
760 #define FN_LOCAL_BOOL(fn_name,val) \
761  BOOL fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
762 #define FN_LOCAL_CHAR(fn_name,val) \
763  char fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
764 #define FN_LOCAL_INTEGER(fn_name,val) \
765  int fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
766
767 FN_GLOBAL_STRING(lp_logfile,&Globals.szLogFile)
768 FN_GLOBAL_STRING(lp_smbrun,&Globals.szSmbrun)
769 FN_GLOBAL_STRING(lp_configfile,&Globals.szConfigFile)
770 FN_GLOBAL_STRING(lp_smb_passwd_file,&Globals.szSMBPasswdFile)
771 FN_GLOBAL_STRING(lp_serverstring,&Globals.szServerString)
772 FN_GLOBAL_STRING(lp_printcapname,&Globals.szPrintcapname)
773 FN_GLOBAL_STRING(lp_lockdir,&Globals.szLockDir)
774 FN_GLOBAL_STRING(lp_rootdir,&Globals.szRootdir)
775 FN_GLOBAL_STRING(lp_defaultservice,&Globals.szDefaultService)
776 FN_GLOBAL_STRING(lp_msg_command,&Globals.szMsgCommand)
777 FN_GLOBAL_STRING(lp_dfree_command,&Globals.szDfree)
778 FN_GLOBAL_STRING(lp_hosts_equiv,&Globals.szHostsEquiv)
779 FN_GLOBAL_STRING(lp_auto_services,&Globals.szAutoServices)
780 FN_GLOBAL_STRING(lp_passwd_program,&Globals.szPasswdProgram)
781 FN_GLOBAL_STRING(lp_passwd_chat,&Globals.szPasswdChat)
782 FN_GLOBAL_STRING(lp_passwordserver,&Globals.szPasswordServer)
783 FN_GLOBAL_STRING(lp_workgroup,&Globals.szWorkGroup)
784 FN_GLOBAL_STRING(lp_domain_controller,&Globals.szDomainController)
785 FN_GLOBAL_STRING(lp_username_map,&Globals.szUsernameMap)
786 FN_GLOBAL_STRING(lp_character_set,&Globals.szCharacterSet) 
787 FN_GLOBAL_STRING(lp_logon_script,&Globals.szLogonScript) 
788 FN_GLOBAL_STRING(lp_logon_path,&Globals.szLogonPath) 
789 FN_GLOBAL_STRING(lp_veto_files,&Globals.szVetoFiles)
790 FN_GLOBAL_STRING(lp_remote_announce,&Globals.szRemoteAnnounce) 
791 FN_GLOBAL_STRING(lp_wins_server,&Globals.szWINSserver)
792 FN_GLOBAL_STRING(lp_interfaces,&Globals.szInterfaces)
793 FN_GLOBAL_STRING(lp_socket_address,&Globals.szSocketAddress)
794 FN_GLOBAL_STRING(lp_nis_home_map_name,&Globals.szNISHomeMapName)
795
796 FN_GLOBAL_BOOL(lp_wins_support,&Globals.bWINSsupport)
797 FN_GLOBAL_BOOL(lp_wins_proxy,&Globals.bWINSproxy)
798 FN_GLOBAL_BOOL(lp_local_master,&Globals.bLocalMaster)
799 FN_GLOBAL_BOOL(lp_domain_master,&Globals.bDomainMaster)
800 FN_GLOBAL_BOOL(lp_domain_logons,&Globals.bDomainLogons)
801 FN_GLOBAL_BOOL(lp_preferred_master,&Globals.bPreferredMaster)
802 FN_GLOBAL_BOOL(lp_load_printers,&Globals.bLoadPrinters)
803 FN_GLOBAL_BOOL(lp_use_rhosts,&Globals.bUseRhosts)
804 FN_GLOBAL_BOOL(lp_getwdcache,&use_getwd_cache)
805 FN_GLOBAL_BOOL(lp_readprediction,&Globals.bReadPrediction)
806 FN_GLOBAL_BOOL(lp_readbmpx,&Globals.bReadbmpx)
807 FN_GLOBAL_BOOL(lp_readraw,&Globals.bReadRaw)
808 FN_GLOBAL_BOOL(lp_writeraw,&Globals.bWriteRaw)
809 FN_GLOBAL_BOOL(lp_null_passwords,&Globals.bNullPasswords)
810 FN_GLOBAL_BOOL(lp_strip_dot,&Globals.bStripDot)
811 FN_GLOBAL_BOOL(lp_encrypted_passwords,&Globals.bEncryptPasswords)
812 FN_GLOBAL_BOOL(lp_syslog_only,&Globals.bSyslogOnly)
813 FN_GLOBAL_BOOL(lp_browse_list,&Globals.bBrowseList)
814 FN_GLOBAL_BOOL(lp_unix_realname,&Globals.bUnixRealname)
815 FN_GLOBAL_BOOL(lp_nis_home_map,&Globals.bNISHomeMap)
816
817 FN_GLOBAL_INTEGER(lp_os_level,&Globals.os_level)
818 FN_GLOBAL_INTEGER(lp_max_ttl,&Globals.max_ttl)
819 FN_GLOBAL_INTEGER(lp_max_log_size,&Globals.max_log_size)
820 FN_GLOBAL_INTEGER(lp_mangledstack,&Globals.mangled_stack)
821 FN_GLOBAL_INTEGER(lp_maxxmit,&Globals.max_xmit)
822 FN_GLOBAL_INTEGER(lp_maxmux,&Globals.max_mux)
823 FN_GLOBAL_INTEGER(lp_maxpacket,&Globals.max_packet)
824 FN_GLOBAL_INTEGER(lp_keepalive,&keepalive)
825 FN_GLOBAL_INTEGER(lp_passwordlevel,&Globals.pwordlevel)
826 FN_GLOBAL_INTEGER(lp_readsize,&Globals.ReadSize)
827 FN_GLOBAL_INTEGER(lp_shmem_size,&Globals.shmem_size)
828 FN_GLOBAL_INTEGER(lp_shmem_hash_size,&Globals.shmem_hash_size)
829 FN_GLOBAL_INTEGER(lp_deadtime,&Globals.deadtime)
830 FN_GLOBAL_INTEGER(lp_maxprotocol,&Globals.maxprotocol)
831 FN_GLOBAL_INTEGER(lp_security,&Globals.security)
832 FN_GLOBAL_INTEGER(lp_printing,&Globals.printing)
833 FN_GLOBAL_INTEGER(lp_maxdisksize,&Globals.maxdisksize)
834 FN_GLOBAL_INTEGER(lp_lpqcachetime,&Globals.lpqcachetime)
835 FN_GLOBAL_INTEGER(lp_syslog,&Globals.syslog)
836 FN_GLOBAL_INTEGER(lp_client_code_page,&Globals.client_code_page)
837
838 FN_LOCAL_STRING(lp_preexec,szPreExec)
839 FN_LOCAL_STRING(lp_postexec,szPostExec)
840 FN_LOCAL_STRING(lp_rootpreexec,szRootPreExec)
841 FN_LOCAL_STRING(lp_rootpostexec,szRootPostExec)
842 FN_LOCAL_STRING(lp_servicename,szService)
843 FN_LOCAL_STRING(lp_pathname,szPath)
844 FN_LOCAL_STRING(lp_dontdescend,szDontdescend)
845 FN_LOCAL_STRING(lp_username,szUsername)
846 FN_LOCAL_STRING(lp_guestaccount,szGuestaccount)
847 FN_LOCAL_STRING(lp_invalid_users,szInvalidUsers)
848 FN_LOCAL_STRING(lp_valid_users,szValidUsers)
849 FN_LOCAL_STRING(lp_admin_users,szAdminUsers)
850 FN_LOCAL_STRING(lp_printcommand,szPrintcommand)
851 FN_LOCAL_STRING(lp_lpqcommand,szLpqcommand)
852 FN_LOCAL_STRING(lp_lprmcommand,szLprmcommand)
853 FN_LOCAL_STRING(lp_lppausecommand,szLppausecommand)
854 FN_LOCAL_STRING(lp_lpresumecommand,szLpresumecommand)
855 FN_LOCAL_STRING(lp_printername,szPrintername)
856 FN_LOCAL_STRING(lp_printerdriver,szPrinterDriver)
857 FN_LOCAL_STRING(lp_hostsallow,szHostsallow)
858 FN_LOCAL_STRING(lp_hostsdeny,szHostsdeny)
859 FN_LOCAL_STRING(lp_magicscript,szMagicScript)
860 FN_LOCAL_STRING(lp_magicoutput,szMagicOutput)
861 FN_LOCAL_STRING(lp_comment,comment)
862 FN_LOCAL_STRING(lp_force_user,force_user)
863 FN_LOCAL_STRING(lp_force_group,force_group)
864 FN_LOCAL_STRING(lp_readlist,readlist)
865 FN_LOCAL_STRING(lp_writelist,writelist)
866 FN_LOCAL_STRING(lp_volume,volume)
867 FN_LOCAL_STRING(lp_mangled_map,szMangledMap)
868
869 FN_LOCAL_BOOL(lp_alternate_permissions,bAlternatePerm)
870 FN_LOCAL_BOOL(lp_revalidate,bRevalidate)
871 FN_LOCAL_BOOL(lp_casesensitive,bCaseSensitive)
872 FN_LOCAL_BOOL(lp_preservecase,bCasePreserve)
873 FN_LOCAL_BOOL(lp_shortpreservecase,bShortCasePreserve)
874 FN_LOCAL_BOOL(lp_casemangle,bCaseMangle)
875 FN_LOCAL_BOOL(lp_status,status)
876 FN_LOCAL_BOOL(lp_hide_dot_files,bHideDotFiles)
877 FN_LOCAL_BOOL(lp_browseable,bBrowseable)
878 FN_LOCAL_BOOL(lp_readonly,bRead_only)
879 FN_LOCAL_BOOL(lp_no_set_dir,bNo_set_dir)
880 FN_LOCAL_BOOL(lp_guest_ok,bGuest_ok)
881 FN_LOCAL_BOOL(lp_guest_only,bGuest_only)
882 FN_LOCAL_BOOL(lp_print_ok,bPrint_ok)
883 FN_LOCAL_BOOL(lp_postscript,bPostscript)
884 FN_LOCAL_BOOL(lp_map_hidden,bMap_hidden)
885 FN_LOCAL_BOOL(lp_map_archive,bMap_archive)
886 FN_LOCAL_BOOL(lp_locking,bLocking)
887 FN_LOCAL_BOOL(lp_strict_locking,bStrictLocking)
888 FN_LOCAL_BOOL(lp_share_modes,bShareModes)
889 FN_LOCAL_BOOL(lp_onlyuser,bOnlyUser)
890 FN_LOCAL_BOOL(lp_manglednames,bMangledNames)
891 FN_LOCAL_BOOL(lp_widelinks,bWidelinks)
892 FN_LOCAL_BOOL(lp_syncalways,bSyncAlways)
893 FN_LOCAL_BOOL(lp_map_system,bMap_system)
894 FN_LOCAL_BOOL(lp_delete_readonly,bDeleteReadonly)
895 FN_LOCAL_BOOL(lp_fake_oplocks,bFakeOplocks)
896
897 FN_LOCAL_INTEGER(lp_create_mode,iCreate_mode)
898 FN_LOCAL_INTEGER(lp_dir_mode,iDir_mode)
899 FN_LOCAL_INTEGER(lp_max_connections,iMaxConnections)
900 FN_LOCAL_INTEGER(lp_defaultcase,iDefaultCase)
901 FN_LOCAL_INTEGER(lp_minprintspace,iMinPrintSpace)
902
903 FN_LOCAL_CHAR(lp_magicchar,magic_char)
904
905
906
907 /* local prototypes */
908 static int    strwicmp( char *psz1, char *psz2 );
909 static int    map_parameter( char *pszParmName);
910 static BOOL   set_boolean( BOOL *pb, char *pszParmValue );
911 static int    getservicebyname(char *pszServiceName, service *pserviceDest);
912 static void   copy_service( service *pserviceDest, 
913                             service *pserviceSource,
914                             BOOL *pcopymapDest );
915 static BOOL   service_ok(int iService);
916 static BOOL   do_parameter(char *pszParmName, char *pszParmValue);
917 static BOOL   do_section(char *pszSectionName);
918 static void   dump_globals(void);
919 static void   dump_a_service(service *pService);
920 static void init_copymap(service *pservice);
921
922
923 /***************************************************************************
924 initialise a service to the defaults
925 ***************************************************************************/
926 static void init_service(service *pservice)
927 {
928   bzero((char *)pservice,sizeof(service));
929   copy_service(pservice,&sDefault,NULL);
930 }
931
932
933 /***************************************************************************
934 free the dynamically allocated parts of a service struct
935 ***************************************************************************/
936 static void free_service(service *pservice)
937 {
938   int i;
939   if (!pservice)
940      return;
941
942   for (i=0;parm_table[i].label;i++)
943     if ((parm_table[i].type == P_STRING ||
944          parm_table[i].type == P_STRING) &&
945         parm_table[i].class == P_LOCAL)
946       string_free((char **)(((char *)pservice) + PTR_DIFF(parm_table[i].ptr,&sDefault)));
947 }
948
949 /***************************************************************************
950 add a new service to the services array initialising it with the given 
951 service
952 ***************************************************************************/
953 static int add_a_service(service *pservice, char *name)
954 {
955   int i;
956   service tservice;
957   int num_to_alloc = iNumServices+1;
958
959   tservice = *pservice;
960
961   /* it might already exist */
962   if (name) 
963     {
964       i = getservicebyname(name,NULL);
965       if (i >= 0)
966         return(i);
967     }
968
969   /* find an invalid one */
970   for (i=0;i<iNumServices;i++)
971     if (!pSERVICE(i)->valid)
972       break;
973
974   /* if not, then create one */
975   if (i == iNumServices)
976     {
977       ServicePtrs = (service **)Realloc(ServicePtrs,sizeof(service *)*num_to_alloc);
978       if (ServicePtrs)
979         pSERVICE(iNumServices) = (service *)malloc(sizeof(service));
980
981       if (!ServicePtrs || !pSERVICE(iNumServices))
982         return(-1);
983
984       iNumServices++;
985     }
986   else
987     free_service(pSERVICE(i));
988
989   pSERVICE(i)->valid = True;
990
991   init_service(pSERVICE(i));
992   copy_service(pSERVICE(i),&tservice,NULL);
993   if (name)
994     string_set(&iSERVICE(i).szService,name);  
995
996   return(i);
997 }
998
999 /***************************************************************************
1000 add a new home service, with the specified home directory, defaults coming 
1001 from service ifrom
1002 ***************************************************************************/
1003 BOOL lp_add_home(char *pszHomename, int iDefaultService, char *pszHomedir)
1004 {
1005   int i = add_a_service(pSERVICE(iDefaultService),pszHomename);
1006
1007   if (i < 0)
1008     return(False);
1009
1010   if (!(*(iSERVICE(i).szPath)) || strequal(iSERVICE(i).szPath,lp_pathname(-1)))
1011     string_set(&iSERVICE(i).szPath,pszHomedir);
1012   if (!(*(iSERVICE(i).comment)))
1013     {
1014       pstring comment;
1015       sprintf(comment,"Home directory of %s",pszHomename);
1016       string_set(&iSERVICE(i).comment,comment);
1017     }
1018   iSERVICE(i).bAvailable = sDefault.bAvailable;
1019   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
1020
1021   DEBUG(3,("adding home directory %s at %s\n", pszHomename, pszHomedir));
1022
1023   return(True);
1024 }
1025
1026 /***************************************************************************
1027 add a new service, based on an old one
1028 ***************************************************************************/
1029 int lp_add_service(char *pszService, int iDefaultService)
1030 {
1031   return(add_a_service(pSERVICE(iDefaultService),pszService));
1032 }
1033
1034
1035 /***************************************************************************
1036 add the IPC service
1037 ***************************************************************************/
1038 static BOOL lp_add_ipc(void)
1039 {
1040   pstring comment;
1041   int i = add_a_service(&sDefault,"IPC$");
1042
1043   if (i < 0)
1044     return(False);
1045
1046   sprintf(comment,"IPC Service (%s)",lp_serverstring());
1047
1048   string_set(&iSERVICE(i).szPath,tmpdir());
1049   string_set(&iSERVICE(i).szUsername,"");
1050   string_set(&iSERVICE(i).comment,comment);
1051   iSERVICE(i).status = False;
1052   iSERVICE(i).iMaxConnections = 0;
1053   iSERVICE(i).bAvailable = True;
1054   iSERVICE(i).bRead_only = True;
1055   iSERVICE(i).bGuest_only = False;
1056   iSERVICE(i).bGuest_ok = True;
1057   iSERVICE(i).bPrint_ok = False;
1058   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
1059
1060   DEBUG(3,("adding IPC service\n"));
1061
1062   return(True);
1063 }
1064
1065
1066 /***************************************************************************
1067 add a new printer service, with defaults coming from service iFrom
1068 ***************************************************************************/
1069 BOOL lp_add_printer(char *pszPrintername, int iDefaultService)
1070 {
1071   char *comment = "From Printcap";
1072   int i = add_a_service(pSERVICE(iDefaultService),pszPrintername);
1073   
1074   if (i < 0)
1075     return(False);
1076   
1077   /* note that we do NOT default the availability flag to True - */
1078   /* we take it from the default service passed. This allows all */
1079   /* dynamic printers to be disabled by disabling the [printers] */
1080   /* entry (if/when the 'available' keyword is implemented!).    */
1081   
1082   /* the printer name is set to the service name. */
1083   string_set(&iSERVICE(i).szPrintername,pszPrintername);
1084   string_set(&iSERVICE(i).comment,comment);
1085   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
1086   /* Printers cannot be read_only. */
1087   iSERVICE(i).bRead_only = False;
1088   /* No share modes on printer services. */
1089   iSERVICE(i).bShareModes = False;
1090   
1091   DEBUG(3,("adding printer service %s\n",pszPrintername));
1092   
1093   return(True);
1094 }
1095
1096
1097 /***************************************************************************
1098 Do a case-insensitive, whitespace-ignoring string compare.
1099 ***************************************************************************/
1100 static int strwicmp(char *psz1, char *psz2)
1101 {
1102    /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
1103    /* appropriate value. */
1104    if (psz1 == psz2)
1105       return (0);
1106    else
1107       if (psz1 == NULL)
1108          return (-1);
1109       else
1110           if (psz2 == NULL)
1111               return (1);
1112
1113    /* sync the strings on first non-whitespace */
1114    while (1)
1115    {
1116       while (isspace(*psz1))
1117          psz1++;
1118       while (isspace(*psz2))
1119          psz2++;
1120       if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0' || *psz2 == '\0')
1121          break;
1122       psz1++;
1123       psz2++;
1124    }
1125    return (*psz1 - *psz2);
1126 }
1127
1128 /***************************************************************************
1129 Map a parameter's string representation to something we can use. 
1130 Returns False if the parameter string is not recognised, else TRUE.
1131 ***************************************************************************/
1132 static int map_parameter(char *pszParmName)
1133 {
1134    int iIndex;
1135
1136    if (*pszParmName == '-')
1137      return(-1);
1138
1139    for (iIndex = 0; parm_table[iIndex].label; iIndex++) 
1140       if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1141          return(iIndex);
1142
1143    DEBUG(0,( "Unknown parameter encountered: \"%s\"\n", pszParmName));
1144    return(-1);
1145 }
1146
1147
1148 /***************************************************************************
1149 Set a boolean variable from the text value stored in the passed string.
1150 Returns True in success, False if the passed string does not correctly 
1151 represent a boolean.
1152 ***************************************************************************/
1153 static BOOL set_boolean(BOOL *pb, char *pszParmValue)
1154 {
1155    BOOL bRetval;
1156
1157    bRetval = True;
1158    if (strwicmp(pszParmValue, "yes") == 0 ||
1159        strwicmp(pszParmValue, "true") == 0 ||
1160        strwicmp(pszParmValue, "1") == 0)
1161       *pb = True;
1162    else
1163       if (strwicmp(pszParmValue, "no") == 0 ||
1164           strwicmp(pszParmValue, "False") == 0 ||
1165           strwicmp(pszParmValue, "0") == 0)
1166          *pb = False;
1167       else
1168       {
1169          DEBUG(0,( "Badly formed boolean in configuration file: \"%s\".\n",
1170                pszParmValue));
1171          bRetval = False;
1172       }
1173    return (bRetval);
1174 }
1175
1176 /***************************************************************************
1177 Find a service by name. Otherwise works like get_service.
1178 ***************************************************************************/
1179 static int getservicebyname(char *pszServiceName, service *pserviceDest)
1180 {
1181    int iService;
1182
1183    for (iService = iNumServices - 1; iService >= 0; iService--)
1184       if (VALID(iService) &&
1185           strwicmp(iSERVICE(iService).szService, pszServiceName) == 0) 
1186       {
1187          if (pserviceDest != NULL)
1188            copy_service(pserviceDest, pSERVICE(iService), NULL);
1189          break;
1190       }
1191
1192    return (iService);
1193 }
1194
1195
1196
1197 /***************************************************************************
1198 Copy a service structure to another
1199
1200 If pcopymapDest is NULL then copy all fields
1201 ***************************************************************************/
1202 static void copy_service(service *pserviceDest, 
1203                          service *pserviceSource,
1204                          BOOL *pcopymapDest)
1205 {
1206   int i;
1207   BOOL bcopyall = (pcopymapDest == NULL);
1208
1209   for (i=0;parm_table[i].label;i++)
1210     if (parm_table[i].ptr && parm_table[i].class == P_LOCAL && 
1211         (bcopyall || pcopymapDest[i]))
1212       {
1213         void *def_ptr = parm_table[i].ptr;
1214         void *src_ptr = 
1215           ((char *)pserviceSource) + PTR_DIFF(def_ptr,&sDefault);
1216         void *dest_ptr = 
1217           ((char *)pserviceDest) + PTR_DIFF(def_ptr,&sDefault);
1218
1219         switch (parm_table[i].type)
1220           {
1221           case P_BOOL:
1222           case P_BOOLREV:
1223             *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
1224             break;
1225
1226           case P_INTEGER:
1227           case P_OCTAL:
1228             *(int *)dest_ptr = *(int *)src_ptr;
1229             break;
1230
1231           case P_CHAR:
1232             *(char *)dest_ptr = *(char *)src_ptr;
1233             break;
1234
1235           case P_STRING:
1236             string_set(dest_ptr,*(char **)src_ptr);
1237             break;
1238
1239           case P_USTRING:
1240             string_set(dest_ptr,*(char **)src_ptr);
1241             strupper(*(char **)dest_ptr);
1242             break;
1243           default:
1244             break;
1245           }
1246       }
1247
1248   if (bcopyall)
1249     {
1250       init_copymap(pserviceDest);
1251       if (pserviceSource->copymap)
1252         memcpy((void *)pserviceDest->copymap,
1253                (void *)pserviceSource->copymap,sizeof(BOOL)*NUMPARAMETERS);
1254     }
1255 }
1256
1257 /***************************************************************************
1258 Check a service for consistency. Return False if the service is in any way
1259 incomplete or faulty, else True.
1260 ***************************************************************************/
1261 static BOOL service_ok(int iService)
1262 {
1263    BOOL bRetval;
1264
1265    bRetval = True;
1266    if (iSERVICE(iService).szService[0] == '\0')
1267    {
1268       DEBUG(0,( "The following message indicates an internal error:\n"));
1269       DEBUG(0,( "No service name in service entry.\n"));
1270       bRetval = False;
1271    }
1272
1273    /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1274    /* I can't see why you'd want a non-printable printer service...        */
1275    if (strwicmp(iSERVICE(iService).szService,PRINTERS_NAME) == 0)
1276       if (!iSERVICE(iService).bPrint_ok)
1277       {
1278          DEBUG(0,( "WARNING: [%s] service MUST be printable!\n",
1279                iSERVICE(iService).szService));
1280          iSERVICE(iService).bPrint_ok = True;
1281       }
1282
1283    if (iSERVICE(iService).szPath[0] == '\0' &&
1284        strwicmp(iSERVICE(iService).szService,HOMES_NAME) != 0)
1285    {
1286       DEBUG(0,("No path in service %s - using %s\n",iSERVICE(iService).szService,tmpdir()));
1287       string_set(&iSERVICE(iService).szPath,tmpdir());      
1288    }
1289
1290    /* If a service is flagged unavailable, log the fact at level 0. */
1291    if (!iSERVICE(iService).bAvailable) 
1292       DEBUG(1,( "NOTE: Service %s is flagged unavailable.\n",
1293             iSERVICE(iService).szService));
1294
1295    return (bRetval);
1296 }
1297
1298 static struct file_lists {
1299   struct file_lists *next;
1300   char *name;
1301   time_t modtime;
1302 } *file_lists = NULL;
1303
1304 /*******************************************************************
1305 keep a linked list of all config files so we know when one has changed 
1306 it's date and needs to be reloaded
1307 ********************************************************************/
1308 static void add_to_file_list(char *fname)
1309 {
1310   struct file_lists *f=file_lists;
1311
1312   while (f) {
1313     if (f->name && !strcmp(f->name,fname)) break;
1314     f = f->next;
1315   }
1316
1317   if (!f) {
1318     f = (struct file_lists *)malloc(sizeof(file_lists[0]));
1319     if (!f) return;
1320     f->next = file_lists;
1321     f->name = strdup(fname);
1322     if (!f->name) {
1323       free(f);
1324       return;
1325     }
1326     file_lists = f;
1327   }
1328
1329   {
1330     pstring n2;
1331     strcpy(n2,fname);
1332     standard_sub_basic(n2);
1333     f->modtime = file_modtime(n2);
1334   }
1335
1336 }
1337
1338 /*******************************************************************
1339 check if a config file has changed date
1340 ********************************************************************/
1341 BOOL lp_file_list_changed(void)
1342 {
1343   struct file_lists *f = file_lists;
1344   while (f) {
1345     pstring n2;
1346     strcpy(n2,f->name);
1347     standard_sub_basic(n2);
1348     if (f->modtime != file_modtime(n2)) return(True);
1349     f = f->next;   
1350   }
1351   return(False);
1352 }
1353
1354 #ifdef KANJI
1355 /***************************************************************************
1356   handle the interpretation of the coding system parameter
1357   *************************************************************************/
1358 static BOOL handle_coding_system(char *pszParmValue,int *val)
1359 {
1360   *val = interpret_coding_system(pszParmValue,*val);
1361   return(True);
1362 }
1363 #endif /* KANJI */
1364
1365 /***************************************************************************
1366 handle the interpretation of the character set system parameter
1367 ***************************************************************************/
1368 static BOOL handle_character_set(char *pszParmValue,int *val)
1369 {
1370   string_set(&Globals.szCharacterSet,pszParmValue);
1371   *val = interpret_character_set(pszParmValue,*val);
1372   return(True);
1373 }
1374
1375
1376 /***************************************************************************
1377 handle the interpretation of the protocol parameter
1378 ***************************************************************************/
1379 static BOOL handle_protocol(char *pszParmValue,int *val)
1380 {
1381   *val = interpret_protocol(pszParmValue,*val);
1382   return(True);
1383 }
1384
1385 /***************************************************************************
1386 handle the interpretation of the security parameter
1387 ***************************************************************************/
1388 static BOOL handle_security(char *pszParmValue,int *val)
1389 {
1390   *val = interpret_security(pszParmValue,*val);
1391   return(True);
1392 }
1393
1394 /***************************************************************************
1395 handle the interpretation of the default case
1396 ***************************************************************************/
1397 static BOOL handle_case(char *pszParmValue,int *val)
1398 {
1399   if (strequal(pszParmValue,"LOWER"))
1400     *val = CASE_LOWER;
1401   else if (strequal(pszParmValue,"UPPER"))
1402     *val = CASE_UPPER;
1403   return(True);
1404 }
1405
1406 /***************************************************************************
1407 handle the interpretation of the printing system
1408 ***************************************************************************/
1409 static BOOL handle_printing(char *pszParmValue,int *val)
1410 {
1411   if (strequal(pszParmValue,"sysv"))
1412     *val = PRINT_SYSV;
1413   else if (strequal(pszParmValue,"aix"))
1414     *val = PRINT_AIX;
1415   else if (strequal(pszParmValue,"hpux"))
1416     *val = PRINT_HPUX;
1417   else if (strequal(pszParmValue,"bsd"))
1418     *val = PRINT_BSD;
1419   else if (strequal(pszParmValue,"qnx"))
1420     *val = PRINT_QNX;
1421   else if (strequal(pszParmValue,"plp"))
1422     *val = PRINT_PLP;
1423   else if (strequal(pszParmValue,"lprng"))
1424     *val = PRINT_LPRNG;
1425   return(True);
1426 }
1427
1428 /***************************************************************************
1429 handle the valid chars lines
1430 ***************************************************************************/
1431 static BOOL handle_valid_chars(char *pszParmValue,char **ptr)
1432
1433   string_set(ptr,pszParmValue);
1434
1435   add_char_string(pszParmValue);
1436   return(True);
1437 }
1438
1439
1440 /***************************************************************************
1441 handle the include operation
1442 ***************************************************************************/
1443 static BOOL handle_include(char *pszParmValue,char **ptr)
1444
1445   pstring fname;
1446   strcpy(fname,pszParmValue);
1447
1448   add_to_file_list(fname);
1449
1450   standard_sub_basic(fname);
1451
1452   string_set(ptr,fname);
1453
1454   if (file_exist(fname,NULL))
1455     return(pm_process(fname, do_section, do_parameter));      
1456
1457   DEBUG(2,("Can't find include file %s\n",fname));
1458
1459   return(False);
1460 }
1461
1462
1463 /***************************************************************************
1464 handle the interpretation of the copy parameter
1465 ***************************************************************************/
1466 static BOOL handle_copy(char *pszParmValue,char **ptr)
1467 {
1468    BOOL bRetval;
1469    int iTemp;
1470    service serviceTemp;
1471
1472    string_set(ptr,pszParmValue);
1473
1474    init_service(&serviceTemp);
1475
1476    bRetval = False;
1477    
1478    DEBUG(3,("Copying service from service %s\n",pszParmValue));
1479
1480    if ((iTemp = getservicebyname(pszParmValue, &serviceTemp)) >= 0)
1481      {
1482        if (iTemp == iServiceIndex)
1483          {
1484            DEBUG(0,("Can't copy service %s - unable to copy self!\n",
1485                     pszParmValue));
1486          }
1487        else
1488          {
1489            copy_service(pSERVICE(iServiceIndex), 
1490                         &serviceTemp,
1491                         iSERVICE(iServiceIndex).copymap);
1492            bRetval = True;
1493          }
1494      }
1495    else
1496      {
1497        DEBUG(0,( "Unable to copy service - source not found: %s\n",
1498                 pszParmValue));
1499        bRetval = False;
1500      }
1501
1502    free_service(&serviceTemp);
1503    return (bRetval);
1504 }
1505
1506
1507 /***************************************************************************
1508 initialise a copymap
1509 ***************************************************************************/
1510 static void init_copymap(service *pservice)
1511 {
1512   int i;
1513   if (pservice->copymap) free(pservice->copymap);
1514   pservice->copymap = (BOOL *)malloc(sizeof(BOOL)*NUMPARAMETERS);
1515   if (!pservice->copymap)
1516     DEBUG(0,("Couldn't allocate copymap!! (size %d)\n",NUMPARAMETERS));
1517
1518   for (i=0;i<NUMPARAMETERS;i++)
1519     pservice->copymap[i] = True;
1520 }
1521
1522
1523 /***************************************************************************
1524 Process a parameter.
1525 ***************************************************************************/
1526 static BOOL do_parameter(char *pszParmName, char *pszParmValue)
1527 {
1528    int parmnum;
1529    void *parm_ptr=NULL; /* where we are going to store the result */
1530    void *def_ptr=NULL;
1531
1532    if (!bInGlobalSection && bGlobalOnly) return(True);
1533
1534    DEBUG(3,("doing parameter %s = %s\n",pszParmName,pszParmValue));
1535    
1536    parmnum = map_parameter(pszParmName);
1537
1538    if (parmnum < 0)
1539      {
1540        DEBUG(0,( "Ignoring unknown parameter \"%s\"\n", pszParmName));
1541        return(True);
1542      }
1543
1544    def_ptr = parm_table[parmnum].ptr;
1545
1546    /* we might point at a service, the default service or a global */
1547    if (bInGlobalSection)
1548      parm_ptr = def_ptr;
1549    else
1550      {
1551        if (parm_table[parmnum].class == P_GLOBAL)
1552          {
1553            DEBUG(0,( "Global parameter %s found in service section!\n",pszParmName));
1554            return(True);
1555          }
1556        parm_ptr = ((char *)pSERVICE(iServiceIndex)) + PTR_DIFF(def_ptr,&sDefault);
1557      }
1558
1559    if (!bInGlobalSection)
1560      {
1561        int i;
1562        if (!iSERVICE(iServiceIndex).copymap)
1563          init_copymap(pSERVICE(iServiceIndex));
1564        
1565        /* this handles the aliases - set the copymap for other entries with
1566           the same data pointer */
1567        for (i=0;parm_table[i].label;i++)
1568          if (parm_table[i].ptr == parm_table[parmnum].ptr)
1569            iSERVICE(iServiceIndex).copymap[i] = False;
1570      }
1571
1572    /* if it is a special case then go ahead */
1573    if (parm_table[parmnum].special)
1574      {
1575        parm_table[parmnum].special(pszParmValue,parm_ptr);
1576        return(True);
1577      }
1578
1579    /* now switch on the type of variable it is */
1580    switch (parm_table[parmnum].type)
1581      {
1582      case P_BOOL:
1583        set_boolean(parm_ptr,pszParmValue);
1584        break;
1585
1586      case P_BOOLREV:
1587        set_boolean(parm_ptr,pszParmValue);
1588        *(BOOL *)parm_ptr = ! *(BOOL *)parm_ptr;
1589        break;
1590
1591      case P_INTEGER:
1592        *(int *)parm_ptr = atoi(pszParmValue);
1593        break;
1594
1595      case P_CHAR:
1596        *(char *)parm_ptr = *pszParmValue;
1597        break;
1598
1599      case P_OCTAL:
1600        sscanf(pszParmValue,"%o",(int *)parm_ptr);
1601        break;
1602
1603      case P_STRING:
1604        string_set(parm_ptr,pszParmValue);
1605        break;
1606
1607      case P_USTRING:
1608        string_set(parm_ptr,pszParmValue);
1609        strupper(*(char **)parm_ptr);
1610        break;
1611
1612      case P_GSTRING:
1613        strcpy((char *)parm_ptr,pszParmValue);
1614        break;
1615
1616      case P_UGSTRING:
1617        strcpy((char *)parm_ptr,pszParmValue);
1618        strupper((char *)parm_ptr);
1619        break;
1620      }
1621
1622    return(True);
1623 }
1624
1625 /***************************************************************************
1626 print a parameter of the specified type
1627 ***************************************************************************/
1628 static void print_parameter(parm_type type,void *ptr)
1629 {
1630   switch (type)
1631     {
1632     case P_BOOL:
1633       printf("%s",BOOLSTR(*(BOOL *)ptr));
1634       break;
1635       
1636     case P_BOOLREV:
1637       printf("%s",BOOLSTR(! *(BOOL *)ptr));
1638       break;
1639       
1640     case P_INTEGER:
1641       printf("%d",*(int *)ptr);
1642       break;
1643       
1644     case P_CHAR:
1645       printf("%c",*(char *)ptr);
1646       break;
1647       
1648     case P_OCTAL:
1649       printf("0%o",*(int *)ptr);
1650       break;
1651       
1652     case P_GSTRING:
1653     case P_UGSTRING:
1654       if ((char *)ptr)
1655         printf("%s",(char *)ptr);
1656       break;
1657
1658     case P_STRING:
1659     case P_USTRING:
1660       if (*(char **)ptr)
1661         printf("%s",*(char **)ptr);
1662       break;
1663     }
1664 }
1665
1666
1667 /***************************************************************************
1668 check if two parameters are equal
1669 ***************************************************************************/
1670 static BOOL equal_parameter(parm_type type,void *ptr1,void *ptr2)
1671 {
1672   switch (type)
1673     {
1674     case P_BOOL:
1675     case P_BOOLREV:
1676       return(*((BOOL *)ptr1) == *((BOOL *)ptr2));
1677
1678     case P_INTEGER:
1679     case P_OCTAL:
1680       return(*((int *)ptr1) == *((int *)ptr2));
1681       
1682     case P_CHAR:
1683       return(*((char *)ptr1) == *((char *)ptr2));
1684
1685     case P_GSTRING:
1686     case P_UGSTRING:
1687       {
1688         char *p1 = (char *)ptr1, *p2 = (char *)ptr2;
1689         if (p1 && !*p1) p1 = NULL;
1690         if (p2 && !*p2) p2 = NULL;
1691         return(p1==p2 || strequal(p1,p2));
1692       }
1693     case P_STRING:
1694     case P_USTRING:
1695       {
1696         char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1697         if (p1 && !*p1) p1 = NULL;
1698         if (p2 && !*p2) p2 = NULL;
1699         return(p1==p2 || strequal(p1,p2));
1700       }
1701     }
1702   return(False);
1703 }
1704
1705 /***************************************************************************
1706 Process a new section (service). At this stage all sections are services.
1707 Later we'll have special sections that permit server parameters to be set.
1708 Returns True on success, False on failure.
1709 ***************************************************************************/
1710 static BOOL do_section(char *pszSectionName)
1711 {
1712    BOOL bRetval;
1713    BOOL isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) || 
1714                     (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1715    bRetval = False;
1716
1717    /* if we were in a global section then do the local inits */
1718    if (bInGlobalSection && !isglobal)
1719      init_locals();
1720
1721    /* if we've just struck a global section, note the fact. */
1722    bInGlobalSection = isglobal;   
1723
1724    /* check for multiple global sections */
1725    if (bInGlobalSection)
1726    {
1727      DEBUG(3,( "Processing section \"[%s]\"\n", pszSectionName));
1728      return(True);
1729    }
1730
1731    if (!bInGlobalSection && bGlobalOnly) return(True);
1732
1733    /* if we have a current service, tidy it up before moving on */
1734    bRetval = True;
1735
1736    if (iServiceIndex >= 0)
1737      bRetval = service_ok(iServiceIndex);
1738
1739    /* if all is still well, move to the next record in the services array */
1740    if (bRetval)
1741      {
1742        /* We put this here to avoid an odd message order if messages are */
1743        /* issued by the post-processing of a previous section. */
1744        DEBUG(2,( "Processing section \"[%s]\"\n", pszSectionName));
1745
1746        if ((iServiceIndex=add_a_service(&sDefault,pszSectionName)) < 0)
1747          {
1748            DEBUG(0,("Failed to add a new service\n"));
1749            return(False);
1750          }
1751      }
1752
1753    return (bRetval);
1754 }
1755
1756 /***************************************************************************
1757 Display the contents of the global structure.
1758 ***************************************************************************/
1759 static void dump_globals(void)
1760 {
1761   int i;
1762   printf("Global parameters:\n");
1763
1764   for (i=0;parm_table[i].label;i++)
1765     if (parm_table[i].class == P_GLOBAL &&
1766         parm_table[i].ptr &&
1767         (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
1768       {
1769         printf("\t%s: ",parm_table[i].label);
1770         print_parameter(parm_table[i].type,parm_table[i].ptr);
1771         printf("\n");
1772       }
1773 }
1774
1775 /***************************************************************************
1776 Display the contents of a single services record.
1777 ***************************************************************************/
1778 static void dump_a_service(service *pService)
1779 {
1780   int i;
1781   if (pService == &sDefault)
1782     printf("\nDefault service parameters:\n");
1783   else
1784     printf("\nService parameters [%s]:\n",pService->szService);
1785
1786   for (i=0;parm_table[i].label;i++)
1787     if (parm_table[i].class == P_LOCAL &&
1788         parm_table[i].ptr && 
1789         (*parm_table[i].label != '-') &&
1790         (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
1791       {
1792         int pdiff = PTR_DIFF(parm_table[i].ptr,&sDefault);
1793
1794         if (pService == &sDefault || !equal_parameter(parm_table[i].type,
1795                                                       ((char *)pService) + pdiff,
1796                                                       ((char *)&sDefault) + pdiff))
1797           {
1798             printf("\t%s: ",parm_table[i].label);
1799             print_parameter(parm_table[i].type,
1800                             ((char *)pService) + pdiff);
1801             printf("\n");
1802           }
1803       }
1804 }
1805
1806 #if 0
1807 /***************************************************************************
1808 Display the contents of a single copy structure.
1809 ***************************************************************************/
1810 static void dump_copy_map(BOOL *pcopymap)
1811 {
1812   int i;
1813   if (!pcopymap) return;
1814
1815   printf("\n\tNon-Copied parameters:\n");
1816
1817   for (i=0;parm_table[i].label;i++)
1818     if (parm_table[i].class == P_LOCAL &&
1819         parm_table[i].ptr && !pcopymap[i] &&
1820         (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
1821       {
1822         printf("\t\t%s\n",parm_table[i].label);
1823       }
1824 }
1825 #endif
1826
1827 /***************************************************************************
1828 Return TRUE if the passed service number is within range.
1829 ***************************************************************************/
1830 BOOL lp_snum_ok(int iService)
1831 {
1832    return (LP_SNUM_OK(iService) && iSERVICE(iService).bAvailable);
1833 }
1834
1835
1836 /***************************************************************************
1837 auto-load some homes and printer services
1838 ***************************************************************************/
1839 static void lp_add_auto_services(char *str)
1840 {
1841   char *s;
1842   char *p;
1843   int homes = lp_servicenumber(HOMES_NAME);
1844   int printers = lp_servicenumber(PRINTERS_NAME);
1845
1846   if (!str)
1847     return;
1848
1849   s = strdup(str);
1850   if (!s) return;
1851
1852   for (p=strtok(s,LIST_SEP);p;p=strtok(NULL,LIST_SEP))
1853     {
1854       char *home = get_home_dir(p);
1855
1856       if (lp_servicenumber(p) >= 0) continue;
1857
1858       if (home && homes >= 0)
1859         {
1860           lp_add_home(p,homes,home);
1861           continue;
1862         }
1863
1864       if (printers >= 0 && pcap_printername_ok(p,NULL))
1865         lp_add_printer(p,printers);
1866     }
1867   free(s);
1868 }
1869
1870 /***************************************************************************
1871 auto-load one printer
1872 ***************************************************************************/
1873 static void lp_add_one_printer(char *name,char *comment)
1874 {
1875   int printers = lp_servicenumber(PRINTERS_NAME);
1876   int i;
1877
1878   if (lp_servicenumber(name) < 0)
1879     {
1880       lp_add_printer(name,printers);
1881       if ((i=lp_servicenumber(name)) >= 0)
1882         string_set(&iSERVICE(i).comment,comment);
1883     }      
1884 }
1885
1886
1887 /***************************************************************************
1888 auto-load printer services
1889 ***************************************************************************/
1890 static void lp_add_all_printers(void)
1891 {
1892   int printers = lp_servicenumber(PRINTERS_NAME);
1893
1894   if (printers < 0) return;
1895
1896   pcap_printer_fn(lp_add_one_printer);
1897 }
1898
1899 /***************************************************************************
1900 have we loaded a services file yet?
1901 ***************************************************************************/
1902 BOOL lp_loaded(void)
1903 {
1904   return(bLoaded);
1905 }
1906
1907 /***************************************************************************
1908 unload unused services
1909 ***************************************************************************/
1910 void lp_killunused(BOOL (*snumused)(int ))
1911 {
1912   int i;
1913   for (i=0;i<iNumServices;i++)
1914     if (VALID(i) && !snumused(i))
1915       {
1916         iSERVICE(i).valid = False;
1917         free_service(pSERVICE(i));
1918       }
1919 }
1920
1921 /***************************************************************************
1922 Load the services array from the services file. Return True on success, 
1923 False on failure.
1924 ***************************************************************************/
1925 BOOL lp_load(char *pszFname,BOOL global_only)
1926 {
1927   pstring n2;
1928   BOOL bRetval;
1929   
1930   add_to_file_list(pszFname);
1931
1932   bRetval = False;
1933
1934   bInGlobalSection = True;
1935   bGlobalOnly = global_only;
1936   
1937   init_globals();
1938   
1939   strcpy(n2,pszFname);
1940   standard_sub_basic(n2);
1941
1942   /* We get sections first, so have to start 'behind' to make up */
1943   iServiceIndex = -1;
1944   bRetval = pm_process(n2, do_section, do_parameter);
1945   
1946   /* finish up the last section */
1947   DEBUG(3,("pm_process() returned %s\n", BOOLSTR(bRetval)));
1948   if (bRetval)
1949     if (iServiceIndex >= 0)
1950       bRetval = service_ok(iServiceIndex);         
1951
1952   lp_add_auto_services(lp_auto_services());
1953   if (lp_load_printers())
1954     lp_add_all_printers();
1955
1956   lp_add_ipc();
1957
1958   bLoaded = True;
1959
1960   return (bRetval);
1961 }
1962
1963
1964 /***************************************************************************
1965 return the max number of services
1966 ***************************************************************************/
1967 int lp_numservices(void)
1968 {
1969   return(iNumServices);
1970 }
1971
1972 /***************************************************************************
1973 Display the contents of the services array in human-readable form.
1974 ***************************************************************************/
1975 void lp_dump(void)
1976 {
1977    int iService;
1978
1979    dump_globals();
1980    
1981    dump_a_service(&sDefault);
1982
1983    for (iService = 0; iService < iNumServices; iService++)
1984    {
1985      if (VALID(iService))
1986        {
1987          if (iSERVICE(iService).szService[0] == '\0')
1988            break;
1989          dump_a_service(pSERVICE(iService));
1990        }
1991    }
1992 }
1993
1994 /***************************************************************************
1995 Return the number of the service with the given name, or -1 if it doesn't
1996 exist. Note that this is a DIFFERENT ANIMAL from the internal function
1997 getservicebyname()! This works ONLY if all services have been loaded, and
1998 does not copy the found service.
1999 ***************************************************************************/
2000 int lp_servicenumber(char *pszServiceName)
2001 {
2002    int iService;
2003
2004    for (iService = iNumServices - 1; iService >= 0; iService--)
2005       if (VALID(iService) &&
2006           strwicmp(iSERVICE(iService).szService, pszServiceName) == 0) 
2007          break;
2008
2009    if (iService < 0)
2010      DEBUG(7,("lp_servicenumber: couldn't find %s\n",pszServiceName));
2011    
2012    return (iService);
2013 }
2014
2015 /*******************************************************************
2016   a useful volume label function
2017   ******************************************************************/
2018 char *volume_label(int snum)
2019 {
2020   char *ret = lp_volume(snum);
2021   if (!*ret) return(lp_servicename(snum));
2022   return(ret);
2023 }