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"
69 #define standard_sub_basic talloc_strdup
71 static bool do_parameter(const char *, const char *, void *);
72 static bool defaults_saved
= false;
74 #define LOADPARM_EXTRA_GLOBALS \
75 struct parmlist_entry *param_opt; \
90 #include "param_global.h"
92 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
95 /* prototypes for the special type handlers */
96 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
97 const char *pszParmValue
, char **ptr
);
98 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
99 const char *pszParmValue
, char **ptr
);
100 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
101 const char *pszParmValue
, char **ptr
);
102 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
103 const char *pszParmValue
, char **ptr
);
104 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
105 const char *pszParmValue
, char **ptr
);
107 #include "param_enums.c"
109 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
110 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
112 static struct parm_struct parm_table
[] = {
114 .label
= "server role",
117 .offset
= GLOBAL_VAR(server_role
),
119 .enum_list
= enum_server_role
122 .label
= "domain logons",
125 .offset
= GLOBAL_VAR(domain_logons
),
127 .enum_list
= enum_bool_auto
130 .label
= "domain master",
133 .offset
= GLOBAL_VAR(domain_master
),
135 .enum_list
= enum_bool_auto
138 .label
= "dos charset",
141 .offset
= GLOBAL_VAR(dos_charset
),
146 .label
= "unix charset",
149 .offset
= GLOBAL_VAR(unix_charset
),
154 .label
= "ncalrpc dir",
157 .offset
= GLOBAL_VAR(ncalrpc_dir
),
165 .offset
= LOCAL_VAR(comment
),
173 .offset
= LOCAL_VAR(szPath
),
178 .label
= "directory",
181 .offset
= LOCAL_VAR(szPath
),
186 .label
= "workgroup",
189 .offset
= GLOBAL_VAR(szWorkgroup
),
197 .offset
= GLOBAL_VAR(szRealm
),
198 .special
= handle_realm
,
202 .label
= "netbios name",
205 .offset
= GLOBAL_VAR(szNetbiosName
),
210 .label
= "netbios aliases",
213 .offset
= GLOBAL_VAR(szNetbiosAliases
),
218 .label
= "netbios scope",
221 .offset
= GLOBAL_VAR(szNetbiosScope
),
226 .label
= "server string",
229 .offset
= GLOBAL_VAR(szServerString
),
234 .label
= "interfaces",
237 .offset
= GLOBAL_VAR(szInterfaces
),
242 .label
= "bind interfaces only",
245 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
250 .label
= "ntvfs handler",
253 .offset
= LOCAL_VAR(ntvfs_handler
),
258 .label
= "ntptr providor",
261 .offset
= GLOBAL_VAR(ntptr_providor
),
266 .label
= "passdb backend",
269 .offset
= GLOBAL_VAR(passdb_backend
),
274 .label
= "dcerpc endpoint servers",
277 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
282 .label
= "server services",
285 .offset
= GLOBAL_VAR(server_services
),
294 .offset
= GLOBAL_VAR(security
),
296 .enum_list
= enum_security
299 .label
= "encrypt passwords",
302 .offset
= GLOBAL_VAR(bEncryptPasswords
),
307 .label
= "null passwords",
310 .offset
= GLOBAL_VAR(bNullPasswords
),
315 .label
= "obey pam restrictions",
318 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
323 .label
= "password server",
326 .offset
= GLOBAL_VAR(szPasswordServers
),
331 .label
= "private dir",
334 .offset
= GLOBAL_VAR(szPrivateDir
),
339 .label
= "passwd chat",
342 .offset
= GLOBAL_VAR(szPasswdChat
),
347 .label
= "password level",
350 .offset
= GLOBAL_VAR(pwordlevel
),
355 .label
= "lanman auth",
358 .offset
= GLOBAL_VAR(bLanmanAuth
),
363 .label
= "ntlm auth",
366 .offset
= GLOBAL_VAR(bNTLMAuth
),
371 .label
= "client NTLMv2 auth",
374 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
379 .label
= "client lanman auth",
382 .offset
= GLOBAL_VAR(bClientLanManAuth
),
387 .label
= "client plaintext auth",
390 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
395 .label
= "client use spnego principal",
398 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
404 .label
= "read only",
407 .offset
= LOCAL_VAR(bRead_only
),
413 .label
= "create mask",
416 .offset
= LOCAL_VAR(iCreate_mask
),
421 .label
= "force create mode",
424 .offset
= LOCAL_VAR(iCreate_force_mode
),
429 .label
= "directory mask",
432 .offset
= LOCAL_VAR(iDir_mask
),
437 .label
= "force directory mode",
440 .offset
= LOCAL_VAR(iDir_force_mode
),
446 .label
= "hosts allow",
449 .offset
= LOCAL_VAR(szHostsallow
),
454 .label
= "hosts deny",
457 .offset
= LOCAL_VAR(szHostsdeny
),
463 .label
= "log level",
466 .offset
= GLOBAL_VAR(loglevel
),
467 .special
= handle_debuglevel
,
471 .label
= "debuglevel",
474 .offset
= GLOBAL_VAR(loglevel
),
475 .special
= handle_debuglevel
,
482 .offset
= GLOBAL_VAR(logfile
),
483 .special
= handle_logfile
,
488 .label
= "smb ports",
491 .offset
= GLOBAL_VAR(smb_ports
),
499 .offset
= GLOBAL_VAR(nbt_port
),
504 .label
= "dgram port",
507 .offset
= GLOBAL_VAR(dgram_port
),
512 .label
= "cldap port",
515 .offset
= GLOBAL_VAR(cldap_port
),
520 .label
= "krb5 port",
523 .offset
= GLOBAL_VAR(krb5_port
),
528 .label
= "kpasswd port",
531 .offset
= GLOBAL_VAR(kpasswd_port
),
539 .offset
= GLOBAL_VAR(web_port
),
544 .label
= "tls enabled",
547 .offset
= GLOBAL_VAR(tls_enabled
),
552 .label
= "tls keyfile",
555 .offset
= GLOBAL_VAR(tls_keyfile
),
560 .label
= "tls certfile",
563 .offset
= GLOBAL_VAR(tls_certfile
),
568 .label
= "tls cafile",
571 .offset
= GLOBAL_VAR(tls_cafile
),
576 .label
= "tls crlfile",
579 .offset
= GLOBAL_VAR(tls_crlfile
),
584 .label
= "tls dh params file",
587 .offset
= GLOBAL_VAR(tls_dhpfile
),
592 .label
= "large readwrite",
595 .offset
= GLOBAL_VAR(bLargeReadwrite
),
600 .label
= "server max protocol",
603 .offset
= GLOBAL_VAR(srv_maxprotocol
),
605 .enum_list
= enum_protocol
608 .label
= "server min protocol",
611 .offset
= GLOBAL_VAR(srv_minprotocol
),
613 .enum_list
= enum_protocol
616 .label
= "client max protocol",
619 .offset
= GLOBAL_VAR(cli_maxprotocol
),
621 .enum_list
= enum_protocol
624 .label
= "client min protocol",
627 .offset
= GLOBAL_VAR(cli_minprotocol
),
629 .enum_list
= enum_protocol
635 .offset
= GLOBAL_VAR(bUnicode
),
643 .offset
= GLOBAL_VAR(bReadRaw
),
648 .label
= "write raw",
651 .offset
= GLOBAL_VAR(bWriteRaw
),
656 .label
= "disable netbios",
659 .offset
= GLOBAL_VAR(bDisableNetbios
),
665 .label
= "nt status support",
668 .offset
= GLOBAL_VAR(bNTStatusSupport
),
677 .offset
= GLOBAL_VAR(max_mux
),
685 .offset
= GLOBAL_VAR(max_xmit
),
691 .label
= "name resolve order",
694 .offset
= GLOBAL_VAR(szNameResolveOrder
),
699 .label
= "max wins ttl",
702 .offset
= GLOBAL_VAR(max_wins_ttl
),
707 .label
= "min wins ttl",
710 .offset
= GLOBAL_VAR(min_wins_ttl
),
715 .label
= "time server",
718 .offset
= GLOBAL_VAR(bTimeServer
),
723 .label
= "unix extensions",
726 .offset
= GLOBAL_VAR(bUnixExtensions
),
731 .label
= "use spnego",
734 .offset
= GLOBAL_VAR(bUseSpnego
),
739 .label
= "server signing",
742 .offset
= GLOBAL_VAR(server_signing
),
744 .enum_list
= enum_smb_signing_vals
747 .label
= "client signing",
750 .offset
= GLOBAL_VAR(client_signing
),
752 .enum_list
= enum_smb_signing_vals
755 .label
= "rpc big endian",
758 .offset
= GLOBAL_VAR(bRpcBigEndian
),
764 .label
= "max connections",
767 .offset
= LOCAL_VAR(iMaxConnections
),
772 .label
= "paranoid server security",
775 .offset
= GLOBAL_VAR(paranoid_server_security
),
780 .label
= "socket options",
783 .offset
= GLOBAL_VAR(socket_options
),
789 .label
= "strict sync",
792 .offset
= LOCAL_VAR(bStrictSync
),
800 .offset
= GLOBAL_VAR(bUseMmap
),
803 .flags
= FLAG_ADVANCED
,
806 .label
= "case insensitive filesystem",
809 .offset
= LOCAL_VAR(bCIFileSystem
),
815 .label
= "max print jobs",
818 .offset
= LOCAL_VAR(iMaxPrintJobs
),
823 .label
= "printable",
826 .offset
= LOCAL_VAR(bPrint_ok
),
834 .offset
= LOCAL_VAR(bPrint_ok
),
840 .label
= "printer name",
843 .offset
= LOCAL_VAR(szPrintername
),
851 .offset
= LOCAL_VAR(szPrintername
),
857 .label
= "map system",
860 .offset
= LOCAL_VAR(bMap_system
),
865 .label
= "map hidden",
868 .offset
= LOCAL_VAR(bMap_hidden
),
873 .label
= "map archive",
876 .offset
= LOCAL_VAR(bMap_archive
),
882 .label
= "preferred master",
885 .offset
= GLOBAL_VAR(bPreferredMaster
),
887 .enum_list
= enum_bool_auto
890 .label
= "prefered master",
893 .offset
= GLOBAL_VAR(bPreferredMaster
),
895 .enum_list
= enum_bool_auto
898 .label
= "local master",
901 .offset
= GLOBAL_VAR(bLocalMaster
),
906 .label
= "browseable",
909 .offset
= LOCAL_VAR(bBrowseable
),
914 .label
= "browsable",
917 .offset
= LOCAL_VAR(bBrowseable
),
923 .label
= "wins server",
926 .offset
= GLOBAL_VAR(szWINSservers
),
931 .label
= "wins support",
934 .offset
= GLOBAL_VAR(bWINSsupport
),
939 .label
= "dns proxy",
942 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
947 .label
= "wins hook",
950 .offset
= GLOBAL_VAR(szWINSHook
),
956 .label
= "csc policy",
959 .offset
= LOCAL_VAR(iCSCPolicy
),
961 .enum_list
= enum_csc_policy
965 .label
= "strict locking",
968 .offset
= LOCAL_VAR(iStrictLocking
),
976 .offset
= LOCAL_VAR(bOpLocks
),
982 .label
= "share backend",
985 .offset
= GLOBAL_VAR(szShareBackend
),
993 .offset
= GLOBAL_VAR(szAutoServices
),
998 .label
= "auto services",
1000 .p_class
= P_GLOBAL
,
1001 .offset
= GLOBAL_VAR(szAutoServices
),
1006 .label
= "lock dir",
1008 .p_class
= P_GLOBAL
,
1009 .offset
= GLOBAL_VAR(szLockDir
),
1014 .label
= "lock directory",
1016 .p_class
= P_GLOBAL
,
1017 .offset
= GLOBAL_VAR(szLockDir
),
1022 .label
= "state directory",
1024 .p_class
= P_GLOBAL
,
1025 .offset
= GLOBAL_VAR(szStateDir
),
1030 .label
= "cache directory",
1032 .p_class
= P_GLOBAL
,
1033 .offset
= GLOBAL_VAR(szCacheDir
),
1038 .label
= "pid directory",
1040 .p_class
= P_GLOBAL
,
1041 .offset
= GLOBAL_VAR(szPidDir
),
1047 .label
= "socket address",
1049 .p_class
= P_GLOBAL
,
1050 .offset
= GLOBAL_VAR(szSocketAddress
),
1058 .offset
= LOCAL_VAR(szCopy
),
1059 .special
= handle_copy
,
1066 .offset
= LOCAL_VAR(szInclude
),
1067 .special
= handle_include
,
1072 .label
= "available",
1075 .offset
= LOCAL_VAR(bAvailable
),
1083 .offset
= LOCAL_VAR(volume
),
1091 .offset
= LOCAL_VAR(fstype
),
1097 .label
= "panic action",
1099 .p_class
= P_GLOBAL
,
1100 .offset
= GLOBAL_VAR(panic_action
),
1106 .label
= "msdfs root",
1109 .offset
= LOCAL_VAR(bMSDfsRoot
),
1114 .label
= "host msdfs",
1116 .p_class
= P_GLOBAL
,
1117 .offset
= GLOBAL_VAR(bHostMSDfs
),
1122 .label
= "winbind separator",
1124 .p_class
= P_GLOBAL
,
1125 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1130 .label
= "winbindd socket directory",
1132 .p_class
= P_GLOBAL
,
1133 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1138 .label
= "winbindd privileged socket directory",
1140 .p_class
= P_GLOBAL
,
1141 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1146 .label
= "winbind sealed pipes",
1148 .p_class
= P_GLOBAL
,
1149 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1154 .label
= "template shell",
1156 .p_class
= P_GLOBAL
,
1157 .offset
= GLOBAL_VAR(szTemplateShell
),
1162 .label
= "template homedir",
1164 .p_class
= P_GLOBAL
,
1165 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1170 .label
= "idmap trusted only",
1172 .p_class
= P_GLOBAL
,
1173 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1179 .label
= "ntp signd socket directory",
1181 .p_class
= P_GLOBAL
,
1182 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1187 .label
= "rndc command",
1189 .p_class
= P_GLOBAL
,
1190 .offset
= GLOBAL_VAR(szRNDCCommand
),
1195 .label
= "dns update command",
1197 .p_class
= P_GLOBAL
,
1198 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1203 .label
= "spn update command",
1205 .p_class
= P_GLOBAL
,
1206 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1211 .label
= "samba kcc command",
1213 .p_class
= P_GLOBAL
,
1214 .offset
= GLOBAL_VAR(szSambaKCCCommand
),
1219 .label
= "nsupdate command",
1221 .p_class
= P_GLOBAL
,
1222 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1227 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1231 /* local variables */
1232 struct loadparm_context
{
1233 const char *szConfigFile
;
1234 struct loadparm_global
*globals
;
1235 struct loadparm_service
**services
;
1236 struct loadparm_service
*sDefault
;
1237 struct smb_iconv_handle
*iconv_handle
;
1239 struct loadparm_service
*currentService
;
1240 bool bInGlobalSection
;
1242 struct file_lists
*next
;
1247 unsigned int flags
[NUMPARAMETERS
];
1250 bool global
; /* Is this the global context, which may set
1251 * global variables such as debug level etc? */
1252 const struct loadparm_s3_context
*s3_fns
;
1256 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1258 if (lp_ctx
->s3_fns
) {
1259 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1261 return lp_ctx
->sDefault
;
1265 * Convenience routine to grab string parameters into temporary memory
1266 * and run standard_sub_basic on them.
1268 * The buffers can be written to by
1269 * callers without affecting the source string.
1272 static const char *lp_string(const char *s
)
1274 #if 0 /* until REWRITE done to make thread-safe */
1275 size_t len
= s
? strlen(s
) : 0;
1279 /* The follow debug is useful for tracking down memory problems
1280 especially if you have an inner loop that is calling a lp_*()
1281 function that returns a string. Perhaps this debug should be
1282 present all the time? */
1285 DEBUG(10, ("lp_string(%s)\n", s
));
1288 #if 0 /* until REWRITE done to make thread-safe */
1290 lp_talloc
= talloc_init("lp_talloc");
1292 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1300 strlcpy(ret
, s
, len
);
1302 if (trim_string(ret
, "\"", "\"")) {
1303 if (strchr(ret
,'"') != NULL
)
1304 strlcpy(ret
, s
, len
);
1307 standard_sub_basic(ret
,len
+100);
1314 In this section all the functions that are used to access the
1315 parameters from the rest of the program are defined
1319 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1320 * for code compatibility between existing Samba4 and Samba3 code.
1323 /* this global context supports the lp_*() function varients */
1324 static struct loadparm_context
*global_loadparm_context
;
1326 #define lpcfg_default_service global_loadparm_context->sDefault
1327 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1329 #define FN_GLOBAL_STRING(fn_name,var_name) \
1330 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1331 if (lp_ctx == NULL) return NULL; \
1332 if (lp_ctx->s3_fns) { \
1333 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1334 return lp_ctx->s3_fns->fn_name(); \
1336 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1339 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1340 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1341 if (lp_ctx == NULL) return NULL; \
1342 if (lp_ctx->s3_fns) { \
1343 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1344 return lp_ctx->s3_fns->fn_name(); \
1346 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1349 #define FN_GLOBAL_LIST(fn_name,var_name) \
1350 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1351 if (lp_ctx == NULL) return NULL; \
1352 if (lp_ctx->s3_fns) { \
1353 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1354 return lp_ctx->s3_fns->fn_name(); \
1356 return lp_ctx->globals->var_name; \
1359 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1360 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1361 if (lp_ctx == NULL) return false; \
1362 if (lp_ctx->s3_fns) { \
1363 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1364 return lp_ctx->s3_fns->fn_name(); \
1366 return lp_ctx->globals->var_name; \
1369 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1370 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
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 /* Local parameters don't need the ->s3_fns because the struct
1379 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1381 #define FN_LOCAL_STRING(fn_name,val) \
1382 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1383 struct loadparm_service *sDefault) { \
1384 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1387 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1389 #define FN_LOCAL_LIST(fn_name,val) \
1390 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1391 struct loadparm_service *sDefault) {\
1392 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1395 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1397 #define FN_LOCAL_BOOL(fn_name,val) \
1398 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1399 struct loadparm_service *sDefault) { \
1400 return((service != NULL)? service->val : sDefault->val); \
1403 #define FN_LOCAL_INTEGER(fn_name,val) \
1404 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1405 struct loadparm_service *sDefault) { \
1406 return((service != NULL)? service->val : sDefault->val); \
1409 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1411 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1413 #define FN_LOCAL_CHAR(fn_name,val) \
1414 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1415 struct loadparm_service *sDefault) { \
1416 return((service != NULL)? service->val : sDefault->val); \
1419 #include "lib/param/param_functions.c"
1421 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
1422 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
1423 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
1424 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
1425 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
1426 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
1427 FN_GLOBAL_INTEGER(web_port
, web_port
)
1428 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
1429 FN_GLOBAL_STRING(logfile
, logfile
)
1430 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
1431 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
1432 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
1433 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
1434 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
1435 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
1436 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
1437 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
1438 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
1439 FN_GLOBAL_STRING(serverstring
, szServerString
)
1440 FN_GLOBAL_STRING(lockdir
, szLockDir
)
1441 FN_GLOBAL_STRING(statedir
, szStateDir
)
1442 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1443 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
1444 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
1445 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
1446 FN_GLOBAL_STRING(piddir
, szPidDir
)
1447 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
1448 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
1449 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
1450 FN_GLOBAL_LIST(samba_kcc_command
, szSambaKCCCommand
)
1451 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
1452 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
1453 FN_GLOBAL_LIST(server_services
, server_services
)
1454 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
1455 FN_GLOBAL_STRING(passdb_backend
, passdb_backend
)
1456 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
1457 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
1458 FN_GLOBAL_LIST(passwordserver
, szPasswordServers
)
1459 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
1460 FN_GLOBAL_STRING(realm
, szRealm_upper
)
1461 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
1462 FN_GLOBAL_STRING(socket_options
, socket_options
)
1463 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
1464 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
1465 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
1466 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
1467 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
1468 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1469 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
1470 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
1471 FN_GLOBAL_BOOL(we_are_a_wins_server
, bWINSsupport
)
1472 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
1473 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
1474 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
1475 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1476 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
1477 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1478 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
1479 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
1480 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
1481 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
1482 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
1483 FN_GLOBAL_BOOL(unicode
, bUnicode
)
1484 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
1485 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
1486 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
1487 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
1488 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
1489 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
1490 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
1491 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
1492 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
1493 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
1494 FN_GLOBAL_BOOL(use_mmap
, bUseMmap
)
1495 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
1496 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
1497 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
1498 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
1499 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
1500 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
1501 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
1502 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
1503 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
1504 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
1505 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
1507 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
1508 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
1510 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
1512 /* local prototypes */
1513 static int map_parameter(const char *pszParmName
);
1514 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1515 const char *pszServiceName
);
1516 static void copy_service(struct loadparm_service
*pserviceDest
,
1517 struct loadparm_service
*pserviceSource
,
1518 struct bitmap
*pcopymapDest
);
1519 static bool lpcfg_service_ok(struct loadparm_service
*service
);
1520 static bool do_section(const char *pszSectionName
, void *);
1521 static void init_copymap(struct loadparm_service
*pservice
);
1523 /* This is a helper function for parametrical options support. */
1524 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1525 /* Actual parametrical functions are quite simple */
1526 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1527 struct loadparm_service
*service
,
1528 const char *type
, const char *option
)
1530 char *vfskey_tmp
= NULL
;
1531 char *vfskey
= NULL
;
1532 struct parmlist_entry
*data
;
1537 if (lp_ctx
->s3_fns
) {
1538 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1541 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1543 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1544 if (vfskey_tmp
== NULL
) return NULL
;
1545 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1546 talloc_free(vfskey_tmp
);
1549 if (strcmp(data
->key
, vfskey
) == 0) {
1550 talloc_free(vfskey
);
1556 if (service
!= NULL
) {
1557 /* Try to fetch the same option but from globals */
1558 /* but only if we are not already working with globals */
1559 for (data
= lp_ctx
->globals
->param_opt
; data
;
1560 data
= data
->next
) {
1561 if (strcmp(data
->key
, vfskey
) == 0) {
1562 talloc_free(vfskey
);
1568 talloc_free(vfskey
);
1575 * convenience routine to return int parameters.
1577 static int lp_int(const char *s
)
1581 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1585 return strtol(s
, NULL
, 0);
1589 * convenience routine to return unsigned long parameters.
1591 static int lp_ulong(const char *s
)
1595 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1599 return strtoul(s
, NULL
, 0);
1603 * convenience routine to return unsigned long parameters.
1605 static double lp_double(const char *s
)
1609 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1613 return strtod(s
, NULL
);
1617 * convenience routine to return boolean parameters.
1619 static bool lp_bool(const char *s
)
1624 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1628 if (!set_boolean(s
, &ret
)) {
1629 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1638 * Return parametric option from a given service. Type is a part of option before ':'
1639 * Parametric option has following syntax: 'Type: option = value'
1640 * Returned value is allocated in 'lp_talloc' context
1643 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1644 struct loadparm_service
*service
, const char *type
,
1647 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1650 return lp_string(value
);
1656 * Return parametric option from a given service. Type is a part of option before ':'
1657 * Parametric option has following syntax: 'Type: option = value'
1658 * Returned value is allocated in 'lp_talloc' context
1661 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1662 struct loadparm_context
*lp_ctx
,
1663 struct loadparm_service
*service
,
1665 const char *option
, const char *separator
)
1667 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1670 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1676 * Return parametric option from a given service. Type is a part of option before ':'
1677 * Parametric option has following syntax: 'Type: option = value'
1680 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1681 struct loadparm_service
*service
, const char *type
,
1682 const char *option
, int default_v
)
1684 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1687 return lp_int(value
);
1693 * Return parametric option from a given service. Type is a part of
1694 * option before ':'.
1695 * Parametric option has following syntax: 'Type: option = value'.
1698 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1699 struct loadparm_service
*service
, const char *type
,
1700 const char *option
, int default_v
)
1704 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1706 if (value
&& conv_str_size_error(value
, &bval
)) {
1707 if (bval
<= INT_MAX
) {
1716 * Return parametric option from a given service.
1717 * Type is a part of option before ':'
1718 * Parametric option has following syntax: 'Type: option = value'
1720 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1721 struct loadparm_service
*service
, const char *type
,
1722 const char *option
, unsigned long default_v
)
1724 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1727 return lp_ulong(value
);
1733 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1734 struct loadparm_service
*service
, const char *type
,
1735 const char *option
, double default_v
)
1737 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1740 return lp_double(value
);
1746 * Return parametric option from a given service. Type is a part of option before ':'
1747 * Parametric option has following syntax: 'Type: option = value'
1750 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1751 struct loadparm_service
*service
, const char *type
,
1752 const char *option
, bool default_v
)
1754 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1757 return lp_bool(value
);
1764 * Initialise a service to the defaults.
1767 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1769 struct loadparm_service
*pservice
=
1770 talloc_zero(mem_ctx
, struct loadparm_service
);
1771 copy_service(pservice
, sDefault
, NULL
);
1776 * Set a string value, deallocating any existing space, and allocing the space
1779 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1786 *dest
= talloc_strdup(mem_ctx
, src
);
1787 if ((*dest
) == NULL
) {
1788 DEBUG(0,("Out of memory in string_set\n"));
1796 * Set a string value, deallocating any existing space, and allocing the space
1799 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1806 *dest
= strupper_talloc(mem_ctx
, src
);
1807 if ((*dest
) == NULL
) {
1808 DEBUG(0,("Out of memory in string_set_upper\n"));
1818 * Add a new service to the services array initialising it with the given
1822 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1823 const struct loadparm_service
*pservice
,
1827 struct loadparm_service tservice
;
1828 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1829 struct parmlist_entry
*data
, *pdata
;
1831 if (pservice
== NULL
) {
1832 pservice
= lp_ctx
->sDefault
;
1835 tservice
= *pservice
;
1837 /* it might already exist */
1839 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1841 if (service
!= NULL
) {
1842 /* Clean all parametric options for service */
1843 /* They will be added during parsing again */
1844 data
= service
->param_opt
;
1850 service
->param_opt
= NULL
;
1855 /* find an invalid one */
1856 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1857 if (lp_ctx
->services
[i
] == NULL
)
1860 /* if not, then create one */
1861 if (i
== lp_ctx
->iNumServices
) {
1862 struct loadparm_service
**tsp
;
1864 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1867 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1870 lp_ctx
->services
= tsp
;
1871 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1874 lp_ctx
->iNumServices
++;
1877 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1878 if (lp_ctx
->services
[i
] == NULL
) {
1879 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1882 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1884 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1885 return lp_ctx
->services
[i
];
1889 * Add a new home service, with the specified home directory, defaults coming
1890 * from service ifrom.
1893 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
1894 const char *pszHomename
,
1895 struct loadparm_service
*default_service
,
1896 const char *user
, const char *pszHomedir
)
1898 struct loadparm_service
*service
;
1900 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
1902 if (service
== NULL
)
1905 if (!(*(default_service
->szPath
))
1906 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1907 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1909 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1912 if (!(*(service
->comment
))) {
1913 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1915 service
->bAvailable
= default_service
->bAvailable
;
1916 service
->bBrowseable
= default_service
->bBrowseable
;
1918 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1919 pszHomename
, user
, service
->szPath
));
1925 * Add a new printer service, with defaults coming from service iFrom.
1928 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
1929 const char *pszPrintername
,
1930 struct loadparm_service
*default_service
)
1932 const char *comment
= "From Printcap";
1933 struct loadparm_service
*service
;
1934 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
1936 if (service
== NULL
)
1939 /* note that we do NOT default the availability flag to True - */
1940 /* we take it from the default service passed. This allows all */
1941 /* dynamic printers to be disabled by disabling the [printers] */
1942 /* entry (if/when the 'available' keyword is implemented!). */
1944 /* the printer name is set to the service name. */
1945 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
1946 lpcfg_string_set(service
, &service
->comment
, comment
);
1947 service
->bBrowseable
= default_service
->bBrowseable
;
1948 /* Printers cannot be read_only. */
1949 service
->bRead_only
= false;
1950 /* Printer services must be printable. */
1951 service
->bPrint_ok
= true;
1953 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
1959 * Map a parameter's string representation to something we can use.
1960 * Returns False if the parameter string is not recognised, else TRUE.
1963 static int map_parameter(const char *pszParmName
)
1967 if (*pszParmName
== '-')
1970 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
1971 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
1974 /* Warn only if it isn't parametric option */
1975 if (strchr(pszParmName
, ':') == NULL
)
1976 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
1977 /* We do return 'fail' for parametric options as well because they are
1978 stored in different storage
1985 return the parameter structure for a parameter
1987 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
1991 if (lp_ctx
->s3_fns
) {
1992 return lp_ctx
->s3_fns
->get_parm_struct(name
);
1995 parmnum
= map_parameter(name
);
1996 if (parmnum
== -1) return NULL
;
1997 return &parm_table
[parmnum
];
2001 return the parameter pointer for a parameter
2003 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2004 struct loadparm_service
*service
, struct parm_struct
*parm
)
2006 if (lp_ctx
->s3_fns
) {
2007 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2010 if (service
== NULL
) {
2011 if (parm
->p_class
== P_LOCAL
)
2012 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2013 else if (parm
->p_class
== P_GLOBAL
)
2014 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2017 return ((char *)service
) + parm
->offset
;
2022 return the parameter pointer for a parameter
2024 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
2028 if (lp_ctx
->s3_fns
) {
2029 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
2031 return parm
->flags
& FLAG_CMDLINE
;
2036 parmnum
= map_parameter(name
);
2037 if (parmnum
== -1) return false;
2039 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
2043 * Find a service by name. Otherwise works like get_service.
2046 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2047 const char *pszServiceName
)
2051 if (lp_ctx
->s3_fns
) {
2052 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2055 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2056 if (lp_ctx
->services
[iService
] != NULL
&&
2057 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2058 return lp_ctx
->services
[iService
];
2065 * Copy a service structure to another.
2066 * If pcopymapDest is NULL then copy all fields
2069 static void copy_service(struct loadparm_service
*pserviceDest
,
2070 struct loadparm_service
*pserviceSource
,
2071 struct bitmap
*pcopymapDest
)
2074 bool bcopyall
= (pcopymapDest
== NULL
);
2075 struct parmlist_entry
*data
, *pdata
, *paramo
;
2078 for (i
= 0; parm_table
[i
].label
; i
++)
2079 if (parm_table
[i
].p_class
== P_LOCAL
&&
2080 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2082 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2084 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2086 switch (parm_table
[i
].type
) {
2088 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2094 *(int *)dest_ptr
= *(int *)src_ptr
;
2098 lpcfg_string_set(pserviceDest
,
2104 lpcfg_string_set_upper(pserviceDest
,
2109 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2110 *(const char ***)src_ptr
);
2118 init_copymap(pserviceDest
);
2119 if (pserviceSource
->copymap
)
2120 bitmap_copy(pserviceDest
->copymap
,
2121 pserviceSource
->copymap
);
2124 data
= pserviceSource
->param_opt
;
2127 pdata
= pserviceDest
->param_opt
;
2128 /* Traverse destination */
2130 /* If we already have same option, override it */
2131 if (strcmp(pdata
->key
, data
->key
) == 0) {
2132 talloc_free(pdata
->value
);
2133 pdata
->value
= talloc_reference(pdata
,
2138 pdata
= pdata
->next
;
2141 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2144 paramo
->key
= talloc_reference(paramo
, data
->key
);
2145 paramo
->value
= talloc_reference(paramo
, data
->value
);
2146 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2153 * Check a service for consistency. Return False if the service is in any way
2154 * incomplete or faulty, else True.
2156 static bool lpcfg_service_ok(struct loadparm_service
*service
)
2161 if (service
->szService
[0] == '\0') {
2162 DEBUG(0, ("The following message indicates an internal error:\n"));
2163 DEBUG(0, ("No service name in service entry.\n"));
2167 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2168 /* I can't see why you'd want a non-printable printer service... */
2169 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2170 if (!service
->bPrint_ok
) {
2171 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2172 service
->szService
));
2173 service
->bPrint_ok
= true;
2175 /* [printers] service must also be non-browsable. */
2176 if (service
->bBrowseable
)
2177 service
->bBrowseable
= false;
2180 /* If a service is flagged unavailable, log the fact at level 0. */
2181 if (!service
->bAvailable
)
2182 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2183 service
->szService
));
2189 /*******************************************************************
2190 Keep a linked list of all config files so we know when one has changed
2191 it's date and needs to be reloaded.
2192 ********************************************************************/
2194 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2195 const char *fname
, const char *subfname
)
2197 struct file_lists
*f
= lp_ctx
->file_lists
;
2200 if (f
->name
&& !strcmp(f
->name
, fname
))
2206 f
= talloc(lp_ctx
, struct file_lists
);
2209 f
->next
= lp_ctx
->file_lists
;
2210 f
->name
= talloc_strdup(f
, fname
);
2215 f
->subfname
= talloc_strdup(f
, subfname
);
2220 lp_ctx
->file_lists
= f
;
2221 f
->modtime
= file_modtime(subfname
);
2223 time_t t
= file_modtime(subfname
);
2229 /*******************************************************************
2230 Check if a config file has changed date.
2231 ********************************************************************/
2232 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2234 struct file_lists
*f
;
2235 DEBUG(6, ("lp_file_list_changed()\n"));
2237 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2241 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2243 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2244 f
->name
, n2
, ctime(&f
->modtime
)));
2246 mod_time
= file_modtime(n2
);
2248 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2249 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2251 f
->modtime
= mod_time
;
2252 talloc_free(f
->subfname
);
2253 f
->subfname
= talloc_strdup(f
, n2
);
2260 /***************************************************************************
2261 Handle the "realm" parameter
2262 ***************************************************************************/
2264 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2265 const char *pszParmValue
, char **ptr
)
2267 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2269 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2270 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2272 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2273 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2278 /***************************************************************************
2279 Handle the include operation.
2280 ***************************************************************************/
2282 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2283 const char *pszParmValue
, char **ptr
)
2285 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2287 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2289 lpcfg_string_set(lp_ctx
, ptr
, fname
);
2291 if (file_exist(fname
))
2292 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2294 DEBUG(2, ("Can't find include file %s\n", fname
));
2299 /***************************************************************************
2300 Handle the interpretation of the copy parameter.
2301 ***************************************************************************/
2303 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2304 const char *pszParmValue
, char **ptr
)
2307 struct loadparm_service
*serviceTemp
;
2309 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2313 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2315 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2316 if (serviceTemp
== lp_ctx
->currentService
) {
2317 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2319 copy_service(lp_ctx
->currentService
,
2321 lp_ctx
->currentService
->copymap
);
2325 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2333 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2334 const char *pszParmValue
, char **ptr
)
2337 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2338 if (lp_ctx
->global
) {
2339 return debug_parse_levels(pszParmValue
);
2344 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2345 const char *pszParmValue
, char **ptr
)
2347 debug_set_logfile(pszParmValue
);
2348 if (lp_ctx
->global
) {
2349 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2354 /***************************************************************************
2355 Initialise a copymap.
2356 ***************************************************************************/
2358 static void init_copymap(struct loadparm_service
*pservice
)
2362 TALLOC_FREE(pservice
->copymap
);
2364 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2365 if (!pservice
->copymap
)
2367 ("Couldn't allocate copymap!! (size %d)\n",
2368 (int)NUMPARAMETERS
));
2370 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2371 bitmap_set(pservice
->copymap
, i
);
2375 * Process a parametric option
2377 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2378 struct loadparm_service
*service
,
2379 const char *pszParmName
,
2380 const char *pszParmValue
, int flags
)
2382 struct parmlist_entry
*paramo
, *data
;
2384 TALLOC_CTX
*mem_ctx
;
2386 while (isspace((unsigned char)*pszParmName
)) {
2390 name
= strlower_talloc(lp_ctx
, pszParmName
);
2391 if (!name
) return false;
2393 if (service
== NULL
) {
2394 data
= lp_ctx
->globals
->param_opt
;
2395 mem_ctx
= lp_ctx
->globals
;
2397 data
= service
->param_opt
;
2401 /* Traverse destination */
2402 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2403 /* If we already have the option set, override it unless
2404 it was a command line option and the new one isn't */
2405 if (strcmp(paramo
->key
, name
) == 0) {
2406 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2407 !(flags
& FLAG_CMDLINE
)) {
2412 talloc_free(paramo
->value
);
2413 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2414 paramo
->priority
= flags
;
2420 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2423 paramo
->key
= talloc_strdup(paramo
, name
);
2424 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2425 paramo
->priority
= flags
;
2426 if (service
== NULL
) {
2427 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2429 DLIST_ADD(service
->param_opt
, paramo
);
2437 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2438 const char *pszParmName
, const char *pszParmValue
,
2439 struct loadparm_context
*lp_ctx
, bool on_globals
)
2442 /* if it is a special case then go ahead */
2443 if (parm_table
[parmnum
].special
) {
2445 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2450 goto mark_non_default
;
2453 /* now switch on the type of variable it is */
2454 switch (parm_table
[parmnum
].type
)
2458 if (!set_boolean(pszParmValue
, &b
)) {
2459 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2462 *(bool *)parm_ptr
= b
;
2468 if (!set_boolean(pszParmValue
, &b
)) {
2469 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2472 *(bool *)parm_ptr
= !b
;
2477 *(int *)parm_ptr
= atoi(pszParmValue
);
2481 *(char *)parm_ptr
= *pszParmValue
;
2485 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2491 if (conv_str_size_error(pszParmValue
, &val
)) {
2492 if (val
<= INT_MAX
) {
2493 *(int *)parm_ptr
= (int)val
;
2498 DEBUG(0,("lp_do_parameter(%s): value is not "
2499 "a valid size specifier!\n", pszParmValue
));
2504 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2505 pszParmValue
, NULL
);
2509 char **new_list
= str_list_make(mem_ctx
,
2510 pszParmValue
, NULL
);
2511 for (i
=0; new_list
[i
]; i
++) {
2512 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
2513 if (!str_list_check(*(const char ***)parm_ptr
,
2515 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2518 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2519 str_list_remove(*(const char ***)parm_ptr
,
2523 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2524 pszParmName
, pszParmValue
));
2527 *(const char ***)parm_ptr
= (const char **) new_list
;
2534 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2538 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2542 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2545 parm_table
[parmnum
].enum_list
[i
].name
)) {
2547 parm_table
[parmnum
].
2552 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2553 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2554 pszParmValue
, pszParmName
));
2561 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2562 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2563 /* we have to also unset FLAG_DEFAULT on aliases */
2564 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2565 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2567 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2568 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2575 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2576 const char *pszParmName
, const char *pszParmValue
)
2578 int parmnum
= map_parameter(pszParmName
);
2582 if (strchr(pszParmName
, ':')) {
2583 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2585 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2589 /* if the flag has been set on the command line, then don't allow override,
2590 but don't report an error */
2591 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2595 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2597 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2598 pszParmName
, pszParmValue
, lp_ctx
, true);
2601 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2602 struct loadparm_service
*service
,
2603 const char *pszParmName
, const char *pszParmValue
)
2607 int parmnum
= map_parameter(pszParmName
);
2610 if (strchr(pszParmName
, ':')) {
2611 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2613 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2617 /* if the flag has been set on the command line, then don't allow override,
2618 but don't report an error */
2619 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2623 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2625 ("Global parameter %s found in service section!\n",
2629 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2631 if (!service
->copymap
)
2632 init_copymap(service
);
2634 /* this handles the aliases - set the copymap for other
2635 * entries with the same data pointer */
2636 for (i
= 0; parm_table
[i
].label
; i
++)
2637 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2638 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2639 bitmap_clear(service
->copymap
, i
);
2641 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2642 pszParmValue
, lp_ctx
, false);
2646 * Process a parameter.
2649 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2652 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2654 if (lp_ctx
->bInGlobalSection
)
2655 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2658 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2659 pszParmName
, pszParmValue
);
2663 variable argument do parameter
2665 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2666 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2667 const char *pszParmName
, const char *fmt
, ...)
2674 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2676 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2683 set a parameter from the commandline - this is called from command line parameter
2684 parsing code. It sets the parameter then marks the parameter as unable to be modified
2685 by smb.conf processing
2687 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2688 const char *pszParmValue
)
2693 if (lp_ctx
->s3_fns
) {
2694 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2697 parmnum
= map_parameter(pszParmName
);
2699 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2702 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2703 /* set a parametric option */
2704 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2705 pszParmValue
, FLAG_CMDLINE
);
2709 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2713 /* reset the CMDLINE flag in case this has been called before */
2714 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2716 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2720 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2722 /* we have to also set FLAG_CMDLINE on aliases */
2723 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2724 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2726 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2727 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2734 set a option from the commandline in 'a=b' format. Use to support --option
2736 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2741 s
= talloc_strdup(NULL
, option
);
2754 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2760 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2763 * Print a parameter of the specified type.
2766 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2768 /* For the seperation of lists values that we print below */
2769 const char *list_sep
= ", ";
2774 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2775 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2777 p
->enum_list
[i
].name
);
2784 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2788 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2793 fprintf(f
, "%d", *(int *)ptr
);
2797 fprintf(f
, "%c", *(char *)ptr
);
2801 int val
= *(int *)ptr
;
2805 fprintf(f
, "0%o", val
);
2814 if ((char ***)ptr
&& *(char ***)ptr
) {
2815 char **list
= *(char ***)ptr
;
2816 for (; *list
; list
++) {
2817 /* surround strings with whitespace in double quotes */
2818 if (*(list
+1) == NULL
) {
2819 /* last item, no extra separator */
2822 if ( strchr_m( *list
, ' ' ) ) {
2823 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2825 fprintf(f
, "%s%s", *list
, list_sep
);
2833 if (*(char **)ptr
) {
2834 fprintf(f
, "%s", *(char **)ptr
);
2843 * Check if two parameters are equal.
2846 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2851 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2857 return (*((int *)ptr1
) == *((int *)ptr2
));
2860 return (*((char *)ptr1
) == *((char *)ptr2
));
2864 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
2869 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2874 return (p1
== p2
|| strequal(p1
, p2
));
2883 * Process a new section (service).
2885 * At this stage all sections are services.
2886 * Later we'll have special sections that permit server parameters to be set.
2887 * Returns True on success, False on failure.
2890 static bool do_section(const char *pszSectionName
, void *userdata
)
2892 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2894 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2895 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2898 /* if we've just struck a global section, note the fact. */
2899 lp_ctx
->bInGlobalSection
= isglobal
;
2901 /* check for multiple global sections */
2902 if (lp_ctx
->bInGlobalSection
) {
2903 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2907 /* if we have a current service, tidy it up before moving on */
2910 if (lp_ctx
->currentService
!= NULL
)
2911 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2913 /* if all is still well, move to the next record in the services array */
2915 /* We put this here to avoid an odd message order if messages are */
2916 /* issued by the post-processing of a previous section. */
2917 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2919 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2922 DEBUG(0, ("Failed to add a new service\n"));
2932 * Determine if a particular base parameter is currently set to the default value.
2935 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2937 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2938 if (!defaults_saved
)
2940 switch (parm_table
[i
].type
) {
2943 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2944 (const char **)def_ptr
);
2947 return strequal(parm_table
[i
].def
.svalue
,
2951 return parm_table
[i
].def
.bvalue
==
2958 return parm_table
[i
].def
.ivalue
==
2965 *Display the contents of the global structure.
2968 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2972 struct parmlist_entry
*data
;
2974 fprintf(f
, "# Global parameters\n[global]\n");
2976 for (i
= 0; parm_table
[i
].label
; i
++)
2977 if (parm_table
[i
].p_class
== P_GLOBAL
&&
2978 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2979 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
2981 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2982 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2985 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2986 for (data
= lp_ctx
->globals
->param_opt
; data
;
2987 data
= data
->next
) {
2988 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2991 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2998 * Display the contents of a single services record.
3001 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3002 unsigned int *flags
)
3005 struct parmlist_entry
*data
;
3007 if (pService
!= sDefault
)
3008 fprintf(f
, "\n[%s]\n", pService
->szService
);
3010 for (i
= 0; parm_table
[i
].label
; i
++) {
3011 if (parm_table
[i
].p_class
== P_LOCAL
&&
3012 (*parm_table
[i
].label
!= '-') &&
3013 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3015 if (pService
== sDefault
) {
3016 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3019 if (defaults_saved
) {
3020 if (is_default(sDefault
, i
)) {
3025 if (equal_parameter(parm_table
[i
].type
,
3026 ((char *)pService
) +
3027 parm_table
[i
].offset
,
3028 ((char *)sDefault
) +
3029 parm_table
[i
].offset
))
3033 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3034 print_parameter(&parm_table
[i
],
3035 ((char *)pService
) + parm_table
[i
].offset
, f
);
3039 if (pService
->param_opt
!= NULL
) {
3040 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3041 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3046 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3047 struct loadparm_service
*service
,
3048 const char *parm_name
, FILE * f
)
3050 struct parm_struct
*parm
;
3053 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3058 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3060 print_parameter(parm
, ptr
, f
);
3066 * Return info about the next parameter in a service.
3067 * snum==-1 gives the globals.
3068 * Return NULL when out of parameters.
3072 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3076 /* do the globals */
3077 for (; parm_table
[*i
].label
; (*i
)++) {
3078 if ((*parm_table
[*i
].label
== '-'))
3082 && (parm_table
[*i
].offset
==
3083 parm_table
[(*i
) - 1].offset
)
3084 && (parm_table
[*i
].p_class
==
3085 parm_table
[(*i
) - 1].p_class
))
3088 return &parm_table
[(*i
)++];
3091 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3093 for (; parm_table
[*i
].label
; (*i
)++) {
3094 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3095 (*parm_table
[*i
].label
!= '-') &&
3097 (parm_table
[*i
].offset
!=
3098 parm_table
[(*i
) - 1].offset
)))
3100 if (allparameters
||
3101 !equal_parameter(parm_table
[*i
].type
,
3102 ((char *)pService
) +
3103 parm_table
[*i
].offset
,
3104 ((char *)lp_ctx
->sDefault
) +
3105 parm_table
[*i
].offset
))
3107 return &parm_table
[(*i
)++];
3118 * Auto-load some home services.
3120 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3128 * Unload unused services.
3131 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3132 struct smbsrv_connection
*smb
,
3133 bool (*snumused
) (struct smbsrv_connection
*, int))
3136 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3137 if (lp_ctx
->services
[i
] == NULL
)
3140 if (!snumused
|| !snumused(smb
, i
)) {
3141 talloc_free(lp_ctx
->services
[i
]);
3142 lp_ctx
->services
[i
] = NULL
;
3148 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3150 struct parmlist_entry
*data
;
3152 if (lp_ctx
->refuse_free
) {
3153 /* someone is trying to free the
3154 global_loadparm_context.
3155 We can't allow that. */
3159 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3160 struct parmlist_entry
*next
;
3161 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3163 if (data
->priority
& FLAG_CMDLINE
) continue;
3164 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3173 * Initialise the global parameter structure.
3175 * Note that most callers should use loadparm_init_global() instead
3177 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3181 struct loadparm_context
*lp_ctx
;
3182 struct parmlist_entry
*parm
;
3185 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3189 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3190 lp_ctx
->bInGlobalSection
= true;
3191 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3192 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3194 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3195 lp_ctx
->sDefault
->bAvailable
= true;
3196 lp_ctx
->sDefault
->bBrowseable
= true;
3197 lp_ctx
->sDefault
->bRead_only
= true;
3198 lp_ctx
->sDefault
->bMap_archive
= true;
3199 lp_ctx
->sDefault
->iStrictLocking
= true;
3200 lp_ctx
->sDefault
->bOpLocks
= true;
3201 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3202 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3203 lp_ctx
->sDefault
->iDir_mask
= 0755;
3204 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3206 DEBUG(3, ("Initialising global parameters\n"));
3208 for (i
= 0; parm_table
[i
].label
; i
++) {
3209 if ((parm_table
[i
].type
== P_STRING
||
3210 parm_table
[i
].type
== P_USTRING
) &&
3211 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3213 if (parm_table
[i
].p_class
== P_LOCAL
) {
3214 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3216 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3218 *r
= talloc_strdup(lp_ctx
, "");
3222 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3223 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3224 talloc_free(logfile
);
3226 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3228 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3230 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
3231 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
3232 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
3234 /* options that can be set on the command line must be initialised via
3235 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3237 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3239 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3240 myname
= get_myname(lp_ctx
);
3241 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3242 talloc_free(myname
);
3243 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3245 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3247 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3248 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3250 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");
3251 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3252 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3253 /* the winbind method for domain controllers is for both RODC
3254 auth forwarding and for trusted domains */
3255 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3256 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3258 /* This hive should be dynamically generated by Samba using
3259 data from the sam, but for the moment leave it in a tdb to
3260 keep regedt32 from popping up an annoying dialog. */
3261 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3263 /* using UTF8 by default allows us to support all chars */
3264 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3266 /* Use codepage 850 as a default for the dos character set */
3267 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3270 * Allow the default PASSWD_CHAT to be overridden in local.h.
3272 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3274 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3275 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3276 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3277 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3278 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3280 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3281 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3282 "Samba %s", SAMBA_VERSION_STRING
);
3284 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3286 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3287 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3288 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
3290 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3291 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3292 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3293 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3294 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3295 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3296 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
3297 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3298 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3299 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3300 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3301 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3302 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3304 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3305 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3306 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3307 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3308 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3309 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3310 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3311 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3313 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3315 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3316 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3318 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3319 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3321 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3322 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3323 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3324 #if _SAMBA_BUILD_ >= 4
3325 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3326 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3327 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3328 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3329 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
3330 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
3332 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3333 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3334 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3336 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
3337 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
3339 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3341 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
3343 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3344 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3345 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3346 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3347 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3348 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3349 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3351 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3353 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3354 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3356 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3357 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3358 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3359 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3360 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3362 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3363 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3365 for (i
= 0; parm_table
[i
].label
; i
++) {
3366 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3367 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3371 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3372 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3373 parm
->priority
|= FLAG_DEFAULT
;
3381 * Initialise the global parameter structure.
3383 struct loadparm_context
*loadparm_init_global(bool load_default
)
3385 if (global_loadparm_context
== NULL
) {
3386 global_loadparm_context
= loadparm_init(NULL
);
3388 if (global_loadparm_context
== NULL
) {
3391 global_loadparm_context
->global
= true;
3392 if (load_default
&& !global_loadparm_context
->loaded
) {
3393 lpcfg_load_default(global_loadparm_context
);
3395 global_loadparm_context
->refuse_free
= true;
3396 return global_loadparm_context
;
3400 * Initialise the global parameter structure.
3402 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3403 const struct loadparm_s3_context
*s3_fns
)
3405 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3406 if (!loadparm_context
) {
3409 loadparm_context
->s3_fns
= s3_fns
;
3410 return loadparm_context
;
3413 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3415 return lp_ctx
->szConfigFile
;
3418 const char *lp_default_path(void)
3420 if (getenv("SMB_CONF_PATH"))
3421 return getenv("SMB_CONF_PATH");
3423 return dyn_CONFIGFILE
;
3427 * Update the internal state of a loadparm context after settings
3430 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3432 struct debug_settings settings
;
3433 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3435 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3436 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3439 if (!lp_ctx
->global
) {
3443 panic_action
= lp_ctx
->globals
->panic_action
;
3445 reload_charcnv(lp_ctx
);
3447 ZERO_STRUCT(settings
);
3448 /* Add any more debug-related smb.conf parameters created in
3450 settings
.timestamp_logs
= true;
3451 debug_set_settings(&settings
);
3453 /* FIXME: This is a bit of a hack, but we can't use a global, since
3454 * not everything that uses lp also uses the socket library */
3455 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3456 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3458 unsetenv("SOCKET_TESTNONBLOCK");
3464 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3468 path
= lp_default_path();
3470 if (!file_exist(path
)) {
3471 /* We allow the default smb.conf file to not exist,
3472 * basically the equivalent of an empty file. */
3473 return lpcfg_update(lp_ctx
);
3476 return lpcfg_load(lp_ctx
, path
);
3480 * Load the services array from the services file.
3482 * Return True on success, False on failure.
3484 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3489 filename
= talloc_strdup(lp_ctx
, filename
);
3491 lp_ctx
->szConfigFile
= filename
;
3493 if (lp_ctx
->s3_fns
) {
3494 return lp_ctx
->s3_fns
->load(filename
);
3497 lp_ctx
->bInGlobalSection
= true;
3498 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3499 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3501 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3503 /* We get sections first, so have to start 'behind' to make up */
3504 lp_ctx
->currentService
= NULL
;
3505 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3507 /* finish up the last section */
3508 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3510 if (lp_ctx
->currentService
!= NULL
)
3511 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3513 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3515 /* we do this unconditionally, so that it happens even
3516 for a missing smb.conf */
3517 reload_charcnv(lp_ctx
);
3519 if (bRetval
== true) {
3520 /* set this up so that any child python tasks will
3521 find the right smb.conf */
3522 setenv("SMB_CONF_PATH", filename
, 1);
3524 /* set the context used by the lp_*() function
3526 global_loadparm_context
= lp_ctx
;
3527 lp_ctx
->loaded
= true;
3534 * Return the max number of services.
3537 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3539 if (lp_ctx
->s3_fns
) {
3540 return lp_ctx
->s3_fns
->get_numservices();
3543 return lp_ctx
->iNumServices
;
3547 * Display the contents of the services array in human-readable form.
3550 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3555 if (lp_ctx
->s3_fns
) {
3556 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3560 defaults_saved
= !show_defaults
;
3562 dump_globals(lp_ctx
, f
, show_defaults
);
3564 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3566 for (iService
= 0; iService
< maxtoprint
; iService
++)
3567 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3571 * Display the contents of one service in human-readable form.
3573 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3575 if (service
!= NULL
) {
3576 if (service
->szService
[0] == '\0')
3578 dump_a_service(service
, sDefault
, f
, NULL
);
3582 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3585 if (lp_ctx
->s3_fns
) {
3586 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3589 return lp_ctx
->services
[snum
];
3592 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3593 const char *service_name
)
3598 if (lp_ctx
->s3_fns
) {
3599 return lp_ctx
->s3_fns
->get_service(service_name
);
3602 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3603 if (lp_ctx
->services
[iService
] &&
3604 lp_ctx
->services
[iService
]->szService
) {
3606 * The substitution here is used to support %U is
3609 serviceName
= standard_sub_basic(
3610 lp_ctx
->services
[iService
],
3611 lp_ctx
->services
[iService
]->szService
);
3612 if (strequal(serviceName
, service_name
)) {
3613 talloc_free(serviceName
);
3614 return lp_ctx
->services
[iService
];
3616 talloc_free(serviceName
);
3620 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3624 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3626 return lp_string((const char *)service
->szService
);
3630 * A useful volume label function.
3632 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3635 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3636 service
->volume
: sDefault
->volume
));
3638 return lpcfg_servicename(service
);
3643 * If we are PDC then prefer us as DMB
3645 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3648 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3649 service
->szPrintername
: sDefault
->szPrintername
));
3650 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3651 ret
= lpcfg_servicename(service
);
3658 * Return the max print jobs per queue.
3660 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3662 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3663 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3664 maxjobs
= PRINT_MAX_JOBID
- 1;
3669 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3671 if (lp_ctx
== NULL
) {
3672 return get_iconv_handle();
3674 return lp_ctx
->iconv_handle
;
3677 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3679 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3680 if (!lp_ctx
->global
) {
3684 if (old_ic
== NULL
) {
3685 old_ic
= global_iconv_handle
;
3687 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3688 global_iconv_handle
= lp_ctx
->iconv_handle
;
3691 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3693 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3696 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3698 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3701 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3703 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3706 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3708 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3711 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3713 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3716 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3718 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
3719 if (settings
== NULL
)
3721 SMB_ASSERT(lp_ctx
!= NULL
);
3722 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3723 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3727 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3729 if (lp_ctx
->s3_fns
) {
3730 return lp_ctx
->s3_fns
->server_role();
3733 return lp_find_server_role(lp_ctx
->globals
->server_role
,
3734 lp_ctx
->globals
->security
,
3735 lp_ctx
->globals
->domain_logons
,
3736 (lp_ctx
->globals
->domain_master
== true) ||
3737 (lp_ctx
->globals
->domain_master
== Auto
));
3740 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3742 if (lp_ctx
->s3_fns
) {
3743 return lp_ctx
->s3_fns
->security();
3746 return lp_find_security(lp_ctx
->globals
->server_role
,
3747 lp_ctx
->globals
->security
);