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),
174 .offset = LOCAL_VAR(szPath),
179 .label = "directory",
182 .offset = LOCAL_VAR(szPath),
187 .label = "workgroup",
190 .offset = GLOBAL_VAR(szWorkgroup),
198 .offset = GLOBAL_VAR(szRealm),
199 .special = handle_realm,
203 .label = "netbios name",
206 .offset = GLOBAL_VAR(szNetbiosName),
211 .label = "netbios aliases",
214 .offset = GLOBAL_VAR(szNetbiosAliases),
219 .label = "netbios scope",
222 .offset = GLOBAL_VAR(szNetbiosScope),
227 .label = "server string",
230 .offset = GLOBAL_VAR(szServerString),
235 .label = "interfaces",
238 .offset = GLOBAL_VAR(szInterfaces),
243 .label = "bind interfaces only",
246 .offset = GLOBAL_VAR(bBindInterfacesOnly),
251 .label = "ntvfs handler",
254 .offset = LOCAL_VAR(ntvfs_handler),
259 .label = "ntptr providor",
262 .offset = GLOBAL_VAR(ntptr_providor),
267 .label = "passdb backend",
270 .offset = GLOBAL_VAR(passdb_backend),
275 .label = "dcerpc endpoint servers",
278 .offset = GLOBAL_VAR(dcerpc_ep_servers),
283 .label = "server services",
286 .offset = GLOBAL_VAR(server_services),
295 .offset = GLOBAL_VAR(security),
297 .enum_list = enum_security
300 .label = "encrypt passwords",
303 .offset = GLOBAL_VAR(bEncryptPasswords),
308 .label = "null passwords",
311 .offset = GLOBAL_VAR(bNullPasswords),
316 .label = "obey pam restrictions",
319 .offset = GLOBAL_VAR(bObeyPamRestrictions),
324 .label = "password server",
327 .offset = GLOBAL_VAR(szPasswordServers),
332 .label = "private dir",
335 .offset = GLOBAL_VAR(szPrivateDir),
340 .label = "passwd chat",
343 .offset = GLOBAL_VAR(szPasswdChat),
348 .label = "password level",
351 .offset = GLOBAL_VAR(pwordlevel),
356 .label = "lanman auth",
359 .offset = GLOBAL_VAR(bLanmanAuth),
364 .label = "ntlm auth",
367 .offset = GLOBAL_VAR(bNTLMAuth),
372 .label = "client NTLMv2 auth",
375 .offset = GLOBAL_VAR(bClientNTLMv2Auth),
380 .label = "client lanman auth",
383 .offset = GLOBAL_VAR(bClientLanManAuth),
388 .label = "client plaintext auth",
391 .offset = GLOBAL_VAR(bClientPlaintextAuth),
396 .label = "client use spnego principal",
399 .offset = GLOBAL_VAR(client_use_spnego_principal),
405 .label = "read only",
408 .offset = LOCAL_VAR(bRead_only),
414 .label = "create mask",
417 .offset = LOCAL_VAR(iCreate_mask),
422 .label = "force create mode",
425 .offset = LOCAL_VAR(iCreate_force_mode),
430 .label = "directory mask",
433 .offset = LOCAL_VAR(iDir_mask),
438 .label = "force directory mode",
441 .offset = LOCAL_VAR(iDir_force_mode),
447 .label = "hosts allow",
450 .offset = LOCAL_VAR(szHostsallow),
455 .label = "hosts deny",
458 .offset = LOCAL_VAR(szHostsdeny),
464 .label = "log level",
467 .offset = GLOBAL_VAR(loglevel),
468 .special = handle_debuglevel,
472 .label = "debuglevel",
475 .offset = GLOBAL_VAR(loglevel),
476 .special = handle_debuglevel,
483 .offset = GLOBAL_VAR(logfile),
484 .special = handle_logfile,
489 .label = "smb ports",
492 .offset = GLOBAL_VAR(smb_ports),
500 .offset = GLOBAL_VAR(nbt_port),
505 .label = "dgram port",
508 .offset = GLOBAL_VAR(dgram_port),
513 .label = "cldap port",
516 .offset = GLOBAL_VAR(cldap_port),
521 .label = "krb5 port",
524 .offset = GLOBAL_VAR(krb5_port),
529 .label = "kpasswd port",
532 .offset = GLOBAL_VAR(kpasswd_port),
540 .offset = GLOBAL_VAR(web_port),
545 .label = "tls enabled",
548 .offset = GLOBAL_VAR(tls_enabled),
553 .label = "tls keyfile",
556 .offset = GLOBAL_VAR(tls_keyfile),
561 .label = "tls certfile",
564 .offset = GLOBAL_VAR(tls_certfile),
569 .label = "tls cafile",
572 .offset = GLOBAL_VAR(tls_cafile),
577 .label = "tls crlfile",
580 .offset = GLOBAL_VAR(tls_crlfile),
585 .label = "tls dh params file",
588 .offset = GLOBAL_VAR(tls_dhpfile),
593 .label = "large readwrite",
596 .offset = GLOBAL_VAR(bLargeReadwrite),
601 .label = "server max protocol",
604 .offset = GLOBAL_VAR(srv_maxprotocol),
606 .enum_list = enum_protocol
609 .label = "server min protocol",
612 .offset = GLOBAL_VAR(srv_minprotocol),
614 .enum_list = enum_protocol
617 .label = "client max protocol",
620 .offset = GLOBAL_VAR(cli_maxprotocol),
622 .enum_list = enum_protocol
625 .label = "client min protocol",
628 .offset = GLOBAL_VAR(cli_minprotocol),
630 .enum_list = enum_protocol
636 .offset = GLOBAL_VAR(bUnicode),
644 .offset = GLOBAL_VAR(bReadRaw),
649 .label = "write raw",
652 .offset = GLOBAL_VAR(bWriteRaw),
657 .label = "disable netbios",
660 .offset = GLOBAL_VAR(bDisableNetbios),
666 .label = "nt status support",
669 .offset = GLOBAL_VAR(bNTStatusSupport),
678 .offset = GLOBAL_VAR(max_mux),
686 .offset = GLOBAL_VAR(max_xmit),
692 .label = "name resolve order",
695 .offset = GLOBAL_VAR(szNameResolveOrder),
700 .label = "max wins ttl",
703 .offset = GLOBAL_VAR(max_wins_ttl),
708 .label = "min wins ttl",
711 .offset = GLOBAL_VAR(min_wins_ttl),
716 .label = "time server",
719 .offset = GLOBAL_VAR(bTimeServer),
724 .label = "unix extensions",
727 .offset = GLOBAL_VAR(bUnixExtensions),
732 .label = "use spnego",
735 .offset = GLOBAL_VAR(bUseSpnego),
740 .label = "server signing",
743 .offset = GLOBAL_VAR(server_signing),
745 .enum_list = enum_smb_signing_vals
748 .label = "client signing",
751 .offset = GLOBAL_VAR(client_signing),
753 .enum_list = enum_smb_signing_vals
756 .label = "rpc big endian",
759 .offset = GLOBAL_VAR(bRpcBigEndian),
765 .label = "max connections",
768 .offset = LOCAL_VAR(iMaxConnections),
773 .label = "paranoid server security",
776 .offset = GLOBAL_VAR(paranoid_server_security),
781 .label = "socket options",
784 .offset = GLOBAL_VAR(socket_options),
790 .label = "strict sync",
793 .offset = LOCAL_VAR(bStrictSync),
801 .offset = GLOBAL_VAR(bUseMmap),
804 .flags = FLAG_ADVANCED,
807 .label = "case insensitive filesystem",
810 .offset = LOCAL_VAR(bCIFileSystem),
816 .label = "max print jobs",
819 .offset = LOCAL_VAR(iMaxPrintJobs),
824 .label = "printable",
827 .offset = LOCAL_VAR(bPrint_ok),
835 .offset = LOCAL_VAR(bPrint_ok),
841 .label = "printer name",
844 .offset = LOCAL_VAR(szPrintername),
852 .offset = LOCAL_VAR(szPrintername),
858 .label = "map system",
861 .offset = LOCAL_VAR(bMap_system),
866 .label = "map hidden",
869 .offset = LOCAL_VAR(bMap_hidden),
874 .label = "map archive",
877 .offset = LOCAL_VAR(bMap_archive),
883 .label = "preferred master",
886 .offset = GLOBAL_VAR(bPreferredMaster),
888 .enum_list = enum_bool_auto
891 .label = "prefered master",
894 .offset = GLOBAL_VAR(bPreferredMaster),
896 .enum_list = enum_bool_auto
899 .label = "local master",
902 .offset = GLOBAL_VAR(bLocalMaster),
907 .label = "browseable",
910 .offset = LOCAL_VAR(bBrowseable),
915 .label = "browsable",
918 .offset = LOCAL_VAR(bBrowseable),
924 .label = "wins server",
927 .offset = GLOBAL_VAR(szWINSservers),
932 .label = "wins support",
935 .offset = GLOBAL_VAR(bWINSsupport),
940 .label = "dns proxy",
943 .offset = GLOBAL_VAR(bWINSdnsProxy),
948 .label = "wins hook",
951 .offset = GLOBAL_VAR(szWINSHook),
957 .label = "csc policy",
960 .offset = LOCAL_VAR(iCSCPolicy),
962 .enum_list = enum_csc_policy
966 .label = "strict locking",
969 .offset = LOCAL_VAR(iStrictLocking),
977 .offset = LOCAL_VAR(bOpLocks),
983 .label = "share backend",
986 .offset = GLOBAL_VAR(szShareBackend),
994 .offset = GLOBAL_VAR(szAutoServices),
999 .label = "auto services",
1001 .p_class = P_GLOBAL,
1002 .offset = GLOBAL_VAR(szAutoServices),
1007 .label = "lock dir",
1009 .p_class = P_GLOBAL,
1010 .offset = GLOBAL_VAR(szLockDir),
1015 .label = "lock directory",
1017 .p_class = P_GLOBAL,
1018 .offset = GLOBAL_VAR(szLockDir),
1023 .label = "state directory",
1025 .p_class = P_GLOBAL,
1026 .offset = GLOBAL_VAR(szStateDir),
1031 .label = "cache directory",
1033 .p_class = P_GLOBAL,
1034 .offset = GLOBAL_VAR(szCacheDir),
1039 .label = "pid directory",
1041 .p_class = P_GLOBAL,
1042 .offset = GLOBAL_VAR(szPidDir),
1048 .label = "socket address",
1050 .p_class = P_GLOBAL,
1051 .offset = GLOBAL_VAR(szSocketAddress),
1059 .offset = LOCAL_VAR(szCopy),
1060 .special = handle_copy,
1067 .offset = LOCAL_VAR(szInclude),
1068 .special = handle_include,
1073 .label = "available",
1076 .offset = LOCAL_VAR(bAvailable),
1084 .offset = LOCAL_VAR(volume),
1092 .offset = LOCAL_VAR(fstype),
1098 .label = "panic action",
1100 .p_class = P_GLOBAL,
1101 .offset = GLOBAL_VAR(panic_action),
1107 .label = "msdfs root",
1110 .offset = LOCAL_VAR(bMSDfsRoot),
1115 .label = "host msdfs",
1117 .p_class = P_GLOBAL,
1118 .offset = GLOBAL_VAR(bHostMSDfs),
1123 .label = "winbind separator",
1125 .p_class = P_GLOBAL,
1126 .offset = GLOBAL_VAR(szWinbindSeparator),
1131 .label = "winbindd socket directory",
1133 .p_class = P_GLOBAL,
1134 .offset = GLOBAL_VAR(szWinbinddSocketDirectory),
1139 .label = "winbindd privileged socket directory",
1141 .p_class = P_GLOBAL,
1142 .offset = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1147 .label = "winbind sealed pipes",
1149 .p_class = P_GLOBAL,
1150 .offset = GLOBAL_VAR(bWinbindSealedPipes),
1155 .label = "template shell",
1157 .p_class = P_GLOBAL,
1158 .offset = GLOBAL_VAR(szTemplateShell),
1163 .label = "template homedir",
1165 .p_class = P_GLOBAL,
1166 .offset = GLOBAL_VAR(szTemplateHomedir),
1171 .label = "idmap trusted only",
1173 .p_class = P_GLOBAL,
1174 .offset = GLOBAL_VAR(bIdmapTrustedOnly),
1180 .label = "ntp signd socket directory",
1182 .p_class = P_GLOBAL,
1183 .offset = GLOBAL_VAR(szNTPSignDSocketDirectory),
1188 .label = "rndc command",
1190 .p_class = P_GLOBAL,
1191 .offset = GLOBAL_VAR(szRNDCCommand),
1196 .label = "dns update command",
1198 .p_class = P_GLOBAL,
1199 .offset = GLOBAL_VAR(szDNSUpdateCommand),
1204 .label = "spn update command",
1206 .p_class = P_GLOBAL,
1207 .offset = GLOBAL_VAR(szSPNUpdateCommand),
1212 .label = "samba kcc command",
1214 .p_class = P_GLOBAL,
1215 .offset = GLOBAL_VAR(szSambaKCCCommand),
1220 .label = "nsupdate command",
1222 .p_class = P_GLOBAL,
1223 .offset = GLOBAL_VAR(szNSUpdateCommand),
1228 .label = "allow dns updates",
1230 .p_class = P_GLOBAL,
1231 .offset = GLOBAL_VAR(allow_dns_updates),
1233 .enum_list = enum_dns_update_settings
1236 {NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}
1240 /* local variables */
1241 struct loadparm_context {
1242 const char *szConfigFile;
1243 struct loadparm_global *globals;
1244 struct loadparm_service **services;
1245 struct loadparm_service *sDefault;
1246 struct smb_iconv_handle *iconv_handle;
1248 struct loadparm_service *currentService;
1249 bool bInGlobalSection;
1251 struct file_lists *next;
1256 unsigned int flags[NUMPARAMETERS];
1259 bool global; /* Is this the global context, which may set
1260 * global variables such as debug level etc? */
1261 const struct loadparm_s3_context *s3_fns;
1265 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1267 if (lp_ctx->s3_fns) {
1268 return lp_ctx->s3_fns->get_default_loadparm_service();
1270 return lp_ctx->sDefault;
1274 * Convenience routine to grab string parameters into temporary memory
1275 * and run standard_sub_basic on them.
1277 * The buffers can be written to by
1278 * callers without affecting the source string.
1281 static const char *lp_string(const char *s)
1283 #if 0 /* until REWRITE done to make thread-safe */
1284 size_t len = s ? strlen(s) : 0;
1288 /* The follow debug is useful for tracking down memory problems
1289 especially if you have an inner loop that is calling a lp_*()
1290 function that returns a string. Perhaps this debug should be
1291 present all the time? */
1294 DEBUG(10, ("lp_string(%s)\n", s));
1297 #if 0 /* until REWRITE done to make thread-safe */
1299 lp_talloc = talloc_init("lp_talloc");
1301 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1309 strlcpy(ret, s, len);
1311 if (trim_string(ret, "\"", "\"")) {
1312 if (strchr(ret,'"') != NULL)
1313 strlcpy(ret, s, len);
1316 standard_sub_basic(ret,len+100);
1323 In this section all the functions that are used to access the
1324 parameters from the rest of the program are defined
1328 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1329 * for code compatibility between existing Samba4 and Samba3 code.
1332 /* this global context supports the lp_*() function varients */
1333 static struct loadparm_context *global_loadparm_context;
1335 #define lpcfg_default_service global_loadparm_context->sDefault
1336 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1338 #define FN_GLOBAL_STRING(fn_name,var_name) \
1339 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1340 if (lp_ctx == NULL) return NULL; \
1341 if (lp_ctx->s3_fns) { \
1342 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1343 return lp_ctx->s3_fns->fn_name(); \
1345 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1348 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1349 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1350 if (lp_ctx == NULL) return NULL; \
1351 if (lp_ctx->s3_fns) { \
1352 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1353 return lp_ctx->s3_fns->fn_name(); \
1355 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1358 #define FN_GLOBAL_LIST(fn_name,var_name) \
1359 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1360 if (lp_ctx == NULL) return NULL; \
1361 if (lp_ctx->s3_fns) { \
1362 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1363 return lp_ctx->s3_fns->fn_name(); \
1365 return lp_ctx->globals->var_name; \
1368 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1369 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1370 if (lp_ctx == NULL) return false; \
1371 if (lp_ctx->s3_fns) { \
1372 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1373 return lp_ctx->s3_fns->fn_name(); \
1375 return lp_ctx->globals->var_name; \
1378 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1379 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1380 if (lp_ctx->s3_fns) { \
1381 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1382 return lp_ctx->s3_fns->fn_name(); \
1384 return lp_ctx->globals->var_name; \
1387 /* Local parameters don't need the ->s3_fns because the struct
1388 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1390 #define FN_LOCAL_STRING(fn_name,val) \
1391 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1392 struct loadparm_service *sDefault) { \
1393 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1396 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1398 #define FN_LOCAL_LIST(fn_name,val) \
1399 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1400 struct loadparm_service *sDefault) {\
1401 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1404 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1406 #define FN_LOCAL_BOOL(fn_name,val) \
1407 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1408 struct loadparm_service *sDefault) { \
1409 return((service != NULL)? service->val : sDefault->val); \
1412 #define FN_LOCAL_INTEGER(fn_name,val) \
1413 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1414 struct loadparm_service *sDefault) { \
1415 return((service != NULL)? service->val : sDefault->val); \
1418 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1420 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1422 #define FN_LOCAL_CHAR(fn_name,val) \
1423 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1424 struct loadparm_service *sDefault) { \
1425 return((service != NULL)? service->val : sDefault->val); \
1428 #include "lib/param/param_functions.c"
1430 FN_GLOBAL_LIST(smb_ports, smb_ports)
1431 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1432 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1433 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1434 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1435 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1436 FN_GLOBAL_INTEGER(web_port, web_port)
1437 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1438 FN_GLOBAL_STRING(logfile, logfile)
1439 FN_GLOBAL_STRING(share_backend, szShareBackend)
1440 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1441 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1442 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1443 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1444 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1445 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1446 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1447 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1448 FN_GLOBAL_STRING(serverstring, szServerString)
1449 FN_GLOBAL_STRING(lockdir, szLockDir)
1450 FN_GLOBAL_STRING(statedir, szStateDir)
1451 FN_GLOBAL_STRING(cachedir, szCacheDir)
1452 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1453 FN_GLOBAL_STRING(dos_charset, dos_charset)
1454 FN_GLOBAL_STRING(unix_charset, unix_charset)
1455 FN_GLOBAL_STRING(piddir, szPidDir)
1456 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1457 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1458 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1459 FN_GLOBAL_LIST(samba_kcc_command, szSambaKCCCommand)
1460 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1461 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1462 FN_GLOBAL_LIST(server_services, server_services)
1463 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1464 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1465 FN_GLOBAL_STRING(auto_services, szAutoServices)
1466 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1467 FN_GLOBAL_LIST(passwordserver, szPasswordServers)
1468 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1469 FN_GLOBAL_STRING(realm, szRealm_upper)
1470 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1471 FN_GLOBAL_STRING(socket_options, socket_options)
1472 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1473 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1474 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1475 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1476 FN_GLOBAL_LIST(interfaces, szInterfaces)
1477 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1478 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1479 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1480 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1481 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1482 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1483 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1484 FN_GLOBAL_BOOL(readraw, bReadRaw)
1485 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1486 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1487 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1488 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1489 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1490 FN_GLOBAL_BOOL(time_server, bTimeServer)
1491 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1492 FN_GLOBAL_BOOL(unicode, bUnicode)
1493 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1494 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1495 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1496 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1497 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1498 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1499 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1500 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1501 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1502 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1503 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1504 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1505 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1506 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1507 FN_GLOBAL_INTEGER(maxmux, max_mux)
1508 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1509 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1510 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1511 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1512 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1513 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1514 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1515 FN_GLOBAL_INTEGER(allow_dns_updates, allow_dns_updates)
1517 FN_GLOBAL_INTEGER(server_signing, server_signing)
1518 FN_GLOBAL_INTEGER(client_signing, client_signing)
1520 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1522 /* local prototypes */
1523 static int map_parameter(const char *pszParmName);
1524 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1525 const char *pszServiceName);
1526 static void copy_service(struct loadparm_service *pserviceDest,
1527 struct loadparm_service *pserviceSource,
1528 struct bitmap *pcopymapDest);
1529 static bool lpcfg_service_ok(struct loadparm_service *service);
1530 static bool do_section(const char *pszSectionName, void *);
1531 static void init_copymap(struct loadparm_service *pservice);
1533 /* This is a helper function for parametrical options support. */
1534 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1535 /* Actual parametrical functions are quite simple */
1536 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1537 struct loadparm_service *service,
1538 const char *type, const char *option)
1540 char *vfskey_tmp = NULL;
1541 char *vfskey = NULL;
1542 struct parmlist_entry *data;
1547 if (lp_ctx->s3_fns) {
1548 return lp_ctx->s3_fns->get_parametric(service, type, option);
1551 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1553 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1554 if (vfskey_tmp == NULL) return NULL;
1555 vfskey = strlower_talloc(NULL, vfskey_tmp);
1556 talloc_free(vfskey_tmp);
1559 if (strcmp(data->key, vfskey) == 0) {
1560 talloc_free(vfskey);
1566 if (service != NULL) {
1567 /* Try to fetch the same option but from globals */
1568 /* but only if we are not already working with globals */
1569 for (data = lp_ctx->globals->param_opt; data;
1570 data = data->next) {
1571 if (strcmp(data->key, vfskey) == 0) {
1572 talloc_free(vfskey);
1578 talloc_free(vfskey);
1585 * convenience routine to return int parameters.
1587 static int lp_int(const char *s)
1591 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1595 return strtol(s, NULL, 0);
1599 * convenience routine to return unsigned long parameters.
1601 static int lp_ulong(const char *s)
1605 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1609 return strtoul(s, NULL, 0);
1613 * convenience routine to return unsigned long parameters.
1615 static double lp_double(const char *s)
1619 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1623 return strtod(s, NULL);
1627 * convenience routine to return boolean parameters.
1629 static bool lp_bool(const char *s)
1634 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1638 if (!set_boolean(s, &ret)) {
1639 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1648 * Return parametric option from a given service. Type is a part of option before ':'
1649 * Parametric option has following syntax: 'Type: option = value'
1650 * Returned value is allocated in 'lp_talloc' context
1653 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1654 struct loadparm_service *service, const char *type,
1657 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1660 return lp_string(value);
1666 * Return parametric option from a given service. Type is a part of option before ':'
1667 * Parametric option has following syntax: 'Type: option = value'
1668 * Returned value is allocated in 'lp_talloc' context
1671 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1672 struct loadparm_context *lp_ctx,
1673 struct loadparm_service *service,
1675 const char *option, const char *separator)
1677 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1680 return (const char **)str_list_make(mem_ctx, value, separator);
1686 * Return parametric option from a given service. Type is a part of option before ':'
1687 * Parametric option has following syntax: 'Type: option = value'
1690 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1691 struct loadparm_service *service, const char *type,
1692 const char *option, int default_v)
1694 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1697 return lp_int(value);
1703 * Return parametric option from a given service. Type is a part of
1704 * option before ':'.
1705 * Parametric option has following syntax: 'Type: option = value'.
1708 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1709 struct loadparm_service *service, const char *type,
1710 const char *option, int default_v)
1714 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1716 if (value && conv_str_size_error(value, &bval)) {
1717 if (bval <= INT_MAX) {
1726 * Return parametric option from a given service.
1727 * Type is a part of option before ':'
1728 * Parametric option has following syntax: 'Type: option = value'
1730 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1731 struct loadparm_service *service, const char *type,
1732 const char *option, unsigned long default_v)
1734 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1737 return lp_ulong(value);
1743 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1744 struct loadparm_service *service, const char *type,
1745 const char *option, double default_v)
1747 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1750 return lp_double(value);
1756 * Return parametric option from a given service. Type is a part of option before ':'
1757 * Parametric option has following syntax: 'Type: option = value'
1760 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1761 struct loadparm_service *service, const char *type,
1762 const char *option, bool default_v)
1764 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1767 return lp_bool(value);
1774 * Initialise a service to the defaults.
1777 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1779 struct loadparm_service *pservice =
1780 talloc_zero(mem_ctx, struct loadparm_service);
1781 copy_service(pservice, sDefault, NULL);
1786 * Set a string value, deallocating any existing space, and allocing the space
1789 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1796 *dest = talloc_strdup(mem_ctx, src);
1797 if ((*dest) == NULL) {
1798 DEBUG(0,("Out of memory in string_set\n"));
1806 * Set a string value, deallocating any existing space, and allocing the space
1809 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1816 *dest = strupper_talloc(mem_ctx, src);
1817 if ((*dest) == NULL) {
1818 DEBUG(0,("Out of memory in string_set_upper\n"));
1828 * Add a new service to the services array initialising it with the given
1832 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1833 const struct loadparm_service *pservice,
1837 struct loadparm_service tservice;
1838 int num_to_alloc = lp_ctx->iNumServices + 1;
1839 struct parmlist_entry *data, *pdata;
1841 if (pservice == NULL) {
1842 pservice = lp_ctx->sDefault;
1845 tservice = *pservice;
1847 /* it might already exist */
1849 struct loadparm_service *service = getservicebyname(lp_ctx,
1851 if (service != NULL) {
1852 /* Clean all parametric options for service */
1853 /* They will be added during parsing again */
1854 data = service->param_opt;
1860 service->param_opt = NULL;
1865 /* find an invalid one */
1866 for (i = 0; i < lp_ctx->iNumServices; i++)
1867 if (lp_ctx->services[i] == NULL)
1870 /* if not, then create one */
1871 if (i == lp_ctx->iNumServices) {
1872 struct loadparm_service **tsp;
1874 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
1877 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1880 lp_ctx->services = tsp;
1881 lp_ctx->services[lp_ctx->iNumServices] = NULL;
1884 lp_ctx->iNumServices++;
1887 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
1888 if (lp_ctx->services[i] == NULL) {
1889 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1892 copy_service(lp_ctx->services[i], &tservice, NULL);
1894 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
1895 return lp_ctx->services[i];
1899 * Add a new home service, with the specified home directory, defaults coming
1900 * from service ifrom.
1903 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
1904 const char *pszHomename,
1905 struct loadparm_service *default_service,
1906 const char *user, const char *pszHomedir)
1908 struct loadparm_service *service;
1910 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
1912 if (service == NULL)
1915 if (!(*(default_service->szPath))
1916 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
1917 service->szPath = talloc_strdup(service, pszHomedir);
1919 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
1922 if (!(*(service->comment))) {
1923 service->comment = talloc_asprintf(service, "Home directory of %s", user);
1925 service->bAvailable = default_service->bAvailable;
1926 service->bBrowseable = default_service->bBrowseable;
1928 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1929 pszHomename, user, service->szPath));
1935 * Add a new printer service, with defaults coming from service iFrom.
1938 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
1939 const char *pszPrintername,
1940 struct loadparm_service *default_service)
1942 const char *comment = "From Printcap";
1943 struct loadparm_service *service;
1944 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
1946 if (service == NULL)
1949 /* note that we do NOT default the availability flag to True - */
1950 /* we take it from the default service passed. This allows all */
1951 /* dynamic printers to be disabled by disabling the [printers] */
1952 /* entry (if/when the 'available' keyword is implemented!). */
1954 /* the printer name is set to the service name. */
1955 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
1956 lpcfg_string_set(service, &service->comment, comment);
1957 service->bBrowseable = default_service->bBrowseable;
1958 /* Printers cannot be read_only. */
1959 service->bRead_only = false;
1960 /* Printer services must be printable. */
1961 service->bPrint_ok = true;
1963 DEBUG(3, ("adding printer service %s\n", pszPrintername));
1969 * Map a parameter's string representation to something we can use.
1970 * Returns False if the parameter string is not recognised, else TRUE.
1973 static int map_parameter(const char *pszParmName)
1977 if (*pszParmName == '-')
1980 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
1981 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
1984 /* Warn only if it isn't parametric option */
1985 if (strchr(pszParmName, ':') == NULL)
1986 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
1987 /* We do return 'fail' for parametric options as well because they are
1988 stored in different storage
1995 return the parameter structure for a parameter
1997 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2001 if (lp_ctx->s3_fns) {
2002 return lp_ctx->s3_fns->get_parm_struct(name);
2005 parmnum = map_parameter(name);
2006 if (parmnum == -1) return NULL;
2007 return &parm_table[parmnum];
2011 return the parameter pointer for a parameter
2013 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2014 struct loadparm_service *service, struct parm_struct *parm)
2016 if (lp_ctx->s3_fns) {
2017 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2020 if (service == NULL) {
2021 if (parm->p_class == P_LOCAL)
2022 return ((char *)lp_ctx->sDefault)+parm->offset;
2023 else if (parm->p_class == P_GLOBAL)
2024 return ((char *)lp_ctx->globals)+parm->offset;
2027 return ((char *)service) + parm->offset;
2032 return the parameter pointer for a parameter
2034 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2038 if (lp_ctx->s3_fns) {
2039 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2041 return parm->flags & FLAG_CMDLINE;
2046 parmnum = map_parameter(name);
2047 if (parmnum == -1) return false;
2049 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2053 * Find a service by name. Otherwise works like get_service.
2056 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2057 const char *pszServiceName)
2061 if (lp_ctx->s3_fns) {
2062 return lp_ctx->s3_fns->get_service(pszServiceName);
2065 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2066 if (lp_ctx->services[iService] != NULL &&
2067 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2068 return lp_ctx->services[iService];
2075 * Copy a service structure to another.
2076 * If pcopymapDest is NULL then copy all fields
2079 static void copy_service(struct loadparm_service *pserviceDest,
2080 struct loadparm_service *pserviceSource,
2081 struct bitmap *pcopymapDest)
2084 bool bcopyall = (pcopymapDest == NULL);
2085 struct parmlist_entry *data, *pdata, *paramo;
2088 for (i = 0; parm_table[i].label; i++)
2089 if (parm_table[i].p_class == P_LOCAL &&
2090 (bcopyall || bitmap_query(pcopymapDest, i))) {
2092 ((char *)pserviceSource) + parm_table[i].offset;
2094 ((char *)pserviceDest) + parm_table[i].offset;
2096 switch (parm_table[i].type) {
2098 *(bool *)dest_ptr = *(bool *)src_ptr;
2105 *(int *)dest_ptr = *(int *)src_ptr;
2109 lpcfg_string_set(pserviceDest,
2115 lpcfg_string_set_upper(pserviceDest,
2120 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
2121 *(const char ***)src_ptr);
2129 init_copymap(pserviceDest);
2130 if (pserviceSource->copymap)
2131 bitmap_copy(pserviceDest->copymap,
2132 pserviceSource->copymap);
2135 data = pserviceSource->param_opt;
2138 pdata = pserviceDest->param_opt;
2139 /* Traverse destination */
2141 /* If we already have same option, override it */
2142 if (strcmp(pdata->key, data->key) == 0) {
2143 talloc_free(pdata->value);
2144 pdata->value = talloc_strdup(pdata,
2149 pdata = pdata->next;
2152 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2155 paramo->key = talloc_strdup(paramo, data->key);
2156 paramo->value = talloc_strdup(paramo, data->value);
2157 DLIST_ADD(pserviceDest->param_opt, paramo);
2164 * Check a service for consistency. Return False if the service is in any way
2165 * incomplete or faulty, else True.
2167 static bool lpcfg_service_ok(struct loadparm_service *service)
2172 if (service->szService[0] == '\0') {
2173 DEBUG(0, ("The following message indicates an internal error:\n"));
2174 DEBUG(0, ("No service name in service entry.\n"));
2178 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2179 /* I can't see why you'd want a non-printable printer service... */
2180 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2181 if (!service->bPrint_ok) {
2182 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2183 service->szService));
2184 service->bPrint_ok = true;
2186 /* [printers] service must also be non-browsable. */
2187 if (service->bBrowseable)
2188 service->bBrowseable = false;
2191 /* If a service is flagged unavailable, log the fact at level 0. */
2192 if (!service->bAvailable)
2193 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2194 service->szService));
2200 /*******************************************************************
2201 Keep a linked list of all config files so we know when one has changed
2202 it's date and needs to be reloaded.
2203 ********************************************************************/
2205 static void add_to_file_list(struct loadparm_context *lp_ctx,
2206 const char *fname, const char *subfname)
2208 struct file_lists *f = lp_ctx->file_lists;
2211 if (f->name && !strcmp(f->name, fname))
2217 f = talloc(lp_ctx, struct file_lists);
2220 f->next = lp_ctx->file_lists;
2221 f->name = talloc_strdup(f, fname);
2226 f->subfname = talloc_strdup(f, subfname);
2231 lp_ctx->file_lists = f;
2232 f->modtime = file_modtime(subfname);
2234 time_t t = file_modtime(subfname);
2240 /*******************************************************************
2241 Check if a config file has changed date.
2242 ********************************************************************/
2243 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2245 struct file_lists *f;
2246 DEBUG(6, ("lp_file_list_changed()\n"));
2248 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2252 n2 = standard_sub_basic(lp_ctx, f->name);
2254 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2255 f->name, n2, ctime(&f->modtime)));
2257 mod_time = file_modtime(n2);
2259 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2260 DEBUGADD(6, ("file %s modified: %s\n", n2,
2262 f->modtime = mod_time;
2263 talloc_free(f->subfname);
2264 f->subfname = talloc_strdup(f, n2);
2271 /***************************************************************************
2272 Handle the "realm" parameter
2273 ***************************************************************************/
2275 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2276 const char *pszParmValue, char **ptr)
2278 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2280 talloc_free(lp_ctx->globals->szRealm_upper);
2281 talloc_free(lp_ctx->globals->szRealm_lower);
2283 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2284 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2289 /***************************************************************************
2290 Handle the include operation.
2291 ***************************************************************************/
2293 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2294 const char *pszParmValue, char **ptr)
2296 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2298 add_to_file_list(lp_ctx, pszParmValue, fname);
2300 lpcfg_string_set(lp_ctx, ptr, fname);
2302 if (file_exist(fname))
2303 return pm_process(fname, do_section, do_parameter, lp_ctx);
2305 DEBUG(2, ("Can't find include file %s\n", fname));
2310 /***************************************************************************
2311 Handle the interpretation of the copy parameter.
2312 ***************************************************************************/
2314 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2315 const char *pszParmValue, char **ptr)
2318 struct loadparm_service *serviceTemp;
2320 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2324 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2326 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2327 if (serviceTemp == lp_ctx->currentService) {
2328 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2330 copy_service(lp_ctx->currentService,
2332 lp_ctx->currentService->copymap);
2336 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2344 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2345 const char *pszParmValue, char **ptr)
2348 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2349 if (lp_ctx->global) {
2350 return debug_parse_levels(pszParmValue);
2355 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2356 const char *pszParmValue, char **ptr)
2358 debug_set_logfile(pszParmValue);
2359 if (lp_ctx->global) {
2360 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2365 /***************************************************************************
2366 Initialise a copymap.
2367 ***************************************************************************/
2369 static void init_copymap(struct loadparm_service *pservice)
2373 TALLOC_FREE(pservice->copymap);
2375 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2376 if (!pservice->copymap)
2378 ("Couldn't allocate copymap!! (size %d)\n",
2379 (int)NUMPARAMETERS));
2381 for (i = 0; i < NUMPARAMETERS; i++)
2382 bitmap_set(pservice->copymap, i);
2386 * Process a parametric option
2388 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2389 struct loadparm_service *service,
2390 const char *pszParmName,
2391 const char *pszParmValue, int flags)
2393 struct parmlist_entry *paramo, *data;
2395 TALLOC_CTX *mem_ctx;
2397 while (isspace((unsigned char)*pszParmName)) {
2401 name = strlower_talloc(lp_ctx, pszParmName);
2402 if (!name) return false;
2404 if (service == NULL) {
2405 data = lp_ctx->globals->param_opt;
2406 mem_ctx = lp_ctx->globals;
2408 data = service->param_opt;
2412 /* Traverse destination */
2413 for (paramo=data; paramo; paramo=paramo->next) {
2414 /* If we already have the option set, override it unless
2415 it was a command line option and the new one isn't */
2416 if (strcmp(paramo->key, name) == 0) {
2417 if ((paramo->priority & FLAG_CMDLINE) &&
2418 !(flags & FLAG_CMDLINE)) {
2423 talloc_free(paramo->value);
2424 paramo->value = talloc_strdup(paramo, pszParmValue);
2425 paramo->priority = flags;
2431 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2434 paramo->key = talloc_strdup(paramo, name);
2435 paramo->value = talloc_strdup(paramo, pszParmValue);
2436 paramo->priority = flags;
2437 if (service == NULL) {
2438 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2440 DLIST_ADD(service->param_opt, paramo);
2448 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2449 const char *pszParmName, const char *pszParmValue,
2450 struct loadparm_context *lp_ctx, bool on_globals)
2453 /* if it is a special case then go ahead */
2454 if (parm_table[parmnum].special) {
2456 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2461 goto mark_non_default;
2464 /* now switch on the type of variable it is */
2465 switch (parm_table[parmnum].type)
2469 if (!set_boolean(pszParmValue, &b)) {
2470 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2473 *(bool *)parm_ptr = b;
2479 if (!set_boolean(pszParmValue, &b)) {
2480 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2483 *(bool *)parm_ptr = !b;
2488 *(int *)parm_ptr = atoi(pszParmValue);
2492 *(char *)parm_ptr = *pszParmValue;
2496 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2502 if (conv_str_size_error(pszParmValue, &val)) {
2503 if (val <= INT_MAX) {
2504 *(int *)parm_ptr = (int)val;
2509 DEBUG(0,("lp_do_parameter(%s): value is not "
2510 "a valid size specifier!\n", pszParmValue));
2515 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2516 pszParmValue, NULL);
2520 char **new_list = str_list_make(mem_ctx,
2521 pszParmValue, NULL);
2522 for (i=0; new_list[i]; i++) {
2523 if (new_list[i][0] == '+' && new_list[i][1]) {
2524 if (!str_list_check(*(const char ***)parm_ptr,
2526 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2529 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2530 str_list_remove(*(const char ***)parm_ptr,
2534 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2535 pszParmName, pszParmValue));
2538 *(const char ***)parm_ptr = (const char **) new_list;
2545 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2549 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2553 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2556 parm_table[parmnum].enum_list[i].name)) {
2558 parm_table[parmnum].
2563 if (!parm_table[parmnum].enum_list[i].name) {
2564 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2565 pszParmValue, pszParmName));
2572 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2573 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2574 /* we have to also unset FLAG_DEFAULT on aliases */
2575 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2576 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2578 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2579 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2586 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2587 const char *pszParmName, const char *pszParmValue)
2589 int parmnum = map_parameter(pszParmName);
2593 if (strchr(pszParmName, ':')) {
2594 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2596 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2600 /* if the flag has been set on the command line, then don't allow override,
2601 but don't report an error */
2602 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2606 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2608 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2609 pszParmName, pszParmValue, lp_ctx, true);
2612 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2613 struct loadparm_service *service,
2614 const char *pszParmName, const char *pszParmValue)
2618 int parmnum = map_parameter(pszParmName);
2621 if (strchr(pszParmName, ':')) {
2622 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2624 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2628 /* if the flag has been set on the command line, then don't allow override,
2629 but don't report an error */
2630 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2634 if (parm_table[parmnum].p_class == P_GLOBAL) {
2636 ("Global parameter %s found in service section!\n",
2640 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2642 if (!service->copymap)
2643 init_copymap(service);
2645 /* this handles the aliases - set the copymap for other
2646 * entries with the same data pointer */
2647 for (i = 0; parm_table[i].label; i++)
2648 if (parm_table[i].offset == parm_table[parmnum].offset &&
2649 parm_table[i].p_class == parm_table[parmnum].p_class)
2650 bitmap_clear(service->copymap, i);
2652 return set_variable(service, parmnum, parm_ptr, pszParmName,
2653 pszParmValue, lp_ctx, false);
2657 * Process a parameter.
2660 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2663 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2665 if (lp_ctx->bInGlobalSection)
2666 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2669 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2670 pszParmName, pszParmValue);
2674 variable argument do parameter
2676 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2677 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2678 const char *pszParmName, const char *fmt, ...)
2685 s = talloc_vasprintf(NULL, fmt, ap);
2687 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2694 set a parameter from the commandline - this is called from command line parameter
2695 parsing code. It sets the parameter then marks the parameter as unable to be modified
2696 by smb.conf processing
2698 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2699 const char *pszParmValue)
2704 if (lp_ctx->s3_fns) {
2705 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2708 parmnum = map_parameter(pszParmName);
2710 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2713 if (parmnum < 0 && strchr(pszParmName, ':')) {
2714 /* set a parametric option */
2715 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2716 pszParmValue, FLAG_CMDLINE);
2720 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2724 /* reset the CMDLINE flag in case this has been called before */
2725 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2727 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2731 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2733 /* we have to also set FLAG_CMDLINE on aliases */
2734 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2735 lp_ctx->flags[i] |= FLAG_CMDLINE;
2737 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2738 lp_ctx->flags[i] |= FLAG_CMDLINE;
2745 set a option from the commandline in 'a=b' format. Use to support --option
2747 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2752 s = talloc_strdup(NULL, option);
2765 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2771 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2774 * Print a parameter of the specified type.
2777 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2779 /* For the seperation of lists values that we print below */
2780 const char *list_sep = ", ";
2785 for (i = 0; p->enum_list[i].name; i++) {
2786 if (*(int *)ptr == p->enum_list[i].value) {
2788 p->enum_list[i].name);
2795 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2799 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2804 fprintf(f, "%d", *(int *)ptr);
2808 fprintf(f, "%c", *(char *)ptr);
2812 int val = *(int *)ptr;
2816 fprintf(f, "0%o", val);
2825 if ((char ***)ptr && *(char ***)ptr) {
2826 char **list = *(char ***)ptr;
2827 for (; *list; list++) {
2828 /* surround strings with whitespace in double quotes */
2829 if (*(list+1) == NULL) {
2830 /* last item, no extra separator */
2833 if ( strchr_m( *list, ' ' ) ) {
2834 fprintf(f, "\"%s\"%s", *list, list_sep);
2836 fprintf(f, "%s%s", *list, list_sep);
2844 if (*(char **)ptr) {
2845 fprintf(f, "%s", *(char **)ptr);
2854 * Check if two parameters are equal.
2857 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2862 return (*((bool *)ptr1) == *((bool *)ptr2));
2868 return (*((int *)ptr1) == *((int *)ptr2));
2871 return (*((char *)ptr1) == *((char *)ptr2));
2875 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2880 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2885 return (p1 == p2 || strequal(p1, p2));
2894 * Process a new section (service).
2896 * At this stage all sections are services.
2897 * Later we'll have special sections that permit server parameters to be set.
2898 * Returns True on success, False on failure.
2901 static bool do_section(const char *pszSectionName, void *userdata)
2903 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2905 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2906 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2909 /* if we've just struck a global section, note the fact. */
2910 lp_ctx->bInGlobalSection = isglobal;
2912 /* check for multiple global sections */
2913 if (lp_ctx->bInGlobalSection) {
2914 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2918 /* if we have a current service, tidy it up before moving on */
2921 if (lp_ctx->currentService != NULL)
2922 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2924 /* if all is still well, move to the next record in the services array */
2926 /* We put this here to avoid an odd message order if messages are */
2927 /* issued by the post-processing of a previous section. */
2928 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2930 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2933 DEBUG(0, ("Failed to add a new service\n"));
2943 * Determine if a particular base parameter is currently set to the default value.
2946 static bool is_default(struct loadparm_service *sDefault, int i)
2948 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
2949 if (!defaults_saved)
2951 switch (parm_table[i].type) {
2954 return str_list_equal((const char **)parm_table[i].def.lvalue,
2955 (const char **)def_ptr);
2958 return strequal(parm_table[i].def.svalue,
2962 return parm_table[i].def.bvalue ==
2969 return parm_table[i].def.ivalue ==
2976 *Display the contents of the global structure.
2979 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2983 struct parmlist_entry *data;
2985 fprintf(f, "# Global parameters\n[global]\n");
2987 for (i = 0; parm_table[i].label; i++)
2988 if (parm_table[i].p_class == P_GLOBAL &&
2989 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2990 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
2992 fprintf(f, "\t%s = ", parm_table[i].label);
2993 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2996 if (lp_ctx->globals->param_opt != NULL) {
2997 for (data = lp_ctx->globals->param_opt; data;
2998 data = data->next) {
2999 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3002 fprintf(f, "\t%s = %s\n", data->key, data->value);
3009 * Display the contents of a single services record.
3012 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3013 unsigned int *flags)
3016 struct parmlist_entry *data;
3018 if (pService != sDefault)
3019 fprintf(f, "\n[%s]\n", pService->szService);
3021 for (i = 0; parm_table[i].label; i++) {
3022 if (parm_table[i].p_class == P_LOCAL &&
3023 (*parm_table[i].label != '-') &&
3024 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3026 if (pService == sDefault) {
3027 if (flags && (flags[i] & FLAG_DEFAULT)) {
3030 if (defaults_saved) {
3031 if (is_default(sDefault, i)) {
3036 if (equal_parameter(parm_table[i].type,
3037 ((char *)pService) +
3038 parm_table[i].offset,
3039 ((char *)sDefault) +
3040 parm_table[i].offset))
3044 fprintf(f, "\t%s = ", parm_table[i].label);
3045 print_parameter(&parm_table[i],
3046 ((char *)pService) + parm_table[i].offset, f);
3050 if (pService->param_opt != NULL) {
3051 for (data = pService->param_opt; data; data = data->next) {
3052 fprintf(f, "\t%s = %s\n", data->key, data->value);
3057 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3058 struct loadparm_service *service,
3059 const char *parm_name, FILE * f)
3061 struct parm_struct *parm;
3064 parm = lpcfg_parm_struct(lp_ctx, parm_name);
3069 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3071 print_parameter(parm, ptr, f);
3077 * Return info about the next parameter in a service.
3078 * snum==-1 gives the globals.
3079 * Return NULL when out of parameters.
3083 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3087 /* do the globals */
3088 for (; parm_table[*i].label; (*i)++) {
3089 if ((*parm_table[*i].label == '-'))
3093 && (parm_table[*i].offset ==
3094 parm_table[(*i) - 1].offset)
3095 && (parm_table[*i].p_class ==
3096 parm_table[(*i) - 1].p_class))
3099 return &parm_table[(*i)++];
3102 struct loadparm_service *pService = lp_ctx->services[snum];
3104 for (; parm_table[*i].label; (*i)++) {
3105 if (parm_table[*i].p_class == P_LOCAL &&
3106 (*parm_table[*i].label != '-') &&
3108 (parm_table[*i].offset !=
3109 parm_table[(*i) - 1].offset)))
3111 if (allparameters ||
3112 !equal_parameter(parm_table[*i].type,
3113 ((char *)pService) +
3114 parm_table[*i].offset,
3115 ((char *)lp_ctx->sDefault) +
3116 parm_table[*i].offset))
3118 return &parm_table[(*i)++];
3129 * Auto-load some home services.
3131 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3139 * Unload unused services.
3142 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3143 struct smbsrv_connection *smb,
3144 bool (*snumused) (struct smbsrv_connection *, int))
3147 for (i = 0; i < lp_ctx->iNumServices; i++) {
3148 if (lp_ctx->services[i] == NULL)
3151 if (!snumused || !snumused(smb, i)) {
3152 talloc_free(lp_ctx->services[i]);
3153 lp_ctx->services[i] = NULL;
3159 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3161 struct parmlist_entry *data;
3163 if (lp_ctx->refuse_free) {
3164 /* someone is trying to free the
3165 global_loadparm_context.
3166 We can't allow that. */
3170 if (lp_ctx->globals->param_opt != NULL) {
3171 struct parmlist_entry *next;
3172 for (data = lp_ctx->globals->param_opt; data; data=next) {
3174 if (data->priority & FLAG_CMDLINE) continue;
3175 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3184 * Initialise the global parameter structure.
3186 * Note that most callers should use loadparm_init_global() instead
3188 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3192 struct loadparm_context *lp_ctx;
3193 struct parmlist_entry *parm;
3196 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3200 talloc_set_destructor(lp_ctx, lpcfg_destructor);
3201 lp_ctx->bInGlobalSection = true;
3202 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3203 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3205 lp_ctx->sDefault->iMaxPrintJobs = 1000;
3206 lp_ctx->sDefault->bAvailable = true;
3207 lp_ctx->sDefault->bBrowseable = true;
3208 lp_ctx->sDefault->bRead_only = true;
3209 lp_ctx->sDefault->bMap_archive = true;
3210 lp_ctx->sDefault->iStrictLocking = true;
3211 lp_ctx->sDefault->bOpLocks = true;
3212 lp_ctx->sDefault->iCreate_mask = 0744;
3213 lp_ctx->sDefault->iCreate_force_mode = 0000;
3214 lp_ctx->sDefault->iDir_mask = 0755;
3215 lp_ctx->sDefault->iDir_force_mode = 0000;
3217 DEBUG(3, ("Initialising global parameters\n"));
3219 for (i = 0; parm_table[i].label; i++) {
3220 if ((parm_table[i].type == P_STRING ||
3221 parm_table[i].type == P_USTRING) &&
3222 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3224 if (parm_table[i].p_class == P_LOCAL) {
3225 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3227 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3229 *r = talloc_strdup(lp_ctx, "");
3233 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3234 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3235 talloc_free(logfile);
3237 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3239 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3241 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3242 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3243 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3245 /* options that can be set on the command line must be initialised via
3246 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3248 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3250 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3251 myname = get_myname(lp_ctx);
3252 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3253 talloc_free(myname);
3254 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3256 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3258 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3259 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3261 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");
3262 lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3263 lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3264 /* the winbind method for domain controllers is for both RODC
3265 auth forwarding and for trusted domains */
3266 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3267 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3269 /* This hive should be dynamically generated by Samba using
3270 data from the sam, but for the moment leave it in a tdb to
3271 keep regedt32 from popping up an annoying dialog. */
3272 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3274 /* using UTF8 by default allows us to support all chars */
3275 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3277 /* Use codepage 850 as a default for the dos character set */
3278 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3281 * Allow the default PASSWD_CHAT to be overridden in local.h.
3283 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3285 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3286 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3287 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3288 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3289 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3291 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3292 lpcfg_do_global_parameter_var(lp_ctx, "server string",
3293 "Samba %s", SAMBA_VERSION_STRING);
3295 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3297 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3298 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3299 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3301 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3302 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3303 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3304 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3305 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3306 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3307 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3308 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3309 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3310 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3311 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3312 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3313 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3315 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3316 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3317 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3318 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3319 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3320 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3321 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3322 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3324 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3326 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3327 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3329 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3330 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3332 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3333 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3334 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3335 #if _SAMBA_BUILD_ >= 4
3336 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3337 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3338 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3339 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3340 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3341 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3343 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3344 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3345 lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3347 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3348 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3350 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3352 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3354 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3355 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3356 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3357 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3358 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3359 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3360 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3362 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3364 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3365 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3367 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3368 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3369 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3370 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3371 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3373 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3374 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3376 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3378 for (i = 0; parm_table[i].label; i++) {
3379 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3380 lp_ctx->flags[i] |= FLAG_DEFAULT;
3384 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3385 if (!(parm->priority & FLAG_CMDLINE)) {
3386 parm->priority |= FLAG_DEFAULT;
3394 * Initialise the global parameter structure.
3396 struct loadparm_context *loadparm_init_global(bool load_default)
3398 if (global_loadparm_context == NULL) {
3399 global_loadparm_context = loadparm_init(NULL);
3401 if (global_loadparm_context == NULL) {
3404 global_loadparm_context->global = true;
3405 if (load_default && !global_loadparm_context->loaded) {
3406 lpcfg_load_default(global_loadparm_context);
3408 global_loadparm_context->refuse_free = true;
3409 return global_loadparm_context;
3413 * Initialise the global parameter structure.
3415 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3416 const struct loadparm_s3_context *s3_fns)
3418 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3419 if (!loadparm_context) {
3422 loadparm_context->s3_fns = s3_fns;
3423 return loadparm_context;
3426 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3428 return lp_ctx->szConfigFile;
3431 const char *lp_default_path(void)
3433 if (getenv("SMB_CONF_PATH"))
3434 return getenv("SMB_CONF_PATH");
3436 return dyn_CONFIGFILE;
3440 * Update the internal state of a loadparm context after settings
3443 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3445 struct debug_settings settings;
3446 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3448 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3449 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3452 if (!lp_ctx->global) {
3456 panic_action = lp_ctx->globals->panic_action;
3458 reload_charcnv(lp_ctx);
3460 ZERO_STRUCT(settings);
3461 /* Add any more debug-related smb.conf parameters created in
3463 settings.timestamp_logs = true;
3464 debug_set_settings(&settings);
3466 /* FIXME: This is a bit of a hack, but we can't use a global, since
3467 * not everything that uses lp also uses the socket library */
3468 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3469 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3471 unsetenv("SOCKET_TESTNONBLOCK");
3477 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3481 path = lp_default_path();
3483 if (!file_exist(path)) {
3484 /* We allow the default smb.conf file to not exist,
3485 * basically the equivalent of an empty file. */
3486 return lpcfg_update(lp_ctx);
3489 return lpcfg_load(lp_ctx, path);
3493 * Load the services array from the services file.
3495 * Return True on success, False on failure.
3497 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3502 filename = talloc_strdup(lp_ctx, filename);
3504 lp_ctx->szConfigFile = filename;
3506 if (lp_ctx->s3_fns) {
3507 return lp_ctx->s3_fns->load(filename);
3510 lp_ctx->bInGlobalSection = true;
3511 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3512 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3514 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3516 /* We get sections first, so have to start 'behind' to make up */
3517 lp_ctx->currentService = NULL;
3518 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3520 /* finish up the last section */
3521 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3523 if (lp_ctx->currentService != NULL)
3524 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3526 bRetval = bRetval && lpcfg_update(lp_ctx);
3528 /* we do this unconditionally, so that it happens even
3529 for a missing smb.conf */
3530 reload_charcnv(lp_ctx);
3532 if (bRetval == true) {
3533 /* set this up so that any child python tasks will
3534 find the right smb.conf */
3535 setenv("SMB_CONF_PATH", filename, 1);
3537 /* set the context used by the lp_*() function
3539 global_loadparm_context = lp_ctx;
3540 lp_ctx->loaded = true;
3547 * Return the max number of services.
3550 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3552 if (lp_ctx->s3_fns) {
3553 return lp_ctx->s3_fns->get_numservices();
3556 return lp_ctx->iNumServices;
3560 * Display the contents of the services array in human-readable form.
3563 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3568 if (lp_ctx->s3_fns) {
3569 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3573 defaults_saved = !show_defaults;
3575 dump_globals(lp_ctx, f, show_defaults);
3577 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3579 for (iService = 0; iService < maxtoprint; iService++)
3580 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3584 * Display the contents of one service in human-readable form.
3586 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3588 if (service != NULL) {
3589 if (service->szService[0] == '\0')
3591 dump_a_service(service, sDefault, f, NULL);
3595 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3598 if (lp_ctx->s3_fns) {
3599 return lp_ctx->s3_fns->get_servicebynum(snum);
3602 return lp_ctx->services[snum];
3605 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3606 const char *service_name)
3611 if (lp_ctx->s3_fns) {
3612 return lp_ctx->s3_fns->get_service(service_name);
3615 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3616 if (lp_ctx->services[iService] &&
3617 lp_ctx->services[iService]->szService) {
3619 * The substitution here is used to support %U is
3622 serviceName = standard_sub_basic(
3623 lp_ctx->services[iService],
3624 lp_ctx->services[iService]->szService);
3625 if (strequal(serviceName, service_name)) {
3626 talloc_free(serviceName);
3627 return lp_ctx->services[iService];
3629 talloc_free(serviceName);
3633 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3637 const char *lpcfg_servicename(const struct loadparm_service *service)
3639 return lp_string((const char *)service->szService);
3643 * A useful volume label function.
3645 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3648 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3649 service->volume : sDefault->volume));
3651 return lpcfg_servicename(service);
3656 * If we are PDC then prefer us as DMB
3658 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3661 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3662 service->szPrintername : sDefault->szPrintername));
3663 if (ret == NULL || (ret != NULL && *ret == '\0'))
3664 ret = lpcfg_servicename(service);
3671 * Return the max print jobs per queue.
3673 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3675 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3676 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3677 maxjobs = PRINT_MAX_JOBID - 1;
3682 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3684 if (lp_ctx == NULL) {
3685 return get_iconv_handle();
3687 return lp_ctx->iconv_handle;
3690 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3692 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3693 if (!lp_ctx->global) {
3697 if (old_ic == NULL) {
3698 old_ic = global_iconv_handle;
3700 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3701 global_iconv_handle = lp_ctx->iconv_handle;
3704 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3706 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3709 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3711 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3714 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3716 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3719 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3721 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3724 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3726 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3729 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3731 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3732 if (settings == NULL)
3734 SMB_ASSERT(lp_ctx != NULL);
3735 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3736 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3740 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3742 if (lp_ctx->s3_fns) {
3743 return lp_ctx->s3_fns->server_role();
3746 return lp_find_server_role(lp_ctx->globals->server_role,
3747 lp_ctx->globals->security,
3748 lp_ctx->globals->domain_logons,
3749 (lp_ctx->globals->domain_master == true) ||
3750 (lp_ctx->globals->domain_master == Auto));
3753 int lpcfg_security(struct loadparm_context *lp_ctx)
3755 if (lp_ctx->s3_fns) {
3756 return lp_ctx->s3_fns->security();
3759 return lp_find_security(lp_ctx->globals->server_role,
3760 lp_ctx->globals->security);