lib/param: Merge Winbind parameters from source3 into lib/param
[Samba/gebeck_regimport.git] / lib / param / loadparm.c
blobf2ab0a719f781c2cc1156abc353550a5657f3067
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
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * Load parameters.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
37 * To add a parameter:
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
46 * Notes:
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
52 * careful!
56 #include "includes.h"
57 #include "version.h"
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
69 #include "source4/dns_server/dns_update.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #define LOADPARM_EXTRA_GLOBALS \
77 struct parmlist_entry *param_opt; \
78 char *szRealm; \
79 char *szIdmapUID; \
80 char *szIdmapGID; \
81 int winbindMaxDomainConnections; \
82 char *tls_keyfile; \
83 char *tls_certfile; \
84 char *tls_cafile; \
85 char *tls_crlfile; \
86 char *tls_dhpfile; \
87 char *loglevel; \
88 char *panic_action; \
89 int bPreferredMaster;
91 #include "lib/param/param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
95 /* we don't need a special handler for "dos charset" and "unix charset" */
96 #define handle_dos_charset NULL
97 #define handle_charset NULL
99 /* these are parameter handlers which are not needed in the
100 * non-source3 code
102 #define handle_netbios_aliases NULL
103 #define handle_debug_list NULL
104 #define handle_printing NULL
105 #define handle_ldap_debug_level NULL
106 #define handle_idmap_backend NULL
107 #define handle_idmap_uid NULL
108 #define handle_idmap_gid NULL
110 #ifndef N_
111 #define N_(x) x
112 #endif
114 /* prototypes for the special type handlers */
115 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
116 const char *pszParmValue, char **ptr);
117 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
118 const char *pszParmValue, char **ptr);
119 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
120 const char *pszParmValue, char **ptr);
121 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
122 const char *pszParmValue, char **ptr);
123 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
124 const char *pszParmValue, char **ptr);
126 #include "lib/param/param_table.c"
128 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
129 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
131 static struct parm_struct parm_table[] = {
133 .label = "server role",
134 .type = P_ENUM,
135 .p_class = P_GLOBAL,
136 .offset = GLOBAL_VAR(server_role),
137 .special = NULL,
138 .enum_list = enum_server_role
141 .label = "domain logons",
142 .type = P_ENUM,
143 .p_class = P_GLOBAL,
144 .offset = GLOBAL_VAR(bDomainLogons),
145 .special = NULL,
146 .enum_list = enum_bool_auto
149 .label = "domain master",
150 .type = P_ENUM,
151 .p_class = P_GLOBAL,
152 .offset = GLOBAL_VAR(domain_master),
153 .special = NULL,
154 .enum_list = enum_bool_auto
157 .label = "dos charset",
158 .type = P_STRING,
159 .p_class = P_GLOBAL,
160 .offset = GLOBAL_VAR(dos_charset),
161 .special = NULL,
162 .enum_list = NULL
165 .label = "unix charset",
166 .type = P_STRING,
167 .p_class = P_GLOBAL,
168 .offset = GLOBAL_VAR(unix_charset),
169 .special = NULL,
170 .enum_list = NULL
173 .label = "comment",
174 .type = P_STRING,
175 .p_class = P_LOCAL,
176 .offset = LOCAL_VAR(comment),
177 .special = NULL,
178 .enum_list = NULL,
179 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
182 .label = "path",
183 .type = P_STRING,
184 .p_class = P_LOCAL,
185 .offset = LOCAL_VAR(szPath),
186 .special = NULL,
187 .enum_list = NULL,
188 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
191 .label = "directory",
192 .type = P_STRING,
193 .p_class = P_LOCAL,
194 .offset = LOCAL_VAR(szPath),
195 .special = NULL,
196 .enum_list = NULL,
197 .flags = FLAG_HIDE,
200 .label = "workgroup",
201 .type = P_USTRING,
202 .p_class = P_GLOBAL,
203 .offset = GLOBAL_VAR(szWorkgroup),
204 .special = NULL,
205 .enum_list = NULL,
206 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
209 .label = "realm",
210 .type = P_STRING,
211 .p_class = P_GLOBAL,
212 .offset = GLOBAL_VAR(szRealm),
213 .special = handle_realm,
214 .enum_list = NULL,
215 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
218 .label = "netbios name",
219 .type = P_USTRING,
220 .p_class = P_GLOBAL,
221 .offset = GLOBAL_VAR(szNetbiosName),
222 .special = NULL,
223 .enum_list = NULL,
224 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
227 .label = "netbios aliases",
228 .type = P_LIST,
229 .p_class = P_GLOBAL,
230 .offset = GLOBAL_VAR(szNetbiosAliases),
231 .special = NULL,
232 .enum_list = NULL
235 .label = "netbios scope",
236 .type = P_USTRING,
237 .p_class = P_GLOBAL,
238 .offset = GLOBAL_VAR(szNetbiosScope),
239 .special = NULL,
240 .enum_list = NULL,
241 .flags = FLAG_ADVANCED,
244 .label = "server string",
245 .type = P_STRING,
246 .p_class = P_GLOBAL,
247 .offset = GLOBAL_VAR(szServerString),
248 .special = NULL,
249 .enum_list = NULL,
250 .flags = FLAG_BASIC | FLAG_ADVANCED,
253 .label = "interfaces",
254 .type = P_LIST,
255 .p_class = P_GLOBAL,
256 .offset = GLOBAL_VAR(szInterfaces),
257 .special = NULL,
258 .enum_list = NULL,
259 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
262 .label = "bind interfaces only",
263 .type = P_BOOL,
264 .p_class = P_GLOBAL,
265 .offset = GLOBAL_VAR(bBindInterfacesOnly),
266 .special = NULL,
267 .enum_list = NULL,
268 .flags = FLAG_ADVANCED | FLAG_WIZARD,
271 .label = "passdb backend",
272 .type = P_STRING,
273 .p_class = P_GLOBAL,
274 .offset = GLOBAL_VAR(passdb_backend),
275 .special = NULL,
276 .enum_list = NULL
280 .label = "security",
281 .type = P_ENUM,
282 .p_class = P_GLOBAL,
283 .offset = GLOBAL_VAR(security),
284 .special = NULL,
285 .enum_list = enum_security
288 .label = "encrypt passwords",
289 .type = P_BOOL,
290 .p_class = P_GLOBAL,
291 .offset = GLOBAL_VAR(bEncryptPasswords),
292 .special = NULL,
293 .enum_list = NULL
296 .label = "null passwords",
297 .type = P_BOOL,
298 .p_class = P_GLOBAL,
299 .offset = GLOBAL_VAR(bNullPasswords),
300 .special = NULL,
301 .enum_list = NULL,
302 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
305 .label = "obey pam restrictions",
306 .type = P_BOOL,
307 .p_class = P_GLOBAL,
308 .offset = GLOBAL_VAR(bObeyPamRestrictions),
309 .special = NULL,
310 .enum_list = NULL,
311 .flags = FLAG_ADVANCED,
314 .label = "password server",
315 .type = P_STRING,
316 .p_class = P_GLOBAL,
317 .offset = GLOBAL_VAR(szPasswordServer),
318 .special = NULL,
319 .enum_list = NULL
322 .label = "private dir",
323 .type = P_STRING,
324 .p_class = P_GLOBAL,
325 .offset = GLOBAL_VAR(szPrivateDir),
326 .special = NULL,
327 .enum_list = NULL
330 .label = "passwd chat",
331 .type = P_STRING,
332 .p_class = P_GLOBAL,
333 .offset = GLOBAL_VAR(szPasswdChat),
334 .special = NULL,
335 .enum_list = NULL
338 .label = "password level",
339 .type = P_INTEGER,
340 .p_class = P_GLOBAL,
341 .offset = GLOBAL_VAR(pwordlevel),
342 .special = NULL,
343 .enum_list = NULL
346 .label = "lanman auth",
347 .type = P_BOOL,
348 .p_class = P_GLOBAL,
349 .offset = GLOBAL_VAR(bLanmanAuth),
350 .special = NULL,
351 .enum_list = NULL,
352 .flags = FLAG_ADVANCED,
355 .label = "ntlm auth",
356 .type = P_BOOL,
357 .p_class = P_GLOBAL,
358 .offset = GLOBAL_VAR(bNTLMAuth),
359 .special = NULL,
360 .enum_list = NULL,
361 .flags = FLAG_ADVANCED,
364 .label = "client NTLMv2 auth",
365 .type = P_BOOL,
366 .p_class = P_GLOBAL,
367 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
368 .special = NULL,
369 .enum_list = NULL,
370 .flags = FLAG_ADVANCED,
373 .label = "client lanman auth",
374 .type = P_BOOL,
375 .p_class = P_GLOBAL,
376 .offset = GLOBAL_VAR(bClientLanManAuth),
377 .special = NULL,
378 .enum_list = NULL,
379 .flags = FLAG_ADVANCED,
382 .label = "client plaintext auth",
383 .type = P_BOOL,
384 .p_class = P_GLOBAL,
385 .offset = GLOBAL_VAR(bClientPlaintextAuth),
386 .special = NULL,
387 .enum_list = NULL,
388 .flags = FLAG_ADVANCED,
391 .label = "client use spnego principal",
392 .type = P_BOOL,
393 .p_class = P_GLOBAL,
394 .offset = GLOBAL_VAR(client_use_spnego_principal),
395 .special = NULL,
396 .enum_list = NULL
400 .label = "read only",
401 .type = P_BOOL,
402 .p_class = P_LOCAL,
403 .offset = LOCAL_VAR(bRead_only),
404 .special = NULL,
405 .enum_list = NULL
409 .label = "create mask",
410 .type = P_OCTAL,
411 .p_class = P_LOCAL,
412 .offset = LOCAL_VAR(iCreate_mask),
413 .special = NULL,
414 .enum_list = NULL
417 .label = "force create mode",
418 .type = P_OCTAL,
419 .p_class = P_LOCAL,
420 .offset = LOCAL_VAR(iCreate_force_mode),
421 .special = NULL,
422 .enum_list = NULL
425 .label = "directory mask",
426 .type = P_OCTAL,
427 .p_class = P_LOCAL,
428 .offset = LOCAL_VAR(iDir_mask),
429 .special = NULL,
430 .enum_list = NULL
433 .label = "force directory mode",
434 .type = P_OCTAL,
435 .p_class = P_LOCAL,
436 .offset = LOCAL_VAR(iDir_force_mode),
437 .special = NULL,
438 .enum_list = NULL
442 .label = "hosts allow",
443 .type = P_LIST,
444 .p_class = P_LOCAL,
445 .offset = LOCAL_VAR(szHostsallow),
446 .special = NULL,
447 .enum_list = NULL
450 .label = "hosts deny",
451 .type = P_LIST,
452 .p_class = P_LOCAL,
453 .offset = LOCAL_VAR(szHostsdeny),
454 .special = NULL,
455 .enum_list = NULL
459 .label = "log level",
460 .type = P_STRING,
461 .p_class = P_GLOBAL,
462 .offset = GLOBAL_VAR(loglevel),
463 .special = handle_debuglevel,
464 .enum_list = NULL
467 .label = "debuglevel",
468 .type = P_STRING,
469 .p_class = P_GLOBAL,
470 .offset = GLOBAL_VAR(loglevel),
471 .special = handle_debuglevel,
472 .enum_list = NULL
475 .label = "log file",
476 .type = P_STRING,
477 .p_class = P_GLOBAL,
478 .offset = GLOBAL_VAR(logfile),
479 .special = handle_logfile,
480 .enum_list = NULL,
481 .flags = FLAG_ADVANCED,
485 .label = "smb ports",
486 .type = P_LIST,
487 .p_class = P_GLOBAL,
488 .offset = GLOBAL_VAR(smb_ports),
489 .special = NULL,
490 .enum_list = NULL
493 .label = "nbt port",
494 .type = P_INTEGER,
495 .p_class = P_GLOBAL,
496 .offset = GLOBAL_VAR(nbt_port),
497 .special = NULL,
498 .enum_list = NULL
501 .label = "dgram port",
502 .type = P_INTEGER,
503 .p_class = P_GLOBAL,
504 .offset = GLOBAL_VAR(dgram_port),
505 .special = NULL,
506 .enum_list = NULL
509 .label = "cldap port",
510 .type = P_INTEGER,
511 .p_class = P_GLOBAL,
512 .offset = GLOBAL_VAR(cldap_port),
513 .special = NULL,
514 .enum_list = NULL
517 .label = "krb5 port",
518 .type = P_INTEGER,
519 .p_class = P_GLOBAL,
520 .offset = GLOBAL_VAR(krb5_port),
521 .special = NULL,
522 .enum_list = NULL
525 .label = "kpasswd port",
526 .type = P_INTEGER,
527 .p_class = P_GLOBAL,
528 .offset = GLOBAL_VAR(kpasswd_port),
529 .special = NULL,
530 .enum_list = NULL
533 .label = "web port",
534 .type = P_INTEGER,
535 .p_class = P_GLOBAL,
536 .offset = GLOBAL_VAR(web_port),
537 .special = NULL,
538 .enum_list = NULL
541 .label = "large readwrite",
542 .type = P_BOOL,
543 .p_class = P_GLOBAL,
544 .offset = GLOBAL_VAR(bLargeReadwrite),
545 .special = NULL,
546 .enum_list = NULL,
547 .flags = FLAG_ADVANCED,
550 .label = "server max protocol",
551 .type = P_ENUM,
552 .p_class = P_GLOBAL,
553 .offset = GLOBAL_VAR(srv_maxprotocol),
554 .special = NULL,
555 .enum_list = enum_protocol,
556 .flags = FLAG_ADVANCED,
559 .label = "max protocol",
560 .type = P_ENUM,
561 .p_class = P_GLOBAL,
562 .offset = GLOBAL_VAR(srv_maxprotocol),
563 .special = NULL,
564 .enum_list = enum_protocol,
565 .flags = FLAG_ADVANCED,
568 .label = "protocol",
569 .type = P_ENUM,
570 .p_class = P_GLOBAL,
571 .offset = GLOBAL_VAR(srv_maxprotocol),
572 .special = NULL,
573 .enum_list = enum_protocol,
574 .flags = FLAG_ADVANCED,
577 .label = "server min protocol",
578 .type = P_ENUM,
579 .p_class = P_GLOBAL,
580 .offset = GLOBAL_VAR(srv_minprotocol),
581 .special = NULL,
582 .enum_list = enum_protocol,
583 .flags = FLAG_ADVANCED,
586 .label = "min protocol",
587 .type = P_ENUM,
588 .p_class = P_GLOBAL,
589 .offset = GLOBAL_VAR(srv_minprotocol),
590 .special = NULL,
591 .enum_list = enum_protocol,
592 .flags = FLAG_ADVANCED,
595 .label = "client max protocol",
596 .type = P_ENUM,
597 .p_class = P_GLOBAL,
598 .offset = GLOBAL_VAR(cli_maxprotocol),
599 .special = NULL,
600 .enum_list = enum_protocol
603 .label = "client min protocol",
604 .type = P_ENUM,
605 .p_class = P_GLOBAL,
606 .offset = GLOBAL_VAR(cli_minprotocol),
607 .special = NULL,
608 .enum_list = enum_protocol
611 .label = "unicode",
612 .type = P_BOOL,
613 .p_class = P_GLOBAL,
614 .offset = GLOBAL_VAR(bUnicode),
615 .special = NULL,
616 .enum_list = NULL
619 .label = "read raw",
620 .type = P_BOOL,
621 .p_class = P_GLOBAL,
622 .offset = GLOBAL_VAR(bReadRaw),
623 .special = NULL,
624 .enum_list = NULL
627 .label = "write raw",
628 .type = P_BOOL,
629 .p_class = P_GLOBAL,
630 .offset = GLOBAL_VAR(bWriteRaw),
631 .special = NULL,
632 .enum_list = NULL
635 .label = "disable netbios",
636 .type = P_BOOL,
637 .p_class = P_GLOBAL,
638 .offset = GLOBAL_VAR(bDisableNetbios),
639 .special = NULL,
640 .enum_list = NULL
644 .label = "nt status support",
645 .type = P_BOOL,
646 .p_class = P_GLOBAL,
647 .offset = GLOBAL_VAR(bNTStatusSupport),
648 .special = NULL,
649 .enum_list = NULL
653 .label = "max mux",
654 .type = P_INTEGER,
655 .p_class = P_GLOBAL,
656 .offset = GLOBAL_VAR(max_mux),
657 .special = NULL,
658 .enum_list = NULL,
659 .flags = FLAG_ADVANCED,
662 .label = "max xmit",
663 .type = P_BYTES,
664 .p_class = P_GLOBAL,
665 .offset = GLOBAL_VAR(max_xmit),
666 .special = NULL,
667 .enum_list = NULL,
668 .flags = FLAG_ADVANCED,
672 .label = "name resolve order",
673 .type = P_LIST,
674 .p_class = P_GLOBAL,
675 .offset = GLOBAL_VAR(szNameResolveOrder),
676 .special = NULL,
677 .enum_list = NULL
680 .label = "max wins ttl",
681 .type = P_INTEGER,
682 .p_class = P_GLOBAL,
683 .offset = GLOBAL_VAR(max_wins_ttl),
684 .special = NULL,
685 .enum_list = NULL,
686 .flags = FLAG_ADVANCED,
689 .label = "min wins ttl",
690 .type = P_INTEGER,
691 .p_class = P_GLOBAL,
692 .offset = GLOBAL_VAR(min_wins_ttl),
693 .special = NULL,
694 .enum_list = NULL,
695 .flags = FLAG_ADVANCED,
698 .label = "time server",
699 .type = P_BOOL,
700 .p_class = P_GLOBAL,
701 .offset = GLOBAL_VAR(bTimeServer),
702 .special = NULL,
703 .enum_list = NULL,
704 .flags = FLAG_ADVANCED,
707 .label = "unix extensions",
708 .type = P_BOOL,
709 .p_class = P_GLOBAL,
710 .offset = GLOBAL_VAR(bUnixExtensions),
711 .special = NULL,
712 .enum_list = NULL,
713 .flags = FLAG_ADVANCED,
716 .label = "use spnego",
717 .type = P_BOOL,
718 .p_class = P_GLOBAL,
719 .offset = GLOBAL_VAR(bUseSpnego),
720 .special = NULL,
721 .enum_list = NULL
724 .label = "server signing",
725 .type = P_ENUM,
726 .p_class = P_GLOBAL,
727 .offset = GLOBAL_VAR(server_signing),
728 .special = NULL,
729 .enum_list = enum_smb_signing_vals,
730 .flags = FLAG_ADVANCED,
733 .label = "client signing",
734 .type = P_ENUM,
735 .p_class = P_GLOBAL,
736 .offset = GLOBAL_VAR(client_signing),
737 .special = NULL,
738 .enum_list = enum_smb_signing_vals
741 .label = "rpc big endian",
742 .type = P_BOOL,
743 .p_class = P_GLOBAL,
744 .offset = GLOBAL_VAR(bRpcBigEndian),
745 .special = NULL,
746 .enum_list = NULL
750 .label = "max connections",
751 .type = P_INTEGER,
752 .p_class = P_LOCAL,
753 .offset = LOCAL_VAR(iMaxConnections),
754 .special = NULL,
755 .enum_list = NULL,
756 .flags = FLAG_ADVANCED | FLAG_SHARE,
759 .label = "paranoid server security",
760 .type = P_BOOL,
761 .p_class = P_GLOBAL,
762 .offset = GLOBAL_VAR(paranoid_server_security),
763 .special = NULL,
764 .enum_list = NULL
767 .label = "socket options",
768 .type = P_STRING,
769 .p_class = P_GLOBAL,
770 .offset = GLOBAL_VAR(socket_options),
771 .special = NULL,
772 .enum_list = NULL
776 .label = "strict sync",
777 .type = P_BOOL,
778 .p_class = P_LOCAL,
779 .offset = LOCAL_VAR(bStrictSync),
780 .special = NULL,
781 .enum_list = NULL
784 .label = "use mmap",
785 .type = P_BOOL,
786 .p_class = P_GLOBAL,
787 .offset = GLOBAL_VAR(bUseMmap),
788 .special = NULL,
789 .enum_list = NULL,
790 .flags = FLAG_ADVANCED,
794 .label = "max print jobs",
795 .type = P_INTEGER,
796 .p_class = P_LOCAL,
797 .offset = LOCAL_VAR(iMaxPrintJobs),
798 .special = NULL,
799 .enum_list = NULL
802 .label = "printable",
803 .type = P_BOOL,
804 .p_class = P_LOCAL,
805 .offset = LOCAL_VAR(bPrint_ok),
806 .special = NULL,
807 .enum_list = NULL
810 .label = "print ok",
811 .type = P_BOOL,
812 .p_class = P_LOCAL,
813 .offset = LOCAL_VAR(bPrint_ok),
814 .special = NULL,
815 .enum_list = NULL
819 .label = "printer name",
820 .type = P_STRING,
821 .p_class = P_LOCAL,
822 .offset = LOCAL_VAR(szPrintername),
823 .special = NULL,
824 .enum_list = NULL,
825 .flags = FLAG_ADVANCED | FLAG_PRINT,
828 .label = "printer",
829 .type = P_STRING,
830 .p_class = P_LOCAL,
831 .offset = LOCAL_VAR(szPrintername),
832 .special = NULL,
833 .enum_list = NULL,
834 .flags = FLAG_HIDE,
838 .label = "map system",
839 .type = P_BOOL,
840 .p_class = P_LOCAL,
841 .offset = LOCAL_VAR(bMap_system),
842 .special = NULL,
843 .enum_list = NULL
846 .label = "map hidden",
847 .type = P_BOOL,
848 .p_class = P_LOCAL,
849 .offset = LOCAL_VAR(bMap_hidden),
850 .special = NULL,
851 .enum_list = NULL
854 .label = "map archive",
855 .type = P_BOOL,
856 .p_class = P_LOCAL,
857 .offset = LOCAL_VAR(bMap_archive),
858 .special = NULL,
859 .enum_list = NULL
863 .label = "preferred master",
864 .type = P_ENUM,
865 .p_class = P_GLOBAL,
866 .offset = GLOBAL_VAR(bPreferredMaster),
867 .special = NULL,
868 .enum_list = enum_bool_auto,
869 .flags = FLAG_BASIC | FLAG_ADVANCED,
872 .label = "prefered master",
873 .type = P_ENUM,
874 .p_class = P_GLOBAL,
875 .offset = GLOBAL_VAR(bPreferredMaster),
876 .special = NULL,
877 .enum_list = enum_bool_auto,
878 .flags = FLAG_HIDE,
881 .label = "local master",
882 .type = P_BOOL,
883 .p_class = P_GLOBAL,
884 .offset = GLOBAL_VAR(bLocalMaster),
885 .special = NULL,
886 .enum_list = NULL
889 .label = "browseable",
890 .type = P_BOOL,
891 .p_class = P_LOCAL,
892 .offset = LOCAL_VAR(bBrowseable),
893 .special = NULL,
894 .enum_list = NULL,
895 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
898 .label = "browsable",
899 .type = P_BOOL,
900 .p_class = P_LOCAL,
901 .offset = LOCAL_VAR(bBrowseable),
902 .special = NULL,
903 .enum_list = NULL
907 .label = "dns proxy",
908 .type = P_BOOL,
909 .p_class = P_GLOBAL,
910 .offset = GLOBAL_VAR(bWINSdnsProxy),
911 .special = NULL,
912 .enum_list = NULL
915 .label = "wins server",
916 .type = P_LIST,
917 .p_class = P_GLOBAL,
918 .offset = GLOBAL_VAR(szWINSservers),
919 .special = NULL,
920 .enum_list = NULL,
921 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
924 .label = "wins support",
925 .type = P_BOOL,
926 .p_class = P_GLOBAL,
927 .offset = GLOBAL_VAR(bWINSsupport),
928 .special = NULL,
929 .enum_list = NULL,
930 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
933 .label = "wins hook",
934 .type = P_STRING,
935 .p_class = P_GLOBAL,
936 .offset = GLOBAL_VAR(szWINSHook),
937 .special = NULL,
938 .enum_list = NULL,
939 .flags = FLAG_ADVANCED,
943 .label = "csc policy",
944 .type = P_ENUM,
945 .p_class = P_LOCAL,
946 .offset = LOCAL_VAR(iCSCPolicy),
947 .special = NULL,
948 .enum_list = enum_csc_policy,
949 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
953 .label = "strict locking",
954 .type = P_BOOL,
955 .p_class = P_LOCAL,
956 .offset = LOCAL_VAR(iStrictLocking),
957 .special = NULL,
958 .enum_list = NULL
961 .label = "oplocks",
962 .type = P_BOOL,
963 .p_class = P_LOCAL,
964 .offset = LOCAL_VAR(bOpLocks),
965 .special = NULL,
966 .enum_list = NULL
970 .label = "preload",
971 .type = P_STRING,
972 .p_class = P_GLOBAL,
973 .offset = GLOBAL_VAR(szAutoServices),
974 .special = NULL,
975 .enum_list = NULL,
976 .flags = FLAG_ADVANCED,
979 .label = "auto services",
980 .type = P_STRING,
981 .p_class = P_GLOBAL,
982 .offset = GLOBAL_VAR(szAutoServices),
983 .special = NULL,
984 .enum_list = NULL,
985 .flags = FLAG_ADVANCED,
988 .label = "lock directory",
989 .type = P_STRING,
990 .p_class = P_GLOBAL,
991 .offset = GLOBAL_VAR(szLockDir),
992 .special = NULL,
993 .enum_list = NULL,
994 .flags = FLAG_ADVANCED,
997 .label = "lock dir",
998 .type = P_STRING,
999 .p_class = P_GLOBAL,
1000 .offset = GLOBAL_VAR(szLockDir),
1001 .special = NULL,
1002 .enum_list = NULL,
1003 .flags = FLAG_HIDE,
1006 .label = "state directory",
1007 .type = P_STRING,
1008 .p_class = P_GLOBAL,
1009 .offset = GLOBAL_VAR(szStateDir),
1010 .special = NULL,
1011 .enum_list = NULL,
1012 .flags = FLAG_ADVANCED,
1015 .label = "cache directory",
1016 .type = P_STRING,
1017 .p_class = P_GLOBAL,
1018 .offset = GLOBAL_VAR(szCacheDir),
1019 .special = NULL,
1020 .enum_list = NULL,
1021 .flags = FLAG_ADVANCED,
1024 .label = "pid directory",
1025 .type = P_STRING,
1026 .p_class = P_GLOBAL,
1027 .offset = GLOBAL_VAR(szPidDir),
1028 .special = NULL,
1029 .enum_list = NULL
1033 .label = "socket address",
1034 .type = P_STRING,
1035 .p_class = P_GLOBAL,
1036 .offset = GLOBAL_VAR(szSocketAddress),
1037 .special = NULL,
1038 .enum_list = NULL
1041 .label = "copy",
1042 .type = P_STRING,
1043 .p_class = P_LOCAL,
1044 .offset = LOCAL_VAR(szCopy),
1045 .special = handle_copy,
1046 .enum_list = NULL,
1047 .flags = FLAG_HIDE,
1050 .label = "include",
1051 .type = P_STRING,
1052 .p_class = P_LOCAL,
1053 .offset = LOCAL_VAR(szInclude),
1054 .special = handle_include,
1055 .enum_list = NULL
1059 .label = "available",
1060 .type = P_BOOL,
1061 .p_class = P_LOCAL,
1062 .offset = LOCAL_VAR(bAvailable),
1063 .special = NULL,
1064 .enum_list = NULL
1067 .label = "volume",
1068 .type = P_STRING,
1069 .p_class = P_LOCAL,
1070 .offset = LOCAL_VAR(volume),
1071 .special = NULL,
1072 .enum_list = NULL,
1073 .flags = FLAG_ADVANCED | FLAG_SHARE,
1076 .label = "fstype",
1077 .type = P_STRING,
1078 .p_class = P_LOCAL,
1079 .offset = LOCAL_VAR(fstype),
1080 .special = NULL,
1081 .enum_list = NULL
1085 .label = "panic action",
1086 .type = P_STRING,
1087 .p_class = P_GLOBAL,
1088 .offset = GLOBAL_VAR(panic_action),
1089 .special = NULL,
1090 .enum_list = NULL
1094 .label = "msdfs root",
1095 .type = P_BOOL,
1096 .p_class = P_LOCAL,
1097 .offset = LOCAL_VAR(bMSDfsRoot),
1098 .special = NULL,
1099 .enum_list = NULL
1102 .label = "host msdfs",
1103 .type = P_BOOL,
1104 .p_class = P_GLOBAL,
1105 .offset = GLOBAL_VAR(bHostMSDfs),
1106 .special = NULL,
1107 .enum_list = NULL,
1108 .flags = FLAG_ADVANCED,
1111 .label = "ntp signd socket directory",
1112 .type = P_STRING,
1113 .p_class = P_GLOBAL,
1114 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1115 .special = NULL,
1116 .enum_list = NULL,
1117 .flags = FLAG_ADVANCED,
1120 {N_("Winbind options"), P_SEP, P_SEPARATOR},
1123 .label = "passdb expand explicit",
1124 .type = P_BOOL,
1125 .p_class = P_GLOBAL,
1126 .offset = GLOBAL_VAR(bPassdbExpandExplicit),
1127 .special = NULL,
1128 .enum_list = NULL,
1129 .flags = FLAG_ADVANCED,
1132 .label = "idmap backend",
1133 .type = P_STRING,
1134 .p_class = P_GLOBAL,
1135 .offset = GLOBAL_VAR(szIdmapBackend),
1136 .special = handle_idmap_backend,
1137 .enum_list = NULL,
1138 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1141 .label = "idmap cache time",
1142 .type = P_INTEGER,
1143 .p_class = P_GLOBAL,
1144 .offset = GLOBAL_VAR(iIdmapCacheTime),
1145 .special = NULL,
1146 .enum_list = NULL,
1147 .flags = FLAG_ADVANCED,
1150 .label = "idmap negative cache time",
1151 .type = P_INTEGER,
1152 .p_class = P_GLOBAL,
1153 .offset = GLOBAL_VAR(iIdmapNegativeCacheTime),
1154 .special = NULL,
1155 .enum_list = NULL,
1156 .flags = FLAG_ADVANCED,
1159 .label = "idmap uid",
1160 .type = P_STRING,
1161 .p_class = P_GLOBAL,
1162 .offset = GLOBAL_VAR(szIdmapUID),
1163 .special = handle_idmap_uid,
1164 .enum_list = NULL,
1165 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1168 .label = "winbind uid",
1169 .type = P_STRING,
1170 .p_class = P_GLOBAL,
1171 .offset = GLOBAL_VAR(szIdmapUID),
1172 .special = handle_idmap_uid,
1173 .enum_list = NULL,
1174 .flags = FLAG_HIDE,
1177 .label = "idmap gid",
1178 .type = P_STRING,
1179 .p_class = P_GLOBAL,
1180 .offset = GLOBAL_VAR(szIdmapGID),
1181 .special = handle_idmap_gid,
1182 .enum_list = NULL,
1183 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
1186 .label = "winbind gid",
1187 .type = P_STRING,
1188 .p_class = P_GLOBAL,
1189 .offset = GLOBAL_VAR(szIdmapGID),
1190 .special = handle_idmap_gid,
1191 .enum_list = NULL,
1192 .flags = FLAG_HIDE,
1195 .label = "template homedir",
1196 .type = P_STRING,
1197 .p_class = P_GLOBAL,
1198 .offset = GLOBAL_VAR(szTemplateHomedir),
1199 .special = NULL,
1200 .enum_list = NULL,
1201 .flags = FLAG_ADVANCED,
1204 .label = "template shell",
1205 .type = P_STRING,
1206 .p_class = P_GLOBAL,
1207 .offset = GLOBAL_VAR(szTemplateShell),
1208 .special = NULL,
1209 .enum_list = NULL,
1210 .flags = FLAG_ADVANCED,
1213 .label = "winbind separator",
1214 .type = P_STRING,
1215 .p_class = P_GLOBAL,
1216 .offset = GLOBAL_VAR(szWinbindSeparator),
1217 .special = NULL,
1218 .enum_list = NULL,
1219 .flags = FLAG_ADVANCED,
1222 .label = "winbind cache time",
1223 .type = P_INTEGER,
1224 .p_class = P_GLOBAL,
1225 .offset = GLOBAL_VAR(winbind_cache_time),
1226 .special = NULL,
1227 .enum_list = NULL,
1228 .flags = FLAG_ADVANCED,
1231 .label = "winbind reconnect delay",
1232 .type = P_INTEGER,
1233 .p_class = P_GLOBAL,
1234 .offset = GLOBAL_VAR(winbind_reconnect_delay),
1235 .special = NULL,
1236 .enum_list = NULL,
1237 .flags = FLAG_ADVANCED,
1240 .label = "winbind max clients",
1241 .type = P_INTEGER,
1242 .p_class = P_GLOBAL,
1243 .offset = GLOBAL_VAR(winbind_max_clients),
1244 .special = NULL,
1245 .enum_list = NULL,
1246 .flags = FLAG_ADVANCED,
1249 .label = "winbind enum users",
1250 .type = P_BOOL,
1251 .p_class = P_GLOBAL,
1252 .offset = GLOBAL_VAR(bWinbindEnumUsers),
1253 .special = NULL,
1254 .enum_list = NULL,
1255 .flags = FLAG_ADVANCED,
1258 .label = "winbind enum groups",
1259 .type = P_BOOL,
1260 .p_class = P_GLOBAL,
1261 .offset = GLOBAL_VAR(bWinbindEnumGroups),
1262 .special = NULL,
1263 .enum_list = NULL,
1264 .flags = FLAG_ADVANCED,
1267 .label = "winbind use default domain",
1268 .type = P_BOOL,
1269 .p_class = P_GLOBAL,
1270 .offset = GLOBAL_VAR(bWinbindUseDefaultDomain),
1271 .special = NULL,
1272 .enum_list = NULL,
1273 .flags = FLAG_ADVANCED,
1276 .label = "winbind trusted domains only",
1277 .type = P_BOOL,
1278 .p_class = P_GLOBAL,
1279 .offset = GLOBAL_VAR(bWinbindTrustedDomainsOnly),
1280 .special = NULL,
1281 .enum_list = NULL,
1282 .flags = FLAG_ADVANCED,
1285 .label = "winbind nested groups",
1286 .type = P_BOOL,
1287 .p_class = P_GLOBAL,
1288 .offset = GLOBAL_VAR(bWinbindNestedGroups),
1289 .special = NULL,
1290 .enum_list = NULL,
1291 .flags = FLAG_ADVANCED,
1294 .label = "winbind expand groups",
1295 .type = P_INTEGER,
1296 .p_class = P_GLOBAL,
1297 .offset = GLOBAL_VAR(winbind_expand_groups),
1298 .special = NULL,
1299 .enum_list = NULL,
1300 .flags = FLAG_ADVANCED,
1303 .label = "winbind nss info",
1304 .type = P_LIST,
1305 .p_class = P_GLOBAL,
1306 .offset = GLOBAL_VAR(szWinbindNssInfo),
1307 .special = NULL,
1308 .enum_list = NULL,
1309 .flags = FLAG_ADVANCED,
1312 .label = "winbind refresh tickets",
1313 .type = P_BOOL,
1314 .p_class = P_GLOBAL,
1315 .offset = GLOBAL_VAR(bWinbindRefreshTickets),
1316 .special = NULL,
1317 .enum_list = NULL,
1318 .flags = FLAG_ADVANCED,
1321 .label = "winbind offline logon",
1322 .type = P_BOOL,
1323 .p_class = P_GLOBAL,
1324 .offset = GLOBAL_VAR(bWinbindOfflineLogon),
1325 .special = NULL,
1326 .enum_list = NULL,
1327 .flags = FLAG_ADVANCED,
1330 .label = "winbind normalize names",
1331 .type = P_BOOL,
1332 .p_class = P_GLOBAL,
1333 .offset = GLOBAL_VAR(bWinbindNormalizeNames),
1334 .special = NULL,
1335 .enum_list = NULL,
1336 .flags = FLAG_ADVANCED,
1339 .label = "winbind rpc only",
1340 .type = P_BOOL,
1341 .p_class = P_GLOBAL,
1342 .offset = GLOBAL_VAR(bWinbindRpcOnly),
1343 .special = NULL,
1344 .enum_list = NULL,
1345 .flags = FLAG_ADVANCED,
1348 .label = "create krb5 conf",
1349 .type = P_BOOL,
1350 .p_class = P_GLOBAL,
1351 .offset = GLOBAL_VAR(bCreateKrb5Conf),
1352 .special = NULL,
1353 .enum_list = NULL,
1354 .flags = FLAG_ADVANCED,
1357 .label = "ncalrpc dir",
1358 .type = P_STRING,
1359 .p_class = P_GLOBAL,
1360 .offset = GLOBAL_VAR(ncalrpc_dir),
1361 .special = NULL,
1362 .enum_list = NULL,
1363 .flags = FLAG_ADVANCED,
1366 .label = "winbind max domain connections",
1367 .type = P_INTEGER,
1368 .p_class = P_GLOBAL,
1369 .offset = GLOBAL_VAR(winbindMaxDomainConnections),
1370 .special = NULL,
1371 .enum_list = NULL,
1372 .flags = FLAG_ADVANCED,
1375 .label = "winbindd socket directory",
1376 .type = P_STRING,
1377 .p_class = P_GLOBAL,
1378 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1379 .special = NULL,
1380 .enum_list = NULL,
1381 .flags = FLAG_ADVANCED,
1384 .label = "winbindd privileged socket directory",
1385 .type = P_STRING,
1386 .p_class = P_GLOBAL,
1387 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1388 .special = NULL,
1389 .enum_list = NULL,
1390 .flags = FLAG_ADVANCED,
1393 .label = "winbind sealed pipes",
1394 .type = P_BOOL,
1395 .p_class = P_GLOBAL,
1396 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1397 .special = NULL,
1398 .enum_list = NULL,
1399 .flags = FLAG_ADVANCED,
1402 {N_("DNS options"), P_SEP, P_SEPARATOR},
1404 .label = "allow dns updates",
1405 .type = P_ENUM,
1406 .p_class = P_GLOBAL,
1407 .offset = GLOBAL_VAR(allow_dns_updates),
1408 .special = NULL,
1409 .enum_list = enum_dns_update_settings,
1410 .flags = FLAG_ADVANCED,
1413 .label = "dns forwarder",
1414 .type = P_STRING,
1415 .p_class = P_GLOBAL,
1416 .offset = GLOBAL_VAR(dns_forwarder),
1417 .special = NULL,
1418 .enum_list = NULL,
1419 .flags = FLAG_ADVANCED,
1422 .label = "dns recursive queries",
1423 .type = P_BOOL,
1424 .p_class = P_GLOBAL,
1425 .offset = GLOBAL_VAR(dns_recursive_queries),
1426 .special = NULL,
1427 .enum_list = NULL
1430 .label = "dns update command",
1431 .type = P_CMDLIST,
1432 .p_class = P_GLOBAL,
1433 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1434 .special = NULL,
1435 .enum_list = NULL,
1436 .flags = FLAG_ADVANCED,
1439 .label = "nsupdate command",
1440 .type = P_CMDLIST,
1441 .p_class = P_GLOBAL,
1442 .offset = GLOBAL_VAR(szNSUpdateCommand),
1443 .special = NULL,
1444 .enum_list = NULL,
1445 .flags = FLAG_ADVANCED,
1448 .label = "rndc command",
1449 .type = P_CMDLIST,
1450 .p_class = P_GLOBAL,
1451 .offset = GLOBAL_VAR(szRNDCCommand),
1452 .special = NULL,
1453 .enum_list = NULL,
1454 .flags = FLAG_ADVANCED,
1457 .label = "multicast dns register",
1458 .type = P_BOOL,
1459 .p_class = P_GLOBAL,
1460 .offset = GLOBAL_VAR(bMulticastDnsRegister),
1461 .special = NULL,
1462 .enum_list = NULL,
1463 .flags = FLAG_ADVANCED | FLAG_GLOBAL,
1466 {N_("AD DC options"), P_SEP, P_SEPARATOR},
1469 .label = "samba kcc command",
1470 .type = P_CMDLIST,
1471 .p_class = P_GLOBAL,
1472 .offset = GLOBAL_VAR(szSambaKCCCommand),
1473 .special = NULL,
1474 .enum_list = NULL,
1475 .flags = FLAG_ADVANCED,
1478 .label = "server services",
1479 .type = P_LIST,
1480 .p_class = P_GLOBAL,
1481 .offset = GLOBAL_VAR(server_services),
1482 .special = NULL,
1483 .enum_list = NULL
1486 .label = "dcerpc endpoint servers",
1487 .type = P_LIST,
1488 .p_class = P_GLOBAL,
1489 .offset = GLOBAL_VAR(dcerpc_ep_servers),
1490 .special = NULL,
1491 .enum_list = NULL
1494 .label = "spn update command",
1495 .type = P_CMDLIST,
1496 .p_class = P_GLOBAL,
1497 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1498 .special = NULL,
1499 .enum_list = NULL,
1500 .flags = FLAG_ADVANCED,
1503 .label = "share backend",
1504 .type = P_STRING,
1505 .p_class = P_GLOBAL,
1506 .offset = GLOBAL_VAR(szShareBackend),
1507 .special = NULL,
1508 .enum_list = NULL
1511 .label = "ntvfs handler",
1512 .type = P_LIST,
1513 .p_class = P_LOCAL,
1514 .offset = LOCAL_VAR(ntvfs_handler),
1515 .special = NULL,
1516 .enum_list = NULL
1519 {N_("TLS options"), P_SEP, P_SEPARATOR},
1522 .label = "tls enabled",
1523 .type = P_BOOL,
1524 .p_class = P_GLOBAL,
1525 .offset = GLOBAL_VAR(tls_enabled),
1526 .special = NULL,
1527 .enum_list = NULL
1530 .label = "tls keyfile",
1531 .type = P_STRING,
1532 .p_class = P_GLOBAL,
1533 .offset = GLOBAL_VAR(tls_keyfile),
1534 .special = NULL,
1535 .enum_list = NULL
1538 .label = "tls certfile",
1539 .type = P_STRING,
1540 .p_class = P_GLOBAL,
1541 .offset = GLOBAL_VAR(tls_certfile),
1542 .special = NULL,
1543 .enum_list = NULL
1546 .label = "tls cafile",
1547 .type = P_STRING,
1548 .p_class = P_GLOBAL,
1549 .offset = GLOBAL_VAR(tls_cafile),
1550 .special = NULL,
1551 .enum_list = NULL
1554 .label = "tls crlfile",
1555 .type = P_STRING,
1556 .p_class = P_GLOBAL,
1557 .offset = GLOBAL_VAR(tls_crlfile),
1558 .special = NULL,
1559 .enum_list = NULL
1562 .label = "tls dh params file",
1563 .type = P_STRING,
1564 .p_class = P_GLOBAL,
1565 .offset = GLOBAL_VAR(tls_dhpfile),
1566 .special = NULL,
1567 .enum_list = NULL
1570 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1574 /* local variables */
1575 struct loadparm_context {
1576 const char *szConfigFile;
1577 struct loadparm_global *globals;
1578 struct loadparm_service **services;
1579 struct loadparm_service *sDefault;
1580 struct smb_iconv_handle *iconv_handle;
1581 int iNumServices;
1582 struct loadparm_service *currentService;
1583 bool bInGlobalSection;
1584 struct file_lists {
1585 struct file_lists *next;
1586 char *name;
1587 char *subfname;
1588 time_t modtime;
1589 } *file_lists;
1590 unsigned int flags[NUMPARAMETERS];
1591 bool loaded;
1592 bool refuse_free;
1593 bool global; /* Is this the global context, which may set
1594 * global variables such as debug level etc? */
1595 const struct loadparm_s3_helpers *s3_fns;
1599 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1601 if (lp_ctx->s3_fns) {
1602 return lp_ctx->s3_fns->get_default_loadparm_service();
1604 return lp_ctx->sDefault;
1608 * Convenience routine to grab string parameters into temporary memory
1609 * and run standard_sub_basic on them.
1611 * The buffers can be written to by
1612 * callers without affecting the source string.
1615 static const char *lp_string(const char *s)
1617 #if 0 /* until REWRITE done to make thread-safe */
1618 size_t len = s ? strlen(s) : 0;
1619 char *ret;
1620 #endif
1622 /* The follow debug is useful for tracking down memory problems
1623 especially if you have an inner loop that is calling a lp_*()
1624 function that returns a string. Perhaps this debug should be
1625 present all the time? */
1627 #if 0
1628 DEBUG(10, ("lp_string(%s)\n", s));
1629 #endif
1631 #if 0 /* until REWRITE done to make thread-safe */
1632 if (!lp_talloc)
1633 lp_talloc = talloc_init("lp_talloc");
1635 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1637 if (!ret)
1638 return NULL;
1640 if (!s)
1641 *ret = 0;
1642 else
1643 strlcpy(ret, s, len);
1645 if (trim_string(ret, "\"", "\"")) {
1646 if (strchr(ret,'"') != NULL)
1647 strlcpy(ret, s, len);
1650 standard_sub_basic(ret,len+100);
1651 return (ret);
1652 #endif
1653 return s;
1657 In this section all the functions that are used to access the
1658 parameters from the rest of the program are defined
1662 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1663 * for code compatibility between existing Samba4 and Samba3 code.
1666 /* this global context supports the lp_*() function varients */
1667 static struct loadparm_context *global_loadparm_context;
1669 #define lpcfg_default_service global_loadparm_context->sDefault
1670 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1672 #define FN_GLOBAL_STRING(fn_name,var_name) \
1673 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1674 if (lp_ctx == NULL) return NULL; \
1675 if (lp_ctx->s3_fns) { \
1676 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1677 return lp_ctx->s3_fns->fn_name(); \
1679 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1682 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1683 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1684 if (lp_ctx == NULL) return NULL; \
1685 if (lp_ctx->s3_fns) { \
1686 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1687 return lp_ctx->s3_fns->fn_name(); \
1689 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1692 #define FN_GLOBAL_LIST(fn_name,var_name) \
1693 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1694 if (lp_ctx == NULL) return NULL; \
1695 if (lp_ctx->s3_fns) { \
1696 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1697 return lp_ctx->s3_fns->fn_name(); \
1699 return lp_ctx->globals->var_name; \
1702 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1703 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1704 if (lp_ctx == NULL) return false; \
1705 if (lp_ctx->s3_fns) { \
1706 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1707 return lp_ctx->s3_fns->fn_name(); \
1709 return lp_ctx->globals->var_name; \
1712 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1713 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1714 if (lp_ctx->s3_fns) { \
1715 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1716 return lp_ctx->s3_fns->fn_name(); \
1718 return lp_ctx->globals->var_name; \
1721 /* Local parameters don't need the ->s3_fns because the struct
1722 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1723 * hook */
1724 #define FN_LOCAL_STRING(fn_name,val) \
1725 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1726 struct loadparm_service *sDefault) { \
1727 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1730 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1732 #define FN_LOCAL_LIST(fn_name,val) \
1733 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1734 struct loadparm_service *sDefault) {\
1735 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1738 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1740 #define FN_LOCAL_BOOL(fn_name,val) \
1741 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1742 struct loadparm_service *sDefault) { \
1743 return((service != NULL)? service->val : sDefault->val); \
1746 #define FN_LOCAL_INTEGER(fn_name,val) \
1747 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1748 struct loadparm_service *sDefault) { \
1749 return((service != NULL)? service->val : sDefault->val); \
1752 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1754 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1756 #define FN_LOCAL_CHAR(fn_name,val) \
1757 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1758 struct loadparm_service *sDefault) { \
1759 return((service != NULL)? service->val : sDefault->val); \
1762 #include "lib/param/param_functions.c"
1764 /* These functions remain only in lib/param for now */
1765 FN_GLOBAL_BOOL(readraw, bReadRaw)
1766 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1767 FN_GLOBAL_STRING(cachedir, szCacheDir)
1768 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1769 FN_GLOBAL_STRING(statedir, szStateDir)
1771 /* local prototypes */
1772 static int map_parameter(const char *pszParmName);
1773 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1774 const char *pszServiceName);
1775 static void copy_service(struct loadparm_service *pserviceDest,
1776 struct loadparm_service *pserviceSource,
1777 struct bitmap *pcopymapDest);
1778 static bool lpcfg_service_ok(struct loadparm_service *service);
1779 static bool do_section(const char *pszSectionName, void *);
1780 static void init_copymap(struct loadparm_service *pservice);
1782 /* This is a helper function for parametrical options support. */
1783 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1784 /* Actual parametrical functions are quite simple */
1785 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1786 struct loadparm_service *service,
1787 const char *type, const char *option)
1789 char *vfskey_tmp = NULL;
1790 char *vfskey = NULL;
1791 struct parmlist_entry *data;
1793 if (lp_ctx == NULL)
1794 return NULL;
1796 if (lp_ctx->s3_fns) {
1797 return lp_ctx->s3_fns->get_parametric(service, type, option);
1800 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1802 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1803 if (vfskey_tmp == NULL) return NULL;
1804 vfskey = strlower_talloc(NULL, vfskey_tmp);
1805 talloc_free(vfskey_tmp);
1807 while (data) {
1808 if (strcmp(data->key, vfskey) == 0) {
1809 talloc_free(vfskey);
1810 return data->value;
1812 data = data->next;
1815 if (service != NULL) {
1816 /* Try to fetch the same option but from globals */
1817 /* but only if we are not already working with globals */
1818 for (data = lp_ctx->globals->param_opt; data;
1819 data = data->next) {
1820 if (strcmp(data->key, vfskey) == 0) {
1821 talloc_free(vfskey);
1822 return data->value;
1827 talloc_free(vfskey);
1829 return NULL;
1834 * convenience routine to return int parameters.
1836 static int lp_int(const char *s)
1839 if (!s) {
1840 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1841 return -1;
1844 return strtol(s, NULL, 0);
1848 * convenience routine to return unsigned long parameters.
1850 static unsigned long lp_ulong(const char *s)
1853 if (!s) {
1854 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1855 return -1;
1858 return strtoul(s, NULL, 0);
1862 * convenience routine to return unsigned long parameters.
1864 static long lp_long(const char *s)
1867 if (!s) {
1868 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1869 return -1;
1872 return strtol(s, NULL, 0);
1876 * convenience routine to return unsigned long parameters.
1878 static double lp_double(const char *s)
1881 if (!s) {
1882 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1883 return -1;
1886 return strtod(s, NULL);
1890 * convenience routine to return boolean parameters.
1892 static bool lp_bool(const char *s)
1894 bool ret = false;
1896 if (!s) {
1897 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1898 return false;
1901 if (!set_boolean(s, &ret)) {
1902 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1903 return false;
1906 return ret;
1911 * Return parametric option from a given service. Type is a part of option before ':'
1912 * Parametric option has following syntax: 'Type: option = value'
1913 * Returned value is allocated in 'lp_talloc' context
1916 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1917 struct loadparm_service *service, const char *type,
1918 const char *option)
1920 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1922 if (value)
1923 return lp_string(value);
1925 return NULL;
1929 * Return parametric option from a given service. Type is a part of option before ':'
1930 * Parametric option has following syntax: 'Type: option = value'
1931 * Returned value is allocated in 'lp_talloc' context
1934 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1935 struct loadparm_context *lp_ctx,
1936 struct loadparm_service *service,
1937 const char *type,
1938 const char *option, const char *separator)
1940 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1942 if (value != NULL)
1943 return (const char **)str_list_make(mem_ctx, value, separator);
1945 return NULL;
1949 * Return parametric option from a given service. Type is a part of option before ':'
1950 * Parametric option has following syntax: 'Type: option = value'
1953 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1954 struct loadparm_service *service, const char *type,
1955 const char *option, int default_v)
1957 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1959 if (value)
1960 return lp_int(value);
1962 return default_v;
1966 * Return parametric option from a given service. Type is a part of
1967 * option before ':'.
1968 * Parametric option has following syntax: 'Type: option = value'.
1971 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1972 struct loadparm_service *service, const char *type,
1973 const char *option, int default_v)
1975 uint64_t bval;
1977 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1979 if (value && conv_str_size_error(value, &bval)) {
1980 if (bval <= INT_MAX) {
1981 return (int)bval;
1985 return default_v;
1989 * Return parametric option from a given service.
1990 * Type is a part of option before ':'
1991 * Parametric option has following syntax: 'Type: option = value'
1993 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1994 struct loadparm_service *service, const char *type,
1995 const char *option, unsigned long default_v)
1997 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1999 if (value)
2000 return lp_ulong(value);
2002 return default_v;
2005 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
2006 struct loadparm_service *service, const char *type,
2007 const char *option, long default_v)
2009 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2011 if (value)
2012 return lp_long(value);
2014 return default_v;
2017 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
2018 struct loadparm_service *service, const char *type,
2019 const char *option, double default_v)
2021 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2023 if (value != NULL)
2024 return lp_double(value);
2026 return default_v;
2030 * Return parametric option from a given service. Type is a part of option before ':'
2031 * Parametric option has following syntax: 'Type: option = value'
2034 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
2035 struct loadparm_service *service, const char *type,
2036 const char *option, bool default_v)
2038 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
2040 if (value != NULL)
2041 return lp_bool(value);
2043 return default_v;
2048 * Initialise a service to the defaults.
2051 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
2053 struct loadparm_service *pservice =
2054 talloc_zero(mem_ctx, struct loadparm_service);
2055 copy_service(pservice, sDefault, NULL);
2056 return pservice;
2060 * Set a string value, deallocating any existing space, and allocing the space
2061 * for the string
2063 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2065 talloc_free(*dest);
2067 if (src == NULL)
2068 src = "";
2070 *dest = talloc_strdup(mem_ctx, src);
2071 if ((*dest) == NULL) {
2072 DEBUG(0,("Out of memory in string_set\n"));
2073 return false;
2076 return true;
2080 * Set a string value, deallocating any existing space, and allocing the space
2081 * for the string
2083 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
2085 talloc_free(*dest);
2087 if (src == NULL)
2088 src = "";
2090 *dest = strupper_talloc(mem_ctx, src);
2091 if ((*dest) == NULL) {
2092 DEBUG(0,("Out of memory in string_set_upper\n"));
2093 return false;
2096 return true;
2102 * Add a new service to the services array initialising it with the given
2103 * service.
2106 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
2107 const struct loadparm_service *pservice,
2108 const char *name)
2110 int i;
2111 struct loadparm_service tservice;
2112 int num_to_alloc = lp_ctx->iNumServices + 1;
2113 struct parmlist_entry *data, *pdata;
2115 if (pservice == NULL) {
2116 pservice = lp_ctx->sDefault;
2119 tservice = *pservice;
2121 /* it might already exist */
2122 if (name) {
2123 struct loadparm_service *service = getservicebyname(lp_ctx,
2124 name);
2125 if (service != NULL) {
2126 /* Clean all parametric options for service */
2127 /* They will be added during parsing again */
2128 data = service->param_opt;
2129 while (data) {
2130 pdata = data->next;
2131 talloc_free(data);
2132 data = pdata;
2134 service->param_opt = NULL;
2135 return service;
2139 /* find an invalid one */
2140 for (i = 0; i < lp_ctx->iNumServices; i++)
2141 if (lp_ctx->services[i] == NULL)
2142 break;
2144 /* if not, then create one */
2145 if (i == lp_ctx->iNumServices) {
2146 struct loadparm_service **tsp;
2148 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2150 if (!tsp) {
2151 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2152 return NULL;
2153 } else {
2154 lp_ctx->services = tsp;
2155 lp_ctx->services[lp_ctx->iNumServices] = NULL;
2158 lp_ctx->iNumServices++;
2161 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2162 if (lp_ctx->services[i] == NULL) {
2163 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2164 return NULL;
2166 copy_service(lp_ctx->services[i], &tservice, NULL);
2167 if (name != NULL)
2168 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2169 return lp_ctx->services[i];
2173 * Add a new home service, with the specified home directory, defaults coming
2174 * from service ifrom.
2177 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2178 const char *pszHomename,
2179 struct loadparm_service *default_service,
2180 const char *user, const char *pszHomedir)
2182 struct loadparm_service *service;
2184 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2186 if (service == NULL)
2187 return false;
2189 if (!(*(default_service->szPath))
2190 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2191 service->szPath = talloc_strdup(service, pszHomedir);
2192 } else {
2193 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2196 if (!(*(service->comment))) {
2197 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2199 service->bAvailable = default_service->bAvailable;
2200 service->bBrowseable = default_service->bBrowseable;
2202 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2203 pszHomename, user, service->szPath));
2205 return true;
2209 * Add a new printer service, with defaults coming from service iFrom.
2212 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2213 const char *pszPrintername,
2214 struct loadparm_service *default_service)
2216 const char *comment = "From Printcap";
2217 struct loadparm_service *service;
2218 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2220 if (service == NULL)
2221 return false;
2223 /* note that we do NOT default the availability flag to True - */
2224 /* we take it from the default service passed. This allows all */
2225 /* dynamic printers to be disabled by disabling the [printers] */
2226 /* entry (if/when the 'available' keyword is implemented!). */
2228 /* the printer name is set to the service name. */
2229 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2230 lpcfg_string_set(service, &service->comment, comment);
2231 service->bBrowseable = default_service->bBrowseable;
2232 /* Printers cannot be read_only. */
2233 service->bRead_only = false;
2234 /* Printer services must be printable. */
2235 service->bPrint_ok = true;
2237 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2239 return true;
2243 * Map a parameter's string representation to something we can use.
2244 * Returns False if the parameter string is not recognised, else TRUE.
2247 static int map_parameter(const char *pszParmName)
2249 int iIndex;
2251 if (*pszParmName == '-')
2252 return -1;
2254 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2255 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2256 return iIndex;
2258 /* Warn only if it isn't parametric option */
2259 if (strchr(pszParmName, ':') == NULL)
2260 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2261 /* We do return 'fail' for parametric options as well because they are
2262 stored in different storage
2264 return -1;
2269 return the parameter structure for a parameter
2271 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2273 int parmnum;
2275 if (lp_ctx->s3_fns) {
2276 return lp_ctx->s3_fns->get_parm_struct(name);
2279 parmnum = map_parameter(name);
2280 if (parmnum == -1) return NULL;
2281 return &parm_table[parmnum];
2285 return the parameter pointer for a parameter
2287 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2288 struct loadparm_service *service, struct parm_struct *parm)
2290 if (lp_ctx->s3_fns) {
2291 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2294 if (service == NULL) {
2295 if (parm->p_class == P_LOCAL)
2296 return ((char *)lp_ctx->sDefault)+parm->offset;
2297 else if (parm->p_class == P_GLOBAL)
2298 return ((char *)lp_ctx->globals)+parm->offset;
2299 else return NULL;
2300 } else {
2301 return ((char *)service) + parm->offset;
2306 return the parameter pointer for a parameter
2308 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2310 int parmnum;
2312 if (lp_ctx->s3_fns) {
2313 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2314 if (parm) {
2315 return parm->flags & FLAG_CMDLINE;
2317 return false;
2320 parmnum = map_parameter(name);
2321 if (parmnum == -1) return false;
2323 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2327 * Find a service by name. Otherwise works like get_service.
2330 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2331 const char *pszServiceName)
2333 int iService;
2335 if (lp_ctx->s3_fns) {
2336 return lp_ctx->s3_fns->get_service(pszServiceName);
2339 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2340 if (lp_ctx->services[iService] != NULL &&
2341 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2342 return lp_ctx->services[iService];
2345 return NULL;
2349 * Copy a service structure to another.
2350 * If pcopymapDest is NULL then copy all fields
2353 static void copy_service(struct loadparm_service *pserviceDest,
2354 struct loadparm_service *pserviceSource,
2355 struct bitmap *pcopymapDest)
2357 int i;
2358 bool bcopyall = (pcopymapDest == NULL);
2359 struct parmlist_entry *data, *pdata, *paramo;
2360 bool not_added;
2362 for (i = 0; parm_table[i].label; i++)
2363 if (parm_table[i].p_class == P_LOCAL &&
2364 (bcopyall || bitmap_query(pcopymapDest, i))) {
2365 void *src_ptr =
2366 ((char *)pserviceSource) + parm_table[i].offset;
2367 void *dest_ptr =
2368 ((char *)pserviceDest) + parm_table[i].offset;
2370 switch (parm_table[i].type) {
2371 case P_BOOL:
2372 *(bool *)dest_ptr = *(bool *)src_ptr;
2373 break;
2375 case P_INTEGER:
2376 case P_BYTES:
2377 case P_OCTAL:
2378 case P_ENUM:
2379 *(int *)dest_ptr = *(int *)src_ptr;
2380 break;
2382 case P_STRING:
2383 lpcfg_string_set(pserviceDest,
2384 (char **)dest_ptr,
2385 *(char **)src_ptr);
2386 break;
2388 case P_USTRING:
2389 lpcfg_string_set_upper(pserviceDest,
2390 (char **)dest_ptr,
2391 *(char **)src_ptr);
2392 break;
2393 case P_LIST:
2394 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2395 *(const char ***)src_ptr);
2396 break;
2397 default:
2398 break;
2402 if (bcopyall) {
2403 init_copymap(pserviceDest);
2404 if (pserviceSource->copymap)
2405 bitmap_copy(pserviceDest->copymap,
2406 pserviceSource->copymap);
2409 data = pserviceSource->param_opt;
2410 while (data) {
2411 not_added = true;
2412 pdata = pserviceDest->param_opt;
2413 /* Traverse destination */
2414 while (pdata) {
2415 /* If we already have same option, override it */
2416 if (strcmp(pdata->key, data->key) == 0) {
2417 talloc_free(pdata->value);
2418 pdata->value = talloc_strdup(pdata,
2419 data->value);
2420 not_added = false;
2421 break;
2423 pdata = pdata->next;
2425 if (not_added) {
2426 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2427 if (paramo == NULL)
2428 smb_panic("OOM");
2429 paramo->key = talloc_strdup(paramo, data->key);
2430 paramo->value = talloc_strdup(paramo, data->value);
2431 DLIST_ADD(pserviceDest->param_opt, paramo);
2433 data = data->next;
2438 * Check a service for consistency. Return False if the service is in any way
2439 * incomplete or faulty, else True.
2441 static bool lpcfg_service_ok(struct loadparm_service *service)
2443 bool bRetval;
2445 bRetval = true;
2446 if (service->szService[0] == '\0') {
2447 DEBUG(0, ("The following message indicates an internal error:\n"));
2448 DEBUG(0, ("No service name in service entry.\n"));
2449 bRetval = false;
2452 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2453 /* I can't see why you'd want a non-printable printer service... */
2454 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2455 if (!service->bPrint_ok) {
2456 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2457 service->szService));
2458 service->bPrint_ok = true;
2460 /* [printers] service must also be non-browsable. */
2461 if (service->bBrowseable)
2462 service->bBrowseable = false;
2465 /* If a service is flagged unavailable, log the fact at level 0. */
2466 if (!service->bAvailable)
2467 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2468 service->szService));
2470 return bRetval;
2474 /*******************************************************************
2475 Keep a linked list of all config files so we know when one has changed
2476 it's date and needs to be reloaded.
2477 ********************************************************************/
2479 static void add_to_file_list(struct loadparm_context *lp_ctx,
2480 const char *fname, const char *subfname)
2482 struct file_lists *f = lp_ctx->file_lists;
2484 while (f) {
2485 if (f->name && !strcmp(f->name, fname))
2486 break;
2487 f = f->next;
2490 if (!f) {
2491 f = talloc(lp_ctx, struct file_lists);
2492 if (!f)
2493 return;
2494 f->next = lp_ctx->file_lists;
2495 f->name = talloc_strdup(f, fname);
2496 if (!f->name) {
2497 talloc_free(f);
2498 return;
2500 f->subfname = talloc_strdup(f, subfname);
2501 if (!f->subfname) {
2502 talloc_free(f);
2503 return;
2505 lp_ctx->file_lists = f;
2506 f->modtime = file_modtime(subfname);
2507 } else {
2508 time_t t = file_modtime(subfname);
2509 if (t)
2510 f->modtime = t;
2514 /*******************************************************************
2515 Check if a config file has changed date.
2516 ********************************************************************/
2517 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2519 struct file_lists *f;
2520 DEBUG(6, ("lp_file_list_changed()\n"));
2522 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2523 char *n2;
2524 time_t mod_time;
2526 n2 = standard_sub_basic(lp_ctx, f->name);
2528 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2529 f->name, n2, ctime(&f->modtime)));
2531 mod_time = file_modtime(n2);
2533 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2534 DEBUGADD(6, ("file %s modified: %s\n", n2,
2535 ctime(&mod_time)));
2536 f->modtime = mod_time;
2537 talloc_free(f->subfname);
2538 f->subfname = talloc_strdup(f, n2);
2539 return true;
2542 return false;
2545 /***************************************************************************
2546 Handle the "realm" parameter
2547 ***************************************************************************/
2549 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2550 const char *pszParmValue, char **ptr)
2552 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2554 talloc_free(lp_ctx->globals->szRealm_upper);
2555 talloc_free(lp_ctx->globals->szRealm_lower);
2557 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2558 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2560 return true;
2563 /***************************************************************************
2564 Handle the include operation.
2565 ***************************************************************************/
2567 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2568 const char *pszParmValue, char **ptr)
2570 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2572 add_to_file_list(lp_ctx, pszParmValue, fname);
2574 lpcfg_string_set(lp_ctx, ptr, fname);
2576 if (file_exist(fname))
2577 return pm_process(fname, do_section, do_parameter, lp_ctx);
2579 DEBUG(2, ("Can't find include file %s\n", fname));
2581 return false;
2584 /***************************************************************************
2585 Handle the interpretation of the copy parameter.
2586 ***************************************************************************/
2588 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2589 const char *pszParmValue, char **ptr)
2591 bool bRetval;
2592 struct loadparm_service *serviceTemp;
2594 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2596 bRetval = false;
2598 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2600 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2601 if (serviceTemp == lp_ctx->currentService) {
2602 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2603 } else {
2604 copy_service(lp_ctx->currentService,
2605 serviceTemp,
2606 lp_ctx->currentService->copymap);
2607 bRetval = true;
2609 } else {
2610 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2611 pszParmValue));
2612 bRetval = false;
2615 return bRetval;
2618 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2619 const char *pszParmValue, char **ptr)
2622 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2623 if (lp_ctx->global) {
2624 return debug_parse_levels(pszParmValue);
2626 return true;
2629 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2630 const char *pszParmValue, char **ptr)
2632 debug_set_logfile(pszParmValue);
2633 if (lp_ctx->global) {
2634 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2636 return true;
2639 /***************************************************************************
2640 Initialise a copymap.
2641 ***************************************************************************/
2643 static void init_copymap(struct loadparm_service *pservice)
2645 int i;
2647 TALLOC_FREE(pservice->copymap);
2649 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2650 if (!pservice->copymap)
2651 DEBUG(0,
2652 ("Couldn't allocate copymap!! (size %d)\n",
2653 (int)NUMPARAMETERS));
2654 else
2655 for (i = 0; i < NUMPARAMETERS; i++)
2656 bitmap_set(pservice->copymap, i);
2660 * Process a parametric option
2662 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2663 struct loadparm_service *service,
2664 const char *pszParmName,
2665 const char *pszParmValue, int flags)
2667 struct parmlist_entry *paramo, *data;
2668 char *name;
2669 TALLOC_CTX *mem_ctx;
2671 while (isspace((unsigned char)*pszParmName)) {
2672 pszParmName++;
2675 name = strlower_talloc(lp_ctx, pszParmName);
2676 if (!name) return false;
2678 if (service == NULL) {
2679 data = lp_ctx->globals->param_opt;
2680 mem_ctx = lp_ctx->globals;
2681 } else {
2682 data = service->param_opt;
2683 mem_ctx = service;
2686 /* Traverse destination */
2687 for (paramo=data; paramo; paramo=paramo->next) {
2688 /* If we already have the option set, override it unless
2689 it was a command line option and the new one isn't */
2690 if (strcmp(paramo->key, name) == 0) {
2691 if ((paramo->priority & FLAG_CMDLINE) &&
2692 !(flags & FLAG_CMDLINE)) {
2693 talloc_free(name);
2694 return true;
2697 talloc_free(paramo->value);
2698 paramo->value = talloc_strdup(paramo, pszParmValue);
2699 paramo->priority = flags;
2700 talloc_free(name);
2701 return true;
2705 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2706 if (!paramo)
2707 smb_panic("OOM");
2708 paramo->key = talloc_strdup(paramo, name);
2709 paramo->value = talloc_strdup(paramo, pszParmValue);
2710 paramo->priority = flags;
2711 if (service == NULL) {
2712 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2713 } else {
2714 DLIST_ADD(service->param_opt, paramo);
2717 talloc_free(name);
2719 return true;
2722 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2723 const char *pszParmName, const char *pszParmValue,
2724 struct loadparm_context *lp_ctx, bool on_globals)
2726 int i;
2727 /* if it is a special case then go ahead */
2728 if (parm_table[parmnum].special) {
2729 bool ret;
2730 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2731 (char **)parm_ptr);
2732 if (!ret) {
2733 return false;
2735 goto mark_non_default;
2738 /* now switch on the type of variable it is */
2739 switch (parm_table[parmnum].type)
2741 case P_BOOL: {
2742 bool b;
2743 if (!set_boolean(pszParmValue, &b)) {
2744 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2745 return false;
2747 *(bool *)parm_ptr = b;
2749 break;
2751 case P_BOOLREV: {
2752 bool b;
2753 if (!set_boolean(pszParmValue, &b)) {
2754 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2755 return false;
2757 *(bool *)parm_ptr = !b;
2759 break;
2761 case P_INTEGER:
2762 *(int *)parm_ptr = atoi(pszParmValue);
2763 break;
2765 case P_CHAR:
2766 *(char *)parm_ptr = *pszParmValue;
2767 break;
2769 case P_OCTAL:
2770 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2771 break;
2773 case P_BYTES:
2775 uint64_t val;
2776 if (conv_str_size_error(pszParmValue, &val)) {
2777 if (val <= INT_MAX) {
2778 *(int *)parm_ptr = (int)val;
2779 break;
2783 DEBUG(0,("lp_do_parameter(%s): value is not "
2784 "a valid size specifier!\n", pszParmValue));
2785 return false;
2788 case P_CMDLIST:
2789 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2790 pszParmValue, NULL);
2791 break;
2792 case P_LIST:
2794 char **new_list = str_list_make(mem_ctx,
2795 pszParmValue, NULL);
2796 for (i=0; new_list[i]; i++) {
2797 if (new_list[i][0] == '+' && new_list[i][1]) {
2798 if (!str_list_check(*(const char ***)parm_ptr,
2799 &new_list[i][1])) {
2800 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2801 &new_list[i][1]);
2803 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2804 str_list_remove(*(const char ***)parm_ptr,
2805 &new_list[i][1]);
2806 } else {
2807 if (i != 0) {
2808 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2809 pszParmName, pszParmValue));
2810 return false;
2812 *(const char ***)parm_ptr = (const char **) new_list;
2813 break;
2816 break;
2818 case P_STRING:
2819 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2820 break;
2822 case P_USTRING:
2823 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2824 break;
2826 case P_ENUM:
2827 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2828 if (strequal
2829 (pszParmValue,
2830 parm_table[parmnum].enum_list[i].name)) {
2831 *(int *)parm_ptr =
2832 parm_table[parmnum].
2833 enum_list[i].value;
2834 break;
2837 if (!parm_table[parmnum].enum_list[i].name) {
2838 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2839 pszParmValue, pszParmName));
2840 return false;
2842 break;
2844 case P_SEP:
2845 break;
2848 mark_non_default:
2849 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2850 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2851 /* we have to also unset FLAG_DEFAULT on aliases */
2852 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2853 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2855 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2856 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2859 return true;
2863 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2864 const char *pszParmName, const char *pszParmValue)
2866 int parmnum = map_parameter(pszParmName);
2867 void *parm_ptr;
2869 if (parmnum < 0) {
2870 if (strchr(pszParmName, ':')) {
2871 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2873 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2874 return true;
2877 /* if the flag has been set on the command line, then don't allow override,
2878 but don't report an error */
2879 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2880 return true;
2883 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2885 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2886 pszParmName, pszParmValue, lp_ctx, true);
2889 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2890 struct loadparm_service *service,
2891 const char *pszParmName, const char *pszParmValue)
2893 void *parm_ptr;
2894 int i;
2895 int parmnum = map_parameter(pszParmName);
2897 if (parmnum < 0) {
2898 if (strchr(pszParmName, ':')) {
2899 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2901 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2902 return true;
2905 /* if the flag has been set on the command line, then don't allow override,
2906 but don't report an error */
2907 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2908 return true;
2911 if (parm_table[parmnum].p_class == P_GLOBAL) {
2912 DEBUG(0,
2913 ("Global parameter %s found in service section!\n",
2914 pszParmName));
2915 return true;
2917 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2919 if (!service->copymap)
2920 init_copymap(service);
2922 /* this handles the aliases - set the copymap for other
2923 * entries with the same data pointer */
2924 for (i = 0; parm_table[i].label; i++)
2925 if (parm_table[i].offset == parm_table[parmnum].offset &&
2926 parm_table[i].p_class == parm_table[parmnum].p_class)
2927 bitmap_clear(service->copymap, i);
2929 return set_variable(service, parmnum, parm_ptr, pszParmName,
2930 pszParmValue, lp_ctx, false);
2934 * Process a parameter.
2937 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2938 void *userdata)
2940 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2942 if (lp_ctx->bInGlobalSection)
2943 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2944 pszParmValue);
2945 else
2946 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2947 pszParmName, pszParmValue);
2951 variable argument do parameter
2953 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2954 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2955 const char *pszParmName, const char *fmt, ...)
2957 char *s;
2958 bool ret;
2959 va_list ap;
2961 va_start(ap, fmt);
2962 s = talloc_vasprintf(NULL, fmt, ap);
2963 va_end(ap);
2964 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2965 talloc_free(s);
2966 return ret;
2971 set a parameter from the commandline - this is called from command line parameter
2972 parsing code. It sets the parameter then marks the parameter as unable to be modified
2973 by smb.conf processing
2975 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2976 const char *pszParmValue)
2978 int parmnum;
2979 int i;
2981 if (lp_ctx->s3_fns) {
2982 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2985 parmnum = map_parameter(pszParmName);
2987 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2990 if (parmnum < 0 && strchr(pszParmName, ':')) {
2991 /* set a parametric option */
2992 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2993 pszParmValue, FLAG_CMDLINE);
2996 if (parmnum < 0) {
2997 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2998 return false;
3001 /* reset the CMDLINE flag in case this has been called before */
3002 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
3004 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
3005 return false;
3008 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
3010 /* we have to also set FLAG_CMDLINE on aliases */
3011 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
3012 lp_ctx->flags[i] |= FLAG_CMDLINE;
3014 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
3015 lp_ctx->flags[i] |= FLAG_CMDLINE;
3018 return true;
3022 set a option from the commandline in 'a=b' format. Use to support --option
3024 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
3026 char *p, *s;
3027 bool ret;
3029 s = talloc_strdup(NULL, option);
3030 if (!s) {
3031 return false;
3034 p = strchr(s, '=');
3035 if (!p) {
3036 talloc_free(s);
3037 return false;
3040 *p = 0;
3042 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
3043 talloc_free(s);
3044 return ret;
3048 #define BOOLSTR(b) ((b) ? "Yes" : "No")
3051 * Print a parameter of the specified type.
3054 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
3056 /* For the seperation of lists values that we print below */
3057 const char *list_sep = ", ";
3058 int i;
3059 switch (p->type)
3061 case P_ENUM:
3062 for (i = 0; p->enum_list[i].name; i++) {
3063 if (*(int *)ptr == p->enum_list[i].value) {
3064 fprintf(f, "%s",
3065 p->enum_list[i].name);
3066 break;
3069 break;
3071 case P_BOOL:
3072 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
3073 break;
3075 case P_BOOLREV:
3076 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
3077 break;
3079 case P_INTEGER:
3080 case P_BYTES:
3081 fprintf(f, "%d", *(int *)ptr);
3082 break;
3084 case P_CHAR:
3085 fprintf(f, "%c", *(char *)ptr);
3086 break;
3088 case P_OCTAL: {
3089 int val = *(int *)ptr;
3090 if (val == -1) {
3091 fprintf(f, "-1");
3092 } else {
3093 fprintf(f, "0%o", val);
3095 break;
3098 case P_CMDLIST:
3099 list_sep = " ";
3100 /* fall through */
3101 case P_LIST:
3102 if ((char ***)ptr && *(char ***)ptr) {
3103 char **list = *(char ***)ptr;
3104 for (; *list; list++) {
3105 /* surround strings with whitespace in double quotes */
3106 if (*(list+1) == NULL) {
3107 /* last item, no extra separator */
3108 list_sep = "";
3110 if ( strchr_m( *list, ' ' ) ) {
3111 fprintf(f, "\"%s\"%s", *list, list_sep);
3112 } else {
3113 fprintf(f, "%s%s", *list, list_sep);
3117 break;
3119 case P_STRING:
3120 case P_USTRING:
3121 if (*(char **)ptr) {
3122 fprintf(f, "%s", *(char **)ptr);
3124 break;
3125 case P_SEP:
3126 break;
3131 * Check if two parameters are equal.
3134 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
3136 switch (type) {
3137 case P_BOOL:
3138 case P_BOOLREV:
3139 return (*((bool *)ptr1) == *((bool *)ptr2));
3141 case P_INTEGER:
3142 case P_ENUM:
3143 case P_OCTAL:
3144 case P_BYTES:
3145 return (*((int *)ptr1) == *((int *)ptr2));
3147 case P_CHAR:
3148 return (*((char *)ptr1) == *((char *)ptr2));
3150 case P_LIST:
3151 case P_CMDLIST:
3152 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3154 case P_STRING:
3155 case P_USTRING:
3157 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3158 if (p1 && !*p1)
3159 p1 = NULL;
3160 if (p2 && !*p2)
3161 p2 = NULL;
3162 return (p1 == p2 || strequal(p1, p2));
3164 case P_SEP:
3165 break;
3167 return false;
3171 * Process a new section (service).
3173 * At this stage all sections are services.
3174 * Later we'll have special sections that permit server parameters to be set.
3175 * Returns True on success, False on failure.
3178 static bool do_section(const char *pszSectionName, void *userdata)
3180 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3181 bool bRetval;
3182 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3183 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3184 bRetval = false;
3186 /* if we've just struck a global section, note the fact. */
3187 lp_ctx->bInGlobalSection = isglobal;
3189 /* check for multiple global sections */
3190 if (lp_ctx->bInGlobalSection) {
3191 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3192 return true;
3195 /* if we have a current service, tidy it up before moving on */
3196 bRetval = true;
3198 if (lp_ctx->currentService != NULL)
3199 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3201 /* if all is still well, move to the next record in the services array */
3202 if (bRetval) {
3203 /* We put this here to avoid an odd message order if messages are */
3204 /* issued by the post-processing of a previous section. */
3205 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3207 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3208 pszSectionName))
3209 == NULL) {
3210 DEBUG(0, ("Failed to add a new service\n"));
3211 return false;
3215 return bRetval;
3220 * Determine if a particular base parameter is currently set to the default value.
3223 static bool is_default(struct loadparm_service *sDefault, int i)
3225 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3226 if (!defaults_saved)
3227 return false;
3228 switch (parm_table[i].type) {
3229 case P_CMDLIST:
3230 case P_LIST:
3231 return str_list_equal((const char **)parm_table[i].def.lvalue,
3232 (const char **)def_ptr);
3233 case P_STRING:
3234 case P_USTRING:
3235 return strequal(parm_table[i].def.svalue,
3236 *(char **)def_ptr);
3237 case P_BOOL:
3238 case P_BOOLREV:
3239 return parm_table[i].def.bvalue ==
3240 *(bool *)def_ptr;
3241 case P_INTEGER:
3242 case P_CHAR:
3243 case P_OCTAL:
3244 case P_BYTES:
3245 case P_ENUM:
3246 return parm_table[i].def.ivalue ==
3247 *(int *)def_ptr;
3248 case P_SEP:
3249 break;
3251 return false;
3255 *Display the contents of the global structure.
3258 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3259 bool show_defaults)
3261 int i;
3262 struct parmlist_entry *data;
3264 fprintf(f, "# Global parameters\n[global]\n");
3266 for (i = 0; parm_table[i].label; i++)
3267 if (parm_table[i].p_class == P_GLOBAL &&
3268 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3269 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3270 continue;
3271 fprintf(f, "\t%s = ", parm_table[i].label);
3272 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3273 fprintf(f, "\n");
3275 if (lp_ctx->globals->param_opt != NULL) {
3276 for (data = lp_ctx->globals->param_opt; data;
3277 data = data->next) {
3278 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3279 continue;
3281 fprintf(f, "\t%s = %s\n", data->key, data->value);
3288 * Display the contents of a single services record.
3291 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3292 unsigned int *flags)
3294 int i;
3295 struct parmlist_entry *data;
3297 if (pService != sDefault)
3298 fprintf(f, "\n[%s]\n", pService->szService);
3300 for (i = 0; parm_table[i].label; i++) {
3301 if (parm_table[i].p_class == P_LOCAL &&
3302 (*parm_table[i].label != '-') &&
3303 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3305 if (pService == sDefault) {
3306 if (flags && (flags[i] & FLAG_DEFAULT)) {
3307 continue;
3309 if (defaults_saved) {
3310 if (is_default(sDefault, i)) {
3311 continue;
3314 } else {
3315 if (equal_parameter(parm_table[i].type,
3316 ((char *)pService) +
3317 parm_table[i].offset,
3318 ((char *)sDefault) +
3319 parm_table[i].offset))
3320 continue;
3323 fprintf(f, "\t%s = ", parm_table[i].label);
3324 print_parameter(&parm_table[i],
3325 ((char *)pService) + parm_table[i].offset, f);
3326 fprintf(f, "\n");
3329 if (pService->param_opt != NULL) {
3330 for (data = pService->param_opt; data; data = data->next) {
3331 fprintf(f, "\t%s = %s\n", data->key, data->value);
3336 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3337 struct loadparm_service *service,
3338 const char *parm_name, FILE * f)
3340 struct parm_struct *parm;
3341 void *ptr;
3343 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3344 if (!parm) {
3345 return false;
3348 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3350 print_parameter(parm, ptr, f);
3351 fprintf(f, "\n");
3352 return true;
3356 * Return info about the next parameter in a service.
3357 * snum==-1 gives the globals.
3358 * Return NULL when out of parameters.
3362 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3363 int allparameters)
3365 if (snum == -1) {
3366 /* do the globals */
3367 for (; parm_table[*i].label; (*i)++) {
3368 if ((*parm_table[*i].label == '-'))
3369 continue;
3371 if ((*i) > 0
3372 && (parm_table[*i].offset ==
3373 parm_table[(*i) - 1].offset)
3374 && (parm_table[*i].p_class ==
3375 parm_table[(*i) - 1].p_class))
3376 continue;
3378 return &parm_table[(*i)++];
3380 } else {
3381 struct loadparm_service *pService = lp_ctx->services[snum];
3383 for (; parm_table[*i].label; (*i)++) {
3384 if (parm_table[*i].p_class == P_LOCAL &&
3385 (*parm_table[*i].label != '-') &&
3386 ((*i) == 0 ||
3387 (parm_table[*i].offset !=
3388 parm_table[(*i) - 1].offset)))
3390 if (allparameters ||
3391 !equal_parameter(parm_table[*i].type,
3392 ((char *)pService) +
3393 parm_table[*i].offset,
3394 ((char *)lp_ctx->sDefault) +
3395 parm_table[*i].offset))
3397 return &parm_table[(*i)++];
3403 return NULL;
3408 * Auto-load some home services.
3410 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3411 const char *str)
3413 return;
3418 * Unload unused services.
3421 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3422 struct smbsrv_connection *smb,
3423 bool (*snumused) (struct smbsrv_connection *, int))
3425 int i;
3426 for (i = 0; i < lp_ctx->iNumServices; i++) {
3427 if (lp_ctx->services[i] == NULL)
3428 continue;
3430 if (!snumused || !snumused(smb, i)) {
3431 talloc_free(lp_ctx->services[i]);
3432 lp_ctx->services[i] = NULL;
3438 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3440 struct parmlist_entry *data;
3442 if (lp_ctx->refuse_free) {
3443 /* someone is trying to free the
3444 global_loadparm_context.
3445 We can't allow that. */
3446 return -1;
3449 if (lp_ctx->globals->param_opt != NULL) {
3450 struct parmlist_entry *next;
3451 for (data = lp_ctx->globals->param_opt; data; data=next) {
3452 next = data->next;
3453 if (data->priority & FLAG_CMDLINE) continue;
3454 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3455 talloc_free(data);
3459 return 0;
3463 * Initialise the global parameter structure.
3465 * Note that most callers should use loadparm_init_global() instead
3467 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3469 int i;
3470 char *myname;
3471 struct loadparm_context *lp_ctx;
3472 struct parmlist_entry *parm;
3473 char *logfile;
3475 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3476 if (lp_ctx == NULL)
3477 return NULL;
3479 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3480 lp_ctx->bInGlobalSection = true;
3481 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3482 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3484 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3485 lp_ctx->sDefault->bAvailable = true;
3486 lp_ctx->sDefault->bBrowseable = true;
3487 lp_ctx->sDefault->bRead_only = true;
3488 lp_ctx->sDefault->bMap_archive = true;
3489 lp_ctx->sDefault->iStrictLocking = true;
3490 lp_ctx->sDefault->bOpLocks = true;
3491 lp_ctx->sDefault->iCreate_mask = 0744;
3492 lp_ctx->sDefault->iCreate_force_mode = 0000;
3493 lp_ctx->sDefault->iDir_mask = 0755;
3494 lp_ctx->sDefault->iDir_force_mode = 0000;
3496 DEBUG(3, ("Initialising global parameters\n"));
3498 for (i = 0; parm_table[i].label; i++) {
3499 if ((parm_table[i].type == P_STRING ||
3500 parm_table[i].type == P_USTRING) &&
3501 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3502 char **r;
3503 if (parm_table[i].p_class == P_LOCAL) {
3504 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3505 } else {
3506 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3508 *r = talloc_strdup(lp_ctx, "");
3512 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3513 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3514 talloc_free(logfile);
3516 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3518 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3520 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3521 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3522 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3524 /* options that can be set on the command line must be initialised via
3525 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3526 #ifdef TCP_NODELAY
3527 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3528 #endif
3529 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3530 myname = get_myname(lp_ctx);
3531 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3532 talloc_free(myname);
3533 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3535 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3537 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3538 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3540 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
3541 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3542 /* the winbind method for domain controllers is for both RODC
3543 auth forwarding and for trusted domains */
3544 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3545 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3547 /* This hive should be dynamically generated by Samba using
3548 data from the sam, but for the moment leave it in a tdb to
3549 keep regedt32 from popping up an annoying dialog. */
3550 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3552 /* using UTF8 by default allows us to support all chars */
3553 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3555 /* Use codepage 850 as a default for the dos character set */
3556 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3559 * Allow the default PASSWD_CHAT to be overridden in local.h.
3561 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3563 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3564 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3565 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3566 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3567 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3569 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3570 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3571 "Samba %s", SAMBA_VERSION_STRING);
3573 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3575 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3576 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3577 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3579 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3580 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3581 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3582 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3583 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3584 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3585 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3586 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3587 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3588 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3589 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3590 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3591 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3593 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3594 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3595 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3596 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3597 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3598 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3599 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3600 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3602 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3604 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3605 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3607 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3608 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3610 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3611 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3612 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3613 #if _SAMBA_BUILD_ >= 4
3614 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3615 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3616 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3617 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3618 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3619 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3620 #endif
3621 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3622 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3624 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3625 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3627 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3629 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3631 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3632 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3633 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3634 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3635 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3636 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3637 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3639 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3641 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3642 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3644 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3645 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3646 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3647 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3648 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3650 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3651 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3653 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3654 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3655 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3657 for (i = 0; parm_table[i].label; i++) {
3658 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3659 lp_ctx->flags[i] |= FLAG_DEFAULT;
3663 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3664 if (!(parm->priority & FLAG_CMDLINE)) {
3665 parm->priority |= FLAG_DEFAULT;
3669 return lp_ctx;
3673 * Initialise the global parameter structure.
3675 struct loadparm_context *loadparm_init_global(bool load_default)
3677 if (global_loadparm_context == NULL) {
3678 global_loadparm_context = loadparm_init(NULL);
3680 if (global_loadparm_context == NULL) {
3681 return NULL;
3683 global_loadparm_context->global = true;
3684 if (load_default && !global_loadparm_context->loaded) {
3685 lpcfg_load_default(global_loadparm_context);
3687 global_loadparm_context->refuse_free = true;
3688 return global_loadparm_context;
3692 * Initialise the global parameter structure.
3694 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3695 const struct loadparm_s3_helpers *s3_fns)
3697 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3698 if (!loadparm_context) {
3699 return NULL;
3701 loadparm_context->s3_fns = s3_fns;
3702 return loadparm_context;
3705 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3707 return lp_ctx->szConfigFile;
3710 const char *lp_default_path(void)
3712 if (getenv("SMB_CONF_PATH"))
3713 return getenv("SMB_CONF_PATH");
3714 else
3715 return dyn_CONFIGFILE;
3719 * Update the internal state of a loadparm context after settings
3720 * have changed.
3722 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3724 struct debug_settings settings;
3725 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3727 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3728 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3731 if (!lp_ctx->global) {
3732 return true;
3735 panic_action = lp_ctx->globals->panic_action;
3737 reload_charcnv(lp_ctx);
3739 ZERO_STRUCT(settings);
3740 /* Add any more debug-related smb.conf parameters created in
3741 * future here */
3742 settings.timestamp_logs = true;
3743 debug_set_settings(&settings);
3745 /* FIXME: This is a bit of a hack, but we can't use a global, since
3746 * not everything that uses lp also uses the socket library */
3747 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3748 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3749 } else {
3750 unsetenv("SOCKET_TESTNONBLOCK");
3753 return true;
3756 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3758 const char *path;
3760 path = lp_default_path();
3762 if (!file_exist(path)) {
3763 /* We allow the default smb.conf file to not exist,
3764 * basically the equivalent of an empty file. */
3765 return lpcfg_update(lp_ctx);
3768 return lpcfg_load(lp_ctx, path);
3772 * Load the services array from the services file.
3774 * Return True on success, False on failure.
3776 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3778 char *n2;
3779 bool bRetval;
3781 filename = talloc_strdup(lp_ctx, filename);
3783 lp_ctx->szConfigFile = filename;
3785 if (lp_ctx->s3_fns) {
3786 return lp_ctx->s3_fns->load(filename);
3789 lp_ctx->bInGlobalSection = true;
3790 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3791 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3793 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3795 /* We get sections first, so have to start 'behind' to make up */
3796 lp_ctx->currentService = NULL;
3797 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3799 /* finish up the last section */
3800 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3801 if (bRetval)
3802 if (lp_ctx->currentService != NULL)
3803 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3805 bRetval = bRetval && lpcfg_update(lp_ctx);
3807 /* we do this unconditionally, so that it happens even
3808 for a missing smb.conf */
3809 reload_charcnv(lp_ctx);
3811 if (bRetval == true) {
3812 /* set this up so that any child python tasks will
3813 find the right smb.conf */
3814 setenv("SMB_CONF_PATH", filename, 1);
3816 /* set the context used by the lp_*() function
3817 varients */
3818 global_loadparm_context = lp_ctx;
3819 lp_ctx->loaded = true;
3822 return bRetval;
3826 * Return the max number of services.
3829 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3831 if (lp_ctx->s3_fns) {
3832 return lp_ctx->s3_fns->get_numservices();
3835 return lp_ctx->iNumServices;
3839 * Display the contents of the services array in human-readable form.
3842 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3843 int maxtoprint)
3845 int iService;
3847 if (lp_ctx->s3_fns) {
3848 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3849 return;
3852 defaults_saved = !show_defaults;
3854 dump_globals(lp_ctx, f, show_defaults);
3856 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3858 for (iService = 0; iService < maxtoprint; iService++)
3859 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3863 * Display the contents of one service in human-readable form.
3865 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3867 if (service != NULL) {
3868 if (service->szService[0] == '\0')
3869 return;
3870 dump_a_service(service, sDefault, f, NULL);
3874 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3875 int snum)
3877 if (lp_ctx->s3_fns) {
3878 return lp_ctx->s3_fns->get_servicebynum(snum);
3881 return lp_ctx->services[snum];
3884 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3885 const char *service_name)
3887 int iService;
3888 char *serviceName;
3890 if (lp_ctx->s3_fns) {
3891 return lp_ctx->s3_fns->get_service(service_name);
3894 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3895 if (lp_ctx->services[iService] &&
3896 lp_ctx->services[iService]->szService) {
3898 * The substitution here is used to support %U is
3899 * service names
3901 serviceName = standard_sub_basic(
3902 lp_ctx->services[iService],
3903 lp_ctx->services[iService]->szService);
3904 if (strequal(serviceName, service_name)) {
3905 talloc_free(serviceName);
3906 return lp_ctx->services[iService];
3908 talloc_free(serviceName);
3912 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3913 return NULL;
3916 const char *lpcfg_servicename(const struct loadparm_service *service)
3918 return lp_string((const char *)service->szService);
3922 * A useful volume label function.
3924 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3926 const char *ret;
3927 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3928 service->volume : sDefault->volume));
3929 if (!*ret)
3930 return lpcfg_servicename(service);
3931 return ret;
3935 * If we are PDC then prefer us as DMB
3937 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3939 const char *ret;
3940 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3941 service->szPrintername : sDefault->szPrintername));
3942 if (ret == NULL || (ret != NULL && *ret == '\0'))
3943 ret = lpcfg_servicename(service);
3945 return ret;
3950 * Return the max print jobs per queue.
3952 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3954 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3955 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3956 maxjobs = PRINT_MAX_JOBID - 1;
3958 return maxjobs;
3961 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3963 if (lp_ctx == NULL) {
3964 return get_iconv_handle();
3966 return lp_ctx->iconv_handle;
3969 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3971 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3972 if (!lp_ctx->global) {
3973 return;
3976 if (old_ic == NULL) {
3977 old_ic = global_iconv_handle;
3979 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3980 global_iconv_handle = lp_ctx->iconv_handle;
3983 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3985 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3988 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3990 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3993 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3995 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3998 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4000 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
4003 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4005 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
4008 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
4010 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
4011 if (settings == NULL)
4012 return NULL;
4013 SMB_ASSERT(lp_ctx != NULL);
4014 settings->lp_ctx = talloc_reference(settings, lp_ctx);
4015 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
4016 return settings;
4019 int lpcfg_server_role(struct loadparm_context *lp_ctx)
4021 int domain_master = lpcfg__domain_master(lp_ctx);
4023 return lp_find_server_role(lpcfg__server_role(lp_ctx),
4024 lpcfg__security(lp_ctx),
4025 lpcfg__domain_logons(lp_ctx),
4026 (domain_master == true) ||
4027 (domain_master == Auto));
4030 int lpcfg_security(struct loadparm_context *lp_ctx)
4032 return lp_find_security(lpcfg__server_role(lp_ctx),
4033 lpcfg__security(lp_ctx));