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
;
2104 *(int *)dest_ptr
= *(int *)src_ptr
;
2108 lpcfg_string_set(pserviceDest
,
2114 lpcfg_string_set_upper(pserviceDest
,
2119 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2120 *(const char ***)src_ptr
);
2128 init_copymap(pserviceDest
);
2129 if (pserviceSource
->copymap
)
2130 bitmap_copy(pserviceDest
->copymap
,
2131 pserviceSource
->copymap
);
2134 data
= pserviceSource
->param_opt
;
2137 pdata
= pserviceDest
->param_opt
;
2138 /* Traverse destination */
2140 /* If we already have same option, override it */
2141 if (strcmp(pdata
->key
, data
->key
) == 0) {
2142 talloc_free(pdata
->value
);
2143 pdata
->value
= talloc_reference(pdata
,
2148 pdata
= pdata
->next
;
2151 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2154 paramo
->key
= talloc_reference(paramo
, data
->key
);
2155 paramo
->value
= talloc_reference(paramo
, data
->value
);
2156 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2163 * Check a service for consistency. Return False if the service is in any way
2164 * incomplete or faulty, else True.
2166 static bool lpcfg_service_ok(struct loadparm_service
*service
)
2171 if (service
->szService
[0] == '\0') {
2172 DEBUG(0, ("The following message indicates an internal error:\n"));
2173 DEBUG(0, ("No service name in service entry.\n"));
2177 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2178 /* I can't see why you'd want a non-printable printer service... */
2179 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2180 if (!service
->bPrint_ok
) {
2181 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2182 service
->szService
));
2183 service
->bPrint_ok
= true;
2185 /* [printers] service must also be non-browsable. */
2186 if (service
->bBrowseable
)
2187 service
->bBrowseable
= false;
2190 /* If a service is flagged unavailable, log the fact at level 0. */
2191 if (!service
->bAvailable
)
2192 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2193 service
->szService
));
2199 /*******************************************************************
2200 Keep a linked list of all config files so we know when one has changed
2201 it's date and needs to be reloaded.
2202 ********************************************************************/
2204 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2205 const char *fname
, const char *subfname
)
2207 struct file_lists
*f
= lp_ctx
->file_lists
;
2210 if (f
->name
&& !strcmp(f
->name
, fname
))
2216 f
= talloc(lp_ctx
, struct file_lists
);
2219 f
->next
= lp_ctx
->file_lists
;
2220 f
->name
= talloc_strdup(f
, fname
);
2225 f
->subfname
= talloc_strdup(f
, subfname
);
2230 lp_ctx
->file_lists
= f
;
2231 f
->modtime
= file_modtime(subfname
);
2233 time_t t
= file_modtime(subfname
);
2239 /*******************************************************************
2240 Check if a config file has changed date.
2241 ********************************************************************/
2242 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2244 struct file_lists
*f
;
2245 DEBUG(6, ("lp_file_list_changed()\n"));
2247 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2251 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2253 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2254 f
->name
, n2
, ctime(&f
->modtime
)));
2256 mod_time
= file_modtime(n2
);
2258 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2259 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2261 f
->modtime
= mod_time
;
2262 talloc_free(f
->subfname
);
2263 f
->subfname
= talloc_strdup(f
, n2
);
2270 /***************************************************************************
2271 Handle the "realm" parameter
2272 ***************************************************************************/
2274 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2275 const char *pszParmValue
, char **ptr
)
2277 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2279 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2280 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2282 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2283 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2288 /***************************************************************************
2289 Handle the include operation.
2290 ***************************************************************************/
2292 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2293 const char *pszParmValue
, char **ptr
)
2295 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2297 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2299 lpcfg_string_set(lp_ctx
, ptr
, fname
);
2301 if (file_exist(fname
))
2302 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2304 DEBUG(2, ("Can't find include file %s\n", fname
));
2309 /***************************************************************************
2310 Handle the interpretation of the copy parameter.
2311 ***************************************************************************/
2313 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2314 const char *pszParmValue
, char **ptr
)
2317 struct loadparm_service
*serviceTemp
;
2319 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2323 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2325 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2326 if (serviceTemp
== lp_ctx
->currentService
) {
2327 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2329 copy_service(lp_ctx
->currentService
,
2331 lp_ctx
->currentService
->copymap
);
2335 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2343 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2344 const char *pszParmValue
, char **ptr
)
2347 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2348 if (lp_ctx
->global
) {
2349 return debug_parse_levels(pszParmValue
);
2354 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2355 const char *pszParmValue
, char **ptr
)
2357 debug_set_logfile(pszParmValue
);
2358 if (lp_ctx
->global
) {
2359 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2364 /***************************************************************************
2365 Initialise a copymap.
2366 ***************************************************************************/
2368 static void init_copymap(struct loadparm_service
*pservice
)
2372 TALLOC_FREE(pservice
->copymap
);
2374 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2375 if (!pservice
->copymap
)
2377 ("Couldn't allocate copymap!! (size %d)\n",
2378 (int)NUMPARAMETERS
));
2380 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2381 bitmap_set(pservice
->copymap
, i
);
2385 * Process a parametric option
2387 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2388 struct loadparm_service
*service
,
2389 const char *pszParmName
,
2390 const char *pszParmValue
, int flags
)
2392 struct parmlist_entry
*paramo
, *data
;
2394 TALLOC_CTX
*mem_ctx
;
2396 while (isspace((unsigned char)*pszParmName
)) {
2400 name
= strlower_talloc(lp_ctx
, pszParmName
);
2401 if (!name
) return false;
2403 if (service
== NULL
) {
2404 data
= lp_ctx
->globals
->param_opt
;
2405 mem_ctx
= lp_ctx
->globals
;
2407 data
= service
->param_opt
;
2411 /* Traverse destination */
2412 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2413 /* If we already have the option set, override it unless
2414 it was a command line option and the new one isn't */
2415 if (strcmp(paramo
->key
, name
) == 0) {
2416 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2417 !(flags
& FLAG_CMDLINE
)) {
2422 talloc_free(paramo
->value
);
2423 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2424 paramo
->priority
= flags
;
2430 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2433 paramo
->key
= talloc_strdup(paramo
, name
);
2434 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2435 paramo
->priority
= flags
;
2436 if (service
== NULL
) {
2437 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2439 DLIST_ADD(service
->param_opt
, paramo
);
2447 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2448 const char *pszParmName
, const char *pszParmValue
,
2449 struct loadparm_context
*lp_ctx
, bool on_globals
)
2452 /* if it is a special case then go ahead */
2453 if (parm_table
[parmnum
].special
) {
2455 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2460 goto mark_non_default
;
2463 /* now switch on the type of variable it is */
2464 switch (parm_table
[parmnum
].type
)
2468 if (!set_boolean(pszParmValue
, &b
)) {
2469 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2472 *(bool *)parm_ptr
= b
;
2478 if (!set_boolean(pszParmValue
, &b
)) {
2479 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2482 *(bool *)parm_ptr
= !b
;
2487 *(int *)parm_ptr
= atoi(pszParmValue
);
2491 *(char *)parm_ptr
= *pszParmValue
;
2495 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2501 if (conv_str_size_error(pszParmValue
, &val
)) {
2502 if (val
<= INT_MAX
) {
2503 *(int *)parm_ptr
= (int)val
;
2508 DEBUG(0,("lp_do_parameter(%s): value is not "
2509 "a valid size specifier!\n", pszParmValue
));
2514 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2515 pszParmValue
, NULL
);
2519 char **new_list
= str_list_make(mem_ctx
,
2520 pszParmValue
, NULL
);
2521 for (i
=0; new_list
[i
]; i
++) {
2522 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
2523 if (!str_list_check(*(const char ***)parm_ptr
,
2525 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2528 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2529 str_list_remove(*(const char ***)parm_ptr
,
2533 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2534 pszParmName
, pszParmValue
));
2537 *(const char ***)parm_ptr
= (const char **) new_list
;
2544 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2548 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2552 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2555 parm_table
[parmnum
].enum_list
[i
].name
)) {
2557 parm_table
[parmnum
].
2562 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2563 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2564 pszParmValue
, pszParmName
));
2571 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2572 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2573 /* we have to also unset FLAG_DEFAULT on aliases */
2574 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2575 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2577 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2578 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2585 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2586 const char *pszParmName
, const char *pszParmValue
)
2588 int parmnum
= map_parameter(pszParmName
);
2592 if (strchr(pszParmName
, ':')) {
2593 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2595 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2599 /* if the flag has been set on the command line, then don't allow override,
2600 but don't report an error */
2601 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2605 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2607 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2608 pszParmName
, pszParmValue
, lp_ctx
, true);
2611 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2612 struct loadparm_service
*service
,
2613 const char *pszParmName
, const char *pszParmValue
)
2617 int parmnum
= map_parameter(pszParmName
);
2620 if (strchr(pszParmName
, ':')) {
2621 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2623 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2627 /* if the flag has been set on the command line, then don't allow override,
2628 but don't report an error */
2629 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2633 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2635 ("Global parameter %s found in service section!\n",
2639 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2641 if (!service
->copymap
)
2642 init_copymap(service
);
2644 /* this handles the aliases - set the copymap for other
2645 * entries with the same data pointer */
2646 for (i
= 0; parm_table
[i
].label
; i
++)
2647 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2648 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2649 bitmap_clear(service
->copymap
, i
);
2651 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2652 pszParmValue
, lp_ctx
, false);
2656 * Process a parameter.
2659 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2662 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2664 if (lp_ctx
->bInGlobalSection
)
2665 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2668 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2669 pszParmName
, pszParmValue
);
2673 variable argument do parameter
2675 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2676 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2677 const char *pszParmName
, const char *fmt
, ...)
2684 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2686 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2693 set a parameter from the commandline - this is called from command line parameter
2694 parsing code. It sets the parameter then marks the parameter as unable to be modified
2695 by smb.conf processing
2697 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2698 const char *pszParmValue
)
2703 if (lp_ctx
->s3_fns
) {
2704 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2707 parmnum
= map_parameter(pszParmName
);
2709 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2712 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2713 /* set a parametric option */
2714 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2715 pszParmValue
, FLAG_CMDLINE
);
2719 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2723 /* reset the CMDLINE flag in case this has been called before */
2724 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2726 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2730 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2732 /* we have to also set FLAG_CMDLINE on aliases */
2733 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2734 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2736 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2737 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2744 set a option from the commandline in 'a=b' format. Use to support --option
2746 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2751 s
= talloc_strdup(NULL
, option
);
2764 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2770 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2773 * Print a parameter of the specified type.
2776 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2778 /* For the seperation of lists values that we print below */
2779 const char *list_sep
= ", ";
2784 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2785 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2787 p
->enum_list
[i
].name
);
2794 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2798 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2803 fprintf(f
, "%d", *(int *)ptr
);
2807 fprintf(f
, "%c", *(char *)ptr
);
2811 int val
= *(int *)ptr
;
2815 fprintf(f
, "0%o", val
);
2824 if ((char ***)ptr
&& *(char ***)ptr
) {
2825 char **list
= *(char ***)ptr
;
2826 for (; *list
; list
++) {
2827 /* surround strings with whitespace in double quotes */
2828 if (*(list
+1) == NULL
) {
2829 /* last item, no extra separator */
2832 if ( strchr_m( *list
, ' ' ) ) {
2833 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2835 fprintf(f
, "%s%s", *list
, list_sep
);
2843 if (*(char **)ptr
) {
2844 fprintf(f
, "%s", *(char **)ptr
);
2853 * Check if two parameters are equal.
2856 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2861 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2867 return (*((int *)ptr1
) == *((int *)ptr2
));
2870 return (*((char *)ptr1
) == *((char *)ptr2
));
2874 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
2879 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2884 return (p1
== p2
|| strequal(p1
, p2
));
2893 * Process a new section (service).
2895 * At this stage all sections are services.
2896 * Later we'll have special sections that permit server parameters to be set.
2897 * Returns True on success, False on failure.
2900 static bool do_section(const char *pszSectionName
, void *userdata
)
2902 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2904 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2905 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2908 /* if we've just struck a global section, note the fact. */
2909 lp_ctx
->bInGlobalSection
= isglobal
;
2911 /* check for multiple global sections */
2912 if (lp_ctx
->bInGlobalSection
) {
2913 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2917 /* if we have a current service, tidy it up before moving on */
2920 if (lp_ctx
->currentService
!= NULL
)
2921 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2923 /* if all is still well, move to the next record in the services array */
2925 /* We put this here to avoid an odd message order if messages are */
2926 /* issued by the post-processing of a previous section. */
2927 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2929 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2932 DEBUG(0, ("Failed to add a new service\n"));
2942 * Determine if a particular base parameter is currently set to the default value.
2945 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2947 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2948 if (!defaults_saved
)
2950 switch (parm_table
[i
].type
) {
2953 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2954 (const char **)def_ptr
);
2957 return strequal(parm_table
[i
].def
.svalue
,
2961 return parm_table
[i
].def
.bvalue
==
2968 return parm_table
[i
].def
.ivalue
==
2975 *Display the contents of the global structure.
2978 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2982 struct parmlist_entry
*data
;
2984 fprintf(f
, "# Global parameters\n[global]\n");
2986 for (i
= 0; parm_table
[i
].label
; i
++)
2987 if (parm_table
[i
].p_class
== P_GLOBAL
&&
2988 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2989 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2991 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2992 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2995 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2996 for (data
= lp_ctx
->globals
->param_opt
; data
;
2997 data
= data
->next
) {
2998 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3001 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3008 * Display the contents of a single services record.
3011 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3012 unsigned int *flags
)
3015 struct parmlist_entry
*data
;
3017 if (pService
!= sDefault
)
3018 fprintf(f
, "\n[%s]\n", pService
->szService
);
3020 for (i
= 0; parm_table
[i
].label
; i
++) {
3021 if (parm_table
[i
].p_class
== P_LOCAL
&&
3022 (*parm_table
[i
].label
!= '-') &&
3023 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3025 if (pService
== sDefault
) {
3026 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3029 if (defaults_saved
) {
3030 if (is_default(sDefault
, i
)) {
3035 if (equal_parameter(parm_table
[i
].type
,
3036 ((char *)pService
) +
3037 parm_table
[i
].offset
,
3038 ((char *)sDefault
) +
3039 parm_table
[i
].offset
))
3043 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3044 print_parameter(&parm_table
[i
],
3045 ((char *)pService
) + parm_table
[i
].offset
, f
);
3049 if (pService
->param_opt
!= NULL
) {
3050 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3051 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3056 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3057 struct loadparm_service
*service
,
3058 const char *parm_name
, FILE * f
)
3060 struct parm_struct
*parm
;
3063 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3068 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3070 print_parameter(parm
, ptr
, f
);
3076 * Return info about the next parameter in a service.
3077 * snum==-1 gives the globals.
3078 * Return NULL when out of parameters.
3082 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3086 /* do the globals */
3087 for (; parm_table
[*i
].label
; (*i
)++) {
3088 if ((*parm_table
[*i
].label
== '-'))
3092 && (parm_table
[*i
].offset
==
3093 parm_table
[(*i
) - 1].offset
)
3094 && (parm_table
[*i
].p_class
==
3095 parm_table
[(*i
) - 1].p_class
))
3098 return &parm_table
[(*i
)++];
3101 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3103 for (; parm_table
[*i
].label
; (*i
)++) {
3104 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3105 (*parm_table
[*i
].label
!= '-') &&
3107 (parm_table
[*i
].offset
!=
3108 parm_table
[(*i
) - 1].offset
)))
3110 if (allparameters
||
3111 !equal_parameter(parm_table
[*i
].type
,
3112 ((char *)pService
) +
3113 parm_table
[*i
].offset
,
3114 ((char *)lp_ctx
->sDefault
) +
3115 parm_table
[*i
].offset
))
3117 return &parm_table
[(*i
)++];
3128 * Auto-load some home services.
3130 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3138 * Unload unused services.
3141 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3142 struct smbsrv_connection
*smb
,
3143 bool (*snumused
) (struct smbsrv_connection
*, int))
3146 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3147 if (lp_ctx
->services
[i
] == NULL
)
3150 if (!snumused
|| !snumused(smb
, i
)) {
3151 talloc_free(lp_ctx
->services
[i
]);
3152 lp_ctx
->services
[i
] = NULL
;
3158 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3160 struct parmlist_entry
*data
;
3162 if (lp_ctx
->refuse_free
) {
3163 /* someone is trying to free the
3164 global_loadparm_context.
3165 We can't allow that. */
3169 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3170 struct parmlist_entry
*next
;
3171 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3173 if (data
->priority
& FLAG_CMDLINE
) continue;
3174 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3183 * Initialise the global parameter structure.
3185 * Note that most callers should use loadparm_init_global() instead
3187 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3191 struct loadparm_context
*lp_ctx
;
3192 struct parmlist_entry
*parm
;
3195 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3199 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3200 lp_ctx
->bInGlobalSection
= true;
3201 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3202 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3204 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3205 lp_ctx
->sDefault
->bAvailable
= true;
3206 lp_ctx
->sDefault
->bBrowseable
= true;
3207 lp_ctx
->sDefault
->bRead_only
= true;
3208 lp_ctx
->sDefault
->bMap_archive
= true;
3209 lp_ctx
->sDefault
->iStrictLocking
= true;
3210 lp_ctx
->sDefault
->bOpLocks
= true;
3211 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3212 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3213 lp_ctx
->sDefault
->iDir_mask
= 0755;
3214 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3216 DEBUG(3, ("Initialising global parameters\n"));
3218 for (i
= 0; parm_table
[i
].label
; i
++) {
3219 if ((parm_table
[i
].type
== P_STRING
||
3220 parm_table
[i
].type
== P_USTRING
) &&
3221 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3223 if (parm_table
[i
].p_class
== P_LOCAL
) {
3224 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3226 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3228 *r
= talloc_strdup(lp_ctx
, "");
3232 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3233 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3234 talloc_free(logfile
);
3236 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3238 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3240 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
3241 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
3242 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
3244 /* options that can be set on the command line must be initialised via
3245 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3247 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3249 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3250 myname
= get_myname(lp_ctx
);
3251 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3252 talloc_free(myname
);
3253 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3255 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3257 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3258 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3260 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");
3261 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3262 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3263 /* the winbind method for domain controllers is for both RODC
3264 auth forwarding and for trusted domains */
3265 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3266 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3268 /* This hive should be dynamically generated by Samba using
3269 data from the sam, but for the moment leave it in a tdb to
3270 keep regedt32 from popping up an annoying dialog. */
3271 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3273 /* using UTF8 by default allows us to support all chars */
3274 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3276 /* Use codepage 850 as a default for the dos character set */
3277 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3280 * Allow the default PASSWD_CHAT to be overridden in local.h.
3282 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3284 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3285 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3286 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3287 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3288 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3290 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3291 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3292 "Samba %s", SAMBA_VERSION_STRING
);
3294 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3296 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3297 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3298 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
3300 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3301 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3302 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3303 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3304 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3305 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3306 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
3307 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3308 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3309 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3310 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3311 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3312 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3314 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3315 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3316 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3317 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3318 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3319 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3320 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3321 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3323 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3325 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3326 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3328 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3329 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3331 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3332 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3333 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3334 #if _SAMBA_BUILD_ >= 4
3335 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3336 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3337 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3338 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3339 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
3340 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
3342 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3343 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3344 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3346 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
3347 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
3349 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3351 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
3353 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3354 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3355 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3356 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3357 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3358 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3359 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3361 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3363 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3364 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3366 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3367 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3368 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3369 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3370 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3372 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3373 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3375 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "False");
3377 for (i
= 0; parm_table
[i
].label
; i
++) {
3378 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3379 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3383 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3384 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3385 parm
->priority
|= FLAG_DEFAULT
;
3393 * Initialise the global parameter structure.
3395 struct loadparm_context
*loadparm_init_global(bool load_default
)
3397 if (global_loadparm_context
== NULL
) {
3398 global_loadparm_context
= loadparm_init(NULL
);
3400 if (global_loadparm_context
== NULL
) {
3403 global_loadparm_context
->global
= true;
3404 if (load_default
&& !global_loadparm_context
->loaded
) {
3405 lpcfg_load_default(global_loadparm_context
);
3407 global_loadparm_context
->refuse_free
= true;
3408 return global_loadparm_context
;
3412 * Initialise the global parameter structure.
3414 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3415 const struct loadparm_s3_context
*s3_fns
)
3417 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3418 if (!loadparm_context
) {
3421 loadparm_context
->s3_fns
= s3_fns
;
3422 return loadparm_context
;
3425 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3427 return lp_ctx
->szConfigFile
;
3430 const char *lp_default_path(void)
3432 if (getenv("SMB_CONF_PATH"))
3433 return getenv("SMB_CONF_PATH");
3435 return dyn_CONFIGFILE
;
3439 * Update the internal state of a loadparm context after settings
3442 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3444 struct debug_settings settings
;
3445 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3447 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3448 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3451 if (!lp_ctx
->global
) {
3455 panic_action
= lp_ctx
->globals
->panic_action
;
3457 reload_charcnv(lp_ctx
);
3459 ZERO_STRUCT(settings
);
3460 /* Add any more debug-related smb.conf parameters created in
3462 settings
.timestamp_logs
= true;
3463 debug_set_settings(&settings
);
3465 /* FIXME: This is a bit of a hack, but we can't use a global, since
3466 * not everything that uses lp also uses the socket library */
3467 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3468 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3470 unsetenv("SOCKET_TESTNONBLOCK");
3476 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3480 path
= lp_default_path();
3482 if (!file_exist(path
)) {
3483 /* We allow the default smb.conf file to not exist,
3484 * basically the equivalent of an empty file. */
3485 return lpcfg_update(lp_ctx
);
3488 return lpcfg_load(lp_ctx
, path
);
3492 * Load the services array from the services file.
3494 * Return True on success, False on failure.
3496 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3501 filename
= talloc_strdup(lp_ctx
, filename
);
3503 lp_ctx
->szConfigFile
= filename
;
3505 if (lp_ctx
->s3_fns
) {
3506 return lp_ctx
->s3_fns
->load(filename
);
3509 lp_ctx
->bInGlobalSection
= true;
3510 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3511 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3513 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3515 /* We get sections first, so have to start 'behind' to make up */
3516 lp_ctx
->currentService
= NULL
;
3517 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3519 /* finish up the last section */
3520 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3522 if (lp_ctx
->currentService
!= NULL
)
3523 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3525 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3527 /* we do this unconditionally, so that it happens even
3528 for a missing smb.conf */
3529 reload_charcnv(lp_ctx
);
3531 if (bRetval
== true) {
3532 /* set this up so that any child python tasks will
3533 find the right smb.conf */
3534 setenv("SMB_CONF_PATH", filename
, 1);
3536 /* set the context used by the lp_*() function
3538 global_loadparm_context
= lp_ctx
;
3539 lp_ctx
->loaded
= true;
3546 * Return the max number of services.
3549 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3551 if (lp_ctx
->s3_fns
) {
3552 return lp_ctx
->s3_fns
->get_numservices();
3555 return lp_ctx
->iNumServices
;
3559 * Display the contents of the services array in human-readable form.
3562 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3567 if (lp_ctx
->s3_fns
) {
3568 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3572 defaults_saved
= !show_defaults
;
3574 dump_globals(lp_ctx
, f
, show_defaults
);
3576 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3578 for (iService
= 0; iService
< maxtoprint
; iService
++)
3579 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3583 * Display the contents of one service in human-readable form.
3585 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3587 if (service
!= NULL
) {
3588 if (service
->szService
[0] == '\0')
3590 dump_a_service(service
, sDefault
, f
, NULL
);
3594 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3597 if (lp_ctx
->s3_fns
) {
3598 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3601 return lp_ctx
->services
[snum
];
3604 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3605 const char *service_name
)
3610 if (lp_ctx
->s3_fns
) {
3611 return lp_ctx
->s3_fns
->get_service(service_name
);
3614 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3615 if (lp_ctx
->services
[iService
] &&
3616 lp_ctx
->services
[iService
]->szService
) {
3618 * The substitution here is used to support %U is
3621 serviceName
= standard_sub_basic(
3622 lp_ctx
->services
[iService
],
3623 lp_ctx
->services
[iService
]->szService
);
3624 if (strequal(serviceName
, service_name
)) {
3625 talloc_free(serviceName
);
3626 return lp_ctx
->services
[iService
];
3628 talloc_free(serviceName
);
3632 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3636 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3638 return lp_string((const char *)service
->szService
);
3642 * A useful volume label function.
3644 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3647 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3648 service
->volume
: sDefault
->volume
));
3650 return lpcfg_servicename(service
);
3655 * If we are PDC then prefer us as DMB
3657 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3660 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3661 service
->szPrintername
: sDefault
->szPrintername
));
3662 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3663 ret
= lpcfg_servicename(service
);
3670 * Return the max print jobs per queue.
3672 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3674 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3675 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3676 maxjobs
= PRINT_MAX_JOBID
- 1;
3681 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3683 if (lp_ctx
== NULL
) {
3684 return get_iconv_handle();
3686 return lp_ctx
->iconv_handle
;
3689 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3691 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3692 if (!lp_ctx
->global
) {
3696 if (old_ic
== NULL
) {
3697 old_ic
= global_iconv_handle
;
3699 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3700 global_iconv_handle
= lp_ctx
->iconv_handle
;
3703 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3705 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3708 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3710 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3713 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3715 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3718 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3720 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3723 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3725 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3728 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3730 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
3731 if (settings
== NULL
)
3733 SMB_ASSERT(lp_ctx
!= NULL
);
3734 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3735 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3739 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3741 if (lp_ctx
->s3_fns
) {
3742 return lp_ctx
->s3_fns
->server_role();
3745 return lp_find_server_role(lp_ctx
->globals
->server_role
,
3746 lp_ctx
->globals
->security
,
3747 lp_ctx
->globals
->domain_logons
,
3748 (lp_ctx
->globals
->domain_master
== true) ||
3749 (lp_ctx
->globals
->domain_master
== Auto
));
3752 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3754 if (lp_ctx
->s3_fns
) {
3755 return lp_ctx
->s3_fns
->security();
3758 return lp_find_security(lp_ctx
->globals
->server_role
,
3759 lp_ctx
->globals
->security
);