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/>.
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.
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
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
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"
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; \
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",
118 .offset
= GLOBAL_VAR(server_role
),
120 .enum_list
= enum_server_role
123 .label
= "domain logons",
126 .offset
= GLOBAL_VAR(domain_logons
),
128 .enum_list
= enum_bool_auto
131 .label
= "domain master",
134 .offset
= GLOBAL_VAR(domain_master
),
136 .enum_list
= enum_bool_auto
139 .label
= "dos charset",
142 .offset
= GLOBAL_VAR(dos_charset
),
147 .label
= "unix charset",
150 .offset
= GLOBAL_VAR(unix_charset
),
155 .label
= "ncalrpc dir",
158 .offset
= GLOBAL_VAR(ncalrpc_dir
),
166 .offset
= LOCAL_VAR(comment
),
169 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
175 .offset
= LOCAL_VAR(szPath
),
178 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
181 .label
= "directory",
184 .offset
= LOCAL_VAR(szPath
),
190 .label
= "workgroup",
193 .offset
= GLOBAL_VAR(szWorkgroup
),
196 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
202 .offset
= GLOBAL_VAR(szRealm
),
203 .special
= handle_realm
,
205 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
208 .label
= "netbios name",
211 .offset
= GLOBAL_VAR(szNetbiosName
),
214 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
217 .label
= "netbios aliases",
220 .offset
= GLOBAL_VAR(szNetbiosAliases
),
225 .label
= "netbios scope",
228 .offset
= GLOBAL_VAR(szNetbiosScope
),
231 .flags
= FLAG_ADVANCED
,
234 .label
= "server string",
237 .offset
= GLOBAL_VAR(szServerString
),
240 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
243 .label
= "interfaces",
246 .offset
= GLOBAL_VAR(szInterfaces
),
249 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_WIZARD
,
252 .label
= "bind interfaces only",
255 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
258 .flags
= FLAG_ADVANCED
| FLAG_WIZARD
,
261 .label
= "ntvfs handler",
264 .offset
= LOCAL_VAR(ntvfs_handler
),
269 .label
= "ntptr providor",
272 .offset
= GLOBAL_VAR(ntptr_providor
),
277 .label
= "passdb backend",
280 .offset
= GLOBAL_VAR(passdb_backend
),
285 .label
= "dcerpc endpoint servers",
288 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
293 .label
= "server services",
296 .offset
= GLOBAL_VAR(server_services
),
305 .offset
= GLOBAL_VAR(security
),
307 .enum_list
= enum_security
310 .label
= "encrypt passwords",
313 .offset
= GLOBAL_VAR(bEncryptPasswords
),
318 .label
= "null passwords",
321 .offset
= GLOBAL_VAR(bNullPasswords
),
324 .flags
= FLAG_ADVANCED
| FLAG_DEPRECATED
,
327 .label
= "obey pam restrictions",
330 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
333 .flags
= FLAG_ADVANCED
,
336 .label
= "password server",
339 .offset
= GLOBAL_VAR(szPasswordServers
),
344 .label
= "private dir",
347 .offset
= GLOBAL_VAR(szPrivateDir
),
352 .label
= "passwd chat",
355 .offset
= GLOBAL_VAR(szPasswdChat
),
360 .label
= "password level",
363 .offset
= GLOBAL_VAR(pwordlevel
),
368 .label
= "lanman auth",
371 .offset
= GLOBAL_VAR(bLanmanAuth
),
374 .flags
= FLAG_ADVANCED
,
377 .label
= "ntlm auth",
380 .offset
= GLOBAL_VAR(bNTLMAuth
),
383 .flags
= FLAG_ADVANCED
,
386 .label
= "client NTLMv2 auth",
389 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
392 .flags
= FLAG_ADVANCED
,
395 .label
= "client lanman auth",
398 .offset
= GLOBAL_VAR(bClientLanManAuth
),
401 .flags
= FLAG_ADVANCED
,
404 .label
= "client plaintext auth",
407 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
410 .flags
= FLAG_ADVANCED
,
413 .label
= "client use spnego principal",
416 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
422 .label
= "read only",
425 .offset
= LOCAL_VAR(bRead_only
),
431 .label
= "create mask",
434 .offset
= LOCAL_VAR(iCreate_mask
),
439 .label
= "force create mode",
442 .offset
= LOCAL_VAR(iCreate_force_mode
),
447 .label
= "directory mask",
450 .offset
= LOCAL_VAR(iDir_mask
),
455 .label
= "force directory mode",
458 .offset
= LOCAL_VAR(iDir_force_mode
),
464 .label
= "hosts allow",
467 .offset
= LOCAL_VAR(szHostsallow
),
472 .label
= "hosts deny",
475 .offset
= LOCAL_VAR(szHostsdeny
),
481 .label
= "log level",
484 .offset
= GLOBAL_VAR(loglevel
),
485 .special
= handle_debuglevel
,
489 .label
= "debuglevel",
492 .offset
= GLOBAL_VAR(loglevel
),
493 .special
= handle_debuglevel
,
500 .offset
= GLOBAL_VAR(logfile
),
501 .special
= handle_logfile
,
503 .flags
= FLAG_ADVANCED
,
507 .label
= "smb ports",
510 .offset
= GLOBAL_VAR(smb_ports
),
518 .offset
= GLOBAL_VAR(nbt_port
),
523 .label
= "dgram port",
526 .offset
= GLOBAL_VAR(dgram_port
),
531 .label
= "cldap port",
534 .offset
= GLOBAL_VAR(cldap_port
),
539 .label
= "krb5 port",
542 .offset
= GLOBAL_VAR(krb5_port
),
547 .label
= "kpasswd port",
550 .offset
= GLOBAL_VAR(kpasswd_port
),
558 .offset
= GLOBAL_VAR(web_port
),
563 .label
= "tls enabled",
566 .offset
= GLOBAL_VAR(tls_enabled
),
571 .label
= "tls keyfile",
574 .offset
= GLOBAL_VAR(tls_keyfile
),
579 .label
= "tls certfile",
582 .offset
= GLOBAL_VAR(tls_certfile
),
587 .label
= "tls cafile",
590 .offset
= GLOBAL_VAR(tls_cafile
),
595 .label
= "tls crlfile",
598 .offset
= GLOBAL_VAR(tls_crlfile
),
603 .label
= "tls dh params file",
606 .offset
= GLOBAL_VAR(tls_dhpfile
),
611 .label
= "large readwrite",
614 .offset
= GLOBAL_VAR(bLargeReadwrite
),
617 .flags
= FLAG_ADVANCED
,
620 .label
= "server max protocol",
623 .offset
= GLOBAL_VAR(srv_maxprotocol
),
625 .enum_list
= enum_protocol
628 .label
= "max protocol",
631 .offset
= GLOBAL_VAR(srv_maxprotocol
),
633 .enum_list
= enum_protocol
639 .offset
= GLOBAL_VAR(srv_maxprotocol
),
641 .enum_list
= enum_protocol
,
642 .flags
= FLAG_ADVANCED
,
645 .label
= "server min protocol",
648 .offset
= GLOBAL_VAR(srv_minprotocol
),
650 .enum_list
= enum_protocol
653 .label
= "min protocol",
656 .offset
= GLOBAL_VAR(srv_minprotocol
),
658 .enum_list
= enum_protocol
661 .label
= "client max protocol",
664 .offset
= GLOBAL_VAR(cli_maxprotocol
),
666 .enum_list
= enum_protocol
669 .label
= "client min protocol",
672 .offset
= GLOBAL_VAR(cli_minprotocol
),
674 .enum_list
= enum_protocol
680 .offset
= GLOBAL_VAR(bUnicode
),
688 .offset
= GLOBAL_VAR(bReadRaw
),
693 .label
= "write raw",
696 .offset
= GLOBAL_VAR(bWriteRaw
),
701 .label
= "disable netbios",
704 .offset
= GLOBAL_VAR(bDisableNetbios
),
710 .label
= "nt status support",
713 .offset
= GLOBAL_VAR(bNTStatusSupport
),
722 .offset
= GLOBAL_VAR(max_mux
),
725 .flags
= FLAG_ADVANCED
,
731 .offset
= GLOBAL_VAR(max_xmit
),
734 .flags
= FLAG_ADVANCED
,
738 .label
= "name resolve order",
741 .offset
= GLOBAL_VAR(szNameResolveOrder
),
746 .label
= "max wins ttl",
749 .offset
= GLOBAL_VAR(max_wins_ttl
),
752 .flags
= FLAG_ADVANCED
,
755 .label
= "min wins ttl",
758 .offset
= GLOBAL_VAR(min_wins_ttl
),
761 .flags
= FLAG_ADVANCED
,
764 .label
= "time server",
767 .offset
= GLOBAL_VAR(bTimeServer
),
770 .flags
= FLAG_ADVANCED
,
773 .label
= "unix extensions",
776 .offset
= GLOBAL_VAR(bUnixExtensions
),
779 .flags
= FLAG_ADVANCED
,
782 .label
= "use spnego",
785 .offset
= GLOBAL_VAR(bUseSpnego
),
790 .label
= "server signing",
793 .offset
= GLOBAL_VAR(server_signing
),
795 .enum_list
= enum_smb_signing_vals
,
796 .flags
= FLAG_ADVANCED
,
799 .label
= "client signing",
802 .offset
= GLOBAL_VAR(client_signing
),
804 .enum_list
= enum_smb_signing_vals
807 .label
= "rpc big endian",
810 .offset
= GLOBAL_VAR(bRpcBigEndian
),
816 .label
= "max connections",
819 .offset
= LOCAL_VAR(iMaxConnections
),
822 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
825 .label
= "paranoid server security",
828 .offset
= GLOBAL_VAR(paranoid_server_security
),
833 .label
= "socket options",
836 .offset
= GLOBAL_VAR(socket_options
),
842 .label
= "strict sync",
845 .offset
= LOCAL_VAR(bStrictSync
),
853 .offset
= GLOBAL_VAR(bUseMmap
),
856 .flags
= FLAG_ADVANCED
,
859 .label
= "case insensitive filesystem",
862 .offset
= LOCAL_VAR(bCIFileSystem
),
868 .label
= "max print jobs",
871 .offset
= LOCAL_VAR(iMaxPrintJobs
),
876 .label
= "printable",
879 .offset
= LOCAL_VAR(bPrint_ok
),
887 .offset
= LOCAL_VAR(bPrint_ok
),
893 .label
= "printer name",
896 .offset
= LOCAL_VAR(szPrintername
),
899 .flags
= FLAG_ADVANCED
| FLAG_PRINT
,
905 .offset
= LOCAL_VAR(szPrintername
),
912 .label
= "map system",
915 .offset
= LOCAL_VAR(bMap_system
),
920 .label
= "map hidden",
923 .offset
= LOCAL_VAR(bMap_hidden
),
928 .label
= "map archive",
931 .offset
= LOCAL_VAR(bMap_archive
),
937 .label
= "preferred master",
940 .offset
= GLOBAL_VAR(bPreferredMaster
),
942 .enum_list
= enum_bool_auto
,
943 .flags
= FLAG_BASIC
| FLAG_ADVANCED
,
946 .label
= "prefered master",
949 .offset
= GLOBAL_VAR(bPreferredMaster
),
951 .enum_list
= enum_bool_auto
,
955 .label
= "local master",
958 .offset
= GLOBAL_VAR(bLocalMaster
),
963 .label
= "browseable",
966 .offset
= LOCAL_VAR(bBrowseable
),
969 .flags
= FLAG_BASIC
| FLAG_ADVANCED
| FLAG_SHARE
| FLAG_PRINT
,
972 .label
= "browsable",
975 .offset
= LOCAL_VAR(bBrowseable
),
981 .label
= "dns proxy",
984 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
989 .label
= "wins server",
992 .offset
= GLOBAL_VAR(szWINSservers
),
997 .label
= "wins support",
1000 .offset
= GLOBAL_VAR(bWINSsupport
),
1005 .label
= "wins hook",
1007 .p_class
= P_GLOBAL
,
1008 .offset
= GLOBAL_VAR(szWINSHook
),
1011 .flags
= FLAG_ADVANCED
,
1015 .label
= "csc policy",
1018 .offset
= LOCAL_VAR(iCSCPolicy
),
1020 .enum_list
= enum_csc_policy
,
1021 .flags
= FLAG_ADVANCED
| FLAG_SHARE
| FLAG_GLOBAL
,
1025 .label
= "strict locking",
1028 .offset
= LOCAL_VAR(iStrictLocking
),
1036 .offset
= LOCAL_VAR(bOpLocks
),
1042 .label
= "share backend",
1044 .p_class
= P_GLOBAL
,
1045 .offset
= GLOBAL_VAR(szShareBackend
),
1052 .p_class
= P_GLOBAL
,
1053 .offset
= GLOBAL_VAR(szAutoServices
),
1056 .flags
= FLAG_ADVANCED
,
1059 .label
= "auto services",
1061 .p_class
= P_GLOBAL
,
1062 .offset
= GLOBAL_VAR(szAutoServices
),
1065 .flags
= FLAG_ADVANCED
,
1068 .label
= "lock directory",
1070 .p_class
= P_GLOBAL
,
1071 .offset
= GLOBAL_VAR(szLockDir
),
1074 .flags
= FLAG_ADVANCED
,
1077 .label
= "lock dir",
1079 .p_class
= P_GLOBAL
,
1080 .offset
= GLOBAL_VAR(szLockDir
),
1086 .label
= "state directory",
1088 .p_class
= P_GLOBAL
,
1089 .offset
= GLOBAL_VAR(szStateDir
),
1092 .flags
= FLAG_ADVANCED
,
1095 .label
= "cache directory",
1097 .p_class
= P_GLOBAL
,
1098 .offset
= GLOBAL_VAR(szCacheDir
),
1101 .flags
= FLAG_ADVANCED
,
1104 .label
= "pid directory",
1106 .p_class
= P_GLOBAL
,
1107 .offset
= GLOBAL_VAR(szPidDir
),
1113 .label
= "socket address",
1115 .p_class
= P_GLOBAL
,
1116 .offset
= GLOBAL_VAR(szSocketAddress
),
1124 .offset
= LOCAL_VAR(szCopy
),
1125 .special
= handle_copy
,
1133 .offset
= LOCAL_VAR(szInclude
),
1134 .special
= handle_include
,
1139 .label
= "available",
1142 .offset
= LOCAL_VAR(bAvailable
),
1150 .offset
= LOCAL_VAR(volume
),
1153 .flags
= FLAG_ADVANCED
| FLAG_SHARE
,
1159 .offset
= LOCAL_VAR(fstype
),
1165 .label
= "panic action",
1167 .p_class
= P_GLOBAL
,
1168 .offset
= GLOBAL_VAR(panic_action
),
1174 .label
= "msdfs root",
1177 .offset
= LOCAL_VAR(bMSDfsRoot
),
1182 .label
= "host msdfs",
1184 .p_class
= P_GLOBAL
,
1185 .offset
= GLOBAL_VAR(bHostMSDfs
),
1188 .flags
= FLAG_ADVANCED
,
1191 .label
= "winbind separator",
1193 .p_class
= P_GLOBAL
,
1194 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1199 .label
= "winbindd socket directory",
1201 .p_class
= P_GLOBAL
,
1202 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1205 .flags
= FLAG_ADVANCED
,
1208 .label
= "winbindd privileged socket directory",
1210 .p_class
= P_GLOBAL
,
1211 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1214 .flags
= FLAG_ADVANCED
,
1217 .label
= "winbind sealed pipes",
1219 .p_class
= P_GLOBAL
,
1220 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1223 .flags
= FLAG_ADVANCED
,
1226 .label
= "template shell",
1228 .p_class
= P_GLOBAL
,
1229 .offset
= GLOBAL_VAR(szTemplateShell
),
1232 .flags
= FLAG_ADVANCED
,
1235 .label
= "template homedir",
1237 .p_class
= P_GLOBAL
,
1238 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1241 .flags
= FLAG_ADVANCED
,
1244 .label
= "idmap trusted only",
1246 .p_class
= P_GLOBAL
,
1247 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1250 .flags
= FLAG_ADVANCED
,
1254 .label
= "ntp signd socket directory",
1256 .p_class
= P_GLOBAL
,
1257 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1260 .flags
= FLAG_ADVANCED
,
1263 .label
= "rndc command",
1265 .p_class
= P_GLOBAL
,
1266 .offset
= GLOBAL_VAR(szRNDCCommand
),
1269 .flags
= FLAG_ADVANCED
,
1272 .label
= "dns update command",
1274 .p_class
= P_GLOBAL
,
1275 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1278 .flags
= FLAG_ADVANCED
,
1281 .label
= "spn update command",
1283 .p_class
= P_GLOBAL
,
1284 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1287 .flags
= FLAG_ADVANCED
,
1290 .label
= "samba kcc command",
1292 .p_class
= P_GLOBAL
,
1293 .offset
= GLOBAL_VAR(szSambaKCCCommand
),
1296 .flags
= FLAG_ADVANCED
,
1299 .label
= "nsupdate command",
1301 .p_class
= P_GLOBAL
,
1302 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1305 .flags
= FLAG_ADVANCED
,
1308 .label
= "allow dns updates",
1310 .p_class
= P_GLOBAL
,
1311 .offset
= GLOBAL_VAR(allow_dns_updates
),
1313 .enum_list
= enum_dns_update_settings
,
1314 .flags
= FLAG_ADVANCED
,
1317 .label
= "dns forwarder",
1319 .p_class
= P_GLOBAL
,
1320 .offset
= GLOBAL_VAR(dns_forwarder
),
1323 .flags
= FLAG_ADVANCED
,
1326 .label
= "dns recursive queries",
1328 .p_class
= P_GLOBAL
,
1329 .offset
= GLOBAL_VAR(dns_recursive_queries
),
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
;
1346 struct loadparm_service
*currentService
;
1347 bool bInGlobalSection
;
1349 struct file_lists
*next
;
1354 unsigned int flags
[NUMPARAMETERS
];
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;
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? */
1392 DEBUG(10, ("lp_string(%s)\n", s
));
1395 #if 0 /* until REWRITE done to make thread-safe */
1397 lp_talloc
= talloc_init("lp_talloc");
1399 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
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);
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
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
;
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
);
1660 if (strcmp(data
->key
, vfskey
) == 0) {
1661 talloc_free(vfskey
);
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
);
1679 talloc_free(vfskey
);
1686 * convenience routine to return int parameters.
1688 static int lp_int(const char *s
)
1692 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1696 return strtol(s
, NULL
, 0);
1700 * convenience routine to return unsigned long parameters.
1702 static unsigned long lp_ulong(const char *s
)
1706 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
1710 return strtoul(s
, NULL
, 0);
1714 * convenience routine to return unsigned long parameters.
1716 static long lp_long(const char *s
)
1720 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
1724 return strtol(s
, NULL
, 0);
1728 * convenience routine to return unsigned long parameters.
1730 static double lp_double(const char *s
)
1734 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1738 return strtod(s
, NULL
);
1742 * convenience routine to return boolean parameters.
1744 static bool lp_bool(const char *s
)
1749 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1753 if (!set_boolean(s
, &ret
)) {
1754 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
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
,
1772 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1775 return lp_string(value
);
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
,
1790 const char *option
, const char *separator
)
1792 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1795 return (const char **)str_list_make(mem_ctx
, value
, separator
);
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
);
1812 return lp_int(value
);
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
)
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
) {
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
);
1852 return lp_ulong(value
);
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
);
1864 return lp_long(value
);
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
);
1876 return lp_double(value
);
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
);
1893 return lp_bool(value
);
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
);
1912 * Set a string value, deallocating any existing space, and allocing the space
1915 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1922 *dest
= talloc_strdup(mem_ctx
, src
);
1923 if ((*dest
) == NULL
) {
1924 DEBUG(0,("Out of memory in string_set\n"));
1932 * Set a string value, deallocating any existing space, and allocing the space
1935 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1942 *dest
= strupper_talloc(mem_ctx
, src
);
1943 if ((*dest
) == NULL
) {
1944 DEBUG(0,("Out of memory in string_set_upper\n"));
1954 * Add a new service to the services array initialising it with the given
1958 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1959 const struct loadparm_service
*pservice
,
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 */
1975 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1977 if (service
!= NULL
) {
1978 /* Clean all parametric options for service */
1979 /* They will be added during parsing again */
1980 data
= service
->param_opt
;
1986 service
->param_opt
= NULL
;
1991 /* find an invalid one */
1992 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1993 if (lp_ctx
->services
[i
] == NULL
)
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
);
2003 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
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"));
2018 copy_service(lp_ctx
->services
[i
], &tservice
, 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
)
2041 if (!(*(default_service
->szPath
))
2042 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
2043 service
->szPath
= talloc_strdup(service
, pszHomedir
);
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
));
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
)
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
));
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
)
2103 if (*pszParmName
== '-')
2106 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2107 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
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
2121 return the parameter structure for a parameter
2123 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
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
;
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
)
2164 if (lp_ctx
->s3_fns
) {
2165 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
2167 return parm
->flags
& FLAG_CMDLINE
;
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
)
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
];
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
)
2210 bool bcopyall
= (pcopymapDest
== NULL
);
2211 struct parmlist_entry
*data
, *pdata
, *paramo
;
2214 for (i
= 0; parm_table
[i
].label
; i
++)
2215 if (parm_table
[i
].p_class
== P_LOCAL
&&
2216 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2218 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2220 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2222 switch (parm_table
[i
].type
) {
2224 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2231 *(int *)dest_ptr
= *(int *)src_ptr
;
2235 lpcfg_string_set(pserviceDest
,
2241 lpcfg_string_set_upper(pserviceDest
,
2246 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2247 *(const char ***)src_ptr
);
2255 init_copymap(pserviceDest
);
2256 if (pserviceSource
->copymap
)
2257 bitmap_copy(pserviceDest
->copymap
,
2258 pserviceSource
->copymap
);
2261 data
= pserviceSource
->param_opt
;
2264 pdata
= pserviceDest
->param_opt
;
2265 /* Traverse destination */
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
,
2275 pdata
= pdata
->next
;
2278 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2281 paramo
->key
= talloc_strdup(paramo
, data
->key
);
2282 paramo
->value
= talloc_strdup(paramo
, data
->value
);
2283 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
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
)
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"));
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
));
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
;
2337 if (f
->name
&& !strcmp(f
->name
, fname
))
2343 f
= talloc(lp_ctx
, struct file_lists
);
2346 f
->next
= lp_ctx
->file_lists
;
2347 f
->name
= talloc_strdup(f
, fname
);
2352 f
->subfname
= talloc_strdup(f
, subfname
);
2357 lp_ctx
->file_lists
= f
;
2358 f
->modtime
= file_modtime(subfname
);
2360 time_t t
= file_modtime(subfname
);
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
) {
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
,
2388 f
->modtime
= mod_time
;
2389 talloc_free(f
->subfname
);
2390 f
->subfname
= talloc_strdup(f
, n2
);
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
);
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
));
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
)
2444 struct loadparm_service
*serviceTemp
;
2446 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
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
));
2456 copy_service(lp_ctx
->currentService
,
2458 lp_ctx
->currentService
->copymap
);
2462 DEBUG(0, ("Unable to copy service - source not found: %s\n",
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
);
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
);
2491 /***************************************************************************
2492 Initialise a copymap.
2493 ***************************************************************************/
2495 static void init_copymap(struct loadparm_service
*pservice
)
2499 TALLOC_FREE(pservice
->copymap
);
2501 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2502 if (!pservice
->copymap
)
2504 ("Couldn't allocate copymap!! (size %d)\n",
2505 (int)NUMPARAMETERS
));
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
;
2521 TALLOC_CTX
*mem_ctx
;
2523 while (isspace((unsigned char)*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
;
2534 data
= service
->param_opt
;
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
)) {
2549 talloc_free(paramo
->value
);
2550 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2551 paramo
->priority
= flags
;
2557 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
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
);
2566 DLIST_ADD(service
->param_opt
, paramo
);
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
)
2579 /* if it is a special case then go ahead */
2580 if (parm_table
[parmnum
].special
) {
2582 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2587 goto mark_non_default
;
2590 /* now switch on the type of variable it is */
2591 switch (parm_table
[parmnum
].type
)
2595 if (!set_boolean(pszParmValue
, &b
)) {
2596 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2599 *(bool *)parm_ptr
= b
;
2605 if (!set_boolean(pszParmValue
, &b
)) {
2606 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2609 *(bool *)parm_ptr
= !b
;
2614 *(int *)parm_ptr
= atoi(pszParmValue
);
2618 *(char *)parm_ptr
= *pszParmValue
;
2622 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2628 if (conv_str_size_error(pszParmValue
, &val
)) {
2629 if (val
<= INT_MAX
) {
2630 *(int *)parm_ptr
= (int)val
;
2635 DEBUG(0,("lp_do_parameter(%s): value is not "
2636 "a valid size specifier!\n", pszParmValue
));
2641 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2642 pszParmValue
, NULL
);
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
,
2652 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2655 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2656 str_list_remove(*(const char ***)parm_ptr
,
2660 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2661 pszParmName
, pszParmValue
));
2664 *(const char ***)parm_ptr
= (const char **) new_list
;
2671 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2675 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2679 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2682 parm_table
[parmnum
].enum_list
[i
].name
)) {
2684 parm_table
[parmnum
].
2689 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2690 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2691 pszParmValue
, pszParmName
));
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
;
2715 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2716 const char *pszParmName
, const char *pszParmValue
)
2718 int parmnum
= map_parameter(pszParmName
);
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
));
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
) {
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
)
2747 int parmnum
= map_parameter(pszParmName
);
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
));
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
) {
2763 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2765 ("Global parameter %s found in service section!\n",
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
,
2792 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2794 if (lp_ctx
->bInGlobalSection
)
2795 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
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
, ...)
2814 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2816 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
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
)
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
);
2849 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
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
)) {
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
;
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
)
2881 s
= talloc_strdup(NULL
, option
);
2894 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
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
= ", ";
2914 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2915 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2917 p
->enum_list
[i
].name
);
2924 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2928 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2933 fprintf(f
, "%d", *(int *)ptr
);
2937 fprintf(f
, "%c", *(char *)ptr
);
2941 int val
= *(int *)ptr
;
2945 fprintf(f
, "0%o", val
);
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 */
2962 if ( strchr_m( *list
, ' ' ) ) {
2963 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2965 fprintf(f
, "%s%s", *list
, list_sep
);
2973 if (*(char **)ptr
) {
2974 fprintf(f
, "%s", *(char **)ptr
);
2983 * Check if two parameters are equal.
2986 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2991 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2997 return (*((int *)ptr1
) == *((int *)ptr2
));
3000 return (*((char *)ptr1
) == *((char *)ptr2
));
3004 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
3009 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
3014 return (p1
== p2
|| strequal(p1
, p2
));
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
;
3034 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
3035 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
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
));
3047 /* if we have a current service, tidy it up before moving on */
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 */
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
,
3062 DEBUG(0, ("Failed to add a new service\n"));
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
)
3080 switch (parm_table
[i
].type
) {
3083 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
3084 (const char **)def_ptr
);
3087 return strequal(parm_table
[i
].def
.svalue
,
3091 return parm_table
[i
].def
.bvalue
==
3098 return parm_table
[i
].def
.ivalue
==
3107 *Display the contents of the global structure.
3110 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
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
))
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
);
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
)) {
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
)
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
)) {
3161 if (defaults_saved
) {
3162 if (is_default(sDefault
, i
)) {
3167 if (equal_parameter(parm_table
[i
].type
,
3168 ((char *)pService
) +
3169 parm_table
[i
].offset
,
3170 ((char *)sDefault
) +
3171 parm_table
[i
].offset
))
3175 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3176 print_parameter(&parm_table
[i
],
3177 ((char *)pService
) + parm_table
[i
].offset
, f
);
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
;
3195 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3200 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3202 print_parameter(parm
, ptr
, f
);
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
,
3218 /* do the globals */
3219 for (; parm_table
[*i
].label
; (*i
)++) {
3220 if ((*parm_table
[*i
].label
== '-'))
3224 && (parm_table
[*i
].offset
==
3225 parm_table
[(*i
) - 1].offset
)
3226 && (parm_table
[*i
].p_class
==
3227 parm_table
[(*i
) - 1].p_class
))
3230 return &parm_table
[(*i
)++];
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
!= '-') &&
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
)++];
3260 * Auto-load some home services.
3262 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
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))
3278 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3279 if (lp_ctx
->services
[i
] == NULL
)
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. */
3301 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3302 struct parmlist_entry
*next
;
3303 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3305 if (data
->priority
& FLAG_CMDLINE
) continue;
3306 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
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
)
3323 struct loadparm_context
*lp_ctx
;
3324 struct parmlist_entry
*parm
;
3327 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
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
)) {
3355 if (parm_table
[i
].p_class
== P_LOCAL
) {
3356 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
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 */
3379 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
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
);
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
;
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
) {
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
) {
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");
3569 return dyn_CONFIGFILE
;
3573 * Update the internal state of a loadparm context after settings
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
) {
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
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);
3604 unsetenv("SOCKET_TESTNONBLOCK");
3610 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
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
)
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
)));
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
3672 global_loadparm_context
= lp_ctx
;
3673 lp_ctx
->loaded
= true;
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
,
3701 if (lp_ctx
->s3_fns
) {
3702 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
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')
3724 dump_a_service(service
, sDefault
, f
, NULL
);
3728 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
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
)
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
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
));
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
)
3781 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3782 service
->volume
: sDefault
->volume
));
3784 return lpcfg_servicename(service
);
3789 * If we are PDC then prefer us as DMB
3791 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
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
);
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;
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
) {
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
)
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");
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
);