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; \
86 #include "param_global.h"
88 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
91 /* prototypes for the special type handlers */
92 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
93 const char *pszParmValue
, char **ptr
);
94 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
95 const char *pszParmValue
, char **ptr
);
96 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
97 const char *pszParmValue
, char **ptr
);
98 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
99 const char *pszParmValue
, char **ptr
);
100 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
101 const char *pszParmValue
, char **ptr
);
103 static const struct enum_list enum_protocol
[] = {
104 {PROTOCOL_SMB2_02
, "SMB2"},
105 {PROTOCOL_SMB2_02
, "SMB2_02"},
106 {PROTOCOL_NT1
, "NT1"},
107 {PROTOCOL_LANMAN2
, "LANMAN2"},
108 {PROTOCOL_LANMAN1
, "LANMAN1"},
109 {PROTOCOL_CORE
, "CORE"},
110 {PROTOCOL_COREPLUS
, "COREPLUS"},
111 {PROTOCOL_COREPLUS
, "CORE+"},
115 static const struct enum_list enum_security
[] = {
116 {SEC_SHARE
, "SHARE"},
122 static const struct enum_list enum_bool_auto
[] = {
133 /* Client-side offline caching policy types */
135 static const struct enum_list enum_csc_policy
[] = {
136 {CSC_POLICY_MANUAL
, "manual"},
137 {CSC_POLICY_DOCUMENTS
, "documents"},
138 {CSC_POLICY_PROGRAMS
, "programs"},
139 {CSC_POLICY_DISABLE
, "disable"},
143 /* SMB signing types. */
144 static const struct enum_list enum_smb_signing_vals
[] = {
145 {SMB_SIGNING_DEFAULT
, "default"},
146 {SMB_SIGNING_OFF
, "No"},
147 {SMB_SIGNING_OFF
, "False"},
148 {SMB_SIGNING_OFF
, "0"},
149 {SMB_SIGNING_OFF
, "Off"},
150 {SMB_SIGNING_OFF
, "disabled"},
151 {SMB_SIGNING_SUPPORTED
, "Yes"},
152 {SMB_SIGNING_SUPPORTED
, "True"},
153 {SMB_SIGNING_SUPPORTED
, "1"},
154 {SMB_SIGNING_SUPPORTED
, "On"},
155 {SMB_SIGNING_SUPPORTED
, "enabled"},
156 {SMB_SIGNING_REQUIRED
, "required"},
157 {SMB_SIGNING_REQUIRED
, "mandatory"},
158 {SMB_SIGNING_REQUIRED
, "force"},
159 {SMB_SIGNING_REQUIRED
, "forced"},
160 {SMB_SIGNING_REQUIRED
, "enforced"},
161 {SMB_SIGNING_AUTO
, "auto"},
165 static const struct enum_list enum_server_role
[] = {
166 {ROLE_STANDALONE
, "standalone"},
167 {ROLE_DOMAIN_MEMBER
, "member server"},
168 {ROLE_DOMAIN_MEMBER
, "member"},
169 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
170 {ROLE_DOMAIN_CONTROLLER
, "dc"},
174 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
175 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
177 static struct parm_struct parm_table
[] = {
179 .label
= "server role",
182 .offset
= GLOBAL_VAR(server_role
),
184 .enum_list
= enum_server_role
187 .label
= "dos charset",
190 .offset
= GLOBAL_VAR(dos_charset
),
195 .label
= "unix charset",
198 .offset
= GLOBAL_VAR(unix_charset
),
203 .label
= "ncalrpc dir",
206 .offset
= GLOBAL_VAR(ncalrpc_dir
),
214 .offset
= LOCAL_VAR(comment
),
222 .offset
= LOCAL_VAR(szPath
),
227 .label
= "directory",
230 .offset
= LOCAL_VAR(szPath
),
235 .label
= "workgroup",
238 .offset
= GLOBAL_VAR(szWorkgroup
),
246 .offset
= GLOBAL_VAR(szRealm
),
247 .special
= handle_realm
,
251 .label
= "netbios name",
254 .offset
= GLOBAL_VAR(szNetbiosName
),
259 .label
= "netbios aliases",
262 .offset
= GLOBAL_VAR(szNetbiosAliases
),
267 .label
= "netbios scope",
270 .offset
= GLOBAL_VAR(szNetbiosScope
),
275 .label
= "server string",
278 .offset
= GLOBAL_VAR(szServerString
),
283 .label
= "interfaces",
286 .offset
= GLOBAL_VAR(szInterfaces
),
291 .label
= "bind interfaces only",
294 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
299 .label
= "ntvfs handler",
302 .offset
= LOCAL_VAR(ntvfs_handler
),
307 .label
= "ntptr providor",
310 .offset
= GLOBAL_VAR(ntptr_providor
),
315 .label
= "passdb backend",
318 .offset
= GLOBAL_VAR(passdb_backend
),
323 .label
= "dcerpc endpoint servers",
326 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
331 .label
= "server services",
334 .offset
= GLOBAL_VAR(server_services
),
343 .offset
= GLOBAL_VAR(security
),
345 .enum_list
= enum_security
348 .label
= "encrypt passwords",
351 .offset
= GLOBAL_VAR(bEncryptPasswords
),
356 .label
= "null passwords",
359 .offset
= GLOBAL_VAR(bNullPasswords
),
364 .label
= "obey pam restrictions",
367 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
372 .label
= "password server",
375 .offset
= GLOBAL_VAR(szPasswordServers
),
380 .label
= "private dir",
383 .offset
= GLOBAL_VAR(szPrivateDir
),
388 .label
= "passwd chat",
391 .offset
= GLOBAL_VAR(szPasswdChat
),
396 .label
= "password level",
399 .offset
= GLOBAL_VAR(pwordlevel
),
404 .label
= "lanman auth",
407 .offset
= GLOBAL_VAR(bLanmanAuth
),
412 .label
= "ntlm auth",
415 .offset
= GLOBAL_VAR(bNTLMAuth
),
420 .label
= "client NTLMv2 auth",
423 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
428 .label
= "client lanman auth",
431 .offset
= GLOBAL_VAR(bClientLanManAuth
),
436 .label
= "client plaintext auth",
439 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
444 .label
= "client use spnego principal",
447 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
453 .label
= "read only",
456 .offset
= LOCAL_VAR(bRead_only
),
462 .label
= "create mask",
465 .offset
= LOCAL_VAR(iCreate_mask
),
470 .label
= "force create mode",
473 .offset
= LOCAL_VAR(iCreate_force_mode
),
478 .label
= "directory mask",
481 .offset
= LOCAL_VAR(iDir_mask
),
486 .label
= "force directory mode",
489 .offset
= LOCAL_VAR(iDir_force_mode
),
495 .label
= "hosts allow",
498 .offset
= LOCAL_VAR(szHostsallow
),
503 .label
= "hosts deny",
506 .offset
= LOCAL_VAR(szHostsdeny
),
512 .label
= "log level",
515 .offset
= GLOBAL_VAR(loglevel
),
516 .special
= handle_debuglevel
,
520 .label
= "debuglevel",
523 .offset
= GLOBAL_VAR(loglevel
),
524 .special
= handle_debuglevel
,
531 .offset
= GLOBAL_VAR(logfile
),
532 .special
= handle_logfile
,
537 .label
= "smb ports",
540 .offset
= GLOBAL_VAR(smb_ports
),
548 .offset
= GLOBAL_VAR(nbt_port
),
553 .label
= "dgram port",
556 .offset
= GLOBAL_VAR(dgram_port
),
561 .label
= "cldap port",
564 .offset
= GLOBAL_VAR(cldap_port
),
569 .label
= "krb5 port",
572 .offset
= GLOBAL_VAR(krb5_port
),
577 .label
= "kpasswd port",
580 .offset
= GLOBAL_VAR(kpasswd_port
),
588 .offset
= GLOBAL_VAR(web_port
),
593 .label
= "tls enabled",
596 .offset
= GLOBAL_VAR(tls_enabled
),
601 .label
= "tls keyfile",
604 .offset
= GLOBAL_VAR(tls_keyfile
),
609 .label
= "tls certfile",
612 .offset
= GLOBAL_VAR(tls_certfile
),
617 .label
= "tls cafile",
620 .offset
= GLOBAL_VAR(tls_cafile
),
625 .label
= "tls crlfile",
628 .offset
= GLOBAL_VAR(tls_crlfile
),
633 .label
= "tls dh params file",
636 .offset
= GLOBAL_VAR(tls_dhpfile
),
641 .label
= "large readwrite",
644 .offset
= GLOBAL_VAR(bLargeReadwrite
),
649 .label
= "server max protocol",
652 .offset
= GLOBAL_VAR(srv_maxprotocol
),
654 .enum_list
= enum_protocol
657 .label
= "server min protocol",
660 .offset
= GLOBAL_VAR(srv_minprotocol
),
662 .enum_list
= enum_protocol
665 .label
= "client max protocol",
668 .offset
= GLOBAL_VAR(cli_maxprotocol
),
670 .enum_list
= enum_protocol
673 .label
= "client min protocol",
676 .offset
= GLOBAL_VAR(cli_minprotocol
),
678 .enum_list
= enum_protocol
684 .offset
= GLOBAL_VAR(bUnicode
),
692 .offset
= GLOBAL_VAR(bReadRaw
),
697 .label
= "write raw",
700 .offset
= GLOBAL_VAR(bWriteRaw
),
705 .label
= "disable netbios",
708 .offset
= GLOBAL_VAR(bDisableNetbios
),
714 .label
= "nt status support",
717 .offset
= GLOBAL_VAR(bNTStatusSupport
),
726 .offset
= GLOBAL_VAR(max_mux
),
734 .offset
= GLOBAL_VAR(max_xmit
),
740 .label
= "name resolve order",
743 .offset
= GLOBAL_VAR(szNameResolveOrder
),
748 .label
= "max wins ttl",
751 .offset
= GLOBAL_VAR(max_wins_ttl
),
756 .label
= "min wins ttl",
759 .offset
= GLOBAL_VAR(min_wins_ttl
),
764 .label
= "time server",
767 .offset
= GLOBAL_VAR(bTimeServer
),
772 .label
= "unix extensions",
775 .offset
= GLOBAL_VAR(bUnixExtensions
),
780 .label
= "use spnego",
783 .offset
= GLOBAL_VAR(bUseSpnego
),
788 .label
= "server signing",
791 .offset
= GLOBAL_VAR(server_signing
),
793 .enum_list
= enum_smb_signing_vals
796 .label
= "client signing",
799 .offset
= GLOBAL_VAR(client_signing
),
801 .enum_list
= enum_smb_signing_vals
804 .label
= "rpc big endian",
807 .offset
= GLOBAL_VAR(bRpcBigEndian
),
813 .label
= "max connections",
816 .offset
= LOCAL_VAR(iMaxConnections
),
821 .label
= "paranoid server security",
824 .offset
= GLOBAL_VAR(paranoid_server_security
),
829 .label
= "socket options",
832 .offset
= GLOBAL_VAR(socket_options
),
838 .label
= "strict sync",
841 .offset
= LOCAL_VAR(bStrictSync
),
849 .offset
= GLOBAL_VAR(bUseMmap
),
852 .flags
= FLAG_ADVANCED
,
855 .label
= "case insensitive filesystem",
858 .offset
= LOCAL_VAR(bCIFileSystem
),
864 .label
= "max print jobs",
867 .offset
= LOCAL_VAR(iMaxPrintJobs
),
872 .label
= "printable",
875 .offset
= LOCAL_VAR(bPrint_ok
),
883 .offset
= LOCAL_VAR(bPrint_ok
),
889 .label
= "printer name",
892 .offset
= LOCAL_VAR(szPrintername
),
900 .offset
= LOCAL_VAR(szPrintername
),
906 .label
= "map system",
909 .offset
= LOCAL_VAR(bMap_system
),
914 .label
= "map hidden",
917 .offset
= LOCAL_VAR(bMap_hidden
),
922 .label
= "map archive",
925 .offset
= LOCAL_VAR(bMap_archive
),
931 .label
= "preferred master",
934 .offset
= GLOBAL_VAR(bPreferredMaster
),
936 .enum_list
= enum_bool_auto
939 .label
= "prefered master",
942 .offset
= GLOBAL_VAR(bPreferredMaster
),
944 .enum_list
= enum_bool_auto
947 .label
= "local master",
950 .offset
= GLOBAL_VAR(bLocalMaster
),
955 .label
= "browseable",
958 .offset
= LOCAL_VAR(bBrowseable
),
963 .label
= "browsable",
966 .offset
= LOCAL_VAR(bBrowseable
),
972 .label
= "wins server",
975 .offset
= GLOBAL_VAR(szWINSservers
),
980 .label
= "wins support",
983 .offset
= GLOBAL_VAR(bWINSsupport
),
988 .label
= "dns proxy",
991 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
996 .label
= "wins hook",
999 .offset
= GLOBAL_VAR(szWINSHook
),
1005 .label
= "csc policy",
1008 .offset
= LOCAL_VAR(iCSCPolicy
),
1010 .enum_list
= enum_csc_policy
1014 .label
= "strict locking",
1017 .offset
= LOCAL_VAR(iStrictLocking
),
1025 .offset
= LOCAL_VAR(bOpLocks
),
1031 .label
= "share backend",
1033 .p_class
= P_GLOBAL
,
1034 .offset
= GLOBAL_VAR(szShareBackend
),
1041 .p_class
= P_GLOBAL
,
1042 .offset
= GLOBAL_VAR(szAutoServices
),
1047 .label
= "auto services",
1049 .p_class
= P_GLOBAL
,
1050 .offset
= GLOBAL_VAR(szAutoServices
),
1055 .label
= "lock dir",
1057 .p_class
= P_GLOBAL
,
1058 .offset
= GLOBAL_VAR(szLockDir
),
1063 .label
= "lock directory",
1065 .p_class
= P_GLOBAL
,
1066 .offset
= GLOBAL_VAR(szLockDir
),
1071 .label
= "state directory",
1073 .p_class
= P_GLOBAL
,
1074 .offset
= GLOBAL_VAR(szStateDir
),
1079 .label
= "cache directory",
1081 .p_class
= P_GLOBAL
,
1082 .offset
= GLOBAL_VAR(szCacheDir
),
1087 .label
= "pid directory",
1089 .p_class
= P_GLOBAL
,
1090 .offset
= GLOBAL_VAR(szPidDir
),
1096 .label
= "socket address",
1098 .p_class
= P_GLOBAL
,
1099 .offset
= GLOBAL_VAR(szSocketAddress
),
1107 .offset
= LOCAL_VAR(szCopy
),
1108 .special
= handle_copy
,
1115 .offset
= LOCAL_VAR(szInclude
),
1116 .special
= handle_include
,
1121 .label
= "available",
1124 .offset
= LOCAL_VAR(bAvailable
),
1132 .offset
= LOCAL_VAR(volume
),
1140 .offset
= LOCAL_VAR(fstype
),
1146 .label
= "panic action",
1148 .p_class
= P_GLOBAL
,
1149 .offset
= GLOBAL_VAR(panic_action
),
1155 .label
= "msdfs root",
1158 .offset
= LOCAL_VAR(bMSDfsRoot
),
1163 .label
= "host msdfs",
1165 .p_class
= P_GLOBAL
,
1166 .offset
= GLOBAL_VAR(bHostMSDfs
),
1171 .label
= "winbind separator",
1173 .p_class
= P_GLOBAL
,
1174 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1179 .label
= "winbindd socket directory",
1181 .p_class
= P_GLOBAL
,
1182 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1187 .label
= "winbindd privileged socket directory",
1189 .p_class
= P_GLOBAL
,
1190 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1195 .label
= "winbind sealed pipes",
1197 .p_class
= P_GLOBAL
,
1198 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1203 .label
= "template shell",
1205 .p_class
= P_GLOBAL
,
1206 .offset
= GLOBAL_VAR(szTemplateShell
),
1211 .label
= "template homedir",
1213 .p_class
= P_GLOBAL
,
1214 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1219 .label
= "idmap trusted only",
1221 .p_class
= P_GLOBAL
,
1222 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1228 .label
= "ntp signd socket directory",
1230 .p_class
= P_GLOBAL
,
1231 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1236 .label
= "rndc command",
1238 .p_class
= P_GLOBAL
,
1239 .offset
= GLOBAL_VAR(szRNDCCommand
),
1244 .label
= "dns update command",
1246 .p_class
= P_GLOBAL
,
1247 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1252 .label
= "spn update command",
1254 .p_class
= P_GLOBAL
,
1255 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1260 .label
= "nsupdate command",
1262 .p_class
= P_GLOBAL
,
1263 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1268 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1272 /* local variables */
1273 struct loadparm_context
{
1274 const char *szConfigFile
;
1275 struct loadparm_global
*globals
;
1276 struct loadparm_service
**services
;
1277 struct loadparm_service
*sDefault
;
1278 struct smb_iconv_handle
*iconv_handle
;
1280 struct loadparm_service
*currentService
;
1281 bool bInGlobalSection
;
1283 struct file_lists
*next
;
1288 unsigned int flags
[NUMPARAMETERS
];
1291 bool global
; /* Is this the global context, which may set
1292 * global variables such as debug level etc? */
1293 const struct loadparm_s3_context
*s3_fns
;
1297 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1299 if (lp_ctx
->s3_fns
) {
1300 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1302 return lp_ctx
->sDefault
;
1306 * Convenience routine to grab string parameters into temporary memory
1307 * and run standard_sub_basic on them.
1309 * The buffers can be written to by
1310 * callers without affecting the source string.
1313 static const char *lp_string(const char *s
)
1315 #if 0 /* until REWRITE done to make thread-safe */
1316 size_t len
= s
? strlen(s
) : 0;
1320 /* The follow debug is useful for tracking down memory problems
1321 especially if you have an inner loop that is calling a lp_*()
1322 function that returns a string. Perhaps this debug should be
1323 present all the time? */
1326 DEBUG(10, ("lp_string(%s)\n", s
));
1329 #if 0 /* until REWRITE done to make thread-safe */
1331 lp_talloc
= talloc_init("lp_talloc");
1333 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1341 strlcpy(ret
, s
, len
);
1343 if (trim_string(ret
, "\"", "\"")) {
1344 if (strchr(ret
,'"') != NULL
)
1345 strlcpy(ret
, s
, len
);
1348 standard_sub_basic(ret
,len
+100);
1355 In this section all the functions that are used to access the
1356 parameters from the rest of the program are defined
1360 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1361 * for code compatibility between existing Samba4 and Samba3 code.
1364 /* this global context supports the lp_*() function varients */
1365 static struct loadparm_context
*global_loadparm_context
;
1367 #define lpcfg_default_service global_loadparm_context->sDefault
1368 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1370 #define FN_GLOBAL_STRING(fn_name,var_name) \
1371 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1372 if (lp_ctx == NULL) return NULL; \
1373 if (lp_ctx->s3_fns) { \
1374 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1375 return lp_ctx->s3_fns->fn_name(); \
1377 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1380 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1381 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1382 if (lp_ctx == NULL) return NULL; \
1383 if (lp_ctx->s3_fns) { \
1384 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1385 return lp_ctx->s3_fns->fn_name(); \
1387 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1390 #define FN_GLOBAL_LIST(fn_name,var_name) \
1391 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1392 if (lp_ctx == NULL) return NULL; \
1393 if (lp_ctx->s3_fns) { \
1394 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1395 return lp_ctx->s3_fns->fn_name(); \
1397 return lp_ctx->globals->var_name; \
1400 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1401 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1402 if (lp_ctx == NULL) return false; \
1403 if (lp_ctx->s3_fns) { \
1404 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1405 return lp_ctx->s3_fns->fn_name(); \
1407 return lp_ctx->globals->var_name; \
1410 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1411 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1412 if (lp_ctx->s3_fns) { \
1413 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1414 return lp_ctx->s3_fns->fn_name(); \
1416 return lp_ctx->globals->var_name; \
1419 /* Local parameters don't need the ->s3_fns because the struct
1420 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1422 #define FN_LOCAL_STRING(fn_name,val) \
1423 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1424 struct loadparm_service *sDefault) { \
1425 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1428 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1430 #define FN_LOCAL_LIST(fn_name,val) \
1431 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1432 struct loadparm_service *sDefault) {\
1433 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1436 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1438 #define FN_LOCAL_BOOL(fn_name,val) \
1439 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1440 struct loadparm_service *sDefault) { \
1441 return((service != NULL)? service->val : sDefault->val); \
1444 #define FN_LOCAL_INTEGER(fn_name,val) \
1445 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1446 struct loadparm_service *sDefault) { \
1447 return((service != NULL)? service->val : sDefault->val); \
1450 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1452 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1454 #define FN_LOCAL_CHAR(fn_name,val) \
1455 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1456 struct loadparm_service *sDefault) { \
1457 return((service != NULL)? service->val : sDefault->val); \
1460 #include "lib/param/param_functions.c"
1462 FN_GLOBAL_INTEGER(server_role
, server_role
)
1463 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
1464 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
1465 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
1466 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
1467 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
1468 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
1469 FN_GLOBAL_INTEGER(web_port
, web_port
)
1470 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
1471 FN_GLOBAL_STRING(logfile
, logfile
)
1472 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
1473 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
1474 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
1475 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
1476 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
1477 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
1478 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
1479 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
1480 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
1481 FN_GLOBAL_STRING(serverstring
, szServerString
)
1482 FN_GLOBAL_STRING(lockdir
, szLockDir
)
1483 FN_GLOBAL_STRING(statedir
, szStateDir
)
1484 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1485 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
1486 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
1487 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
1488 FN_GLOBAL_STRING(piddir
, szPidDir
)
1489 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
1490 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
1491 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
1492 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
1493 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
1494 FN_GLOBAL_LIST(server_services
, server_services
)
1495 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
1496 FN_GLOBAL_STRING(passdb_backend
, passdb_backend
)
1497 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
1498 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
1499 FN_GLOBAL_LIST(passwordserver
, szPasswordServers
)
1500 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
1501 FN_GLOBAL_STRING(realm
, szRealm_upper
)
1502 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
1503 FN_GLOBAL_STRING(socket_options
, socket_options
)
1504 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
1505 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
1506 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
1507 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
1508 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
1509 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1510 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
1511 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
1512 FN_GLOBAL_BOOL(we_are_a_wins_server
, bWINSsupport
)
1513 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
1514 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
1515 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
1516 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1517 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
1518 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1519 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
1520 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
1521 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
1522 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
1523 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
1524 FN_GLOBAL_BOOL(unicode
, bUnicode
)
1525 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
1526 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
1527 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
1528 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
1529 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
1530 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
1531 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
1532 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
1533 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
1534 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
1535 FN_GLOBAL_BOOL(use_mmap
, bUseMmap
)
1536 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
1537 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
1538 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
1539 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
1540 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
1541 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
1542 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
1543 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
1544 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
1545 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
1546 FN_GLOBAL_INTEGER(security
, security
)
1547 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
1549 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
1550 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
1552 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
1554 /* local prototypes */
1555 static int map_parameter(const char *pszParmName
);
1556 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1557 const char *pszServiceName
);
1558 static void copy_service(struct loadparm_service
*pserviceDest
,
1559 struct loadparm_service
*pserviceSource
,
1560 struct bitmap
*pcopymapDest
);
1561 static bool lpcfg_service_ok(struct loadparm_service
*service
);
1562 static bool do_section(const char *pszSectionName
, void *);
1563 static void init_copymap(struct loadparm_service
*pservice
);
1565 /* This is a helper function for parametrical options support. */
1566 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1567 /* Actual parametrical functions are quite simple */
1568 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1569 struct loadparm_service
*service
,
1570 const char *type
, const char *option
)
1572 char *vfskey_tmp
= NULL
;
1573 char *vfskey
= NULL
;
1574 struct parmlist_entry
*data
;
1579 if (lp_ctx
->s3_fns
) {
1580 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1583 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1585 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1586 if (vfskey_tmp
== NULL
) return NULL
;
1587 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1588 talloc_free(vfskey_tmp
);
1591 if (strcmp(data
->key
, vfskey
) == 0) {
1592 talloc_free(vfskey
);
1598 if (service
!= NULL
) {
1599 /* Try to fetch the same option but from globals */
1600 /* but only if we are not already working with globals */
1601 for (data
= lp_ctx
->globals
->param_opt
; data
;
1602 data
= data
->next
) {
1603 if (strcmp(data
->key
, vfskey
) == 0) {
1604 talloc_free(vfskey
);
1610 talloc_free(vfskey
);
1617 * convenience routine to return int parameters.
1619 static int lp_int(const char *s
)
1623 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1627 return strtol(s
, NULL
, 0);
1631 * convenience routine to return unsigned long parameters.
1633 static int lp_ulong(const char *s
)
1637 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1641 return strtoul(s
, NULL
, 0);
1645 * convenience routine to return unsigned long parameters.
1647 static double lp_double(const char *s
)
1651 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1655 return strtod(s
, NULL
);
1659 * convenience routine to return boolean parameters.
1661 static bool lp_bool(const char *s
)
1666 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1670 if (!set_boolean(s
, &ret
)) {
1671 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1680 * Return parametric option from a given service. Type is a part of option before ':'
1681 * Parametric option has following syntax: 'Type: option = value'
1682 * Returned value is allocated in 'lp_talloc' context
1685 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1686 struct loadparm_service
*service
, const char *type
,
1689 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1692 return lp_string(value
);
1698 * Return parametric option from a given service. Type is a part of option before ':'
1699 * Parametric option has following syntax: 'Type: option = value'
1700 * Returned value is allocated in 'lp_talloc' context
1703 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1704 struct loadparm_context
*lp_ctx
,
1705 struct loadparm_service
*service
,
1707 const char *option
, const char *separator
)
1709 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1712 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1718 * Return parametric option from a given service. Type is a part of option before ':'
1719 * Parametric option has following syntax: 'Type: option = value'
1722 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1723 struct loadparm_service
*service
, const char *type
,
1724 const char *option
, int default_v
)
1726 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1729 return lp_int(value
);
1735 * Return parametric option from a given service. Type is a part of
1736 * option before ':'.
1737 * Parametric option has following syntax: 'Type: option = value'.
1740 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1741 struct loadparm_service
*service
, const char *type
,
1742 const char *option
, int default_v
)
1746 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1748 if (value
&& conv_str_size_error(value
, &bval
)) {
1749 if (bval
<= INT_MAX
) {
1758 * Return parametric option from a given service.
1759 * Type is a part of option before ':'
1760 * Parametric option has following syntax: 'Type: option = value'
1762 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1763 struct loadparm_service
*service
, const char *type
,
1764 const char *option
, unsigned long default_v
)
1766 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1769 return lp_ulong(value
);
1775 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1776 struct loadparm_service
*service
, const char *type
,
1777 const char *option
, double default_v
)
1779 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1782 return lp_double(value
);
1788 * Return parametric option from a given service. Type is a part of option before ':'
1789 * Parametric option has following syntax: 'Type: option = value'
1792 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1793 struct loadparm_service
*service
, const char *type
,
1794 const char *option
, bool default_v
)
1796 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1799 return lp_bool(value
);
1806 * Initialise a service to the defaults.
1809 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1811 struct loadparm_service
*pservice
=
1812 talloc_zero(mem_ctx
, struct loadparm_service
);
1813 copy_service(pservice
, sDefault
, NULL
);
1818 * Set a string value, deallocating any existing space, and allocing the space
1821 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1828 *dest
= talloc_strdup(mem_ctx
, src
);
1829 if ((*dest
) == NULL
) {
1830 DEBUG(0,("Out of memory in string_set\n"));
1838 * Set a string value, deallocating any existing space, and allocing the space
1841 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1848 *dest
= strupper_talloc(mem_ctx
, src
);
1849 if ((*dest
) == NULL
) {
1850 DEBUG(0,("Out of memory in string_set_upper\n"));
1860 * Add a new service to the services array initialising it with the given
1864 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1865 const struct loadparm_service
*pservice
,
1869 struct loadparm_service tservice
;
1870 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1871 struct parmlist_entry
*data
, *pdata
;
1873 if (pservice
== NULL
) {
1874 pservice
= lp_ctx
->sDefault
;
1877 tservice
= *pservice
;
1879 /* it might already exist */
1881 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1883 if (service
!= NULL
) {
1884 /* Clean all parametric options for service */
1885 /* They will be added during parsing again */
1886 data
= service
->param_opt
;
1892 service
->param_opt
= NULL
;
1897 /* find an invalid one */
1898 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1899 if (lp_ctx
->services
[i
] == NULL
)
1902 /* if not, then create one */
1903 if (i
== lp_ctx
->iNumServices
) {
1904 struct loadparm_service
**tsp
;
1906 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1909 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1912 lp_ctx
->services
= tsp
;
1913 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1916 lp_ctx
->iNumServices
++;
1919 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1920 if (lp_ctx
->services
[i
] == NULL
) {
1921 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1924 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1926 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1927 return lp_ctx
->services
[i
];
1931 * Add a new home service, with the specified home directory, defaults coming
1932 * from service ifrom.
1935 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
1936 const char *pszHomename
,
1937 struct loadparm_service
*default_service
,
1938 const char *user
, const char *pszHomedir
)
1940 struct loadparm_service
*service
;
1942 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
1944 if (service
== NULL
)
1947 if (!(*(default_service
->szPath
))
1948 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1949 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1951 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1954 if (!(*(service
->comment
))) {
1955 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1957 service
->bAvailable
= default_service
->bAvailable
;
1958 service
->bBrowseable
= default_service
->bBrowseable
;
1960 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1961 pszHomename
, user
, service
->szPath
));
1967 * Add a new printer service, with defaults coming from service iFrom.
1970 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
1971 const char *pszPrintername
,
1972 struct loadparm_service
*default_service
)
1974 const char *comment
= "From Printcap";
1975 struct loadparm_service
*service
;
1976 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
1978 if (service
== NULL
)
1981 /* note that we do NOT default the availability flag to True - */
1982 /* we take it from the default service passed. This allows all */
1983 /* dynamic printers to be disabled by disabling the [printers] */
1984 /* entry (if/when the 'available' keyword is implemented!). */
1986 /* the printer name is set to the service name. */
1987 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
1988 lpcfg_string_set(service
, &service
->comment
, comment
);
1989 service
->bBrowseable
= default_service
->bBrowseable
;
1990 /* Printers cannot be read_only. */
1991 service
->bRead_only
= false;
1992 /* Printer services must be printable. */
1993 service
->bPrint_ok
= true;
1995 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
2001 * Map a parameter's string representation to something we can use.
2002 * Returns False if the parameter string is not recognised, else TRUE.
2005 static int map_parameter(const char *pszParmName
)
2009 if (*pszParmName
== '-')
2012 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2013 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
2016 /* Warn only if it isn't parametric option */
2017 if (strchr(pszParmName
, ':') == NULL
)
2018 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
2019 /* We do return 'fail' for parametric options as well because they are
2020 stored in different storage
2027 return the parameter structure for a parameter
2029 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
2033 if (lp_ctx
->s3_fns
) {
2034 return lp_ctx
->s3_fns
->get_parm_struct(name
);
2037 parmnum
= map_parameter(name
);
2038 if (parmnum
== -1) return NULL
;
2039 return &parm_table
[parmnum
];
2043 return the parameter pointer for a parameter
2045 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2046 struct loadparm_service
*service
, struct parm_struct
*parm
)
2048 if (lp_ctx
->s3_fns
) {
2049 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2052 if (service
== NULL
) {
2053 if (parm
->p_class
== P_LOCAL
)
2054 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2055 else if (parm
->p_class
== P_GLOBAL
)
2056 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2059 return ((char *)service
) + parm
->offset
;
2064 return the parameter pointer for a parameter
2066 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
2070 if (lp_ctx
->s3_fns
) {
2071 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
2073 return parm
->flags
& FLAG_CMDLINE
;
2078 parmnum
= map_parameter(name
);
2079 if (parmnum
== -1) return false;
2081 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
2085 * Find a service by name. Otherwise works like get_service.
2088 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2089 const char *pszServiceName
)
2093 if (lp_ctx
->s3_fns
) {
2094 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2097 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2098 if (lp_ctx
->services
[iService
] != NULL
&&
2099 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2100 return lp_ctx
->services
[iService
];
2107 * Copy a service structure to another.
2108 * If pcopymapDest is NULL then copy all fields
2111 static void copy_service(struct loadparm_service
*pserviceDest
,
2112 struct loadparm_service
*pserviceSource
,
2113 struct bitmap
*pcopymapDest
)
2116 bool bcopyall
= (pcopymapDest
== NULL
);
2117 struct parmlist_entry
*data
, *pdata
, *paramo
;
2120 for (i
= 0; parm_table
[i
].label
; i
++)
2121 if (parm_table
[i
].p_class
== P_LOCAL
&&
2122 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2124 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2126 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2128 switch (parm_table
[i
].type
) {
2130 *(bool *)dest_ptr
= *(bool *)src_ptr
;
2136 *(int *)dest_ptr
= *(int *)src_ptr
;
2140 lpcfg_string_set(pserviceDest
,
2146 lpcfg_string_set_upper(pserviceDest
,
2151 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2152 *(const char ***)src_ptr
);
2160 init_copymap(pserviceDest
);
2161 if (pserviceSource
->copymap
)
2162 bitmap_copy(pserviceDest
->copymap
,
2163 pserviceSource
->copymap
);
2166 data
= pserviceSource
->param_opt
;
2169 pdata
= pserviceDest
->param_opt
;
2170 /* Traverse destination */
2172 /* If we already have same option, override it */
2173 if (strcmp(pdata
->key
, data
->key
) == 0) {
2174 talloc_free(pdata
->value
);
2175 pdata
->value
= talloc_reference(pdata
,
2180 pdata
= pdata
->next
;
2183 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2186 paramo
->key
= talloc_reference(paramo
, data
->key
);
2187 paramo
->value
= talloc_reference(paramo
, data
->value
);
2188 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2195 * Check a service for consistency. Return False if the service is in any way
2196 * incomplete or faulty, else True.
2198 static bool lpcfg_service_ok(struct loadparm_service
*service
)
2203 if (service
->szService
[0] == '\0') {
2204 DEBUG(0, ("The following message indicates an internal error:\n"));
2205 DEBUG(0, ("No service name in service entry.\n"));
2209 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2210 /* I can't see why you'd want a non-printable printer service... */
2211 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2212 if (!service
->bPrint_ok
) {
2213 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2214 service
->szService
));
2215 service
->bPrint_ok
= true;
2217 /* [printers] service must also be non-browsable. */
2218 if (service
->bBrowseable
)
2219 service
->bBrowseable
= false;
2222 /* If a service is flagged unavailable, log the fact at level 0. */
2223 if (!service
->bAvailable
)
2224 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2225 service
->szService
));
2231 /*******************************************************************
2232 Keep a linked list of all config files so we know when one has changed
2233 it's date and needs to be reloaded.
2234 ********************************************************************/
2236 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2237 const char *fname
, const char *subfname
)
2239 struct file_lists
*f
= lp_ctx
->file_lists
;
2242 if (f
->name
&& !strcmp(f
->name
, fname
))
2248 f
= talloc(lp_ctx
, struct file_lists
);
2251 f
->next
= lp_ctx
->file_lists
;
2252 f
->name
= talloc_strdup(f
, fname
);
2257 f
->subfname
= talloc_strdup(f
, subfname
);
2262 lp_ctx
->file_lists
= f
;
2263 f
->modtime
= file_modtime(subfname
);
2265 time_t t
= file_modtime(subfname
);
2271 /*******************************************************************
2272 Check if a config file has changed date.
2273 ********************************************************************/
2274 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2276 struct file_lists
*f
;
2277 DEBUG(6, ("lp_file_list_changed()\n"));
2279 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2283 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2285 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2286 f
->name
, n2
, ctime(&f
->modtime
)));
2288 mod_time
= file_modtime(n2
);
2290 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2291 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2293 f
->modtime
= mod_time
;
2294 talloc_free(f
->subfname
);
2295 f
->subfname
= talloc_strdup(f
, n2
);
2302 /***************************************************************************
2303 Handle the "realm" parameter
2304 ***************************************************************************/
2306 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2307 const char *pszParmValue
, char **ptr
)
2309 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2311 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2312 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2314 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2315 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2320 /***************************************************************************
2321 Handle the include operation.
2322 ***************************************************************************/
2324 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2325 const char *pszParmValue
, char **ptr
)
2327 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2329 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2331 lpcfg_string_set(lp_ctx
, ptr
, fname
);
2333 if (file_exist(fname
))
2334 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2336 DEBUG(2, ("Can't find include file %s\n", fname
));
2341 /***************************************************************************
2342 Handle the interpretation of the copy parameter.
2343 ***************************************************************************/
2345 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2346 const char *pszParmValue
, char **ptr
)
2349 struct loadparm_service
*serviceTemp
;
2351 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2355 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2357 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2358 if (serviceTemp
== lp_ctx
->currentService
) {
2359 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2361 copy_service(lp_ctx
->currentService
,
2363 lp_ctx
->currentService
->copymap
);
2367 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2375 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2376 const char *pszParmValue
, char **ptr
)
2379 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2380 if (lp_ctx
->global
) {
2381 return debug_parse_levels(pszParmValue
);
2386 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2387 const char *pszParmValue
, char **ptr
)
2389 debug_set_logfile(pszParmValue
);
2390 if (lp_ctx
->global
) {
2391 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
2396 /***************************************************************************
2397 Initialise a copymap.
2398 ***************************************************************************/
2400 static void init_copymap(struct loadparm_service
*pservice
)
2404 TALLOC_FREE(pservice
->copymap
);
2406 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2407 if (!pservice
->copymap
)
2409 ("Couldn't allocate copymap!! (size %d)\n",
2410 (int)NUMPARAMETERS
));
2412 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2413 bitmap_set(pservice
->copymap
, i
);
2417 * Process a parametric option
2419 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2420 struct loadparm_service
*service
,
2421 const char *pszParmName
,
2422 const char *pszParmValue
, int flags
)
2424 struct parmlist_entry
*paramo
, *data
;
2426 TALLOC_CTX
*mem_ctx
;
2428 while (isspace((unsigned char)*pszParmName
)) {
2432 name
= strlower_talloc(lp_ctx
, pszParmName
);
2433 if (!name
) return false;
2435 if (service
== NULL
) {
2436 data
= lp_ctx
->globals
->param_opt
;
2437 mem_ctx
= lp_ctx
->globals
;
2439 data
= service
->param_opt
;
2443 /* Traverse destination */
2444 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2445 /* If we already have the option set, override it unless
2446 it was a command line option and the new one isn't */
2447 if (strcmp(paramo
->key
, name
) == 0) {
2448 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2449 !(flags
& FLAG_CMDLINE
)) {
2454 talloc_free(paramo
->value
);
2455 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2456 paramo
->priority
= flags
;
2462 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2465 paramo
->key
= talloc_strdup(paramo
, name
);
2466 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2467 paramo
->priority
= flags
;
2468 if (service
== NULL
) {
2469 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2471 DLIST_ADD(service
->param_opt
, paramo
);
2479 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2480 const char *pszParmName
, const char *pszParmValue
,
2481 struct loadparm_context
*lp_ctx
, bool on_globals
)
2484 /* if it is a special case then go ahead */
2485 if (parm_table
[parmnum
].special
) {
2487 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2492 goto mark_non_default
;
2495 /* now switch on the type of variable it is */
2496 switch (parm_table
[parmnum
].type
)
2500 if (!set_boolean(pszParmValue
, &b
)) {
2501 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2504 *(bool *)parm_ptr
= b
;
2510 if (!set_boolean(pszParmValue
, &b
)) {
2511 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2514 *(bool *)parm_ptr
= !b
;
2519 *(int *)parm_ptr
= atoi(pszParmValue
);
2523 *(char *)parm_ptr
= *pszParmValue
;
2527 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2533 if (conv_str_size_error(pszParmValue
, &val
)) {
2534 if (val
<= INT_MAX
) {
2535 *(int *)parm_ptr
= (int)val
;
2540 DEBUG(0,("lp_do_parameter(%s): value is not "
2541 "a valid size specifier!\n", pszParmValue
));
2546 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2547 pszParmValue
, NULL
);
2551 char **new_list
= str_list_make(mem_ctx
,
2552 pszParmValue
, NULL
);
2553 for (i
=0; new_list
[i
]; i
++) {
2554 if (new_list
[i
][0] == '+' && new_list
[i
][1] &&
2555 (!str_list_check(*(const char ***)parm_ptr
,
2556 &new_list
[i
][1]))) {
2557 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2559 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2560 #if 0 /* This is commented out because we sometimes parse the list
2561 * twice, and so we can't assert on this */
2562 if (!str_list_check(*(const char ***)parm_ptr
,
2564 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2565 pszParmName
, pszParmValue
, new_list
[i
],
2566 str_list_join_shell(mem_ctx
, *(const char ***)parm_ptr
, ' ')));
2571 str_list_remove(*(const char ***)parm_ptr
,
2575 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2576 pszParmName
, pszParmValue
));
2579 *(const char ***)parm_ptr
= (const char **) new_list
;
2586 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2590 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2594 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2597 parm_table
[parmnum
].enum_list
[i
].name
)) {
2599 parm_table
[parmnum
].
2604 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2605 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2606 pszParmValue
, pszParmName
));
2613 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2614 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2615 /* we have to also unset FLAG_DEFAULT on aliases */
2616 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2617 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2619 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2620 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2627 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2628 const char *pszParmName
, const char *pszParmValue
)
2630 int parmnum
= map_parameter(pszParmName
);
2634 if (strchr(pszParmName
, ':')) {
2635 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2637 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2641 /* if the flag has been set on the command line, then don't allow override,
2642 but don't report an error */
2643 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2647 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2649 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2650 pszParmName
, pszParmValue
, lp_ctx
, true);
2653 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2654 struct loadparm_service
*service
,
2655 const char *pszParmName
, const char *pszParmValue
)
2659 int parmnum
= map_parameter(pszParmName
);
2662 if (strchr(pszParmName
, ':')) {
2663 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2665 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2669 /* if the flag has been set on the command line, then don't allow override,
2670 but don't report an error */
2671 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2675 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2677 ("Global parameter %s found in service section!\n",
2681 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2683 if (!service
->copymap
)
2684 init_copymap(service
);
2686 /* this handles the aliases - set the copymap for other
2687 * entries with the same data pointer */
2688 for (i
= 0; parm_table
[i
].label
; i
++)
2689 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2690 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2691 bitmap_clear(service
->copymap
, i
);
2693 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2694 pszParmValue
, lp_ctx
, false);
2698 * Process a parameter.
2701 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2704 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2706 if (lp_ctx
->bInGlobalSection
)
2707 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2710 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2711 pszParmName
, pszParmValue
);
2715 variable argument do parameter
2717 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2718 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2719 const char *pszParmName
, const char *fmt
, ...)
2726 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2728 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2735 set a parameter from the commandline - this is called from command line parameter
2736 parsing code. It sets the parameter then marks the parameter as unable to be modified
2737 by smb.conf processing
2739 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2740 const char *pszParmValue
)
2745 if (lp_ctx
->s3_fns
) {
2746 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2749 parmnum
= map_parameter(pszParmName
);
2751 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2754 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2755 /* set a parametric option */
2756 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2757 pszParmValue
, FLAG_CMDLINE
);
2761 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2765 /* reset the CMDLINE flag in case this has been called before */
2766 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2768 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2772 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2774 /* we have to also set FLAG_CMDLINE on aliases */
2775 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2776 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2778 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2779 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2786 set a option from the commandline in 'a=b' format. Use to support --option
2788 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2793 s
= talloc_strdup(NULL
, option
);
2806 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2812 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2815 * Print a parameter of the specified type.
2818 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2820 /* For the seperation of lists values that we print below */
2821 const char *list_sep
= ", ";
2826 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2827 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2829 p
->enum_list
[i
].name
);
2836 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2840 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2845 fprintf(f
, "%d", *(int *)ptr
);
2849 fprintf(f
, "%c", *(char *)ptr
);
2853 int val
= *(int *)ptr
;
2857 fprintf(f
, "0%o", val
);
2866 if ((char ***)ptr
&& *(char ***)ptr
) {
2867 char **list
= *(char ***)ptr
;
2868 for (; *list
; list
++) {
2869 /* surround strings with whitespace in double quotes */
2870 if (*(list
+1) == NULL
) {
2871 /* last item, no extra separator */
2874 if ( strchr_m( *list
, ' ' ) ) {
2875 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2877 fprintf(f
, "%s%s", *list
, list_sep
);
2885 if (*(char **)ptr
) {
2886 fprintf(f
, "%s", *(char **)ptr
);
2895 * Check if two parameters are equal.
2898 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2903 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2909 return (*((int *)ptr1
) == *((int *)ptr2
));
2912 return (*((char *)ptr1
) == *((char *)ptr2
));
2916 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
2921 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2926 return (p1
== p2
|| strequal(p1
, p2
));
2935 * Process a new section (service).
2937 * At this stage all sections are services.
2938 * Later we'll have special sections that permit server parameters to be set.
2939 * Returns True on success, False on failure.
2942 static bool do_section(const char *pszSectionName
, void *userdata
)
2944 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2946 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2947 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2950 /* if we've just struck a global section, note the fact. */
2951 lp_ctx
->bInGlobalSection
= isglobal
;
2953 /* check for multiple global sections */
2954 if (lp_ctx
->bInGlobalSection
) {
2955 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2959 /* if we have a current service, tidy it up before moving on */
2962 if (lp_ctx
->currentService
!= NULL
)
2963 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2965 /* if all is still well, move to the next record in the services array */
2967 /* We put this here to avoid an odd message order if messages are */
2968 /* issued by the post-processing of a previous section. */
2969 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2971 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2974 DEBUG(0, ("Failed to add a new service\n"));
2984 * Determine if a particular base parameter is currently set to the default value.
2987 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2989 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2990 if (!defaults_saved
)
2992 switch (parm_table
[i
].type
) {
2995 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2996 (const char **)def_ptr
);
2999 return strequal(parm_table
[i
].def
.svalue
,
3003 return parm_table
[i
].def
.bvalue
==
3010 return parm_table
[i
].def
.ivalue
==
3017 *Display the contents of the global structure.
3020 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
3024 struct parmlist_entry
*data
;
3026 fprintf(f
, "# Global parameters\n[global]\n");
3028 for (i
= 0; parm_table
[i
].label
; i
++)
3029 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3030 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3031 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
3033 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3034 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
3037 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3038 for (data
= lp_ctx
->globals
->param_opt
; data
;
3039 data
= data
->next
) {
3040 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3043 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3050 * Display the contents of a single services record.
3053 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3054 unsigned int *flags
)
3057 struct parmlist_entry
*data
;
3059 if (pService
!= sDefault
)
3060 fprintf(f
, "\n[%s]\n", pService
->szService
);
3062 for (i
= 0; parm_table
[i
].label
; i
++) {
3063 if (parm_table
[i
].p_class
== P_LOCAL
&&
3064 (*parm_table
[i
].label
!= '-') &&
3065 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3067 if (pService
== sDefault
) {
3068 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3071 if (defaults_saved
) {
3072 if (is_default(sDefault
, i
)) {
3077 if (equal_parameter(parm_table
[i
].type
,
3078 ((char *)pService
) +
3079 parm_table
[i
].offset
,
3080 ((char *)sDefault
) +
3081 parm_table
[i
].offset
))
3085 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3086 print_parameter(&parm_table
[i
],
3087 ((char *)pService
) + parm_table
[i
].offset
, f
);
3091 if (pService
->param_opt
!= NULL
) {
3092 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3093 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3098 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3099 struct loadparm_service
*service
,
3100 const char *parm_name
, FILE * f
)
3102 struct parm_struct
*parm
;
3105 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3110 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3112 print_parameter(parm
, ptr
, f
);
3118 * Return info about the next parameter in a service.
3119 * snum==-1 gives the globals.
3120 * Return NULL when out of parameters.
3124 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3128 /* do the globals */
3129 for (; parm_table
[*i
].label
; (*i
)++) {
3130 if ((*parm_table
[*i
].label
== '-'))
3134 && (parm_table
[*i
].offset
==
3135 parm_table
[(*i
) - 1].offset
)
3136 && (parm_table
[*i
].p_class
==
3137 parm_table
[(*i
) - 1].p_class
))
3140 return &parm_table
[(*i
)++];
3143 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3145 for (; parm_table
[*i
].label
; (*i
)++) {
3146 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3147 (*parm_table
[*i
].label
!= '-') &&
3149 (parm_table
[*i
].offset
!=
3150 parm_table
[(*i
) - 1].offset
)))
3152 if (allparameters
||
3153 !equal_parameter(parm_table
[*i
].type
,
3154 ((char *)pService
) +
3155 parm_table
[*i
].offset
,
3156 ((char *)lp_ctx
->sDefault
) +
3157 parm_table
[*i
].offset
))
3159 return &parm_table
[(*i
)++];
3170 * Auto-load some home services.
3172 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3180 * Unload unused services.
3183 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3184 struct smbsrv_connection
*smb
,
3185 bool (*snumused
) (struct smbsrv_connection
*, int))
3188 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3189 if (lp_ctx
->services
[i
] == NULL
)
3192 if (!snumused
|| !snumused(smb
, i
)) {
3193 talloc_free(lp_ctx
->services
[i
]);
3194 lp_ctx
->services
[i
] = NULL
;
3200 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3202 struct parmlist_entry
*data
;
3204 if (lp_ctx
->refuse_free
) {
3205 /* someone is trying to free the
3206 global_loadparm_context.
3207 We can't allow that. */
3211 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3212 struct parmlist_entry
*next
;
3213 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3215 if (data
->priority
& FLAG_CMDLINE
) continue;
3216 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3225 * Initialise the global parameter structure.
3227 * Note that most callers should use loadparm_init_global() instead
3229 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3233 struct loadparm_context
*lp_ctx
;
3234 struct parmlist_entry
*parm
;
3237 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3241 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3242 lp_ctx
->bInGlobalSection
= true;
3243 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3244 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3246 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3247 lp_ctx
->sDefault
->bAvailable
= true;
3248 lp_ctx
->sDefault
->bBrowseable
= true;
3249 lp_ctx
->sDefault
->bRead_only
= true;
3250 lp_ctx
->sDefault
->bMap_archive
= true;
3251 lp_ctx
->sDefault
->iStrictLocking
= true;
3252 lp_ctx
->sDefault
->bOpLocks
= true;
3253 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3254 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3255 lp_ctx
->sDefault
->iDir_mask
= 0755;
3256 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3258 DEBUG(3, ("Initialising global parameters\n"));
3260 for (i
= 0; parm_table
[i
].label
; i
++) {
3261 if ((parm_table
[i
].type
== P_STRING
||
3262 parm_table
[i
].type
== P_USTRING
) &&
3263 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3265 if (parm_table
[i
].p_class
== P_LOCAL
) {
3266 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3268 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3270 *r
= talloc_strdup(lp_ctx
, "");
3274 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3275 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3276 talloc_free(logfile
);
3278 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3280 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3282 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3284 lpcfg_do_global_parameter(lp_ctx
, "server role", "standalone");
3286 /* options that can be set on the command line must be initialised via
3287 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3289 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3291 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3292 myname
= get_myname(lp_ctx
);
3293 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3294 talloc_free(myname
);
3295 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3297 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3299 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3300 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3302 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");
3303 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3304 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3305 /* the winbind method for domain controllers is for both RODC
3306 auth forwarding and for trusted domains */
3307 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3308 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3310 /* This hive should be dynamically generated by Samba using
3311 data from the sam, but for the moment leave it in a tdb to
3312 keep regedt32 from popping up an annoying dialog. */
3313 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3315 /* using UTF8 by default allows us to support all chars */
3316 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3318 /* Use codepage 850 as a default for the dos character set */
3319 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3322 * Allow the default PASSWD_CHAT to be overridden in local.h.
3324 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3326 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3327 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3328 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3329 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3330 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3332 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3333 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3334 "Samba %s", SAMBA_VERSION_STRING
);
3336 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3338 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3339 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3340 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3341 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3342 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3343 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3344 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3345 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3346 lpcfg_do_global_parameter(lp_ctx
, "security", "USER");
3347 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3348 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3349 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3350 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3351 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3352 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3354 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3355 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3356 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3357 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3358 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3359 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3360 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3361 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3363 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3365 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3366 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3368 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3369 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3371 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3372 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3373 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3374 #if _SAMBA_BUILD_ >= 4
3375 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3376 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3377 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3378 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3380 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3381 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3382 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3384 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
3385 lpcfg_do_global_parameter(lp_ctx
, "server signing", "auto");
3387 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3389 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
3391 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3392 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3393 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3394 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3395 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3396 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3397 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3399 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3401 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3402 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3404 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3405 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3406 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3407 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3408 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3410 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3411 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3413 for (i
= 0; parm_table
[i
].label
; i
++) {
3414 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3415 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3419 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3420 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3421 parm
->priority
|= FLAG_DEFAULT
;
3429 * Initialise the global parameter structure.
3431 struct loadparm_context
*loadparm_init_global(bool load_default
)
3433 if (global_loadparm_context
== NULL
) {
3434 global_loadparm_context
= loadparm_init(NULL
);
3436 if (global_loadparm_context
== NULL
) {
3439 global_loadparm_context
->global
= true;
3440 if (load_default
&& !global_loadparm_context
->loaded
) {
3441 lpcfg_load_default(global_loadparm_context
);
3443 global_loadparm_context
->refuse_free
= true;
3444 return global_loadparm_context
;
3448 * Initialise the global parameter structure.
3450 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3451 const struct loadparm_s3_context
*s3_fns
)
3453 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3454 if (!loadparm_context
) {
3457 loadparm_context
->s3_fns
= s3_fns
;
3458 return loadparm_context
;
3461 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3463 return lp_ctx
->szConfigFile
;
3466 const char *lp_default_path(void)
3468 if (getenv("SMB_CONF_PATH"))
3469 return getenv("SMB_CONF_PATH");
3471 return dyn_CONFIGFILE
;
3475 * Update the internal state of a loadparm context after settings
3478 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3480 struct debug_settings settings
;
3481 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3483 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3484 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3487 if (!lp_ctx
->global
) {
3491 panic_action
= lp_ctx
->globals
->panic_action
;
3493 reload_charcnv(lp_ctx
);
3495 ZERO_STRUCT(settings
);
3496 /* Add any more debug-related smb.conf parameters created in
3498 settings
.timestamp_logs
= true;
3499 debug_set_settings(&settings
);
3501 /* FIXME: This is a bit of a hack, but we can't use a global, since
3502 * not everything that uses lp also uses the socket library */
3503 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3504 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3506 unsetenv("SOCKET_TESTNONBLOCK");
3512 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3516 path
= lp_default_path();
3518 if (!file_exist(path
)) {
3519 /* We allow the default smb.conf file to not exist,
3520 * basically the equivalent of an empty file. */
3521 return lpcfg_update(lp_ctx
);
3524 return lpcfg_load(lp_ctx
, path
);
3528 * Load the services array from the services file.
3530 * Return True on success, False on failure.
3532 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3537 filename
= talloc_strdup(lp_ctx
, filename
);
3539 lp_ctx
->szConfigFile
= filename
;
3541 if (lp_ctx
->s3_fns
) {
3542 return lp_ctx
->s3_fns
->load(filename
);
3545 lp_ctx
->bInGlobalSection
= true;
3546 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3547 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3549 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3551 /* We get sections first, so have to start 'behind' to make up */
3552 lp_ctx
->currentService
= NULL
;
3553 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3555 /* finish up the last section */
3556 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3558 if (lp_ctx
->currentService
!= NULL
)
3559 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3561 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3563 /* we do this unconditionally, so that it happens even
3564 for a missing smb.conf */
3565 reload_charcnv(lp_ctx
);
3567 if (bRetval
== true) {
3568 /* set this up so that any child python tasks will
3569 find the right smb.conf */
3570 setenv("SMB_CONF_PATH", filename
, 1);
3572 /* set the context used by the lp_*() function
3574 global_loadparm_context
= lp_ctx
;
3575 lp_ctx
->loaded
= true;
3582 * Return the max number of services.
3585 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3587 if (lp_ctx
->s3_fns
) {
3588 return lp_ctx
->s3_fns
->get_numservices();
3591 return lp_ctx
->iNumServices
;
3595 * Display the contents of the services array in human-readable form.
3598 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3603 if (lp_ctx
->s3_fns
) {
3604 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3608 defaults_saved
= !show_defaults
;
3610 dump_globals(lp_ctx
, f
, show_defaults
);
3612 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3614 for (iService
= 0; iService
< maxtoprint
; iService
++)
3615 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3619 * Display the contents of one service in human-readable form.
3621 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3623 if (service
!= NULL
) {
3624 if (service
->szService
[0] == '\0')
3626 dump_a_service(service
, sDefault
, f
, NULL
);
3630 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3633 if (lp_ctx
->s3_fns
) {
3634 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3637 return lp_ctx
->services
[snum
];
3640 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3641 const char *service_name
)
3646 if (lp_ctx
->s3_fns
) {
3647 return lp_ctx
->s3_fns
->get_service(service_name
);
3650 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3651 if (lp_ctx
->services
[iService
] &&
3652 lp_ctx
->services
[iService
]->szService
) {
3654 * The substitution here is used to support %U is
3657 serviceName
= standard_sub_basic(
3658 lp_ctx
->services
[iService
],
3659 lp_ctx
->services
[iService
]->szService
);
3660 if (strequal(serviceName
, service_name
)) {
3661 talloc_free(serviceName
);
3662 return lp_ctx
->services
[iService
];
3664 talloc_free(serviceName
);
3668 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3672 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3674 return lp_string((const char *)service
->szService
);
3678 * A useful volume label function.
3680 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3683 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3684 service
->volume
: sDefault
->volume
));
3686 return lpcfg_servicename(service
);
3691 * If we are PDC then prefer us as DMB
3693 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3696 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3697 service
->szPrintername
: sDefault
->szPrintername
));
3698 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3699 ret
= lpcfg_servicename(service
);
3706 * Return the max print jobs per queue.
3708 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3710 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3711 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3712 maxjobs
= PRINT_MAX_JOBID
- 1;
3717 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3719 if (lp_ctx
== NULL
) {
3720 return get_iconv_handle();
3722 return lp_ctx
->iconv_handle
;
3725 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3727 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3728 if (!lp_ctx
->global
) {
3732 if (old_ic
== NULL
) {
3733 old_ic
= global_iconv_handle
;
3735 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3736 global_iconv_handle
= lp_ctx
->iconv_handle
;
3739 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3741 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3744 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3746 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3749 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3751 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3754 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3756 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3759 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3761 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3764 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3766 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
3767 if (settings
== NULL
)
3769 SMB_ASSERT(lp_ctx
!= NULL
);
3770 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3771 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");