s3:libsmb: make use of cli_state_is_connected()
[Samba/gebeck_regimport.git] / source4 / param / loadparm.c
blobb890ad81a9565a3a999f5af9ccfabc766ef87c3c
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 "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "../lib/util/dlinklist.h"
64 #include "param/param.h"
65 #include "param/loadparm.h"
66 #include "libcli/raw/libcliraw.h"
67 #include "rpc_server/common/common.h"
68 #include "lib/socket/socket.h"
69 #include "auth/gensec/gensec.h"
70 #include "s3_param.h"
71 #include "../lib/util/bitmap.h"
73 #define standard_sub_basic talloc_strdup
75 static bool do_parameter(const char *, const char *, void *);
76 static bool defaults_saved = false;
78 #define LOADPARM_EXTRA_GLOBALS \
79 struct parmlist_entry *param_opt; \
80 char *szRealm; \
81 char *tls_keyfile; \
82 char *tls_certfile; \
83 char *tls_cafile; \
84 char *tls_crlfile; \
85 char *tls_dhpfile; \
86 char *loglevel; \
87 char *panic_action; \
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 static const struct enum_list enum_protocol[] = {
108 {PROTOCOL_SMB2, "SMB2"},
109 {PROTOCOL_NT1, "NT1"},
110 {PROTOCOL_LANMAN2, "LANMAN2"},
111 {PROTOCOL_LANMAN1, "LANMAN1"},
112 {PROTOCOL_CORE, "CORE"},
113 {PROTOCOL_COREPLUS, "COREPLUS"},
114 {PROTOCOL_COREPLUS, "CORE+"},
115 {-1, NULL}
118 static const struct enum_list enum_security[] = {
119 {SEC_SHARE, "SHARE"},
120 {SEC_USER, "USER"},
121 {SEC_ADS, "ADS"},
122 {-1, NULL}
125 static const struct enum_list enum_bool_auto[] = {
126 {false, "No"},
127 {false, "False"},
128 {false, "0"},
129 {true, "Yes"},
130 {true, "True"},
131 {true, "1"},
132 {Auto, "Auto"},
133 {-1, NULL}
136 /* Client-side offline caching policy types */
137 enum csc_policy {
138 CSC_POLICY_MANUAL=0,
139 CSC_POLICY_DOCUMENTS=1,
140 CSC_POLICY_PROGRAMS=2,
141 CSC_POLICY_DISABLE=3
144 static const struct enum_list enum_csc_policy[] = {
145 {CSC_POLICY_MANUAL, "manual"},
146 {CSC_POLICY_DOCUMENTS, "documents"},
147 {CSC_POLICY_PROGRAMS, "programs"},
148 {CSC_POLICY_DISABLE, "disable"},
149 {-1, NULL}
152 /* SMB signing types. */
153 static const struct enum_list enum_smb_signing_vals[] = {
154 {SMB_SIGNING_OFF, "No"},
155 {SMB_SIGNING_OFF, "False"},
156 {SMB_SIGNING_OFF, "0"},
157 {SMB_SIGNING_OFF, "Off"},
158 {SMB_SIGNING_OFF, "disabled"},
159 {SMB_SIGNING_SUPPORTED, "Yes"},
160 {SMB_SIGNING_SUPPORTED, "True"},
161 {SMB_SIGNING_SUPPORTED, "1"},
162 {SMB_SIGNING_SUPPORTED, "On"},
163 {SMB_SIGNING_SUPPORTED, "enabled"},
164 {SMB_SIGNING_REQUIRED, "required"},
165 {SMB_SIGNING_REQUIRED, "mandatory"},
166 {SMB_SIGNING_REQUIRED, "force"},
167 {SMB_SIGNING_REQUIRED, "forced"},
168 {SMB_SIGNING_REQUIRED, "enforced"},
169 {SMB_SIGNING_AUTO, "auto"},
170 {-1, NULL}
173 static const struct enum_list enum_server_role[] = {
174 {ROLE_STANDALONE, "standalone"},
175 {ROLE_DOMAIN_MEMBER, "member server"},
176 {ROLE_DOMAIN_MEMBER, "member"},
177 {ROLE_DOMAIN_CONTROLLER, "domain controller"},
178 {ROLE_DOMAIN_CONTROLLER, "dc"},
179 {-1, NULL}
182 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
183 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
185 static struct parm_struct parm_table[] = {
187 .label = "server role",
188 .type = P_ENUM,
189 .p_class = P_GLOBAL,
190 .offset = GLOBAL_VAR(server_role),
191 .special = NULL,
192 .enum_list = enum_server_role
195 .label = "dos charset",
196 .type = P_STRING,
197 .p_class = P_GLOBAL,
198 .offset = GLOBAL_VAR(dos_charset),
199 .special = NULL,
200 .enum_list = NULL
203 .label = "unix charset",
204 .type = P_STRING,
205 .p_class = P_GLOBAL,
206 .offset = GLOBAL_VAR(unix_charset),
207 .special = NULL,
208 .enum_list = NULL
211 .label = "ncalrpc dir",
212 .type = P_STRING,
213 .p_class = P_GLOBAL,
214 .offset = GLOBAL_VAR(ncalrpc_dir),
215 .special = NULL,
216 .enum_list = NULL
219 .label = "comment",
220 .type = P_STRING,
221 .p_class = P_LOCAL,
222 .offset = LOCAL_VAR(comment),
223 .special = NULL,
224 .enum_list = NULL
227 .label = "path",
228 .type = P_STRING,
229 .p_class = P_LOCAL,
230 .offset = LOCAL_VAR(szPath),
231 .special = NULL,
232 .enum_list = NULL
235 .label = "directory",
236 .type = P_STRING,
237 .p_class = P_LOCAL,
238 .offset = LOCAL_VAR(szPath),
239 .special = NULL,
240 .enum_list = NULL
243 .label = "workgroup",
244 .type = P_USTRING,
245 .p_class = P_GLOBAL,
246 .offset = GLOBAL_VAR(szWorkgroup),
247 .special = NULL,
248 .enum_list = NULL
251 .label = "realm",
252 .type = P_STRING,
253 .p_class = P_GLOBAL,
254 .offset = GLOBAL_VAR(szRealm),
255 .special = handle_realm,
256 .enum_list = NULL
259 .label = "netbios name",
260 .type = P_USTRING,
261 .p_class = P_GLOBAL,
262 .offset = GLOBAL_VAR(szNetbiosName),
263 .special = NULL,
264 .enum_list = NULL
267 .label = "netbios aliases",
268 .type = P_LIST,
269 .p_class = P_GLOBAL,
270 .offset = GLOBAL_VAR(szNetbiosAliases),
271 .special = NULL,
272 .enum_list = NULL
275 .label = "netbios scope",
276 .type = P_USTRING,
277 .p_class = P_GLOBAL,
278 .offset = GLOBAL_VAR(szNetbiosScope),
279 .special = NULL,
280 .enum_list = NULL
283 .label = "server string",
284 .type = P_STRING,
285 .p_class = P_GLOBAL,
286 .offset = GLOBAL_VAR(szServerString),
287 .special = NULL,
288 .enum_list = NULL
291 .label = "interfaces",
292 .type = P_LIST,
293 .p_class = P_GLOBAL,
294 .offset = GLOBAL_VAR(szInterfaces),
295 .special = NULL,
296 .enum_list = NULL
299 .label = "bind interfaces only",
300 .type = P_BOOL,
301 .p_class = P_GLOBAL,
302 .offset = GLOBAL_VAR(bBindInterfacesOnly),
303 .special = NULL,
304 .enum_list = NULL
307 .label = "ntvfs handler",
308 .type = P_LIST,
309 .p_class = P_LOCAL,
310 .offset = LOCAL_VAR(ntvfs_handler),
311 .special = NULL,
312 .enum_list = NULL
315 .label = "ntptr providor",
316 .type = P_STRING,
317 .p_class = P_GLOBAL,
318 .offset = GLOBAL_VAR(ntptr_providor),
319 .special = NULL,
320 .enum_list = NULL
323 .label = "dcerpc endpoint servers",
324 .type = P_LIST,
325 .p_class = P_GLOBAL,
326 .offset = GLOBAL_VAR(dcerpc_ep_servers),
327 .special = NULL,
328 .enum_list = NULL
331 .label = "server services",
332 .type = P_LIST,
333 .p_class = P_GLOBAL,
334 .offset = GLOBAL_VAR(server_services),
335 .special = NULL,
336 .enum_list = NULL
340 .label = "security",
341 .type = P_ENUM,
342 .p_class = P_GLOBAL,
343 .offset = GLOBAL_VAR(security),
344 .special = NULL,
345 .enum_list = enum_security
348 .label = "encrypt passwords",
349 .type = P_BOOL,
350 .p_class = P_GLOBAL,
351 .offset = GLOBAL_VAR(bEncryptPasswords),
352 .special = NULL,
353 .enum_list = NULL
356 .label = "null passwords",
357 .type = P_BOOL,
358 .p_class = P_GLOBAL,
359 .offset = GLOBAL_VAR(bNullPasswords),
360 .special = NULL,
361 .enum_list = NULL
364 .label = "obey pam restrictions",
365 .type = P_BOOL,
366 .p_class = P_GLOBAL,
367 .offset = GLOBAL_VAR(bObeyPamRestrictions),
368 .special = NULL,
369 .enum_list = NULL
372 .label = "password server",
373 .type = P_LIST,
374 .p_class = P_GLOBAL,
375 .offset = GLOBAL_VAR(szPasswordServers),
376 .special = NULL,
377 .enum_list = NULL
380 .label = "spoolss database",
381 .type = P_STRING,
382 .p_class = P_GLOBAL,
383 .offset = GLOBAL_VAR(szSPOOLSS_URL),
384 .special = NULL,
385 .enum_list = NULL
388 .label = "wins config database",
389 .type = P_STRING,
390 .p_class = P_GLOBAL,
391 .offset = GLOBAL_VAR(szWINS_CONFIG_URL),
392 .special = NULL,
393 .enum_list = NULL
396 .label = "wins database",
397 .type = P_STRING,
398 .p_class = P_GLOBAL,
399 .offset = GLOBAL_VAR(szWINS_URL),
400 .special = NULL,
401 .enum_list = NULL
404 .label = "private dir",
405 .type = P_STRING,
406 .p_class = P_GLOBAL,
407 .offset = GLOBAL_VAR(szPrivateDir),
408 .special = NULL,
409 .enum_list = NULL
412 .label = "passwd chat",
413 .type = P_STRING,
414 .p_class = P_GLOBAL,
415 .offset = GLOBAL_VAR(szPasswdChat),
416 .special = NULL,
417 .enum_list = NULL
420 .label = "password level",
421 .type = P_INTEGER,
422 .p_class = P_GLOBAL,
423 .offset = GLOBAL_VAR(pwordlevel),
424 .special = NULL,
425 .enum_list = NULL
428 .label = "lanman auth",
429 .type = P_BOOL,
430 .p_class = P_GLOBAL,
431 .offset = GLOBAL_VAR(bLanmanAuth),
432 .special = NULL,
433 .enum_list = NULL
436 .label = "ntlm auth",
437 .type = P_BOOL,
438 .p_class = P_GLOBAL,
439 .offset = GLOBAL_VAR(bNTLMAuth),
440 .special = NULL,
441 .enum_list = NULL
444 .label = "client NTLMv2 auth",
445 .type = P_BOOL,
446 .p_class = P_GLOBAL,
447 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
448 .special = NULL,
449 .enum_list = NULL
452 .label = "client lanman auth",
453 .type = P_BOOL,
454 .p_class = P_GLOBAL,
455 .offset = GLOBAL_VAR(bClientLanManAuth),
456 .special = NULL,
457 .enum_list = NULL
460 .label = "client plaintext auth",
461 .type = P_BOOL,
462 .p_class = P_GLOBAL,
463 .offset = GLOBAL_VAR(bClientPlaintextAuth),
464 .special = NULL,
465 .enum_list = NULL
468 .label = "client use spnego principal",
469 .type = P_BOOL,
470 .p_class = P_GLOBAL,
471 .offset = GLOBAL_VAR(client_use_spnego_principal),
472 .special = NULL,
473 .enum_list = NULL
477 .label = "read only",
478 .type = P_BOOL,
479 .p_class = P_LOCAL,
480 .offset = LOCAL_VAR(bRead_only),
481 .special = NULL,
482 .enum_list = NULL
486 .label = "create mask",
487 .type = P_OCTAL,
488 .p_class = P_LOCAL,
489 .offset = LOCAL_VAR(iCreate_mask),
490 .special = NULL,
491 .enum_list = NULL
494 .label = "force create mode",
495 .type = P_OCTAL,
496 .p_class = P_LOCAL,
497 .offset = LOCAL_VAR(iCreate_force_mode),
498 .special = NULL,
499 .enum_list = NULL
502 .label = "directory mask",
503 .type = P_OCTAL,
504 .p_class = P_LOCAL,
505 .offset = LOCAL_VAR(iDir_mask),
506 .special = NULL,
507 .enum_list = NULL
510 .label = "force directory mode",
511 .type = P_OCTAL,
512 .p_class = P_LOCAL,
513 .offset = LOCAL_VAR(iDir_force_mode),
514 .special = NULL,
515 .enum_list = NULL
519 .label = "hosts allow",
520 .type = P_LIST,
521 .p_class = P_LOCAL,
522 .offset = LOCAL_VAR(szHostsallow),
523 .special = NULL,
524 .enum_list = NULL
527 .label = "hosts deny",
528 .type = P_LIST,
529 .p_class = P_LOCAL,
530 .offset = LOCAL_VAR(szHostsdeny),
531 .special = NULL,
532 .enum_list = NULL
536 .label = "log level",
537 .type = P_STRING,
538 .p_class = P_GLOBAL,
539 .offset = GLOBAL_VAR(loglevel),
540 .special = handle_debuglevel,
541 .enum_list = NULL
544 .label = "debuglevel",
545 .type = P_STRING,
546 .p_class = P_GLOBAL,
547 .offset = GLOBAL_VAR(loglevel),
548 .special = handle_debuglevel,
549 .enum_list = NULL
552 .label = "log file",
553 .type = P_STRING,
554 .p_class = P_GLOBAL,
555 .offset = GLOBAL_VAR(logfile),
556 .special = handle_logfile,
557 .enum_list = NULL
561 .label = "smb ports",
562 .type = P_LIST,
563 .p_class = P_GLOBAL,
564 .offset = GLOBAL_VAR(smb_ports),
565 .special = NULL,
566 .enum_list = NULL
569 .label = "nbt port",
570 .type = P_INTEGER,
571 .p_class = P_GLOBAL,
572 .offset = GLOBAL_VAR(nbt_port),
573 .special = NULL,
574 .enum_list = NULL
577 .label = "dgram port",
578 .type = P_INTEGER,
579 .p_class = P_GLOBAL,
580 .offset = GLOBAL_VAR(dgram_port),
581 .special = NULL,
582 .enum_list = NULL
585 .label = "cldap port",
586 .type = P_INTEGER,
587 .p_class = P_GLOBAL,
588 .offset = GLOBAL_VAR(cldap_port),
589 .special = NULL,
590 .enum_list = NULL
593 .label = "krb5 port",
594 .type = P_INTEGER,
595 .p_class = P_GLOBAL,
596 .offset = GLOBAL_VAR(krb5_port),
597 .special = NULL,
598 .enum_list = NULL
601 .label = "kpasswd port",
602 .type = P_INTEGER,
603 .p_class = P_GLOBAL,
604 .offset = GLOBAL_VAR(kpasswd_port),
605 .special = NULL,
606 .enum_list = NULL
609 .label = "web port",
610 .type = P_INTEGER,
611 .p_class = P_GLOBAL,
612 .offset = GLOBAL_VAR(web_port),
613 .special = NULL,
614 .enum_list = NULL
617 .label = "tls enabled",
618 .type = P_BOOL,
619 .p_class = P_GLOBAL,
620 .offset = GLOBAL_VAR(tls_enabled),
621 .special = NULL,
622 .enum_list = NULL
625 .label = "tls keyfile",
626 .type = P_STRING,
627 .p_class = P_GLOBAL,
628 .offset = GLOBAL_VAR(tls_keyfile),
629 .special = NULL,
630 .enum_list = NULL
633 .label = "tls certfile",
634 .type = P_STRING,
635 .p_class = P_GLOBAL,
636 .offset = GLOBAL_VAR(tls_certfile),
637 .special = NULL,
638 .enum_list = NULL
641 .label = "tls cafile",
642 .type = P_STRING,
643 .p_class = P_GLOBAL,
644 .offset = GLOBAL_VAR(tls_cafile),
645 .special = NULL,
646 .enum_list = NULL
649 .label = "tls crlfile",
650 .type = P_STRING,
651 .p_class = P_GLOBAL,
652 .offset = GLOBAL_VAR(tls_crlfile),
653 .special = NULL,
654 .enum_list = NULL
657 .label = "tls dh params file",
658 .type = P_STRING,
659 .p_class = P_GLOBAL,
660 .offset = GLOBAL_VAR(tls_dhpfile),
661 .special = NULL,
662 .enum_list = NULL
665 .label = "large readwrite",
666 .type = P_BOOL,
667 .p_class = P_GLOBAL,
668 .offset = GLOBAL_VAR(bLargeReadwrite),
669 .special = NULL,
670 .enum_list = NULL
673 .label = "server max protocol",
674 .type = P_ENUM,
675 .p_class = P_GLOBAL,
676 .offset = GLOBAL_VAR(srv_maxprotocol),
677 .special = NULL,
678 .enum_list = enum_protocol
681 .label = "server min protocol",
682 .type = P_ENUM,
683 .p_class = P_GLOBAL,
684 .offset = GLOBAL_VAR(srv_minprotocol),
685 .special = NULL,
686 .enum_list = enum_protocol
689 .label = "client max protocol",
690 .type = P_ENUM,
691 .p_class = P_GLOBAL,
692 .offset = GLOBAL_VAR(cli_maxprotocol),
693 .special = NULL,
694 .enum_list = enum_protocol
697 .label = "client min protocol",
698 .type = P_ENUM,
699 .p_class = P_GLOBAL,
700 .offset = GLOBAL_VAR(cli_minprotocol),
701 .special = NULL,
702 .enum_list = enum_protocol
705 .label = "unicode",
706 .type = P_BOOL,
707 .p_class = P_GLOBAL,
708 .offset = GLOBAL_VAR(bUnicode),
709 .special = NULL,
710 .enum_list = NULL
713 .label = "read raw",
714 .type = P_BOOL,
715 .p_class = P_GLOBAL,
716 .offset = GLOBAL_VAR(bReadRaw),
717 .special = NULL,
718 .enum_list = NULL
721 .label = "write raw",
722 .type = P_BOOL,
723 .p_class = P_GLOBAL,
724 .offset = GLOBAL_VAR(bWriteRaw),
725 .special = NULL,
726 .enum_list = NULL
729 .label = "disable netbios",
730 .type = P_BOOL,
731 .p_class = P_GLOBAL,
732 .offset = GLOBAL_VAR(bDisableNetbios),
733 .special = NULL,
734 .enum_list = NULL
738 .label = "nt status support",
739 .type = P_BOOL,
740 .p_class = P_GLOBAL,
741 .offset = GLOBAL_VAR(bNTStatusSupport),
742 .special = NULL,
743 .enum_list = NULL
747 .label = "max mux",
748 .type = P_INTEGER,
749 .p_class = P_GLOBAL,
750 .offset = GLOBAL_VAR(max_mux),
751 .special = NULL,
752 .enum_list = NULL
755 .label = "max xmit",
756 .type = P_BYTES,
757 .p_class = P_GLOBAL,
758 .offset = GLOBAL_VAR(max_xmit),
759 .special = NULL,
760 .enum_list = NULL
764 .label = "name resolve order",
765 .type = P_LIST,
766 .p_class = P_GLOBAL,
767 .offset = GLOBAL_VAR(szNameResolveOrder),
768 .special = NULL,
769 .enum_list = NULL
772 .label = "max wins ttl",
773 .type = P_INTEGER,
774 .p_class = P_GLOBAL,
775 .offset = GLOBAL_VAR(max_wins_ttl),
776 .special = NULL,
777 .enum_list = NULL
780 .label = "min wins ttl",
781 .type = P_INTEGER,
782 .p_class = P_GLOBAL,
783 .offset = GLOBAL_VAR(min_wins_ttl),
784 .special = NULL,
785 .enum_list = NULL
788 .label = "time server",
789 .type = P_BOOL,
790 .p_class = P_GLOBAL,
791 .offset = GLOBAL_VAR(bTimeServer),
792 .special = NULL,
793 .enum_list = NULL
796 .label = "unix extensions",
797 .type = P_BOOL,
798 .p_class = P_GLOBAL,
799 .offset = GLOBAL_VAR(bUnixExtensions),
800 .special = NULL,
801 .enum_list = NULL
804 .label = "use spnego",
805 .type = P_BOOL,
806 .p_class = P_GLOBAL,
807 .offset = GLOBAL_VAR(bUseSpnego),
808 .special = NULL,
809 .enum_list = NULL
812 .label = "server signing",
813 .type = P_ENUM,
814 .p_class = P_GLOBAL,
815 .offset = GLOBAL_VAR(server_signing),
816 .special = NULL,
817 .enum_list = enum_smb_signing_vals
820 .label = "client signing",
821 .type = P_ENUM,
822 .p_class = P_GLOBAL,
823 .offset = GLOBAL_VAR(client_signing),
824 .special = NULL,
825 .enum_list = enum_smb_signing_vals
828 .label = "rpc big endian",
829 .type = P_BOOL,
830 .p_class = P_GLOBAL,
831 .offset = GLOBAL_VAR(bRpcBigEndian),
832 .special = NULL,
833 .enum_list = NULL
837 .label = "max connections",
838 .type = P_INTEGER,
839 .p_class = P_LOCAL,
840 .offset = LOCAL_VAR(iMaxConnections),
841 .special = NULL,
842 .enum_list = NULL
845 .label = "paranoid server security",
846 .type = P_BOOL,
847 .p_class = P_GLOBAL,
848 .offset = GLOBAL_VAR(paranoid_server_security),
849 .special = NULL,
850 .enum_list = NULL
853 .label = "socket options",
854 .type = P_STRING,
855 .p_class = P_GLOBAL,
856 .offset = GLOBAL_VAR(socket_options),
857 .special = NULL,
858 .enum_list = NULL
862 .label = "strict sync",
863 .type = P_BOOL,
864 .p_class = P_LOCAL,
865 .offset = LOCAL_VAR(bStrictSync),
866 .special = NULL,
867 .enum_list = NULL
870 .label = "case insensitive filesystem",
871 .type = P_BOOL,
872 .p_class = P_LOCAL,
873 .offset = LOCAL_VAR(bCIFileSystem),
874 .special = NULL,
875 .enum_list = NULL
879 .label = "max print jobs",
880 .type = P_INTEGER,
881 .p_class = P_LOCAL,
882 .offset = LOCAL_VAR(iMaxPrintJobs),
883 .special = NULL,
884 .enum_list = NULL
887 .label = "printable",
888 .type = P_BOOL,
889 .p_class = P_LOCAL,
890 .offset = LOCAL_VAR(bPrint_ok),
891 .special = NULL,
892 .enum_list = NULL
895 .label = "print ok",
896 .type = P_BOOL,
897 .p_class = P_LOCAL,
898 .offset = LOCAL_VAR(bPrint_ok),
899 .special = NULL,
900 .enum_list = NULL
904 .label = "printer name",
905 .type = P_STRING,
906 .p_class = P_LOCAL,
907 .offset = LOCAL_VAR(szPrintername),
908 .special = NULL,
909 .enum_list = NULL
912 .label = "printer",
913 .type = P_STRING,
914 .p_class = P_LOCAL,
915 .offset = LOCAL_VAR(szPrintername),
916 .special = NULL,
917 .enum_list = NULL
921 .label = "map system",
922 .type = P_BOOL,
923 .p_class = P_LOCAL,
924 .offset = LOCAL_VAR(bMap_system),
925 .special = NULL,
926 .enum_list = NULL
929 .label = "map hidden",
930 .type = P_BOOL,
931 .p_class = P_LOCAL,
932 .offset = LOCAL_VAR(bMap_hidden),
933 .special = NULL,
934 .enum_list = NULL
937 .label = "map archive",
938 .type = P_BOOL,
939 .p_class = P_LOCAL,
940 .offset = LOCAL_VAR(bMap_archive),
941 .special = NULL,
942 .enum_list = NULL
946 .label = "preferred master",
947 .type = P_ENUM,
948 .p_class = P_GLOBAL,
949 .offset = GLOBAL_VAR(bPreferredMaster),
950 .special = NULL,
951 .enum_list = enum_bool_auto
954 .label = "prefered master",
955 .type = P_ENUM,
956 .p_class = P_GLOBAL,
957 .offset = GLOBAL_VAR(bPreferredMaster),
958 .special = NULL,
959 .enum_list = enum_bool_auto
962 .label = "local master",
963 .type = P_BOOL,
964 .p_class = P_GLOBAL,
965 .offset = GLOBAL_VAR(bLocalMaster),
966 .special = NULL,
967 .enum_list = NULL
970 .label = "browseable",
971 .type = P_BOOL,
972 .p_class = P_LOCAL,
973 .offset = LOCAL_VAR(bBrowseable),
974 .special = NULL,
975 .enum_list = NULL
978 .label = "browsable",
979 .type = P_BOOL,
980 .p_class = P_LOCAL,
981 .offset = LOCAL_VAR(bBrowseable),
982 .special = NULL,
983 .enum_list = NULL
987 .label = "wins server",
988 .type = P_LIST,
989 .p_class = P_GLOBAL,
990 .offset = GLOBAL_VAR(szWINSservers),
991 .special = NULL,
992 .enum_list = NULL
995 .label = "wins support",
996 .type = P_BOOL,
997 .p_class = P_GLOBAL,
998 .offset = GLOBAL_VAR(bWINSsupport),
999 .special = NULL,
1000 .enum_list = NULL
1003 .label = "dns proxy",
1004 .type = P_BOOL,
1005 .p_class = P_GLOBAL,
1006 .offset = GLOBAL_VAR(bWINSdnsProxy),
1007 .special = NULL,
1008 .enum_list = NULL
1011 .label = "wins hook",
1012 .type = P_STRING,
1013 .p_class = P_GLOBAL,
1014 .offset = GLOBAL_VAR(szWINSHook),
1015 .special = NULL,
1016 .enum_list = NULL
1020 .label = "csc policy",
1021 .type = P_ENUM,
1022 .p_class = P_LOCAL,
1023 .offset = LOCAL_VAR(iCSCPolicy),
1024 .special = NULL,
1025 .enum_list = enum_csc_policy
1029 .label = "strict locking",
1030 .type = P_BOOL,
1031 .p_class = P_LOCAL,
1032 .offset = LOCAL_VAR(iStrictLocking),
1033 .special = NULL,
1034 .enum_list = NULL
1037 .label = "oplocks",
1038 .type = P_BOOL,
1039 .p_class = P_LOCAL,
1040 .offset = LOCAL_VAR(bOpLocks),
1041 .special = NULL,
1042 .enum_list = NULL
1046 .label = "share backend",
1047 .type = P_STRING,
1048 .p_class = P_GLOBAL,
1049 .offset = GLOBAL_VAR(szShareBackend),
1050 .special = NULL,
1051 .enum_list = NULL
1054 .label = "preload",
1055 .type = P_STRING,
1056 .p_class = P_GLOBAL,
1057 .offset = GLOBAL_VAR(szAutoServices),
1058 .special = NULL,
1059 .enum_list = NULL
1062 .label = "auto services",
1063 .type = P_STRING,
1064 .p_class = P_GLOBAL,
1065 .offset = GLOBAL_VAR(szAutoServices),
1066 .special = NULL,
1067 .enum_list = NULL
1070 .label = "lock dir",
1071 .type = P_STRING,
1072 .p_class = P_GLOBAL,
1073 .offset = GLOBAL_VAR(szLockDir),
1074 .special = NULL,
1075 .enum_list = NULL
1078 .label = "lock directory",
1079 .type = P_STRING,
1080 .p_class = P_GLOBAL,
1081 .offset = GLOBAL_VAR(szLockDir),
1082 .special = NULL,
1083 .enum_list = NULL
1086 .label = "pid directory",
1087 .type = P_STRING,
1088 .p_class = P_GLOBAL,
1089 .offset = GLOBAL_VAR(szPidDir),
1090 .special = NULL,
1091 .enum_list = NULL
1095 .label = "socket address",
1096 .type = P_STRING,
1097 .p_class = P_GLOBAL,
1098 .offset = GLOBAL_VAR(szSocketAddress),
1099 .special = NULL,
1100 .enum_list = NULL
1103 .label = "copy",
1104 .type = P_STRING,
1105 .p_class = P_LOCAL,
1106 .offset = LOCAL_VAR(szCopy),
1107 .special = handle_copy,
1108 .enum_list = NULL
1111 .label = "include",
1112 .type = P_STRING,
1113 .p_class = P_LOCAL,
1114 .offset = LOCAL_VAR(szInclude),
1115 .special = handle_include,
1116 .enum_list = NULL
1120 .label = "available",
1121 .type = P_BOOL,
1122 .p_class = P_LOCAL,
1123 .offset = LOCAL_VAR(bAvailable),
1124 .special = NULL,
1125 .enum_list = NULL
1128 .label = "volume",
1129 .type = P_STRING,
1130 .p_class = P_LOCAL,
1131 .offset = LOCAL_VAR(volume),
1132 .special = NULL,
1133 .enum_list = NULL
1136 .label = "fstype",
1137 .type = P_STRING,
1138 .p_class = P_LOCAL,
1139 .offset = LOCAL_VAR(fstype),
1140 .special = NULL,
1141 .enum_list = NULL
1145 .label = "panic action",
1146 .type = P_STRING,
1147 .p_class = P_GLOBAL,
1148 .offset = GLOBAL_VAR(panic_action),
1149 .special = NULL,
1150 .enum_list = NULL
1154 .label = "msdfs root",
1155 .type = P_BOOL,
1156 .p_class = P_LOCAL,
1157 .offset = LOCAL_VAR(bMSDfsRoot),
1158 .special = NULL,
1159 .enum_list = NULL
1162 .label = "host msdfs",
1163 .type = P_BOOL,
1164 .p_class = P_GLOBAL,
1165 .offset = GLOBAL_VAR(bHostMSDfs),
1166 .special = NULL,
1167 .enum_list = NULL
1170 .label = "winbind separator",
1171 .type = P_STRING,
1172 .p_class = P_GLOBAL,
1173 .offset = GLOBAL_VAR(szWinbindSeparator),
1174 .special = NULL,
1175 .enum_list = NULL
1178 .label = "winbindd socket directory",
1179 .type = P_STRING,
1180 .p_class = P_GLOBAL,
1181 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1182 .special = NULL,
1183 .enum_list = NULL
1186 .label = "winbindd privileged socket directory",
1187 .type = P_STRING,
1188 .p_class = P_GLOBAL,
1189 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1190 .special = NULL,
1191 .enum_list = NULL
1194 .label = "winbind sealed pipes",
1195 .type = P_BOOL,
1196 .p_class = P_GLOBAL,
1197 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1198 .special = NULL,
1199 .enum_list = NULL
1202 .label = "template shell",
1203 .type = P_STRING,
1204 .p_class = P_GLOBAL,
1205 .offset = GLOBAL_VAR(szTemplateShell),
1206 .special = NULL,
1207 .enum_list = NULL
1210 .label = "template homedir",
1211 .type = P_STRING,
1212 .p_class = P_GLOBAL,
1213 .offset = GLOBAL_VAR(szTemplateHomedir),
1214 .special = NULL,
1215 .enum_list = NULL
1218 .label = "idmap trusted only",
1219 .type = P_BOOL,
1220 .p_class = P_GLOBAL,
1221 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1222 .special = NULL,
1223 .enum_list = NULL
1227 .label = "ntp signd socket directory",
1228 .type = P_STRING,
1229 .p_class = P_GLOBAL,
1230 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1231 .special = NULL,
1232 .enum_list = NULL
1235 .label = "rndc command",
1236 .type = P_CMDLIST,
1237 .p_class = P_GLOBAL,
1238 .offset = GLOBAL_VAR(szRNDCCommand),
1239 .special = NULL,
1240 .enum_list = NULL
1243 .label = "dns update command",
1244 .type = P_CMDLIST,
1245 .p_class = P_GLOBAL,
1246 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1247 .special = NULL,
1248 .enum_list = NULL
1251 .label = "spn update command",
1252 .type = P_CMDLIST,
1253 .p_class = P_GLOBAL,
1254 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1255 .special = NULL,
1256 .enum_list = NULL
1259 .label = "nsupdate command",
1260 .type = P_CMDLIST,
1261 .p_class = P_GLOBAL,
1262 .offset = GLOBAL_VAR(szNSUpdateCommand),
1263 .special = NULL,
1264 .enum_list = NULL
1267 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1271 /* local variables */
1272 struct loadparm_context {
1273 const char *szConfigFile;
1274 struct loadparm_global *globals;
1275 struct loadparm_service **services;
1276 struct loadparm_service *sDefault;
1277 struct smb_iconv_handle *iconv_handle;
1278 int iNumServices;
1279 struct loadparm_service *currentService;
1280 bool bInGlobalSection;
1281 struct file_lists {
1282 struct file_lists *next;
1283 char *name;
1284 char *subfname;
1285 time_t modtime;
1286 } *file_lists;
1287 unsigned int flags[NUMPARAMETERS];
1288 bool loaded;
1289 bool refuse_free;
1290 bool global; /* Is this the global context, which may set
1291 * global variables such as debug level etc? */
1292 const struct loadparm_s3_context *s3_fns;
1296 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1298 return lp_ctx->sDefault;
1302 * Convenience routine to grab string parameters into temporary memory
1303 * and run standard_sub_basic on them.
1305 * The buffers can be written to by
1306 * callers without affecting the source string.
1309 static const char *lp_string(const char *s)
1311 #if 0 /* until REWRITE done to make thread-safe */
1312 size_t len = s ? strlen(s) : 0;
1313 char *ret;
1314 #endif
1316 /* The follow debug is useful for tracking down memory problems
1317 especially if you have an inner loop that is calling a lp_*()
1318 function that returns a string. Perhaps this debug should be
1319 present all the time? */
1321 #if 0
1322 DEBUG(10, ("lp_string(%s)\n", s));
1323 #endif
1325 #if 0 /* until REWRITE done to make thread-safe */
1326 if (!lp_talloc)
1327 lp_talloc = talloc_init("lp_talloc");
1329 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1331 if (!ret)
1332 return NULL;
1334 if (!s)
1335 *ret = 0;
1336 else
1337 strlcpy(ret, s, len);
1339 if (trim_string(ret, "\"", "\"")) {
1340 if (strchr(ret,'"') != NULL)
1341 strlcpy(ret, s, len);
1344 standard_sub_basic(ret,len+100);
1345 return (ret);
1346 #endif
1347 return s;
1351 In this section all the functions that are used to access the
1352 parameters from the rest of the program are defined
1356 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1357 * for code compatibility between existing Samba4 and Samba3 code.
1360 /* this global context supports the lp_*() function varients */
1361 static struct loadparm_context *global_loadparm_context;
1363 #define lpcfg_default_service global_loadparm_context->sDefault
1364 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1366 #define FN_GLOBAL_STRING(fn_name,var_name) \
1367 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1368 if (lp_ctx == NULL) return NULL; \
1369 if (lp_ctx->s3_fns) { \
1370 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1371 return lp_ctx->s3_fns->fn_name(); \
1373 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1376 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1377 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1378 if (lp_ctx == NULL) return NULL; \
1379 if (lp_ctx->s3_fns) { \
1380 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1381 return lp_ctx->s3_fns->fn_name(); \
1383 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1386 #define FN_GLOBAL_LIST(fn_name,var_name) \
1387 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1388 if (lp_ctx == NULL) return NULL; \
1389 if (lp_ctx->s3_fns) { \
1390 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1391 return lp_ctx->s3_fns->fn_name(); \
1393 return lp_ctx->globals->var_name; \
1396 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1397 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1398 if (lp_ctx == NULL) return false; \
1399 if (lp_ctx->s3_fns) { \
1400 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1401 return lp_ctx->s3_fns->fn_name(); \
1403 return lp_ctx->globals->var_name; \
1406 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1407 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1408 if (lp_ctx->s3_fns) { \
1409 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1410 return lp_ctx->s3_fns->fn_name(); \
1412 return lp_ctx->globals->var_name; \
1415 #define FN_LOCAL_STRING(fn_name,val) \
1416 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1417 struct loadparm_service *sDefault) { \
1418 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1421 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1423 #define FN_LOCAL_LIST(fn_name,val) \
1424 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1425 struct loadparm_service *sDefault) {\
1426 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1429 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1431 #define FN_LOCAL_BOOL(fn_name,val) \
1432 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1433 struct loadparm_service *sDefault) { \
1434 return((service != NULL)? service->val : sDefault->val); \
1437 #define FN_LOCAL_INTEGER(fn_name,val) \
1438 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1439 struct loadparm_service *sDefault) { \
1440 return((service != NULL)? service->val : sDefault->val); \
1443 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1445 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1447 #define FN_LOCAL_CHAR(fn_name,val) \
1448 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1449 struct loadparm_service *sDefault) { \
1450 return((service != NULL)? service->val : sDefault->val); \
1453 #include "lib/param/param_functions.c"
1455 FN_GLOBAL_INTEGER(server_role, server_role)
1456 FN_GLOBAL_LIST(smb_ports, smb_ports)
1457 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1458 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1459 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1460 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1461 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1462 FN_GLOBAL_INTEGER(web_port, web_port)
1463 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1464 FN_GLOBAL_STRING(logfile, logfile)
1465 FN_GLOBAL_STRING(share_backend, szShareBackend)
1466 FN_GLOBAL_STRING(spoolss_url, szSPOOLSS_URL)
1467 FN_GLOBAL_STRING(wins_config_url, szWINS_CONFIG_URL)
1468 FN_GLOBAL_STRING(wins_url, szWINS_URL)
1469 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1470 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1471 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1472 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1473 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1474 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1475 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1476 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1477 FN_GLOBAL_STRING(serverstring, szServerString)
1478 FN_GLOBAL_STRING(lockdir, szLockDir)
1479 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1480 FN_GLOBAL_STRING(dos_charset, dos_charset)
1481 FN_GLOBAL_STRING(unix_charset, unix_charset)
1482 FN_GLOBAL_STRING(piddir, szPidDir)
1483 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1484 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1485 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1486 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1487 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1488 FN_GLOBAL_LIST(server_services, server_services)
1489 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1490 FN_GLOBAL_STRING(auto_services, szAutoServices)
1491 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1492 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1493 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1494 FN_GLOBAL_STRING(realm, szRealm_upper)
1495 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1496 FN_GLOBAL_STRING(socket_options, socket_options)
1497 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1498 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1499 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1500 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1501 FN_GLOBAL_LIST(interfaces, szInterfaces)
1502 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1503 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1504 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1505 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1506 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1507 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1508 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1509 FN_GLOBAL_BOOL(readraw, bReadRaw)
1510 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1511 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1512 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1513 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1514 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1515 FN_GLOBAL_BOOL(time_server, bTimeServer)
1516 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1517 FN_GLOBAL_BOOL(unicode, bUnicode)
1518 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1519 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1520 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1521 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1522 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1523 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1524 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1525 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1526 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1527 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1528 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1529 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1530 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1531 FN_GLOBAL_INTEGER(maxmux, max_mux)
1532 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1533 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1534 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1535 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1536 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1537 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1538 FN_GLOBAL_INTEGER(security, security)
1539 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1541 FN_GLOBAL_INTEGER(server_signing, server_signing)
1542 FN_GLOBAL_INTEGER(client_signing, client_signing)
1544 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1546 /* local prototypes */
1547 static int map_parameter(const char *pszParmName);
1548 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1549 const char *pszServiceName);
1550 static void copy_service(struct loadparm_service *pserviceDest,
1551 struct loadparm_service *pserviceSource,
1552 struct bitmap *pcopymapDest);
1553 static bool service_ok(struct loadparm_service *service);
1554 static bool do_section(const char *pszSectionName, void *);
1555 static void init_copymap(struct loadparm_service *pservice);
1557 /* This is a helper function for parametrical options support. */
1558 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1559 /* Actual parametrical functions are quite simple */
1560 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1561 struct loadparm_service *service,
1562 const char *type, const char *option)
1564 char *vfskey_tmp = NULL;
1565 char *vfskey = NULL;
1566 struct parmlist_entry *data;
1568 if (lp_ctx == NULL)
1569 return NULL;
1571 if (lp_ctx->s3_fns) {
1572 return lp_ctx->s3_fns->get_parametric(service, type, option);
1575 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1577 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1578 if (vfskey_tmp == NULL) return NULL;
1579 vfskey = strlower_talloc(NULL, vfskey_tmp);
1580 talloc_free(vfskey_tmp);
1582 while (data) {
1583 if (strcmp(data->key, vfskey) == 0) {
1584 talloc_free(vfskey);
1585 return data->value;
1587 data = data->next;
1590 if (service != NULL) {
1591 /* Try to fetch the same option but from globals */
1592 /* but only if we are not already working with globals */
1593 for (data = lp_ctx->globals->param_opt; data;
1594 data = data->next) {
1595 if (strcmp(data->key, vfskey) == 0) {
1596 talloc_free(vfskey);
1597 return data->value;
1602 talloc_free(vfskey);
1604 return NULL;
1609 * convenience routine to return int parameters.
1611 static int lp_int(const char *s)
1614 if (!s) {
1615 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1616 return -1;
1619 return strtol(s, NULL, 0);
1623 * convenience routine to return unsigned long parameters.
1625 static int lp_ulong(const char *s)
1628 if (!s) {
1629 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1630 return -1;
1633 return strtoul(s, NULL, 0);
1637 * convenience routine to return unsigned long parameters.
1639 static double lp_double(const char *s)
1642 if (!s) {
1643 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1644 return -1;
1647 return strtod(s, NULL);
1651 * convenience routine to return boolean parameters.
1653 static bool lp_bool(const char *s)
1655 bool ret = false;
1657 if (!s) {
1658 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1659 return false;
1662 if (!set_boolean(s, &ret)) {
1663 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1664 return false;
1667 return ret;
1672 * Return parametric option from a given service. Type is a part of option before ':'
1673 * Parametric option has following syntax: 'Type: option = value'
1674 * Returned value is allocated in 'lp_talloc' context
1677 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1678 struct loadparm_service *service, const char *type,
1679 const char *option)
1681 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1683 if (value)
1684 return lp_string(value);
1686 return NULL;
1690 * Return parametric option from a given service. Type is a part of option before ':'
1691 * Parametric option has following syntax: 'Type: option = value'
1692 * Returned value is allocated in 'lp_talloc' context
1695 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1696 struct loadparm_context *lp_ctx,
1697 struct loadparm_service *service,
1698 const char *type,
1699 const char *option, const char *separator)
1701 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1703 if (value != NULL)
1704 return (const char **)str_list_make(mem_ctx, value, separator);
1706 return NULL;
1710 * Return parametric option from a given service. Type is a part of option before ':'
1711 * Parametric option has following syntax: 'Type: option = value'
1714 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1715 struct loadparm_service *service, const char *type,
1716 const char *option, int default_v)
1718 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1720 if (value)
1721 return lp_int(value);
1723 return default_v;
1727 * Return parametric option from a given service. Type is a part of
1728 * option before ':'.
1729 * Parametric option has following syntax: 'Type: option = value'.
1732 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1733 struct loadparm_service *service, const char *type,
1734 const char *option, int default_v)
1736 uint64_t bval;
1738 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1740 if (value && conv_str_size_error(value, &bval)) {
1741 if (bval <= INT_MAX) {
1742 return (int)bval;
1746 return default_v;
1750 * Return parametric option from a given service.
1751 * Type is a part of option before ':'
1752 * Parametric option has following syntax: 'Type: option = value'
1754 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1755 struct loadparm_service *service, const char *type,
1756 const char *option, unsigned long default_v)
1758 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1760 if (value)
1761 return lp_ulong(value);
1763 return default_v;
1767 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1768 struct loadparm_service *service, const char *type,
1769 const char *option, double default_v)
1771 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1773 if (value != NULL)
1774 return lp_double(value);
1776 return default_v;
1780 * Return parametric option from a given service. Type is a part of option before ':'
1781 * Parametric option has following syntax: 'Type: option = value'
1784 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1785 struct loadparm_service *service, const char *type,
1786 const char *option, bool default_v)
1788 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1790 if (value != NULL)
1791 return lp_bool(value);
1793 return default_v;
1798 * Initialise a service to the defaults.
1801 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1803 struct loadparm_service *pservice =
1804 talloc_zero(mem_ctx, struct loadparm_service);
1805 copy_service(pservice, sDefault, NULL);
1806 return pservice;
1810 * Set a string value, deallocating any existing space, and allocing the space
1811 * for the string
1813 static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1815 talloc_free(*dest);
1817 if (src == NULL)
1818 src = "";
1820 *dest = talloc_strdup(mem_ctx, src);
1821 if ((*dest) == NULL) {
1822 DEBUG(0,("Out of memory in string_set\n"));
1823 return false;
1826 return true;
1830 * Set a string value, deallocating any existing space, and allocing the space
1831 * for the string
1833 static bool string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1835 talloc_free(*dest);
1837 if (src == NULL)
1838 src = "";
1840 *dest = strupper_talloc(mem_ctx, src);
1841 if ((*dest) == NULL) {
1842 DEBUG(0,("Out of memory in string_set_upper\n"));
1843 return false;
1846 return true;
1852 * Add a new service to the services array initialising it with the given
1853 * service.
1856 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1857 const struct loadparm_service *pservice,
1858 const char *name)
1860 int i;
1861 struct loadparm_service tservice;
1862 int num_to_alloc = lp_ctx->iNumServices + 1;
1863 struct parmlist_entry *data, *pdata;
1865 if (pservice == NULL) {
1866 pservice = lp_ctx->sDefault;
1869 tservice = *pservice;
1871 /* it might already exist */
1872 if (name) {
1873 struct loadparm_service *service = getservicebyname(lp_ctx,
1874 name);
1875 if (service != NULL) {
1876 /* Clean all parametric options for service */
1877 /* They will be added during parsing again */
1878 data = service->param_opt;
1879 while (data) {
1880 pdata = data->next;
1881 talloc_free(data);
1882 data = pdata;
1884 service->param_opt = NULL;
1885 return service;
1889 /* find an invalid one */
1890 for (i = 0; i < lp_ctx->iNumServices; i++)
1891 if (lp_ctx->services[i] == NULL)
1892 break;
1894 /* if not, then create one */
1895 if (i == lp_ctx->iNumServices) {
1896 struct loadparm_service **tsp;
1898 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1900 if (!tsp) {
1901 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1902 return NULL;
1903 } else {
1904 lp_ctx->services = tsp;
1905 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1908 lp_ctx->iNumServices++;
1911 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1912 if (lp_ctx->services[i] == NULL) {
1913 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1914 return NULL;
1916 copy_service(lp_ctx->services[i], &tservice, NULL);
1917 if (name != NULL)
1918 string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1919 return lp_ctx->services[i];
1923 * Add a new home service, with the specified home directory, defaults coming
1924 * from service ifrom.
1927 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1928 const char *pszHomename,
1929 struct loadparm_service *default_service,
1930 const char *user, const char *pszHomedir)
1932 struct loadparm_service *service;
1934 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1936 if (service == NULL)
1937 return false;
1939 if (!(*(default_service->szPath))
1940 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1941 service->szPath = talloc_strdup(service, pszHomedir);
1942 } else {
1943 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1946 if (!(*(service->comment))) {
1947 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1949 service->bAvailable = default_service->bAvailable;
1950 service->bBrowseable = default_service->bBrowseable;
1952 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1953 pszHomename, user, service->szPath));
1955 return true;
1959 * Add a new printer service, with defaults coming from service iFrom.
1962 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1963 const char *pszPrintername,
1964 struct loadparm_service *default_service)
1966 const char *comment = "From Printcap";
1967 struct loadparm_service *service;
1968 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1970 if (service == NULL)
1971 return false;
1973 /* note that we do NOT default the availability flag to True - */
1974 /* we take it from the default service passed. This allows all */
1975 /* dynamic printers to be disabled by disabling the [printers] */
1976 /* entry (if/when the 'available' keyword is implemented!). */
1978 /* the printer name is set to the service name. */
1979 string_set(service, &service->szPrintername, pszPrintername);
1980 string_set(service, &service->comment, comment);
1981 service->bBrowseable = default_service->bBrowseable;
1982 /* Printers cannot be read_only. */
1983 service->bRead_only = false;
1984 /* Printer services must be printable. */
1985 service->bPrint_ok = true;
1987 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1989 return true;
1993 * Map a parameter's string representation to something we can use.
1994 * Returns False if the parameter string is not recognised, else TRUE.
1997 static int map_parameter(const char *pszParmName)
1999 int iIndex;
2001 if (*pszParmName == '-')
2002 return -1;
2004 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2005 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2006 return iIndex;
2008 /* Warn only if it isn't parametric option */
2009 if (strchr(pszParmName, ':') == NULL)
2010 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2011 /* We do return 'fail' for parametric options as well because they are
2012 stored in different storage
2014 return -1;
2019 return the parameter structure for a parameter
2021 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2023 int parmnum;
2025 if (lp_ctx->s3_fns) {
2026 return lp_ctx->s3_fns->get_parm_struct(name);
2029 parmnum = map_parameter(name);
2030 if (parmnum == -1) return NULL;
2031 return &parm_table[parmnum];
2035 return the parameter pointer for a parameter
2037 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2038 struct loadparm_service *service, struct parm_struct *parm)
2040 if (lp_ctx->s3_fns) {
2041 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2044 if (service == NULL) {
2045 if (parm->p_class == P_LOCAL)
2046 return ((char *)lp_ctx->sDefault)+parm->offset;
2047 else if (parm->p_class == P_GLOBAL)
2048 return ((char *)lp_ctx->globals)+parm->offset;
2049 else return NULL;
2050 } else {
2051 return ((char *)service) + parm->offset;
2056 * Find a service by name. Otherwise works like get_service.
2059 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2060 const char *pszServiceName)
2062 int iService;
2064 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2065 if (lp_ctx->services[iService] != NULL &&
2066 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2067 return lp_ctx->services[iService];
2070 return NULL;
2074 * Copy a service structure to another.
2075 * If pcopymapDest is NULL then copy all fields
2078 static void copy_service(struct loadparm_service *pserviceDest,
2079 struct loadparm_service *pserviceSource,
2080 struct bitmap *pcopymapDest)
2082 int i;
2083 bool bcopyall = (pcopymapDest == NULL);
2084 struct parmlist_entry *data, *pdata, *paramo;
2085 bool not_added;
2087 for (i = 0; parm_table[i].label; i++)
2088 if (parm_table[i].p_class == P_LOCAL &&
2089 (bcopyall || bitmap_query(pcopymapDest, i))) {
2090 void *src_ptr =
2091 ((char *)pserviceSource) + parm_table[i].offset;
2092 void *dest_ptr =
2093 ((char *)pserviceDest) + parm_table[i].offset;
2095 switch (parm_table[i].type) {
2096 case P_BOOL:
2097 *(int *)dest_ptr = *(int *)src_ptr;
2098 break;
2100 case P_INTEGER:
2101 case P_OCTAL:
2102 case P_ENUM:
2103 *(int *)dest_ptr = *(int *)src_ptr;
2104 break;
2106 case P_STRING:
2107 string_set(pserviceDest,
2108 (char **)dest_ptr,
2109 *(char **)src_ptr);
2110 break;
2112 case P_USTRING:
2113 string_set_upper(pserviceDest,
2114 (char **)dest_ptr,
2115 *(char **)src_ptr);
2116 break;
2117 case P_LIST:
2118 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2119 *(const char ***)src_ptr);
2120 break;
2121 default:
2122 break;
2126 if (bcopyall) {
2127 init_copymap(pserviceDest);
2128 if (pserviceSource->copymap)
2129 bitmap_copy(pserviceDest->copymap,
2130 pserviceSource->copymap);
2133 data = pserviceSource->param_opt;
2134 while (data) {
2135 not_added = true;
2136 pdata = pserviceDest->param_opt;
2137 /* Traverse destination */
2138 while (pdata) {
2139 /* If we already have same option, override it */
2140 if (strcmp(pdata->key, data->key) == 0) {
2141 talloc_free(pdata->value);
2142 pdata->value = talloc_reference(pdata,
2143 data->value);
2144 not_added = false;
2145 break;
2147 pdata = pdata->next;
2149 if (not_added) {
2150 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2151 if (paramo == NULL)
2152 smb_panic("OOM");
2153 paramo->key = talloc_reference(paramo, data->key);
2154 paramo->value = talloc_reference(paramo, data->value);
2155 DLIST_ADD(pserviceDest->param_opt, paramo);
2157 data = data->next;
2162 * Check a service for consistency. Return False if the service is in any way
2163 * incomplete or faulty, else True.
2165 static bool service_ok(struct loadparm_service *service)
2167 bool bRetval;
2169 bRetval = true;
2170 if (service->szService[0] == '\0') {
2171 DEBUG(0, ("The following message indicates an internal error:\n"));
2172 DEBUG(0, ("No service name in service entry.\n"));
2173 bRetval = false;
2176 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2177 /* I can't see why you'd want a non-printable printer service... */
2178 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2179 if (!service->bPrint_ok) {
2180 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2181 service->szService));
2182 service->bPrint_ok = true;
2184 /* [printers] service must also be non-browsable. */
2185 if (service->bBrowseable)
2186 service->bBrowseable = false;
2189 /* If a service is flagged unavailable, log the fact at level 0. */
2190 if (!service->bAvailable)
2191 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2192 service->szService));
2194 return bRetval;
2198 /*******************************************************************
2199 Keep a linked list of all config files so we know when one has changed
2200 it's date and needs to be reloaded.
2201 ********************************************************************/
2203 static void add_to_file_list(struct loadparm_context *lp_ctx,
2204 const char *fname, const char *subfname)
2206 struct file_lists *f = lp_ctx->file_lists;
2208 while (f) {
2209 if (f->name && !strcmp(f->name, fname))
2210 break;
2211 f = f->next;
2214 if (!f) {
2215 f = talloc(lp_ctx, struct file_lists);
2216 if (!f)
2217 return;
2218 f->next = lp_ctx->file_lists;
2219 f->name = talloc_strdup(f, fname);
2220 if (!f->name) {
2221 talloc_free(f);
2222 return;
2224 f->subfname = talloc_strdup(f, subfname);
2225 if (!f->subfname) {
2226 talloc_free(f);
2227 return;
2229 lp_ctx->file_lists = f;
2230 f->modtime = file_modtime(subfname);
2231 } else {
2232 time_t t = file_modtime(subfname);
2233 if (t)
2234 f->modtime = t;
2238 /*******************************************************************
2239 Check if a config file has changed date.
2240 ********************************************************************/
2241 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2243 struct file_lists *f;
2244 DEBUG(6, ("lp_file_list_changed()\n"));
2246 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2247 char *n2;
2248 time_t mod_time;
2250 n2 = standard_sub_basic(lp_ctx, f->name);
2252 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2253 f->name, n2, ctime(&f->modtime)));
2255 mod_time = file_modtime(n2);
2257 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2258 DEBUGADD(6, ("file %s modified: %s\n", n2,
2259 ctime(&mod_time)));
2260 f->modtime = mod_time;
2261 talloc_free(f->subfname);
2262 f->subfname = talloc_strdup(f, n2);
2263 return true;
2266 return false;
2269 /***************************************************************************
2270 Handle the "realm" parameter
2271 ***************************************************************************/
2273 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2274 const char *pszParmValue, char **ptr)
2276 string_set(lp_ctx, ptr, pszParmValue);
2278 talloc_free(lp_ctx->globals->szRealm_upper);
2279 talloc_free(lp_ctx->globals->szRealm_lower);
2281 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2282 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2284 return true;
2287 /***************************************************************************
2288 Handle the include operation.
2289 ***************************************************************************/
2291 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2292 const char *pszParmValue, char **ptr)
2294 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2296 add_to_file_list(lp_ctx, pszParmValue, fname);
2298 string_set(lp_ctx, ptr, fname);
2300 if (file_exist(fname))
2301 return pm_process(fname, do_section, do_parameter, lp_ctx);
2303 DEBUG(2, ("Can't find include file %s\n", fname));
2305 return false;
2308 /***************************************************************************
2309 Handle the interpretation of the copy parameter.
2310 ***************************************************************************/
2312 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2313 const char *pszParmValue, char **ptr)
2315 bool bRetval;
2316 struct loadparm_service *serviceTemp;
2318 string_set(lp_ctx, ptr, pszParmValue);
2320 bRetval = false;
2322 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2324 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2325 if (serviceTemp == lp_ctx->currentService) {
2326 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2327 } else {
2328 copy_service(lp_ctx->currentService,
2329 serviceTemp,
2330 lp_ctx->currentService->copymap);
2331 bRetval = true;
2333 } else {
2334 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2335 pszParmValue));
2336 bRetval = false;
2339 return bRetval;
2342 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2343 const char *pszParmValue, char **ptr)
2346 string_set(lp_ctx, ptr, pszParmValue);
2347 if (lp_ctx->global) {
2348 return debug_parse_levels(pszParmValue);
2350 return true;
2353 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2354 const char *pszParmValue, char **ptr)
2356 debug_set_logfile(pszParmValue);
2357 if (lp_ctx->global) {
2358 string_set(lp_ctx, ptr, pszParmValue);
2360 return true;
2363 /***************************************************************************
2364 Initialise a copymap.
2365 ***************************************************************************/
2367 static void init_copymap(struct loadparm_service *pservice)
2369 int i;
2371 TALLOC_FREE(pservice->copymap);
2373 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2374 if (!pservice->copymap)
2375 DEBUG(0,
2376 ("Couldn't allocate copymap!! (size %d)\n",
2377 (int)NUMPARAMETERS));
2378 else
2379 for (i = 0; i < NUMPARAMETERS; i++)
2380 bitmap_set(pservice->copymap, i);
2384 * Process a parametric option
2386 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2387 struct loadparm_service *service,
2388 const char *pszParmName,
2389 const char *pszParmValue, int flags)
2391 struct parmlist_entry *paramo, *data;
2392 char *name;
2393 TALLOC_CTX *mem_ctx;
2395 while (isspace((unsigned char)*pszParmName)) {
2396 pszParmName++;
2399 name = strlower_talloc(lp_ctx, pszParmName);
2400 if (!name) return false;
2402 if (service == NULL) {
2403 data = lp_ctx->globals->param_opt;
2404 mem_ctx = lp_ctx->globals;
2405 } else {
2406 data = service->param_opt;
2407 mem_ctx = service;
2410 /* Traverse destination */
2411 for (paramo=data; paramo; paramo=paramo->next) {
2412 /* If we already have the option set, override it unless
2413 it was a command line option and the new one isn't */
2414 if (strcmp(paramo->key, name) == 0) {
2415 if ((paramo->priority & FLAG_CMDLINE) &&
2416 !(flags & FLAG_CMDLINE)) {
2417 talloc_free(name);
2418 return true;
2421 talloc_free(paramo->value);
2422 paramo->value = talloc_strdup(paramo, pszParmValue);
2423 paramo->priority = flags;
2424 talloc_free(name);
2425 return true;
2429 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2430 if (!paramo)
2431 smb_panic("OOM");
2432 paramo->key = talloc_strdup(paramo, name);
2433 paramo->value = talloc_strdup(paramo, pszParmValue);
2434 paramo->priority = flags;
2435 if (service == NULL) {
2436 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2437 } else {
2438 DLIST_ADD(service->param_opt, paramo);
2441 talloc_free(name);
2443 return true;
2446 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2447 const char *pszParmName, const char *pszParmValue,
2448 struct loadparm_context *lp_ctx, bool on_globals)
2450 int i;
2451 /* if it is a special case then go ahead */
2452 if (parm_table[parmnum].special) {
2453 bool ret;
2454 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2455 (char **)parm_ptr);
2456 if (!ret) {
2457 return false;
2459 goto mark_non_default;
2462 /* now switch on the type of variable it is */
2463 switch (parm_table[parmnum].type)
2465 case P_BOOL: {
2466 bool b;
2467 if (!set_boolean(pszParmValue, &b)) {
2468 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2469 return false;
2471 *(int *)parm_ptr = b;
2473 break;
2475 case P_BOOLREV: {
2476 bool b;
2477 if (!set_boolean(pszParmValue, &b)) {
2478 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2479 return false;
2481 *(int *)parm_ptr = !b;
2483 break;
2485 case P_INTEGER:
2486 *(int *)parm_ptr = atoi(pszParmValue);
2487 break;
2489 case P_OCTAL:
2490 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2491 break;
2493 case P_BYTES:
2495 uint64_t val;
2496 if (conv_str_size_error(pszParmValue, &val)) {
2497 if (val <= INT_MAX) {
2498 *(int *)parm_ptr = (int)val;
2499 break;
2503 DEBUG(0,("lp_do_parameter(%s): value is not "
2504 "a valid size specifier!\n", pszParmValue));
2505 return false;
2508 case P_CMDLIST:
2509 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2510 pszParmValue, NULL);
2511 break;
2512 case P_LIST:
2514 char **new_list = str_list_make(mem_ctx,
2515 pszParmValue, NULL);
2516 for (i=0; new_list[i]; i++) {
2517 if (new_list[i][0] == '+' && new_list[i][1] &&
2518 (!str_list_check(*(const char ***)parm_ptr,
2519 &new_list[i][1]))) {
2520 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2521 &new_list[i][1]);
2522 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2523 #if 0 /* This is commented out because we sometimes parse the list
2524 * twice, and so we can't assert on this */
2525 if (!str_list_check(*(const char ***)parm_ptr,
2526 &new_list[i][1])) {
2527 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2528 pszParmName, pszParmValue, new_list[i],
2529 str_list_join_shell(mem_ctx, *(const char ***)parm_ptr, ' ')));
2530 return false;
2533 #endif
2534 str_list_remove(*(const char ***)parm_ptr,
2535 &new_list[i][1]);
2536 } else {
2537 if (i != 0) {
2538 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2539 pszParmName, pszParmValue));
2540 return false;
2542 *(const char ***)parm_ptr = (const char **) new_list;
2543 break;
2546 break;
2548 case P_STRING:
2549 string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2550 break;
2552 case P_USTRING:
2553 string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2554 break;
2556 case P_ENUM:
2557 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2558 if (strequal
2559 (pszParmValue,
2560 parm_table[parmnum].enum_list[i].name)) {
2561 *(int *)parm_ptr =
2562 parm_table[parmnum].
2563 enum_list[i].value;
2564 break;
2567 if (!parm_table[parmnum].enum_list[i].name) {
2568 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2569 pszParmValue, pszParmName));
2570 return false;
2572 break;
2575 mark_non_default:
2576 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2577 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2578 /* we have to also unset FLAG_DEFAULT on aliases */
2579 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2580 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2582 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2583 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2586 return true;
2590 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2591 const char *pszParmName, const char *pszParmValue)
2593 int parmnum = map_parameter(pszParmName);
2594 void *parm_ptr;
2596 if (parmnum < 0) {
2597 if (strchr(pszParmName, ':')) {
2598 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2600 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2601 return true;
2604 /* if the flag has been set on the command line, then don't allow override,
2605 but don't report an error */
2606 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2607 return true;
2610 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2612 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2613 pszParmName, pszParmValue, lp_ctx, true);
2616 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2617 struct loadparm_service *service,
2618 const char *pszParmName, const char *pszParmValue)
2620 void *parm_ptr;
2621 int i;
2622 int parmnum = map_parameter(pszParmName);
2624 if (parmnum < 0) {
2625 if (strchr(pszParmName, ':')) {
2626 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2628 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2629 return true;
2632 /* if the flag has been set on the command line, then don't allow override,
2633 but don't report an error */
2634 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2635 return true;
2638 if (parm_table[parmnum].p_class == P_GLOBAL) {
2639 DEBUG(0,
2640 ("Global parameter %s found in service section!\n",
2641 pszParmName));
2642 return true;
2644 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2646 if (!service->copymap)
2647 init_copymap(service);
2649 /* this handles the aliases - set the copymap for other
2650 * entries with the same data pointer */
2651 for (i = 0; parm_table[i].label; i++)
2652 if (parm_table[i].offset == parm_table[parmnum].offset &&
2653 parm_table[i].p_class == parm_table[parmnum].p_class)
2654 bitmap_clear(service->copymap, i);
2656 return set_variable(service, parmnum, parm_ptr, pszParmName,
2657 pszParmValue, lp_ctx, false);
2661 * Process a parameter.
2664 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2665 void *userdata)
2667 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2669 if (lp_ctx->bInGlobalSection)
2670 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2671 pszParmValue);
2672 else
2673 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2674 pszParmName, pszParmValue);
2678 variable argument do parameter
2680 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2681 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2682 const char *pszParmName, const char *fmt, ...)
2684 char *s;
2685 bool ret;
2686 va_list ap;
2688 va_start(ap, fmt);
2689 s = talloc_vasprintf(NULL, fmt, ap);
2690 va_end(ap);
2691 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2692 talloc_free(s);
2693 return ret;
2698 set a parameter from the commandline - this is called from command line parameter
2699 parsing code. It sets the parameter then marks the parameter as unable to be modified
2700 by smb.conf processing
2702 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2703 const char *pszParmValue)
2705 int parmnum = map_parameter(pszParmName);
2706 int i;
2708 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2711 if (parmnum < 0 && strchr(pszParmName, ':')) {
2712 /* set a parametric option */
2713 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2714 pszParmValue, FLAG_CMDLINE);
2717 if (parmnum < 0) {
2718 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2719 return false;
2722 /* reset the CMDLINE flag in case this has been called before */
2723 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2725 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2726 return false;
2729 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2731 /* we have to also set FLAG_CMDLINE on aliases */
2732 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2733 lp_ctx->flags[i] |= FLAG_CMDLINE;
2735 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2736 lp_ctx->flags[i] |= FLAG_CMDLINE;
2739 return true;
2743 set a option from the commandline in 'a=b' format. Use to support --option
2745 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2747 char *p, *s;
2748 bool ret;
2750 s = strdup(option);
2751 if (!s) {
2752 return false;
2755 p = strchr(s, '=');
2756 if (!p) {
2757 free(s);
2758 return false;
2761 *p = 0;
2763 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2764 free(s);
2765 return ret;
2769 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2772 * Print a parameter of the specified type.
2775 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2777 int i;
2778 const char *list_sep = ", "; /* For the seperation of lists values that we print below */
2779 switch (p->type)
2781 case P_ENUM:
2782 for (i = 0; p->enum_list[i].name; i++) {
2783 if (*(int *)ptr == p->enum_list[i].value) {
2784 fprintf(f, "%s",
2785 p->enum_list[i].name);
2786 break;
2789 break;
2791 case P_BOOL:
2792 fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
2793 break;
2795 case P_BOOLREV:
2796 fprintf(f, "%s", BOOLSTR(!(bool)*(int *)ptr));
2797 break;
2799 case P_INTEGER:
2800 case P_BYTES:
2801 fprintf(f, "%d", *(int *)ptr);
2802 break;
2804 case P_OCTAL:
2805 fprintf(f, "0%o", *(int *)ptr);
2806 break;
2808 case P_CMDLIST:
2809 list_sep = " ";
2810 /* fall through */
2811 case P_LIST:
2812 if ((char ***)ptr && *(char ***)ptr) {
2813 char **list = *(char ***)ptr;
2815 for (; *list; list++) {
2816 if (*(list+1) == NULL) {
2817 /* last item, print no extra seperator after */
2818 list_sep = "";
2820 fprintf(f, "%s%s", *list, list_sep);
2823 break;
2825 case P_STRING:
2826 case P_USTRING:
2827 if (*(char **)ptr) {
2828 fprintf(f, "%s", *(char **)ptr);
2830 break;
2835 * Check if two parameters are equal.
2838 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2840 switch (type) {
2841 case P_BOOL:
2842 case P_BOOLREV:
2843 return (*((int *)ptr1) == *((int *)ptr2));
2845 case P_INTEGER:
2846 case P_OCTAL:
2847 case P_BYTES:
2848 case P_ENUM:
2849 return (*((int *)ptr1) == *((int *)ptr2));
2851 case P_CMDLIST:
2852 case P_LIST:
2853 return str_list_equal((const char **)(*(char ***)ptr1),
2854 (const char **)(*(char ***)ptr2));
2856 case P_STRING:
2857 case P_USTRING:
2859 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2860 if (p1 && !*p1)
2861 p1 = NULL;
2862 if (p2 && !*p2)
2863 p2 = NULL;
2864 return (p1 == p2 || strequal(p1, p2));
2867 return false;
2871 * Process a new section (service).
2873 * At this stage all sections are services.
2874 * Later we'll have special sections that permit server parameters to be set.
2875 * Returns True on success, False on failure.
2878 static bool do_section(const char *pszSectionName, void *userdata)
2880 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2881 bool bRetval;
2882 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2883 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2884 bRetval = false;
2886 /* if we've just struck a global section, note the fact. */
2887 lp_ctx->bInGlobalSection = isglobal;
2889 /* check for multiple global sections */
2890 if (lp_ctx->bInGlobalSection) {
2891 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2892 return true;
2895 /* if we have a current service, tidy it up before moving on */
2896 bRetval = true;
2898 if (lp_ctx->currentService != NULL)
2899 bRetval = service_ok(lp_ctx->currentService);
2901 /* if all is still well, move to the next record in the services array */
2902 if (bRetval) {
2903 /* We put this here to avoid an odd message order if messages are */
2904 /* issued by the post-processing of a previous section. */
2905 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2907 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2908 pszSectionName))
2909 == NULL) {
2910 DEBUG(0, ("Failed to add a new service\n"));
2911 return false;
2915 return bRetval;
2920 * Determine if a particular base parameter is currently set to the default value.
2923 static bool is_default(struct loadparm_service *sDefault, int i)
2925 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2926 if (!defaults_saved)
2927 return false;
2928 switch (parm_table[i].type) {
2929 case P_CMDLIST:
2930 case P_LIST:
2931 return str_list_equal((const char **)parm_table[i].def.lvalue,
2932 (const char **)def_ptr);
2933 case P_STRING:
2934 case P_USTRING:
2935 return strequal(parm_table[i].def.svalue,
2936 *(char **)def_ptr);
2937 case P_BOOL:
2938 case P_BOOLREV:
2939 return parm_table[i].def.bvalue ==
2940 *(int *)def_ptr;
2941 case P_INTEGER:
2942 case P_OCTAL:
2943 case P_BYTES:
2944 case P_ENUM:
2945 return parm_table[i].def.ivalue ==
2946 *(int *)def_ptr;
2948 return false;
2952 *Display the contents of the global structure.
2955 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2956 bool show_defaults)
2958 int i;
2959 struct parmlist_entry *data;
2961 fprintf(f, "# Global parameters\n[global]\n");
2963 for (i = 0; parm_table[i].label; i++)
2964 if (parm_table[i].p_class == P_GLOBAL &&
2965 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2966 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2967 continue;
2968 fprintf(f, "\t%s = ", parm_table[i].label);
2969 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2970 fprintf(f, "\n");
2972 if (lp_ctx->globals->param_opt != NULL) {
2973 for (data = lp_ctx->globals->param_opt; data;
2974 data = data->next) {
2975 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2976 continue;
2978 fprintf(f, "\t%s = %s\n", data->key, data->value);
2985 * Display the contents of a single services record.
2988 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2989 unsigned int *flags)
2991 int i;
2992 struct parmlist_entry *data;
2994 if (pService != sDefault)
2995 fprintf(f, "\n[%s]\n", pService->szService);
2997 for (i = 0; parm_table[i].label; i++) {
2998 if (parm_table[i].p_class == P_LOCAL &&
2999 (*parm_table[i].label != '-') &&
3000 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3002 if (pService == sDefault) {
3003 if (flags && (flags[i] & FLAG_DEFAULT)) {
3004 continue;
3006 if (defaults_saved) {
3007 if (is_default(sDefault, i)) {
3008 continue;
3011 } else {
3012 if (equal_parameter(parm_table[i].type,
3013 ((char *)pService) +
3014 parm_table[i].offset,
3015 ((char *)sDefault) +
3016 parm_table[i].offset))
3017 continue;
3020 fprintf(f, "\t%s = ", parm_table[i].label);
3021 print_parameter(&parm_table[i],
3022 ((char *)pService) + parm_table[i].offset, f);
3023 fprintf(f, "\n");
3026 if (pService->param_opt != NULL) {
3027 for (data = pService->param_opt; data; data = data->next) {
3028 fprintf(f, "\t%s = %s\n", data->key, data->value);
3033 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3034 struct loadparm_service *service,
3035 const char *parm_name, FILE * f)
3037 struct parm_struct *parm;
3038 void *ptr;
3040 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3041 if (!parm) {
3042 return false;
3045 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3047 print_parameter(parm, ptr, f);
3048 fprintf(f, "\n");
3049 return true;
3053 * Return info about the next parameter in a service.
3054 * snum==-1 gives the globals.
3055 * Return NULL when out of parameters.
3059 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3060 int allparameters)
3062 if (snum == -1) {
3063 /* do the globals */
3064 for (; parm_table[*i].label; (*i)++) {
3065 if ((*parm_table[*i].label == '-'))
3066 continue;
3068 if ((*i) > 0
3069 && (parm_table[*i].offset ==
3070 parm_table[(*i) - 1].offset)
3071 && (parm_table[*i].p_class ==
3072 parm_table[(*i) - 1].p_class))
3073 continue;
3075 return &parm_table[(*i)++];
3077 } else {
3078 struct loadparm_service *pService = lp_ctx->services[snum];
3080 for (; parm_table[*i].label; (*i)++) {
3081 if (parm_table[*i].p_class == P_LOCAL &&
3082 (*parm_table[*i].label != '-') &&
3083 ((*i) == 0 ||
3084 (parm_table[*i].offset !=
3085 parm_table[(*i) - 1].offset)))
3087 if (allparameters ||
3088 !equal_parameter(parm_table[*i].type,
3089 ((char *)pService) +
3090 parm_table[*i].offset,
3091 ((char *)lp_ctx->sDefault) +
3092 parm_table[*i].offset))
3094 return &parm_table[(*i)++];
3100 return NULL;
3105 * Auto-load some home services.
3107 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3108 const char *str)
3110 return;
3115 * Unload unused services.
3118 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3119 struct smbsrv_connection *smb,
3120 bool (*snumused) (struct smbsrv_connection *, int))
3122 int i;
3123 for (i = 0; i < lp_ctx->iNumServices; i++) {
3124 if (lp_ctx->services[i] == NULL)
3125 continue;
3127 if (!snumused || !snumused(smb, i)) {
3128 talloc_free(lp_ctx->services[i]);
3129 lp_ctx->services[i] = NULL;
3135 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3137 struct parmlist_entry *data;
3139 if (lp_ctx->refuse_free) {
3140 /* someone is trying to free the
3141 global_loadparm_context.
3142 We can't allow that. */
3143 return -1;
3146 if (lp_ctx->globals->param_opt != NULL) {
3147 struct parmlist_entry *next;
3148 for (data = lp_ctx->globals->param_opt; data; data=next) {
3149 next = data->next;
3150 if (data->priority & FLAG_CMDLINE) continue;
3151 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3152 talloc_free(data);
3156 return 0;
3160 * Initialise the global parameter structure.
3162 * Note that most callers should use loadparm_init_global() instead
3164 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3166 int i;
3167 char *myname;
3168 struct loadparm_context *lp_ctx;
3169 struct parmlist_entry *parm;
3170 char *logfile;
3172 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3173 if (lp_ctx == NULL)
3174 return NULL;
3176 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3177 lp_ctx->bInGlobalSection = true;
3178 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3179 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3181 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3182 lp_ctx->sDefault->bAvailable = true;
3183 lp_ctx->sDefault->bBrowseable = true;
3184 lp_ctx->sDefault->bRead_only = true;
3185 lp_ctx->sDefault->bMap_archive = true;
3186 lp_ctx->sDefault->iStrictLocking = true;
3187 lp_ctx->sDefault->bOpLocks = true;
3188 lp_ctx->sDefault->iCreate_mask = 0744;
3189 lp_ctx->sDefault->iCreate_force_mode = 0000;
3190 lp_ctx->sDefault->iDir_mask = 0755;
3191 lp_ctx->sDefault->iDir_force_mode = 0000;
3193 DEBUG(3, ("Initialising global parameters\n"));
3195 for (i = 0; parm_table[i].label; i++) {
3196 if ((parm_table[i].type == P_STRING ||
3197 parm_table[i].type == P_USTRING) &&
3198 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3199 char **r;
3200 if (parm_table[i].p_class == P_LOCAL) {
3201 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3202 } else {
3203 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3205 *r = talloc_strdup(lp_ctx, "");
3209 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3210 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3211 talloc_free(logfile);
3213 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3215 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3217 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3219 lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
3221 /* options that can be set on the command line must be initialised via
3222 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3223 #ifdef TCP_NODELAY
3224 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3225 #endif
3226 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3227 myname = get_myname(lp_ctx);
3228 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3229 talloc_free(myname);
3230 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3232 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3234 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3235 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3237 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3238 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
3239 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3240 /* the winbind method for domain controllers is for both RODC
3241 auth forwarding and for trusted domains */
3242 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3243 lpcfg_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
3244 lpcfg_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
3245 lpcfg_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
3246 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3248 /* This hive should be dynamically generated by Samba using
3249 data from the sam, but for the moment leave it in a tdb to
3250 keep regedt32 from popping up an annoying dialog. */
3251 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3253 /* using UTF8 by default allows us to support all chars */
3254 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3256 /* Use codepage 850 as a default for the dos character set */
3257 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3260 * Allow the default PASSWD_CHAT to be overridden in local.h.
3262 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3264 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3265 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3266 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3268 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3269 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3270 "Samba %s", SAMBA_VERSION_STRING);
3272 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3274 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3275 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3276 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3277 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3278 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3279 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3280 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3281 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3282 lpcfg_do_global_parameter(lp_ctx, "security", "USER");
3283 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3284 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3285 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3286 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3287 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3288 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3290 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3291 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3292 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3293 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3294 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3295 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3296 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3297 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3299 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3301 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3302 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3304 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3305 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3307 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3308 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3309 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3310 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3311 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3312 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3313 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3315 lpcfg_do_global_parameter(lp_ctx, "client signing", "Yes");
3316 lpcfg_do_global_parameter(lp_ctx, "server signing", "auto");
3318 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3320 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3321 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3322 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3323 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3324 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3325 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3326 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3328 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3330 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3331 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3333 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3334 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3335 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3336 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3337 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3339 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3340 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3341 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3342 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3343 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3345 for (i = 0; parm_table[i].label; i++) {
3346 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3347 lp_ctx->flags[i] |= FLAG_DEFAULT;
3351 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3352 if (!(parm->priority & FLAG_CMDLINE)) {
3353 parm->priority |= FLAG_DEFAULT;
3357 return lp_ctx;
3361 * Initialise the global parameter structure.
3363 struct loadparm_context *loadparm_init_global(bool load_default)
3365 if (global_loadparm_context == NULL) {
3366 global_loadparm_context = loadparm_init(NULL);
3368 if (global_loadparm_context == NULL) {
3369 return NULL;
3371 global_loadparm_context->global = true;
3372 if (load_default && !global_loadparm_context->loaded) {
3373 lpcfg_load_default(global_loadparm_context);
3375 global_loadparm_context->refuse_free = true;
3376 return global_loadparm_context;
3380 * Initialise the global parameter structure.
3382 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3383 const struct loadparm_s3_context *s3_fns)
3385 struct loadparm_context *loadparm_context = loadparm_init(mem_ctx);
3386 if (!loadparm_context) {
3387 return NULL;
3389 loadparm_context->s3_fns = s3_fns;
3390 return loadparm_context;
3393 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3395 return lp_ctx->szConfigFile;
3398 const char *lp_default_path(void)
3400 if (getenv("SMB_CONF_PATH"))
3401 return getenv("SMB_CONF_PATH");
3402 else
3403 return dyn_CONFIGFILE;
3407 * Update the internal state of a loadparm context after settings
3408 * have changed.
3410 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3412 struct debug_settings settings;
3413 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3415 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3416 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3419 if (!lp_ctx->global) {
3420 return true;
3423 panic_action = lp_ctx->globals->panic_action;
3425 reload_charcnv(lp_ctx);
3427 ZERO_STRUCT(settings);
3428 /* Add any more debug-related smb.conf parameters created in
3429 * future here */
3430 settings.timestamp_logs = true;
3431 debug_set_settings(&settings);
3433 /* FIXME: This is a bit of a hack, but we can't use a global, since
3434 * not everything that uses lp also uses the socket library */
3435 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3436 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3437 } else {
3438 unsetenv("SOCKET_TESTNONBLOCK");
3441 return true;
3444 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3446 const char *path;
3448 path = lp_default_path();
3450 if (!file_exist(path)) {
3451 /* We allow the default smb.conf file to not exist,
3452 * basically the equivalent of an empty file. */
3453 return lpcfg_update(lp_ctx);
3456 return lpcfg_load(lp_ctx, path);
3460 * Load the services array from the services file.
3462 * Return True on success, False on failure.
3464 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3466 char *n2;
3467 bool bRetval;
3469 filename = talloc_strdup(lp_ctx, filename);
3471 lp_ctx->szConfigFile = filename;
3473 lp_ctx->bInGlobalSection = true;
3474 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3475 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3477 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3479 /* We get sections first, so have to start 'behind' to make up */
3480 lp_ctx->currentService = NULL;
3481 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3483 /* finish up the last section */
3484 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3485 if (bRetval)
3486 if (lp_ctx->currentService != NULL)
3487 bRetval = service_ok(lp_ctx->currentService);
3489 bRetval = bRetval && lpcfg_update(lp_ctx);
3491 /* we do this unconditionally, so that it happens even
3492 for a missing smb.conf */
3493 reload_charcnv(lp_ctx);
3495 if (bRetval == true) {
3496 /* set this up so that any child python tasks will
3497 find the right smb.conf */
3498 setenv("SMB_CONF_PATH", filename, 1);
3500 /* set the context used by the lp_*() function
3501 varients */
3502 global_loadparm_context = lp_ctx;
3503 lp_ctx->loaded = true;
3506 return bRetval;
3510 * Return the max number of services.
3513 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3515 return lp_ctx->iNumServices;
3519 * Display the contents of the services array in human-readable form.
3522 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3523 int maxtoprint)
3525 int iService;
3527 defaults_saved = !show_defaults;
3529 dump_globals(lp_ctx, f, show_defaults);
3531 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3533 for (iService = 0; iService < maxtoprint; iService++)
3534 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3538 * Display the contents of one service in human-readable form.
3540 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3542 if (service != NULL) {
3543 if (service->szService[0] == '\0')
3544 return;
3545 dump_a_service(service, sDefault, f, NULL);
3549 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3550 int snum)
3552 return lp_ctx->services[snum];
3555 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3556 const char *service_name)
3558 int iService;
3559 char *serviceName;
3561 if (lp_ctx->s3_fns) {
3562 return lp_ctx->s3_fns->get_service(service_name);
3565 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3566 if (lp_ctx->services[iService] &&
3567 lp_ctx->services[iService]->szService) {
3569 * The substitution here is used to support %U is
3570 * service names
3572 serviceName = standard_sub_basic(
3573 lp_ctx->services[iService],
3574 lp_ctx->services[iService]->szService);
3575 if (strequal(serviceName, service_name)) {
3576 talloc_free(serviceName);
3577 return lp_ctx->services[iService];
3579 talloc_free(serviceName);
3583 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3584 return NULL;
3587 const char *lpcfg_servicename(const struct loadparm_service *service)
3589 return lp_string((const char *)service->szService);
3593 * A useful volume label function.
3595 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3597 const char *ret;
3598 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3599 service->volume : sDefault->volume));
3600 if (!*ret)
3601 return lpcfg_servicename(service);
3602 return ret;
3606 * If we are PDC then prefer us as DMB
3608 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3610 const char *ret;
3611 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3612 service->szPrintername : sDefault->szPrintername));
3613 if (ret == NULL || (ret != NULL && *ret == '\0'))
3614 ret = lpcfg_servicename(service);
3616 return ret;
3621 * Return the max print jobs per queue.
3623 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3625 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3626 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3627 maxjobs = PRINT_MAX_JOBID - 1;
3629 return maxjobs;
3632 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3634 if (lp_ctx == NULL) {
3635 return get_iconv_handle();
3637 return lp_ctx->iconv_handle;
3640 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3642 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3643 if (!lp_ctx->global) {
3644 return;
3647 if (old_ic == NULL) {
3648 old_ic = global_iconv_handle;
3650 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3651 global_iconv_handle = lp_ctx->iconv_handle;
3654 void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
3655 struct smbcli_options *options)
3657 options->max_xmit = lpcfg_max_xmit(lp_ctx);
3658 options->max_mux = lpcfg_maxmux(lp_ctx);
3659 options->use_spnego = lpcfg_nt_status_support(lp_ctx) && lpcfg_use_spnego(lp_ctx);
3660 options->signing = lpcfg_client_signing(lp_ctx);
3661 options->request_timeout = SMB_REQUEST_TIMEOUT;
3662 options->ntstatus_support = lpcfg_nt_status_support(lp_ctx);
3663 options->max_protocol = lpcfg_cli_maxprotocol(lp_ctx);
3664 options->unicode = lpcfg_unicode(lp_ctx);
3665 options->use_oplocks = true;
3666 options->use_level2_oplocks = true;
3669 void lpcfg_smbcli_session_options(struct loadparm_context *lp_ctx,
3670 struct smbcli_session_options *options)
3672 options->lanman_auth = lpcfg_client_lanman_auth(lp_ctx);
3673 options->ntlmv2_auth = lpcfg_client_ntlmv2_auth(lp_ctx);
3674 options->plaintext_auth = lpcfg_client_plaintext_auth(lp_ctx);
3677 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3679 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3682 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3684 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3687 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3689 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3692 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3694 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3697 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3699 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3702 _PUBLIC_ struct dcerpc_server_info *lpcfg_dcerpc_server_info(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3704 struct dcerpc_server_info *ret = talloc_zero(mem_ctx, struct dcerpc_server_info);
3706 ret->domain_name = talloc_reference(mem_ctx, lpcfg_workgroup(lp_ctx));
3707 ret->version_major = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_major", 5);
3708 ret->version_minor = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_minor", 2);
3709 ret->version_build = lpcfg_parm_int(lp_ctx, NULL, "server_info", "version_build", 3790);
3711 return ret;
3714 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3716 struct gensec_settings *settings = talloc(mem_ctx, struct gensec_settings);
3717 if (settings == NULL)
3718 return NULL;
3719 SMB_ASSERT(lp_ctx != NULL);
3720 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3721 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3722 return settings;