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
52 /* Set default coding system for KANJI if none specified in Makefile. */
59 extern int DEBUGLEVEL
;
60 extern pstring user_socket_options
;
61 extern pstring myname
;
64 #define GLOBAL_NAME "global"
69 #define PRINTCAP_NAME "/etc/qconfig"
71 #define PRINTCAP_NAME "/etc/printcap"
76 #define PRINTERS_NAME "printers"
80 #define HOMES_NAME "homes"
83 /* some helpful bits */
84 #define pSERVICE(i) ServicePtrs[i]
85 #define iSERVICE(i) (*pSERVICE(i))
86 #define LP_SNUM_OK(iService) (((iService) >= 0) && ((iService) < iNumServices) && iSERVICE(iService).valid)
87 #define VALID(i) iSERVICE(i).valid
89 /* these are the types of parameter we have */
92 P_BOOL
,P_BOOLREV
,P_CHAR
,P_INTEGER
,P_OCTAL
,
93 P_STRING
,P_USTRING
,P_GSTRING
,P_UGSTRING
98 P_LOCAL
,P_GLOBAL
,P_NONE
102 extern BOOL use_getwd_cache
;
104 extern int extra_time_offset
;
105 extern int coding_system
;
108 * This structure describes global (ie., server-wide) parameters.
112 char *szPrintcapname
;
115 char *szDefaultService
;
119 char *szServerString
;
120 char *szAutoServices
;
121 char *szPasswdProgram
;
125 char *szSMBPasswdFile
;
126 char *szPasswordServer
;
127 char *szSocketOptions
;
130 char *szDomainController
;
132 char *szCharacterSet
;
138 char *szRemoteAnnounce
;
139 char *szSocketAddress
;
140 char *szNISHomeMapName
;
141 char *szAnnounceVersion
; /* This is initialised in init_globals */
142 char *szNetbiosAliases
;
161 int client_code_page
;
162 int announce_as
; /* This is initialised in init_globals */
167 BOOL bPreferredMaster
;
170 BOOL bEncryptPasswords
;
177 BOOL bReadPrediction
;
186 static global Globals
;
191 * This structure describes a single service.
199 char *szGuestaccount
;
200 char *szInvalidUsers
;
208 char *szRootPostExec
;
209 char *szPrintcommand
;
212 char *szLppausecommand
;
213 char *szLpresumecommand
;
215 char *szPrinterDriver
;
232 int iCreate_force_mode
;
241 BOOL bShortCasePreserve
;
266 BOOL bDeleteReadonly
;
268 BOOL bDeleteVetoFiles
;
269 char dummy
[3]; /* for alignment */
273 /* This is a default service used to prime a services structure */
274 static service sDefault
=
277 NULL
, /* szService */
279 NULL
, /* szUsername */
280 NULL
, /* szGuestAccount - this is set in init_globals() */
281 NULL
, /* szInvalidUsers */
282 NULL
, /* szValidUsers */
283 NULL
, /* szAdminUsers */
285 NULL
, /* szInclude */
286 NULL
, /* szPreExec */
287 NULL
, /* szPostExec */
288 NULL
, /* szRootPreExec */
289 NULL
, /* szRootPostExec */
290 NULL
, /* szPrintcommand */
291 NULL
, /* szLpqcommand */
292 NULL
, /* szLprmcommand */
293 NULL
, /* szLppausecommand */
294 NULL
, /* szLpresumecommand */
295 NULL
, /* szPrintername */
296 NULL
, /* szPrinterDriver - this is set in init_globals() */
297 NULL
, /* szDontdescend */
298 NULL
, /* szHostsallow */
299 NULL
, /* szHostsdeny */
300 NULL
, /* szMagicScript */
301 NULL
, /* szMagicOutput */
302 NULL
, /* szMangledMap */
303 NULL
, /* szVetoFiles */
304 NULL
, /* szHideFiles */
306 NULL
, /* force user */
307 NULL
, /* force group */
309 NULL
, /* writelist */
311 0, /* iMinPrintSpace */
312 0744, /* iCreate_mask */
313 0000, /* iCreate_force_mode */
314 0755, /* iDir_mask */
315 0000, /* iDir_force_mode */
316 0, /* iMaxConnections */
317 CASE_LOWER
, /* iDefaultCase */
318 False
, /* bAlternatePerm */
319 False
, /* revalidate */
320 False
, /* case sensitive */
321 False
, /* case preserve */
322 False
, /* short case preserve */
323 False
, /* case mangle */
325 True
, /* bHideDotFiles */
326 True
, /* bBrowseable */
327 True
, /* bAvailable */
328 True
, /* bRead_only */
329 True
, /* bNo_set_dir */
330 False
, /* bGuest_only */
331 False
, /* bGuest_ok */
332 False
, /* bPrint_ok */
333 False
, /* bPostscript */
334 False
, /* bMap_system */
335 False
, /* bMap_hidden */
336 True
, /* bMap_archive */
338 False
, /* bStrictLocking */
339 True
, /* bShareModes */
340 False
, /* bOnlyUser */
341 True
, /* bMangledNames */
342 True
, /* bWidelinks */
343 True
, /* bSymlinks */
344 False
, /* bSyncAlways */
345 '~', /* magic char */
347 False
, /* bDeleteReadonly */
348 False
, /* bFakeOplocks */
349 False
, /* bDeleteVetoFiles */
355 /* local variables */
356 static service
**ServicePtrs
= NULL
;
357 static int iNumServices
= 0;
358 static int iServiceIndex
= 0;
359 static BOOL bInGlobalSection
= True
;
360 static BOOL bGlobalOnly
= False
;
361 static int default_server_announce
;
363 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
365 /* prototypes for the special type handlers */
366 static BOOL
handle_valid_chars(char *pszParmValue
, char **ptr
);
367 static BOOL
handle_include(char *pszParmValue
, char **ptr
);
368 static BOOL
handle_copy(char *pszParmValue
, char **ptr
);
369 static BOOL
handle_protocol(char *pszParmValue
,int *val
);
370 static BOOL
handle_security(char *pszParmValue
,int *val
);
371 static BOOL
handle_case(char *pszParmValue
,int *val
);
372 static BOOL
handle_printing(char *pszParmValue
,int *val
);
373 static BOOL
handle_character_set(char *pszParmValue
,int *val
);
374 static BOOL
handle_announce_as(char *pszParmValue
, int *val
);
375 static BOOL
handle_coding_system(char *pszParmValue
,int *val
);
377 static void set_default_server_announce_type(void);
388 {"debuglevel", P_INTEGER
, P_GLOBAL
, &DEBUGLEVEL
, NULL
},
389 {"log level", P_INTEGER
, P_GLOBAL
, &DEBUGLEVEL
, NULL
},
390 {"syslog", P_INTEGER
, P_GLOBAL
, &Globals
.syslog
, NULL
},
391 {"syslog only", P_BOOL
, P_GLOBAL
, &Globals
.bSyslogOnly
, NULL
},
392 {"protocol", P_INTEGER
, P_GLOBAL
, &Globals
.maxprotocol
,handle_protocol
},
393 {"security", P_INTEGER
, P_GLOBAL
, &Globals
.security
,handle_security
},
394 {"printing", P_INTEGER
, P_GLOBAL
, &Globals
.printing
,handle_printing
},
395 {"max disk size", P_INTEGER
, P_GLOBAL
, &Globals
.maxdisksize
, NULL
},
396 {"lpq cache time", P_INTEGER
, P_GLOBAL
, &Globals
.lpqcachetime
, NULL
},
397 {"announce as", P_INTEGER
, P_GLOBAL
, &Globals
.announce_as
, handle_announce_as
},
398 {"encrypt passwords",P_BOOL
, P_GLOBAL
, &Globals
.bEncryptPasswords
, NULL
},
399 {"getwd cache", P_BOOL
, P_GLOBAL
, &use_getwd_cache
, NULL
},
400 {"read prediction", P_BOOL
, P_GLOBAL
, &Globals
.bReadPrediction
, NULL
},
401 {"read bmpx", P_BOOL
, P_GLOBAL
, &Globals
.bReadbmpx
, NULL
},
402 {"read raw", P_BOOL
, P_GLOBAL
, &Globals
.bReadRaw
, NULL
},
403 {"write raw", P_BOOL
, P_GLOBAL
, &Globals
.bWriteRaw
, NULL
},
404 {"use rhosts", P_BOOL
, P_GLOBAL
, &Globals
.bUseRhosts
, NULL
},
405 {"load printers", P_BOOL
, P_GLOBAL
, &Globals
.bLoadPrinters
, NULL
},
406 {"null passwords", P_BOOL
, P_GLOBAL
, &Globals
.bNullPasswords
, NULL
},
407 {"strip dot", P_BOOL
, P_GLOBAL
, &Globals
.bStripDot
, NULL
},
408 {"interfaces", P_STRING
, P_GLOBAL
, &Globals
.szInterfaces
, NULL
},
409 {"password server", P_STRING
, P_GLOBAL
, &Globals
.szPasswordServer
, NULL
},
410 {"socket options", P_GSTRING
, P_GLOBAL
, user_socket_options
, NULL
},
411 {"netbios name", P_UGSTRING
,P_GLOBAL
, myname
, NULL
},
412 {"netbios aliases", P_STRING
, P_GLOBAL
, &Globals
.szNetbiosAliases
, NULL
},
413 {"smbrun", P_STRING
, P_GLOBAL
, &Globals
.szSmbrun
, NULL
},
414 {"log file", P_STRING
, P_GLOBAL
, &Globals
.szLogFile
, NULL
},
415 {"config file", P_STRING
, P_GLOBAL
, &Globals
.szConfigFile
, NULL
},
416 {"smb passwd file", P_STRING
, P_GLOBAL
, &Globals
.szSMBPasswdFile
, NULL
},
417 {"hosts equiv", P_STRING
, P_GLOBAL
, &Globals
.szHostsEquiv
, NULL
},
418 {"preload", P_STRING
, P_GLOBAL
, &Globals
.szAutoServices
, NULL
},
419 {"auto services", P_STRING
, P_GLOBAL
, &Globals
.szAutoServices
, NULL
},
420 {"server string", P_STRING
, P_GLOBAL
, &Globals
.szServerString
, NULL
},
421 {"printcap name", P_STRING
, P_GLOBAL
, &Globals
.szPrintcapname
, NULL
},
422 {"printcap", P_STRING
, P_GLOBAL
, &Globals
.szPrintcapname
, NULL
},
423 {"lock dir", P_STRING
, P_GLOBAL
, &Globals
.szLockDir
, NULL
},
424 {"lock directory", P_STRING
, P_GLOBAL
, &Globals
.szLockDir
, NULL
},
425 {"root directory", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
426 {"root dir", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
427 {"root", P_STRING
, P_GLOBAL
, &Globals
.szRootdir
, NULL
},
428 {"default service", P_STRING
, P_GLOBAL
, &Globals
.szDefaultService
, NULL
},
429 {"default", P_STRING
, P_GLOBAL
, &Globals
.szDefaultService
, NULL
},
430 {"message command", P_STRING
, P_GLOBAL
, &Globals
.szMsgCommand
, NULL
},
431 {"dfree command", P_STRING
, P_GLOBAL
, &Globals
.szDfree
, NULL
},
432 {"passwd program", P_STRING
, P_GLOBAL
, &Globals
.szPasswdProgram
, NULL
},
433 {"passwd chat", P_STRING
, P_GLOBAL
, &Globals
.szPasswdChat
, NULL
},
434 {"valid chars", P_STRING
, P_GLOBAL
, &Globals
.szValidChars
, handle_valid_chars
},
435 {"workgroup", P_USTRING
, P_GLOBAL
, &Globals
.szWorkGroup
, NULL
},
436 {"domain controller",P_STRING
, P_GLOBAL
, &Globals
.szDomainController
,NULL
},
437 {"username map", P_STRING
, P_GLOBAL
, &Globals
.szUsernameMap
, NULL
},
438 {"character set", P_STRING
, P_GLOBAL
, &Globals
.szCharacterSet
, handle_character_set
},
439 {"logon script", P_STRING
, P_GLOBAL
, &Globals
.szLogonScript
, NULL
},
440 {"logon path", P_STRING
, P_GLOBAL
, &Globals
.szLogonPath
, NULL
},
441 {"remote announce", P_STRING
, P_GLOBAL
, &Globals
.szRemoteAnnounce
, NULL
},
442 {"socket address", P_STRING
, P_GLOBAL
, &Globals
.szSocketAddress
, NULL
},
443 {"homedir map", P_STRING
, P_GLOBAL
, &Globals
.szNISHomeMapName
, NULL
},
444 {"announce version", P_STRING
, P_GLOBAL
, &Globals
.szAnnounceVersion
, NULL
},
445 {"max log size", P_INTEGER
, P_GLOBAL
, &Globals
.max_log_size
, NULL
},
446 {"mangled stack", P_INTEGER
, P_GLOBAL
, &Globals
.mangled_stack
, NULL
},
447 {"max mux", P_INTEGER
, P_GLOBAL
, &Globals
.max_mux
, NULL
},
448 {"max xmit", P_INTEGER
, P_GLOBAL
, &Globals
.max_xmit
, NULL
},
449 {"max packet", P_INTEGER
, P_GLOBAL
, &Globals
.max_packet
, NULL
},
450 {"packet size", P_INTEGER
, P_GLOBAL
, &Globals
.max_packet
, NULL
},
451 {"password level", P_INTEGER
, P_GLOBAL
, &Globals
.pwordlevel
, NULL
},
452 {"keepalive", P_INTEGER
, P_GLOBAL
, &keepalive
, NULL
},
453 {"deadtime", P_INTEGER
, P_GLOBAL
, &Globals
.deadtime
, NULL
},
454 {"time offset", P_INTEGER
, P_GLOBAL
, &extra_time_offset
, NULL
},
455 {"read size", P_INTEGER
, P_GLOBAL
, &Globals
.ReadSize
, NULL
},
456 {"shared mem size", P_INTEGER
, P_GLOBAL
, &Globals
.shmem_size
, NULL
},
457 {"shared file entries", P_INTEGER
, P_GLOBAL
, &Globals
.shmem_hash_size
, NULL
},
458 {"coding system", P_INTEGER
, P_GLOBAL
, &coding_system
, handle_coding_system
},
459 {"client code page", P_INTEGER
, P_GLOBAL
, &Globals
.client_code_page
, NULL
},
460 {"os level", P_INTEGER
, P_GLOBAL
, &Globals
.os_level
, NULL
},
461 {"max ttl", P_INTEGER
, P_GLOBAL
, &Globals
.max_ttl
, NULL
},
462 {"dns proxy", P_BOOL
, P_GLOBAL
, &Globals
.bDNSproxy
, NULL
},
463 {"wins support", P_BOOL
, P_GLOBAL
, &Globals
.bWINSsupport
, NULL
},
464 {"wins proxy", P_BOOL
, P_GLOBAL
, &Globals
.bWINSproxy
, NULL
},
465 {"wins server", P_STRING
, P_GLOBAL
, &Globals
.szWINSserver
, NULL
},
466 {"preferred master", P_BOOL
, P_GLOBAL
, &Globals
.bPreferredMaster
, NULL
},
467 {"prefered master", P_BOOL
, P_GLOBAL
, &Globals
.bPreferredMaster
, NULL
},
468 {"local master", P_BOOL
, P_GLOBAL
, &Globals
.bLocalMaster
, NULL
},
469 {"domain master", P_BOOL
, P_GLOBAL
, &Globals
.bDomainMaster
, NULL
},
470 {"domain logons", P_BOOL
, P_GLOBAL
, &Globals
.bDomainLogons
, NULL
},
471 {"browse list", P_BOOL
, P_GLOBAL
, &Globals
.bBrowseList
, NULL
},
472 {"unix realname", P_BOOL
, P_GLOBAL
, &Globals
.bUnixRealname
, NULL
},
473 {"NIS homedir", P_BOOL
, P_GLOBAL
, &Globals
.bNISHomeMap
, NULL
},
474 {"time server", P_BOOL
, P_GLOBAL
, &Globals
.bTimeServer
, NULL
},
475 {"-valid", P_BOOL
, P_LOCAL
, &sDefault
.valid
, NULL
},
476 {"comment", P_STRING
, P_LOCAL
, &sDefault
.comment
, NULL
},
477 {"copy", P_STRING
, P_LOCAL
, &sDefault
.szCopy
, handle_copy
},
478 {"include", P_STRING
, P_LOCAL
, &sDefault
.szInclude
, handle_include
},
479 {"exec", P_STRING
, P_LOCAL
, &sDefault
.szPreExec
, NULL
},
480 {"preexec", P_STRING
, P_LOCAL
, &sDefault
.szPreExec
, NULL
},
481 {"postexec", P_STRING
, P_LOCAL
, &sDefault
.szPostExec
, NULL
},
482 {"root preexec", P_STRING
, P_LOCAL
, &sDefault
.szRootPreExec
, NULL
},
483 {"root postexec", P_STRING
, P_LOCAL
, &sDefault
.szRootPostExec
, NULL
},
484 {"alternate permissions",P_BOOL
,P_LOCAL
, &sDefault
.bAlternatePerm
, NULL
},
485 {"revalidate", P_BOOL
, P_LOCAL
, &sDefault
.bRevalidate
, NULL
},
486 {"default case", P_INTEGER
, P_LOCAL
, &sDefault
.iDefaultCase
, handle_case
},
487 {"case sensitive", P_BOOL
, P_LOCAL
, &sDefault
.bCaseSensitive
, NULL
},
488 {"casesignames", P_BOOL
, P_LOCAL
, &sDefault
.bCaseSensitive
, NULL
},
489 {"preserve case", P_BOOL
, P_LOCAL
, &sDefault
.bCasePreserve
, NULL
},
490 {"short preserve case",P_BOOL
, P_LOCAL
, &sDefault
.bShortCasePreserve
,NULL
},
491 {"mangle case", P_BOOL
, P_LOCAL
, &sDefault
.bCaseMangle
, NULL
},
492 {"mangling char", P_CHAR
, P_LOCAL
, &sDefault
.magic_char
, NULL
},
493 {"browseable", P_BOOL
, P_LOCAL
, &sDefault
.bBrowseable
, NULL
},
494 {"browsable", P_BOOL
, P_LOCAL
, &sDefault
.bBrowseable
, NULL
},
495 {"available", P_BOOL
, P_LOCAL
, &sDefault
.bAvailable
, NULL
},
496 {"path", P_STRING
, P_LOCAL
, &sDefault
.szPath
, NULL
},
497 {"directory", P_STRING
, P_LOCAL
, &sDefault
.szPath
, NULL
},
498 {"username", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
499 {"user", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
500 {"users", P_STRING
, P_LOCAL
, &sDefault
.szUsername
, NULL
},
501 {"guest account", P_STRING
, P_LOCAL
, &sDefault
.szGuestaccount
, NULL
},
502 {"invalid users", P_STRING
, P_LOCAL
, &sDefault
.szInvalidUsers
, NULL
},
503 {"valid users", P_STRING
, P_LOCAL
, &sDefault
.szValidUsers
, NULL
},
504 {"admin users", P_STRING
, P_LOCAL
, &sDefault
.szAdminUsers
, NULL
},
505 {"read list", P_STRING
, P_LOCAL
, &sDefault
.readlist
, NULL
},
506 {"write list", P_STRING
, P_LOCAL
, &sDefault
.writelist
, NULL
},
507 {"volume", P_STRING
, P_LOCAL
, &sDefault
.volume
, NULL
},
508 {"force user", P_STRING
, P_LOCAL
, &sDefault
.force_user
, NULL
},
509 {"force group", P_STRING
, P_LOCAL
, &sDefault
.force_group
, NULL
},
510 {"group", P_STRING
, P_LOCAL
, &sDefault
.force_group
, NULL
},
511 {"read only", P_BOOL
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
512 {"write ok", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
513 {"writeable", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
514 {"writable", P_BOOLREV
, P_LOCAL
, &sDefault
.bRead_only
, NULL
},
515 {"max connections", P_INTEGER
, P_LOCAL
, &sDefault
.iMaxConnections
, NULL
},
516 {"min print space", P_INTEGER
, P_LOCAL
, &sDefault
.iMinPrintSpace
, NULL
},
517 {"create mask", P_OCTAL
, P_LOCAL
, &sDefault
.iCreate_mask
, NULL
},
518 {"create mode", P_OCTAL
, P_LOCAL
, &sDefault
.iCreate_mask
, NULL
},
519 {"force create mode",P_OCTAL
, P_LOCAL
, &sDefault
.iCreate_force_mode
, NULL
},
520 {"directory mask", P_OCTAL
, P_LOCAL
, &sDefault
.iDir_mask
, NULL
},
521 {"directory mode", P_OCTAL
, P_LOCAL
, &sDefault
.iDir_mask
, NULL
},
522 {"force directory mode", P_OCTAL
, P_LOCAL
, &sDefault
.iDir_force_mode
, NULL
},
523 {"set directory", P_BOOLREV
, P_LOCAL
, &sDefault
.bNo_set_dir
, NULL
},
524 {"status", P_BOOL
, P_LOCAL
, &sDefault
.status
, NULL
},
525 {"hide dot files", P_BOOL
, P_LOCAL
, &sDefault
.bHideDotFiles
, NULL
},
526 {"delete veto files",P_BOOL
, P_LOCAL
, &sDefault
.bDeleteVetoFiles
, NULL
},
527 {"veto files", P_STRING
, P_LOCAL
, &sDefault
.szVetoFiles
, NULL
},
528 {"hide files", P_STRING
, P_LOCAL
, &sDefault
.szHideFiles
, NULL
},
529 {"guest only", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_only
, NULL
},
530 {"only guest", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_only
, NULL
},
531 {"guest ok", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_ok
, NULL
},
532 {"public", P_BOOL
, P_LOCAL
, &sDefault
.bGuest_ok
, NULL
},
533 {"print ok", P_BOOL
, P_LOCAL
, &sDefault
.bPrint_ok
, NULL
},
534 {"printable", P_BOOL
, P_LOCAL
, &sDefault
.bPrint_ok
, NULL
},
535 {"postscript", P_BOOL
, P_LOCAL
, &sDefault
.bPostscript
, NULL
},
536 {"map system", P_BOOL
, P_LOCAL
, &sDefault
.bMap_system
, NULL
},
537 {"map hidden", P_BOOL
, P_LOCAL
, &sDefault
.bMap_hidden
, NULL
},
538 {"map archive", P_BOOL
, P_LOCAL
, &sDefault
.bMap_archive
, NULL
},
539 {"locking", P_BOOL
, P_LOCAL
, &sDefault
.bLocking
, NULL
},
540 {"strict locking", P_BOOL
, P_LOCAL
, &sDefault
.bStrictLocking
, NULL
},
541 {"share modes", P_BOOL
, P_LOCAL
, &sDefault
.bShareModes
, NULL
},
542 {"only user", P_BOOL
, P_LOCAL
, &sDefault
.bOnlyUser
, NULL
},
543 {"wide links", P_BOOL
, P_LOCAL
, &sDefault
.bWidelinks
, NULL
},
544 {"follow symlinks", P_BOOL
, P_LOCAL
, &sDefault
.bSymlinks
, NULL
},
545 {"sync always", P_BOOL
, P_LOCAL
, &sDefault
.bSyncAlways
, NULL
},
546 {"mangled names", P_BOOL
, P_LOCAL
, &sDefault
.bMangledNames
, NULL
},
547 {"fake oplocks", P_BOOL
, P_LOCAL
, &sDefault
.bFakeOplocks
, NULL
},
548 {"print command", P_STRING
, P_LOCAL
, &sDefault
.szPrintcommand
, NULL
},
549 {"lpq command", P_STRING
, P_LOCAL
, &sDefault
.szLpqcommand
, NULL
},
550 {"lprm command", P_STRING
, P_LOCAL
, &sDefault
.szLprmcommand
, NULL
},
551 {"lppause command", P_STRING
, P_LOCAL
, &sDefault
.szLppausecommand
, NULL
},
552 {"lpresume command", P_STRING
, P_LOCAL
, &sDefault
.szLpresumecommand
,NULL
},
553 {"printer", P_STRING
, P_LOCAL
, &sDefault
.szPrintername
, NULL
},
554 {"printer name", P_STRING
, P_LOCAL
, &sDefault
.szPrintername
, NULL
},
555 {"printer driver", P_STRING
, P_LOCAL
, &sDefault
.szPrinterDriver
, NULL
},
556 {"hosts allow", P_STRING
, P_LOCAL
, &sDefault
.szHostsallow
, NULL
},
557 {"allow hosts", P_STRING
, P_LOCAL
, &sDefault
.szHostsallow
, NULL
},
558 {"hosts deny", P_STRING
, P_LOCAL
, &sDefault
.szHostsdeny
, NULL
},
559 {"deny hosts", P_STRING
, P_LOCAL
, &sDefault
.szHostsdeny
, NULL
},
560 {"dont descend", P_STRING
, P_LOCAL
, &sDefault
.szDontdescend
, NULL
},
561 {"magic script", P_STRING
, P_LOCAL
, &sDefault
.szMagicScript
, NULL
},
562 {"magic output", P_STRING
, P_LOCAL
, &sDefault
.szMagicOutput
, NULL
},
563 {"mangled map", P_STRING
, P_LOCAL
, &sDefault
.szMangledMap
, NULL
},
564 {"delete readonly", P_BOOL
, P_LOCAL
, &sDefault
.bDeleteReadonly
, NULL
},
566 {NULL
, P_BOOL
, P_NONE
, NULL
, NULL
}
571 /***************************************************************************
572 Initialise the global parameter structure.
573 ***************************************************************************/
574 static void init_globals(void)
576 static BOOL done_init
= False
;
582 bzero((void *)&Globals
,sizeof(Globals
));
584 for (i
= 0; parm_table
[i
].label
; i
++)
585 if ((parm_table
[i
].type
== P_STRING
||
586 parm_table
[i
].type
== P_USTRING
) &&
588 string_init(parm_table
[i
].ptr
,"");
590 string_set(&sDefault
.szGuestaccount
, GUEST_ACCOUNT
);
591 string_set(&sDefault
.szPrinterDriver
, "NULL");
597 DEBUG(3,("Initialising global parameters\n"));
599 #ifdef SMB_PASSWD_FILE
600 string_set(&Globals
.szSMBPasswdFile
, SMB_PASSWD_FILE
);
602 string_set(&Globals
.szPasswdChat
,"*old*password* %o\\n *new*password* %n\\n *new*password* %n\\n *changed*");
603 string_set(&Globals
.szWorkGroup
, WORKGROUP
);
604 string_set(&Globals
.szPasswdProgram
, SMB_PASSWD
);
605 string_set(&Globals
.szPrintcapname
, PRINTCAP_NAME
);
606 string_set(&Globals
.szLockDir
, LOCKDIR
);
607 string_set(&Globals
.szRootdir
, "/");
608 string_set(&Globals
.szSmbrun
, SMBRUN
);
609 string_set(&Globals
.szSocketAddress
, "0.0.0.0");
610 sprintf(s
,"Samba %s",VERSION
);
611 string_set(&Globals
.szServerString
,s
);
612 sprintf(s
,"%d.%d", DEFAULT_MAJOR_VERSION
, DEFAULT_MINOR_VERSION
);
613 string_set(&Globals
.szAnnounceVersion
,s
);
614 Globals
.bLoadPrinters
= True
;
615 Globals
.bUseRhosts
= False
;
616 Globals
.max_packet
= 65535;
617 Globals
.mangled_stack
= 50;
618 Globals
.max_xmit
= 65535;
619 Globals
.max_mux
= 50; /* This is *needed* for profile support. */
620 Globals
.lpqcachetime
= 10;
621 Globals
.pwordlevel
= 0;
622 Globals
.deadtime
= 0;
623 Globals
.max_log_size
= 5000;
624 Globals
.maxprotocol
= PROTOCOL_NT1
;
625 Globals
.security
= SEC_SHARE
;
626 Globals
.bEncryptPasswords
= False
;
627 Globals
.printing
= DEFAULT_PRINTING
;
628 Globals
.bReadRaw
= True
;
629 Globals
.bWriteRaw
= True
;
630 Globals
.bReadPrediction
= False
;
631 Globals
.bReadbmpx
= True
;
632 Globals
.bNullPasswords
= False
;
633 Globals
.bStripDot
= False
;
635 Globals
.bSyslogOnly
= False
;
636 Globals
.os_level
= 0;
637 Globals
.max_ttl
= 60*60*4; /* 2 hours default */
638 Globals
.ReadSize
= 16*1024;
639 Globals
.shmem_size
= SHMEM_SIZE
;
640 Globals
.shmem_hash_size
= SHMEM_HASH_SIZE
;
641 Globals
.announce_as
= ANNOUNCE_AS_NT
;
642 Globals
.bUnixRealname
= False
;
643 #if (defined(NETGROUP) && defined(AUTOMOUNT))
644 Globals
.bNISHomeMap
= False
;
645 string_set(&Globals
.szNISHomeMapName
, "auto.home");
647 coding_system
= interpret_coding_system (KANJI
, SJIS_CODE
);
648 Globals
.client_code_page
= DEFAULT_CLIENT_CODE_PAGE
;
649 Globals
.bTimeServer
= False
;
651 /* these parameters are set to defaults that are more appropriate
652 for the increasing samba install base:
654 as a member of the workgroup, that will possibly become a
655 _local_ master browser (lm = True). this is opposed to a forced
656 local master browser startup (pm = True).
658 doesn't provide WINS server service by default (wsupp = False),
659 and doesn't provide domain master browser services by default, either.
663 Globals
.bPreferredMaster
= False
;
664 Globals
.bLocalMaster
= True
;
665 Globals
.bDomainMaster
= False
;
666 Globals
.bDomainLogons
= False
;
667 Globals
.bBrowseList
= True
;
668 Globals
.bWINSsupport
= False
;
669 Globals
.bWINSproxy
= False
;
671 /* this parameter is currently set to the default functionality
672 in samba. given that w95 and NT is starting to use DNS for
673 server resolution, i expect that at some point it would be
674 sensible to default this to False.
676 this parameter is added because nmbd is a single process, and
677 gethostbyname is a blocking call, which can take out nmbd for
678 several seconds while a dns lookup is performed.
682 Globals
.bDNSproxy
= True
;
685 /***************************************************************************
686 check if a string is initialised and if not then initialise it
687 ***************************************************************************/
688 static void string_initial(char **s
,char *v
)
695 /***************************************************************************
696 Initialise the sDefault parameter structure.
697 ***************************************************************************/
698 static void init_locals(void)
700 /* choose defaults depending on the type of printing */
701 switch (Globals
.printing
)
707 string_initial(&sDefault
.szLpqcommand
,"lpq -P%p");
708 string_initial(&sDefault
.szLprmcommand
,"lprm -P%p %j");
709 string_initial(&sDefault
.szPrintcommand
,"lpr -r -P%p %s");
714 string_initial(&sDefault
.szLpqcommand
,"lpstat -o%p");
715 string_initial(&sDefault
.szLprmcommand
,"cancel %p-%j");
716 string_initial(&sDefault
.szPrintcommand
,"lp -c -d%p %s; rm %s");
718 string_initial(&sDefault
.szLppausecommand
,"lp -i %p-%j -H hold");
719 string_initial(&sDefault
.szLpresumecommand
,"lp -i %p-%j -H resume");
724 string_initial(&sDefault
.szLpqcommand
,"lpq -P%p");
725 string_initial(&sDefault
.szLprmcommand
,"lprm -P%p %j");
726 string_initial(&sDefault
.szPrintcommand
,"lp -r -P%p %s");
734 /******************************************************************* a
735 convenience routine to grab string parameters into a rotating buffer,
736 and run standard_sub_basic on them. The buffers can be written to by
737 callers without affecting the source string.
738 ********************************************************************/
739 char *lp_string(char *s
)
741 static char *bufs
[10];
742 static int buflen
[10];
743 static int next
= -1;
746 int len
= s
?strlen(s
):0;
757 len
= MAX(len
+100,sizeof(pstring
)); /* the +100 is for some
760 if (buflen
[next
] != len
) {
762 if (bufs
[next
]) free(bufs
[next
]);
763 bufs
[next
] = (char *)malloc(len
);
765 DEBUG(0,("out of memory in lp_string()"));
770 ret
= &bufs
[next
][0];
778 standard_sub_basic(ret
);
784 In this section all the functions that are used to access the
785 parameters from the rest of the program are defined
788 #define FN_GLOBAL_STRING(fn_name,ptr) \
789 char *fn_name(void) {return(lp_string(*(char **)(ptr) ? *(char **)(ptr) : ""));}
790 #define FN_GLOBAL_BOOL(fn_name,ptr) \
791 BOOL fn_name(void) {return(*(BOOL *)(ptr));}
792 #define FN_GLOBAL_CHAR(fn_name,ptr) \
793 char fn_name(void) {return(*(char *)(ptr));}
794 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
795 int fn_name(void) {return(*(int *)(ptr));}
797 #define FN_LOCAL_STRING(fn_name,val) \
798 char *fn_name(int i) {return(lp_string((LP_SNUM_OK(i)&&pSERVICE(i)->val)?pSERVICE(i)->val : sDefault.val));}
799 #define FN_LOCAL_BOOL(fn_name,val) \
800 BOOL fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
801 #define FN_LOCAL_CHAR(fn_name,val) \
802 char fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
803 #define FN_LOCAL_INTEGER(fn_name,val) \
804 int fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
806 FN_GLOBAL_STRING(lp_logfile
,&Globals
.szLogFile
)
807 FN_GLOBAL_STRING(lp_smbrun
,&Globals
.szSmbrun
)
808 FN_GLOBAL_STRING(lp_configfile
,&Globals
.szConfigFile
)
809 FN_GLOBAL_STRING(lp_smb_passwd_file
,&Globals
.szSMBPasswdFile
)
810 FN_GLOBAL_STRING(lp_serverstring
,&Globals
.szServerString
)
811 FN_GLOBAL_STRING(lp_printcapname
,&Globals
.szPrintcapname
)
812 FN_GLOBAL_STRING(lp_lockdir
,&Globals
.szLockDir
)
813 FN_GLOBAL_STRING(lp_rootdir
,&Globals
.szRootdir
)
814 FN_GLOBAL_STRING(lp_defaultservice
,&Globals
.szDefaultService
)
815 FN_GLOBAL_STRING(lp_msg_command
,&Globals
.szMsgCommand
)
816 FN_GLOBAL_STRING(lp_dfree_command
,&Globals
.szDfree
)
817 FN_GLOBAL_STRING(lp_hosts_equiv
,&Globals
.szHostsEquiv
)
818 FN_GLOBAL_STRING(lp_auto_services
,&Globals
.szAutoServices
)
819 FN_GLOBAL_STRING(lp_passwd_program
,&Globals
.szPasswdProgram
)
820 FN_GLOBAL_STRING(lp_passwd_chat
,&Globals
.szPasswdChat
)
821 FN_GLOBAL_STRING(lp_passwordserver
,&Globals
.szPasswordServer
)
822 FN_GLOBAL_STRING(lp_workgroup
,&Globals
.szWorkGroup
)
823 FN_GLOBAL_STRING(lp_domain_controller
,&Globals
.szDomainController
)
824 FN_GLOBAL_STRING(lp_username_map
,&Globals
.szUsernameMap
)
825 FN_GLOBAL_STRING(lp_character_set
,&Globals
.szCharacterSet
)
826 FN_GLOBAL_STRING(lp_logon_script
,&Globals
.szLogonScript
)
827 FN_GLOBAL_STRING(lp_logon_path
,&Globals
.szLogonPath
)
828 FN_GLOBAL_STRING(lp_remote_announce
,&Globals
.szRemoteAnnounce
)
829 FN_GLOBAL_STRING(lp_wins_server
,&Globals
.szWINSserver
)
830 FN_GLOBAL_STRING(lp_interfaces
,&Globals
.szInterfaces
)
831 FN_GLOBAL_STRING(lp_socket_address
,&Globals
.szSocketAddress
)
832 FN_GLOBAL_STRING(lp_nis_home_map_name
,&Globals
.szNISHomeMapName
)
833 FN_GLOBAL_STRING(lp_announce_version
,&Globals
.szAnnounceVersion
)
834 FN_GLOBAL_STRING(lp_netbios_aliases
,&Globals
.szNetbiosAliases
)
836 FN_GLOBAL_BOOL(lp_dns_proxy
,&Globals
.bDNSproxy
)
837 FN_GLOBAL_BOOL(lp_wins_support
,&Globals
.bWINSsupport
)
838 FN_GLOBAL_BOOL(lp_wins_proxy
,&Globals
.bWINSproxy
)
839 FN_GLOBAL_BOOL(lp_local_master
,&Globals
.bLocalMaster
)
840 FN_GLOBAL_BOOL(lp_domain_master
,&Globals
.bDomainMaster
)
841 FN_GLOBAL_BOOL(lp_domain_logons
,&Globals
.bDomainLogons
)
842 FN_GLOBAL_BOOL(lp_preferred_master
,&Globals
.bPreferredMaster
)
843 FN_GLOBAL_BOOL(lp_load_printers
,&Globals
.bLoadPrinters
)
844 FN_GLOBAL_BOOL(lp_use_rhosts
,&Globals
.bUseRhosts
)
845 FN_GLOBAL_BOOL(lp_getwdcache
,&use_getwd_cache
)
846 FN_GLOBAL_BOOL(lp_readprediction
,&Globals
.bReadPrediction
)
847 FN_GLOBAL_BOOL(lp_readbmpx
,&Globals
.bReadbmpx
)
848 FN_GLOBAL_BOOL(lp_readraw
,&Globals
.bReadRaw
)
849 FN_GLOBAL_BOOL(lp_writeraw
,&Globals
.bWriteRaw
)
850 FN_GLOBAL_BOOL(lp_null_passwords
,&Globals
.bNullPasswords
)
851 FN_GLOBAL_BOOL(lp_strip_dot
,&Globals
.bStripDot
)
852 FN_GLOBAL_BOOL(lp_encrypted_passwords
,&Globals
.bEncryptPasswords
)
853 FN_GLOBAL_BOOL(lp_syslog_only
,&Globals
.bSyslogOnly
)
854 FN_GLOBAL_BOOL(lp_browse_list
,&Globals
.bBrowseList
)
855 FN_GLOBAL_BOOL(lp_unix_realname
,&Globals
.bUnixRealname
)
856 FN_GLOBAL_BOOL(lp_nis_home_map
,&Globals
.bNISHomeMap
)
857 FN_GLOBAL_BOOL(lp_time_server
,&Globals
.bTimeServer
)
859 FN_GLOBAL_INTEGER(lp_os_level
,&Globals
.os_level
)
860 FN_GLOBAL_INTEGER(lp_max_ttl
,&Globals
.max_ttl
)
861 FN_GLOBAL_INTEGER(lp_max_log_size
,&Globals
.max_log_size
)
862 FN_GLOBAL_INTEGER(lp_mangledstack
,&Globals
.mangled_stack
)
863 FN_GLOBAL_INTEGER(lp_maxxmit
,&Globals
.max_xmit
)
864 FN_GLOBAL_INTEGER(lp_maxmux
,&Globals
.max_mux
)
865 FN_GLOBAL_INTEGER(lp_maxpacket
,&Globals
.max_packet
)
866 FN_GLOBAL_INTEGER(lp_keepalive
,&keepalive
)
867 FN_GLOBAL_INTEGER(lp_passwordlevel
,&Globals
.pwordlevel
)
868 FN_GLOBAL_INTEGER(lp_readsize
,&Globals
.ReadSize
)
869 FN_GLOBAL_INTEGER(lp_shmem_size
,&Globals
.shmem_size
)
870 FN_GLOBAL_INTEGER(lp_shmem_hash_size
,&Globals
.shmem_hash_size
)
871 FN_GLOBAL_INTEGER(lp_deadtime
,&Globals
.deadtime
)
872 FN_GLOBAL_INTEGER(lp_maxprotocol
,&Globals
.maxprotocol
)
873 FN_GLOBAL_INTEGER(lp_security
,&Globals
.security
)
874 FN_GLOBAL_INTEGER(lp_printing
,&Globals
.printing
)
875 FN_GLOBAL_INTEGER(lp_maxdisksize
,&Globals
.maxdisksize
)
876 FN_GLOBAL_INTEGER(lp_lpqcachetime
,&Globals
.lpqcachetime
)
877 FN_GLOBAL_INTEGER(lp_syslog
,&Globals
.syslog
)
878 FN_GLOBAL_INTEGER(lp_client_code_page
,&Globals
.client_code_page
)
879 FN_GLOBAL_INTEGER(lp_announce_as
,&Globals
.announce_as
)
881 FN_LOCAL_STRING(lp_preexec
,szPreExec
)
882 FN_LOCAL_STRING(lp_postexec
,szPostExec
)
883 FN_LOCAL_STRING(lp_rootpreexec
,szRootPreExec
)
884 FN_LOCAL_STRING(lp_rootpostexec
,szRootPostExec
)
885 FN_LOCAL_STRING(lp_servicename
,szService
)
886 FN_LOCAL_STRING(lp_pathname
,szPath
)
887 FN_LOCAL_STRING(lp_dontdescend
,szDontdescend
)
888 FN_LOCAL_STRING(lp_username
,szUsername
)
889 FN_LOCAL_STRING(lp_guestaccount
,szGuestaccount
)
890 FN_LOCAL_STRING(lp_invalid_users
,szInvalidUsers
)
891 FN_LOCAL_STRING(lp_valid_users
,szValidUsers
)
892 FN_LOCAL_STRING(lp_admin_users
,szAdminUsers
)
893 FN_LOCAL_STRING(lp_printcommand
,szPrintcommand
)
894 FN_LOCAL_STRING(lp_lpqcommand
,szLpqcommand
)
895 FN_LOCAL_STRING(lp_lprmcommand
,szLprmcommand
)
896 FN_LOCAL_STRING(lp_lppausecommand
,szLppausecommand
)
897 FN_LOCAL_STRING(lp_lpresumecommand
,szLpresumecommand
)
898 FN_LOCAL_STRING(lp_printername
,szPrintername
)
899 FN_LOCAL_STRING(lp_printerdriver
,szPrinterDriver
)
900 FN_LOCAL_STRING(lp_hostsallow
,szHostsallow
)
901 FN_LOCAL_STRING(lp_hostsdeny
,szHostsdeny
)
902 FN_LOCAL_STRING(lp_magicscript
,szMagicScript
)
903 FN_LOCAL_STRING(lp_magicoutput
,szMagicOutput
)
904 FN_LOCAL_STRING(lp_comment
,comment
)
905 FN_LOCAL_STRING(lp_force_user
,force_user
)
906 FN_LOCAL_STRING(lp_force_group
,force_group
)
907 FN_LOCAL_STRING(lp_readlist
,readlist
)
908 FN_LOCAL_STRING(lp_writelist
,writelist
)
909 FN_LOCAL_STRING(lp_volume
,volume
)
910 FN_LOCAL_STRING(lp_mangled_map
,szMangledMap
)
911 FN_LOCAL_STRING(lp_veto_files
,szVetoFiles
)
912 FN_LOCAL_STRING(lp_hide_files
,szHideFiles
)
914 FN_LOCAL_BOOL(lp_alternate_permissions
,bAlternatePerm
)
915 FN_LOCAL_BOOL(lp_revalidate
,bRevalidate
)
916 FN_LOCAL_BOOL(lp_casesensitive
,bCaseSensitive
)
917 FN_LOCAL_BOOL(lp_preservecase
,bCasePreserve
)
918 FN_LOCAL_BOOL(lp_shortpreservecase
,bShortCasePreserve
)
919 FN_LOCAL_BOOL(lp_casemangle
,bCaseMangle
)
920 FN_LOCAL_BOOL(lp_status
,status
)
921 FN_LOCAL_BOOL(lp_hide_dot_files
,bHideDotFiles
)
922 FN_LOCAL_BOOL(lp_browseable
,bBrowseable
)
923 FN_LOCAL_BOOL(lp_readonly
,bRead_only
)
924 FN_LOCAL_BOOL(lp_no_set_dir
,bNo_set_dir
)
925 FN_LOCAL_BOOL(lp_guest_ok
,bGuest_ok
)
926 FN_LOCAL_BOOL(lp_guest_only
,bGuest_only
)
927 FN_LOCAL_BOOL(lp_print_ok
,bPrint_ok
)
928 FN_LOCAL_BOOL(lp_postscript
,bPostscript
)
929 FN_LOCAL_BOOL(lp_map_hidden
,bMap_hidden
)
930 FN_LOCAL_BOOL(lp_map_archive
,bMap_archive
)
931 FN_LOCAL_BOOL(lp_locking
,bLocking
)
932 FN_LOCAL_BOOL(lp_strict_locking
,bStrictLocking
)
933 FN_LOCAL_BOOL(lp_share_modes
,bShareModes
)
934 FN_LOCAL_BOOL(lp_onlyuser
,bOnlyUser
)
935 FN_LOCAL_BOOL(lp_manglednames
,bMangledNames
)
936 FN_LOCAL_BOOL(lp_widelinks
,bWidelinks
)
937 FN_LOCAL_BOOL(lp_symlinks
,bSymlinks
)
938 FN_LOCAL_BOOL(lp_syncalways
,bSyncAlways
)
939 FN_LOCAL_BOOL(lp_map_system
,bMap_system
)
940 FN_LOCAL_BOOL(lp_delete_readonly
,bDeleteReadonly
)
941 FN_LOCAL_BOOL(lp_fake_oplocks
,bFakeOplocks
)
942 FN_LOCAL_BOOL(lp_recursive_veto_delete
,bDeleteVetoFiles
)
944 FN_LOCAL_INTEGER(lp_create_mode
,iCreate_mask
)
945 FN_LOCAL_INTEGER(lp_force_create_mode
,iCreate_force_mode
)
946 FN_LOCAL_INTEGER(lp_dir_mode
,iDir_mask
)
947 FN_LOCAL_INTEGER(lp_force_dir_mode
,iDir_force_mode
)
948 FN_LOCAL_INTEGER(lp_max_connections
,iMaxConnections
)
949 FN_LOCAL_INTEGER(lp_defaultcase
,iDefaultCase
)
950 FN_LOCAL_INTEGER(lp_minprintspace
,iMinPrintSpace
)
952 FN_LOCAL_CHAR(lp_magicchar
,magic_char
)
956 /* local prototypes */
957 static int strwicmp( char *psz1
, char *psz2
);
958 static int map_parameter( char *pszParmName
);
959 static BOOL
set_boolean( BOOL
*pb
, char *pszParmValue
);
960 static int getservicebyname(char *pszServiceName
, service
*pserviceDest
);
961 static void copy_service( service
*pserviceDest
,
962 service
*pserviceSource
,
963 BOOL
*pcopymapDest
);
964 static BOOL
service_ok(int iService
);
965 static BOOL
do_parameter(char *pszParmName
, char *pszParmValue
);
966 static BOOL
do_section(char *pszSectionName
);
967 static void init_copymap(service
*pservice
);
970 /***************************************************************************
971 initialise a service to the defaults
972 ***************************************************************************/
973 static void init_service(service
*pservice
)
975 bzero((char *)pservice
,sizeof(service
));
976 copy_service(pservice
,&sDefault
,NULL
);
980 /***************************************************************************
981 free the dynamically allocated parts of a service struct
982 ***************************************************************************/
983 static void free_service(service
*pservice
)
989 for (i
=0;parm_table
[i
].label
;i
++)
990 if ((parm_table
[i
].type
== P_STRING
||
991 parm_table
[i
].type
== P_STRING
) &&
992 parm_table
[i
].class == P_LOCAL
)
993 string_free((char **)(((char *)pservice
) + PTR_DIFF(parm_table
[i
].ptr
,&sDefault
)));
996 /***************************************************************************
997 add a new service to the services array initialising it with the given
999 ***************************************************************************/
1000 static int add_a_service(service
*pservice
, char *name
)
1004 int num_to_alloc
= iNumServices
+1;
1006 tservice
= *pservice
;
1008 /* it might already exist */
1011 i
= getservicebyname(name
,NULL
);
1016 /* find an invalid one */
1017 for (i
=0;i
<iNumServices
;i
++)
1018 if (!pSERVICE(i
)->valid
)
1021 /* if not, then create one */
1022 if (i
== iNumServices
)
1024 ServicePtrs
= (service
**)Realloc(ServicePtrs
,sizeof(service
*)*num_to_alloc
);
1026 pSERVICE(iNumServices
) = (service
*)malloc(sizeof(service
));
1028 if (!ServicePtrs
|| !pSERVICE(iNumServices
))
1034 free_service(pSERVICE(i
));
1036 pSERVICE(i
)->valid
= True
;
1038 init_service(pSERVICE(i
));
1039 copy_service(pSERVICE(i
),&tservice
,NULL
);
1041 string_set(&iSERVICE(i
).szService
,name
);
1046 /***************************************************************************
1047 add a new home service, with the specified home directory, defaults coming
1049 ***************************************************************************/
1050 BOOL
lp_add_home(char *pszHomename
, int iDefaultService
, char *pszHomedir
)
1052 int i
= add_a_service(pSERVICE(iDefaultService
),pszHomename
);
1057 if (!(*(iSERVICE(i
).szPath
)) || strequal(iSERVICE(i
).szPath
,lp_pathname(-1)))
1058 string_set(&iSERVICE(i
).szPath
,pszHomedir
);
1059 if (!(*(iSERVICE(i
).comment
)))
1062 sprintf(comment
,"Home directory of %s",pszHomename
);
1063 string_set(&iSERVICE(i
).comment
,comment
);
1065 iSERVICE(i
).bAvailable
= sDefault
.bAvailable
;
1066 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
1068 DEBUG(3,("adding home directory %s at %s\n", pszHomename
, pszHomedir
));
1073 /***************************************************************************
1074 add a new service, based on an old one
1075 ***************************************************************************/
1076 int lp_add_service(char *pszService
, int iDefaultService
)
1078 return(add_a_service(pSERVICE(iDefaultService
),pszService
));
1082 /***************************************************************************
1084 ***************************************************************************/
1085 static BOOL
lp_add_ipc(void)
1088 int i
= add_a_service(&sDefault
,"IPC$");
1093 sprintf(comment
,"IPC Service (%s)",lp_serverstring());
1095 string_set(&iSERVICE(i
).szPath
,tmpdir());
1096 string_set(&iSERVICE(i
).szUsername
,"");
1097 string_set(&iSERVICE(i
).comment
,comment
);
1098 iSERVICE(i
).status
= False
;
1099 iSERVICE(i
).iMaxConnections
= 0;
1100 iSERVICE(i
).bAvailable
= True
;
1101 iSERVICE(i
).bRead_only
= True
;
1102 iSERVICE(i
).bGuest_only
= False
;
1103 iSERVICE(i
).bGuest_ok
= True
;
1104 iSERVICE(i
).bPrint_ok
= False
;
1105 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
1107 DEBUG(3,("adding IPC service\n"));
1113 /***************************************************************************
1114 add a new printer service, with defaults coming from service iFrom
1115 ***************************************************************************/
1116 BOOL
lp_add_printer(char *pszPrintername
, int iDefaultService
)
1118 char *comment
= "From Printcap";
1119 int i
= add_a_service(pSERVICE(iDefaultService
),pszPrintername
);
1124 /* note that we do NOT default the availability flag to True - */
1125 /* we take it from the default service passed. This allows all */
1126 /* dynamic printers to be disabled by disabling the [printers] */
1127 /* entry (if/when the 'available' keyword is implemented!). */
1129 /* the printer name is set to the service name. */
1130 string_set(&iSERVICE(i
).szPrintername
,pszPrintername
);
1131 string_set(&iSERVICE(i
).comment
,comment
);
1132 iSERVICE(i
).bBrowseable
= sDefault
.bBrowseable
;
1133 /* Printers cannot be read_only. */
1134 iSERVICE(i
).bRead_only
= False
;
1135 /* No share modes on printer services. */
1136 iSERVICE(i
).bShareModes
= False
;
1137 /* Printer services must be printable. */
1138 iSERVICE(i
).bPrint_ok
= True
;
1140 DEBUG(3,("adding printer service %s\n",pszPrintername
));
1146 /***************************************************************************
1147 Do a case-insensitive, whitespace-ignoring string compare.
1148 ***************************************************************************/
1149 static int strwicmp(char *psz1
, char *psz2
)
1151 /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
1152 /* appropriate value. */
1162 /* sync the strings on first non-whitespace */
1165 while (isspace(*psz1
))
1167 while (isspace(*psz2
))
1169 if (toupper(*psz1
) != toupper(*psz2
) || *psz1
== '\0' || *psz2
== '\0')
1174 return (*psz1
- *psz2
);
1177 /***************************************************************************
1178 Map a parameter's string representation to something we can use.
1179 Returns False if the parameter string is not recognised, else TRUE.
1180 ***************************************************************************/
1181 static int map_parameter(char *pszParmName
)
1185 if (*pszParmName
== '-')
1188 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1189 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1192 DEBUG(0,( "Unknown parameter encountered: \"%s\"\n", pszParmName
));
1197 /***************************************************************************
1198 Set a boolean variable from the text value stored in the passed string.
1199 Returns True in success, False if the passed string does not correctly
1200 represent a boolean.
1201 ***************************************************************************/
1202 static BOOL
set_boolean(BOOL
*pb
, char *pszParmValue
)
1207 if (strwicmp(pszParmValue
, "yes") == 0 ||
1208 strwicmp(pszParmValue
, "true") == 0 ||
1209 strwicmp(pszParmValue
, "1") == 0)
1212 if (strwicmp(pszParmValue
, "no") == 0 ||
1213 strwicmp(pszParmValue
, "False") == 0 ||
1214 strwicmp(pszParmValue
, "0") == 0)
1218 DEBUG(0,( "Badly formed boolean in configuration file: \"%s\".\n",
1225 /***************************************************************************
1226 Find a service by name. Otherwise works like get_service.
1227 ***************************************************************************/
1228 static int getservicebyname(char *pszServiceName
, service
*pserviceDest
)
1232 for (iService
= iNumServices
- 1; iService
>= 0; iService
--)
1233 if (VALID(iService
) &&
1234 strwicmp(iSERVICE(iService
).szService
, pszServiceName
) == 0)
1236 if (pserviceDest
!= NULL
)
1237 copy_service(pserviceDest
, pSERVICE(iService
), NULL
);
1246 /***************************************************************************
1247 Copy a service structure to another
1249 If pcopymapDest is NULL then copy all fields
1250 ***************************************************************************/
1251 static void copy_service(service
*pserviceDest
,
1252 service
*pserviceSource
,
1256 BOOL bcopyall
= (pcopymapDest
== NULL
);
1258 for (i
=0;parm_table
[i
].label
;i
++)
1259 if (parm_table
[i
].ptr
&& parm_table
[i
].class == P_LOCAL
&&
1260 (bcopyall
|| pcopymapDest
[i
]))
1262 void *def_ptr
= parm_table
[i
].ptr
;
1264 ((char *)pserviceSource
) + PTR_DIFF(def_ptr
,&sDefault
);
1266 ((char *)pserviceDest
) + PTR_DIFF(def_ptr
,&sDefault
);
1268 switch (parm_table
[i
].type
)
1272 *(BOOL
*)dest_ptr
= *(BOOL
*)src_ptr
;
1277 *(int *)dest_ptr
= *(int *)src_ptr
;
1281 *(char *)dest_ptr
= *(char *)src_ptr
;
1285 string_set(dest_ptr
,*(char **)src_ptr
);
1289 string_set(dest_ptr
,*(char **)src_ptr
);
1290 strupper(*(char **)dest_ptr
);
1299 init_copymap(pserviceDest
);
1300 if (pserviceSource
->copymap
)
1301 memcpy((void *)pserviceDest
->copymap
,
1302 (void *)pserviceSource
->copymap
,sizeof(BOOL
)*NUMPARAMETERS
);
1306 /***************************************************************************
1307 Check a service for consistency. Return False if the service is in any way
1308 incomplete or faulty, else True.
1309 ***************************************************************************/
1310 static BOOL
service_ok(int iService
)
1315 if (iSERVICE(iService
).szService
[0] == '\0')
1317 DEBUG(0,( "The following message indicates an internal error:\n"));
1318 DEBUG(0,( "No service name in service entry.\n"));
1322 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1323 /* I can't see why you'd want a non-printable printer service... */
1324 if (strwicmp(iSERVICE(iService
).szService
,PRINTERS_NAME
) == 0)
1325 if (!iSERVICE(iService
).bPrint_ok
)
1327 DEBUG(0,( "WARNING: [%s] service MUST be printable!\n",
1328 iSERVICE(iService
).szService
));
1329 iSERVICE(iService
).bPrint_ok
= True
;
1332 if (iSERVICE(iService
).szPath
[0] == '\0' &&
1333 strwicmp(iSERVICE(iService
).szService
,HOMES_NAME
) != 0)
1335 DEBUG(0,("No path in service %s - using %s\n",iSERVICE(iService
).szService
,tmpdir()));
1336 string_set(&iSERVICE(iService
).szPath
,tmpdir());
1339 /* If a service is flagged unavailable, log the fact at level 0. */
1340 if (!iSERVICE(iService
).bAvailable
)
1341 DEBUG(1,( "NOTE: Service %s is flagged unavailable.\n",
1342 iSERVICE(iService
).szService
));
1347 static struct file_lists
{
1348 struct file_lists
*next
;
1351 } *file_lists
= NULL
;
1353 /*******************************************************************
1354 keep a linked list of all config files so we know when one has changed
1355 it's date and needs to be reloaded
1356 ********************************************************************/
1357 static void add_to_file_list(char *fname
)
1359 struct file_lists
*f
=file_lists
;
1362 if (f
->name
&& !strcmp(f
->name
,fname
)) break;
1367 f
= (struct file_lists
*)malloc(sizeof(file_lists
[0]));
1369 f
->next
= file_lists
;
1370 f
->name
= strdup(fname
);
1381 standard_sub_basic(n2
);
1382 f
->modtime
= file_modtime(n2
);
1387 /*******************************************************************
1388 check if a config file has changed date
1389 ********************************************************************/
1390 BOOL
lp_file_list_changed(void)
1392 struct file_lists
*f
= file_lists
;
1393 DEBUG(6,("lp_file_list_changed()\n"));
1401 standard_sub_basic(n2
);
1403 DEBUG(6,("file %s -> %s last mod_time: %s\n",
1404 f
->name
, n2
, ctime(&f
->modtime
)));
1406 mod_time
= file_modtime(n2
);
1408 if (f
->modtime
!= mod_time
)
1410 DEBUG(6,("file %s modified: %s\n", n2
, ctime(&mod_time
)));
1418 /***************************************************************************
1419 handle the interpretation of the coding system parameter
1420 *************************************************************************/
1421 static BOOL
handle_coding_system(char *pszParmValue
,int *val
)
1423 *val
= interpret_coding_system(pszParmValue
,*val
);
1427 /***************************************************************************
1428 handle the interpretation of the character set system parameter
1429 ***************************************************************************/
1430 static BOOL
handle_character_set(char *pszParmValue
,int *val
)
1432 string_set(&Globals
.szCharacterSet
,pszParmValue
);
1433 *val
= interpret_character_set(pszParmValue
,*val
);
1438 /***************************************************************************
1439 handle the interpretation of the protocol parameter
1440 ***************************************************************************/
1441 static BOOL
handle_protocol(char *pszParmValue
,int *val
)
1443 *val
= interpret_protocol(pszParmValue
,*val
);
1447 /***************************************************************************
1448 handle the interpretation of the security parameter
1449 ***************************************************************************/
1450 static BOOL
handle_security(char *pszParmValue
,int *val
)
1452 *val
= interpret_security(pszParmValue
,*val
);
1456 /***************************************************************************
1457 handle the interpretation of the default case
1458 ***************************************************************************/
1459 static BOOL
handle_case(char *pszParmValue
,int *val
)
1461 if (strnequal(pszParmValue
,"LOWER", 5))
1463 else if (strnequal(pszParmValue
,"UPPER", 5))
1468 /***************************************************************************
1469 handle the interpretation of the printing system
1470 ***************************************************************************/
1471 static BOOL
handle_printing(char *pszParmValue
,int *val
)
1473 if (strnequal(pszParmValue
,"sysv", 4))
1475 else if (strnequal(pszParmValue
,"aix", 3))
1477 else if (strnequal(pszParmValue
,"hpux", 4))
1479 else if (strnequal(pszParmValue
,"bsd", 3))
1481 else if (strnequal(pszParmValue
,"qnx",3))
1483 else if (strnequal(pszParmValue
,"plp", 3))
1485 else if (strnequal(pszParmValue
,"lprng", 5))
1490 /***************************************************************************
1491 handle the announce as parameter
1492 ***************************************************************************/
1493 static BOOL
handle_announce_as(char *pszParmValue
,int *val
)
1495 if (strnequal(pszParmValue
,"NT", 2))
1496 *val
= ANNOUNCE_AS_NT
;
1497 else if (strnequal(pszParmValue
,"win95", 5))
1498 *val
= ANNOUNCE_AS_WIN95
;
1499 else if (strnequal(pszParmValue
,"WfW", 3))
1500 *val
= ANNOUNCE_AS_WFW
;
1504 /***************************************************************************
1505 handle the valid chars lines
1506 ***************************************************************************/
1507 static BOOL
handle_valid_chars(char *pszParmValue
,char **ptr
)
1509 string_set(ptr
,pszParmValue
);
1511 /* A dependency here is that the parameter client code page must be
1512 set before this is called - as calling codepage_initialise()
1513 would overwrite the valid char lines.
1515 codepage_initialise(lp_client_code_page());
1517 add_char_string(pszParmValue
);
1522 /***************************************************************************
1523 handle the include operation
1524 ***************************************************************************/
1525 static BOOL
handle_include(char *pszParmValue
,char **ptr
)
1528 strcpy(fname
,pszParmValue
);
1530 add_to_file_list(fname
);
1532 standard_sub_basic(fname
);
1534 string_set(ptr
,fname
);
1536 if (file_exist(fname
,NULL
))
1537 return(pm_process(fname
, do_section
, do_parameter
));
1539 DEBUG(2,("Can't find include file %s\n",fname
));
1545 /***************************************************************************
1546 handle the interpretation of the copy parameter
1547 ***************************************************************************/
1548 static BOOL
handle_copy(char *pszParmValue
,char **ptr
)
1552 service serviceTemp
;
1554 string_set(ptr
,pszParmValue
);
1556 init_service(&serviceTemp
);
1560 DEBUG(3,("Copying service from service %s\n",pszParmValue
));
1562 if ((iTemp
= getservicebyname(pszParmValue
, &serviceTemp
)) >= 0)
1564 if (iTemp
== iServiceIndex
)
1566 DEBUG(0,("Can't copy service %s - unable to copy self!\n",
1571 copy_service(pSERVICE(iServiceIndex
),
1573 iSERVICE(iServiceIndex
).copymap
);
1579 DEBUG(0,( "Unable to copy service - source not found: %s\n",
1584 free_service(&serviceTemp
);
1589 /***************************************************************************
1590 initialise a copymap
1591 ***************************************************************************/
1592 static void init_copymap(service
*pservice
)
1595 if (pservice
->copymap
) free(pservice
->copymap
);
1596 pservice
->copymap
= (BOOL
*)malloc(sizeof(BOOL
)*NUMPARAMETERS
);
1597 if (!pservice
->copymap
)
1598 DEBUG(0,("Couldn't allocate copymap!! (size %d)\n",NUMPARAMETERS
));
1600 for (i
=0;i
<NUMPARAMETERS
;i
++)
1601 pservice
->copymap
[i
] = True
;
1605 /***************************************************************************
1606 Process a parameter for a particular service number. If snum < 0
1607 then assume we are in the globals
1608 ***************************************************************************/
1609 BOOL
lp_do_parameter(int snum
, char *pszParmName
, char *pszParmValue
)
1612 void *parm_ptr
=NULL
; /* where we are going to store the result */
1615 parmnum
= map_parameter(pszParmName
);
1619 DEBUG(0,( "Ignoring unknown parameter \"%s\"\n", pszParmName
));
1623 def_ptr
= parm_table
[parmnum
].ptr
;
1625 /* we might point at a service, the default service or a global */
1629 if (parm_table
[parmnum
].class == P_GLOBAL
) {
1630 DEBUG(0,( "Global parameter %s found in service section!\n",pszParmName
));
1633 parm_ptr
= ((char *)pSERVICE(snum
)) + PTR_DIFF(def_ptr
,&sDefault
);
1638 if (!iSERVICE(snum
).copymap
)
1639 init_copymap(pSERVICE(snum
));
1641 /* this handles the aliases - set the copymap for other entries with
1642 the same data pointer */
1643 for (i
=0;parm_table
[i
].label
;i
++)
1644 if (parm_table
[i
].ptr
== parm_table
[parmnum
].ptr
)
1645 iSERVICE(snum
).copymap
[i
] = False
;
1648 /* if it is a special case then go ahead */
1649 if (parm_table
[parmnum
].special
) {
1650 parm_table
[parmnum
].special(pszParmValue
,parm_ptr
);
1654 /* now switch on the type of variable it is */
1655 switch (parm_table
[parmnum
].type
)
1658 set_boolean(parm_ptr
,pszParmValue
);
1662 set_boolean(parm_ptr
,pszParmValue
);
1663 *(BOOL
*)parm_ptr
= ! *(BOOL
*)parm_ptr
;
1667 *(int *)parm_ptr
= atoi(pszParmValue
);
1671 *(char *)parm_ptr
= *pszParmValue
;
1675 sscanf(pszParmValue
,"%o",(int *)parm_ptr
);
1679 string_set(parm_ptr
,pszParmValue
);
1683 string_set(parm_ptr
,pszParmValue
);
1684 strupper(*(char **)parm_ptr
);
1688 strcpy((char *)parm_ptr
,pszParmValue
);
1692 strcpy((char *)parm_ptr
,pszParmValue
);
1693 strupper((char *)parm_ptr
);
1700 /***************************************************************************
1701 Process a parameter.
1702 ***************************************************************************/
1703 static BOOL
do_parameter(char *pszParmName
, char *pszParmValue
)
1705 if (!bInGlobalSection
&& bGlobalOnly
) return(True
);
1707 DEBUG(3,("doing parameter %s = %s\n",pszParmName
,pszParmValue
));
1709 return lp_do_parameter(bInGlobalSection
?-2:iServiceIndex
, pszParmName
, pszParmValue
);
1713 /***************************************************************************
1714 print a parameter of the specified type
1715 ***************************************************************************/
1716 static void print_parameter(parm_type type
,void *ptr
, FILE *f
)
1721 fprintf(f
,"%s",BOOLSTR(*(BOOL
*)ptr
));
1725 fprintf(f
,"%s",BOOLSTR(! *(BOOL
*)ptr
));
1729 fprintf(f
,"%d",*(int *)ptr
);
1733 fprintf(f
,"%c",*(char *)ptr
);
1737 fprintf(f
,"0%o",*(int *)ptr
);
1743 fprintf(f
,"%s",(char *)ptr
);
1749 fprintf(f
,"%s",*(char **)ptr
);
1755 /***************************************************************************
1756 print a parameter of the specified type
1757 ***************************************************************************/
1758 static void parameter_string(parm_type type
,void *ptr
,char *s
)
1765 sprintf(s
, "%s",BOOLSTR(*(BOOL
*)ptr
));
1769 sprintf(s
, "%s",BOOLSTR(! *(BOOL
*)ptr
));
1773 sprintf(s
, "%d",*(int *)ptr
);
1777 sprintf(s
, "%c",*(char *)ptr
);
1781 sprintf(s
, "0%o",*(int *)ptr
);
1787 sprintf(s
, "%s",(char *)ptr
);
1793 sprintf(s
, "%s",*(char **)ptr
);
1799 /***************************************************************************
1800 check if two parameters are equal
1801 ***************************************************************************/
1802 static BOOL
equal_parameter(parm_type type
,void *ptr1
,void *ptr2
)
1808 return(*((BOOL
*)ptr1
) == *((BOOL
*)ptr2
));
1812 return(*((int *)ptr1
) == *((int *)ptr2
));
1815 return(*((char *)ptr1
) == *((char *)ptr2
));
1820 char *p1
= (char *)ptr1
, *p2
= (char *)ptr2
;
1821 if (p1
&& !*p1
) p1
= NULL
;
1822 if (p2
&& !*p2
) p2
= NULL
;
1823 return(p1
==p2
|| strequal(p1
,p2
));
1828 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1829 if (p1
&& !*p1
) p1
= NULL
;
1830 if (p2
&& !*p2
) p2
= NULL
;
1831 return(p1
==p2
|| strequal(p1
,p2
));
1837 /***************************************************************************
1838 Process a new section (service). At this stage all sections are services.
1839 Later we'll have special sections that permit server parameters to be set.
1840 Returns True on success, False on failure.
1841 ***************************************************************************/
1842 static BOOL
do_section(char *pszSectionName
)
1845 BOOL isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1846 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1849 /* if we were in a global section then do the local inits */
1850 if (bInGlobalSection
&& !isglobal
)
1853 /* if we've just struck a global section, note the fact. */
1854 bInGlobalSection
= isglobal
;
1856 /* check for multiple global sections */
1857 if (bInGlobalSection
)
1859 DEBUG(3,( "Processing section \"[%s]\"\n", pszSectionName
));
1863 if (!bInGlobalSection
&& bGlobalOnly
) return(True
);
1865 /* if we have a current service, tidy it up before moving on */
1868 if (iServiceIndex
>= 0)
1869 bRetval
= service_ok(iServiceIndex
);
1871 /* if all is still well, move to the next record in the services array */
1874 /* We put this here to avoid an odd message order if messages are */
1875 /* issued by the post-processing of a previous section. */
1876 DEBUG(2,( "Processing section \"[%s]\"\n", pszSectionName
));
1878 if ((iServiceIndex
=add_a_service(&sDefault
,pszSectionName
)) < 0)
1880 DEBUG(0,("Failed to add a new service\n"));
1888 /***************************************************************************
1889 Display the contents of the global structure.
1890 ***************************************************************************/
1891 static void dump_globals(FILE *f
)
1894 fprintf(f
, "# Global parameters\n");
1896 for (i
=0;parm_table
[i
].label
;i
++)
1897 if (parm_table
[i
].class == P_GLOBAL
&&
1898 parm_table
[i
].ptr
&&
1899 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
1901 fprintf(f
,"\t%s = ",parm_table
[i
].label
);
1902 print_parameter(parm_table
[i
].type
,parm_table
[i
].ptr
, f
);
1907 /***************************************************************************
1908 Display the contents of a single services record.
1909 ***************************************************************************/
1910 static void dump_a_service(service
*pService
, FILE *f
)
1913 if (pService
== &sDefault
)
1914 fprintf(f
,"\n\n# Default service parameters\n");
1916 fprintf(f
,"\n[%s]\n",pService
->szService
);
1918 for (i
=0;parm_table
[i
].label
;i
++)
1919 if (parm_table
[i
].class == P_LOCAL
&&
1920 parm_table
[i
].ptr
&&
1921 (*parm_table
[i
].label
!= '-') &&
1922 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
1924 int pdiff
= PTR_DIFF(parm_table
[i
].ptr
,&sDefault
);
1926 if (pService
== &sDefault
|| !equal_parameter(parm_table
[i
].type
,
1927 ((char *)pService
) + pdiff
,
1928 ((char *)&sDefault
) + pdiff
))
1930 fprintf(f
,"\t%s = ",parm_table
[i
].label
);
1931 print_parameter(parm_table
[i
].type
,
1932 ((char *)pService
) + pdiff
, f
);
1939 /***************************************************************************
1940 return info about the next service in a service. snum==-1 gives the default
1941 serice and snum==-2 gives the globals
1943 return 0 when out of parameters
1944 ***************************************************************************/
1945 int lp_next_parameter(int snum
, int *i
, char *label
,
1946 char *value
, int allparameters
)
1949 /* do the globals */
1950 for (;parm_table
[*i
].label
;(*i
)++)
1951 if (parm_table
[*i
].class == P_GLOBAL
&&
1952 parm_table
[*i
].ptr
&&
1953 (*parm_table
[*i
].label
!= '-') &&
1955 (parm_table
[*i
].ptr
!= parm_table
[(*i
)-1].ptr
))) {
1956 strcpy(label
, parm_table
[*i
].label
);
1957 parameter_string(parm_table
[*i
].type
,
1965 service
*pService
= (snum
==-1?&sDefault
:pSERVICE(snum
));
1967 for (;parm_table
[*i
].label
;(*i
)++)
1968 if (parm_table
[*i
].class == P_LOCAL
&&
1969 parm_table
[*i
].ptr
&&
1970 (*parm_table
[*i
].label
!= '-') &&
1972 (parm_table
[*i
].ptr
!= parm_table
[(*i
)-1].ptr
))) {
1973 int pdiff
= PTR_DIFF(parm_table
[*i
].ptr
,&sDefault
);
1975 if (snum
== -1 || allparameters
||
1976 !equal_parameter(parm_table
[*i
].type
,
1977 ((char *)pService
) + pdiff
,
1978 ((char *)&sDefault
) + pdiff
)) {
1979 strcpy(label
, parm_table
[*i
].label
);
1980 parameter_string(parm_table
[*i
].type
,
1981 ((char *)pService
) + pdiff
,
1994 /***************************************************************************
1995 Display the contents of a single copy structure.
1996 ***************************************************************************/
1997 static void dump_copy_map(BOOL
*pcopymap
)
2000 if (!pcopymap
) return;
2002 printf("\n\tNon-Copied parameters:\n");
2004 for (i
=0;parm_table
[i
].label
;i
++)
2005 if (parm_table
[i
].class == P_LOCAL
&&
2006 parm_table
[i
].ptr
&& !pcopymap
[i
] &&
2007 (i
== 0 || (parm_table
[i
].ptr
!= parm_table
[i
-1].ptr
)))
2009 printf("\t\t%s\n",parm_table
[i
].label
);
2014 /***************************************************************************
2015 Return TRUE if the passed service number is within range.
2016 ***************************************************************************/
2017 BOOL
lp_snum_ok(int iService
)
2019 return (LP_SNUM_OK(iService
) && iSERVICE(iService
).bAvailable
);
2023 /***************************************************************************
2024 auto-load some homes and printer services
2025 ***************************************************************************/
2026 static void lp_add_auto_services(char *str
)
2030 int homes
= lp_servicenumber(HOMES_NAME
);
2031 int printers
= lp_servicenumber(PRINTERS_NAME
);
2039 for (p
=strtok(s
,LIST_SEP
);p
;p
=strtok(NULL
,LIST_SEP
))
2041 char *home
= get_home_dir(p
);
2043 if (lp_servicenumber(p
) >= 0) continue;
2045 if (home
&& homes
>= 0)
2047 lp_add_home(p
,homes
,home
);
2051 if (printers
>= 0 && pcap_printername_ok(p
,NULL
))
2052 lp_add_printer(p
,printers
);
2057 /***************************************************************************
2058 auto-load one printer
2059 ***************************************************************************/
2060 static void lp_add_one_printer(char *name
,char *comment
)
2062 int printers
= lp_servicenumber(PRINTERS_NAME
);
2065 if (lp_servicenumber(name
) < 0)
2067 lp_add_printer(name
,printers
);
2068 if ((i
=lp_servicenumber(name
)) >= 0)
2069 string_set(&iSERVICE(i
).comment
,comment
);
2074 /***************************************************************************
2075 auto-load printer services
2076 ***************************************************************************/
2077 static void lp_add_all_printers(void)
2079 int printers
= lp_servicenumber(PRINTERS_NAME
);
2081 if (printers
< 0) return;
2083 pcap_printer_fn(lp_add_one_printer
);
2086 /***************************************************************************
2087 have we loaded a services file yet?
2088 ***************************************************************************/
2089 BOOL
lp_loaded(void)
2094 /***************************************************************************
2095 unload unused services
2096 ***************************************************************************/
2097 void lp_killunused(BOOL (*snumused
)(int ))
2100 for (i
=0;i
<iNumServices
;i
++)
2101 if (VALID(i
) && (!snumused
|| !snumused(i
)))
2103 iSERVICE(i
).valid
= False
;
2104 free_service(pSERVICE(i
));
2108 /***************************************************************************
2109 Load the services array from the services file. Return True on success,
2111 ***************************************************************************/
2112 BOOL
lp_load(char *pszFname
,BOOL global_only
)
2117 add_to_file_list(pszFname
);
2121 bInGlobalSection
= True
;
2122 bGlobalOnly
= global_only
;
2126 strcpy(n2
,pszFname
);
2127 standard_sub_basic(n2
);
2129 /* We get sections first, so have to start 'behind' to make up */
2131 bRetval
= pm_process(n2
, do_section
, do_parameter
);
2133 /* finish up the last section */
2134 DEBUG(3,("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2136 if (iServiceIndex
>= 0)
2137 bRetval
= service_ok(iServiceIndex
);
2139 lp_add_auto_services(lp_auto_services());
2140 if (lp_load_printers())
2141 lp_add_all_printers();
2145 set_default_server_announce_type();
2153 /***************************************************************************
2154 return the max number of services
2155 ***************************************************************************/
2156 int lp_numservices(void)
2158 return(iNumServices
);
2161 /***************************************************************************
2162 Display the contents of the services array in human-readable form.
2163 ***************************************************************************/
2164 void lp_dump(FILE *f
)
2170 dump_a_service(&sDefault
, f
);
2172 for (iService
= 0; iService
< iNumServices
; iService
++)
2174 if (VALID(iService
))
2176 if (iSERVICE(iService
).szService
[0] == '\0')
2178 dump_a_service(pSERVICE(iService
), f
);
2184 /***************************************************************************
2185 Return the number of the service with the given name, or -1 if it doesn't
2186 exist. Note that this is a DIFFERENT ANIMAL from the internal function
2187 getservicebyname()! This works ONLY if all services have been loaded, and
2188 does not copy the found service.
2189 ***************************************************************************/
2190 int lp_servicenumber(char *pszServiceName
)
2194 for (iService
= iNumServices
- 1; iService
>= 0; iService
--)
2195 if (VALID(iService
) &&
2196 strwicmp(iSERVICE(iService
).szService
, pszServiceName
) == 0)
2200 DEBUG(7,("lp_servicenumber: couldn't find %s\n",pszServiceName
));
2205 /*******************************************************************
2206 a useful volume label function
2207 ******************************************************************/
2208 char *volume_label(int snum
)
2210 char *ret
= lp_volume(snum
);
2211 if (!*ret
) return(lp_servicename(snum
));
2217 * nmbd only loads the global section. There seems to be no way to
2218 * determine exactly is a service is printable by only looking at the
2219 * [global] section so for now always announce as a print server. This
2220 * will need looking at in the future. Jeremy (jallison@whistle.com).
2222 /*******************************************************************
2223 Return true if any printer services are defined.
2224 ******************************************************************/
2225 static BOOL
lp_printer_services(void)
2229 for (iService
= iNumServices
- 1; iService
>= 0; iService
--)
2230 if (VALID(iService
) && iSERVICE(iService
).bPrint_ok
)
2236 /*******************************************************************
2237 Set the server type we will announce as via nmbd.
2238 ********************************************************************/
2239 static void set_default_server_announce_type()
2241 default_server_announce
= (SV_TYPE_WORKSTATION
| SV_TYPE_SERVER
|
2242 SV_TYPE_SERVER_UNIX
| SV_TYPE_PRINTQ_SERVER
);
2243 if(lp_announce_as() == ANNOUNCE_AS_NT
)
2244 default_server_announce
|= (SV_TYPE_SERVER_NT
| SV_TYPE_NT
);
2245 else if(lp_announce_as() == ANNOUNCE_AS_WIN95
)
2246 default_server_announce
|= SV_TYPE_WIN95_PLUS
;
2247 else if(lp_announce_as() == ANNOUNCE_AS_WFW
)
2248 default_server_announce
|= SV_TYPE_WFW
;
2249 default_server_announce
|= (lp_time_server() ? SV_TYPE_TIME_SOURCE
: 0);
2251 * nmbd only loads the [global] section. There seems to be no way to
2252 * determine exactly if any service is printable by only looking at the
2253 * [global] section so for now always announce as a print server. This
2254 * will need looking at in the future. Jeremy (jallison@whistle.com).
2257 default_server_announce
|= (lp_printer_services() ? SV_TYPE_PRINTQ_SERVER
: 0);
2262 /*******************************************************************
2264 ********************************************************************/
2265 void lp_rename_service(int snum
, char *new_name
)
2267 string_set(&pSERVICE(snum
)->szService
, new_name
);
2270 /*******************************************************************
2272 ********************************************************************/
2273 void lp_remove_service(int snum
)
2275 pSERVICE(snum
)->valid
= False
;
2278 /*******************************************************************
2280 ********************************************************************/
2281 void lp_copy_service(int snum
, char *new_name
)
2283 char *oldname
= lp_servicename(snum
);
2284 do_section(new_name
);
2286 snum
= lp_servicenumber(new_name
);
2288 lp_do_parameter(snum
, "copy", oldname
);
2293 /*******************************************************************
2294 Get the default server type we will announce as via nmbd.
2295 ********************************************************************/
2296 int lp_default_server_announce(void)
2298 return default_server_announce
;
2301 /*******************************************************************
2302 Split the announce version into major and minor numbers.
2303 ********************************************************************/
2304 int lp_major_announce_version(void)
2306 static BOOL got_major
= False
;
2307 static int major_version
= DEFAULT_MAJOR_VERSION
;
2312 return major_version
;
2315 if((vers
= lp_announce_version()) == NULL
)
2316 return major_version
;
2318 if((p
= strchr(vers
, '.')) == 0)
2319 return major_version
;
2322 major_version
= atoi(vers
);
2323 return major_version
;
2326 int lp_minor_announce_version(void)
2328 static BOOL got_minor
= False
;
2329 static int minor_version
= DEFAULT_MINOR_VERSION
;
2334 return minor_version
;
2337 if((vers
= lp_announce_version()) == NULL
)
2338 return minor_version
;
2340 if((p
= strchr(vers
, '.')) == 0)
2341 return minor_version
;
2344 minor_version
= atoi(p
);
2345 return minor_version
;