2 Unix SMB/Netbios implementation.
4 Parameter loading functions
5 Copyright (C) Karl Auer 1993,1997
7 Largely re-written by Andrew Tridgell, September 1994
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.
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.
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.
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.
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
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
54 extern int DEBUGLEVEL
;
55 extern pstring user_socket_options
;
56 extern pstring myname
;
59 #define GLOBAL_NAME "global"
64 #define PRINTCAP_NAME "/etc/qconfig"
66 #define PRINTCAP_NAME "/etc/printcap"
71 #define PRINTERS_NAME "printers"
75 #define HOMES_NAME "homes"
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
84 /* these are the types of parameter we have */
87 P_BOOL
,P_BOOLREV
,P_CHAR
,P_INTEGER
,P_OCTAL
,
88 P_STRING
,P_USTRING
,P_GSTRING
,P_UGSTRING
93 P_LOCAL
,P_GLOBAL
,P_NONE
97 extern BOOL use_getwd_cache
;
99 extern int extra_time_offset
;
101 extern int coding_system
;
105 * This structure describes global (ie., server-wide) parameters.
109 char *szPrintcapname
;
112 char *szDefaultService
;
116 char *szServerString
;
117 char *szAutoServices
;
118 char *szPasswdProgram
;
122 char *szSMBPasswdFile
;
123 char *szPasswordServer
;
124 char *szSocketOptions
;
127 char *szDomainController
;
129 char *szCharacterSet
;
136 char *szRemoteAnnounce
;
137 char *szSocketAddress
;
138 char *szNISHomeMapName
;
157 BOOL bPreferredMaster
;
160 BOOL bEncryptPasswords
;
167 BOOL bReadPrediction
;
175 static global Globals
;
180 * This structure describes a single service.
188 char *szGuestaccount
;
189 char *szInvalidUsers
;
197 char *szRootPostExec
;
198 char *szPrintcommand
;
201 char *szLppausecommand
;
202 char *szLpresumecommand
;
204 char *szPrinterDriver
;
226 BOOL bShortCasePreserve
;
250 BOOL bDeleteReadonly
;
252 char dummy
[3]; /* for alignment */
256 /* This is a default service used to prime a services structure */
257 static service sDefault
=
260 NULL
, /* szService */
262 NULL
, /* szUsername */
263 NULL
, /* szGuestAccount */
264 NULL
, /* szInvalidUsers */
265 NULL
, /* szValidUsers */
266 NULL
, /* szAdminUsers */
268 NULL
, /* szInclude */
269 NULL
, /* szPreExec */
270 NULL
, /* szPostExec */
271 NULL
, /* szRootPreExec */
272 NULL
, /* szRootPostExec */
273 NULL
, /* szPrintcommand */
274 NULL
, /* szLpqcommand */
275 NULL
, /* szLprmcommand */
276 NULL
, /* szLppausecommand */
277 NULL
, /* szLpresumecommand */
278 NULL
, /* szPrintername */
279 NULL
, /* szPrinterDriver */
280 NULL
, /* szDontdescend */
281 NULL
, /* szHostsallow */
282 NULL
, /* szHostsdeny */
283 NULL
, /* szMagicScript */
284 NULL
, /* szMagicOutput */
285 NULL
, /* szMangledMap */
287 NULL
, /* force user */
288 NULL
, /* force group */
290 NULL
, /* writelist */
292 0, /* iMinPrintSpace */
293 0644, /* iCreate_mode */
294 0755, /* iDir_mode */
295 0, /* iMaxConnections */
296 CASE_LOWER
, /* iDefaultCase */
297 False
, /* bAlternatePerm */
298 False
, /* revalidate */
299 False
, /* case sensitive */
300 False
, /* case preserve */
301 False
, /* short case preserve */
302 False
, /* case mangle */
304 True
, /* bHideDotFiles */
305 True
, /* bBrowseable */
306 True
, /* bAvailable */
307 True
, /* bRead_only */
308 True
, /* bNo_set_dir */
309 False
, /* bGuest_only */
310 False
, /* bGuest_ok */
311 False
, /* bPrint_ok */
312 False
, /* bPostscript */
313 False
, /* bMap_system */
314 False
, /* bMap_hidden */
315 True
, /* bMap_archive */
317 False
, /* bStrictLocking */
318 True
, /* bShareModes */
319 False
, /* bOnlyUser */
320 True
, /* bMangledNames */
321 True
, /* bWidelinks */
322 False
, /* bSyncAlways */
323 '~', /* magic char */
325 False
, /* bDeleteReadonly */
326 False
, /* bFakeOplocks */
332 /* local variables */
333 static service
**ServicePtrs
= NULL
;
334 static int iNumServices
= 0;
335 static int iServiceIndex
= 0;
336 static BOOL bInGlobalSection
= True
;
337 static BOOL bGlobalOnly
= False
;
340 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
342 /* prototypes for the special type handlers */
343 static BOOL
handle_valid_chars(char *pszParmValue
, char **ptr
);
344 static BOOL
handle_include(char *pszParmValue
, char **ptr
);
345 static BOOL
handle_copy(char *pszParmValue
, char **ptr
);
346 static BOOL
handle_protocol(char *pszParmValue
,int *val
);
347 static BOOL
handle_security(char *pszParmValue
,int *val
);
348 static BOOL
handle_case(char *pszParmValue
,int *val
);
349 static BOOL
handle_printing(char *pszParmValue
,int *val
);
350 static BOOL
handle_character_set(char *pszParmValue
,int *val
);
352 static BOOL
handle_coding_system(char *pszParmValue
,int *val
);
364 {"debuglevel", P_INTEGER
, P_GLOBAL
, &DEBUGLEVEL
, NULL
},
365 {"log level", P_INTEGER
, P_GLOBAL
, &DEBUGLEVEL
, NULL
},
366 {"syslog", P_INTEGER
, P_GLOBAL
, &Globals
.syslog
, NULL
},
367 {"syslog only", P_BOOL
, P_GLOBAL
, &Globals
.bSyslogOnly
, NULL
},
368 {"protocol", P_INTEGER
, P_GLOBAL
, &Globals
.maxprotocol
,handle_protocol
},
369 {"security", P_INTEGER
, P_GLOBAL
, &Globals
.security
,handle_security
},
370 {"printing", P_INTEGER
, P_GLOBAL
, &Globals
.printing
,handle_printing
},
371 {"max disk size", P_INTEGER
, P_GLOBAL
, &Globals
.maxdisksize
, NULL
},
372 {"lpq cache time", P_INTEGER
, P_GLOBAL
, &Globals
.lpqcachetime
, NULL
},
373 {"encrypt passwords",P_BOOL
, P_GLOBAL
, &Globals
.bEncryptPasswords
, NULL
},
374 {"getwd cache", P_BOOL
, P_GLOBAL
, &use_getwd_cache
, NULL
},
375 {"read prediction", P_BOOL
, P_GLOBAL
, &Globals
.bReadPrediction
, NULL
},
376 {"read bmpx", P_BOOL
, P_GLOBAL
, &Globals
.bReadbmpx
, NULL
},
377 {"read raw", P_BOOL
, P_GLOBAL
, &Globals
.bReadRaw
, NULL
},
378 {"write raw", P_BOOL
, P_GLOBAL
, &Globals
.bWriteRaw
, NULL
},
379 {"use rhosts", P_BOOL
, P_GLOBAL
, &Globals
.bUseRhosts
, NULL
},
380 {"load printers", P_BOOL
, P_GLOBAL
, &Globals
.bLoadPrinters
, NULL
},
381 {"null passwords", P_BOOL
, P_GLOBAL
, &Globals
.bNullPasswords
, NULL
},
382 {"strip dot", P_BOOL
, P_GLOBAL
, &Globals
.bStripDot
, NULL
},
383 {"interfaces", P_STRING
, P_GLOBAL
, &Globals
.szInterfaces
, NULL
},
384 {"password server", P_STRING
, P_GLOBAL
, &Globals
.szPasswordServer
, NULL
},
385 {"socket options", P_GSTRING
, P_GLOBAL
, user_socket_options
, NULL
},
386 {"netbios name", P_UGSTRING
,P_GLOBAL
, myname
, NULL
},
387 {"smbrun", P_STRING
, P_GLOBAL
, &Globals
.szSmbrun
, NULL
},
388 {"veto files", P_STRING
, P_GLOBAL
, &Globals
.szVetoFiles
, NULL
},
389 {"log file", P_STRING
, P_GLOBAL
, &Globals
.szLogFile
, NULL
},
390 {"config file", P_STRING
, P_GLOBAL
, &Globals
.szConfigFile
, NULL
},
391 {"smb passwd file", P_STRING
, P_GLOBAL
, &Globals
.szSMBPasswdFile
, NULL
},
392 {"hosts equiv", P_STRING
, P_GLOBAL
, &Globals
.szHostsEquiv
, NULL
},
393 {"preload", P_STRING
, P_GLOBAL
, &Globals
.szAutoServices
, NULL
},
394 {"auto services", P_STRING
, P_GLOBAL
, &Globals
.szAutoServices
, NULL
},
395 {"server string", P_STRING
, P_GLOBAL
, &Globals
.szServerString
, NULL
},
396 {"printcap name", P_STRING
, P_GLOBAL
, &Globals
.szPrintcapname
, NULL
},
397 {"printcap", P_STRING
, P_GLOBAL
, &Globals
.szPrintcapname
, NULL
},
398 {"lock dir", P_STRING
, P_GLOBAL
, &Globals
.szLockDir
, NULL
},
399 {"lock directory", P_STRING
, P_GLOBAL
, &Globals
.szLockDir
, NULL
},
400 {"root directory", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
401 {"root dir", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
402 {"root", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
403 {"default service", P_STRING
, P_GLOBAL
, &Globals
.szDefaultService
, NULL
},
404 {"default", P_STRING
, P_GLOBAL
, &Globals
.szDefaultService
, NULL
},
405 {"message command", P_STRING
, P_GLOBAL
, &Globals
.szMsgCommand
, NULL
},
406 {"dfree command", P_STRING
, P_GLOBAL
, &Globals
.szDfree
, NULL
},
407 {"passwd program", P_STRING
, P_GLOBAL
, &Globals
.szPasswdProgram
, NULL
},
408 {"passwd chat", P_STRING
, P_GLOBAL
, &Globals
.szPasswdChat
, NULL
},
409 {"valid chars", P_STRING
, P_GLOBAL
, &Globals
.szValidChars
, handle_valid_chars
},
410 {"workgroup", P_USTRING
, P_GLOBAL
, &Globals
.szWorkGroup
, NULL
},
411 {"domain controller",P_STRING
, P_GLOBAL
, &Globals
.szDomainController
,NULL
},
412 {"username map", P_STRING
, P_GLOBAL
, &Globals
.szUsernameMap
, NULL
},
413 {"character set", P_STRING
, P_GLOBAL
, &Globals
.szCharacterSet
, handle_character_set
},
414 {"logon script", P_STRING
, P_GLOBAL
, &Globals
.szLogonScript
, NULL
},
415 {"logon path", P_STRING
, P_GLOBAL
, &Globals
.szLogonPath
, NULL
},
416 {"remote announce", P_STRING
, P_GLOBAL
, &Globals
.szRemoteAnnounce
, NULL
},
417 {"socket address", P_STRING
, P_GLOBAL
, &Globals
.szSocketAddress
, NULL
},
418 {"homedir map", P_STRING
, P_GLOBAL
, &Globals
.szNISHomeMapName
, NULL
},
419 {"max log size", P_INTEGER
, P_GLOBAL
, &Globals
.max_log_size
, NULL
},
420 {"mangled stack", P_INTEGER
, P_GLOBAL
, &Globals
.mangled_stack
, NULL
},
421 {"max mux", P_INTEGER
, P_GLOBAL
, &Globals
.max_mux
, NULL
},
422 {"max xmit", P_INTEGER
, P_GLOBAL
, &Globals
.max_xmit
, NULL
},
423 {"max packet", P_INTEGER
, P_GLOBAL
, &Globals
.max_packet
, NULL
},
424 {"packet size", P_INTEGER
, P_GLOBAL
, &Globals
.max_packet
, NULL
},
425 {"password level", P_INTEGER
, P_GLOBAL
, &Globals
.pwordlevel
, NULL
},
426 {"keepalive", P_INTEGER
, P_GLOBAL
, &keepalive
, NULL
},
427 {"deadtime", P_INTEGER
, P_GLOBAL
, &Globals
.deadtime
, NULL
},
428 {"time offset", P_INTEGER
, P_GLOBAL
, &extra_time_offset
, NULL
},
429 {"read size", P_INTEGER
, P_GLOBAL
, &Globals
.ReadSize
, NULL
},
431 {"coding system", P_INTEGER
, P_GLOBAL
, &coding_system
, handle_coding_system
},
433 {"os level", P_INTEGER
, P_GLOBAL
, &Globals
.os_level
, NULL
},
434 {"max ttl", P_INTEGER
, P_GLOBAL
, &Globals
.max_ttl
, NULL
},
435 {"wins support", P_BOOL
, P_GLOBAL
, &Globals
.bWINSsupport
, NULL
},
436 {"wins proxy", P_BOOL
, P_GLOBAL
, &Globals
.bWINSproxy
, NULL
},
437 {"wins server", P_STRING
, P_GLOBAL
, &Globals
.szWINSserver
, NULL
},
438 {"preferred master", P_BOOL
, P_GLOBAL
, &Globals
.bPreferredMaster
, NULL
},
439 {"prefered master", P_BOOL
, P_GLOBAL
, &Globals
.bPreferredMaster
, NULL
},
440 {"domain master", P_BOOL
, P_GLOBAL
, &Globals
.bDomainMaster
, NULL
},
441 {"domain logons", P_BOOL
, P_GLOBAL
, &Globals
.bDomainLogons
, NULL
},
442 {"browse list", P_BOOL
, P_GLOBAL
, &Globals
.bBrowseList
, NULL
},
443 {"unix realname", P_BOOL
, P_GLOBAL
, &Globals
.bUnixRealname
, NULL
},
444 {"NIS homedir", P_BOOL
, P_GLOBAL
, &Globals
.bNISHomeMap
, NULL
},
445 {"-valid", P_BOOL
, P_LOCAL
, &sDefault
.valid
, NULL
},
446 {"comment", P_STRING
, P_LOCAL
, &sDefault
.comment
, NULL
},
447 {"copy", P_STRING
, P_LOCAL
, &sDefault
.szCopy
, handle_copy
},
448 {"include", P_STRING
, P_LOCAL
, &sDefault
.szInclude
, handle_include
},
449 {"exec", P_STRING
, P_LOCAL
, &sDefault
.szPreExec
, NULL
},
450 {"preexec", P_STRING
, P_LOCAL
, &sDefault
.szPreExec
, NULL
},
451 {"postexec", P_STRING
, P_LOCAL
, &sDefault
.szPostExec
, NULL
},
452 {"root preexec", P_STRING
, P_LOCAL
, &sDefault
.szRootPreExec
, NULL
},
453 {"root postexec", P_STRING
, P_LOCAL
, &sDefault
.szRootPostExec
, NULL
},
454 {"alternate permissions",P_BOOL
,P_LOCAL
, &sDefault
.bAlternatePerm
, NULL
},
455 {"revalidate", P_BOOL
, P_LOCAL
, &sDefault
.bRevalidate
, NULL
},
456 {"default case", P_INTEGER
, P_LOCAL
, &sDefault
.iDefaultCase
, handle_case
},
457 {"case sensitive", P_BOOL
, P_LOCAL
, &sDefault
.bCaseSensitive
, NULL
},
458 {"casesignames", P_BOOL
, P_LOCAL
, &sDefault
.bCaseSensitive
, NULL
},
459 {"preserve case", P_BOOL
, P_LOCAL
, &sDefault
.bCasePreserve
, NULL
},
460 {"short preserve case",P_BOOL
, P_LOCAL
, &sDefault
.bShortCasePreserve
,NULL
},
461 {"mangle case", P_BOOL
, P_LOCAL
, &sDefault
.bCaseMangle
, NULL
},
462 {"mangling char", P_CHAR
, P_LOCAL
, &sDefault
.magic_char
, NULL
},
463 {"browseable", P_BOOL
, P_LOCAL
, &sDefault
.bBrowseable
, NULL
},
464 {"browsable", P_BOOL
, P_LOCAL
, &sDefault
.bBrowseable
, NULL
},
465 {"available", P_BOOL
, P_LOCAL
, &sDefault
.bAvailable
, NULL
},
466 {"path", P_STRING
, P_LOCAL
, &sDefault
.szPath
, NULL
},
467 {"directory", P_STRING
, P_LOCAL
, &sDefault
.szPath
, NULL
},
468 {"username", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
469 {"user", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
470 {"users", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
471 {"guest account", P_STRING
, P_LOCAL
, &sDefault
.szGuestaccount
, NULL
},
472 {"invalid users", P_STRING
, P_LOCAL
, &sDefault
.szInvalidUsers
, NULL
},
473 {"valid users", P_STRING
, P_LOCAL
, &sDefault
.szValidUsers
, NULL
},
474 {"admin users", P_STRING
, P_LOCAL
, &sDefault
.szAdminUsers
, NULL
},
475 {"read list", P_STRING
, P_LOCAL
, &sDefault
.readlist
, NULL
},
476 {"write list", P_STRING
, P_LOCAL
, &sDefault
.writelist
, NULL
},
477 {"volume", P_STRING
, P_LOCAL
, &sDefault
.volume
, NULL
},
478 {"force user", P_STRING
, P_LOCAL
, &sDefault
.force_user
, NULL
},
479 {"force group", P_STRING
, P_LOCAL
, &sDefault
.force_group
, NULL
},
480 {"group", P_STRING
, P_LOCAL
, &sDefault
.force_group
, NULL
},
481 {"read only", P_BOOL
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
482 {"write ok", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
483 {"writeable", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
484 {"writable", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
485 {"max connections", P_INTEGER
, P_LOCAL
, &sDefault
.iMaxConnections
, NULL
},
486 {"min print space", P_INTEGER
, P_LOCAL
, &sDefault
.iMinPrintSpace
, NULL
},
487 {"create mask", P_OCTAL
, P_LOCAL
, &sDefault
.iCreate_mode
, NULL
},
488 {"create mode", P_OCTAL
, P_LOCAL
, &sDefault
.iCreate_mode
, NULL
},
489 {"directory mask", P_OCTAL
, P_LOCAL
, &sDefault
.iDir_mode
, NULL
},
490 {"directory mode", P_OCTAL
, P_LOCAL
, &sDefault
.iDir_mode
, NULL
},
491 {"set directory", P_BOOLREV
, P_LOCAL
, &sDefault
.bNo_set_dir
, NULL
},
492 {"status", P_BOOL
, P_LOCAL
, &sDefault
.status
, NULL
},
493 {"hide dot files", P_BOOL
, P_LOCAL
, &sDefault
.bHideDotFiles
, NULL
},
494 {"guest only", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_only
, NULL
},
495 {"only guest", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_only
, NULL
},
496 {"guest ok", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_ok
, NULL
},
497 {"public", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_ok
, NULL
},
498 {"print ok", P_BOOL
, P_LOCAL
, &sDefault
.bPrint_ok
, NULL
},
499 {"printable", P_BOOL
, P_LOCAL
, &sDefault
.bPrint_ok
, NULL
},
500 {"postscript", P_BOOL
, P_LOCAL
, &sDefault
.bPostscript
, NULL
},
501 {"map system", P_BOOL
, P_LOCAL
, &sDefault
.bMap_system
, NULL
},
502 {"map hidden", P_BOOL
, P_LOCAL
, &sDefault
.bMap_hidden
, NULL
},
503 {"map archive", P_BOOL
, P_LOCAL
, &sDefault
.bMap_archive
, NULL
},
504 {"locking", P_BOOL
, P_LOCAL
, &sDefault
.bLocking
, NULL
},
505 {"strict locking", P_BOOL
, P_LOCAL
, &sDefault
.bStrictLocking
, NULL
},
506 {"share modes", P_BOOL
, P_LOCAL
, &sDefault
.bShareModes
, NULL
},
507 {"only user", P_BOOL
, P_LOCAL
, &sDefault
.bOnlyUser
, NULL
},
508 {"wide links", P_BOOL
, P_LOCAL
, &sDefault
.bWidelinks
, NULL
},
509 {"sync always", P_BOOL
, P_LOCAL
, &sDefault
.bSyncAlways
, NULL
},
510 {"mangled names", P_BOOL
, P_LOCAL
, &sDefault
.bMangledNames
, NULL
},
511 {"fake oplocks", P_BOOL
, P_LOCAL
, &sDefault
.bFakeOplocks
, NULL
},
512 {"print command", P_STRING
, P_LOCAL
, &sDefault
.szPrintcommand
, NULL
},
513 {"lpq command", P_STRING
, P_LOCAL
, &sDefault
.szLpqcommand
, NULL
},
514 {"lprm command", P_STRING
, P_LOCAL
, &sDefault
.szLprmcommand
, NULL
},
515 {"lppause command", P_STRING
, P_LOCAL
, &sDefault
.szLppausecommand
, NULL
},
516 {"lpresume command", P_STRING
, P_LOCAL
, &sDefault
.szLpresumecommand
,NULL
},
517 {"printer", P_STRING
, P_LOCAL
, &sDefault
.szPrintername
, NULL
},
518 {"printer name", P_STRING
, P_LOCAL
, &sDefault
.szPrintername
, NULL
},
519 {"printer driver", P_STRING
, P_LOCAL
, &sDefault
.szPrinterDriver
, NULL
},
520 {"hosts allow", P_STRING
, P_LOCAL
, &sDefault
.szHostsallow
, NULL
},
521 {"allow hosts", P_STRING
, P_LOCAL
, &sDefault
.szHostsallow
, NULL
},
522 {"hosts deny", P_STRING
, P_LOCAL
, &sDefault
.szHostsdeny
, NULL
},
523 {"deny hosts", P_STRING
, P_LOCAL
, &sDefault
.szHostsdeny
, NULL
},
524 {"dont descend", P_STRING
, P_LOCAL
, &sDefault
.szDontdescend
, NULL
},
525 {"magic script", P_STRING
, P_LOCAL
, &sDefault
.szMagicScript
, NULL
},
526 {"magic output", P_STRING
, P_LOCAL
, &sDefault
.szMagicOutput
, NULL
},
527 {"mangled map", P_STRING
, P_LOCAL
, &sDefault
.szMangledMap
, NULL
},
528 {"delete readonly", P_BOOL
, P_LOCAL
, &sDefault
.bDeleteReadonly
, NULL
},
530 {NULL
, P_BOOL
, P_NONE
, NULL
, NULL
}
535 /***************************************************************************
536 Initialise the global parameter structure.
537 ***************************************************************************/
538 static void init_globals(void)
540 static BOOL done_init
= False
;
546 bzero((void *)&Globals
,sizeof(Globals
));
548 for (i
= 0; parm_table
[i
].label
; i
++)
549 if ((parm_table
[i
].type
== P_STRING
||
550 parm_table
[i
].type
== P_USTRING
) &&
552 string_init(parm_table
[i
].ptr
,"");
554 string_set(&sDefault
.szGuestaccount
, GUEST_ACCOUNT
);
555 string_set(&sDefault
.szPrinterDriver
, "NULL");
561 DEBUG(3,("Initialising global parameters\n"));
563 #ifdef SMB_PASSWD_FILE
564 string_set(&Globals
.szSMBPasswdFile
, SMB_PASSWD_FILE
);
566 string_set(&Globals
.szPasswdChat
,"*old*password* %o\\n *new*password* %n\\n *new*password* %n\\n *changed*");
567 string_set(&Globals
.szWorkGroup
, WORKGROUP
);
569 string_set(&Globals
.szPasswdProgram
, SMB_PASSWD
);
571 string_set(&Globals
.szPasswdProgram
, "/bin/passwd");
573 string_set(&Globals
.szPrintcapname
, PRINTCAP_NAME
);
574 string_set(&Globals
.szLockDir
, LOCKDIR
);
575 string_set(&Globals
.szRootdir
, "/");
576 string_set(&Globals
.szSmbrun
, SMBRUN
);
577 string_set(&Globals
.szSocketAddress
, "0.0.0.0");
578 sprintf(s
,"Samba %s",VERSION
);
579 string_set(&Globals
.szServerString
,s
);
580 Globals
.bLoadPrinters
= True
;
581 Globals
.bUseRhosts
= False
;
582 Globals
.max_packet
= 65535;
583 Globals
.mangled_stack
= 50;
584 Globals
.max_xmit
= Globals
.max_packet
;
586 Globals
.lpqcachetime
= 10;
587 Globals
.pwordlevel
= 0;
588 Globals
.deadtime
= 0;
589 Globals
.max_log_size
= 5000;
590 Globals
.maxprotocol
= PROTOCOL_NT1
;
591 Globals
.security
= SEC_SHARE
;
592 Globals
.bEncryptPasswords
= False
;
593 Globals
.printing
= DEFAULT_PRINTING
;
594 Globals
.bReadRaw
= True
;
595 Globals
.bWriteRaw
= True
;
596 Globals
.bReadPrediction
= False
;
597 Globals
.bReadbmpx
= True
;
598 Globals
.bNullPasswords
= False
;
599 Globals
.bStripDot
= False
;
601 Globals
.bSyslogOnly
= False
;
602 Globals
.os_level
= 0;
603 Globals
.max_ttl
= 60*60*4; /* 2 hours default */
604 Globals
.bPreferredMaster
= True
;
605 Globals
.bDomainMaster
= False
;
606 Globals
.bDomainLogons
= False
;
607 Globals
.bBrowseList
= True
;
608 Globals
.bWINSsupport
= False
;
609 Globals
.bWINSproxy
= False
;
610 Globals
.ReadSize
= 16*1024;
611 Globals
.bUnixRealname
= False
;
613 Globals
.bNISHomeMap
= False
;
614 string_set(&Globals
.szNISHomeMapName
, "auto.home");
617 coding_system
= interpret_coding_system (KANJI
, SJIS_CODE
);
622 /***************************************************************************
623 check if a string is initialised and if not then initialise it
624 ***************************************************************************/
625 static void string_initial(char **s
,char *v
)
632 /***************************************************************************
633 Initialise the sDefault parameter structure.
634 ***************************************************************************/
635 static void init_locals(void)
637 /* choose defaults depending on the type of printing */
638 switch (Globals
.printing
)
644 string_initial(&sDefault
.szLpqcommand
,"lpq -P%p");
645 string_initial(&sDefault
.szLprmcommand
,"lprm -P%p %j");
646 string_initial(&sDefault
.szPrintcommand
,"lpr -r -P%p %s");
651 string_initial(&sDefault
.szLpqcommand
,"lpstat -o%p");
652 string_initial(&sDefault
.szLprmcommand
,"cancel %p-%j");
653 string_initial(&sDefault
.szPrintcommand
,"lp -c -d%p %s; rm %s");
655 string_initial(&sDefault
.szLppausecommand
,"lp -i %p-%j -H hold");
656 string_initial(&sDefault
.szLpresumecommand
,"lp -i %p-%j -H resume");
661 string_initial(&sDefault
.szLpqcommand
,"lpq -P%p");
662 string_initial(&sDefault
.szLprmcommand
,"lprm -P%p %j");
663 string_initial(&sDefault
.szPrintcommand
,"lp -r -P%p %s");
671 /******************************************************************* a
672 convenience routine to grab string parameters into a rotating buffer,
673 and run standard_sub_basic on them. The buffers can be written to by
674 callers without affecting the source string.
675 ********************************************************************/
676 char *lp_string(char *s
)
678 static char *bufs
[10];
679 static int buflen
[10];
680 static int next
= -1;
683 int len
= s
?strlen(s
):0;
694 len
= MAX(len
+100,sizeof(pstring
)); /* the +100 is for some
697 if (buflen
[next
] != len
) {
699 if (bufs
[next
]) free(bufs
[next
]);
700 bufs
[next
] = (char *)malloc(len
);
702 DEBUG(0,("out of memory in lp_string()"));
707 ret
= &bufs
[next
][0];
715 standard_sub_basic(ret
);
721 In this section all the functions that are used to access the
722 parameters from the rest of the program are defined
725 #define FN_GLOBAL_STRING(fn_name,ptr) \
726 char *fn_name(void) {return(lp_string(*(char **)(ptr) ? *(char **)(ptr) : ""));}
727 #define FN_GLOBAL_BOOL(fn_name,ptr) \
728 BOOL fn_name(void) {return(*(BOOL *)(ptr));}
729 #define FN_GLOBAL_CHAR(fn_name,ptr) \
730 char fn_name(void) {return(*(char *)(ptr));}
731 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
732 int fn_name(void) {return(*(int *)(ptr));}
734 #define FN_LOCAL_STRING(fn_name,val) \
735 char *fn_name(int i) {return(lp_string((LP_SNUM_OK(i)&&pSERVICE(i)->val)?pSERVICE(i)->val : sDefault.val));}
736 #define FN_LOCAL_BOOL(fn_name,val) \
737 BOOL fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
738 #define FN_LOCAL_CHAR(fn_name,val) \
739 char fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
740 #define FN_LOCAL_INTEGER(fn_name,val) \
741 int fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
743 FN_GLOBAL_STRING(lp_logfile
,&Globals
.szLogFile
)
744 FN_GLOBAL_STRING(lp_smbrun
,&Globals
.szSmbrun
)
745 FN_GLOBAL_STRING(lp_configfile
,&Globals
.szConfigFile
)
746 FN_GLOBAL_STRING(lp_smb_passwd_file
,&Globals
.szSMBPasswdFile
)
747 FN_GLOBAL_STRING(lp_serverstring
,&Globals
.szServerString
)
748 FN_GLOBAL_STRING(lp_printcapname
,&Globals
.szPrintcapname
)
749 FN_GLOBAL_STRING(lp_lockdir
,&Globals
.szLockDir
)
750 FN_GLOBAL_STRING(lp_rootdir
,&Globals
.szRootdir
)
751 FN_GLOBAL_STRING(lp_defaultservice
,&Globals
.szDefaultService
)
752 FN_GLOBAL_STRING(lp_msg_command
,&Globals
.szMsgCommand
)
753 FN_GLOBAL_STRING(lp_dfree_command
,&Globals
.szDfree
)
754 FN_GLOBAL_STRING(lp_hosts_equiv
,&Globals
.szHostsEquiv
)
755 FN_GLOBAL_STRING(lp_auto_services
,&Globals
.szAutoServices
)
756 FN_GLOBAL_STRING(lp_passwd_program
,&Globals
.szPasswdProgram
)
757 FN_GLOBAL_STRING(lp_passwd_chat
,&Globals
.szPasswdChat
)
758 FN_GLOBAL_STRING(lp_passwordserver
,&Globals
.szPasswordServer
)
759 FN_GLOBAL_STRING(lp_workgroup
,&Globals
.szWorkGroup
)
760 FN_GLOBAL_STRING(lp_domain_controller
,&Globals
.szDomainController
)
761 FN_GLOBAL_STRING(lp_username_map
,&Globals
.szUsernameMap
)
762 FN_GLOBAL_STRING(lp_character_set
,&Globals
.szCharacterSet
)
763 FN_GLOBAL_STRING(lp_logon_script
,&Globals
.szLogonScript
)
764 FN_GLOBAL_STRING(lp_logon_path
,&Globals
.szLogonPath
)
765 FN_GLOBAL_STRING(lp_veto_files
,&Globals
.szVetoFiles
)
766 FN_GLOBAL_STRING(lp_remote_announce
,&Globals
.szRemoteAnnounce
)
767 FN_GLOBAL_STRING(lp_wins_server
,&Globals
.szWINSserver
)
768 FN_GLOBAL_STRING(lp_interfaces
,&Globals
.szInterfaces
)
769 FN_GLOBAL_STRING(lp_socket_address
,&Globals
.szSocketAddress
)
770 FN_GLOBAL_STRING(lp_nis_home_map_name
,&Globals
.szNISHomeMapName
)
772 FN_GLOBAL_BOOL(lp_wins_support
,&Globals
.bWINSsupport
)
773 FN_GLOBAL_BOOL(lp_wins_proxy
,&Globals
.bWINSproxy
)
774 FN_GLOBAL_BOOL(lp_domain_master
,&Globals
.bDomainMaster
)
775 FN_GLOBAL_BOOL(lp_domain_logons
,&Globals
.bDomainLogons
)
776 FN_GLOBAL_BOOL(lp_preferred_master
,&Globals
.bPreferredMaster
)
777 FN_GLOBAL_BOOL(lp_load_printers
,&Globals
.bLoadPrinters
)
778 FN_GLOBAL_BOOL(lp_use_rhosts
,&Globals
.bUseRhosts
)
779 FN_GLOBAL_BOOL(lp_getwdcache
,&use_getwd_cache
)
780 FN_GLOBAL_BOOL(lp_readprediction
,&Globals
.bReadPrediction
)
781 FN_GLOBAL_BOOL(lp_readbmpx
,&Globals
.bReadbmpx
)
782 FN_GLOBAL_BOOL(lp_readraw
,&Globals
.bReadRaw
)
783 FN_GLOBAL_BOOL(lp_writeraw
,&Globals
.bWriteRaw
)
784 FN_GLOBAL_BOOL(lp_null_passwords
,&Globals
.bNullPasswords
)
785 FN_GLOBAL_BOOL(lp_strip_dot
,&Globals
.bStripDot
)
786 FN_GLOBAL_BOOL(lp_encrypted_passwords
,&Globals
.bEncryptPasswords
)
787 FN_GLOBAL_BOOL(lp_syslog_only
,&Globals
.bSyslogOnly
)
788 FN_GLOBAL_BOOL(lp_browse_list
,&Globals
.bBrowseList
)
789 FN_GLOBAL_BOOL(lp_unix_realname
,&Globals
.bUnixRealname
)
790 FN_GLOBAL_BOOL(lp_nis_home_map
,&Globals
.bNISHomeMap
)
792 FN_GLOBAL_INTEGER(lp_os_level
,&Globals
.os_level
)
793 FN_GLOBAL_INTEGER(lp_max_ttl
,&Globals
.max_ttl
)
794 FN_GLOBAL_INTEGER(lp_max_log_size
,&Globals
.max_log_size
)
795 FN_GLOBAL_INTEGER(lp_mangledstack
,&Globals
.mangled_stack
)
796 FN_GLOBAL_INTEGER(lp_maxxmit
,&Globals
.max_xmit
)
797 FN_GLOBAL_INTEGER(lp_maxmux
,&Globals
.max_mux
)
798 FN_GLOBAL_INTEGER(lp_maxpacket
,&Globals
.max_packet
)
799 FN_GLOBAL_INTEGER(lp_keepalive
,&keepalive
)
800 FN_GLOBAL_INTEGER(lp_passwordlevel
,&Globals
.pwordlevel
)
801 FN_GLOBAL_INTEGER(lp_readsize
,&Globals
.ReadSize
)
802 FN_GLOBAL_INTEGER(lp_deadtime
,&Globals
.deadtime
)
803 FN_GLOBAL_INTEGER(lp_maxprotocol
,&Globals
.maxprotocol
)
804 FN_GLOBAL_INTEGER(lp_security
,&Globals
.security
)
805 FN_GLOBAL_INTEGER(lp_printing
,&Globals
.printing
)
806 FN_GLOBAL_INTEGER(lp_maxdisksize
,&Globals
.maxdisksize
)
807 FN_GLOBAL_INTEGER(lp_lpqcachetime
,&Globals
.lpqcachetime
)
808 FN_GLOBAL_INTEGER(lp_syslog
,&Globals
.syslog
)
810 FN_LOCAL_STRING(lp_preexec
,szPreExec
)
811 FN_LOCAL_STRING(lp_postexec
,szPostExec
)
812 FN_LOCAL_STRING(lp_rootpreexec
,szRootPreExec
)
813 FN_LOCAL_STRING(lp_rootpostexec
,szRootPostExec
)
814 FN_LOCAL_STRING(lp_servicename
,szService
)
815 FN_LOCAL_STRING(lp_pathname
,szPath
)
816 FN_LOCAL_STRING(lp_dontdescend
,szDontdescend
)
817 FN_LOCAL_STRING(lp_username
,szUsername
)
818 FN_LOCAL_STRING(lp_guestaccount
,szGuestaccount
)
819 FN_LOCAL_STRING(lp_invalid_users
,szInvalidUsers
)
820 FN_LOCAL_STRING(lp_valid_users
,szValidUsers
)
821 FN_LOCAL_STRING(lp_admin_users
,szAdminUsers
)
822 FN_LOCAL_STRING(lp_printcommand
,szPrintcommand
)
823 FN_LOCAL_STRING(lp_lpqcommand
,szLpqcommand
)
824 FN_LOCAL_STRING(lp_lprmcommand
,szLprmcommand
)
825 FN_LOCAL_STRING(lp_lppausecommand
,szLppausecommand
)
826 FN_LOCAL_STRING(lp_lpresumecommand
,szLpresumecommand
)
827 FN_LOCAL_STRING(lp_printername
,szPrintername
)
828 FN_LOCAL_STRING(lp_printerdriver
,szPrinterDriver
)
829 FN_LOCAL_STRING(lp_hostsallow
,szHostsallow
)
830 FN_LOCAL_STRING(lp_hostsdeny
,szHostsdeny
)
831 FN_LOCAL_STRING(lp_magicscript
,szMagicScript
)
832 FN_LOCAL_STRING(lp_magicoutput
,szMagicOutput
)
833 FN_LOCAL_STRING(lp_comment
,comment
)
834 FN_LOCAL_STRING(lp_force_user
,force_user
)
835 FN_LOCAL_STRING(lp_force_group
,force_group
)
836 FN_LOCAL_STRING(lp_readlist
,readlist
)
837 FN_LOCAL_STRING(lp_writelist
,writelist
)
838 FN_LOCAL_STRING(lp_volume
,volume
)
839 FN_LOCAL_STRING(lp_mangled_map
,szMangledMap
)
841 FN_LOCAL_BOOL(lp_alternate_permissions
,bAlternatePerm
)
842 FN_LOCAL_BOOL(lp_revalidate
,bRevalidate
)
843 FN_LOCAL_BOOL(lp_casesensitive
,bCaseSensitive
)
844 FN_LOCAL_BOOL(lp_preservecase
,bCasePreserve
)
845 FN_LOCAL_BOOL(lp_shortpreservecase
,bShortCasePreserve
)
846 FN_LOCAL_BOOL(lp_casemangle
,bCaseMangle
)
847 FN_LOCAL_BOOL(lp_status
,status
)
848 FN_LOCAL_BOOL(lp_hide_dot_files
,bHideDotFiles
)
849 FN_LOCAL_BOOL(lp_browseable
,bBrowseable
)
850 FN_LOCAL_BOOL(lp_readonly
,bRead_only
)
851 FN_LOCAL_BOOL(lp_no_set_dir
,bNo_set_dir
)
852 FN_LOCAL_BOOL(lp_guest_ok
,bGuest_ok
)
853 FN_LOCAL_BOOL(lp_guest_only
,bGuest_only
)
854 FN_LOCAL_BOOL(lp_print_ok
,bPrint_ok
)
855 FN_LOCAL_BOOL(lp_postscript
,bPostscript
)
856 FN_LOCAL_BOOL(lp_map_hidden
,bMap_hidden
)
857 FN_LOCAL_BOOL(lp_map_archive
,bMap_archive
)
858 FN_LOCAL_BOOL(lp_locking
,bLocking
)
859 FN_LOCAL_BOOL(lp_strict_locking
,bStrictLocking
)
860 FN_LOCAL_BOOL(lp_share_modes
,bShareModes
)
861 FN_LOCAL_BOOL(lp_onlyuser
,bOnlyUser
)
862 FN_LOCAL_BOOL(lp_manglednames
,bMangledNames
)
863 FN_LOCAL_BOOL(lp_widelinks
,bWidelinks
)
864 FN_LOCAL_BOOL(lp_syncalways
,bSyncAlways
)
865 FN_LOCAL_BOOL(lp_map_system
,bMap_system
)
866 FN_LOCAL_BOOL(lp_delete_readonly
,bDeleteReadonly
)
867 FN_LOCAL_BOOL(lp_fake_oplocks
,bFakeOplocks
)
869 FN_LOCAL_INTEGER(lp_create_mode
,iCreate_mode
)
870 FN_LOCAL_INTEGER(lp_dir_mode
,iDir_mode
)
871 FN_LOCAL_INTEGER(lp_max_connections
,iMaxConnections
)
872 FN_LOCAL_INTEGER(lp_defaultcase
,iDefaultCase
)
873 FN_LOCAL_INTEGER(lp_minprintspace
,iMinPrintSpace
)
875 FN_LOCAL_CHAR(lp_magicchar
,magic_char
)
879 /* local prototypes */
880 static int strwicmp( char *psz1
, char *psz2
);
881 static int map_parameter( char *pszParmName
);
882 static BOOL
set_boolean( BOOL
*pb
, char *pszParmValue
);
883 static int getservicebyname(char *pszServiceName
, service
*pserviceDest
);
884 static void copy_service( service
*pserviceDest
,
885 service
*pserviceSource
,
886 BOOL
*pcopymapDest
);
887 static BOOL
service_ok(int iService
);
888 static BOOL
do_parameter(char *pszParmName
, char *pszParmValue
);
889 static BOOL
do_section(char *pszSectionName
);
890 static void dump_globals(void);
891 static void dump_a_service(service
*pService
);
892 static void init_copymap(service
*pservice
);
895 /***************************************************************************
896 initialise a service to the defaults
897 ***************************************************************************/
898 static void init_service(service
*pservice
)
900 bzero((char *)pservice
,sizeof(service
));
901 copy_service(pservice
,&sDefault
,NULL
);
905 /***************************************************************************
906 free the dynamically allocated parts of a service struct
907 ***************************************************************************/
908 static void free_service(service
*pservice
)
914 for (i
=0;parm_table
[i
].label
;i
++)
915 if ((parm_table
[i
].type
== P_STRING
||
916 parm_table
[i
].type
== P_STRING
) &&
917 parm_table
[i
].class == P_LOCAL
)
918 string_free((char **)(((char *)pservice
) + PTR_DIFF(parm_table
[i
].ptr
,&sDefault
)));
921 /***************************************************************************
922 add a new service to the services array initialising it with the given
924 ***************************************************************************/
925 static int add_a_service(service
*pservice
, char *name
)
929 int num_to_alloc
= iNumServices
+1;
931 tservice
= *pservice
;
933 /* it might already exist */
936 i
= getservicebyname(name
,NULL
);
941 /* find an invalid one */
942 for (i
=0;i
<iNumServices
;i
++)
943 if (!pSERVICE(i
)->valid
)
946 /* if not, then create one */
947 if (i
== iNumServices
)
949 ServicePtrs
= (service
**)Realloc(ServicePtrs
,sizeof(service
*)*num_to_alloc
);
951 pSERVICE(iNumServices
) = (service
*)malloc(sizeof(service
));
953 if (!ServicePtrs
|| !pSERVICE(iNumServices
))
959 free_service(pSERVICE(i
));
961 pSERVICE(i
)->valid
= True
;
963 init_service(pSERVICE(i
));
964 copy_service(pSERVICE(i
),&tservice
,NULL
);
966 string_set(&iSERVICE(i
).szService
,name
);
971 /***************************************************************************
972 add a new home service, with the specified home directory, defaults coming
974 ***************************************************************************/
975 BOOL
lp_add_home(char *pszHomename
, int iDefaultService
, char *pszHomedir
)
977 int i
= add_a_service(pSERVICE(iDefaultService
),pszHomename
);
982 if (!(*(iSERVICE(i
).szPath
)) || strequal(iSERVICE(i
).szPath
,lp_pathname(-1)))
983 string_set(&iSERVICE(i
).szPath
,pszHomedir
);
984 if (!(*(iSERVICE(i
).comment
)))
987 sprintf(comment
,"Home directory of %s",pszHomename
);
988 string_set(&iSERVICE(i
).comment
,comment
);
990 iSERVICE(i
).bAvailable
= sDefault
.bAvailable
;
991 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
993 DEBUG(3,("adding home directory %s at %s\n", pszHomename
, pszHomedir
));
998 /***************************************************************************
999 add a new service, based on an old one
1000 ***************************************************************************/
1001 int lp_add_service(char *pszService
, int iDefaultService
)
1003 return(add_a_service(pSERVICE(iDefaultService
),pszService
));
1007 /***************************************************************************
1009 ***************************************************************************/
1010 static BOOL
lp_add_ipc(void)
1013 int i
= add_a_service(&sDefault
,"IPC$");
1018 sprintf(comment
,"IPC Service (%s)",lp_serverstring());
1020 string_set(&iSERVICE(i
).szPath
,tmpdir());
1021 string_set(&iSERVICE(i
).szUsername
,"");
1022 string_set(&iSERVICE(i
).comment
,comment
);
1023 iSERVICE(i
).status
= False
;
1024 iSERVICE(i
).iMaxConnections
= 0;
1025 iSERVICE(i
).bAvailable
= True
;
1026 iSERVICE(i
).bRead_only
= True
;
1027 iSERVICE(i
).bGuest_only
= False
;
1028 iSERVICE(i
).bGuest_ok
= True
;
1029 iSERVICE(i
).bPrint_ok
= False
;
1030 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
1032 DEBUG(3,("adding IPC service\n"));
1038 /***************************************************************************
1039 add a new printer service, with defaults coming from service iFrom
1040 ***************************************************************************/
1041 BOOL
lp_add_printer(char *pszPrintername
, int iDefaultService
)
1043 char *comment
= "From Printcap";
1044 int i
= add_a_service(pSERVICE(iDefaultService
),pszPrintername
);
1049 /* note that we do NOT default the availability flag to True - */
1050 /* we take it from the default service passed. This allows all */
1051 /* dynamic printers to be disabled by disabling the [printers] */
1052 /* entry (if/when the 'available' keyword is implemented!). */
1054 /* the printer name is set to the service name. */
1055 string_set(&iSERVICE(i
).szPrintername
,pszPrintername
);
1056 string_set(&iSERVICE(i
).comment
,comment
);
1057 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
1059 DEBUG(3,("adding printer service %s\n",pszPrintername
));
1065 /***************************************************************************
1066 Do a case-insensitive, whitespace-ignoring string compare.
1067 ***************************************************************************/
1068 static int strwicmp(char *psz1
, char *psz2
)
1070 /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
1071 /* appropriate value. */
1081 /* sync the strings on first non-whitespace */
1084 while (isspace(*psz1
))
1086 while (isspace(*psz2
))
1088 if (toupper(*psz1
) != toupper(*psz2
) || *psz1
== '\0' || *psz2
== '\0')
1093 return (*psz1
- *psz2
);
1096 /***************************************************************************
1097 Map a parameter's string representation to something we can use.
1098 Returns False if the parameter string is not recognised, else TRUE.
1099 ***************************************************************************/
1100 static int map_parameter(char *pszParmName
)
1104 if (*pszParmName
== '-')
1107 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1108 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1111 DEBUG(0,( "Unknown parameter encountered: \"%s\"\n", pszParmName
));
1116 /***************************************************************************
1117 Set a boolean variable from the text value stored in the passed string.
1118 Returns True in success, False if the passed string does not correctly
1119 represent a boolean.
1120 ***************************************************************************/
1121 static BOOL
set_boolean(BOOL
*pb
, char *pszParmValue
)
1126 if (strwicmp(pszParmValue
, "yes") == 0 ||
1127 strwicmp(pszParmValue
, "true") == 0 ||
1128 strwicmp(pszParmValue
, "1") == 0)
1131 if (strwicmp(pszParmValue
, "no") == 0 ||
1132 strwicmp(pszParmValue
, "False") == 0 ||
1133 strwicmp(pszParmValue
, "0") == 0)
1137 DEBUG(0,( "Badly formed boolean in configuration file: \"%s\".\n",
1144 /***************************************************************************
1145 Find a service by name. Otherwise works like get_service.
1146 ***************************************************************************/
1147 static int getservicebyname(char *pszServiceName
, service
*pserviceDest
)
1151 for (iService
= iNumServices
- 1; iService
>= 0; iService
--)
1152 if (VALID(iService
) &&
1153 strwicmp(iSERVICE(iService
).szService
, pszServiceName
) == 0)
1155 if (pserviceDest
!= NULL
)
1156 copy_service(pserviceDest
, pSERVICE(iService
), NULL
);
1165 /***************************************************************************
1166 Copy a service structure to another
1168 If pcopymapDest is NULL then copy all fields
1169 ***************************************************************************/
1170 static void copy_service(service
*pserviceDest
,
1171 service
*pserviceSource
,
1175 BOOL bcopyall
= (pcopymapDest
== NULL
);
1177 for (i
=0;parm_table
[i
].label
;i
++)
1178 if (parm_table
[i
].ptr
&& parm_table
[i
].class == P_LOCAL
&&
1179 (bcopyall
|| pcopymapDest
[i
]))
1181 void *def_ptr
= parm_table
[i
].ptr
;
1183 ((char *)pserviceSource
) + PTR_DIFF(def_ptr
,&sDefault
);
1185 ((char *)pserviceDest
) + PTR_DIFF(def_ptr
,&sDefault
);
1187 switch (parm_table
[i
].type
)
1191 *(BOOL
*)dest_ptr
= *(BOOL
*)src_ptr
;
1196 *(int *)dest_ptr
= *(int *)src_ptr
;
1200 *(char *)dest_ptr
= *(char *)src_ptr
;
1204 string_set(dest_ptr
,*(char **)src_ptr
);
1208 string_set(dest_ptr
,*(char **)src_ptr
);
1209 strupper(*(char **)dest_ptr
);
1218 init_copymap(pserviceDest
);
1219 if (pserviceSource
->copymap
)
1220 memcpy((void *)pserviceDest
->copymap
,
1221 (void *)pserviceSource
->copymap
,sizeof(BOOL
)*NUMPARAMETERS
);
1225 /***************************************************************************
1226 Check a service for consistency. Return False if the service is in any way
1227 incomplete or faulty, else True.
1228 ***************************************************************************/
1229 static BOOL
service_ok(int iService
)
1234 if (iSERVICE(iService
).szService
[0] == '\0')
1236 DEBUG(0,( "The following message indicates an internal error:\n"));
1237 DEBUG(0,( "No service name in service entry.\n"));
1241 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1242 /* I can't see why you'd want a non-printable printer service... */
1243 if (strwicmp(iSERVICE(iService
).szService
,PRINTERS_NAME
) == 0)
1244 if (!iSERVICE(iService
).bPrint_ok
)
1246 DEBUG(0,( "WARNING: [%s] service MUST be printable!\n",
1247 iSERVICE(iService
).szService
));
1248 iSERVICE(iService
).bPrint_ok
= True
;
1251 if (iSERVICE(iService
).szPath
[0] == '\0' &&
1252 strwicmp(iSERVICE(iService
).szService
,HOMES_NAME
) != 0)
1254 DEBUG(0,("No path in service %s - using %s\n",iSERVICE(iService
).szService
,tmpdir()));
1255 string_set(&iSERVICE(iService
).szPath
,tmpdir());
1258 /* If a service is flagged unavailable, log the fact at level 0. */
1259 if (!iSERVICE(iService
).bAvailable
)
1260 DEBUG(1,( "NOTE: Service %s is flagged unavailable.\n",
1261 iSERVICE(iService
).szService
));
1266 static struct file_lists
{
1267 struct file_lists
*next
;
1270 } *file_lists
= NULL
;
1272 /*******************************************************************
1273 keep a linked list of all config files so we know when one has changed
1274 it's date and needs to be reloaded
1275 ********************************************************************/
1276 static void add_to_file_list(char *fname
)
1278 struct file_lists
*f
=file_lists
;
1281 if (f
->name
&& !strcmp(f
->name
,fname
)) break;
1286 f
= (struct file_lists
*)malloc(sizeof(file_lists
[0]));
1288 f
->next
= file_lists
;
1289 f
->name
= strdup(fname
);
1300 standard_sub_basic(n2
);
1301 f
->modtime
= file_modtime(n2
);
1306 /*******************************************************************
1307 check if a config file has changed date
1308 ********************************************************************/
1309 BOOL
lp_file_list_changed(void)
1311 struct file_lists
*f
= file_lists
;
1315 standard_sub_basic(n2
);
1316 if (f
->modtime
!= file_modtime(n2
)) return(True
);
1323 /***************************************************************************
1324 handle the interpretation of the coding system parameter
1325 *************************************************************************/
1326 static BOOL
handle_coding_system(char *pszParmValue
,int *val
)
1328 *val
= interpret_coding_system(pszParmValue
,*val
);
1333 /***************************************************************************
1334 handle the interpretation of the character set system parameter
1335 ***************************************************************************/
1336 static BOOL
handle_character_set(char *pszParmValue
,int *val
)
1338 string_set(&Globals
.szCharacterSet
,pszParmValue
);
1339 *val
= interpret_character_set(pszParmValue
,*val
);
1344 /***************************************************************************
1345 handle the interpretation of the protocol parameter
1346 ***************************************************************************/
1347 static BOOL
handle_protocol(char *pszParmValue
,int *val
)
1349 *val
= interpret_protocol(pszParmValue
,*val
);
1353 /***************************************************************************
1354 handle the interpretation of the security parameter
1355 ***************************************************************************/
1356 static BOOL
handle_security(char *pszParmValue
,int *val
)
1358 *val
= interpret_security(pszParmValue
,*val
);
1362 /***************************************************************************
1363 handle the interpretation of the default case
1364 ***************************************************************************/
1365 static BOOL
handle_case(char *pszParmValue
,int *val
)
1367 if (strequal(pszParmValue
,"LOWER"))
1369 else if (strequal(pszParmValue
,"UPPER"))
1374 /***************************************************************************
1375 handle the interpretation of the printing system
1376 ***************************************************************************/
1377 static BOOL
handle_printing(char *pszParmValue
,int *val
)
1379 if (strequal(pszParmValue
,"sysv"))
1381 else if (strequal(pszParmValue
,"aix"))
1383 else if (strequal(pszParmValue
,"hpux"))
1385 else if (strequal(pszParmValue
,"bsd"))
1387 else if (strequal(pszParmValue
,"qnx"))
1389 else if (strequal(pszParmValue
,"plp"))
1391 else if (strequal(pszParmValue
,"lprng"))
1396 /***************************************************************************
1397 handle the valid chars lines
1398 ***************************************************************************/
1399 static BOOL
handle_valid_chars(char *pszParmValue
,char **ptr
)
1401 string_set(ptr
,pszParmValue
);
1403 add_char_string(pszParmValue
);
1408 /***************************************************************************
1409 handle the include operation
1410 ***************************************************************************/
1411 static BOOL
handle_include(char *pszParmValue
,char **ptr
)
1414 strcpy(fname
,pszParmValue
);
1416 add_to_file_list(fname
);
1418 standard_sub_basic(fname
);
1420 string_set(ptr
,fname
);
1422 if (file_exist(fname
,NULL
))
1423 return(pm_process(fname
, do_section
, do_parameter
));
1425 DEBUG(2,("Can't find include file %s\n",fname
));
1431 /***************************************************************************
1432 handle the interpretation of the copy parameter
1433 ***************************************************************************/
1434 static BOOL
handle_copy(char *pszParmValue
,char **ptr
)
1438 service serviceTemp
;
1440 string_set(ptr
,pszParmValue
);
1442 init_service(&serviceTemp
);
1446 DEBUG(3,("Copying service from service %s\n",pszParmValue
));
1448 if ((iTemp
= getservicebyname(pszParmValue
, &serviceTemp
)) >= 0)
1450 if (iTemp
== iServiceIndex
)
1452 DEBUG(0,("Can't copy service %s - unable to copy self!\n",
1457 copy_service(pSERVICE(iServiceIndex
),
1459 iSERVICE(iServiceIndex
).copymap
);
1465 DEBUG(0,( "Unable to copy service - source not found: %s\n",
1470 free_service(&serviceTemp
);
1475 /***************************************************************************
1476 initialise a copymap
1477 ***************************************************************************/
1478 static void init_copymap(service
*pservice
)
1481 if (pservice
->copymap
) free(pservice
->copymap
);
1482 pservice
->copymap
= (BOOL
*)malloc(sizeof(BOOL
)*NUMPARAMETERS
);
1483 if (!pservice
->copymap
)
1484 DEBUG(0,("Couldn't allocate copymap!! (size %d)\n",NUMPARAMETERS
));
1486 for (i
=0;i
<NUMPARAMETERS
;i
++)
1487 pservice
->copymap
[i
] = True
;
1491 /***************************************************************************
1492 Process a parameter.
1493 ***************************************************************************/
1494 static BOOL
do_parameter(char *pszParmName
, char *pszParmValue
)
1497 void *parm_ptr
=NULL
; /* where we are going to store the result */
1500 if (!bInGlobalSection
&& bGlobalOnly
) return(True
);
1502 DEBUG(3,("doing parameter %s = %s\n",pszParmName
,pszParmValue
));
1504 parmnum
= map_parameter(pszParmName
);
1508 DEBUG(0,( "Ignoring unknown parameter \"%s\"\n", pszParmName
));
1512 def_ptr
= parm_table
[parmnum
].ptr
;
1514 /* we might point at a service, the default service or a global */
1515 if (bInGlobalSection
)
1519 if (parm_table
[parmnum
].class == P_GLOBAL
)
1521 DEBUG(0,( "Global parameter %s found in service section!\n",pszParmName
));
1524 parm_ptr
= ((char *)pSERVICE(iServiceIndex
)) + PTR_DIFF(def_ptr
,&sDefault
);
1527 if (!bInGlobalSection
)
1530 if (!iSERVICE(iServiceIndex
).copymap
)
1531 init_copymap(pSERVICE(iServiceIndex
));
1533 /* this handles the aliases - set the copymap for other entries with
1534 the same data pointer */
1535 for (i
=0;parm_table
[i
].label
;i
++)
1536 if (parm_table
[i
].ptr
== parm_table
[parmnum
].ptr
)
1537 iSERVICE(iServiceIndex
).copymap
[i
] = False
;
1540 /* if it is a special case then go ahead */
1541 if (parm_table
[parmnum
].special
)
1543 parm_table
[parmnum
].special(pszParmValue
,parm_ptr
);
1547 /* now switch on the type of variable it is */
1548 switch (parm_table
[parmnum
].type
)
1551 set_boolean(parm_ptr
,pszParmValue
);
1555 set_boolean(parm_ptr
,pszParmValue
);
1556 *(BOOL
*)parm_ptr
= ! *(BOOL
*)parm_ptr
;
1560 *(int *)parm_ptr
= atoi(pszParmValue
);
1564 *(char *)parm_ptr
= *pszParmValue
;
1568 sscanf(pszParmValue
,"%o",(int *)parm_ptr
);
1572 string_set(parm_ptr
,pszParmValue
);
1576 string_set(parm_ptr
,pszParmValue
);
1577 strupper(*(char **)parm_ptr
);
1581 strcpy((char *)parm_ptr
,pszParmValue
);
1585 strcpy((char *)parm_ptr
,pszParmValue
);
1586 strupper((char *)parm_ptr
);
1593 /***************************************************************************
1594 print a parameter of the specified type
1595 ***************************************************************************/
1596 static void print_parameter(parm_type type
,void *ptr
)
1601 printf("%s",BOOLSTR(*(BOOL
*)ptr
));
1605 printf("%s",BOOLSTR(! *(BOOL
*)ptr
));
1609 printf("%d",*(int *)ptr
);
1613 printf("%c",*(char *)ptr
);
1617 printf("0%o",*(int *)ptr
);
1623 printf("%s",(char *)ptr
);
1629 printf("%s",*(char **)ptr
);
1635 /***************************************************************************
1636 check if two parameters are equal
1637 ***************************************************************************/
1638 static BOOL
equal_parameter(parm_type type
,void *ptr1
,void *ptr2
)
1644 return(*((BOOL
*)ptr1
) == *((BOOL
*)ptr2
));
1648 return(*((int *)ptr1
) == *((int *)ptr2
));
1651 return(*((char *)ptr1
) == *((char *)ptr2
));
1656 char *p1
= (char *)ptr1
, *p2
= (char *)ptr2
;
1657 if (p1
&& !*p1
) p1
= NULL
;
1658 if (p2
&& !*p2
) p2
= NULL
;
1659 return(p1
==p2
|| strequal(p1
,p2
));
1664 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1665 if (p1
&& !*p1
) p1
= NULL
;
1666 if (p2
&& !*p2
) p2
= NULL
;
1667 return(p1
==p2
|| strequal(p1
,p2
));
1673 /***************************************************************************
1674 Process a new section (service). At this stage all sections are services.
1675 Later we'll have special sections that permit server parameters to be set.
1676 Returns True on success, False on failure.
1677 ***************************************************************************/
1678 static BOOL
do_section(char *pszSectionName
)
1681 BOOL isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1682 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1685 /* if we were in a global section then do the local inits */
1686 if (bInGlobalSection
&& !isglobal
)
1689 /* if we've just struck a global section, note the fact. */
1690 bInGlobalSection
= isglobal
;
1692 /* check for multiple global sections */
1693 if (bInGlobalSection
)
1695 DEBUG(3,( "Processing section \"[%s]\"\n", pszSectionName
));
1699 if (!bInGlobalSection
&& bGlobalOnly
) return(True
);
1701 /* if we have a current service, tidy it up before moving on */
1704 if (iServiceIndex
>= 0)
1705 bRetval
= service_ok(iServiceIndex
);
1707 /* if all is still well, move to the next record in the services array */
1710 /* We put this here to avoid an odd message order if messages are */
1711 /* issued by the post-processing of a previous section. */
1712 DEBUG(2,( "Processing section \"[%s]\"\n", pszSectionName
));
1714 if ((iServiceIndex
=add_a_service(&sDefault
,pszSectionName
)) < 0)
1716 DEBUG(0,("Failed to add a new service\n"));
1724 /***************************************************************************
1725 Display the contents of the global structure.
1726 ***************************************************************************/
1727 static void dump_globals(void)
1730 printf("Global parameters:\n");
1732 for (i
=0;parm_table
[i
].label
;i
++)
1733 if (parm_table
[i
].class == P_GLOBAL
&&
1734 parm_table
[i
].ptr
&&
1735 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
1737 printf("\t%s: ",parm_table
[i
].label
);
1738 print_parameter(parm_table
[i
].type
,parm_table
[i
].ptr
);
1743 /***************************************************************************
1744 Display the contents of a single services record.
1745 ***************************************************************************/
1746 static void dump_a_service(service
*pService
)
1749 if (pService
== &sDefault
)
1750 printf("\nDefault service parameters:\n");
1752 printf("\nService parameters [%s]:\n",pService
->szService
);
1754 for (i
=0;parm_table
[i
].label
;i
++)
1755 if (parm_table
[i
].class == P_LOCAL
&&
1756 parm_table
[i
].ptr
&&
1757 (*parm_table
[i
].label
!= '-') &&
1758 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
1760 int pdiff
= PTR_DIFF(parm_table
[i
].ptr
,&sDefault
);
1762 if (pService
== &sDefault
|| !equal_parameter(parm_table
[i
].type
,
1763 ((char *)pService
) + pdiff
,
1764 ((char *)&sDefault
) + pdiff
))
1766 printf("\t%s: ",parm_table
[i
].label
);
1767 print_parameter(parm_table
[i
].type
,
1768 ((char *)pService
) + pdiff
);
1775 /***************************************************************************
1776 Display the contents of a single copy structure.
1777 ***************************************************************************/
1778 static void dump_copy_map(BOOL
*pcopymap
)
1781 if (!pcopymap
) return;
1783 printf("\n\tNon-Copied parameters:\n");
1785 for (i
=0;parm_table
[i
].label
;i
++)
1786 if (parm_table
[i
].class == P_LOCAL
&&
1787 parm_table
[i
].ptr
&& !pcopymap
[i
] &&
1788 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
1790 printf("\t\t%s\n",parm_table
[i
].label
);
1795 /***************************************************************************
1796 Return TRUE if the passed service number is within range.
1797 ***************************************************************************/
1798 BOOL
lp_snum_ok(int iService
)
1800 return (LP_SNUM_OK(iService
) && iSERVICE(iService
).bAvailable
);
1804 /***************************************************************************
1805 auto-load some homes and printer services
1806 ***************************************************************************/
1807 static void lp_add_auto_services(char *str
)
1811 int homes
= lp_servicenumber(HOMES_NAME
);
1812 int printers
= lp_servicenumber(PRINTERS_NAME
);
1820 for (p
=strtok(s
,LIST_SEP
);p
;p
=strtok(NULL
,LIST_SEP
))
1822 char *home
= get_home_dir(p
);
1824 if (lp_servicenumber(p
) >= 0) continue;
1826 if (home
&& homes
>= 0)
1828 lp_add_home(p
,homes
,home
);
1832 if (printers
>= 0 && pcap_printername_ok(p
,NULL
))
1833 lp_add_printer(p
,printers
);
1838 /***************************************************************************
1839 auto-load one printer
1840 ***************************************************************************/
1841 static void lp_add_one_printer(char *name
,char *comment
)
1843 int printers
= lp_servicenumber(PRINTERS_NAME
);
1846 if (lp_servicenumber(name
) < 0)
1848 lp_add_printer(name
,printers
);
1849 if ((i
=lp_servicenumber(name
)) >= 0)
1850 string_set(&iSERVICE(i
).comment
,comment
);
1855 /***************************************************************************
1856 auto-load printer services
1857 ***************************************************************************/
1858 static void lp_add_all_printers(void)
1860 int printers
= lp_servicenumber(PRINTERS_NAME
);
1862 if (printers
< 0) return;
1864 pcap_printer_fn(lp_add_one_printer
);
1867 /***************************************************************************
1868 have we loaded a services file yet?
1869 ***************************************************************************/
1870 BOOL
lp_loaded(void)
1875 /***************************************************************************
1876 unload unused services
1877 ***************************************************************************/
1878 void lp_killunused(BOOL (*snumused
)(int ))
1881 for (i
=0;i
<iNumServices
;i
++)
1882 if (VALID(i
) && !snumused(i
))
1884 iSERVICE(i
).valid
= False
;
1885 free_service(pSERVICE(i
));
1889 /***************************************************************************
1890 Load the services array from the services file. Return True on success,
1892 ***************************************************************************/
1893 BOOL
lp_load(char *pszFname
,BOOL global_only
)
1898 add_to_file_list(pszFname
);
1902 bInGlobalSection
= True
;
1903 bGlobalOnly
= global_only
;
1907 strcpy(n2
,pszFname
);
1908 standard_sub_basic(n2
);
1910 /* We get sections first, so have to start 'behind' to make up */
1912 bRetval
= pm_process(n2
, do_section
, do_parameter
);
1914 /* finish up the last section */
1915 DEBUG(3,("pm_process() returned %s\n", BOOLSTR(bRetval
)));
1917 if (iServiceIndex
>= 0)
1918 bRetval
= service_ok(iServiceIndex
);
1920 lp_add_auto_services(lp_auto_services());
1921 if (lp_load_printers())
1922 lp_add_all_printers();
1932 /***************************************************************************
1933 return the max number of services
1934 ***************************************************************************/
1935 int lp_numservices(void)
1937 return(iNumServices
);
1940 /***************************************************************************
1941 Display the contents of the services array in human-readable form.
1942 ***************************************************************************/
1949 dump_a_service(&sDefault
);
1951 for (iService
= 0; iService
< iNumServices
; iService
++)
1953 if (VALID(iService
))
1955 if (iSERVICE(iService
).szService
[0] == '\0')
1957 dump_a_service(pSERVICE(iService
));
1962 /***************************************************************************
1963 Return the number of the service with the given name, or -1 if it doesn't
1964 exist. Note that this is a DIFFERENT ANIMAL from the internal function
1965 getservicebyname()! This works ONLY if all services have been loaded, and
1966 does not copy the found service.
1967 ***************************************************************************/
1968 int lp_servicenumber(char *pszServiceName
)
1972 for (iService
= iNumServices
- 1; iService
>= 0; iService
--)
1973 if (VALID(iService
) &&
1974 strwicmp(iSERVICE(iService
).szService
, pszServiceName
) == 0)
1978 DEBUG(7,("lp_servicenumber: couldn't find %s\n",pszServiceName
));
1983 /*******************************************************************
1984 a useful volume label function
1985 ******************************************************************/
1986 char *volume_label(int snum
)
1988 char *ret
= lp_volume(snum
);
1989 if (!*ret
) return(lp_servicename(snum
));