s4-smbtorture: add ndr test for nbt_netlogon_packet to avoid future regressions.
[Samba/gebeck_regimport.git] / lib / param / loadparm.c
blob9abd11fc307bfc097557952ef0664abcaf44a2e5
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * Load parameters.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
36 * To add a parameter:
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
45 * Notes:
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
51 * careful!
55 #include "includes.h"
56 #include "version.h"
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
65 #include "s3_param.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
69 #define standard_sub_basic talloc_strdup
71 static bool do_parameter(const char *, const char *, void *);
72 static bool defaults_saved = false;
74 #define LOADPARM_EXTRA_GLOBALS \
75 struct parmlist_entry *param_opt; \
76 char *szRealm; \
77 char *tls_keyfile; \
78 char *tls_certfile; \
79 char *tls_cafile; \
80 char *tls_crlfile; \
81 char *tls_dhpfile; \
82 char *loglevel; \
83 char *panic_action; \
84 int server_role; \
85 int security; \
86 int domain_master; \
87 bool domain_logons; \
88 int bPreferredMaster;
90 #include "param_global.h"
92 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
95 /* prototypes for the special type handlers */
96 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
97 const char *pszParmValue, char **ptr);
98 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
99 const char *pszParmValue, char **ptr);
100 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
101 const char *pszParmValue, char **ptr);
102 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
103 const char *pszParmValue, char **ptr);
104 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
105 const char *pszParmValue, char **ptr);
107 #include "param_enums.c"
109 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
110 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
112 static struct parm_struct parm_table[] = {
114 .label = "server role",
115 .type = P_ENUM,
116 .p_class = P_GLOBAL,
117 .offset = GLOBAL_VAR(server_role),
118 .special = NULL,
119 .enum_list = enum_server_role
122 .label = "domain logons",
123 .type = P_ENUM,
124 .p_class = P_GLOBAL,
125 .offset = GLOBAL_VAR(domain_logons),
126 .special = NULL,
127 .enum_list = enum_bool_auto
130 .label = "domain master",
131 .type = P_ENUM,
132 .p_class = P_GLOBAL,
133 .offset = GLOBAL_VAR(domain_master),
134 .special = NULL,
135 .enum_list = enum_bool_auto
138 .label = "dos charset",
139 .type = P_STRING,
140 .p_class = P_GLOBAL,
141 .offset = GLOBAL_VAR(dos_charset),
142 .special = NULL,
143 .enum_list = NULL
146 .label = "unix charset",
147 .type = P_STRING,
148 .p_class = P_GLOBAL,
149 .offset = GLOBAL_VAR(unix_charset),
150 .special = NULL,
151 .enum_list = NULL
154 .label = "ncalrpc dir",
155 .type = P_STRING,
156 .p_class = P_GLOBAL,
157 .offset = GLOBAL_VAR(ncalrpc_dir),
158 .special = NULL,
159 .enum_list = NULL
162 .label = "comment",
163 .type = P_STRING,
164 .p_class = P_LOCAL,
165 .offset = LOCAL_VAR(comment),
166 .special = NULL,
167 .enum_list = NULL
170 .label = "path",
171 .type = P_STRING,
172 .p_class = P_LOCAL,
173 .offset = LOCAL_VAR(szPath),
174 .special = NULL,
175 .enum_list = NULL
178 .label = "directory",
179 .type = P_STRING,
180 .p_class = P_LOCAL,
181 .offset = LOCAL_VAR(szPath),
182 .special = NULL,
183 .enum_list = NULL
186 .label = "workgroup",
187 .type = P_USTRING,
188 .p_class = P_GLOBAL,
189 .offset = GLOBAL_VAR(szWorkgroup),
190 .special = NULL,
191 .enum_list = NULL
194 .label = "realm",
195 .type = P_STRING,
196 .p_class = P_GLOBAL,
197 .offset = GLOBAL_VAR(szRealm),
198 .special = handle_realm,
199 .enum_list = NULL
202 .label = "netbios name",
203 .type = P_USTRING,
204 .p_class = P_GLOBAL,
205 .offset = GLOBAL_VAR(szNetbiosName),
206 .special = NULL,
207 .enum_list = NULL
210 .label = "netbios aliases",
211 .type = P_LIST,
212 .p_class = P_GLOBAL,
213 .offset = GLOBAL_VAR(szNetbiosAliases),
214 .special = NULL,
215 .enum_list = NULL
218 .label = "netbios scope",
219 .type = P_USTRING,
220 .p_class = P_GLOBAL,
221 .offset = GLOBAL_VAR(szNetbiosScope),
222 .special = NULL,
223 .enum_list = NULL
226 .label = "server string",
227 .type = P_STRING,
228 .p_class = P_GLOBAL,
229 .offset = GLOBAL_VAR(szServerString),
230 .special = NULL,
231 .enum_list = NULL
234 .label = "interfaces",
235 .type = P_LIST,
236 .p_class = P_GLOBAL,
237 .offset = GLOBAL_VAR(szInterfaces),
238 .special = NULL,
239 .enum_list = NULL
242 .label = "bind interfaces only",
243 .type = P_BOOL,
244 .p_class = P_GLOBAL,
245 .offset = GLOBAL_VAR(bBindInterfacesOnly),
246 .special = NULL,
247 .enum_list = NULL
250 .label = "ntvfs handler",
251 .type = P_LIST,
252 .p_class = P_LOCAL,
253 .offset = LOCAL_VAR(ntvfs_handler),
254 .special = NULL,
255 .enum_list = NULL
258 .label = "ntptr providor",
259 .type = P_STRING,
260 .p_class = P_GLOBAL,
261 .offset = GLOBAL_VAR(ntptr_providor),
262 .special = NULL,
263 .enum_list = NULL
266 .label = "passdb backend",
267 .type = P_STRING,
268 .p_class = P_GLOBAL,
269 .offset = GLOBAL_VAR(passdb_backend),
270 .special = NULL,
271 .enum_list = NULL
274 .label = "dcerpc endpoint servers",
275 .type = P_LIST,
276 .p_class = P_GLOBAL,
277 .offset = GLOBAL_VAR(dcerpc_ep_servers),
278 .special = NULL,
279 .enum_list = NULL
282 .label = "server services",
283 .type = P_LIST,
284 .p_class = P_GLOBAL,
285 .offset = GLOBAL_VAR(server_services),
286 .special = NULL,
287 .enum_list = NULL
291 .label = "security",
292 .type = P_ENUM,
293 .p_class = P_GLOBAL,
294 .offset = GLOBAL_VAR(security),
295 .special = NULL,
296 .enum_list = enum_security
299 .label = "encrypt passwords",
300 .type = P_BOOL,
301 .p_class = P_GLOBAL,
302 .offset = GLOBAL_VAR(bEncryptPasswords),
303 .special = NULL,
304 .enum_list = NULL
307 .label = "null passwords",
308 .type = P_BOOL,
309 .p_class = P_GLOBAL,
310 .offset = GLOBAL_VAR(bNullPasswords),
311 .special = NULL,
312 .enum_list = NULL
315 .label = "obey pam restrictions",
316 .type = P_BOOL,
317 .p_class = P_GLOBAL,
318 .offset = GLOBAL_VAR(bObeyPamRestrictions),
319 .special = NULL,
320 .enum_list = NULL
323 .label = "password server",
324 .type = P_LIST,
325 .p_class = P_GLOBAL,
326 .offset = GLOBAL_VAR(szPasswordServers),
327 .special = NULL,
328 .enum_list = NULL
331 .label = "private dir",
332 .type = P_STRING,
333 .p_class = P_GLOBAL,
334 .offset = GLOBAL_VAR(szPrivateDir),
335 .special = NULL,
336 .enum_list = NULL
339 .label = "passwd chat",
340 .type = P_STRING,
341 .p_class = P_GLOBAL,
342 .offset = GLOBAL_VAR(szPasswdChat),
343 .special = NULL,
344 .enum_list = NULL
347 .label = "password level",
348 .type = P_INTEGER,
349 .p_class = P_GLOBAL,
350 .offset = GLOBAL_VAR(pwordlevel),
351 .special = NULL,
352 .enum_list = NULL
355 .label = "lanman auth",
356 .type = P_BOOL,
357 .p_class = P_GLOBAL,
358 .offset = GLOBAL_VAR(bLanmanAuth),
359 .special = NULL,
360 .enum_list = NULL
363 .label = "ntlm auth",
364 .type = P_BOOL,
365 .p_class = P_GLOBAL,
366 .offset = GLOBAL_VAR(bNTLMAuth),
367 .special = NULL,
368 .enum_list = NULL
371 .label = "client NTLMv2 auth",
372 .type = P_BOOL,
373 .p_class = P_GLOBAL,
374 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
375 .special = NULL,
376 .enum_list = NULL
379 .label = "client lanman auth",
380 .type = P_BOOL,
381 .p_class = P_GLOBAL,
382 .offset = GLOBAL_VAR(bClientLanManAuth),
383 .special = NULL,
384 .enum_list = NULL
387 .label = "client plaintext auth",
388 .type = P_BOOL,
389 .p_class = P_GLOBAL,
390 .offset = GLOBAL_VAR(bClientPlaintextAuth),
391 .special = NULL,
392 .enum_list = NULL
395 .label = "client use spnego principal",
396 .type = P_BOOL,
397 .p_class = P_GLOBAL,
398 .offset = GLOBAL_VAR(client_use_spnego_principal),
399 .special = NULL,
400 .enum_list = NULL
404 .label = "read only",
405 .type = P_BOOL,
406 .p_class = P_LOCAL,
407 .offset = LOCAL_VAR(bRead_only),
408 .special = NULL,
409 .enum_list = NULL
413 .label = "create mask",
414 .type = P_OCTAL,
415 .p_class = P_LOCAL,
416 .offset = LOCAL_VAR(iCreate_mask),
417 .special = NULL,
418 .enum_list = NULL
421 .label = "force create mode",
422 .type = P_OCTAL,
423 .p_class = P_LOCAL,
424 .offset = LOCAL_VAR(iCreate_force_mode),
425 .special = NULL,
426 .enum_list = NULL
429 .label = "directory mask",
430 .type = P_OCTAL,
431 .p_class = P_LOCAL,
432 .offset = LOCAL_VAR(iDir_mask),
433 .special = NULL,
434 .enum_list = NULL
437 .label = "force directory mode",
438 .type = P_OCTAL,
439 .p_class = P_LOCAL,
440 .offset = LOCAL_VAR(iDir_force_mode),
441 .special = NULL,
442 .enum_list = NULL
446 .label = "hosts allow",
447 .type = P_LIST,
448 .p_class = P_LOCAL,
449 .offset = LOCAL_VAR(szHostsallow),
450 .special = NULL,
451 .enum_list = NULL
454 .label = "hosts deny",
455 .type = P_LIST,
456 .p_class = P_LOCAL,
457 .offset = LOCAL_VAR(szHostsdeny),
458 .special = NULL,
459 .enum_list = NULL
463 .label = "log level",
464 .type = P_STRING,
465 .p_class = P_GLOBAL,
466 .offset = GLOBAL_VAR(loglevel),
467 .special = handle_debuglevel,
468 .enum_list = NULL
471 .label = "debuglevel",
472 .type = P_STRING,
473 .p_class = P_GLOBAL,
474 .offset = GLOBAL_VAR(loglevel),
475 .special = handle_debuglevel,
476 .enum_list = NULL
479 .label = "log file",
480 .type = P_STRING,
481 .p_class = P_GLOBAL,
482 .offset = GLOBAL_VAR(logfile),
483 .special = handle_logfile,
484 .enum_list = NULL
488 .label = "smb ports",
489 .type = P_LIST,
490 .p_class = P_GLOBAL,
491 .offset = GLOBAL_VAR(smb_ports),
492 .special = NULL,
493 .enum_list = NULL
496 .label = "nbt port",
497 .type = P_INTEGER,
498 .p_class = P_GLOBAL,
499 .offset = GLOBAL_VAR(nbt_port),
500 .special = NULL,
501 .enum_list = NULL
504 .label = "dgram port",
505 .type = P_INTEGER,
506 .p_class = P_GLOBAL,
507 .offset = GLOBAL_VAR(dgram_port),
508 .special = NULL,
509 .enum_list = NULL
512 .label = "cldap port",
513 .type = P_INTEGER,
514 .p_class = P_GLOBAL,
515 .offset = GLOBAL_VAR(cldap_port),
516 .special = NULL,
517 .enum_list = NULL
520 .label = "krb5 port",
521 .type = P_INTEGER,
522 .p_class = P_GLOBAL,
523 .offset = GLOBAL_VAR(krb5_port),
524 .special = NULL,
525 .enum_list = NULL
528 .label = "kpasswd port",
529 .type = P_INTEGER,
530 .p_class = P_GLOBAL,
531 .offset = GLOBAL_VAR(kpasswd_port),
532 .special = NULL,
533 .enum_list = NULL
536 .label = "web port",
537 .type = P_INTEGER,
538 .p_class = P_GLOBAL,
539 .offset = GLOBAL_VAR(web_port),
540 .special = NULL,
541 .enum_list = NULL
544 .label = "tls enabled",
545 .type = P_BOOL,
546 .p_class = P_GLOBAL,
547 .offset = GLOBAL_VAR(tls_enabled),
548 .special = NULL,
549 .enum_list = NULL
552 .label = "tls keyfile",
553 .type = P_STRING,
554 .p_class = P_GLOBAL,
555 .offset = GLOBAL_VAR(tls_keyfile),
556 .special = NULL,
557 .enum_list = NULL
560 .label = "tls certfile",
561 .type = P_STRING,
562 .p_class = P_GLOBAL,
563 .offset = GLOBAL_VAR(tls_certfile),
564 .special = NULL,
565 .enum_list = NULL
568 .label = "tls cafile",
569 .type = P_STRING,
570 .p_class = P_GLOBAL,
571 .offset = GLOBAL_VAR(tls_cafile),
572 .special = NULL,
573 .enum_list = NULL
576 .label = "tls crlfile",
577 .type = P_STRING,
578 .p_class = P_GLOBAL,
579 .offset = GLOBAL_VAR(tls_crlfile),
580 .special = NULL,
581 .enum_list = NULL
584 .label = "tls dh params file",
585 .type = P_STRING,
586 .p_class = P_GLOBAL,
587 .offset = GLOBAL_VAR(tls_dhpfile),
588 .special = NULL,
589 .enum_list = NULL
592 .label = "large readwrite",
593 .type = P_BOOL,
594 .p_class = P_GLOBAL,
595 .offset = GLOBAL_VAR(bLargeReadwrite),
596 .special = NULL,
597 .enum_list = NULL
600 .label = "server max protocol",
601 .type = P_ENUM,
602 .p_class = P_GLOBAL,
603 .offset = GLOBAL_VAR(srv_maxprotocol),
604 .special = NULL,
605 .enum_list = enum_protocol
608 .label = "server min protocol",
609 .type = P_ENUM,
610 .p_class = P_GLOBAL,
611 .offset = GLOBAL_VAR(srv_minprotocol),
612 .special = NULL,
613 .enum_list = enum_protocol
616 .label = "client max protocol",
617 .type = P_ENUM,
618 .p_class = P_GLOBAL,
619 .offset = GLOBAL_VAR(cli_maxprotocol),
620 .special = NULL,
621 .enum_list = enum_protocol
624 .label = "client min protocol",
625 .type = P_ENUM,
626 .p_class = P_GLOBAL,
627 .offset = GLOBAL_VAR(cli_minprotocol),
628 .special = NULL,
629 .enum_list = enum_protocol
632 .label = "unicode",
633 .type = P_BOOL,
634 .p_class = P_GLOBAL,
635 .offset = GLOBAL_VAR(bUnicode),
636 .special = NULL,
637 .enum_list = NULL
640 .label = "read raw",
641 .type = P_BOOL,
642 .p_class = P_GLOBAL,
643 .offset = GLOBAL_VAR(bReadRaw),
644 .special = NULL,
645 .enum_list = NULL
648 .label = "write raw",
649 .type = P_BOOL,
650 .p_class = P_GLOBAL,
651 .offset = GLOBAL_VAR(bWriteRaw),
652 .special = NULL,
653 .enum_list = NULL
656 .label = "disable netbios",
657 .type = P_BOOL,
658 .p_class = P_GLOBAL,
659 .offset = GLOBAL_VAR(bDisableNetbios),
660 .special = NULL,
661 .enum_list = NULL
665 .label = "nt status support",
666 .type = P_BOOL,
667 .p_class = P_GLOBAL,
668 .offset = GLOBAL_VAR(bNTStatusSupport),
669 .special = NULL,
670 .enum_list = NULL
674 .label = "max mux",
675 .type = P_INTEGER,
676 .p_class = P_GLOBAL,
677 .offset = GLOBAL_VAR(max_mux),
678 .special = NULL,
679 .enum_list = NULL
682 .label = "max xmit",
683 .type = P_BYTES,
684 .p_class = P_GLOBAL,
685 .offset = GLOBAL_VAR(max_xmit),
686 .special = NULL,
687 .enum_list = NULL
691 .label = "name resolve order",
692 .type = P_LIST,
693 .p_class = P_GLOBAL,
694 .offset = GLOBAL_VAR(szNameResolveOrder),
695 .special = NULL,
696 .enum_list = NULL
699 .label = "max wins ttl",
700 .type = P_INTEGER,
701 .p_class = P_GLOBAL,
702 .offset = GLOBAL_VAR(max_wins_ttl),
703 .special = NULL,
704 .enum_list = NULL
707 .label = "min wins ttl",
708 .type = P_INTEGER,
709 .p_class = P_GLOBAL,
710 .offset = GLOBAL_VAR(min_wins_ttl),
711 .special = NULL,
712 .enum_list = NULL
715 .label = "time server",
716 .type = P_BOOL,
717 .p_class = P_GLOBAL,
718 .offset = GLOBAL_VAR(bTimeServer),
719 .special = NULL,
720 .enum_list = NULL
723 .label = "unix extensions",
724 .type = P_BOOL,
725 .p_class = P_GLOBAL,
726 .offset = GLOBAL_VAR(bUnixExtensions),
727 .special = NULL,
728 .enum_list = NULL
731 .label = "use spnego",
732 .type = P_BOOL,
733 .p_class = P_GLOBAL,
734 .offset = GLOBAL_VAR(bUseSpnego),
735 .special = NULL,
736 .enum_list = NULL
739 .label = "server signing",
740 .type = P_ENUM,
741 .p_class = P_GLOBAL,
742 .offset = GLOBAL_VAR(server_signing),
743 .special = NULL,
744 .enum_list = enum_smb_signing_vals
747 .label = "client signing",
748 .type = P_ENUM,
749 .p_class = P_GLOBAL,
750 .offset = GLOBAL_VAR(client_signing),
751 .special = NULL,
752 .enum_list = enum_smb_signing_vals
755 .label = "rpc big endian",
756 .type = P_BOOL,
757 .p_class = P_GLOBAL,
758 .offset = GLOBAL_VAR(bRpcBigEndian),
759 .special = NULL,
760 .enum_list = NULL
764 .label = "max connections",
765 .type = P_INTEGER,
766 .p_class = P_LOCAL,
767 .offset = LOCAL_VAR(iMaxConnections),
768 .special = NULL,
769 .enum_list = NULL
772 .label = "paranoid server security",
773 .type = P_BOOL,
774 .p_class = P_GLOBAL,
775 .offset = GLOBAL_VAR(paranoid_server_security),
776 .special = NULL,
777 .enum_list = NULL
780 .label = "socket options",
781 .type = P_STRING,
782 .p_class = P_GLOBAL,
783 .offset = GLOBAL_VAR(socket_options),
784 .special = NULL,
785 .enum_list = NULL
789 .label = "strict sync",
790 .type = P_BOOL,
791 .p_class = P_LOCAL,
792 .offset = LOCAL_VAR(bStrictSync),
793 .special = NULL,
794 .enum_list = NULL
797 .label = "use mmap",
798 .type = P_BOOL,
799 .p_class = P_GLOBAL,
800 .offset = GLOBAL_VAR(bUseMmap),
801 .special = NULL,
802 .enum_list = NULL,
803 .flags = FLAG_ADVANCED,
806 .label = "case insensitive filesystem",
807 .type = P_BOOL,
808 .p_class = P_LOCAL,
809 .offset = LOCAL_VAR(bCIFileSystem),
810 .special = NULL,
811 .enum_list = NULL
815 .label = "max print jobs",
816 .type = P_INTEGER,
817 .p_class = P_LOCAL,
818 .offset = LOCAL_VAR(iMaxPrintJobs),
819 .special = NULL,
820 .enum_list = NULL
823 .label = "printable",
824 .type = P_BOOL,
825 .p_class = P_LOCAL,
826 .offset = LOCAL_VAR(bPrint_ok),
827 .special = NULL,
828 .enum_list = NULL
831 .label = "print ok",
832 .type = P_BOOL,
833 .p_class = P_LOCAL,
834 .offset = LOCAL_VAR(bPrint_ok),
835 .special = NULL,
836 .enum_list = NULL
840 .label = "printer name",
841 .type = P_STRING,
842 .p_class = P_LOCAL,
843 .offset = LOCAL_VAR(szPrintername),
844 .special = NULL,
845 .enum_list = NULL
848 .label = "printer",
849 .type = P_STRING,
850 .p_class = P_LOCAL,
851 .offset = LOCAL_VAR(szPrintername),
852 .special = NULL,
853 .enum_list = NULL
857 .label = "map system",
858 .type = P_BOOL,
859 .p_class = P_LOCAL,
860 .offset = LOCAL_VAR(bMap_system),
861 .special = NULL,
862 .enum_list = NULL
865 .label = "map hidden",
866 .type = P_BOOL,
867 .p_class = P_LOCAL,
868 .offset = LOCAL_VAR(bMap_hidden),
869 .special = NULL,
870 .enum_list = NULL
873 .label = "map archive",
874 .type = P_BOOL,
875 .p_class = P_LOCAL,
876 .offset = LOCAL_VAR(bMap_archive),
877 .special = NULL,
878 .enum_list = NULL
882 .label = "preferred master",
883 .type = P_ENUM,
884 .p_class = P_GLOBAL,
885 .offset = GLOBAL_VAR(bPreferredMaster),
886 .special = NULL,
887 .enum_list = enum_bool_auto
890 .label = "prefered master",
891 .type = P_ENUM,
892 .p_class = P_GLOBAL,
893 .offset = GLOBAL_VAR(bPreferredMaster),
894 .special = NULL,
895 .enum_list = enum_bool_auto
898 .label = "local master",
899 .type = P_BOOL,
900 .p_class = P_GLOBAL,
901 .offset = GLOBAL_VAR(bLocalMaster),
902 .special = NULL,
903 .enum_list = NULL
906 .label = "browseable",
907 .type = P_BOOL,
908 .p_class = P_LOCAL,
909 .offset = LOCAL_VAR(bBrowseable),
910 .special = NULL,
911 .enum_list = NULL
914 .label = "browsable",
915 .type = P_BOOL,
916 .p_class = P_LOCAL,
917 .offset = LOCAL_VAR(bBrowseable),
918 .special = NULL,
919 .enum_list = NULL
923 .label = "wins server",
924 .type = P_LIST,
925 .p_class = P_GLOBAL,
926 .offset = GLOBAL_VAR(szWINSservers),
927 .special = NULL,
928 .enum_list = NULL
931 .label = "wins support",
932 .type = P_BOOL,
933 .p_class = P_GLOBAL,
934 .offset = GLOBAL_VAR(bWINSsupport),
935 .special = NULL,
936 .enum_list = NULL
939 .label = "dns proxy",
940 .type = P_BOOL,
941 .p_class = P_GLOBAL,
942 .offset = GLOBAL_VAR(bWINSdnsProxy),
943 .special = NULL,
944 .enum_list = NULL
947 .label = "wins hook",
948 .type = P_STRING,
949 .p_class = P_GLOBAL,
950 .offset = GLOBAL_VAR(szWINSHook),
951 .special = NULL,
952 .enum_list = NULL
956 .label = "csc policy",
957 .type = P_ENUM,
958 .p_class = P_LOCAL,
959 .offset = LOCAL_VAR(iCSCPolicy),
960 .special = NULL,
961 .enum_list = enum_csc_policy
965 .label = "strict locking",
966 .type = P_BOOL,
967 .p_class = P_LOCAL,
968 .offset = LOCAL_VAR(iStrictLocking),
969 .special = NULL,
970 .enum_list = NULL
973 .label = "oplocks",
974 .type = P_BOOL,
975 .p_class = P_LOCAL,
976 .offset = LOCAL_VAR(bOpLocks),
977 .special = NULL,
978 .enum_list = NULL
982 .label = "share backend",
983 .type = P_STRING,
984 .p_class = P_GLOBAL,
985 .offset = GLOBAL_VAR(szShareBackend),
986 .special = NULL,
987 .enum_list = NULL
990 .label = "preload",
991 .type = P_STRING,
992 .p_class = P_GLOBAL,
993 .offset = GLOBAL_VAR(szAutoServices),
994 .special = NULL,
995 .enum_list = NULL
998 .label = "auto services",
999 .type = P_STRING,
1000 .p_class = P_GLOBAL,
1001 .offset = GLOBAL_VAR(szAutoServices),
1002 .special = NULL,
1003 .enum_list = NULL
1006 .label = "lock dir",
1007 .type = P_STRING,
1008 .p_class = P_GLOBAL,
1009 .offset = GLOBAL_VAR(szLockDir),
1010 .special = NULL,
1011 .enum_list = NULL
1014 .label = "lock directory",
1015 .type = P_STRING,
1016 .p_class = P_GLOBAL,
1017 .offset = GLOBAL_VAR(szLockDir),
1018 .special = NULL,
1019 .enum_list = NULL
1022 .label = "state directory",
1023 .type = P_STRING,
1024 .p_class = P_GLOBAL,
1025 .offset = GLOBAL_VAR(szStateDir),
1026 .special = NULL,
1027 .enum_list = NULL
1030 .label = "cache directory",
1031 .type = P_STRING,
1032 .p_class = P_GLOBAL,
1033 .offset = GLOBAL_VAR(szCacheDir),
1034 .special = NULL,
1035 .enum_list = NULL
1038 .label = "pid directory",
1039 .type = P_STRING,
1040 .p_class = P_GLOBAL,
1041 .offset = GLOBAL_VAR(szPidDir),
1042 .special = NULL,
1043 .enum_list = NULL
1047 .label = "socket address",
1048 .type = P_STRING,
1049 .p_class = P_GLOBAL,
1050 .offset = GLOBAL_VAR(szSocketAddress),
1051 .special = NULL,
1052 .enum_list = NULL
1055 .label = "copy",
1056 .type = P_STRING,
1057 .p_class = P_LOCAL,
1058 .offset = LOCAL_VAR(szCopy),
1059 .special = handle_copy,
1060 .enum_list = NULL
1063 .label = "include",
1064 .type = P_STRING,
1065 .p_class = P_LOCAL,
1066 .offset = LOCAL_VAR(szInclude),
1067 .special = handle_include,
1068 .enum_list = NULL
1072 .label = "available",
1073 .type = P_BOOL,
1074 .p_class = P_LOCAL,
1075 .offset = LOCAL_VAR(bAvailable),
1076 .special = NULL,
1077 .enum_list = NULL
1080 .label = "volume",
1081 .type = P_STRING,
1082 .p_class = P_LOCAL,
1083 .offset = LOCAL_VAR(volume),
1084 .special = NULL,
1085 .enum_list = NULL
1088 .label = "fstype",
1089 .type = P_STRING,
1090 .p_class = P_LOCAL,
1091 .offset = LOCAL_VAR(fstype),
1092 .special = NULL,
1093 .enum_list = NULL
1097 .label = "panic action",
1098 .type = P_STRING,
1099 .p_class = P_GLOBAL,
1100 .offset = GLOBAL_VAR(panic_action),
1101 .special = NULL,
1102 .enum_list = NULL
1106 .label = "msdfs root",
1107 .type = P_BOOL,
1108 .p_class = P_LOCAL,
1109 .offset = LOCAL_VAR(bMSDfsRoot),
1110 .special = NULL,
1111 .enum_list = NULL
1114 .label = "host msdfs",
1115 .type = P_BOOL,
1116 .p_class = P_GLOBAL,
1117 .offset = GLOBAL_VAR(bHostMSDfs),
1118 .special = NULL,
1119 .enum_list = NULL
1122 .label = "winbind separator",
1123 .type = P_STRING,
1124 .p_class = P_GLOBAL,
1125 .offset = GLOBAL_VAR(szWinbindSeparator),
1126 .special = NULL,
1127 .enum_list = NULL
1130 .label = "winbindd socket directory",
1131 .type = P_STRING,
1132 .p_class = P_GLOBAL,
1133 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1134 .special = NULL,
1135 .enum_list = NULL
1138 .label = "winbindd privileged socket directory",
1139 .type = P_STRING,
1140 .p_class = P_GLOBAL,
1141 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1142 .special = NULL,
1143 .enum_list = NULL
1146 .label = "winbind sealed pipes",
1147 .type = P_BOOL,
1148 .p_class = P_GLOBAL,
1149 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1150 .special = NULL,
1151 .enum_list = NULL
1154 .label = "template shell",
1155 .type = P_STRING,
1156 .p_class = P_GLOBAL,
1157 .offset = GLOBAL_VAR(szTemplateShell),
1158 .special = NULL,
1159 .enum_list = NULL
1162 .label = "template homedir",
1163 .type = P_STRING,
1164 .p_class = P_GLOBAL,
1165 .offset = GLOBAL_VAR(szTemplateHomedir),
1166 .special = NULL,
1167 .enum_list = NULL
1170 .label = "idmap trusted only",
1171 .type = P_BOOL,
1172 .p_class = P_GLOBAL,
1173 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1174 .special = NULL,
1175 .enum_list = NULL
1179 .label = "ntp signd socket directory",
1180 .type = P_STRING,
1181 .p_class = P_GLOBAL,
1182 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1183 .special = NULL,
1184 .enum_list = NULL
1187 .label = "rndc command",
1188 .type = P_CMDLIST,
1189 .p_class = P_GLOBAL,
1190 .offset = GLOBAL_VAR(szRNDCCommand),
1191 .special = NULL,
1192 .enum_list = NULL
1195 .label = "dns update command",
1196 .type = P_CMDLIST,
1197 .p_class = P_GLOBAL,
1198 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1199 .special = NULL,
1200 .enum_list = NULL
1203 .label = "spn update command",
1204 .type = P_CMDLIST,
1205 .p_class = P_GLOBAL,
1206 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1207 .special = NULL,
1208 .enum_list = NULL
1211 .label = "nsupdate command",
1212 .type = P_CMDLIST,
1213 .p_class = P_GLOBAL,
1214 .offset = GLOBAL_VAR(szNSUpdateCommand),
1215 .special = NULL,
1216 .enum_list = NULL
1219 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1223 /* local variables */
1224 struct loadparm_context {
1225 const char *szConfigFile;
1226 struct loadparm_global *globals;
1227 struct loadparm_service **services;
1228 struct loadparm_service *sDefault;
1229 struct smb_iconv_handle *iconv_handle;
1230 int iNumServices;
1231 struct loadparm_service *currentService;
1232 bool bInGlobalSection;
1233 struct file_lists {
1234 struct file_lists *next;
1235 char *name;
1236 char *subfname;
1237 time_t modtime;
1238 } *file_lists;
1239 unsigned int flags[NUMPARAMETERS];
1240 bool loaded;
1241 bool refuse_free;
1242 bool global; /* Is this the global context, which may set
1243 * global variables such as debug level etc? */
1244 const struct loadparm_s3_context *s3_fns;
1248 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1250 if (lp_ctx->s3_fns) {
1251 return lp_ctx->s3_fns->get_default_loadparm_service();
1253 return lp_ctx->sDefault;
1257 * Convenience routine to grab string parameters into temporary memory
1258 * and run standard_sub_basic on them.
1260 * The buffers can be written to by
1261 * callers without affecting the source string.
1264 static const char *lp_string(const char *s)
1266 #if 0 /* until REWRITE done to make thread-safe */
1267 size_t len = s ? strlen(s) : 0;
1268 char *ret;
1269 #endif
1271 /* The follow debug is useful for tracking down memory problems
1272 especially if you have an inner loop that is calling a lp_*()
1273 function that returns a string. Perhaps this debug should be
1274 present all the time? */
1276 #if 0
1277 DEBUG(10, ("lp_string(%s)\n", s));
1278 #endif
1280 #if 0 /* until REWRITE done to make thread-safe */
1281 if (!lp_talloc)
1282 lp_talloc = talloc_init("lp_talloc");
1284 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1286 if (!ret)
1287 return NULL;
1289 if (!s)
1290 *ret = 0;
1291 else
1292 strlcpy(ret, s, len);
1294 if (trim_string(ret, "\"", "\"")) {
1295 if (strchr(ret,'"') != NULL)
1296 strlcpy(ret, s, len);
1299 standard_sub_basic(ret,len+100);
1300 return (ret);
1301 #endif
1302 return s;
1306 In this section all the functions that are used to access the
1307 parameters from the rest of the program are defined
1311 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1312 * for code compatibility between existing Samba4 and Samba3 code.
1315 /* this global context supports the lp_*() function varients */
1316 static struct loadparm_context *global_loadparm_context;
1318 #define lpcfg_default_service global_loadparm_context->sDefault
1319 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1321 #define FN_GLOBAL_STRING(fn_name,var_name) \
1322 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1323 if (lp_ctx == NULL) return NULL; \
1324 if (lp_ctx->s3_fns) { \
1325 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1326 return lp_ctx->s3_fns->fn_name(); \
1328 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1331 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1332 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1333 if (lp_ctx == NULL) return NULL; \
1334 if (lp_ctx->s3_fns) { \
1335 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1336 return lp_ctx->s3_fns->fn_name(); \
1338 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1341 #define FN_GLOBAL_LIST(fn_name,var_name) \
1342 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1343 if (lp_ctx == NULL) return NULL; \
1344 if (lp_ctx->s3_fns) { \
1345 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1346 return lp_ctx->s3_fns->fn_name(); \
1348 return lp_ctx->globals->var_name; \
1351 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1352 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1353 if (lp_ctx == NULL) return false; \
1354 if (lp_ctx->s3_fns) { \
1355 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1356 return lp_ctx->s3_fns->fn_name(); \
1358 return lp_ctx->globals->var_name; \
1361 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1362 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1363 if (lp_ctx->s3_fns) { \
1364 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1365 return lp_ctx->s3_fns->fn_name(); \
1367 return lp_ctx->globals->var_name; \
1370 /* Local parameters don't need the ->s3_fns because the struct
1371 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1372 * hook */
1373 #define FN_LOCAL_STRING(fn_name,val) \
1374 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1375 struct loadparm_service *sDefault) { \
1376 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1379 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1381 #define FN_LOCAL_LIST(fn_name,val) \
1382 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1383 struct loadparm_service *sDefault) {\
1384 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1387 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1389 #define FN_LOCAL_BOOL(fn_name,val) \
1390 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1391 struct loadparm_service *sDefault) { \
1392 return((service != NULL)? service->val : sDefault->val); \
1395 #define FN_LOCAL_INTEGER(fn_name,val) \
1396 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1397 struct loadparm_service *sDefault) { \
1398 return((service != NULL)? service->val : sDefault->val); \
1401 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1403 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1405 #define FN_LOCAL_CHAR(fn_name,val) \
1406 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1407 struct loadparm_service *sDefault) { \
1408 return((service != NULL)? service->val : sDefault->val); \
1411 #include "lib/param/param_functions.c"
1413 FN_GLOBAL_LIST(smb_ports, smb_ports)
1414 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1415 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1416 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1417 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1418 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1419 FN_GLOBAL_INTEGER(web_port, web_port)
1420 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1421 FN_GLOBAL_STRING(logfile, logfile)
1422 FN_GLOBAL_STRING(share_backend, szShareBackend)
1423 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1424 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1425 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1426 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1427 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1428 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1429 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1430 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1431 FN_GLOBAL_STRING(serverstring, szServerString)
1432 FN_GLOBAL_STRING(lockdir, szLockDir)
1433 FN_GLOBAL_STRING(statedir, szStateDir)
1434 FN_GLOBAL_STRING(cachedir, szCacheDir)
1435 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1436 FN_GLOBAL_STRING(dos_charset, dos_charset)
1437 FN_GLOBAL_STRING(unix_charset, unix_charset)
1438 FN_GLOBAL_STRING(piddir, szPidDir)
1439 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1440 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1441 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1442 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1443 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1444 FN_GLOBAL_LIST(server_services, server_services)
1445 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1446 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1447 FN_GLOBAL_STRING(auto_services, szAutoServices)
1448 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1449 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1450 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1451 FN_GLOBAL_STRING(realm, szRealm_upper)
1452 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1453 FN_GLOBAL_STRING(socket_options, socket_options)
1454 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1455 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1456 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1457 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1458 FN_GLOBAL_LIST(interfaces, szInterfaces)
1459 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1460 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1461 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1462 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1463 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1464 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1465 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1466 FN_GLOBAL_BOOL(readraw, bReadRaw)
1467 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1468 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1469 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1470 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1471 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1472 FN_GLOBAL_BOOL(time_server, bTimeServer)
1473 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1474 FN_GLOBAL_BOOL(unicode, bUnicode)
1475 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1476 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1477 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1478 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1479 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1480 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1481 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1482 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1483 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1484 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1485 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1486 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1487 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1488 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1489 FN_GLOBAL_INTEGER(maxmux, max_mux)
1490 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1491 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1492 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1493 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1494 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1495 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1496 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1498 FN_GLOBAL_INTEGER(server_signing, server_signing)
1499 FN_GLOBAL_INTEGER(client_signing, client_signing)
1501 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1503 /* local prototypes */
1504 static int map_parameter(const char *pszParmName);
1505 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1506 const char *pszServiceName);
1507 static void copy_service(struct loadparm_service *pserviceDest,
1508 struct loadparm_service *pserviceSource,
1509 struct bitmap *pcopymapDest);
1510 static bool lpcfg_service_ok(struct loadparm_service *service);
1511 static bool do_section(const char *pszSectionName, void *);
1512 static void init_copymap(struct loadparm_service *pservice);
1514 /* This is a helper function for parametrical options support. */
1515 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1516 /* Actual parametrical functions are quite simple */
1517 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1518 struct loadparm_service *service,
1519 const char *type, const char *option)
1521 char *vfskey_tmp = NULL;
1522 char *vfskey = NULL;
1523 struct parmlist_entry *data;
1525 if (lp_ctx == NULL)
1526 return NULL;
1528 if (lp_ctx->s3_fns) {
1529 return lp_ctx->s3_fns->get_parametric(service, type, option);
1532 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1534 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1535 if (vfskey_tmp == NULL) return NULL;
1536 vfskey = strlower_talloc(NULL, vfskey_tmp);
1537 talloc_free(vfskey_tmp);
1539 while (data) {
1540 if (strcmp(data->key, vfskey) == 0) {
1541 talloc_free(vfskey);
1542 return data->value;
1544 data = data->next;
1547 if (service != NULL) {
1548 /* Try to fetch the same option but from globals */
1549 /* but only if we are not already working with globals */
1550 for (data = lp_ctx->globals->param_opt; data;
1551 data = data->next) {
1552 if (strcmp(data->key, vfskey) == 0) {
1553 talloc_free(vfskey);
1554 return data->value;
1559 talloc_free(vfskey);
1561 return NULL;
1566 * convenience routine to return int parameters.
1568 static int lp_int(const char *s)
1571 if (!s) {
1572 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1573 return -1;
1576 return strtol(s, NULL, 0);
1580 * convenience routine to return unsigned long parameters.
1582 static int lp_ulong(const char *s)
1585 if (!s) {
1586 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1587 return -1;
1590 return strtoul(s, NULL, 0);
1594 * convenience routine to return unsigned long parameters.
1596 static double lp_double(const char *s)
1599 if (!s) {
1600 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1601 return -1;
1604 return strtod(s, NULL);
1608 * convenience routine to return boolean parameters.
1610 static bool lp_bool(const char *s)
1612 bool ret = false;
1614 if (!s) {
1615 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1616 return false;
1619 if (!set_boolean(s, &ret)) {
1620 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1621 return false;
1624 return ret;
1629 * Return parametric option from a given service. Type is a part of option before ':'
1630 * Parametric option has following syntax: 'Type: option = value'
1631 * Returned value is allocated in 'lp_talloc' context
1634 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1635 struct loadparm_service *service, const char *type,
1636 const char *option)
1638 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1640 if (value)
1641 return lp_string(value);
1643 return NULL;
1647 * Return parametric option from a given service. Type is a part of option before ':'
1648 * Parametric option has following syntax: 'Type: option = value'
1649 * Returned value is allocated in 'lp_talloc' context
1652 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1653 struct loadparm_context *lp_ctx,
1654 struct loadparm_service *service,
1655 const char *type,
1656 const char *option, const char *separator)
1658 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1660 if (value != NULL)
1661 return (const char **)str_list_make(mem_ctx, value, separator);
1663 return NULL;
1667 * Return parametric option from a given service. Type is a part of option before ':'
1668 * Parametric option has following syntax: 'Type: option = value'
1671 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1672 struct loadparm_service *service, const char *type,
1673 const char *option, int default_v)
1675 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1677 if (value)
1678 return lp_int(value);
1680 return default_v;
1684 * Return parametric option from a given service. Type is a part of
1685 * option before ':'.
1686 * Parametric option has following syntax: 'Type: option = value'.
1689 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1690 struct loadparm_service *service, const char *type,
1691 const char *option, int default_v)
1693 uint64_t bval;
1695 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1697 if (value && conv_str_size_error(value, &bval)) {
1698 if (bval <= INT_MAX) {
1699 return (int)bval;
1703 return default_v;
1707 * Return parametric option from a given service.
1708 * Type is a part of option before ':'
1709 * Parametric option has following syntax: 'Type: option = value'
1711 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1712 struct loadparm_service *service, const char *type,
1713 const char *option, unsigned long default_v)
1715 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1717 if (value)
1718 return lp_ulong(value);
1720 return default_v;
1724 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1725 struct loadparm_service *service, const char *type,
1726 const char *option, double default_v)
1728 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1730 if (value != NULL)
1731 return lp_double(value);
1733 return default_v;
1737 * Return parametric option from a given service. Type is a part of option before ':'
1738 * Parametric option has following syntax: 'Type: option = value'
1741 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1742 struct loadparm_service *service, const char *type,
1743 const char *option, bool default_v)
1745 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1747 if (value != NULL)
1748 return lp_bool(value);
1750 return default_v;
1755 * Initialise a service to the defaults.
1758 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1760 struct loadparm_service *pservice =
1761 talloc_zero(mem_ctx, struct loadparm_service);
1762 copy_service(pservice, sDefault, NULL);
1763 return pservice;
1767 * Set a string value, deallocating any existing space, and allocing the space
1768 * for the string
1770 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1772 talloc_free(*dest);
1774 if (src == NULL)
1775 src = "";
1777 *dest = talloc_strdup(mem_ctx, src);
1778 if ((*dest) == NULL) {
1779 DEBUG(0,("Out of memory in string_set\n"));
1780 return false;
1783 return true;
1787 * Set a string value, deallocating any existing space, and allocing the space
1788 * for the string
1790 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1792 talloc_free(*dest);
1794 if (src == NULL)
1795 src = "";
1797 *dest = strupper_talloc(mem_ctx, src);
1798 if ((*dest) == NULL) {
1799 DEBUG(0,("Out of memory in string_set_upper\n"));
1800 return false;
1803 return true;
1809 * Add a new service to the services array initialising it with the given
1810 * service.
1813 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1814 const struct loadparm_service *pservice,
1815 const char *name)
1817 int i;
1818 struct loadparm_service tservice;
1819 int num_to_alloc = lp_ctx->iNumServices + 1;
1820 struct parmlist_entry *data, *pdata;
1822 if (pservice == NULL) {
1823 pservice = lp_ctx->sDefault;
1826 tservice = *pservice;
1828 /* it might already exist */
1829 if (name) {
1830 struct loadparm_service *service = getservicebyname(lp_ctx,
1831 name);
1832 if (service != NULL) {
1833 /* Clean all parametric options for service */
1834 /* They will be added during parsing again */
1835 data = service->param_opt;
1836 while (data) {
1837 pdata = data->next;
1838 talloc_free(data);
1839 data = pdata;
1841 service->param_opt = NULL;
1842 return service;
1846 /* find an invalid one */
1847 for (i = 0; i < lp_ctx->iNumServices; i++)
1848 if (lp_ctx->services[i] == NULL)
1849 break;
1851 /* if not, then create one */
1852 if (i == lp_ctx->iNumServices) {
1853 struct loadparm_service **tsp;
1855 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1857 if (!tsp) {
1858 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1859 return NULL;
1860 } else {
1861 lp_ctx->services = tsp;
1862 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1865 lp_ctx->iNumServices++;
1868 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1869 if (lp_ctx->services[i] == NULL) {
1870 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1871 return NULL;
1873 copy_service(lp_ctx->services[i], &tservice, NULL);
1874 if (name != NULL)
1875 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1876 return lp_ctx->services[i];
1880 * Add a new home service, with the specified home directory, defaults coming
1881 * from service ifrom.
1884 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1885 const char *pszHomename,
1886 struct loadparm_service *default_service,
1887 const char *user, const char *pszHomedir)
1889 struct loadparm_service *service;
1891 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1893 if (service == NULL)
1894 return false;
1896 if (!(*(default_service->szPath))
1897 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1898 service->szPath = talloc_strdup(service, pszHomedir);
1899 } else {
1900 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1903 if (!(*(service->comment))) {
1904 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1906 service->bAvailable = default_service->bAvailable;
1907 service->bBrowseable = default_service->bBrowseable;
1909 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1910 pszHomename, user, service->szPath));
1912 return true;
1916 * Add a new printer service, with defaults coming from service iFrom.
1919 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1920 const char *pszPrintername,
1921 struct loadparm_service *default_service)
1923 const char *comment = "From Printcap";
1924 struct loadparm_service *service;
1925 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1927 if (service == NULL)
1928 return false;
1930 /* note that we do NOT default the availability flag to True - */
1931 /* we take it from the default service passed. This allows all */
1932 /* dynamic printers to be disabled by disabling the [printers] */
1933 /* entry (if/when the 'available' keyword is implemented!). */
1935 /* the printer name is set to the service name. */
1936 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1937 lpcfg_string_set(service, &service->comment, comment);
1938 service->bBrowseable = default_service->bBrowseable;
1939 /* Printers cannot be read_only. */
1940 service->bRead_only = false;
1941 /* Printer services must be printable. */
1942 service->bPrint_ok = true;
1944 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1946 return true;
1950 * Map a parameter's string representation to something we can use.
1951 * Returns False if the parameter string is not recognised, else TRUE.
1954 static int map_parameter(const char *pszParmName)
1956 int iIndex;
1958 if (*pszParmName == '-')
1959 return -1;
1961 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1962 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1963 return iIndex;
1965 /* Warn only if it isn't parametric option */
1966 if (strchr(pszParmName, ':') == NULL)
1967 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1968 /* We do return 'fail' for parametric options as well because they are
1969 stored in different storage
1971 return -1;
1976 return the parameter structure for a parameter
1978 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
1980 int parmnum;
1982 if (lp_ctx->s3_fns) {
1983 return lp_ctx->s3_fns->get_parm_struct(name);
1986 parmnum = map_parameter(name);
1987 if (parmnum == -1) return NULL;
1988 return &parm_table[parmnum];
1992 return the parameter pointer for a parameter
1994 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
1995 struct loadparm_service *service, struct parm_struct *parm)
1997 if (lp_ctx->s3_fns) {
1998 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2001 if (service == NULL) {
2002 if (parm->p_class == P_LOCAL)
2003 return ((char *)lp_ctx->sDefault)+parm->offset;
2004 else if (parm->p_class == P_GLOBAL)
2005 return ((char *)lp_ctx->globals)+parm->offset;
2006 else return NULL;
2007 } else {
2008 return ((char *)service) + parm->offset;
2013 return the parameter pointer for a parameter
2015 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2017 int parmnum;
2019 if (lp_ctx->s3_fns) {
2020 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2021 if (parm) {
2022 return parm->flags & FLAG_CMDLINE;
2024 return false;
2027 parmnum = map_parameter(name);
2028 if (parmnum == -1) return false;
2030 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2034 * Find a service by name. Otherwise works like get_service.
2037 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2038 const char *pszServiceName)
2040 int iService;
2042 if (lp_ctx->s3_fns) {
2043 return lp_ctx->s3_fns->get_service(pszServiceName);
2046 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2047 if (lp_ctx->services[iService] != NULL &&
2048 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2049 return lp_ctx->services[iService];
2052 return NULL;
2056 * Copy a service structure to another.
2057 * If pcopymapDest is NULL then copy all fields
2060 static void copy_service(struct loadparm_service *pserviceDest,
2061 struct loadparm_service *pserviceSource,
2062 struct bitmap *pcopymapDest)
2064 int i;
2065 bool bcopyall = (pcopymapDest == NULL);
2066 struct parmlist_entry *data, *pdata, *paramo;
2067 bool not_added;
2069 for (i = 0; parm_table[i].label; i++)
2070 if (parm_table[i].p_class == P_LOCAL &&
2071 (bcopyall || bitmap_query(pcopymapDest, i))) {
2072 void *src_ptr =
2073 ((char *)pserviceSource) + parm_table[i].offset;
2074 void *dest_ptr =
2075 ((char *)pserviceDest) + parm_table[i].offset;
2077 switch (parm_table[i].type) {
2078 case P_BOOL:
2079 *(bool *)dest_ptr = *(bool *)src_ptr;
2080 break;
2082 case P_INTEGER:
2083 case P_OCTAL:
2084 case P_ENUM:
2085 *(int *)dest_ptr = *(int *)src_ptr;
2086 break;
2088 case P_STRING:
2089 lpcfg_string_set(pserviceDest,
2090 (char **)dest_ptr,
2091 *(char **)src_ptr);
2092 break;
2094 case P_USTRING:
2095 lpcfg_string_set_upper(pserviceDest,
2096 (char **)dest_ptr,
2097 *(char **)src_ptr);
2098 break;
2099 case P_LIST:
2100 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2101 *(const char ***)src_ptr);
2102 break;
2103 default:
2104 break;
2108 if (bcopyall) {
2109 init_copymap(pserviceDest);
2110 if (pserviceSource->copymap)
2111 bitmap_copy(pserviceDest->copymap,
2112 pserviceSource->copymap);
2115 data = pserviceSource->param_opt;
2116 while (data) {
2117 not_added = true;
2118 pdata = pserviceDest->param_opt;
2119 /* Traverse destination */
2120 while (pdata) {
2121 /* If we already have same option, override it */
2122 if (strcmp(pdata->key, data->key) == 0) {
2123 talloc_free(pdata->value);
2124 pdata->value = talloc_reference(pdata,
2125 data->value);
2126 not_added = false;
2127 break;
2129 pdata = pdata->next;
2131 if (not_added) {
2132 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2133 if (paramo == NULL)
2134 smb_panic("OOM");
2135 paramo->key = talloc_reference(paramo, data->key);
2136 paramo->value = talloc_reference(paramo, data->value);
2137 DLIST_ADD(pserviceDest->param_opt, paramo);
2139 data = data->next;
2144 * Check a service for consistency. Return False if the service is in any way
2145 * incomplete or faulty, else True.
2147 static bool lpcfg_service_ok(struct loadparm_service *service)
2149 bool bRetval;
2151 bRetval = true;
2152 if (service->szService[0] == '\0') {
2153 DEBUG(0, ("The following message indicates an internal error:\n"));
2154 DEBUG(0, ("No service name in service entry.\n"));
2155 bRetval = false;
2158 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2159 /* I can't see why you'd want a non-printable printer service... */
2160 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2161 if (!service->bPrint_ok) {
2162 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2163 service->szService));
2164 service->bPrint_ok = true;
2166 /* [printers] service must also be non-browsable. */
2167 if (service->bBrowseable)
2168 service->bBrowseable = false;
2171 /* If a service is flagged unavailable, log the fact at level 0. */
2172 if (!service->bAvailable)
2173 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2174 service->szService));
2176 return bRetval;
2180 /*******************************************************************
2181 Keep a linked list of all config files so we know when one has changed
2182 it's date and needs to be reloaded.
2183 ********************************************************************/
2185 static void add_to_file_list(struct loadparm_context *lp_ctx,
2186 const char *fname, const char *subfname)
2188 struct file_lists *f = lp_ctx->file_lists;
2190 while (f) {
2191 if (f->name && !strcmp(f->name, fname))
2192 break;
2193 f = f->next;
2196 if (!f) {
2197 f = talloc(lp_ctx, struct file_lists);
2198 if (!f)
2199 return;
2200 f->next = lp_ctx->file_lists;
2201 f->name = talloc_strdup(f, fname);
2202 if (!f->name) {
2203 talloc_free(f);
2204 return;
2206 f->subfname = talloc_strdup(f, subfname);
2207 if (!f->subfname) {
2208 talloc_free(f);
2209 return;
2211 lp_ctx->file_lists = f;
2212 f->modtime = file_modtime(subfname);
2213 } else {
2214 time_t t = file_modtime(subfname);
2215 if (t)
2216 f->modtime = t;
2220 /*******************************************************************
2221 Check if a config file has changed date.
2222 ********************************************************************/
2223 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2225 struct file_lists *f;
2226 DEBUG(6, ("lp_file_list_changed()\n"));
2228 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2229 char *n2;
2230 time_t mod_time;
2232 n2 = standard_sub_basic(lp_ctx, f->name);
2234 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2235 f->name, n2, ctime(&f->modtime)));
2237 mod_time = file_modtime(n2);
2239 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2240 DEBUGADD(6, ("file %s modified: %s\n", n2,
2241 ctime(&mod_time)));
2242 f->modtime = mod_time;
2243 talloc_free(f->subfname);
2244 f->subfname = talloc_strdup(f, n2);
2245 return true;
2248 return false;
2251 /***************************************************************************
2252 Handle the "realm" parameter
2253 ***************************************************************************/
2255 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2256 const char *pszParmValue, char **ptr)
2258 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2260 talloc_free(lp_ctx->globals->szRealm_upper);
2261 talloc_free(lp_ctx->globals->szRealm_lower);
2263 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2264 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2266 return true;
2269 /***************************************************************************
2270 Handle the include operation.
2271 ***************************************************************************/
2273 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2274 const char *pszParmValue, char **ptr)
2276 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2278 add_to_file_list(lp_ctx, pszParmValue, fname);
2280 lpcfg_string_set(lp_ctx, ptr, fname);
2282 if (file_exist(fname))
2283 return pm_process(fname, do_section, do_parameter, lp_ctx);
2285 DEBUG(2, ("Can't find include file %s\n", fname));
2287 return false;
2290 /***************************************************************************
2291 Handle the interpretation of the copy parameter.
2292 ***************************************************************************/
2294 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2295 const char *pszParmValue, char **ptr)
2297 bool bRetval;
2298 struct loadparm_service *serviceTemp;
2300 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2302 bRetval = false;
2304 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2306 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2307 if (serviceTemp == lp_ctx->currentService) {
2308 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2309 } else {
2310 copy_service(lp_ctx->currentService,
2311 serviceTemp,
2312 lp_ctx->currentService->copymap);
2313 bRetval = true;
2315 } else {
2316 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2317 pszParmValue));
2318 bRetval = false;
2321 return bRetval;
2324 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2325 const char *pszParmValue, char **ptr)
2328 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2329 if (lp_ctx->global) {
2330 return debug_parse_levels(pszParmValue);
2332 return true;
2335 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2336 const char *pszParmValue, char **ptr)
2338 debug_set_logfile(pszParmValue);
2339 if (lp_ctx->global) {
2340 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2342 return true;
2345 /***************************************************************************
2346 Initialise a copymap.
2347 ***************************************************************************/
2349 static void init_copymap(struct loadparm_service *pservice)
2351 int i;
2353 TALLOC_FREE(pservice->copymap);
2355 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2356 if (!pservice->copymap)
2357 DEBUG(0,
2358 ("Couldn't allocate copymap!! (size %d)\n",
2359 (int)NUMPARAMETERS));
2360 else
2361 for (i = 0; i < NUMPARAMETERS; i++)
2362 bitmap_set(pservice->copymap, i);
2366 * Process a parametric option
2368 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2369 struct loadparm_service *service,
2370 const char *pszParmName,
2371 const char *pszParmValue, int flags)
2373 struct parmlist_entry *paramo, *data;
2374 char *name;
2375 TALLOC_CTX *mem_ctx;
2377 while (isspace((unsigned char)*pszParmName)) {
2378 pszParmName++;
2381 name = strlower_talloc(lp_ctx, pszParmName);
2382 if (!name) return false;
2384 if (service == NULL) {
2385 data = lp_ctx->globals->param_opt;
2386 mem_ctx = lp_ctx->globals;
2387 } else {
2388 data = service->param_opt;
2389 mem_ctx = service;
2392 /* Traverse destination */
2393 for (paramo=data; paramo; paramo=paramo->next) {
2394 /* If we already have the option set, override it unless
2395 it was a command line option and the new one isn't */
2396 if (strcmp(paramo->key, name) == 0) {
2397 if ((paramo->priority & FLAG_CMDLINE) &&
2398 !(flags & FLAG_CMDLINE)) {
2399 talloc_free(name);
2400 return true;
2403 talloc_free(paramo->value);
2404 paramo->value = talloc_strdup(paramo, pszParmValue);
2405 paramo->priority = flags;
2406 talloc_free(name);
2407 return true;
2411 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2412 if (!paramo)
2413 smb_panic("OOM");
2414 paramo->key = talloc_strdup(paramo, name);
2415 paramo->value = talloc_strdup(paramo, pszParmValue);
2416 paramo->priority = flags;
2417 if (service == NULL) {
2418 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2419 } else {
2420 DLIST_ADD(service->param_opt, paramo);
2423 talloc_free(name);
2425 return true;
2428 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2429 const char *pszParmName, const char *pszParmValue,
2430 struct loadparm_context *lp_ctx, bool on_globals)
2432 int i;
2433 /* if it is a special case then go ahead */
2434 if (parm_table[parmnum].special) {
2435 bool ret;
2436 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2437 (char **)parm_ptr);
2438 if (!ret) {
2439 return false;
2441 goto mark_non_default;
2444 /* now switch on the type of variable it is */
2445 switch (parm_table[parmnum].type)
2447 case P_BOOL: {
2448 bool b;
2449 if (!set_boolean(pszParmValue, &b)) {
2450 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2451 return false;
2453 *(bool *)parm_ptr = b;
2455 break;
2457 case P_BOOLREV: {
2458 bool b;
2459 if (!set_boolean(pszParmValue, &b)) {
2460 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2461 return false;
2463 *(bool *)parm_ptr = !b;
2465 break;
2467 case P_INTEGER:
2468 *(int *)parm_ptr = atoi(pszParmValue);
2469 break;
2471 case P_CHAR:
2472 *(char *)parm_ptr = *pszParmValue;
2473 break;
2475 case P_OCTAL:
2476 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2477 break;
2479 case P_BYTES:
2481 uint64_t val;
2482 if (conv_str_size_error(pszParmValue, &val)) {
2483 if (val <= INT_MAX) {
2484 *(int *)parm_ptr = (int)val;
2485 break;
2489 DEBUG(0,("lp_do_parameter(%s): value is not "
2490 "a valid size specifier!\n", pszParmValue));
2491 return false;
2494 case P_CMDLIST:
2495 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2496 pszParmValue, NULL);
2497 break;
2498 case P_LIST:
2500 char **new_list = str_list_make(mem_ctx,
2501 pszParmValue, NULL);
2502 for (i=0; new_list[i]; i++) {
2503 if (new_list[i][0] == '+' && new_list[i][1] &&
2504 (!str_list_check(*(const char ***)parm_ptr,
2505 &new_list[i][1]))) {
2506 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2507 &new_list[i][1]);
2508 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2509 #if 0 /* This is commented out because we sometimes parse the list
2510 * twice, and so we can't assert on this */
2511 if (!str_list_check(*(const char ***)parm_ptr,
2512 &new_list[i][1])) {
2513 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2514 pszParmName, pszParmValue, new_list[i],
2515 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2516 return false;
2519 #endif
2520 str_list_remove(*(const char ***)parm_ptr,
2521 &new_list[i][1]);
2522 } else {
2523 if (i != 0) {
2524 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2525 pszParmName, pszParmValue));
2526 return false;
2528 *(const char ***)parm_ptr = (const char **) new_list;
2529 break;
2532 break;
2534 case P_STRING:
2535 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2536 break;
2538 case P_USTRING:
2539 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2540 break;
2542 case P_ENUM:
2543 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2544 if (strequal
2545 (pszParmValue,
2546 parm_table[parmnum].enum_list[i].name)) {
2547 *(int *)parm_ptr =
2548 parm_table[parmnum].
2549 enum_list[i].value;
2550 break;
2553 if (!parm_table[parmnum].enum_list[i].name) {
2554 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2555 pszParmValue, pszParmName));
2556 return false;
2558 break;
2561 mark_non_default:
2562 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2563 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2564 /* we have to also unset FLAG_DEFAULT on aliases */
2565 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2566 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2568 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2569 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2572 return true;
2576 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2577 const char *pszParmName, const char *pszParmValue)
2579 int parmnum = map_parameter(pszParmName);
2580 void *parm_ptr;
2582 if (parmnum < 0) {
2583 if (strchr(pszParmName, ':')) {
2584 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2586 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2587 return true;
2590 /* if the flag has been set on the command line, then don't allow override,
2591 but don't report an error */
2592 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2593 return true;
2596 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2598 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2599 pszParmName, pszParmValue, lp_ctx, true);
2602 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2603 struct loadparm_service *service,
2604 const char *pszParmName, const char *pszParmValue)
2606 void *parm_ptr;
2607 int i;
2608 int parmnum = map_parameter(pszParmName);
2610 if (parmnum < 0) {
2611 if (strchr(pszParmName, ':')) {
2612 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2614 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2615 return true;
2618 /* if the flag has been set on the command line, then don't allow override,
2619 but don't report an error */
2620 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2621 return true;
2624 if (parm_table[parmnum].p_class == P_GLOBAL) {
2625 DEBUG(0,
2626 ("Global parameter %s found in service section!\n",
2627 pszParmName));
2628 return true;
2630 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2632 if (!service->copymap)
2633 init_copymap(service);
2635 /* this handles the aliases - set the copymap for other
2636 * entries with the same data pointer */
2637 for (i = 0; parm_table[i].label; i++)
2638 if (parm_table[i].offset == parm_table[parmnum].offset &&
2639 parm_table[i].p_class == parm_table[parmnum].p_class)
2640 bitmap_clear(service->copymap, i);
2642 return set_variable(service, parmnum, parm_ptr, pszParmName,
2643 pszParmValue, lp_ctx, false);
2647 * Process a parameter.
2650 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2651 void *userdata)
2653 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2655 if (lp_ctx->bInGlobalSection)
2656 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2657 pszParmValue);
2658 else
2659 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2660 pszParmName, pszParmValue);
2664 variable argument do parameter
2666 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2667 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2668 const char *pszParmName, const char *fmt, ...)
2670 char *s;
2671 bool ret;
2672 va_list ap;
2674 va_start(ap, fmt);
2675 s = talloc_vasprintf(NULL, fmt, ap);
2676 va_end(ap);
2677 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2678 talloc_free(s);
2679 return ret;
2684 set a parameter from the commandline - this is called from command line parameter
2685 parsing code. It sets the parameter then marks the parameter as unable to be modified
2686 by smb.conf processing
2688 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2689 const char *pszParmValue)
2691 int parmnum;
2692 int i;
2694 if (lp_ctx->s3_fns) {
2695 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2698 parmnum = map_parameter(pszParmName);
2700 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2703 if (parmnum < 0 && strchr(pszParmName, ':')) {
2704 /* set a parametric option */
2705 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2706 pszParmValue, FLAG_CMDLINE);
2709 if (parmnum < 0) {
2710 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2711 return false;
2714 /* reset the CMDLINE flag in case this has been called before */
2715 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2717 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2718 return false;
2721 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2723 /* we have to also set FLAG_CMDLINE on aliases */
2724 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2725 lp_ctx->flags[i] |= FLAG_CMDLINE;
2727 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2728 lp_ctx->flags[i] |= FLAG_CMDLINE;
2731 return true;
2735 set a option from the commandline in 'a=b' format. Use to support --option
2737 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2739 char *p, *s;
2740 bool ret;
2742 s = talloc_strdup(NULL, option);
2743 if (!s) {
2744 return false;
2747 p = strchr(s, '=');
2748 if (!p) {
2749 talloc_free(s);
2750 return false;
2753 *p = 0;
2755 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2756 talloc_free(s);
2757 return ret;
2761 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2764 * Print a parameter of the specified type.
2767 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2769 /* For the seperation of lists values that we print below */
2770 const char *list_sep = ", ";
2771 int i;
2772 switch (p->type)
2774 case P_ENUM:
2775 for (i = 0; p->enum_list[i].name; i++) {
2776 if (*(int *)ptr == p->enum_list[i].value) {
2777 fprintf(f, "%s",
2778 p->enum_list[i].name);
2779 break;
2782 break;
2784 case P_BOOL:
2785 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2786 break;
2788 case P_BOOLREV:
2789 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2790 break;
2792 case P_INTEGER:
2793 case P_BYTES:
2794 fprintf(f, "%d", *(int *)ptr);
2795 break;
2797 case P_CHAR:
2798 fprintf(f, "%c", *(char *)ptr);
2799 break;
2801 case P_OCTAL: {
2802 int val = *(int *)ptr;
2803 if (val == -1) {
2804 fprintf(f, "-1");
2805 } else {
2806 fprintf(f, "0%o", val);
2808 break;
2811 case P_CMDLIST:
2812 list_sep = " ";
2813 /* fall through */
2814 case P_LIST:
2815 if ((char ***)ptr && *(char ***)ptr) {
2816 char **list = *(char ***)ptr;
2817 for (; *list; list++) {
2818 /* surround strings with whitespace in double quotes */
2819 if (*(list+1) == NULL) {
2820 /* last item, no extra separator */
2821 list_sep = "";
2823 if ( strchr_m( *list, ' ' ) ) {
2824 fprintf(f, "\"%s\"%s", *list, list_sep);
2825 } else {
2826 fprintf(f, "%s%s", *list, list_sep);
2830 break;
2832 case P_STRING:
2833 case P_USTRING:
2834 if (*(char **)ptr) {
2835 fprintf(f, "%s", *(char **)ptr);
2837 break;
2838 case P_SEP:
2839 break;
2844 * Check if two parameters are equal.
2847 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2849 switch (type) {
2850 case P_BOOL:
2851 case P_BOOLREV:
2852 return (*((bool *)ptr1) == *((bool *)ptr2));
2854 case P_INTEGER:
2855 case P_ENUM:
2856 case P_OCTAL:
2857 case P_BYTES:
2858 return (*((int *)ptr1) == *((int *)ptr2));
2860 case P_CHAR:
2861 return (*((char *)ptr1) == *((char *)ptr2));
2863 case P_LIST:
2864 case P_CMDLIST:
2865 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2867 case P_STRING:
2868 case P_USTRING:
2870 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2871 if (p1 && !*p1)
2872 p1 = NULL;
2873 if (p2 && !*p2)
2874 p2 = NULL;
2875 return (p1 == p2 || strequal(p1, p2));
2877 case P_SEP:
2878 break;
2880 return false;
2884 * Process a new section (service).
2886 * At this stage all sections are services.
2887 * Later we'll have special sections that permit server parameters to be set.
2888 * Returns True on success, False on failure.
2891 static bool do_section(const char *pszSectionName, void *userdata)
2893 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2894 bool bRetval;
2895 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2896 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2897 bRetval = false;
2899 /* if we've just struck a global section, note the fact. */
2900 lp_ctx->bInGlobalSection = isglobal;
2902 /* check for multiple global sections */
2903 if (lp_ctx->bInGlobalSection) {
2904 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2905 return true;
2908 /* if we have a current service, tidy it up before moving on */
2909 bRetval = true;
2911 if (lp_ctx->currentService != NULL)
2912 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2914 /* if all is still well, move to the next record in the services array */
2915 if (bRetval) {
2916 /* We put this here to avoid an odd message order if messages are */
2917 /* issued by the post-processing of a previous section. */
2918 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2920 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2921 pszSectionName))
2922 == NULL) {
2923 DEBUG(0, ("Failed to add a new service\n"));
2924 return false;
2928 return bRetval;
2933 * Determine if a particular base parameter is currently set to the default value.
2936 static bool is_default(struct loadparm_service *sDefault, int i)
2938 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2939 if (!defaults_saved)
2940 return false;
2941 switch (parm_table[i].type) {
2942 case P_CMDLIST:
2943 case P_LIST:
2944 return str_list_equal((const char **)parm_table[i].def.lvalue,
2945 (const char **)def_ptr);
2946 case P_STRING:
2947 case P_USTRING:
2948 return strequal(parm_table[i].def.svalue,
2949 *(char **)def_ptr);
2950 case P_BOOL:
2951 case P_BOOLREV:
2952 return parm_table[i].def.bvalue ==
2953 *(bool *)def_ptr;
2954 case P_INTEGER:
2955 case P_CHAR:
2956 case P_OCTAL:
2957 case P_BYTES:
2958 case P_ENUM:
2959 return parm_table[i].def.ivalue ==
2960 *(int *)def_ptr;
2962 return false;
2966 *Display the contents of the global structure.
2969 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2970 bool show_defaults)
2972 int i;
2973 struct parmlist_entry *data;
2975 fprintf(f, "# Global parameters\n[global]\n");
2977 for (i = 0; parm_table[i].label; i++)
2978 if (parm_table[i].p_class == P_GLOBAL &&
2979 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2980 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2981 continue;
2982 fprintf(f, "\t%s = ", parm_table[i].label);
2983 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2984 fprintf(f, "\n");
2986 if (lp_ctx->globals->param_opt != NULL) {
2987 for (data = lp_ctx->globals->param_opt; data;
2988 data = data->next) {
2989 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2990 continue;
2992 fprintf(f, "\t%s = %s\n", data->key, data->value);
2999 * Display the contents of a single services record.
3002 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3003 unsigned int *flags)
3005 int i;
3006 struct parmlist_entry *data;
3008 if (pService != sDefault)
3009 fprintf(f, "\n[%s]\n", pService->szService);
3011 for (i = 0; parm_table[i].label; i++) {
3012 if (parm_table[i].p_class == P_LOCAL &&
3013 (*parm_table[i].label != '-') &&
3014 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3016 if (pService == sDefault) {
3017 if (flags && (flags[i] & FLAG_DEFAULT)) {
3018 continue;
3020 if (defaults_saved) {
3021 if (is_default(sDefault, i)) {
3022 continue;
3025 } else {
3026 if (equal_parameter(parm_table[i].type,
3027 ((char *)pService) +
3028 parm_table[i].offset,
3029 ((char *)sDefault) +
3030 parm_table[i].offset))
3031 continue;
3034 fprintf(f, "\t%s = ", parm_table[i].label);
3035 print_parameter(&parm_table[i],
3036 ((char *)pService) + parm_table[i].offset, f);
3037 fprintf(f, "\n");
3040 if (pService->param_opt != NULL) {
3041 for (data = pService->param_opt; data; data = data->next) {
3042 fprintf(f, "\t%s = %s\n", data->key, data->value);
3047 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3048 struct loadparm_service *service,
3049 const char *parm_name, FILE * f)
3051 struct parm_struct *parm;
3052 void *ptr;
3054 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3055 if (!parm) {
3056 return false;
3059 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3061 print_parameter(parm, ptr, f);
3062 fprintf(f, "\n");
3063 return true;
3067 * Return info about the next parameter in a service.
3068 * snum==-1 gives the globals.
3069 * Return NULL when out of parameters.
3073 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3074 int allparameters)
3076 if (snum == -1) {
3077 /* do the globals */
3078 for (; parm_table[*i].label; (*i)++) {
3079 if ((*parm_table[*i].label == '-'))
3080 continue;
3082 if ((*i) > 0
3083 && (parm_table[*i].offset ==
3084 parm_table[(*i) - 1].offset)
3085 && (parm_table[*i].p_class ==
3086 parm_table[(*i) - 1].p_class))
3087 continue;
3089 return &parm_table[(*i)++];
3091 } else {
3092 struct loadparm_service *pService = lp_ctx->services[snum];
3094 for (; parm_table[*i].label; (*i)++) {
3095 if (parm_table[*i].p_class == P_LOCAL &&
3096 (*parm_table[*i].label != '-') &&
3097 ((*i) == 0 ||
3098 (parm_table[*i].offset !=
3099 parm_table[(*i) - 1].offset)))
3101 if (allparameters ||
3102 !equal_parameter(parm_table[*i].type,
3103 ((char *)pService) +
3104 parm_table[*i].offset,
3105 ((char *)lp_ctx->sDefault) +
3106 parm_table[*i].offset))
3108 return &parm_table[(*i)++];
3114 return NULL;
3119 * Auto-load some home services.
3121 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3122 const char *str)
3124 return;
3129 * Unload unused services.
3132 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3133 struct smbsrv_connection *smb,
3134 bool (*snumused) (struct smbsrv_connection *, int))
3136 int i;
3137 for (i = 0; i < lp_ctx->iNumServices; i++) {
3138 if (lp_ctx->services[i] == NULL)
3139 continue;
3141 if (!snumused || !snumused(smb, i)) {
3142 talloc_free(lp_ctx->services[i]);
3143 lp_ctx->services[i] = NULL;
3149 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3151 struct parmlist_entry *data;
3153 if (lp_ctx->refuse_free) {
3154 /* someone is trying to free the
3155 global_loadparm_context.
3156 We can't allow that. */
3157 return -1;
3160 if (lp_ctx->globals->param_opt != NULL) {
3161 struct parmlist_entry *next;
3162 for (data = lp_ctx->globals->param_opt; data; data=next) {
3163 next = data->next;
3164 if (data->priority & FLAG_CMDLINE) continue;
3165 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3166 talloc_free(data);
3170 return 0;
3174 * Initialise the global parameter structure.
3176 * Note that most callers should use loadparm_init_global() instead
3178 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3180 int i;
3181 char *myname;
3182 struct loadparm_context *lp_ctx;
3183 struct parmlist_entry *parm;
3184 char *logfile;
3186 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3187 if (lp_ctx == NULL)
3188 return NULL;
3190 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3191 lp_ctx->bInGlobalSection = true;
3192 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3193 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3195 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3196 lp_ctx->sDefault->bAvailable = true;
3197 lp_ctx->sDefault->bBrowseable = true;
3198 lp_ctx->sDefault->bRead_only = true;
3199 lp_ctx->sDefault->bMap_archive = true;
3200 lp_ctx->sDefault->iStrictLocking = true;
3201 lp_ctx->sDefault->bOpLocks = true;
3202 lp_ctx->sDefault->iCreate_mask = 0744;
3203 lp_ctx->sDefault->iCreate_force_mode = 0000;
3204 lp_ctx->sDefault->iDir_mask = 0755;
3205 lp_ctx->sDefault->iDir_force_mode = 0000;
3207 DEBUG(3, ("Initialising global parameters\n"));
3209 for (i = 0; parm_table[i].label; i++) {
3210 if ((parm_table[i].type == P_STRING ||
3211 parm_table[i].type == P_USTRING) &&
3212 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3213 char **r;
3214 if (parm_table[i].p_class == P_LOCAL) {
3215 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3216 } else {
3217 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3219 *r = talloc_strdup(lp_ctx, "");
3223 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3224 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3225 talloc_free(logfile);
3227 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3229 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3231 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3232 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3233 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3235 /* options that can be set on the command line must be initialised via
3236 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3237 #ifdef TCP_NODELAY
3238 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3239 #endif
3240 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3241 myname = get_myname(lp_ctx);
3242 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3243 talloc_free(myname);
3244 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3246 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3248 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3249 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3251 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3252 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3253 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3254 /* the winbind method for domain controllers is for both RODC
3255 auth forwarding and for trusted domains */
3256 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3257 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3259 /* This hive should be dynamically generated by Samba using
3260 data from the sam, but for the moment leave it in a tdb to
3261 keep regedt32 from popping up an annoying dialog. */
3262 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3264 /* using UTF8 by default allows us to support all chars */
3265 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3267 /* Use codepage 850 as a default for the dos character set */
3268 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3271 * Allow the default PASSWD_CHAT to be overridden in local.h.
3273 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3275 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3276 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3277 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3278 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3279 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3281 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3282 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3283 "Samba %s", SAMBA_VERSION_STRING);
3285 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3287 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3288 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3289 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3290 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3291 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3292 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3293 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3294 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3295 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3296 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3297 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3298 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3299 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3300 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3301 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3303 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3304 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3305 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3306 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3307 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3308 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3309 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3310 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3312 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3314 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3315 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3317 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3318 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3320 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3321 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3322 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3323 #if _SAMBA_BUILD_ >= 4
3324 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3325 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3326 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3327 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3328 #endif
3329 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3330 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3331 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3333 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3334 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3336 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3338 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3340 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3341 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3342 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3343 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3344 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3345 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3346 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3348 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3350 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3351 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3353 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3354 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3355 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3356 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3357 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3359 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3360 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3362 for (i = 0; parm_table[i].label; i++) {
3363 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3364 lp_ctx->flags[i] |= FLAG_DEFAULT;
3368 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3369 if (!(parm->priority & FLAG_CMDLINE)) {
3370 parm->priority |= FLAG_DEFAULT;
3374 return lp_ctx;
3378 * Initialise the global parameter structure.
3380 struct loadparm_context *loadparm_init_global(bool load_default)
3382 if (global_loadparm_context == NULL) {
3383 global_loadparm_context = loadparm_init(NULL);
3385 if (global_loadparm_context == NULL) {
3386 return NULL;
3388 global_loadparm_context->global = true;
3389 if (load_default && !global_loadparm_context->loaded) {
3390 lpcfg_load_default(global_loadparm_context);
3392 global_loadparm_context->refuse_free = true;
3393 return global_loadparm_context;
3397 * Initialise the global parameter structure.
3399 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3400 const struct loadparm_s3_context *s3_fns)
3402 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3403 if (!loadparm_context) {
3404 return NULL;
3406 loadparm_context->s3_fns = s3_fns;
3407 return loadparm_context;
3410 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3412 return lp_ctx->szConfigFile;
3415 const char *lp_default_path(void)
3417 if (getenv("SMB_CONF_PATH"))
3418 return getenv("SMB_CONF_PATH");
3419 else
3420 return dyn_CONFIGFILE;
3424 * Update the internal state of a loadparm context after settings
3425 * have changed.
3427 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3429 struct debug_settings settings;
3430 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3432 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3433 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3436 if (!lp_ctx->global) {
3437 return true;
3440 panic_action = lp_ctx->globals->panic_action;
3442 reload_charcnv(lp_ctx);
3444 ZERO_STRUCT(settings);
3445 /* Add any more debug-related smb.conf parameters created in
3446 * future here */
3447 settings.timestamp_logs = true;
3448 debug_set_settings(&settings);
3450 /* FIXME: This is a bit of a hack, but we can't use a global, since
3451 * not everything that uses lp also uses the socket library */
3452 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3453 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3454 } else {
3455 unsetenv("SOCKET_TESTNONBLOCK");
3458 return true;
3461 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3463 const char *path;
3465 path = lp_default_path();
3467 if (!file_exist(path)) {
3468 /* We allow the default smb.conf file to not exist,
3469 * basically the equivalent of an empty file. */
3470 return lpcfg_update(lp_ctx);
3473 return lpcfg_load(lp_ctx, path);
3477 * Load the services array from the services file.
3479 * Return True on success, False on failure.
3481 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3483 char *n2;
3484 bool bRetval;
3486 filename = talloc_strdup(lp_ctx, filename);
3488 lp_ctx->szConfigFile = filename;
3490 if (lp_ctx->s3_fns) {
3491 return lp_ctx->s3_fns->load(filename);
3494 lp_ctx->bInGlobalSection = true;
3495 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3496 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3498 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3500 /* We get sections first, so have to start 'behind' to make up */
3501 lp_ctx->currentService = NULL;
3502 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3504 /* finish up the last section */
3505 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3506 if (bRetval)
3507 if (lp_ctx->currentService != NULL)
3508 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3510 bRetval = bRetval && lpcfg_update(lp_ctx);
3512 /* we do this unconditionally, so that it happens even
3513 for a missing smb.conf */
3514 reload_charcnv(lp_ctx);
3516 if (bRetval == true) {
3517 /* set this up so that any child python tasks will
3518 find the right smb.conf */
3519 setenv("SMB_CONF_PATH", filename, 1);
3521 /* set the context used by the lp_*() function
3522 varients */
3523 global_loadparm_context = lp_ctx;
3524 lp_ctx->loaded = true;
3527 return bRetval;
3531 * Return the max number of services.
3534 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3536 if (lp_ctx->s3_fns) {
3537 return lp_ctx->s3_fns->get_numservices();
3540 return lp_ctx->iNumServices;
3544 * Display the contents of the services array in human-readable form.
3547 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3548 int maxtoprint)
3550 int iService;
3552 if (lp_ctx->s3_fns) {
3553 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3554 return;
3557 defaults_saved = !show_defaults;
3559 dump_globals(lp_ctx, f, show_defaults);
3561 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3563 for (iService = 0; iService < maxtoprint; iService++)
3564 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3568 * Display the contents of one service in human-readable form.
3570 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3572 if (service != NULL) {
3573 if (service->szService[0] == '\0')
3574 return;
3575 dump_a_service(service, sDefault, f, NULL);
3579 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3580 int snum)
3582 if (lp_ctx->s3_fns) {
3583 return lp_ctx->s3_fns->get_servicebynum(snum);
3586 return lp_ctx->services[snum];
3589 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3590 const char *service_name)
3592 int iService;
3593 char *serviceName;
3595 if (lp_ctx->s3_fns) {
3596 return lp_ctx->s3_fns->get_service(service_name);
3599 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3600 if (lp_ctx->services[iService] &&
3601 lp_ctx->services[iService]->szService) {
3603 * The substitution here is used to support %U is
3604 * service names
3606 serviceName = standard_sub_basic(
3607 lp_ctx->services[iService],
3608 lp_ctx->services[iService]->szService);
3609 if (strequal(serviceName, service_name)) {
3610 talloc_free(serviceName);
3611 return lp_ctx->services[iService];
3613 talloc_free(serviceName);
3617 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3618 return NULL;
3621 const char *lpcfg_servicename(const struct loadparm_service *service)
3623 return lp_string((const char *)service->szService);
3627 * A useful volume label function.
3629 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3631 const char *ret;
3632 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3633 service->volume : sDefault->volume));
3634 if (!*ret)
3635 return lpcfg_servicename(service);
3636 return ret;
3640 * If we are PDC then prefer us as DMB
3642 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3644 const char *ret;
3645 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3646 service->szPrintername : sDefault->szPrintername));
3647 if (ret == NULL || (ret != NULL && *ret == '\0'))
3648 ret = lpcfg_servicename(service);
3650 return ret;
3655 * Return the max print jobs per queue.
3657 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3659 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3660 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3661 maxjobs = PRINT_MAX_JOBID - 1;
3663 return maxjobs;
3666 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3668 if (lp_ctx == NULL) {
3669 return get_iconv_handle();
3671 return lp_ctx->iconv_handle;
3674 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3676 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3677 if (!lp_ctx->global) {
3678 return;
3681 if (old_ic == NULL) {
3682 old_ic = global_iconv_handle;
3684 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3685 global_iconv_handle = lp_ctx->iconv_handle;
3688 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3690 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3693 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3695 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3698 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3700 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3703 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3705 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3708 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3710 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3713 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3715 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3716 if (settings == NULL)
3717 return NULL;
3718 SMB_ASSERT(lp_ctx != NULL);
3719 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3720 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3721 return settings;
3724 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3726 if (lp_ctx->s3_fns) {
3727 return lp_ctx->s3_fns->server_role();
3730 return lp_find_server_role(lp_ctx->globals->server_role,
3731 lp_ctx->globals->security,
3732 lp_ctx->globals->domain_logons,
3733 (lp_ctx->globals->domain_master == true) ||
3734 (lp_ctx->globals->domain_master == Auto));
3737 int lpcfg_security(struct loadparm_context *lp_ctx)
3739 if (lp_ctx->s3_fns) {
3740 return lp_ctx->s3_fns->security();
3743 return lp_find_security(lp_ctx->globals->server_role,
3744 lp_ctx->globals->security);