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 "smb_server/smb_server.h"
62 #include "libcli/raw/signing.h"
63 #include "../lib/util/dlinklist.h"
64 #include "param/param.h"
65 #include "param/loadparm.h"
66 #include "libcli/raw/libcliraw.h"
67 #include "rpc_server/common/common.h"
68 #include "lib/socket/socket.h"
69 #include "auth/gensec/gensec.h"
71 #include "../lib/util/bitmap.h"
73 #define standard_sub_basic talloc_strdup
75 static bool do_parameter(const char *, const char *, void *);
76 static bool defaults_saved
= false;
78 #define LOADPARM_EXTRA_GLOBALS \
79 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 static const struct enum_list enum_protocol
[] = {
108 {PROTOCOL_SMB2
, "SMB2"},
109 {PROTOCOL_NT1
, "NT1"},
110 {PROTOCOL_LANMAN2
, "LANMAN2"},
111 {PROTOCOL_LANMAN1
, "LANMAN1"},
112 {PROTOCOL_CORE
, "CORE"},
113 {PROTOCOL_COREPLUS
, "COREPLUS"},
114 {PROTOCOL_COREPLUS
, "CORE+"},
118 static const struct enum_list enum_security
[] = {
119 {SEC_SHARE
, "SHARE"},
125 static const struct enum_list enum_bool_auto
[] = {
136 /* Client-side offline caching policy types */
139 CSC_POLICY_DOCUMENTS
=1,
140 CSC_POLICY_PROGRAMS
=2,
144 static const struct enum_list enum_csc_policy
[] = {
145 {CSC_POLICY_MANUAL
, "manual"},
146 {CSC_POLICY_DOCUMENTS
, "documents"},
147 {CSC_POLICY_PROGRAMS
, "programs"},
148 {CSC_POLICY_DISABLE
, "disable"},
152 /* SMB signing types. */
153 static const struct enum_list enum_smb_signing_vals
[] = {
154 {SMB_SIGNING_OFF
, "No"},
155 {SMB_SIGNING_OFF
, "False"},
156 {SMB_SIGNING_OFF
, "0"},
157 {SMB_SIGNING_OFF
, "Off"},
158 {SMB_SIGNING_OFF
, "disabled"},
159 {SMB_SIGNING_SUPPORTED
, "Yes"},
160 {SMB_SIGNING_SUPPORTED
, "True"},
161 {SMB_SIGNING_SUPPORTED
, "1"},
162 {SMB_SIGNING_SUPPORTED
, "On"},
163 {SMB_SIGNING_SUPPORTED
, "enabled"},
164 {SMB_SIGNING_REQUIRED
, "required"},
165 {SMB_SIGNING_REQUIRED
, "mandatory"},
166 {SMB_SIGNING_REQUIRED
, "force"},
167 {SMB_SIGNING_REQUIRED
, "forced"},
168 {SMB_SIGNING_REQUIRED
, "enforced"},
169 {SMB_SIGNING_AUTO
, "auto"},
173 static const struct enum_list enum_server_role
[] = {
174 {ROLE_STANDALONE
, "standalone"},
175 {ROLE_DOMAIN_MEMBER
, "member server"},
176 {ROLE_DOMAIN_MEMBER
, "member"},
177 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
178 {ROLE_DOMAIN_CONTROLLER
, "dc"},
182 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
183 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
185 static struct parm_struct parm_table
[] = {
187 .label
= "server role",
190 .offset
= GLOBAL_VAR(server_role
),
192 .enum_list
= enum_server_role
195 .label
= "dos charset",
198 .offset
= GLOBAL_VAR(dos_charset
),
203 .label
= "unix charset",
206 .offset
= GLOBAL_VAR(unix_charset
),
211 .label
= "ncalrpc dir",
214 .offset
= GLOBAL_VAR(ncalrpc_dir
),
222 .offset
= LOCAL_VAR(comment
),
230 .offset
= LOCAL_VAR(szPath
),
235 .label
= "directory",
238 .offset
= LOCAL_VAR(szPath
),
243 .label
= "workgroup",
246 .offset
= GLOBAL_VAR(szWorkgroup
),
254 .offset
= GLOBAL_VAR(szRealm
),
255 .special
= handle_realm
,
259 .label
= "netbios name",
262 .offset
= GLOBAL_VAR(szNetbiosName
),
267 .label
= "netbios aliases",
270 .offset
= GLOBAL_VAR(szNetbiosAliases
),
275 .label
= "netbios scope",
278 .offset
= GLOBAL_VAR(szNetbiosScope
),
283 .label
= "server string",
286 .offset
= GLOBAL_VAR(szServerString
),
291 .label
= "interfaces",
294 .offset
= GLOBAL_VAR(szInterfaces
),
299 .label
= "bind interfaces only",
302 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
307 .label
= "ntvfs handler",
310 .offset
= LOCAL_VAR(ntvfs_handler
),
315 .label
= "ntptr providor",
318 .offset
= GLOBAL_VAR(ntptr_providor
),
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
= "spoolss database",
383 .offset
= GLOBAL_VAR(szSPOOLSS_URL
),
388 .label
= "wins config database",
391 .offset
= GLOBAL_VAR(szWINS_CONFIG_URL
),
396 .label
= "wins database",
399 .offset
= GLOBAL_VAR(szWINS_URL
),
404 .label
= "private dir",
407 .offset
= GLOBAL_VAR(szPrivateDir
),
412 .label
= "passwd chat",
415 .offset
= GLOBAL_VAR(szPasswdChat
),
420 .label
= "password level",
423 .offset
= GLOBAL_VAR(pwordlevel
),
428 .label
= "lanman auth",
431 .offset
= GLOBAL_VAR(bLanmanAuth
),
436 .label
= "ntlm auth",
439 .offset
= GLOBAL_VAR(bNTLMAuth
),
444 .label
= "client NTLMv2 auth",
447 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
452 .label
= "client lanman auth",
455 .offset
= GLOBAL_VAR(bClientLanManAuth
),
460 .label
= "client plaintext auth",
463 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
468 .label
= "client use spnego principal",
471 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
477 .label
= "read only",
480 .offset
= LOCAL_VAR(bRead_only
),
486 .label
= "create mask",
489 .offset
= LOCAL_VAR(iCreate_mask
),
494 .label
= "force create mode",
497 .offset
= LOCAL_VAR(iCreate_force_mode
),
502 .label
= "directory mask",
505 .offset
= LOCAL_VAR(iDir_mask
),
510 .label
= "force directory mode",
513 .offset
= LOCAL_VAR(iDir_force_mode
),
519 .label
= "hosts allow",
522 .offset
= LOCAL_VAR(szHostsallow
),
527 .label
= "hosts deny",
530 .offset
= LOCAL_VAR(szHostsdeny
),
536 .label
= "log level",
539 .offset
= GLOBAL_VAR(loglevel
),
540 .special
= handle_debuglevel
,
544 .label
= "debuglevel",
547 .offset
= GLOBAL_VAR(loglevel
),
548 .special
= handle_debuglevel
,
555 .offset
= GLOBAL_VAR(logfile
),
556 .special
= handle_logfile
,
561 .label
= "smb ports",
564 .offset
= GLOBAL_VAR(smb_ports
),
572 .offset
= GLOBAL_VAR(nbt_port
),
577 .label
= "dgram port",
580 .offset
= GLOBAL_VAR(dgram_port
),
585 .label
= "cldap port",
588 .offset
= GLOBAL_VAR(cldap_port
),
593 .label
= "krb5 port",
596 .offset
= GLOBAL_VAR(krb5_port
),
601 .label
= "kpasswd port",
604 .offset
= GLOBAL_VAR(kpasswd_port
),
612 .offset
= GLOBAL_VAR(web_port
),
617 .label
= "tls enabled",
620 .offset
= GLOBAL_VAR(tls_enabled
),
625 .label
= "tls keyfile",
628 .offset
= GLOBAL_VAR(tls_keyfile
),
633 .label
= "tls certfile",
636 .offset
= GLOBAL_VAR(tls_certfile
),
641 .label
= "tls cafile",
644 .offset
= GLOBAL_VAR(tls_cafile
),
649 .label
= "tls crlfile",
652 .offset
= GLOBAL_VAR(tls_crlfile
),
657 .label
= "tls dh params file",
660 .offset
= GLOBAL_VAR(tls_dhpfile
),
665 .label
= "large readwrite",
668 .offset
= GLOBAL_VAR(bLargeReadwrite
),
673 .label
= "server max protocol",
676 .offset
= GLOBAL_VAR(srv_maxprotocol
),
678 .enum_list
= enum_protocol
681 .label
= "server min protocol",
684 .offset
= GLOBAL_VAR(srv_minprotocol
),
686 .enum_list
= enum_protocol
689 .label
= "client max protocol",
692 .offset
= GLOBAL_VAR(cli_maxprotocol
),
694 .enum_list
= enum_protocol
697 .label
= "client min protocol",
700 .offset
= GLOBAL_VAR(cli_minprotocol
),
702 .enum_list
= enum_protocol
708 .offset
= GLOBAL_VAR(bUnicode
),
716 .offset
= GLOBAL_VAR(bReadRaw
),
721 .label
= "write raw",
724 .offset
= GLOBAL_VAR(bWriteRaw
),
729 .label
= "disable netbios",
732 .offset
= GLOBAL_VAR(bDisableNetbios
),
738 .label
= "nt status support",
741 .offset
= GLOBAL_VAR(bNTStatusSupport
),
750 .offset
= GLOBAL_VAR(max_mux
),
758 .offset
= GLOBAL_VAR(max_xmit
),
764 .label
= "name resolve order",
767 .offset
= GLOBAL_VAR(szNameResolveOrder
),
772 .label
= "max wins ttl",
775 .offset
= GLOBAL_VAR(max_wins_ttl
),
780 .label
= "min wins ttl",
783 .offset
= GLOBAL_VAR(min_wins_ttl
),
788 .label
= "time server",
791 .offset
= GLOBAL_VAR(bTimeServer
),
796 .label
= "unix extensions",
799 .offset
= GLOBAL_VAR(bUnixExtensions
),
804 .label
= "use spnego",
807 .offset
= GLOBAL_VAR(bUseSpnego
),
812 .label
= "server signing",
815 .offset
= GLOBAL_VAR(server_signing
),
817 .enum_list
= enum_smb_signing_vals
820 .label
= "client signing",
823 .offset
= GLOBAL_VAR(client_signing
),
825 .enum_list
= enum_smb_signing_vals
828 .label
= "rpc big endian",
831 .offset
= GLOBAL_VAR(bRpcBigEndian
),
837 .label
= "max connections",
840 .offset
= LOCAL_VAR(iMaxConnections
),
845 .label
= "paranoid server security",
848 .offset
= GLOBAL_VAR(paranoid_server_security
),
853 .label
= "socket options",
856 .offset
= GLOBAL_VAR(socket_options
),
862 .label
= "strict sync",
865 .offset
= LOCAL_VAR(bStrictSync
),
870 .label
= "case insensitive filesystem",
873 .offset
= LOCAL_VAR(bCIFileSystem
),
879 .label
= "max print jobs",
882 .offset
= LOCAL_VAR(iMaxPrintJobs
),
887 .label
= "printable",
890 .offset
= LOCAL_VAR(bPrint_ok
),
898 .offset
= LOCAL_VAR(bPrint_ok
),
904 .label
= "printer name",
907 .offset
= LOCAL_VAR(szPrintername
),
915 .offset
= LOCAL_VAR(szPrintername
),
921 .label
= "map system",
924 .offset
= LOCAL_VAR(bMap_system
),
929 .label
= "map hidden",
932 .offset
= LOCAL_VAR(bMap_hidden
),
937 .label
= "map archive",
940 .offset
= LOCAL_VAR(bMap_archive
),
946 .label
= "preferred master",
949 .offset
= GLOBAL_VAR(bPreferredMaster
),
951 .enum_list
= enum_bool_auto
954 .label
= "prefered master",
957 .offset
= GLOBAL_VAR(bPreferredMaster
),
959 .enum_list
= enum_bool_auto
962 .label
= "local master",
965 .offset
= GLOBAL_VAR(bLocalMaster
),
970 .label
= "browseable",
973 .offset
= LOCAL_VAR(bBrowseable
),
978 .label
= "browsable",
981 .offset
= LOCAL_VAR(bBrowseable
),
987 .label
= "wins server",
990 .offset
= GLOBAL_VAR(szWINSservers
),
995 .label
= "wins support",
998 .offset
= GLOBAL_VAR(bWINSsupport
),
1003 .label
= "dns proxy",
1005 .p_class
= P_GLOBAL
,
1006 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
1011 .label
= "wins hook",
1013 .p_class
= P_GLOBAL
,
1014 .offset
= GLOBAL_VAR(szWINSHook
),
1020 .label
= "csc policy",
1023 .offset
= LOCAL_VAR(iCSCPolicy
),
1025 .enum_list
= enum_csc_policy
1029 .label
= "strict locking",
1032 .offset
= LOCAL_VAR(iStrictLocking
),
1040 .offset
= LOCAL_VAR(bOpLocks
),
1046 .label
= "share backend",
1048 .p_class
= P_GLOBAL
,
1049 .offset
= GLOBAL_VAR(szShareBackend
),
1056 .p_class
= P_GLOBAL
,
1057 .offset
= GLOBAL_VAR(szAutoServices
),
1062 .label
= "auto services",
1064 .p_class
= P_GLOBAL
,
1065 .offset
= GLOBAL_VAR(szAutoServices
),
1070 .label
= "lock dir",
1072 .p_class
= P_GLOBAL
,
1073 .offset
= GLOBAL_VAR(szLockDir
),
1078 .label
= "lock directory",
1080 .p_class
= P_GLOBAL
,
1081 .offset
= GLOBAL_VAR(szLockDir
),
1086 .label
= "state directory",
1088 .p_class
= P_GLOBAL
,
1089 .offset
= GLOBAL_VAR(szStateDir
),
1094 .label
= "cache directory",
1096 .p_class
= P_GLOBAL
,
1097 .offset
= GLOBAL_VAR(szCacheDir
),
1102 .label
= "pid directory",
1104 .p_class
= P_GLOBAL
,
1105 .offset
= GLOBAL_VAR(szPidDir
),
1111 .label
= "socket address",
1113 .p_class
= P_GLOBAL
,
1114 .offset
= GLOBAL_VAR(szSocketAddress
),
1122 .offset
= LOCAL_VAR(szCopy
),
1123 .special
= handle_copy
,
1130 .offset
= LOCAL_VAR(szInclude
),
1131 .special
= handle_include
,
1136 .label
= "available",
1139 .offset
= LOCAL_VAR(bAvailable
),
1147 .offset
= LOCAL_VAR(volume
),
1155 .offset
= LOCAL_VAR(fstype
),
1161 .label
= "panic action",
1163 .p_class
= P_GLOBAL
,
1164 .offset
= GLOBAL_VAR(panic_action
),
1170 .label
= "msdfs root",
1173 .offset
= LOCAL_VAR(bMSDfsRoot
),
1178 .label
= "host msdfs",
1180 .p_class
= P_GLOBAL
,
1181 .offset
= GLOBAL_VAR(bHostMSDfs
),
1186 .label
= "winbind separator",
1188 .p_class
= P_GLOBAL
,
1189 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1194 .label
= "winbindd socket directory",
1196 .p_class
= P_GLOBAL
,
1197 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1202 .label
= "winbindd privileged socket directory",
1204 .p_class
= P_GLOBAL
,
1205 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1210 .label
= "winbind sealed pipes",
1212 .p_class
= P_GLOBAL
,
1213 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1218 .label
= "template shell",
1220 .p_class
= P_GLOBAL
,
1221 .offset
= GLOBAL_VAR(szTemplateShell
),
1226 .label
= "template homedir",
1228 .p_class
= P_GLOBAL
,
1229 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1234 .label
= "idmap trusted only",
1236 .p_class
= P_GLOBAL
,
1237 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1243 .label
= "ntp signd socket directory",
1245 .p_class
= P_GLOBAL
,
1246 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1251 .label
= "rndc command",
1253 .p_class
= P_GLOBAL
,
1254 .offset
= GLOBAL_VAR(szRNDCCommand
),
1259 .label
= "dns update command",
1261 .p_class
= P_GLOBAL
,
1262 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1267 .label
= "spn update command",
1269 .p_class
= P_GLOBAL
,
1270 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1275 .label
= "nsupdate command",
1277 .p_class
= P_GLOBAL
,
1278 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1283 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1287 /* local variables */
1288 struct loadparm_context
{
1289 const char *szConfigFile
;
1290 struct loadparm_global
*globals
;
1291 struct loadparm_service
**services
;
1292 struct loadparm_service
*sDefault
;
1293 struct smb_iconv_handle
*iconv_handle
;
1295 struct loadparm_service
*currentService
;
1296 bool bInGlobalSection
;
1298 struct file_lists
*next
;
1303 unsigned int flags
[NUMPARAMETERS
];
1306 bool global
; /* Is this the global context, which may set
1307 * global variables such as debug level etc? */
1308 const struct loadparm_s3_context
*s3_fns
;
1312 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1314 if (lp_ctx
->s3_fns
) {
1315 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1317 return lp_ctx
->sDefault
;
1321 * Convenience routine to grab string parameters into temporary memory
1322 * and run standard_sub_basic on them.
1324 * The buffers can be written to by
1325 * callers without affecting the source string.
1328 static const char *lp_string(const char *s
)
1330 #if 0 /* until REWRITE done to make thread-safe */
1331 size_t len
= s
? strlen(s
) : 0;
1335 /* The follow debug is useful for tracking down memory problems
1336 especially if you have an inner loop that is calling a lp_*()
1337 function that returns a string. Perhaps this debug should be
1338 present all the time? */
1341 DEBUG(10, ("lp_string(%s)\n", s
));
1344 #if 0 /* until REWRITE done to make thread-safe */
1346 lp_talloc
= talloc_init("lp_talloc");
1348 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1356 strlcpy(ret
, s
, len
);
1358 if (trim_string(ret
, "\"", "\"")) {
1359 if (strchr(ret
,'"') != NULL
)
1360 strlcpy(ret
, s
, len
);
1363 standard_sub_basic(ret
,len
+100);
1370 In this section all the functions that are used to access the
1371 parameters from the rest of the program are defined
1375 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1376 * for code compatibility between existing Samba4 and Samba3 code.
1379 /* this global context supports the lp_*() function varients */
1380 static struct loadparm_context
*global_loadparm_context
;
1382 #define lpcfg_default_service global_loadparm_context->sDefault
1383 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1385 #define FN_GLOBAL_STRING(fn_name,var_name) \
1386 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1387 if (lp_ctx == NULL) return NULL; \
1388 if (lp_ctx->s3_fns) { \
1389 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1390 return lp_ctx->s3_fns->fn_name(); \
1392 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1395 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1396 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1397 if (lp_ctx == NULL) return NULL; \
1398 if (lp_ctx->s3_fns) { \
1399 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1400 return lp_ctx->s3_fns->fn_name(); \
1402 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1405 #define FN_GLOBAL_LIST(fn_name,var_name) \
1406 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1407 if (lp_ctx == NULL) return NULL; \
1408 if (lp_ctx->s3_fns) { \
1409 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1410 return lp_ctx->s3_fns->fn_name(); \
1412 return lp_ctx->globals->var_name; \
1415 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1416 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1417 if (lp_ctx == NULL) return false; \
1418 if (lp_ctx->s3_fns) { \
1419 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1420 return lp_ctx->s3_fns->fn_name(); \
1422 return lp_ctx->globals->var_name; \
1425 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1426 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1427 if (lp_ctx->s3_fns) { \
1428 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1429 return lp_ctx->s3_fns->fn_name(); \
1431 return lp_ctx->globals->var_name; \
1434 /* Local parameters don't need the ->s3_fns because the struct
1435 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1437 #define FN_LOCAL_STRING(fn_name,val) \
1438 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1439 struct loadparm_service *sDefault) { \
1440 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1443 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1445 #define FN_LOCAL_LIST(fn_name,val) \
1446 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1447 struct loadparm_service *sDefault) {\
1448 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1451 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1453 #define FN_LOCAL_BOOL(fn_name,val) \
1454 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1455 struct loadparm_service *sDefault) { \
1456 return((service != NULL)? service->val : sDefault->val); \
1459 #define FN_LOCAL_INTEGER(fn_name,val) \
1460 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1461 struct loadparm_service *sDefault) { \
1462 return((service != NULL)? service->val : sDefault->val); \
1465 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1467 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1469 #define FN_LOCAL_CHAR(fn_name,val) \
1470 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1471 struct loadparm_service *sDefault) { \
1472 return((service != NULL)? service->val : sDefault->val); \
1475 #include "lib/param/param_functions.c"
1477 FN_GLOBAL_INTEGER(server_role
, server_role
)
1478 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
1479 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
1480 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
1481 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
1482 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
1483 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
1484 FN_GLOBAL_INTEGER(web_port
, web_port
)
1485 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
1486 FN_GLOBAL_STRING(logfile
, logfile
)
1487 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
1488 FN_GLOBAL_STRING(spoolss_url
, szSPOOLSS_URL
)
1489 FN_GLOBAL_STRING(wins_config_url
, szWINS_CONFIG_URL
)
1490 FN_GLOBAL_STRING(wins_url
, szWINS_URL
)
1491 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
1492 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
1493 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
1494 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
1495 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
1496 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
1497 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
1498 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
1499 FN_GLOBAL_STRING(serverstring
, szServerString
)
1500 FN_GLOBAL_STRING(lockdir
, szLockDir
)
1501 FN_GLOBAL_STRING(statedir
, szStateDir
)
1502 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1503 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
1504 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
1505 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
1506 FN_GLOBAL_STRING(piddir
, szPidDir
)
1507 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
1508 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
1509 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
1510 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
1511 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
1512 FN_GLOBAL_LIST(server_services
, server_services
)
1513 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
1514 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
1515 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
1516 FN_GLOBAL_LIST(passwordserver
, szPasswordServers
)
1517 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
1518 FN_GLOBAL_STRING(realm
, szRealm_upper
)
1519 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
1520 FN_GLOBAL_STRING(socket_options
, socket_options
)
1521 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
1522 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
1523 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
1524 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
1525 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
1526 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1527 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
1528 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
1529 FN_GLOBAL_BOOL(we_are_a_wins_server
, bWINSsupport
)
1530 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
1531 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
1532 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
1533 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1534 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
1535 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1536 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
1537 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
1538 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
1539 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
1540 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
1541 FN_GLOBAL_BOOL(unicode
, bUnicode
)
1542 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
1543 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
1544 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
1545 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
1546 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
1547 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
1548 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
1549 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
1550 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
1551 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
1552 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
1553 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
1554 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
1555 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
1556 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
1557 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
1558 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
1559 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
1560 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
1561 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
1562 FN_GLOBAL_INTEGER(security
, security
)
1563 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
1565 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
1566 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
1568 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
1570 /* local prototypes */
1571 static int map_parameter(const char *pszParmName
);
1572 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1573 const char *pszServiceName
);
1574 static void copy_service(struct loadparm_service
*pserviceDest
,
1575 struct loadparm_service
*pserviceSource
,
1576 struct bitmap
*pcopymapDest
);
1577 static bool service_ok(struct loadparm_service
*service
);
1578 static bool do_section(const char *pszSectionName
, void *);
1579 static void init_copymap(struct loadparm_service
*pservice
);
1581 /* This is a helper function for parametrical options support. */
1582 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1583 /* Actual parametrical functions are quite simple */
1584 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1585 struct loadparm_service
*service
,
1586 const char *type
, const char *option
)
1588 char *vfskey_tmp
= NULL
;
1589 char *vfskey
= NULL
;
1590 struct parmlist_entry
*data
;
1595 if (lp_ctx
->s3_fns
) {
1596 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1599 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1601 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1602 if (vfskey_tmp
== NULL
) return NULL
;
1603 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1604 talloc_free(vfskey_tmp
);
1607 if (strcmp(data
->key
, vfskey
) == 0) {
1608 talloc_free(vfskey
);
1614 if (service
!= NULL
) {
1615 /* Try to fetch the same option but from globals */
1616 /* but only if we are not already working with globals */
1617 for (data
= lp_ctx
->globals
->param_opt
; data
;
1618 data
= data
->next
) {
1619 if (strcmp(data
->key
, vfskey
) == 0) {
1620 talloc_free(vfskey
);
1626 talloc_free(vfskey
);
1633 * convenience routine to return int parameters.
1635 static int lp_int(const char *s
)
1639 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1643 return strtol(s
, NULL
, 0);
1647 * convenience routine to return unsigned long parameters.
1649 static int lp_ulong(const char *s
)
1653 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1657 return strtoul(s
, NULL
, 0);
1661 * convenience routine to return unsigned long parameters.
1663 static double lp_double(const char *s
)
1667 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1671 return strtod(s
, NULL
);
1675 * convenience routine to return boolean parameters.
1677 static bool lp_bool(const char *s
)
1682 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1686 if (!set_boolean(s
, &ret
)) {
1687 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1696 * Return parametric option from a given service. Type is a part of option before ':'
1697 * Parametric option has following syntax: 'Type: option = value'
1698 * Returned value is allocated in 'lp_talloc' context
1701 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1702 struct loadparm_service
*service
, const char *type
,
1705 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1708 return lp_string(value
);
1714 * Return parametric option from a given service. Type is a part of option before ':'
1715 * Parametric option has following syntax: 'Type: option = value'
1716 * Returned value is allocated in 'lp_talloc' context
1719 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1720 struct loadparm_context
*lp_ctx
,
1721 struct loadparm_service
*service
,
1723 const char *option
, const char *separator
)
1725 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1728 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1734 * Return parametric option from a given service. Type is a part of option before ':'
1735 * Parametric option has following syntax: 'Type: option = value'
1738 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1739 struct loadparm_service
*service
, const char *type
,
1740 const char *option
, int default_v
)
1742 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1745 return lp_int(value
);
1751 * Return parametric option from a given service. Type is a part of
1752 * option before ':'.
1753 * Parametric option has following syntax: 'Type: option = value'.
1756 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1757 struct loadparm_service
*service
, const char *type
,
1758 const char *option
, int default_v
)
1762 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1764 if (value
&& conv_str_size_error(value
, &bval
)) {
1765 if (bval
<= INT_MAX
) {
1774 * Return parametric option from a given service.
1775 * Type is a part of option before ':'
1776 * Parametric option has following syntax: 'Type: option = value'
1778 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1779 struct loadparm_service
*service
, const char *type
,
1780 const char *option
, unsigned long default_v
)
1782 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1785 return lp_ulong(value
);
1791 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1792 struct loadparm_service
*service
, const char *type
,
1793 const char *option
, double default_v
)
1795 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1798 return lp_double(value
);
1804 * Return parametric option from a given service. Type is a part of option before ':'
1805 * Parametric option has following syntax: 'Type: option = value'
1808 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1809 struct loadparm_service
*service
, const char *type
,
1810 const char *option
, bool default_v
)
1812 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1815 return lp_bool(value
);
1822 * Initialise a service to the defaults.
1825 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1827 struct loadparm_service
*pservice
=
1828 talloc_zero(mem_ctx
, struct loadparm_service
);
1829 copy_service(pservice
, sDefault
, NULL
);
1834 * Set a string value, deallocating any existing space, and allocing the space
1837 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1844 *dest
= talloc_strdup(mem_ctx
, src
);
1845 if ((*dest
) == NULL
) {
1846 DEBUG(0,("Out of memory in string_set\n"));
1854 * Set a string value, deallocating any existing space, and allocing the space
1857 static bool string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1864 *dest
= strupper_talloc(mem_ctx
, src
);
1865 if ((*dest
) == NULL
) {
1866 DEBUG(0,("Out of memory in string_set_upper\n"));
1876 * Add a new service to the services array initialising it with the given
1880 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1881 const struct loadparm_service
*pservice
,
1885 struct loadparm_service tservice
;
1886 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1887 struct parmlist_entry
*data
, *pdata
;
1889 if (pservice
== NULL
) {
1890 pservice
= lp_ctx
->sDefault
;
1893 tservice
= *pservice
;
1895 /* it might already exist */
1897 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1899 if (service
!= NULL
) {
1900 /* Clean all parametric options for service */
1901 /* They will be added during parsing again */
1902 data
= service
->param_opt
;
1908 service
->param_opt
= NULL
;
1913 /* find an invalid one */
1914 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1915 if (lp_ctx
->services
[i
] == NULL
)
1918 /* if not, then create one */
1919 if (i
== lp_ctx
->iNumServices
) {
1920 struct loadparm_service
**tsp
;
1922 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1925 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1928 lp_ctx
->services
= tsp
;
1929 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1932 lp_ctx
->iNumServices
++;
1935 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1936 if (lp_ctx
->services
[i
] == NULL
) {
1937 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1940 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1942 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1943 return lp_ctx
->services
[i
];
1947 * Add a new home service, with the specified home directory, defaults coming
1948 * from service ifrom.
1951 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
1952 const char *pszHomename
,
1953 struct loadparm_service
*default_service
,
1954 const char *user
, const char *pszHomedir
)
1956 struct loadparm_service
*service
;
1958 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
1960 if (service
== NULL
)
1963 if (!(*(default_service
->szPath
))
1964 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1965 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1967 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1970 if (!(*(service
->comment
))) {
1971 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1973 service
->bAvailable
= default_service
->bAvailable
;
1974 service
->bBrowseable
= default_service
->bBrowseable
;
1976 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1977 pszHomename
, user
, service
->szPath
));
1983 * Add a new printer service, with defaults coming from service iFrom.
1986 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
1987 const char *pszPrintername
,
1988 struct loadparm_service
*default_service
)
1990 const char *comment
= "From Printcap";
1991 struct loadparm_service
*service
;
1992 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
1994 if (service
== NULL
)
1997 /* note that we do NOT default the availability flag to True - */
1998 /* we take it from the default service passed. This allows all */
1999 /* dynamic printers to be disabled by disabling the [printers] */
2000 /* entry (if/when the 'available' keyword is implemented!). */
2002 /* the printer name is set to the service name. */
2003 string_set(service
, &service
->szPrintername
, pszPrintername
);
2004 string_set(service
, &service
->comment
, comment
);
2005 service
->bBrowseable
= default_service
->bBrowseable
;
2006 /* Printers cannot be read_only. */
2007 service
->bRead_only
= false;
2008 /* Printer services must be printable. */
2009 service
->bPrint_ok
= true;
2011 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
2017 * Map a parameter's string representation to something we can use.
2018 * Returns False if the parameter string is not recognised, else TRUE.
2021 static int map_parameter(const char *pszParmName
)
2025 if (*pszParmName
== '-')
2028 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2029 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
2032 /* Warn only if it isn't parametric option */
2033 if (strchr(pszParmName
, ':') == NULL
)
2034 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
2035 /* We do return 'fail' for parametric options as well because they are
2036 stored in different storage
2043 return the parameter structure for a parameter
2045 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
2049 if (lp_ctx
->s3_fns
) {
2050 return lp_ctx
->s3_fns
->get_parm_struct(name
);
2053 parmnum
= map_parameter(name
);
2054 if (parmnum
== -1) return NULL
;
2055 return &parm_table
[parmnum
];
2059 return the parameter pointer for a parameter
2061 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2062 struct loadparm_service
*service
, struct parm_struct
*parm
)
2064 if (lp_ctx
->s3_fns
) {
2065 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2068 if (service
== NULL
) {
2069 if (parm
->p_class
== P_LOCAL
)
2070 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2071 else if (parm
->p_class
== P_GLOBAL
)
2072 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2075 return ((char *)service
) + parm
->offset
;
2080 * Find a service by name. Otherwise works like get_service.
2083 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2084 const char *pszServiceName
)
2088 if (lp_ctx
->s3_fns
) {
2089 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2092 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2093 if (lp_ctx
->services
[iService
] != NULL
&&
2094 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2095 return lp_ctx
->services
[iService
];
2102 * Copy a service structure to another.
2103 * If pcopymapDest is NULL then copy all fields
2106 static void copy_service(struct loadparm_service
*pserviceDest
,
2107 struct loadparm_service
*pserviceSource
,
2108 struct bitmap
*pcopymapDest
)
2111 bool bcopyall
= (pcopymapDest
== NULL
);
2112 struct parmlist_entry
*data
, *pdata
, *paramo
;
2115 for (i
= 0; parm_table
[i
].label
; i
++)
2116 if (parm_table
[i
].p_class
== P_LOCAL
&&
2117 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2119 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2121 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2123 switch (parm_table
[i
].type
) {
2125 *(int *)dest_ptr
= *(int *)src_ptr
;
2131 *(int *)dest_ptr
= *(int *)src_ptr
;
2135 string_set(pserviceDest
,
2141 string_set_upper(pserviceDest
,
2146 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2147 *(const char ***)src_ptr
);
2155 init_copymap(pserviceDest
);
2156 if (pserviceSource
->copymap
)
2157 bitmap_copy(pserviceDest
->copymap
,
2158 pserviceSource
->copymap
);
2161 data
= pserviceSource
->param_opt
;
2164 pdata
= pserviceDest
->param_opt
;
2165 /* Traverse destination */
2167 /* If we already have same option, override it */
2168 if (strcmp(pdata
->key
, data
->key
) == 0) {
2169 talloc_free(pdata
->value
);
2170 pdata
->value
= talloc_reference(pdata
,
2175 pdata
= pdata
->next
;
2178 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2181 paramo
->key
= talloc_reference(paramo
, data
->key
);
2182 paramo
->value
= talloc_reference(paramo
, data
->value
);
2183 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2190 * Check a service for consistency. Return False if the service is in any way
2191 * incomplete or faulty, else True.
2193 static bool service_ok(struct loadparm_service
*service
)
2198 if (service
->szService
[0] == '\0') {
2199 DEBUG(0, ("The following message indicates an internal error:\n"));
2200 DEBUG(0, ("No service name in service entry.\n"));
2204 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2205 /* I can't see why you'd want a non-printable printer service... */
2206 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2207 if (!service
->bPrint_ok
) {
2208 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2209 service
->szService
));
2210 service
->bPrint_ok
= true;
2212 /* [printers] service must also be non-browsable. */
2213 if (service
->bBrowseable
)
2214 service
->bBrowseable
= false;
2217 /* If a service is flagged unavailable, log the fact at level 0. */
2218 if (!service
->bAvailable
)
2219 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2220 service
->szService
));
2226 /*******************************************************************
2227 Keep a linked list of all config files so we know when one has changed
2228 it's date and needs to be reloaded.
2229 ********************************************************************/
2231 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2232 const char *fname
, const char *subfname
)
2234 struct file_lists
*f
= lp_ctx
->file_lists
;
2237 if (f
->name
&& !strcmp(f
->name
, fname
))
2243 f
= talloc(lp_ctx
, struct file_lists
);
2246 f
->next
= lp_ctx
->file_lists
;
2247 f
->name
= talloc_strdup(f
, fname
);
2252 f
->subfname
= talloc_strdup(f
, subfname
);
2257 lp_ctx
->file_lists
= f
;
2258 f
->modtime
= file_modtime(subfname
);
2260 time_t t
= file_modtime(subfname
);
2266 /*******************************************************************
2267 Check if a config file has changed date.
2268 ********************************************************************/
2269 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2271 struct file_lists
*f
;
2272 DEBUG(6, ("lp_file_list_changed()\n"));
2274 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2278 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2280 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2281 f
->name
, n2
, ctime(&f
->modtime
)));
2283 mod_time
= file_modtime(n2
);
2285 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2286 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2288 f
->modtime
= mod_time
;
2289 talloc_free(f
->subfname
);
2290 f
->subfname
= talloc_strdup(f
, n2
);
2297 /***************************************************************************
2298 Handle the "realm" parameter
2299 ***************************************************************************/
2301 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2302 const char *pszParmValue
, char **ptr
)
2304 string_set(lp_ctx
, ptr
, pszParmValue
);
2306 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2307 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2309 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2310 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2315 /***************************************************************************
2316 Handle the include operation.
2317 ***************************************************************************/
2319 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2320 const char *pszParmValue
, char **ptr
)
2322 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2324 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2326 string_set(lp_ctx
, ptr
, fname
);
2328 if (file_exist(fname
))
2329 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2331 DEBUG(2, ("Can't find include file %s\n", fname
));
2336 /***************************************************************************
2337 Handle the interpretation of the copy parameter.
2338 ***************************************************************************/
2340 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2341 const char *pszParmValue
, char **ptr
)
2344 struct loadparm_service
*serviceTemp
;
2346 string_set(lp_ctx
, ptr
, pszParmValue
);
2350 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2352 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2353 if (serviceTemp
== lp_ctx
->currentService
) {
2354 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2356 copy_service(lp_ctx
->currentService
,
2358 lp_ctx
->currentService
->copymap
);
2362 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2370 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2371 const char *pszParmValue
, char **ptr
)
2374 string_set(lp_ctx
, ptr
, pszParmValue
);
2375 if (lp_ctx
->global
) {
2376 return debug_parse_levels(pszParmValue
);
2381 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2382 const char *pszParmValue
, char **ptr
)
2384 debug_set_logfile(pszParmValue
);
2385 if (lp_ctx
->global
) {
2386 string_set(lp_ctx
, ptr
, pszParmValue
);
2391 /***************************************************************************
2392 Initialise a copymap.
2393 ***************************************************************************/
2395 static void init_copymap(struct loadparm_service
*pservice
)
2399 TALLOC_FREE(pservice
->copymap
);
2401 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2402 if (!pservice
->copymap
)
2404 ("Couldn't allocate copymap!! (size %d)\n",
2405 (int)NUMPARAMETERS
));
2407 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2408 bitmap_set(pservice
->copymap
, i
);
2412 * Process a parametric option
2414 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2415 struct loadparm_service
*service
,
2416 const char *pszParmName
,
2417 const char *pszParmValue
, int flags
)
2419 struct parmlist_entry
*paramo
, *data
;
2421 TALLOC_CTX
*mem_ctx
;
2423 while (isspace((unsigned char)*pszParmName
)) {
2427 name
= strlower_talloc(lp_ctx
, pszParmName
);
2428 if (!name
) return false;
2430 if (service
== NULL
) {
2431 data
= lp_ctx
->globals
->param_opt
;
2432 mem_ctx
= lp_ctx
->globals
;
2434 data
= service
->param_opt
;
2438 /* Traverse destination */
2439 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2440 /* If we already have the option set, override it unless
2441 it was a command line option and the new one isn't */
2442 if (strcmp(paramo
->key
, name
) == 0) {
2443 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2444 !(flags
& FLAG_CMDLINE
)) {
2449 talloc_free(paramo
->value
);
2450 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2451 paramo
->priority
= flags
;
2457 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2460 paramo
->key
= talloc_strdup(paramo
, name
);
2461 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2462 paramo
->priority
= flags
;
2463 if (service
== NULL
) {
2464 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2466 DLIST_ADD(service
->param_opt
, paramo
);
2474 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2475 const char *pszParmName
, const char *pszParmValue
,
2476 struct loadparm_context
*lp_ctx
, bool on_globals
)
2479 /* if it is a special case then go ahead */
2480 if (parm_table
[parmnum
].special
) {
2482 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2487 goto mark_non_default
;
2490 /* now switch on the type of variable it is */
2491 switch (parm_table
[parmnum
].type
)
2495 if (!set_boolean(pszParmValue
, &b
)) {
2496 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2499 *(int *)parm_ptr
= b
;
2505 if (!set_boolean(pszParmValue
, &b
)) {
2506 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2509 *(int *)parm_ptr
= !b
;
2514 *(int *)parm_ptr
= atoi(pszParmValue
);
2518 *(char *)parm_ptr
= *pszParmValue
;
2522 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2528 if (conv_str_size_error(pszParmValue
, &val
)) {
2529 if (val
<= INT_MAX
) {
2530 *(int *)parm_ptr
= (int)val
;
2535 DEBUG(0,("lp_do_parameter(%s): value is not "
2536 "a valid size specifier!\n", pszParmValue
));
2541 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2542 pszParmValue
, NULL
);
2546 char **new_list
= str_list_make(mem_ctx
,
2547 pszParmValue
, NULL
);
2548 for (i
=0; new_list
[i
]; i
++) {
2549 if (new_list
[i
][0] == '+' && new_list
[i
][1] &&
2550 (!str_list_check(*(const char ***)parm_ptr
,
2551 &new_list
[i
][1]))) {
2552 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2554 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2555 #if 0 /* This is commented out because we sometimes parse the list
2556 * twice, and so we can't assert on this */
2557 if (!str_list_check(*(const char ***)parm_ptr
,
2559 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2560 pszParmName
, pszParmValue
, new_list
[i
],
2561 str_list_join_shell(mem_ctx
, *(const char ***)parm_ptr
, ' ')));
2566 str_list_remove(*(const char ***)parm_ptr
,
2570 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2571 pszParmName
, pszParmValue
));
2574 *(const char ***)parm_ptr
= (const char **) new_list
;
2581 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2585 string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2589 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2592 parm_table
[parmnum
].enum_list
[i
].name
)) {
2594 parm_table
[parmnum
].
2599 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2600 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2601 pszParmValue
, pszParmName
));
2608 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2609 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2610 /* we have to also unset FLAG_DEFAULT on aliases */
2611 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2612 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2614 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2615 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2622 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2623 const char *pszParmName
, const char *pszParmValue
)
2625 int parmnum
= map_parameter(pszParmName
);
2629 if (strchr(pszParmName
, ':')) {
2630 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2632 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2636 /* if the flag has been set on the command line, then don't allow override,
2637 but don't report an error */
2638 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2642 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2644 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2645 pszParmName
, pszParmValue
, lp_ctx
, true);
2648 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2649 struct loadparm_service
*service
,
2650 const char *pszParmName
, const char *pszParmValue
)
2654 int parmnum
= map_parameter(pszParmName
);
2657 if (strchr(pszParmName
, ':')) {
2658 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2660 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2664 /* if the flag has been set on the command line, then don't allow override,
2665 but don't report an error */
2666 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2670 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2672 ("Global parameter %s found in service section!\n",
2676 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2678 if (!service
->copymap
)
2679 init_copymap(service
);
2681 /* this handles the aliases - set the copymap for other
2682 * entries with the same data pointer */
2683 for (i
= 0; parm_table
[i
].label
; i
++)
2684 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2685 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2686 bitmap_clear(service
->copymap
, i
);
2688 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2689 pszParmValue
, lp_ctx
, false);
2693 * Process a parameter.
2696 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2699 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2701 if (lp_ctx
->bInGlobalSection
)
2702 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2705 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2706 pszParmName
, pszParmValue
);
2710 variable argument do parameter
2712 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2713 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2714 const char *pszParmName
, const char *fmt
, ...)
2721 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2723 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2730 set a parameter from the commandline - this is called from command line parameter
2731 parsing code. It sets the parameter then marks the parameter as unable to be modified
2732 by smb.conf processing
2734 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2735 const char *pszParmValue
)
2740 if (lp_ctx
->s3_fns
) {
2741 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2744 parmnum
= map_parameter(pszParmName
);
2746 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2749 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2750 /* set a parametric option */
2751 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2752 pszParmValue
, FLAG_CMDLINE
);
2756 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2760 /* reset the CMDLINE flag in case this has been called before */
2761 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2763 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2767 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2769 /* we have to also set FLAG_CMDLINE on aliases */
2770 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2771 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2773 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2774 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2781 set a option from the commandline in 'a=b' format. Use to support --option
2783 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2801 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2807 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2810 * Print a parameter of the specified type.
2813 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2816 const char *list_sep
= ", "; /* For the seperation of lists values that we print below */
2820 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2821 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2823 p
->enum_list
[i
].name
);
2830 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
2834 fprintf(f
, "%s", BOOLSTR(!(bool)*(int *)ptr
));
2839 fprintf(f
, "%d", *(int *)ptr
);
2843 fprintf(f
, "%c", *(char *)ptr
);
2847 fprintf(f
, "0%o", *(int *)ptr
);
2854 if ((char ***)ptr
&& *(char ***)ptr
) {
2855 char **list
= *(char ***)ptr
;
2857 for (; *list
; list
++) {
2858 if (*(list
+1) == NULL
) {
2859 /* last item, print no extra seperator after */
2862 fprintf(f
, "%s%s", *list
, list_sep
);
2869 if (*(char **)ptr
) {
2870 fprintf(f
, "%s", *(char **)ptr
);
2877 * Check if two parameters are equal.
2880 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2885 return (*((int *)ptr1
) == *((int *)ptr2
));
2891 return (*((int *)ptr1
) == *((int *)ptr2
));
2894 return (*((char *)ptr1
) == *((char *)ptr2
));
2898 return str_list_equal((const char **)(*(char ***)ptr1
),
2899 (const char **)(*(char ***)ptr2
));
2904 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2909 return (p1
== p2
|| strequal(p1
, p2
));
2916 * Process a new section (service).
2918 * At this stage all sections are services.
2919 * Later we'll have special sections that permit server parameters to be set.
2920 * Returns True on success, False on failure.
2923 static bool do_section(const char *pszSectionName
, void *userdata
)
2925 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2927 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2928 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2931 /* if we've just struck a global section, note the fact. */
2932 lp_ctx
->bInGlobalSection
= isglobal
;
2934 /* check for multiple global sections */
2935 if (lp_ctx
->bInGlobalSection
) {
2936 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2940 /* if we have a current service, tidy it up before moving on */
2943 if (lp_ctx
->currentService
!= NULL
)
2944 bRetval
= service_ok(lp_ctx
->currentService
);
2946 /* if all is still well, move to the next record in the services array */
2948 /* We put this here to avoid an odd message order if messages are */
2949 /* issued by the post-processing of a previous section. */
2950 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2952 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2955 DEBUG(0, ("Failed to add a new service\n"));
2965 * Determine if a particular base parameter is currently set to the default value.
2968 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2970 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2971 if (!defaults_saved
)
2973 switch (parm_table
[i
].type
) {
2976 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2977 (const char **)def_ptr
);
2980 return strequal(parm_table
[i
].def
.svalue
,
2984 return parm_table
[i
].def
.bvalue
==
2991 return parm_table
[i
].def
.ivalue
==
2998 *Display the contents of the global structure.
3001 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
3005 struct parmlist_entry
*data
;
3007 fprintf(f
, "# Global parameters\n[global]\n");
3009 for (i
= 0; parm_table
[i
].label
; i
++)
3010 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3011 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3012 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
3014 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3015 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
3018 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3019 for (data
= lp_ctx
->globals
->param_opt
; data
;
3020 data
= data
->next
) {
3021 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3024 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3031 * Display the contents of a single services record.
3034 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3035 unsigned int *flags
)
3038 struct parmlist_entry
*data
;
3040 if (pService
!= sDefault
)
3041 fprintf(f
, "\n[%s]\n", pService
->szService
);
3043 for (i
= 0; parm_table
[i
].label
; i
++) {
3044 if (parm_table
[i
].p_class
== P_LOCAL
&&
3045 (*parm_table
[i
].label
!= '-') &&
3046 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3048 if (pService
== sDefault
) {
3049 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3052 if (defaults_saved
) {
3053 if (is_default(sDefault
, i
)) {
3058 if (equal_parameter(parm_table
[i
].type
,
3059 ((char *)pService
) +
3060 parm_table
[i
].offset
,
3061 ((char *)sDefault
) +
3062 parm_table
[i
].offset
))
3066 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3067 print_parameter(&parm_table
[i
],
3068 ((char *)pService
) + parm_table
[i
].offset
, f
);
3072 if (pService
->param_opt
!= NULL
) {
3073 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3074 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3079 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3080 struct loadparm_service
*service
,
3081 const char *parm_name
, FILE * f
)
3083 struct parm_struct
*parm
;
3086 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3091 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3093 print_parameter(parm
, ptr
, f
);
3099 * Return info about the next parameter in a service.
3100 * snum==-1 gives the globals.
3101 * Return NULL when out of parameters.
3105 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3109 /* do the globals */
3110 for (; parm_table
[*i
].label
; (*i
)++) {
3111 if ((*parm_table
[*i
].label
== '-'))
3115 && (parm_table
[*i
].offset
==
3116 parm_table
[(*i
) - 1].offset
)
3117 && (parm_table
[*i
].p_class
==
3118 parm_table
[(*i
) - 1].p_class
))
3121 return &parm_table
[(*i
)++];
3124 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3126 for (; parm_table
[*i
].label
; (*i
)++) {
3127 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3128 (*parm_table
[*i
].label
!= '-') &&
3130 (parm_table
[*i
].offset
!=
3131 parm_table
[(*i
) - 1].offset
)))
3133 if (allparameters
||
3134 !equal_parameter(parm_table
[*i
].type
,
3135 ((char *)pService
) +
3136 parm_table
[*i
].offset
,
3137 ((char *)lp_ctx
->sDefault
) +
3138 parm_table
[*i
].offset
))
3140 return &parm_table
[(*i
)++];
3151 * Auto-load some home services.
3153 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3161 * Unload unused services.
3164 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3165 struct smbsrv_connection
*smb
,
3166 bool (*snumused
) (struct smbsrv_connection
*, int))
3169 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3170 if (lp_ctx
->services
[i
] == NULL
)
3173 if (!snumused
|| !snumused(smb
, i
)) {
3174 talloc_free(lp_ctx
->services
[i
]);
3175 lp_ctx
->services
[i
] = NULL
;
3181 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3183 struct parmlist_entry
*data
;
3185 if (lp_ctx
->refuse_free
) {
3186 /* someone is trying to free the
3187 global_loadparm_context.
3188 We can't allow that. */
3192 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3193 struct parmlist_entry
*next
;
3194 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3196 if (data
->priority
& FLAG_CMDLINE
) continue;
3197 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3206 * Initialise the global parameter structure.
3208 * Note that most callers should use loadparm_init_global() instead
3210 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3214 struct loadparm_context
*lp_ctx
;
3215 struct parmlist_entry
*parm
;
3218 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3222 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3223 lp_ctx
->bInGlobalSection
= true;
3224 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3225 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3227 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3228 lp_ctx
->sDefault
->bAvailable
= true;
3229 lp_ctx
->sDefault
->bBrowseable
= true;
3230 lp_ctx
->sDefault
->bRead_only
= true;
3231 lp_ctx
->sDefault
->bMap_archive
= true;
3232 lp_ctx
->sDefault
->iStrictLocking
= true;
3233 lp_ctx
->sDefault
->bOpLocks
= true;
3234 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3235 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3236 lp_ctx
->sDefault
->iDir_mask
= 0755;
3237 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3239 DEBUG(3, ("Initialising global parameters\n"));
3241 for (i
= 0; parm_table
[i
].label
; i
++) {
3242 if ((parm_table
[i
].type
== P_STRING
||
3243 parm_table
[i
].type
== P_USTRING
) &&
3244 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3246 if (parm_table
[i
].p_class
== P_LOCAL
) {
3247 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3249 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3251 *r
= talloc_strdup(lp_ctx
, "");
3255 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3256 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3257 talloc_free(logfile
);
3259 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3261 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3263 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3265 lpcfg_do_global_parameter(lp_ctx
, "server role", "standalone");
3267 /* options that can be set on the command line must be initialised via
3268 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3270 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3272 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3273 myname
= get_myname(lp_ctx
);
3274 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3275 talloc_free(myname
);
3276 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3278 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3280 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3281 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3283 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3284 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate web");
3285 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3286 /* the winbind method for domain controllers is for both RODC
3287 auth forwarding and for trusted domains */
3288 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3289 lpcfg_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
3290 lpcfg_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
3291 lpcfg_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
3292 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3294 /* This hive should be dynamically generated by Samba using
3295 data from the sam, but for the moment leave it in a tdb to
3296 keep regedt32 from popping up an annoying dialog. */
3297 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3299 /* using UTF8 by default allows us to support all chars */
3300 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3302 /* Use codepage 850 as a default for the dos character set */
3303 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3306 * Allow the default PASSWD_CHAT to be overridden in local.h.
3308 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3310 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3311 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3312 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3313 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3314 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3316 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3317 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3318 "Samba %s", SAMBA_VERSION_STRING
);
3320 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3322 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3323 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3324 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3325 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3326 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3327 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3328 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3329 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3330 lpcfg_do_global_parameter(lp_ctx
, "security", "USER");
3331 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3332 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3333 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3334 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3335 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3336 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3338 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3339 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3340 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3341 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3342 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3343 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3344 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3345 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3347 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3349 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3350 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3352 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3353 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3355 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3356 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3357 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3358 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3359 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3360 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3361 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3363 lpcfg_do_global_parameter(lp_ctx
, "client signing", "Yes");
3364 lpcfg_do_global_parameter(lp_ctx
, "server signing", "auto");
3366 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3368 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3369 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3370 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3371 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3372 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3373 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3374 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3376 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3378 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3379 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3381 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3382 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3383 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3384 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3385 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3387 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3388 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3389 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3390 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3391 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3393 for (i
= 0; parm_table
[i
].label
; i
++) {
3394 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3395 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3399 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3400 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3401 parm
->priority
|= FLAG_DEFAULT
;
3409 * Initialise the global parameter structure.
3411 struct loadparm_context
*loadparm_init_global(bool load_default
)
3413 if (global_loadparm_context
== NULL
) {
3414 global_loadparm_context
= loadparm_init(NULL
);
3416 if (global_loadparm_context
== NULL
) {
3419 global_loadparm_context
->global
= true;
3420 if (load_default
&& !global_loadparm_context
->loaded
) {
3421 lpcfg_load_default(global_loadparm_context
);
3423 global_loadparm_context
->refuse_free
= true;
3424 return global_loadparm_context
;
3428 * Initialise the global parameter structure.
3430 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3431 const struct loadparm_s3_context
*s3_fns
)
3433 struct loadparm_context
*loadparm_context
= loadparm_init(mem_ctx
);
3434 if (!loadparm_context
) {
3437 loadparm_context
->s3_fns
= s3_fns
;
3438 return loadparm_context
;
3441 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3443 return lp_ctx
->szConfigFile
;
3446 const char *lp_default_path(void)
3448 if (getenv("SMB_CONF_PATH"))
3449 return getenv("SMB_CONF_PATH");
3451 return dyn_CONFIGFILE
;
3455 * Update the internal state of a loadparm context after settings
3458 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3460 struct debug_settings settings
;
3461 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3463 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3464 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3467 if (!lp_ctx
->global
) {
3471 panic_action
= lp_ctx
->globals
->panic_action
;
3473 reload_charcnv(lp_ctx
);
3475 ZERO_STRUCT(settings
);
3476 /* Add any more debug-related smb.conf parameters created in
3478 settings
.timestamp_logs
= true;
3479 debug_set_settings(&settings
);
3481 /* FIXME: This is a bit of a hack, but we can't use a global, since
3482 * not everything that uses lp also uses the socket library */
3483 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3484 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3486 unsetenv("SOCKET_TESTNONBLOCK");
3492 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3496 path
= lp_default_path();
3498 if (!file_exist(path
)) {
3499 /* We allow the default smb.conf file to not exist,
3500 * basically the equivalent of an empty file. */
3501 return lpcfg_update(lp_ctx
);
3504 return lpcfg_load(lp_ctx
, path
);
3508 * Load the services array from the services file.
3510 * Return True on success, False on failure.
3512 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3517 filename
= talloc_strdup(lp_ctx
, filename
);
3519 lp_ctx
->szConfigFile
= filename
;
3521 lp_ctx
->bInGlobalSection
= true;
3522 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3523 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3525 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3527 /* We get sections first, so have to start 'behind' to make up */
3528 lp_ctx
->currentService
= NULL
;
3529 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3531 /* finish up the last section */
3532 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3534 if (lp_ctx
->currentService
!= NULL
)
3535 bRetval
= service_ok(lp_ctx
->currentService
);
3537 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3539 /* we do this unconditionally, so that it happens even
3540 for a missing smb.conf */
3541 reload_charcnv(lp_ctx
);
3543 if (bRetval
== true) {
3544 /* set this up so that any child python tasks will
3545 find the right smb.conf */
3546 setenv("SMB_CONF_PATH", filename
, 1);
3548 /* set the context used by the lp_*() function
3550 global_loadparm_context
= lp_ctx
;
3551 lp_ctx
->loaded
= true;
3558 * Return the max number of services.
3561 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3563 if (lp_ctx
->s3_fns
) {
3564 return lp_ctx
->s3_fns
->get_numservices();
3567 return lp_ctx
->iNumServices
;
3571 * Display the contents of the services array in human-readable form.
3574 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3579 defaults_saved
= !show_defaults
;
3581 dump_globals(lp_ctx
, f
, show_defaults
);
3583 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3585 for (iService
= 0; iService
< maxtoprint
; iService
++)
3586 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3590 * Display the contents of one service in human-readable form.
3592 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3594 if (service
!= NULL
) {
3595 if (service
->szService
[0] == '\0')
3597 dump_a_service(service
, sDefault
, f
, NULL
);
3601 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3604 if (lp_ctx
->s3_fns
) {
3605 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3608 return lp_ctx
->services
[snum
];
3611 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3612 const char *service_name
)
3617 if (lp_ctx
->s3_fns
) {
3618 return lp_ctx
->s3_fns
->get_service(service_name
);
3621 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3622 if (lp_ctx
->services
[iService
] &&
3623 lp_ctx
->services
[iService
]->szService
) {
3625 * The substitution here is used to support %U is
3628 serviceName
= standard_sub_basic(
3629 lp_ctx
->services
[iService
],
3630 lp_ctx
->services
[iService
]->szService
);
3631 if (strequal(serviceName
, service_name
)) {
3632 talloc_free(serviceName
);
3633 return lp_ctx
->services
[iService
];
3635 talloc_free(serviceName
);
3639 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3643 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3645 return lp_string((const char *)service
->szService
);
3649 * A useful volume label function.
3651 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3654 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3655 service
->volume
: sDefault
->volume
));
3657 return lpcfg_servicename(service
);
3662 * If we are PDC then prefer us as DMB
3664 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3667 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3668 service
->szPrintername
: sDefault
->szPrintername
));
3669 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3670 ret
= lpcfg_servicename(service
);
3677 * Return the max print jobs per queue.
3679 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3681 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3682 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3683 maxjobs
= PRINT_MAX_JOBID
- 1;
3688 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3690 if (lp_ctx
== NULL
) {
3691 return get_iconv_handle();
3693 return lp_ctx
->iconv_handle
;
3696 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3698 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3699 if (!lp_ctx
->global
) {
3703 if (old_ic
== NULL
) {
3704 old_ic
= global_iconv_handle
;
3706 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3707 global_iconv_handle
= lp_ctx
->iconv_handle
;
3710 void lpcfg_smbcli_options(struct loadparm_context
*lp_ctx
,
3711 struct smbcli_options
*options
)
3713 options
->max_xmit
= lpcfg_max_xmit(lp_ctx
);
3714 options
->max_mux
= lpcfg_maxmux(lp_ctx
);
3715 options
->use_spnego
= lpcfg_nt_status_support(lp_ctx
) && lpcfg_use_spnego(lp_ctx
);
3716 options
->signing
= lpcfg_client_signing(lp_ctx
);
3717 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
3718 options
->ntstatus_support
= lpcfg_nt_status_support(lp_ctx
);
3719 options
->max_protocol
= lpcfg_cli_maxprotocol(lp_ctx
);
3720 options
->unicode
= lpcfg_unicode(lp_ctx
);
3721 options
->use_oplocks
= true;
3722 options
->use_level2_oplocks
= true;
3725 void lpcfg_smbcli_session_options(struct loadparm_context
*lp_ctx
,
3726 struct smbcli_session_options
*options
)
3728 options
->lanman_auth
= lpcfg_client_lanman_auth(lp_ctx
);
3729 options
->ntlmv2_auth
= lpcfg_client_ntlmv2_auth(lp_ctx
);
3730 options
->plaintext_auth
= lpcfg_client_plaintext_auth(lp_ctx
);
3733 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3735 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3738 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3740 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3743 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3745 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3748 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3750 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3753 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3755 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3758 _PUBLIC_
struct dcerpc_server_info
*lpcfg_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3760 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
3762 ret
->domain_name
= talloc_reference(mem_ctx
, lpcfg_workgroup(lp_ctx
));
3763 ret
->version_major
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
3764 ret
->version_minor
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
3765 ret
->version_build
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
3770 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3772 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
3773 if (settings
== NULL
)
3775 SMB_ASSERT(lp_ctx
!= NULL
);
3776 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3777 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");