s4:torture: Add raw.session.reauth2 test
[Samba/bb.git] / lib / param / loadparm.c
blobd68d585617115b70d0615364f3550e8cd53701ea
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * Load parameters.
32 * This module provides suitable callback functions for the params
33 * module. It builds the internal table of service details which is
34 * then used by the rest of the server.
36 * To add a parameter:
38 * 1) add it to the global or service structure definition
39 * 2) add it to the parm_table
40 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
41 * 4) If it's a global then initialise it in init_globals. If a local
42 * (ie. service) parameter then initialise it in the sDefault structure
45 * Notes:
46 * The configuration file is processed sequentially for speed. It is NOT
47 * accessed randomly as happens in 'real' Windows. For this reason, there
48 * is a fair bit of sequence-dependent code here - ie., code which assumes
49 * that certain things happen before others. In particular, the code which
50 * happens at the boundary between sections is delicately poised, so be
51 * careful!
55 #include "includes.h"
56 #include "version.h"
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
65 #include "s3_param.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
68 #include "source4/dns_server/dns_update.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved = false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
77 char *szRealm; \
78 char *tls_keyfile; \
79 char *tls_certfile; \
80 char *tls_cafile; \
81 char *tls_crlfile; \
82 char *tls_dhpfile; \
83 char *loglevel; \
84 char *panic_action; \
85 int server_role; \
86 int security; \
87 int domain_master; \
88 int domain_logons; \
89 int bPreferredMaster;
91 #include "param_global.h"
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
96 /* prototypes for the special type handlers */
97 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
98 const char *pszParmValue, char **ptr);
99 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
100 const char *pszParmValue, char **ptr);
101 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
102 const char *pszParmValue, char **ptr);
103 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
104 const char *pszParmValue, char **ptr);
105 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
106 const char *pszParmValue, char **ptr);
108 #include "param_enums.c"
110 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
111 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
113 static struct parm_struct parm_table[] = {
115 .label = "server role",
116 .type = P_ENUM,
117 .p_class = P_GLOBAL,
118 .offset = GLOBAL_VAR(server_role),
119 .special = NULL,
120 .enum_list = enum_server_role
123 .label = "domain logons",
124 .type = P_ENUM,
125 .p_class = P_GLOBAL,
126 .offset = GLOBAL_VAR(domain_logons),
127 .special = NULL,
128 .enum_list = enum_bool_auto
131 .label = "domain master",
132 .type = P_ENUM,
133 .p_class = P_GLOBAL,
134 .offset = GLOBAL_VAR(domain_master),
135 .special = NULL,
136 .enum_list = enum_bool_auto
139 .label = "dos charset",
140 .type = P_STRING,
141 .p_class = P_GLOBAL,
142 .offset = GLOBAL_VAR(dos_charset),
143 .special = NULL,
144 .enum_list = NULL
147 .label = "unix charset",
148 .type = P_STRING,
149 .p_class = P_GLOBAL,
150 .offset = GLOBAL_VAR(unix_charset),
151 .special = NULL,
152 .enum_list = NULL
155 .label = "ncalrpc dir",
156 .type = P_STRING,
157 .p_class = P_GLOBAL,
158 .offset = GLOBAL_VAR(ncalrpc_dir),
159 .special = NULL,
160 .enum_list = NULL
163 .label = "comment",
164 .type = P_STRING,
165 .p_class = P_LOCAL,
166 .offset = LOCAL_VAR(comment),
167 .special = NULL,
168 .enum_list = NULL,
169 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
172 .label = "path",
173 .type = P_STRING,
174 .p_class = P_LOCAL,
175 .offset = LOCAL_VAR(szPath),
176 .special = NULL,
177 .enum_list = NULL,
178 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
181 .label = "directory",
182 .type = P_STRING,
183 .p_class = P_LOCAL,
184 .offset = LOCAL_VAR(szPath),
185 .special = NULL,
186 .enum_list = NULL,
187 .flags = FLAG_HIDE,
190 .label = "workgroup",
191 .type = P_USTRING,
192 .p_class = P_GLOBAL,
193 .offset = GLOBAL_VAR(szWorkgroup),
194 .special = NULL,
195 .enum_list = NULL,
196 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
199 .label = "realm",
200 .type = P_STRING,
201 .p_class = P_GLOBAL,
202 .offset = GLOBAL_VAR(szRealm),
203 .special = handle_realm,
204 .enum_list = NULL,
205 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
208 .label = "netbios name",
209 .type = P_USTRING,
210 .p_class = P_GLOBAL,
211 .offset = GLOBAL_VAR(szNetbiosName),
212 .special = NULL,
213 .enum_list = NULL,
214 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
217 .label = "netbios aliases",
218 .type = P_LIST,
219 .p_class = P_GLOBAL,
220 .offset = GLOBAL_VAR(szNetbiosAliases),
221 .special = NULL,
222 .enum_list = NULL
225 .label = "netbios scope",
226 .type = P_USTRING,
227 .p_class = P_GLOBAL,
228 .offset = GLOBAL_VAR(szNetbiosScope),
229 .special = NULL,
230 .enum_list = NULL,
231 .flags = FLAG_ADVANCED,
234 .label = "server string",
235 .type = P_STRING,
236 .p_class = P_GLOBAL,
237 .offset = GLOBAL_VAR(szServerString),
238 .special = NULL,
239 .enum_list = NULL,
240 .flags = FLAG_BASIC | FLAG_ADVANCED,
243 .label = "interfaces",
244 .type = P_LIST,
245 .p_class = P_GLOBAL,
246 .offset = GLOBAL_VAR(szInterfaces),
247 .special = NULL,
248 .enum_list = NULL,
249 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
252 .label = "bind interfaces only",
253 .type = P_BOOL,
254 .p_class = P_GLOBAL,
255 .offset = GLOBAL_VAR(bBindInterfacesOnly),
256 .special = NULL,
257 .enum_list = NULL,
258 .flags = FLAG_ADVANCED | FLAG_WIZARD,
261 .label = "ntvfs handler",
262 .type = P_LIST,
263 .p_class = P_LOCAL,
264 .offset = LOCAL_VAR(ntvfs_handler),
265 .special = NULL,
266 .enum_list = NULL
269 .label = "ntptr providor",
270 .type = P_STRING,
271 .p_class = P_GLOBAL,
272 .offset = GLOBAL_VAR(ntptr_providor),
273 .special = NULL,
274 .enum_list = NULL
277 .label = "passdb backend",
278 .type = P_STRING,
279 .p_class = P_GLOBAL,
280 .offset = GLOBAL_VAR(passdb_backend),
281 .special = NULL,
282 .enum_list = NULL
285 .label = "dcerpc endpoint servers",
286 .type = P_LIST,
287 .p_class = P_GLOBAL,
288 .offset = GLOBAL_VAR(dcerpc_ep_servers),
289 .special = NULL,
290 .enum_list = NULL
293 .label = "server services",
294 .type = P_LIST,
295 .p_class = P_GLOBAL,
296 .offset = GLOBAL_VAR(server_services),
297 .special = NULL,
298 .enum_list = NULL
302 .label = "security",
303 .type = P_ENUM,
304 .p_class = P_GLOBAL,
305 .offset = GLOBAL_VAR(security),
306 .special = NULL,
307 .enum_list = enum_security
310 .label = "encrypt passwords",
311 .type = P_BOOL,
312 .p_class = P_GLOBAL,
313 .offset = GLOBAL_VAR(bEncryptPasswords),
314 .special = NULL,
315 .enum_list = NULL
318 .label = "null passwords",
319 .type = P_BOOL,
320 .p_class = P_GLOBAL,
321 .offset = GLOBAL_VAR(bNullPasswords),
322 .special = NULL,
323 .enum_list = NULL,
324 .flags = FLAG_ADVANCED | FLAG_DEPRECATED,
327 .label = "obey pam restrictions",
328 .type = P_BOOL,
329 .p_class = P_GLOBAL,
330 .offset = GLOBAL_VAR(bObeyPamRestrictions),
331 .special = NULL,
332 .enum_list = NULL,
333 .flags = FLAG_ADVANCED,
336 .label = "password server",
337 .type = P_LIST,
338 .p_class = P_GLOBAL,
339 .offset = GLOBAL_VAR(szPasswordServers),
340 .special = NULL,
341 .enum_list = NULL
344 .label = "private dir",
345 .type = P_STRING,
346 .p_class = P_GLOBAL,
347 .offset = GLOBAL_VAR(szPrivateDir),
348 .special = NULL,
349 .enum_list = NULL
352 .label = "passwd chat",
353 .type = P_STRING,
354 .p_class = P_GLOBAL,
355 .offset = GLOBAL_VAR(szPasswdChat),
356 .special = NULL,
357 .enum_list = NULL
360 .label = "password level",
361 .type = P_INTEGER,
362 .p_class = P_GLOBAL,
363 .offset = GLOBAL_VAR(pwordlevel),
364 .special = NULL,
365 .enum_list = NULL
368 .label = "lanman auth",
369 .type = P_BOOL,
370 .p_class = P_GLOBAL,
371 .offset = GLOBAL_VAR(bLanmanAuth),
372 .special = NULL,
373 .enum_list = NULL,
374 .flags = FLAG_ADVANCED,
377 .label = "ntlm auth",
378 .type = P_BOOL,
379 .p_class = P_GLOBAL,
380 .offset = GLOBAL_VAR(bNTLMAuth),
381 .special = NULL,
382 .enum_list = NULL,
383 .flags = FLAG_ADVANCED,
386 .label = "client NTLMv2 auth",
387 .type = P_BOOL,
388 .p_class = P_GLOBAL,
389 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
390 .special = NULL,
391 .enum_list = NULL,
392 .flags = FLAG_ADVANCED,
395 .label = "client lanman auth",
396 .type = P_BOOL,
397 .p_class = P_GLOBAL,
398 .offset = GLOBAL_VAR(bClientLanManAuth),
399 .special = NULL,
400 .enum_list = NULL,
401 .flags = FLAG_ADVANCED,
404 .label = "client plaintext auth",
405 .type = P_BOOL,
406 .p_class = P_GLOBAL,
407 .offset = GLOBAL_VAR(bClientPlaintextAuth),
408 .special = NULL,
409 .enum_list = NULL,
410 .flags = FLAG_ADVANCED,
413 .label = "client use spnego principal",
414 .type = P_BOOL,
415 .p_class = P_GLOBAL,
416 .offset = GLOBAL_VAR(client_use_spnego_principal),
417 .special = NULL,
418 .enum_list = NULL
422 .label = "read only",
423 .type = P_BOOL,
424 .p_class = P_LOCAL,
425 .offset = LOCAL_VAR(bRead_only),
426 .special = NULL,
427 .enum_list = NULL
431 .label = "create mask",
432 .type = P_OCTAL,
433 .p_class = P_LOCAL,
434 .offset = LOCAL_VAR(iCreate_mask),
435 .special = NULL,
436 .enum_list = NULL
439 .label = "force create mode",
440 .type = P_OCTAL,
441 .p_class = P_LOCAL,
442 .offset = LOCAL_VAR(iCreate_force_mode),
443 .special = NULL,
444 .enum_list = NULL
447 .label = "directory mask",
448 .type = P_OCTAL,
449 .p_class = P_LOCAL,
450 .offset = LOCAL_VAR(iDir_mask),
451 .special = NULL,
452 .enum_list = NULL
455 .label = "force directory mode",
456 .type = P_OCTAL,
457 .p_class = P_LOCAL,
458 .offset = LOCAL_VAR(iDir_force_mode),
459 .special = NULL,
460 .enum_list = NULL
464 .label = "hosts allow",
465 .type = P_LIST,
466 .p_class = P_LOCAL,
467 .offset = LOCAL_VAR(szHostsallow),
468 .special = NULL,
469 .enum_list = NULL
472 .label = "hosts deny",
473 .type = P_LIST,
474 .p_class = P_LOCAL,
475 .offset = LOCAL_VAR(szHostsdeny),
476 .special = NULL,
477 .enum_list = NULL
481 .label = "log level",
482 .type = P_STRING,
483 .p_class = P_GLOBAL,
484 .offset = GLOBAL_VAR(loglevel),
485 .special = handle_debuglevel,
486 .enum_list = NULL
489 .label = "debuglevel",
490 .type = P_STRING,
491 .p_class = P_GLOBAL,
492 .offset = GLOBAL_VAR(loglevel),
493 .special = handle_debuglevel,
494 .enum_list = NULL
497 .label = "log file",
498 .type = P_STRING,
499 .p_class = P_GLOBAL,
500 .offset = GLOBAL_VAR(logfile),
501 .special = handle_logfile,
502 .enum_list = NULL,
503 .flags = FLAG_ADVANCED,
507 .label = "smb ports",
508 .type = P_LIST,
509 .p_class = P_GLOBAL,
510 .offset = GLOBAL_VAR(smb_ports),
511 .special = NULL,
512 .enum_list = NULL
515 .label = "nbt port",
516 .type = P_INTEGER,
517 .p_class = P_GLOBAL,
518 .offset = GLOBAL_VAR(nbt_port),
519 .special = NULL,
520 .enum_list = NULL
523 .label = "dgram port",
524 .type = P_INTEGER,
525 .p_class = P_GLOBAL,
526 .offset = GLOBAL_VAR(dgram_port),
527 .special = NULL,
528 .enum_list = NULL
531 .label = "cldap port",
532 .type = P_INTEGER,
533 .p_class = P_GLOBAL,
534 .offset = GLOBAL_VAR(cldap_port),
535 .special = NULL,
536 .enum_list = NULL
539 .label = "krb5 port",
540 .type = P_INTEGER,
541 .p_class = P_GLOBAL,
542 .offset = GLOBAL_VAR(krb5_port),
543 .special = NULL,
544 .enum_list = NULL
547 .label = "kpasswd port",
548 .type = P_INTEGER,
549 .p_class = P_GLOBAL,
550 .offset = GLOBAL_VAR(kpasswd_port),
551 .special = NULL,
552 .enum_list = NULL
555 .label = "web port",
556 .type = P_INTEGER,
557 .p_class = P_GLOBAL,
558 .offset = GLOBAL_VAR(web_port),
559 .special = NULL,
560 .enum_list = NULL
563 .label = "tls enabled",
564 .type = P_BOOL,
565 .p_class = P_GLOBAL,
566 .offset = GLOBAL_VAR(tls_enabled),
567 .special = NULL,
568 .enum_list = NULL
571 .label = "tls keyfile",
572 .type = P_STRING,
573 .p_class = P_GLOBAL,
574 .offset = GLOBAL_VAR(tls_keyfile),
575 .special = NULL,
576 .enum_list = NULL
579 .label = "tls certfile",
580 .type = P_STRING,
581 .p_class = P_GLOBAL,
582 .offset = GLOBAL_VAR(tls_certfile),
583 .special = NULL,
584 .enum_list = NULL
587 .label = "tls cafile",
588 .type = P_STRING,
589 .p_class = P_GLOBAL,
590 .offset = GLOBAL_VAR(tls_cafile),
591 .special = NULL,
592 .enum_list = NULL
595 .label = "tls crlfile",
596 .type = P_STRING,
597 .p_class = P_GLOBAL,
598 .offset = GLOBAL_VAR(tls_crlfile),
599 .special = NULL,
600 .enum_list = NULL
603 .label = "tls dh params file",
604 .type = P_STRING,
605 .p_class = P_GLOBAL,
606 .offset = GLOBAL_VAR(tls_dhpfile),
607 .special = NULL,
608 .enum_list = NULL
611 .label = "large readwrite",
612 .type = P_BOOL,
613 .p_class = P_GLOBAL,
614 .offset = GLOBAL_VAR(bLargeReadwrite),
615 .special = NULL,
616 .enum_list = NULL,
617 .flags = FLAG_ADVANCED,
620 .label = "server max protocol",
621 .type = P_ENUM,
622 .p_class = P_GLOBAL,
623 .offset = GLOBAL_VAR(srv_maxprotocol),
624 .special = NULL,
625 .enum_list = enum_protocol
628 .label = "max protocol",
629 .type = P_ENUM,
630 .p_class = P_GLOBAL,
631 .offset = GLOBAL_VAR(srv_maxprotocol),
632 .special = NULL,
633 .enum_list = enum_protocol
636 .label = "protocol",
637 .type = P_ENUM,
638 .p_class = P_GLOBAL,
639 .offset = GLOBAL_VAR(srv_maxprotocol),
640 .special = NULL,
641 .enum_list = enum_protocol,
642 .flags = FLAG_ADVANCED,
645 .label = "server min protocol",
646 .type = P_ENUM,
647 .p_class = P_GLOBAL,
648 .offset = GLOBAL_VAR(srv_minprotocol),
649 .special = NULL,
650 .enum_list = enum_protocol
653 .label = "min protocol",
654 .type = P_ENUM,
655 .p_class = P_GLOBAL,
656 .offset = GLOBAL_VAR(srv_minprotocol),
657 .special = NULL,
658 .enum_list = enum_protocol
661 .label = "client max protocol",
662 .type = P_ENUM,
663 .p_class = P_GLOBAL,
664 .offset = GLOBAL_VAR(cli_maxprotocol),
665 .special = NULL,
666 .enum_list = enum_protocol
669 .label = "client min protocol",
670 .type = P_ENUM,
671 .p_class = P_GLOBAL,
672 .offset = GLOBAL_VAR(cli_minprotocol),
673 .special = NULL,
674 .enum_list = enum_protocol
677 .label = "unicode",
678 .type = P_BOOL,
679 .p_class = P_GLOBAL,
680 .offset = GLOBAL_VAR(bUnicode),
681 .special = NULL,
682 .enum_list = NULL
685 .label = "read raw",
686 .type = P_BOOL,
687 .p_class = P_GLOBAL,
688 .offset = GLOBAL_VAR(bReadRaw),
689 .special = NULL,
690 .enum_list = NULL
693 .label = "write raw",
694 .type = P_BOOL,
695 .p_class = P_GLOBAL,
696 .offset = GLOBAL_VAR(bWriteRaw),
697 .special = NULL,
698 .enum_list = NULL
701 .label = "disable netbios",
702 .type = P_BOOL,
703 .p_class = P_GLOBAL,
704 .offset = GLOBAL_VAR(bDisableNetbios),
705 .special = NULL,
706 .enum_list = NULL
710 .label = "nt status support",
711 .type = P_BOOL,
712 .p_class = P_GLOBAL,
713 .offset = GLOBAL_VAR(bNTStatusSupport),
714 .special = NULL,
715 .enum_list = NULL
719 .label = "max mux",
720 .type = P_INTEGER,
721 .p_class = P_GLOBAL,
722 .offset = GLOBAL_VAR(max_mux),
723 .special = NULL,
724 .enum_list = NULL,
725 .flags = FLAG_ADVANCED,
728 .label = "max xmit",
729 .type = P_BYTES,
730 .p_class = P_GLOBAL,
731 .offset = GLOBAL_VAR(max_xmit),
732 .special = NULL,
733 .enum_list = NULL,
734 .flags = FLAG_ADVANCED,
738 .label = "name resolve order",
739 .type = P_LIST,
740 .p_class = P_GLOBAL,
741 .offset = GLOBAL_VAR(szNameResolveOrder),
742 .special = NULL,
743 .enum_list = NULL
746 .label = "max wins ttl",
747 .type = P_INTEGER,
748 .p_class = P_GLOBAL,
749 .offset = GLOBAL_VAR(max_wins_ttl),
750 .special = NULL,
751 .enum_list = NULL,
752 .flags = FLAG_ADVANCED,
755 .label = "min wins ttl",
756 .type = P_INTEGER,
757 .p_class = P_GLOBAL,
758 .offset = GLOBAL_VAR(min_wins_ttl),
759 .special = NULL,
760 .enum_list = NULL,
761 .flags = FLAG_ADVANCED,
764 .label = "time server",
765 .type = P_BOOL,
766 .p_class = P_GLOBAL,
767 .offset = GLOBAL_VAR(bTimeServer),
768 .special = NULL,
769 .enum_list = NULL,
770 .flags = FLAG_ADVANCED,
773 .label = "unix extensions",
774 .type = P_BOOL,
775 .p_class = P_GLOBAL,
776 .offset = GLOBAL_VAR(bUnixExtensions),
777 .special = NULL,
778 .enum_list = NULL,
779 .flags = FLAG_ADVANCED,
782 .label = "use spnego",
783 .type = P_BOOL,
784 .p_class = P_GLOBAL,
785 .offset = GLOBAL_VAR(bUseSpnego),
786 .special = NULL,
787 .enum_list = NULL
790 .label = "server signing",
791 .type = P_ENUM,
792 .p_class = P_GLOBAL,
793 .offset = GLOBAL_VAR(server_signing),
794 .special = NULL,
795 .enum_list = enum_smb_signing_vals,
796 .flags = FLAG_ADVANCED,
799 .label = "client signing",
800 .type = P_ENUM,
801 .p_class = P_GLOBAL,
802 .offset = GLOBAL_VAR(client_signing),
803 .special = NULL,
804 .enum_list = enum_smb_signing_vals
807 .label = "rpc big endian",
808 .type = P_BOOL,
809 .p_class = P_GLOBAL,
810 .offset = GLOBAL_VAR(bRpcBigEndian),
811 .special = NULL,
812 .enum_list = NULL
816 .label = "max connections",
817 .type = P_INTEGER,
818 .p_class = P_LOCAL,
819 .offset = LOCAL_VAR(iMaxConnections),
820 .special = NULL,
821 .enum_list = NULL,
822 .flags = FLAG_ADVANCED | FLAG_SHARE,
825 .label = "paranoid server security",
826 .type = P_BOOL,
827 .p_class = P_GLOBAL,
828 .offset = GLOBAL_VAR(paranoid_server_security),
829 .special = NULL,
830 .enum_list = NULL
833 .label = "socket options",
834 .type = P_STRING,
835 .p_class = P_GLOBAL,
836 .offset = GLOBAL_VAR(socket_options),
837 .special = NULL,
838 .enum_list = NULL
842 .label = "strict sync",
843 .type = P_BOOL,
844 .p_class = P_LOCAL,
845 .offset = LOCAL_VAR(bStrictSync),
846 .special = NULL,
847 .enum_list = NULL
850 .label = "use mmap",
851 .type = P_BOOL,
852 .p_class = P_GLOBAL,
853 .offset = GLOBAL_VAR(bUseMmap),
854 .special = NULL,
855 .enum_list = NULL,
856 .flags = FLAG_ADVANCED,
859 .label = "case insensitive filesystem",
860 .type = P_BOOL,
861 .p_class = P_LOCAL,
862 .offset = LOCAL_VAR(bCIFileSystem),
863 .special = NULL,
864 .enum_list = NULL
868 .label = "max print jobs",
869 .type = P_INTEGER,
870 .p_class = P_LOCAL,
871 .offset = LOCAL_VAR(iMaxPrintJobs),
872 .special = NULL,
873 .enum_list = NULL
876 .label = "printable",
877 .type = P_BOOL,
878 .p_class = P_LOCAL,
879 .offset = LOCAL_VAR(bPrint_ok),
880 .special = NULL,
881 .enum_list = NULL
884 .label = "print ok",
885 .type = P_BOOL,
886 .p_class = P_LOCAL,
887 .offset = LOCAL_VAR(bPrint_ok),
888 .special = NULL,
889 .enum_list = NULL
893 .label = "printer name",
894 .type = P_STRING,
895 .p_class = P_LOCAL,
896 .offset = LOCAL_VAR(szPrintername),
897 .special = NULL,
898 .enum_list = NULL,
899 .flags = FLAG_ADVANCED | FLAG_PRINT,
902 .label = "printer",
903 .type = P_STRING,
904 .p_class = P_LOCAL,
905 .offset = LOCAL_VAR(szPrintername),
906 .special = NULL,
907 .enum_list = NULL,
908 .flags = FLAG_HIDE,
912 .label = "map system",
913 .type = P_BOOL,
914 .p_class = P_LOCAL,
915 .offset = LOCAL_VAR(bMap_system),
916 .special = NULL,
917 .enum_list = NULL
920 .label = "map hidden",
921 .type = P_BOOL,
922 .p_class = P_LOCAL,
923 .offset = LOCAL_VAR(bMap_hidden),
924 .special = NULL,
925 .enum_list = NULL
928 .label = "map archive",
929 .type = P_BOOL,
930 .p_class = P_LOCAL,
931 .offset = LOCAL_VAR(bMap_archive),
932 .special = NULL,
933 .enum_list = NULL
937 .label = "preferred master",
938 .type = P_ENUM,
939 .p_class = P_GLOBAL,
940 .offset = GLOBAL_VAR(bPreferredMaster),
941 .special = NULL,
942 .enum_list = enum_bool_auto,
943 .flags = FLAG_BASIC | FLAG_ADVANCED,
946 .label = "prefered master",
947 .type = P_ENUM,
948 .p_class = P_GLOBAL,
949 .offset = GLOBAL_VAR(bPreferredMaster),
950 .special = NULL,
951 .enum_list = enum_bool_auto,
952 .flags = FLAG_HIDE,
955 .label = "local master",
956 .type = P_BOOL,
957 .p_class = P_GLOBAL,
958 .offset = GLOBAL_VAR(bLocalMaster),
959 .special = NULL,
960 .enum_list = NULL
963 .label = "browseable",
964 .type = P_BOOL,
965 .p_class = P_LOCAL,
966 .offset = LOCAL_VAR(bBrowseable),
967 .special = NULL,
968 .enum_list = NULL,
969 .flags = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
972 .label = "browsable",
973 .type = P_BOOL,
974 .p_class = P_LOCAL,
975 .offset = LOCAL_VAR(bBrowseable),
976 .special = NULL,
977 .enum_list = NULL
981 .label = "dns proxy",
982 .type = P_BOOL,
983 .p_class = P_GLOBAL,
984 .offset = GLOBAL_VAR(bWINSdnsProxy),
985 .special = NULL,
986 .enum_list = NULL
989 .label = "wins server",
990 .type = P_LIST,
991 .p_class = P_GLOBAL,
992 .offset = GLOBAL_VAR(szWINSservers),
993 .special = NULL,
994 .enum_list = NULL
997 .label = "wins support",
998 .type = P_BOOL,
999 .p_class = P_GLOBAL,
1000 .offset = GLOBAL_VAR(bWINSsupport),
1001 .special = NULL,
1002 .enum_list = NULL
1005 .label = "wins hook",
1006 .type = P_STRING,
1007 .p_class = P_GLOBAL,
1008 .offset = GLOBAL_VAR(szWINSHook),
1009 .special = NULL,
1010 .enum_list = NULL,
1011 .flags = FLAG_ADVANCED,
1015 .label = "csc policy",
1016 .type = P_ENUM,
1017 .p_class = P_LOCAL,
1018 .offset = LOCAL_VAR(iCSCPolicy),
1019 .special = NULL,
1020 .enum_list = enum_csc_policy,
1021 .flags = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1025 .label = "strict locking",
1026 .type = P_BOOL,
1027 .p_class = P_LOCAL,
1028 .offset = LOCAL_VAR(iStrictLocking),
1029 .special = NULL,
1030 .enum_list = NULL
1033 .label = "oplocks",
1034 .type = P_BOOL,
1035 .p_class = P_LOCAL,
1036 .offset = LOCAL_VAR(bOpLocks),
1037 .special = NULL,
1038 .enum_list = NULL
1042 .label = "share backend",
1043 .type = P_STRING,
1044 .p_class = P_GLOBAL,
1045 .offset = GLOBAL_VAR(szShareBackend),
1046 .special = NULL,
1047 .enum_list = NULL
1050 .label = "preload",
1051 .type = P_STRING,
1052 .p_class = P_GLOBAL,
1053 .offset = GLOBAL_VAR(szAutoServices),
1054 .special = NULL,
1055 .enum_list = NULL,
1056 .flags = FLAG_ADVANCED,
1059 .label = "auto services",
1060 .type = P_STRING,
1061 .p_class = P_GLOBAL,
1062 .offset = GLOBAL_VAR(szAutoServices),
1063 .special = NULL,
1064 .enum_list = NULL,
1065 .flags = FLAG_ADVANCED,
1068 .label = "lock directory",
1069 .type = P_STRING,
1070 .p_class = P_GLOBAL,
1071 .offset = GLOBAL_VAR(szLockDir),
1072 .special = NULL,
1073 .enum_list = NULL,
1074 .flags = FLAG_ADVANCED,
1077 .label = "lock dir",
1078 .type = P_STRING,
1079 .p_class = P_GLOBAL,
1080 .offset = GLOBAL_VAR(szLockDir),
1081 .special = NULL,
1082 .enum_list = NULL,
1083 .flags = FLAG_HIDE,
1086 .label = "state directory",
1087 .type = P_STRING,
1088 .p_class = P_GLOBAL,
1089 .offset = GLOBAL_VAR(szStateDir),
1090 .special = NULL,
1091 .enum_list = NULL,
1092 .flags = FLAG_ADVANCED,
1095 .label = "cache directory",
1096 .type = P_STRING,
1097 .p_class = P_GLOBAL,
1098 .offset = GLOBAL_VAR(szCacheDir),
1099 .special = NULL,
1100 .enum_list = NULL,
1101 .flags = FLAG_ADVANCED,
1104 .label = "pid directory",
1105 .type = P_STRING,
1106 .p_class = P_GLOBAL,
1107 .offset = GLOBAL_VAR(szPidDir),
1108 .special = NULL,
1109 .enum_list = NULL
1113 .label = "socket address",
1114 .type = P_STRING,
1115 .p_class = P_GLOBAL,
1116 .offset = GLOBAL_VAR(szSocketAddress),
1117 .special = NULL,
1118 .enum_list = NULL
1121 .label = "copy",
1122 .type = P_STRING,
1123 .p_class = P_LOCAL,
1124 .offset = LOCAL_VAR(szCopy),
1125 .special = handle_copy,
1126 .enum_list = NULL,
1127 .flags = FLAG_HIDE,
1130 .label = "include",
1131 .type = P_STRING,
1132 .p_class = P_LOCAL,
1133 .offset = LOCAL_VAR(szInclude),
1134 .special = handle_include,
1135 .enum_list = NULL
1139 .label = "available",
1140 .type = P_BOOL,
1141 .p_class = P_LOCAL,
1142 .offset = LOCAL_VAR(bAvailable),
1143 .special = NULL,
1144 .enum_list = NULL
1147 .label = "volume",
1148 .type = P_STRING,
1149 .p_class = P_LOCAL,
1150 .offset = LOCAL_VAR(volume),
1151 .special = NULL,
1152 .enum_list = NULL,
1153 .flags = FLAG_ADVANCED | FLAG_SHARE,
1156 .label = "fstype",
1157 .type = P_STRING,
1158 .p_class = P_LOCAL,
1159 .offset = LOCAL_VAR(fstype),
1160 .special = NULL,
1161 .enum_list = NULL
1165 .label = "panic action",
1166 .type = P_STRING,
1167 .p_class = P_GLOBAL,
1168 .offset = GLOBAL_VAR(panic_action),
1169 .special = NULL,
1170 .enum_list = NULL
1174 .label = "msdfs root",
1175 .type = P_BOOL,
1176 .p_class = P_LOCAL,
1177 .offset = LOCAL_VAR(bMSDfsRoot),
1178 .special = NULL,
1179 .enum_list = NULL
1182 .label = "host msdfs",
1183 .type = P_BOOL,
1184 .p_class = P_GLOBAL,
1185 .offset = GLOBAL_VAR(bHostMSDfs),
1186 .special = NULL,
1187 .enum_list = NULL,
1188 .flags = FLAG_ADVANCED,
1191 .label = "winbind separator",
1192 .type = P_STRING,
1193 .p_class = P_GLOBAL,
1194 .offset = GLOBAL_VAR(szWinbindSeparator),
1195 .special = NULL,
1196 .enum_list = NULL
1199 .label = "winbindd socket directory",
1200 .type = P_STRING,
1201 .p_class = P_GLOBAL,
1202 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1203 .special = NULL,
1204 .enum_list = NULL,
1205 .flags = FLAG_ADVANCED,
1208 .label = "winbindd privileged socket directory",
1209 .type = P_STRING,
1210 .p_class = P_GLOBAL,
1211 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1212 .special = NULL,
1213 .enum_list = NULL,
1214 .flags = FLAG_ADVANCED,
1217 .label = "winbind sealed pipes",
1218 .type = P_BOOL,
1219 .p_class = P_GLOBAL,
1220 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1221 .special = NULL,
1222 .enum_list = NULL,
1223 .flags = FLAG_ADVANCED,
1226 .label = "template shell",
1227 .type = P_STRING,
1228 .p_class = P_GLOBAL,
1229 .offset = GLOBAL_VAR(szTemplateShell),
1230 .special = NULL,
1231 .enum_list = NULL,
1232 .flags = FLAG_ADVANCED,
1235 .label = "template homedir",
1236 .type = P_STRING,
1237 .p_class = P_GLOBAL,
1238 .offset = GLOBAL_VAR(szTemplateHomedir),
1239 .special = NULL,
1240 .enum_list = NULL,
1241 .flags = FLAG_ADVANCED,
1244 .label = "idmap trusted only",
1245 .type = P_BOOL,
1246 .p_class = P_GLOBAL,
1247 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1248 .special = NULL,
1249 .enum_list = NULL,
1250 .flags = FLAG_ADVANCED,
1254 .label = "ntp signd socket directory",
1255 .type = P_STRING,
1256 .p_class = P_GLOBAL,
1257 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1258 .special = NULL,
1259 .enum_list = NULL,
1260 .flags = FLAG_ADVANCED,
1263 .label = "rndc command",
1264 .type = P_CMDLIST,
1265 .p_class = P_GLOBAL,
1266 .offset = GLOBAL_VAR(szRNDCCommand),
1267 .special = NULL,
1268 .enum_list = NULL,
1269 .flags = FLAG_ADVANCED,
1272 .label = "dns update command",
1273 .type = P_CMDLIST,
1274 .p_class = P_GLOBAL,
1275 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1276 .special = NULL,
1277 .enum_list = NULL,
1278 .flags = FLAG_ADVANCED,
1281 .label = "spn update command",
1282 .type = P_CMDLIST,
1283 .p_class = P_GLOBAL,
1284 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1285 .special = NULL,
1286 .enum_list = NULL,
1287 .flags = FLAG_ADVANCED,
1290 .label = "samba kcc command",
1291 .type = P_CMDLIST,
1292 .p_class = P_GLOBAL,
1293 .offset = GLOBAL_VAR(szSambaKCCCommand),
1294 .special = NULL,
1295 .enum_list = NULL,
1296 .flags = FLAG_ADVANCED,
1299 .label = "nsupdate command",
1300 .type = P_CMDLIST,
1301 .p_class = P_GLOBAL,
1302 .offset = GLOBAL_VAR(szNSUpdateCommand),
1303 .special = NULL,
1304 .enum_list = NULL,
1305 .flags = FLAG_ADVANCED,
1308 .label = "allow dns updates",
1309 .type = P_ENUM,
1310 .p_class = P_GLOBAL,
1311 .offset = GLOBAL_VAR(allow_dns_updates),
1312 .special = NULL,
1313 .enum_list = enum_dns_update_settings,
1314 .flags = FLAG_ADVANCED,
1317 .label = "dns forwarder",
1318 .type = P_STRING,
1319 .p_class = P_GLOBAL,
1320 .offset = GLOBAL_VAR(dns_forwarder),
1321 .special = NULL,
1322 .enum_list = NULL,
1323 .flags = FLAG_ADVANCED,
1326 .label = "dns recursive queries",
1327 .type = P_BOOL,
1328 .p_class = P_GLOBAL,
1329 .offset = GLOBAL_VAR(dns_recursive_queries),
1330 .special = NULL,
1331 .enum_list = NULL
1334 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1338 /* local variables */
1339 struct loadparm_context {
1340 const char *szConfigFile;
1341 struct loadparm_global *globals;
1342 struct loadparm_service **services;
1343 struct loadparm_service *sDefault;
1344 struct smb_iconv_handle *iconv_handle;
1345 int iNumServices;
1346 struct loadparm_service *currentService;
1347 bool bInGlobalSection;
1348 struct file_lists {
1349 struct file_lists *next;
1350 char *name;
1351 char *subfname;
1352 time_t modtime;
1353 } *file_lists;
1354 unsigned int flags[NUMPARAMETERS];
1355 bool loaded;
1356 bool refuse_free;
1357 bool global; /* Is this the global context, which may set
1358 * global variables such as debug level etc? */
1359 const struct loadparm_s3_context *s3_fns;
1363 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1365 if (lp_ctx->s3_fns) {
1366 return lp_ctx->s3_fns->get_default_loadparm_service();
1368 return lp_ctx->sDefault;
1372 * Convenience routine to grab string parameters into temporary memory
1373 * and run standard_sub_basic on them.
1375 * The buffers can be written to by
1376 * callers without affecting the source string.
1379 static const char *lp_string(const char *s)
1381 #if 0 /* until REWRITE done to make thread-safe */
1382 size_t len = s ? strlen(s) : 0;
1383 char *ret;
1384 #endif
1386 /* The follow debug is useful for tracking down memory problems
1387 especially if you have an inner loop that is calling a lp_*()
1388 function that returns a string. Perhaps this debug should be
1389 present all the time? */
1391 #if 0
1392 DEBUG(10, ("lp_string(%s)\n", s));
1393 #endif
1395 #if 0 /* until REWRITE done to make thread-safe */
1396 if (!lp_talloc)
1397 lp_talloc = talloc_init("lp_talloc");
1399 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1401 if (!ret)
1402 return NULL;
1404 if (!s)
1405 *ret = 0;
1406 else
1407 strlcpy(ret, s, len);
1409 if (trim_string(ret, "\"", "\"")) {
1410 if (strchr(ret,'"') != NULL)
1411 strlcpy(ret, s, len);
1414 standard_sub_basic(ret,len+100);
1415 return (ret);
1416 #endif
1417 return s;
1421 In this section all the functions that are used to access the
1422 parameters from the rest of the program are defined
1426 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1427 * for code compatibility between existing Samba4 and Samba3 code.
1430 /* this global context supports the lp_*() function varients */
1431 static struct loadparm_context *global_loadparm_context;
1433 #define lpcfg_default_service global_loadparm_context->sDefault
1434 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1436 #define FN_GLOBAL_STRING(fn_name,var_name) \
1437 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1438 if (lp_ctx == NULL) return NULL; \
1439 if (lp_ctx->s3_fns) { \
1440 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1441 return lp_ctx->s3_fns->fn_name(); \
1443 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1446 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1447 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1448 if (lp_ctx == NULL) return NULL; \
1449 if (lp_ctx->s3_fns) { \
1450 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1451 return lp_ctx->s3_fns->fn_name(); \
1453 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1456 #define FN_GLOBAL_LIST(fn_name,var_name) \
1457 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1458 if (lp_ctx == NULL) return NULL; \
1459 if (lp_ctx->s3_fns) { \
1460 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1461 return lp_ctx->s3_fns->fn_name(); \
1463 return lp_ctx->globals->var_name; \
1466 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1467 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1468 if (lp_ctx == NULL) return false; \
1469 if (lp_ctx->s3_fns) { \
1470 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1471 return lp_ctx->s3_fns->fn_name(); \
1473 return lp_ctx->globals->var_name; \
1476 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1477 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1478 if (lp_ctx->s3_fns) { \
1479 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1480 return lp_ctx->s3_fns->fn_name(); \
1482 return lp_ctx->globals->var_name; \
1485 /* Local parameters don't need the ->s3_fns because the struct
1486 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1487 * hook */
1488 #define FN_LOCAL_STRING(fn_name,val) \
1489 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1490 struct loadparm_service *sDefault) { \
1491 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1494 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1496 #define FN_LOCAL_LIST(fn_name,val) \
1497 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1498 struct loadparm_service *sDefault) {\
1499 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1502 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1504 #define FN_LOCAL_BOOL(fn_name,val) \
1505 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1506 struct loadparm_service *sDefault) { \
1507 return((service != NULL)? service->val : sDefault->val); \
1510 #define FN_LOCAL_INTEGER(fn_name,val) \
1511 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1512 struct loadparm_service *sDefault) { \
1513 return((service != NULL)? service->val : sDefault->val); \
1516 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1518 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1520 #define FN_LOCAL_CHAR(fn_name,val) \
1521 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1522 struct loadparm_service *sDefault) { \
1523 return((service != NULL)? service->val : sDefault->val); \
1526 #include "lib/param/param_functions.c"
1528 FN_GLOBAL_LIST(smb_ports, smb_ports)
1529 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1530 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1531 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1532 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1533 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1534 FN_GLOBAL_INTEGER(web_port, web_port)
1535 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1536 FN_GLOBAL_STRING(logfile, logfile)
1537 FN_GLOBAL_STRING(share_backend, szShareBackend)
1538 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1539 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1540 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1541 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1542 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1543 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1544 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1545 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1546 FN_GLOBAL_STRING(serverstring, szServerString)
1547 FN_GLOBAL_STRING(lockdir, szLockDir)
1548 FN_GLOBAL_STRING(statedir, szStateDir)
1549 FN_GLOBAL_STRING(cachedir, szCacheDir)
1550 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1551 FN_GLOBAL_STRING(dos_charset, dos_charset)
1552 FN_GLOBAL_STRING(unix_charset, unix_charset)
1553 FN_GLOBAL_STRING(piddir, szPidDir)
1554 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1555 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1556 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1557 FN_GLOBAL_LIST(samba_kcc_command, szSambaKCCCommand)
1558 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1559 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1560 FN_GLOBAL_LIST(server_services, server_services)
1561 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1562 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1563 FN_GLOBAL_STRING(auto_services, szAutoServices)
1564 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1565 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1566 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1567 FN_GLOBAL_STRING(realm, szRealm_upper)
1568 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1569 FN_GLOBAL_STRING(socket_options, socket_options)
1570 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1571 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1572 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1573 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1574 FN_GLOBAL_LIST(interfaces, szInterfaces)
1575 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1576 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1577 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1578 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1579 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1580 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1581 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1582 FN_GLOBAL_BOOL(readraw, bReadRaw)
1583 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1584 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1585 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1586 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1587 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1588 FN_GLOBAL_BOOL(time_server, bTimeServer)
1589 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1590 FN_GLOBAL_BOOL(unicode, bUnicode)
1591 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1592 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1593 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1594 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1595 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1596 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1597 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1598 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1599 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1600 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1601 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1602 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1603 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1604 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1605 FN_GLOBAL_INTEGER(maxmux, max_mux)
1606 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1607 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1608 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1609 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1610 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1611 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1612 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1614 FN_GLOBAL_INTEGER(allow_dns_updates, allow_dns_updates)
1615 FN_GLOBAL_CONST_STRING(dns_forwarder, dns_forwarder)
1616 FN_GLOBAL_BOOL(dns_recursive_queries, dns_recursive_queries)
1618 FN_GLOBAL_INTEGER(server_signing, server_signing)
1619 FN_GLOBAL_INTEGER(client_signing, client_signing)
1621 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1623 /* local prototypes */
1624 static int map_parameter(const char *pszParmName);
1625 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1626 const char *pszServiceName);
1627 static void copy_service(struct loadparm_service *pserviceDest,
1628 struct loadparm_service *pserviceSource,
1629 struct bitmap *pcopymapDest);
1630 static bool lpcfg_service_ok(struct loadparm_service *service);
1631 static bool do_section(const char *pszSectionName, void *);
1632 static void init_copymap(struct loadparm_service *pservice);
1634 /* This is a helper function for parametrical options support. */
1635 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1636 /* Actual parametrical functions are quite simple */
1637 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1638 struct loadparm_service *service,
1639 const char *type, const char *option)
1641 char *vfskey_tmp = NULL;
1642 char *vfskey = NULL;
1643 struct parmlist_entry *data;
1645 if (lp_ctx == NULL)
1646 return NULL;
1648 if (lp_ctx->s3_fns) {
1649 return lp_ctx->s3_fns->get_parametric(service, type, option);
1652 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1654 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1655 if (vfskey_tmp == NULL) return NULL;
1656 vfskey = strlower_talloc(NULL, vfskey_tmp);
1657 talloc_free(vfskey_tmp);
1659 while (data) {
1660 if (strcmp(data->key, vfskey) == 0) {
1661 talloc_free(vfskey);
1662 return data->value;
1664 data = data->next;
1667 if (service != NULL) {
1668 /* Try to fetch the same option but from globals */
1669 /* but only if we are not already working with globals */
1670 for (data = lp_ctx->globals->param_opt; data;
1671 data = data->next) {
1672 if (strcmp(data->key, vfskey) == 0) {
1673 talloc_free(vfskey);
1674 return data->value;
1679 talloc_free(vfskey);
1681 return NULL;
1686 * convenience routine to return int parameters.
1688 static int lp_int(const char *s)
1691 if (!s) {
1692 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1693 return -1;
1696 return strtol(s, NULL, 0);
1700 * convenience routine to return unsigned long parameters.
1702 static unsigned long lp_ulong(const char *s)
1705 if (!s) {
1706 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1707 return -1;
1710 return strtoul(s, NULL, 0);
1714 * convenience routine to return unsigned long parameters.
1716 static long lp_long(const char *s)
1719 if (!s) {
1720 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1721 return -1;
1724 return strtol(s, NULL, 0);
1728 * convenience routine to return unsigned long parameters.
1730 static double lp_double(const char *s)
1733 if (!s) {
1734 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1735 return -1;
1738 return strtod(s, NULL);
1742 * convenience routine to return boolean parameters.
1744 static bool lp_bool(const char *s)
1746 bool ret = false;
1748 if (!s) {
1749 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1750 return false;
1753 if (!set_boolean(s, &ret)) {
1754 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1755 return false;
1758 return ret;
1763 * Return parametric option from a given service. Type is a part of option before ':'
1764 * Parametric option has following syntax: 'Type: option = value'
1765 * Returned value is allocated in 'lp_talloc' context
1768 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1769 struct loadparm_service *service, const char *type,
1770 const char *option)
1772 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1774 if (value)
1775 return lp_string(value);
1777 return NULL;
1781 * Return parametric option from a given service. Type is a part of option before ':'
1782 * Parametric option has following syntax: 'Type: option = value'
1783 * Returned value is allocated in 'lp_talloc' context
1786 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1787 struct loadparm_context *lp_ctx,
1788 struct loadparm_service *service,
1789 const char *type,
1790 const char *option, const char *separator)
1792 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1794 if (value != NULL)
1795 return (const char **)str_list_make(mem_ctx, value, separator);
1797 return NULL;
1801 * Return parametric option from a given service. Type is a part of option before ':'
1802 * Parametric option has following syntax: 'Type: option = value'
1805 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1806 struct loadparm_service *service, const char *type,
1807 const char *option, int default_v)
1809 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1811 if (value)
1812 return lp_int(value);
1814 return default_v;
1818 * Return parametric option from a given service. Type is a part of
1819 * option before ':'.
1820 * Parametric option has following syntax: 'Type: option = value'.
1823 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1824 struct loadparm_service *service, const char *type,
1825 const char *option, int default_v)
1827 uint64_t bval;
1829 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1831 if (value && conv_str_size_error(value, &bval)) {
1832 if (bval <= INT_MAX) {
1833 return (int)bval;
1837 return default_v;
1841 * Return parametric option from a given service.
1842 * Type is a part of option before ':'
1843 * Parametric option has following syntax: 'Type: option = value'
1845 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1846 struct loadparm_service *service, const char *type,
1847 const char *option, unsigned long default_v)
1849 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1851 if (value)
1852 return lp_ulong(value);
1854 return default_v;
1857 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1858 struct loadparm_service *service, const char *type,
1859 const char *option, long default_v)
1861 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1863 if (value)
1864 return lp_long(value);
1866 return default_v;
1869 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1870 struct loadparm_service *service, const char *type,
1871 const char *option, double default_v)
1873 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1875 if (value != NULL)
1876 return lp_double(value);
1878 return default_v;
1882 * Return parametric option from a given service. Type is a part of option before ':'
1883 * Parametric option has following syntax: 'Type: option = value'
1886 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1887 struct loadparm_service *service, const char *type,
1888 const char *option, bool default_v)
1890 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1892 if (value != NULL)
1893 return lp_bool(value);
1895 return default_v;
1900 * Initialise a service to the defaults.
1903 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1905 struct loadparm_service *pservice =
1906 talloc_zero(mem_ctx, struct loadparm_service);
1907 copy_service(pservice, sDefault, NULL);
1908 return pservice;
1912 * Set a string value, deallocating any existing space, and allocing the space
1913 * for the string
1915 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1917 talloc_free(*dest);
1919 if (src == NULL)
1920 src = "";
1922 *dest = talloc_strdup(mem_ctx, src);
1923 if ((*dest) == NULL) {
1924 DEBUG(0,("Out of memory in string_set\n"));
1925 return false;
1928 return true;
1932 * Set a string value, deallocating any existing space, and allocing the space
1933 * for the string
1935 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1937 talloc_free(*dest);
1939 if (src == NULL)
1940 src = "";
1942 *dest = strupper_talloc(mem_ctx, src);
1943 if ((*dest) == NULL) {
1944 DEBUG(0,("Out of memory in string_set_upper\n"));
1945 return false;
1948 return true;
1954 * Add a new service to the services array initialising it with the given
1955 * service.
1958 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1959 const struct loadparm_service *pservice,
1960 const char *name)
1962 int i;
1963 struct loadparm_service tservice;
1964 int num_to_alloc = lp_ctx->iNumServices + 1;
1965 struct parmlist_entry *data, *pdata;
1967 if (pservice == NULL) {
1968 pservice = lp_ctx->sDefault;
1971 tservice = *pservice;
1973 /* it might already exist */
1974 if (name) {
1975 struct loadparm_service *service = getservicebyname(lp_ctx,
1976 name);
1977 if (service != NULL) {
1978 /* Clean all parametric options for service */
1979 /* They will be added during parsing again */
1980 data = service->param_opt;
1981 while (data) {
1982 pdata = data->next;
1983 talloc_free(data);
1984 data = pdata;
1986 service->param_opt = NULL;
1987 return service;
1991 /* find an invalid one */
1992 for (i = 0; i < lp_ctx->iNumServices; i++)
1993 if (lp_ctx->services[i] == NULL)
1994 break;
1996 /* if not, then create one */
1997 if (i == lp_ctx->iNumServices) {
1998 struct loadparm_service **tsp;
2000 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2002 if (!tsp) {
2003 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2004 return NULL;
2005 } else {
2006 lp_ctx->services = tsp;
2007 lp_ctx->services[lp_ctx->iNumServices] = NULL;
2010 lp_ctx->iNumServices++;
2013 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2014 if (lp_ctx->services[i] == NULL) {
2015 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2016 return NULL;
2018 copy_service(lp_ctx->services[i], &tservice, NULL);
2019 if (name != NULL)
2020 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2021 return lp_ctx->services[i];
2025 * Add a new home service, with the specified home directory, defaults coming
2026 * from service ifrom.
2029 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2030 const char *pszHomename,
2031 struct loadparm_service *default_service,
2032 const char *user, const char *pszHomedir)
2034 struct loadparm_service *service;
2036 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2038 if (service == NULL)
2039 return false;
2041 if (!(*(default_service->szPath))
2042 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2043 service->szPath = talloc_strdup(service, pszHomedir);
2044 } else {
2045 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2048 if (!(*(service->comment))) {
2049 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2051 service->bAvailable = default_service->bAvailable;
2052 service->bBrowseable = default_service->bBrowseable;
2054 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2055 pszHomename, user, service->szPath));
2057 return true;
2061 * Add a new printer service, with defaults coming from service iFrom.
2064 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2065 const char *pszPrintername,
2066 struct loadparm_service *default_service)
2068 const char *comment = "From Printcap";
2069 struct loadparm_service *service;
2070 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2072 if (service == NULL)
2073 return false;
2075 /* note that we do NOT default the availability flag to True - */
2076 /* we take it from the default service passed. This allows all */
2077 /* dynamic printers to be disabled by disabling the [printers] */
2078 /* entry (if/when the 'available' keyword is implemented!). */
2080 /* the printer name is set to the service name. */
2081 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2082 lpcfg_string_set(service, &service->comment, comment);
2083 service->bBrowseable = default_service->bBrowseable;
2084 /* Printers cannot be read_only. */
2085 service->bRead_only = false;
2086 /* Printer services must be printable. */
2087 service->bPrint_ok = true;
2089 DEBUG(3, ("adding printer service %s\n", pszPrintername));
2091 return true;
2095 * Map a parameter's string representation to something we can use.
2096 * Returns False if the parameter string is not recognised, else TRUE.
2099 static int map_parameter(const char *pszParmName)
2101 int iIndex;
2103 if (*pszParmName == '-')
2104 return -1;
2106 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2107 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2108 return iIndex;
2110 /* Warn only if it isn't parametric option */
2111 if (strchr(pszParmName, ':') == NULL)
2112 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2113 /* We do return 'fail' for parametric options as well because they are
2114 stored in different storage
2116 return -1;
2121 return the parameter structure for a parameter
2123 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2125 int parmnum;
2127 if (lp_ctx->s3_fns) {
2128 return lp_ctx->s3_fns->get_parm_struct(name);
2131 parmnum = map_parameter(name);
2132 if (parmnum == -1) return NULL;
2133 return &parm_table[parmnum];
2137 return the parameter pointer for a parameter
2139 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2140 struct loadparm_service *service, struct parm_struct *parm)
2142 if (lp_ctx->s3_fns) {
2143 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2146 if (service == NULL) {
2147 if (parm->p_class == P_LOCAL)
2148 return ((char *)lp_ctx->sDefault)+parm->offset;
2149 else if (parm->p_class == P_GLOBAL)
2150 return ((char *)lp_ctx->globals)+parm->offset;
2151 else return NULL;
2152 } else {
2153 return ((char *)service) + parm->offset;
2158 return the parameter pointer for a parameter
2160 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2162 int parmnum;
2164 if (lp_ctx->s3_fns) {
2165 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2166 if (parm) {
2167 return parm->flags & FLAG_CMDLINE;
2169 return false;
2172 parmnum = map_parameter(name);
2173 if (parmnum == -1) return false;
2175 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2179 * Find a service by name. Otherwise works like get_service.
2182 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2183 const char *pszServiceName)
2185 int iService;
2187 if (lp_ctx->s3_fns) {
2188 return lp_ctx->s3_fns->get_service(pszServiceName);
2191 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2192 if (lp_ctx->services[iService] != NULL &&
2193 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2194 return lp_ctx->services[iService];
2197 return NULL;
2201 * Copy a service structure to another.
2202 * If pcopymapDest is NULL then copy all fields
2205 static void copy_service(struct loadparm_service *pserviceDest,
2206 struct loadparm_service *pserviceSource,
2207 struct bitmap *pcopymapDest)
2209 int i;
2210 bool bcopyall = (pcopymapDest == NULL);
2211 struct parmlist_entry *data, *pdata, *paramo;
2212 bool not_added;
2214 for (i = 0; parm_table[i].label; i++)
2215 if (parm_table[i].p_class == P_LOCAL &&
2216 (bcopyall || bitmap_query(pcopymapDest, i))) {
2217 void *src_ptr =
2218 ((char *)pserviceSource) + parm_table[i].offset;
2219 void *dest_ptr =
2220 ((char *)pserviceDest) + parm_table[i].offset;
2222 switch (parm_table[i].type) {
2223 case P_BOOL:
2224 *(bool *)dest_ptr = *(bool *)src_ptr;
2225 break;
2227 case P_INTEGER:
2228 case P_BYTES:
2229 case P_OCTAL:
2230 case P_ENUM:
2231 *(int *)dest_ptr = *(int *)src_ptr;
2232 break;
2234 case P_STRING:
2235 lpcfg_string_set(pserviceDest,
2236 (char **)dest_ptr,
2237 *(char **)src_ptr);
2238 break;
2240 case P_USTRING:
2241 lpcfg_string_set_upper(pserviceDest,
2242 (char **)dest_ptr,
2243 *(char **)src_ptr);
2244 break;
2245 case P_LIST:
2246 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2247 *(const char ***)src_ptr);
2248 break;
2249 default:
2250 break;
2254 if (bcopyall) {
2255 init_copymap(pserviceDest);
2256 if (pserviceSource->copymap)
2257 bitmap_copy(pserviceDest->copymap,
2258 pserviceSource->copymap);
2261 data = pserviceSource->param_opt;
2262 while (data) {
2263 not_added = true;
2264 pdata = pserviceDest->param_opt;
2265 /* Traverse destination */
2266 while (pdata) {
2267 /* If we already have same option, override it */
2268 if (strcmp(pdata->key, data->key) == 0) {
2269 talloc_free(pdata->value);
2270 pdata->value = talloc_strdup(pdata,
2271 data->value);
2272 not_added = false;
2273 break;
2275 pdata = pdata->next;
2277 if (not_added) {
2278 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2279 if (paramo == NULL)
2280 smb_panic("OOM");
2281 paramo->key = talloc_strdup(paramo, data->key);
2282 paramo->value = talloc_strdup(paramo, data->value);
2283 DLIST_ADD(pserviceDest->param_opt, paramo);
2285 data = data->next;
2290 * Check a service for consistency. Return False if the service is in any way
2291 * incomplete or faulty, else True.
2293 static bool lpcfg_service_ok(struct loadparm_service *service)
2295 bool bRetval;
2297 bRetval = true;
2298 if (service->szService[0] == '\0') {
2299 DEBUG(0, ("The following message indicates an internal error:\n"));
2300 DEBUG(0, ("No service name in service entry.\n"));
2301 bRetval = false;
2304 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2305 /* I can't see why you'd want a non-printable printer service... */
2306 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2307 if (!service->bPrint_ok) {
2308 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2309 service->szService));
2310 service->bPrint_ok = true;
2312 /* [printers] service must also be non-browsable. */
2313 if (service->bBrowseable)
2314 service->bBrowseable = false;
2317 /* If a service is flagged unavailable, log the fact at level 0. */
2318 if (!service->bAvailable)
2319 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2320 service->szService));
2322 return bRetval;
2326 /*******************************************************************
2327 Keep a linked list of all config files so we know when one has changed
2328 it's date and needs to be reloaded.
2329 ********************************************************************/
2331 static void add_to_file_list(struct loadparm_context *lp_ctx,
2332 const char *fname, const char *subfname)
2334 struct file_lists *f = lp_ctx->file_lists;
2336 while (f) {
2337 if (f->name && !strcmp(f->name, fname))
2338 break;
2339 f = f->next;
2342 if (!f) {
2343 f = talloc(lp_ctx, struct file_lists);
2344 if (!f)
2345 return;
2346 f->next = lp_ctx->file_lists;
2347 f->name = talloc_strdup(f, fname);
2348 if (!f->name) {
2349 talloc_free(f);
2350 return;
2352 f->subfname = talloc_strdup(f, subfname);
2353 if (!f->subfname) {
2354 talloc_free(f);
2355 return;
2357 lp_ctx->file_lists = f;
2358 f->modtime = file_modtime(subfname);
2359 } else {
2360 time_t t = file_modtime(subfname);
2361 if (t)
2362 f->modtime = t;
2366 /*******************************************************************
2367 Check if a config file has changed date.
2368 ********************************************************************/
2369 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2371 struct file_lists *f;
2372 DEBUG(6, ("lp_file_list_changed()\n"));
2374 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2375 char *n2;
2376 time_t mod_time;
2378 n2 = standard_sub_basic(lp_ctx, f->name);
2380 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2381 f->name, n2, ctime(&f->modtime)));
2383 mod_time = file_modtime(n2);
2385 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2386 DEBUGADD(6, ("file %s modified: %s\n", n2,
2387 ctime(&mod_time)));
2388 f->modtime = mod_time;
2389 talloc_free(f->subfname);
2390 f->subfname = talloc_strdup(f, n2);
2391 return true;
2394 return false;
2397 /***************************************************************************
2398 Handle the "realm" parameter
2399 ***************************************************************************/
2401 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2402 const char *pszParmValue, char **ptr)
2404 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2406 talloc_free(lp_ctx->globals->szRealm_upper);
2407 talloc_free(lp_ctx->globals->szRealm_lower);
2409 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2410 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2412 return true;
2415 /***************************************************************************
2416 Handle the include operation.
2417 ***************************************************************************/
2419 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2420 const char *pszParmValue, char **ptr)
2422 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2424 add_to_file_list(lp_ctx, pszParmValue, fname);
2426 lpcfg_string_set(lp_ctx, ptr, fname);
2428 if (file_exist(fname))
2429 return pm_process(fname, do_section, do_parameter, lp_ctx);
2431 DEBUG(2, ("Can't find include file %s\n", fname));
2433 return false;
2436 /***************************************************************************
2437 Handle the interpretation of the copy parameter.
2438 ***************************************************************************/
2440 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2441 const char *pszParmValue, char **ptr)
2443 bool bRetval;
2444 struct loadparm_service *serviceTemp;
2446 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2448 bRetval = false;
2450 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2452 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2453 if (serviceTemp == lp_ctx->currentService) {
2454 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2455 } else {
2456 copy_service(lp_ctx->currentService,
2457 serviceTemp,
2458 lp_ctx->currentService->copymap);
2459 bRetval = true;
2461 } else {
2462 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2463 pszParmValue));
2464 bRetval = false;
2467 return bRetval;
2470 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2471 const char *pszParmValue, char **ptr)
2474 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2475 if (lp_ctx->global) {
2476 return debug_parse_levels(pszParmValue);
2478 return true;
2481 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2482 const char *pszParmValue, char **ptr)
2484 debug_set_logfile(pszParmValue);
2485 if (lp_ctx->global) {
2486 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2488 return true;
2491 /***************************************************************************
2492 Initialise a copymap.
2493 ***************************************************************************/
2495 static void init_copymap(struct loadparm_service *pservice)
2497 int i;
2499 TALLOC_FREE(pservice->copymap);
2501 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2502 if (!pservice->copymap)
2503 DEBUG(0,
2504 ("Couldn't allocate copymap!! (size %d)\n",
2505 (int)NUMPARAMETERS));
2506 else
2507 for (i = 0; i < NUMPARAMETERS; i++)
2508 bitmap_set(pservice->copymap, i);
2512 * Process a parametric option
2514 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2515 struct loadparm_service *service,
2516 const char *pszParmName,
2517 const char *pszParmValue, int flags)
2519 struct parmlist_entry *paramo, *data;
2520 char *name;
2521 TALLOC_CTX *mem_ctx;
2523 while (isspace((unsigned char)*pszParmName)) {
2524 pszParmName++;
2527 name = strlower_talloc(lp_ctx, pszParmName);
2528 if (!name) return false;
2530 if (service == NULL) {
2531 data = lp_ctx->globals->param_opt;
2532 mem_ctx = lp_ctx->globals;
2533 } else {
2534 data = service->param_opt;
2535 mem_ctx = service;
2538 /* Traverse destination */
2539 for (paramo=data; paramo; paramo=paramo->next) {
2540 /* If we already have the option set, override it unless
2541 it was a command line option and the new one isn't */
2542 if (strcmp(paramo->key, name) == 0) {
2543 if ((paramo->priority & FLAG_CMDLINE) &&
2544 !(flags & FLAG_CMDLINE)) {
2545 talloc_free(name);
2546 return true;
2549 talloc_free(paramo->value);
2550 paramo->value = talloc_strdup(paramo, pszParmValue);
2551 paramo->priority = flags;
2552 talloc_free(name);
2553 return true;
2557 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2558 if (!paramo)
2559 smb_panic("OOM");
2560 paramo->key = talloc_strdup(paramo, name);
2561 paramo->value = talloc_strdup(paramo, pszParmValue);
2562 paramo->priority = flags;
2563 if (service == NULL) {
2564 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2565 } else {
2566 DLIST_ADD(service->param_opt, paramo);
2569 talloc_free(name);
2571 return true;
2574 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2575 const char *pszParmName, const char *pszParmValue,
2576 struct loadparm_context *lp_ctx, bool on_globals)
2578 int i;
2579 /* if it is a special case then go ahead */
2580 if (parm_table[parmnum].special) {
2581 bool ret;
2582 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2583 (char **)parm_ptr);
2584 if (!ret) {
2585 return false;
2587 goto mark_non_default;
2590 /* now switch on the type of variable it is */
2591 switch (parm_table[parmnum].type)
2593 case P_BOOL: {
2594 bool b;
2595 if (!set_boolean(pszParmValue, &b)) {
2596 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2597 return false;
2599 *(bool *)parm_ptr = b;
2601 break;
2603 case P_BOOLREV: {
2604 bool b;
2605 if (!set_boolean(pszParmValue, &b)) {
2606 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2607 return false;
2609 *(bool *)parm_ptr = !b;
2611 break;
2613 case P_INTEGER:
2614 *(int *)parm_ptr = atoi(pszParmValue);
2615 break;
2617 case P_CHAR:
2618 *(char *)parm_ptr = *pszParmValue;
2619 break;
2621 case P_OCTAL:
2622 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2623 break;
2625 case P_BYTES:
2627 uint64_t val;
2628 if (conv_str_size_error(pszParmValue, &val)) {
2629 if (val <= INT_MAX) {
2630 *(int *)parm_ptr = (int)val;
2631 break;
2635 DEBUG(0,("lp_do_parameter(%s): value is not "
2636 "a valid size specifier!\n", pszParmValue));
2637 return false;
2640 case P_CMDLIST:
2641 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2642 pszParmValue, NULL);
2643 break;
2644 case P_LIST:
2646 char **new_list = str_list_make(mem_ctx,
2647 pszParmValue, NULL);
2648 for (i=0; new_list[i]; i++) {
2649 if (new_list[i][0] == '+' && new_list[i][1]) {
2650 if (!str_list_check(*(const char ***)parm_ptr,
2651 &new_list[i][1])) {
2652 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2653 &new_list[i][1]);
2655 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2656 str_list_remove(*(const char ***)parm_ptr,
2657 &new_list[i][1]);
2658 } else {
2659 if (i != 0) {
2660 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2661 pszParmName, pszParmValue));
2662 return false;
2664 *(const char ***)parm_ptr = (const char **) new_list;
2665 break;
2668 break;
2670 case P_STRING:
2671 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2672 break;
2674 case P_USTRING:
2675 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2676 break;
2678 case P_ENUM:
2679 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2680 if (strequal
2681 (pszParmValue,
2682 parm_table[parmnum].enum_list[i].name)) {
2683 *(int *)parm_ptr =
2684 parm_table[parmnum].
2685 enum_list[i].value;
2686 break;
2689 if (!parm_table[parmnum].enum_list[i].name) {
2690 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2691 pszParmValue, pszParmName));
2692 return false;
2694 break;
2696 case P_SEP:
2697 break;
2700 mark_non_default:
2701 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2702 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2703 /* we have to also unset FLAG_DEFAULT on aliases */
2704 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2705 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2707 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2708 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2711 return true;
2715 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2716 const char *pszParmName, const char *pszParmValue)
2718 int parmnum = map_parameter(pszParmName);
2719 void *parm_ptr;
2721 if (parmnum < 0) {
2722 if (strchr(pszParmName, ':')) {
2723 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2725 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2726 return true;
2729 /* if the flag has been set on the command line, then don't allow override,
2730 but don't report an error */
2731 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2732 return true;
2735 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2737 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2738 pszParmName, pszParmValue, lp_ctx, true);
2741 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2742 struct loadparm_service *service,
2743 const char *pszParmName, const char *pszParmValue)
2745 void *parm_ptr;
2746 int i;
2747 int parmnum = map_parameter(pszParmName);
2749 if (parmnum < 0) {
2750 if (strchr(pszParmName, ':')) {
2751 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2753 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2754 return true;
2757 /* if the flag has been set on the command line, then don't allow override,
2758 but don't report an error */
2759 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2760 return true;
2763 if (parm_table[parmnum].p_class == P_GLOBAL) {
2764 DEBUG(0,
2765 ("Global parameter %s found in service section!\n",
2766 pszParmName));
2767 return true;
2769 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2771 if (!service->copymap)
2772 init_copymap(service);
2774 /* this handles the aliases - set the copymap for other
2775 * entries with the same data pointer */
2776 for (i = 0; parm_table[i].label; i++)
2777 if (parm_table[i].offset == parm_table[parmnum].offset &&
2778 parm_table[i].p_class == parm_table[parmnum].p_class)
2779 bitmap_clear(service->copymap, i);
2781 return set_variable(service, parmnum, parm_ptr, pszParmName,
2782 pszParmValue, lp_ctx, false);
2786 * Process a parameter.
2789 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2790 void *userdata)
2792 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2794 if (lp_ctx->bInGlobalSection)
2795 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2796 pszParmValue);
2797 else
2798 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2799 pszParmName, pszParmValue);
2803 variable argument do parameter
2805 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2806 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2807 const char *pszParmName, const char *fmt, ...)
2809 char *s;
2810 bool ret;
2811 va_list ap;
2813 va_start(ap, fmt);
2814 s = talloc_vasprintf(NULL, fmt, ap);
2815 va_end(ap);
2816 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2817 talloc_free(s);
2818 return ret;
2823 set a parameter from the commandline - this is called from command line parameter
2824 parsing code. It sets the parameter then marks the parameter as unable to be modified
2825 by smb.conf processing
2827 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2828 const char *pszParmValue)
2830 int parmnum;
2831 int i;
2833 if (lp_ctx->s3_fns) {
2834 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2837 parmnum = map_parameter(pszParmName);
2839 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2842 if (parmnum < 0 && strchr(pszParmName, ':')) {
2843 /* set a parametric option */
2844 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2845 pszParmValue, FLAG_CMDLINE);
2848 if (parmnum < 0) {
2849 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2850 return false;
2853 /* reset the CMDLINE flag in case this has been called before */
2854 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2856 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2857 return false;
2860 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2862 /* we have to also set FLAG_CMDLINE on aliases */
2863 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2864 lp_ctx->flags[i] |= FLAG_CMDLINE;
2866 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2867 lp_ctx->flags[i] |= FLAG_CMDLINE;
2870 return true;
2874 set a option from the commandline in 'a=b' format. Use to support --option
2876 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2878 char *p, *s;
2879 bool ret;
2881 s = talloc_strdup(NULL, option);
2882 if (!s) {
2883 return false;
2886 p = strchr(s, '=');
2887 if (!p) {
2888 talloc_free(s);
2889 return false;
2892 *p = 0;
2894 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2895 talloc_free(s);
2896 return ret;
2900 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2903 * Print a parameter of the specified type.
2906 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2908 /* For the seperation of lists values that we print below */
2909 const char *list_sep = ", ";
2910 int i;
2911 switch (p->type)
2913 case P_ENUM:
2914 for (i = 0; p->enum_list[i].name; i++) {
2915 if (*(int *)ptr == p->enum_list[i].value) {
2916 fprintf(f, "%s",
2917 p->enum_list[i].name);
2918 break;
2921 break;
2923 case P_BOOL:
2924 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2925 break;
2927 case P_BOOLREV:
2928 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2929 break;
2931 case P_INTEGER:
2932 case P_BYTES:
2933 fprintf(f, "%d", *(int *)ptr);
2934 break;
2936 case P_CHAR:
2937 fprintf(f, "%c", *(char *)ptr);
2938 break;
2940 case P_OCTAL: {
2941 int val = *(int *)ptr;
2942 if (val == -1) {
2943 fprintf(f, "-1");
2944 } else {
2945 fprintf(f, "0%o", val);
2947 break;
2950 case P_CMDLIST:
2951 list_sep = " ";
2952 /* fall through */
2953 case P_LIST:
2954 if ((char ***)ptr && *(char ***)ptr) {
2955 char **list = *(char ***)ptr;
2956 for (; *list; list++) {
2957 /* surround strings with whitespace in double quotes */
2958 if (*(list+1) == NULL) {
2959 /* last item, no extra separator */
2960 list_sep = "";
2962 if ( strchr_m( *list, ' ' ) ) {
2963 fprintf(f, "\"%s\"%s", *list, list_sep);
2964 } else {
2965 fprintf(f, "%s%s", *list, list_sep);
2969 break;
2971 case P_STRING:
2972 case P_USTRING:
2973 if (*(char **)ptr) {
2974 fprintf(f, "%s", *(char **)ptr);
2976 break;
2977 case P_SEP:
2978 break;
2983 * Check if two parameters are equal.
2986 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2988 switch (type) {
2989 case P_BOOL:
2990 case P_BOOLREV:
2991 return (*((bool *)ptr1) == *((bool *)ptr2));
2993 case P_INTEGER:
2994 case P_ENUM:
2995 case P_OCTAL:
2996 case P_BYTES:
2997 return (*((int *)ptr1) == *((int *)ptr2));
2999 case P_CHAR:
3000 return (*((char *)ptr1) == *((char *)ptr2));
3002 case P_LIST:
3003 case P_CMDLIST:
3004 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3006 case P_STRING:
3007 case P_USTRING:
3009 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3010 if (p1 && !*p1)
3011 p1 = NULL;
3012 if (p2 && !*p2)
3013 p2 = NULL;
3014 return (p1 == p2 || strequal(p1, p2));
3016 case P_SEP:
3017 break;
3019 return false;
3023 * Process a new section (service).
3025 * At this stage all sections are services.
3026 * Later we'll have special sections that permit server parameters to be set.
3027 * Returns True on success, False on failure.
3030 static bool do_section(const char *pszSectionName, void *userdata)
3032 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3033 bool bRetval;
3034 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3035 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3036 bRetval = false;
3038 /* if we've just struck a global section, note the fact. */
3039 lp_ctx->bInGlobalSection = isglobal;
3041 /* check for multiple global sections */
3042 if (lp_ctx->bInGlobalSection) {
3043 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3044 return true;
3047 /* if we have a current service, tidy it up before moving on */
3048 bRetval = true;
3050 if (lp_ctx->currentService != NULL)
3051 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3053 /* if all is still well, move to the next record in the services array */
3054 if (bRetval) {
3055 /* We put this here to avoid an odd message order if messages are */
3056 /* issued by the post-processing of a previous section. */
3057 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3059 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3060 pszSectionName))
3061 == NULL) {
3062 DEBUG(0, ("Failed to add a new service\n"));
3063 return false;
3067 return bRetval;
3072 * Determine if a particular base parameter is currently set to the default value.
3075 static bool is_default(struct loadparm_service *sDefault, int i)
3077 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3078 if (!defaults_saved)
3079 return false;
3080 switch (parm_table[i].type) {
3081 case P_CMDLIST:
3082 case P_LIST:
3083 return str_list_equal((const char **)parm_table[i].def.lvalue,
3084 (const char **)def_ptr);
3085 case P_STRING:
3086 case P_USTRING:
3087 return strequal(parm_table[i].def.svalue,
3088 *(char **)def_ptr);
3089 case P_BOOL:
3090 case P_BOOLREV:
3091 return parm_table[i].def.bvalue ==
3092 *(bool *)def_ptr;
3093 case P_INTEGER:
3094 case P_CHAR:
3095 case P_OCTAL:
3096 case P_BYTES:
3097 case P_ENUM:
3098 return parm_table[i].def.ivalue ==
3099 *(int *)def_ptr;
3100 case P_SEP:
3101 break;
3103 return false;
3107 *Display the contents of the global structure.
3110 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3111 bool show_defaults)
3113 int i;
3114 struct parmlist_entry *data;
3116 fprintf(f, "# Global parameters\n[global]\n");
3118 for (i = 0; parm_table[i].label; i++)
3119 if (parm_table[i].p_class == P_GLOBAL &&
3120 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3121 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3122 continue;
3123 fprintf(f, "\t%s = ", parm_table[i].label);
3124 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3125 fprintf(f, "\n");
3127 if (lp_ctx->globals->param_opt != NULL) {
3128 for (data = lp_ctx->globals->param_opt; data;
3129 data = data->next) {
3130 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3131 continue;
3133 fprintf(f, "\t%s = %s\n", data->key, data->value);
3140 * Display the contents of a single services record.
3143 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3144 unsigned int *flags)
3146 int i;
3147 struct parmlist_entry *data;
3149 if (pService != sDefault)
3150 fprintf(f, "\n[%s]\n", pService->szService);
3152 for (i = 0; parm_table[i].label; i++) {
3153 if (parm_table[i].p_class == P_LOCAL &&
3154 (*parm_table[i].label != '-') &&
3155 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3157 if (pService == sDefault) {
3158 if (flags && (flags[i] & FLAG_DEFAULT)) {
3159 continue;
3161 if (defaults_saved) {
3162 if (is_default(sDefault, i)) {
3163 continue;
3166 } else {
3167 if (equal_parameter(parm_table[i].type,
3168 ((char *)pService) +
3169 parm_table[i].offset,
3170 ((char *)sDefault) +
3171 parm_table[i].offset))
3172 continue;
3175 fprintf(f, "\t%s = ", parm_table[i].label);
3176 print_parameter(&parm_table[i],
3177 ((char *)pService) + parm_table[i].offset, f);
3178 fprintf(f, "\n");
3181 if (pService->param_opt != NULL) {
3182 for (data = pService->param_opt; data; data = data->next) {
3183 fprintf(f, "\t%s = %s\n", data->key, data->value);
3188 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3189 struct loadparm_service *service,
3190 const char *parm_name, FILE * f)
3192 struct parm_struct *parm;
3193 void *ptr;
3195 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3196 if (!parm) {
3197 return false;
3200 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3202 print_parameter(parm, ptr, f);
3203 fprintf(f, "\n");
3204 return true;
3208 * Return info about the next parameter in a service.
3209 * snum==-1 gives the globals.
3210 * Return NULL when out of parameters.
3214 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3215 int allparameters)
3217 if (snum == -1) {
3218 /* do the globals */
3219 for (; parm_table[*i].label; (*i)++) {
3220 if ((*parm_table[*i].label == '-'))
3221 continue;
3223 if ((*i) > 0
3224 && (parm_table[*i].offset ==
3225 parm_table[(*i) - 1].offset)
3226 && (parm_table[*i].p_class ==
3227 parm_table[(*i) - 1].p_class))
3228 continue;
3230 return &parm_table[(*i)++];
3232 } else {
3233 struct loadparm_service *pService = lp_ctx->services[snum];
3235 for (; parm_table[*i].label; (*i)++) {
3236 if (parm_table[*i].p_class == P_LOCAL &&
3237 (*parm_table[*i].label != '-') &&
3238 ((*i) == 0 ||
3239 (parm_table[*i].offset !=
3240 parm_table[(*i) - 1].offset)))
3242 if (allparameters ||
3243 !equal_parameter(parm_table[*i].type,
3244 ((char *)pService) +
3245 parm_table[*i].offset,
3246 ((char *)lp_ctx->sDefault) +
3247 parm_table[*i].offset))
3249 return &parm_table[(*i)++];
3255 return NULL;
3260 * Auto-load some home services.
3262 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3263 const char *str)
3265 return;
3270 * Unload unused services.
3273 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3274 struct smbsrv_connection *smb,
3275 bool (*snumused) (struct smbsrv_connection *, int))
3277 int i;
3278 for (i = 0; i < lp_ctx->iNumServices; i++) {
3279 if (lp_ctx->services[i] == NULL)
3280 continue;
3282 if (!snumused || !snumused(smb, i)) {
3283 talloc_free(lp_ctx->services[i]);
3284 lp_ctx->services[i] = NULL;
3290 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3292 struct parmlist_entry *data;
3294 if (lp_ctx->refuse_free) {
3295 /* someone is trying to free the
3296 global_loadparm_context.
3297 We can't allow that. */
3298 return -1;
3301 if (lp_ctx->globals->param_opt != NULL) {
3302 struct parmlist_entry *next;
3303 for (data = lp_ctx->globals->param_opt; data; data=next) {
3304 next = data->next;
3305 if (data->priority & FLAG_CMDLINE) continue;
3306 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3307 talloc_free(data);
3311 return 0;
3315 * Initialise the global parameter structure.
3317 * Note that most callers should use loadparm_init_global() instead
3319 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3321 int i;
3322 char *myname;
3323 struct loadparm_context *lp_ctx;
3324 struct parmlist_entry *parm;
3325 char *logfile;
3327 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3328 if (lp_ctx == NULL)
3329 return NULL;
3331 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3332 lp_ctx->bInGlobalSection = true;
3333 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3334 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3336 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3337 lp_ctx->sDefault->bAvailable = true;
3338 lp_ctx->sDefault->bBrowseable = true;
3339 lp_ctx->sDefault->bRead_only = true;
3340 lp_ctx->sDefault->bMap_archive = true;
3341 lp_ctx->sDefault->iStrictLocking = true;
3342 lp_ctx->sDefault->bOpLocks = true;
3343 lp_ctx->sDefault->iCreate_mask = 0744;
3344 lp_ctx->sDefault->iCreate_force_mode = 0000;
3345 lp_ctx->sDefault->iDir_mask = 0755;
3346 lp_ctx->sDefault->iDir_force_mode = 0000;
3348 DEBUG(3, ("Initialising global parameters\n"));
3350 for (i = 0; parm_table[i].label; i++) {
3351 if ((parm_table[i].type == P_STRING ||
3352 parm_table[i].type == P_USTRING) &&
3353 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3354 char **r;
3355 if (parm_table[i].p_class == P_LOCAL) {
3356 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3357 } else {
3358 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3360 *r = talloc_strdup(lp_ctx, "");
3364 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3365 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3366 talloc_free(logfile);
3368 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3370 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3372 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3373 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3374 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3376 /* options that can be set on the command line must be initialised via
3377 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3378 #ifdef TCP_NODELAY
3379 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3380 #endif
3381 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3382 myname = get_myname(lp_ctx);
3383 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3384 talloc_free(myname);
3385 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3387 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3389 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3390 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3392 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3393 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3394 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3395 /* the winbind method for domain controllers is for both RODC
3396 auth forwarding and for trusted domains */
3397 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3398 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3400 /* This hive should be dynamically generated by Samba using
3401 data from the sam, but for the moment leave it in a tdb to
3402 keep regedt32 from popping up an annoying dialog. */
3403 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3405 /* using UTF8 by default allows us to support all chars */
3406 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3408 /* Use codepage 850 as a default for the dos character set */
3409 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3412 * Allow the default PASSWD_CHAT to be overridden in local.h.
3414 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3416 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3417 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3418 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3419 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3420 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3422 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3423 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3424 "Samba %s", SAMBA_VERSION_STRING);
3426 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3428 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3429 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3430 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3432 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3433 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3434 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3435 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3436 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3437 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3438 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3439 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3440 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3441 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3442 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3443 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3444 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3446 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3447 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3448 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3449 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3450 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3451 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3452 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3453 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3455 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3457 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3458 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3460 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3461 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3463 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3464 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3465 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3466 #if _SAMBA_BUILD_ >= 4
3467 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3468 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3469 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3470 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3471 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3472 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3473 #endif
3474 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3475 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3476 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3478 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3479 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3481 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3483 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3485 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3486 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3487 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3488 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3489 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3490 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3491 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3493 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3495 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3496 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3498 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3499 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3500 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3501 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3502 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3504 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3505 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3507 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3508 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3509 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3511 for (i = 0; parm_table[i].label; i++) {
3512 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3513 lp_ctx->flags[i] |= FLAG_DEFAULT;
3517 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3518 if (!(parm->priority & FLAG_CMDLINE)) {
3519 parm->priority |= FLAG_DEFAULT;
3523 return lp_ctx;
3527 * Initialise the global parameter structure.
3529 struct loadparm_context *loadparm_init_global(bool load_default)
3531 if (global_loadparm_context == NULL) {
3532 global_loadparm_context = loadparm_init(NULL);
3534 if (global_loadparm_context == NULL) {
3535 return NULL;
3537 global_loadparm_context->global = true;
3538 if (load_default && !global_loadparm_context->loaded) {
3539 lpcfg_load_default(global_loadparm_context);
3541 global_loadparm_context->refuse_free = true;
3542 return global_loadparm_context;
3546 * Initialise the global parameter structure.
3548 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3549 const struct loadparm_s3_context *s3_fns)
3551 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3552 if (!loadparm_context) {
3553 return NULL;
3555 loadparm_context->s3_fns = s3_fns;
3556 return loadparm_context;
3559 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3561 return lp_ctx->szConfigFile;
3564 const char *lp_default_path(void)
3566 if (getenv("SMB_CONF_PATH"))
3567 return getenv("SMB_CONF_PATH");
3568 else
3569 return dyn_CONFIGFILE;
3573 * Update the internal state of a loadparm context after settings
3574 * have changed.
3576 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3578 struct debug_settings settings;
3579 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3581 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3582 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3585 if (!lp_ctx->global) {
3586 return true;
3589 panic_action = lp_ctx->globals->panic_action;
3591 reload_charcnv(lp_ctx);
3593 ZERO_STRUCT(settings);
3594 /* Add any more debug-related smb.conf parameters created in
3595 * future here */
3596 settings.timestamp_logs = true;
3597 debug_set_settings(&settings);
3599 /* FIXME: This is a bit of a hack, but we can't use a global, since
3600 * not everything that uses lp also uses the socket library */
3601 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3602 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3603 } else {
3604 unsetenv("SOCKET_TESTNONBLOCK");
3607 return true;
3610 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3612 const char *path;
3614 path = lp_default_path();
3616 if (!file_exist(path)) {
3617 /* We allow the default smb.conf file to not exist,
3618 * basically the equivalent of an empty file. */
3619 return lpcfg_update(lp_ctx);
3622 return lpcfg_load(lp_ctx, path);
3626 * Load the services array from the services file.
3628 * Return True on success, False on failure.
3630 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3632 char *n2;
3633 bool bRetval;
3635 filename = talloc_strdup(lp_ctx, filename);
3637 lp_ctx->szConfigFile = filename;
3639 if (lp_ctx->s3_fns) {
3640 return lp_ctx->s3_fns->load(filename);
3643 lp_ctx->bInGlobalSection = true;
3644 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3645 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3647 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3649 /* We get sections first, so have to start 'behind' to make up */
3650 lp_ctx->currentService = NULL;
3651 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3653 /* finish up the last section */
3654 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3655 if (bRetval)
3656 if (lp_ctx->currentService != NULL)
3657 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3659 bRetval = bRetval && lpcfg_update(lp_ctx);
3661 /* we do this unconditionally, so that it happens even
3662 for a missing smb.conf */
3663 reload_charcnv(lp_ctx);
3665 if (bRetval == true) {
3666 /* set this up so that any child python tasks will
3667 find the right smb.conf */
3668 setenv("SMB_CONF_PATH", filename, 1);
3670 /* set the context used by the lp_*() function
3671 varients */
3672 global_loadparm_context = lp_ctx;
3673 lp_ctx->loaded = true;
3676 return bRetval;
3680 * Return the max number of services.
3683 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3685 if (lp_ctx->s3_fns) {
3686 return lp_ctx->s3_fns->get_numservices();
3689 return lp_ctx->iNumServices;
3693 * Display the contents of the services array in human-readable form.
3696 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3697 int maxtoprint)
3699 int iService;
3701 if (lp_ctx->s3_fns) {
3702 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3703 return;
3706 defaults_saved = !show_defaults;
3708 dump_globals(lp_ctx, f, show_defaults);
3710 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3712 for (iService = 0; iService < maxtoprint; iService++)
3713 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3717 * Display the contents of one service in human-readable form.
3719 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3721 if (service != NULL) {
3722 if (service->szService[0] == '\0')
3723 return;
3724 dump_a_service(service, sDefault, f, NULL);
3728 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3729 int snum)
3731 if (lp_ctx->s3_fns) {
3732 return lp_ctx->s3_fns->get_servicebynum(snum);
3735 return lp_ctx->services[snum];
3738 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3739 const char *service_name)
3741 int iService;
3742 char *serviceName;
3744 if (lp_ctx->s3_fns) {
3745 return lp_ctx->s3_fns->get_service(service_name);
3748 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3749 if (lp_ctx->services[iService] &&
3750 lp_ctx->services[iService]->szService) {
3752 * The substitution here is used to support %U is
3753 * service names
3755 serviceName = standard_sub_basic(
3756 lp_ctx->services[iService],
3757 lp_ctx->services[iService]->szService);
3758 if (strequal(serviceName, service_name)) {
3759 talloc_free(serviceName);
3760 return lp_ctx->services[iService];
3762 talloc_free(serviceName);
3766 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3767 return NULL;
3770 const char *lpcfg_servicename(const struct loadparm_service *service)
3772 return lp_string((const char *)service->szService);
3776 * A useful volume label function.
3778 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3780 const char *ret;
3781 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3782 service->volume : sDefault->volume));
3783 if (!*ret)
3784 return lpcfg_servicename(service);
3785 return ret;
3789 * If we are PDC then prefer us as DMB
3791 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3793 const char *ret;
3794 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3795 service->szPrintername : sDefault->szPrintername));
3796 if (ret == NULL || (ret != NULL && *ret == '\0'))
3797 ret = lpcfg_servicename(service);
3799 return ret;
3804 * Return the max print jobs per queue.
3806 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3808 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3809 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3810 maxjobs = PRINT_MAX_JOBID - 1;
3812 return maxjobs;
3815 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3817 if (lp_ctx == NULL) {
3818 return get_iconv_handle();
3820 return lp_ctx->iconv_handle;
3823 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3825 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3826 if (!lp_ctx->global) {
3827 return;
3830 if (old_ic == NULL) {
3831 old_ic = global_iconv_handle;
3833 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3834 global_iconv_handle = lp_ctx->iconv_handle;
3837 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3839 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3842 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3844 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3847 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3849 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3852 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3854 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3857 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3859 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3862 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3864 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3865 if (settings == NULL)
3866 return NULL;
3867 SMB_ASSERT(lp_ctx != NULL);
3868 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3869 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3870 return settings;
3873 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3875 if (lp_ctx->s3_fns) {
3876 return lp_ctx->s3_fns->server_role();
3879 return lp_find_server_role(lp_ctx->globals->server_role,
3880 lp_ctx->globals->security,
3881 lp_ctx->globals->domain_logons,
3882 (lp_ctx->globals->domain_master == true) ||
3883 (lp_ctx->globals->domain_master == Auto));
3886 int lpcfg_security(struct loadparm_context *lp_ctx)
3888 if (lp_ctx->s3_fns) {
3889 return lp_ctx->s3_fns->security();
3892 return lp_find_security(lp_ctx->globals->server_role,
3893 lp_ctx->globals->security);