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_02
, "SMB2"},
109 {PROTOCOL_SMB2_02
, "SMB2_02"},
110 {PROTOCOL_NT1
, "NT1"},
111 {PROTOCOL_LANMAN2
, "LANMAN2"},
112 {PROTOCOL_LANMAN1
, "LANMAN1"},
113 {PROTOCOL_CORE
, "CORE"},
114 {PROTOCOL_COREPLUS
, "COREPLUS"},
115 {PROTOCOL_COREPLUS
, "CORE+"},
119 static const struct enum_list enum_security
[] = {
120 {SEC_SHARE
, "SHARE"},
126 static const struct enum_list enum_bool_auto
[] = {
137 /* Client-side offline caching policy types */
140 CSC_POLICY_DOCUMENTS
=1,
141 CSC_POLICY_PROGRAMS
=2,
145 static const struct enum_list enum_csc_policy
[] = {
146 {CSC_POLICY_MANUAL
, "manual"},
147 {CSC_POLICY_DOCUMENTS
, "documents"},
148 {CSC_POLICY_PROGRAMS
, "programs"},
149 {CSC_POLICY_DISABLE
, "disable"},
153 /* SMB signing types. */
154 static const struct enum_list enum_smb_signing_vals
[] = {
155 {SMB_SIGNING_OFF
, "No"},
156 {SMB_SIGNING_OFF
, "False"},
157 {SMB_SIGNING_OFF
, "0"},
158 {SMB_SIGNING_OFF
, "Off"},
159 {SMB_SIGNING_OFF
, "disabled"},
160 {SMB_SIGNING_SUPPORTED
, "Yes"},
161 {SMB_SIGNING_SUPPORTED
, "True"},
162 {SMB_SIGNING_SUPPORTED
, "1"},
163 {SMB_SIGNING_SUPPORTED
, "On"},
164 {SMB_SIGNING_SUPPORTED
, "enabled"},
165 {SMB_SIGNING_REQUIRED
, "required"},
166 {SMB_SIGNING_REQUIRED
, "mandatory"},
167 {SMB_SIGNING_REQUIRED
, "force"},
168 {SMB_SIGNING_REQUIRED
, "forced"},
169 {SMB_SIGNING_REQUIRED
, "enforced"},
170 {SMB_SIGNING_AUTO
, "auto"},
174 static const struct enum_list enum_server_role
[] = {
175 {ROLE_STANDALONE
, "standalone"},
176 {ROLE_DOMAIN_MEMBER
, "member server"},
177 {ROLE_DOMAIN_MEMBER
, "member"},
178 {ROLE_DOMAIN_CONTROLLER
, "domain controller"},
179 {ROLE_DOMAIN_CONTROLLER
, "dc"},
183 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
184 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
186 static struct parm_struct parm_table
[] = {
188 .label
= "server role",
191 .offset
= GLOBAL_VAR(server_role
),
193 .enum_list
= enum_server_role
196 .label
= "dos charset",
199 .offset
= GLOBAL_VAR(dos_charset
),
204 .label
= "unix charset",
207 .offset
= GLOBAL_VAR(unix_charset
),
212 .label
= "ncalrpc dir",
215 .offset
= GLOBAL_VAR(ncalrpc_dir
),
223 .offset
= LOCAL_VAR(comment
),
231 .offset
= LOCAL_VAR(szPath
),
236 .label
= "directory",
239 .offset
= LOCAL_VAR(szPath
),
244 .label
= "workgroup",
247 .offset
= GLOBAL_VAR(szWorkgroup
),
255 .offset
= GLOBAL_VAR(szRealm
),
256 .special
= handle_realm
,
260 .label
= "netbios name",
263 .offset
= GLOBAL_VAR(szNetbiosName
),
268 .label
= "netbios aliases",
271 .offset
= GLOBAL_VAR(szNetbiosAliases
),
276 .label
= "netbios scope",
279 .offset
= GLOBAL_VAR(szNetbiosScope
),
284 .label
= "server string",
287 .offset
= GLOBAL_VAR(szServerString
),
292 .label
= "interfaces",
295 .offset
= GLOBAL_VAR(szInterfaces
),
300 .label
= "bind interfaces only",
303 .offset
= GLOBAL_VAR(bBindInterfacesOnly
),
308 .label
= "ntvfs handler",
311 .offset
= LOCAL_VAR(ntvfs_handler
),
316 .label
= "ntptr providor",
319 .offset
= GLOBAL_VAR(ntptr_providor
),
324 .label
= "passdb backend",
327 .offset
= GLOBAL_VAR(passdb_backend
),
332 .label
= "dcerpc endpoint servers",
335 .offset
= GLOBAL_VAR(dcerpc_ep_servers
),
340 .label
= "server services",
343 .offset
= GLOBAL_VAR(server_services
),
352 .offset
= GLOBAL_VAR(security
),
354 .enum_list
= enum_security
357 .label
= "encrypt passwords",
360 .offset
= GLOBAL_VAR(bEncryptPasswords
),
365 .label
= "null passwords",
368 .offset
= GLOBAL_VAR(bNullPasswords
),
373 .label
= "obey pam restrictions",
376 .offset
= GLOBAL_VAR(bObeyPamRestrictions
),
381 .label
= "password server",
384 .offset
= GLOBAL_VAR(szPasswordServers
),
389 .label
= "spoolss database",
392 .offset
= GLOBAL_VAR(szSPOOLSS_URL
),
397 .label
= "wins config database",
400 .offset
= GLOBAL_VAR(szWINS_CONFIG_URL
),
405 .label
= "wins database",
408 .offset
= GLOBAL_VAR(szWINS_URL
),
413 .label
= "private dir",
416 .offset
= GLOBAL_VAR(szPrivateDir
),
421 .label
= "passwd chat",
424 .offset
= GLOBAL_VAR(szPasswdChat
),
429 .label
= "password level",
432 .offset
= GLOBAL_VAR(pwordlevel
),
437 .label
= "lanman auth",
440 .offset
= GLOBAL_VAR(bLanmanAuth
),
445 .label
= "ntlm auth",
448 .offset
= GLOBAL_VAR(bNTLMAuth
),
453 .label
= "client NTLMv2 auth",
456 .offset
= GLOBAL_VAR(bClientNTLMv2Auth
),
461 .label
= "client lanman auth",
464 .offset
= GLOBAL_VAR(bClientLanManAuth
),
469 .label
= "client plaintext auth",
472 .offset
= GLOBAL_VAR(bClientPlaintextAuth
),
477 .label
= "client use spnego principal",
480 .offset
= GLOBAL_VAR(client_use_spnego_principal
),
486 .label
= "read only",
489 .offset
= LOCAL_VAR(bRead_only
),
495 .label
= "create mask",
498 .offset
= LOCAL_VAR(iCreate_mask
),
503 .label
= "force create mode",
506 .offset
= LOCAL_VAR(iCreate_force_mode
),
511 .label
= "directory mask",
514 .offset
= LOCAL_VAR(iDir_mask
),
519 .label
= "force directory mode",
522 .offset
= LOCAL_VAR(iDir_force_mode
),
528 .label
= "hosts allow",
531 .offset
= LOCAL_VAR(szHostsallow
),
536 .label
= "hosts deny",
539 .offset
= LOCAL_VAR(szHostsdeny
),
545 .label
= "log level",
548 .offset
= GLOBAL_VAR(loglevel
),
549 .special
= handle_debuglevel
,
553 .label
= "debuglevel",
556 .offset
= GLOBAL_VAR(loglevel
),
557 .special
= handle_debuglevel
,
564 .offset
= GLOBAL_VAR(logfile
),
565 .special
= handle_logfile
,
570 .label
= "smb ports",
573 .offset
= GLOBAL_VAR(smb_ports
),
581 .offset
= GLOBAL_VAR(nbt_port
),
586 .label
= "dgram port",
589 .offset
= GLOBAL_VAR(dgram_port
),
594 .label
= "cldap port",
597 .offset
= GLOBAL_VAR(cldap_port
),
602 .label
= "krb5 port",
605 .offset
= GLOBAL_VAR(krb5_port
),
610 .label
= "kpasswd port",
613 .offset
= GLOBAL_VAR(kpasswd_port
),
621 .offset
= GLOBAL_VAR(web_port
),
626 .label
= "tls enabled",
629 .offset
= GLOBAL_VAR(tls_enabled
),
634 .label
= "tls keyfile",
637 .offset
= GLOBAL_VAR(tls_keyfile
),
642 .label
= "tls certfile",
645 .offset
= GLOBAL_VAR(tls_certfile
),
650 .label
= "tls cafile",
653 .offset
= GLOBAL_VAR(tls_cafile
),
658 .label
= "tls crlfile",
661 .offset
= GLOBAL_VAR(tls_crlfile
),
666 .label
= "tls dh params file",
669 .offset
= GLOBAL_VAR(tls_dhpfile
),
674 .label
= "large readwrite",
677 .offset
= GLOBAL_VAR(bLargeReadwrite
),
682 .label
= "server max protocol",
685 .offset
= GLOBAL_VAR(srv_maxprotocol
),
687 .enum_list
= enum_protocol
690 .label
= "server min protocol",
693 .offset
= GLOBAL_VAR(srv_minprotocol
),
695 .enum_list
= enum_protocol
698 .label
= "client max protocol",
701 .offset
= GLOBAL_VAR(cli_maxprotocol
),
703 .enum_list
= enum_protocol
706 .label
= "client min protocol",
709 .offset
= GLOBAL_VAR(cli_minprotocol
),
711 .enum_list
= enum_protocol
717 .offset
= GLOBAL_VAR(bUnicode
),
725 .offset
= GLOBAL_VAR(bReadRaw
),
730 .label
= "write raw",
733 .offset
= GLOBAL_VAR(bWriteRaw
),
738 .label
= "disable netbios",
741 .offset
= GLOBAL_VAR(bDisableNetbios
),
747 .label
= "nt status support",
750 .offset
= GLOBAL_VAR(bNTStatusSupport
),
759 .offset
= GLOBAL_VAR(max_mux
),
767 .offset
= GLOBAL_VAR(max_xmit
),
773 .label
= "name resolve order",
776 .offset
= GLOBAL_VAR(szNameResolveOrder
),
781 .label
= "max wins ttl",
784 .offset
= GLOBAL_VAR(max_wins_ttl
),
789 .label
= "min wins ttl",
792 .offset
= GLOBAL_VAR(min_wins_ttl
),
797 .label
= "time server",
800 .offset
= GLOBAL_VAR(bTimeServer
),
805 .label
= "unix extensions",
808 .offset
= GLOBAL_VAR(bUnixExtensions
),
813 .label
= "use spnego",
816 .offset
= GLOBAL_VAR(bUseSpnego
),
821 .label
= "server signing",
824 .offset
= GLOBAL_VAR(server_signing
),
826 .enum_list
= enum_smb_signing_vals
829 .label
= "client signing",
832 .offset
= GLOBAL_VAR(client_signing
),
834 .enum_list
= enum_smb_signing_vals
837 .label
= "rpc big endian",
840 .offset
= GLOBAL_VAR(bRpcBigEndian
),
846 .label
= "max connections",
849 .offset
= LOCAL_VAR(iMaxConnections
),
854 .label
= "paranoid server security",
857 .offset
= GLOBAL_VAR(paranoid_server_security
),
862 .label
= "socket options",
865 .offset
= GLOBAL_VAR(socket_options
),
871 .label
= "strict sync",
874 .offset
= LOCAL_VAR(bStrictSync
),
879 .label
= "case insensitive filesystem",
882 .offset
= LOCAL_VAR(bCIFileSystem
),
888 .label
= "max print jobs",
891 .offset
= LOCAL_VAR(iMaxPrintJobs
),
896 .label
= "printable",
899 .offset
= LOCAL_VAR(bPrint_ok
),
907 .offset
= LOCAL_VAR(bPrint_ok
),
913 .label
= "printer name",
916 .offset
= LOCAL_VAR(szPrintername
),
924 .offset
= LOCAL_VAR(szPrintername
),
930 .label
= "map system",
933 .offset
= LOCAL_VAR(bMap_system
),
938 .label
= "map hidden",
941 .offset
= LOCAL_VAR(bMap_hidden
),
946 .label
= "map archive",
949 .offset
= LOCAL_VAR(bMap_archive
),
955 .label
= "preferred master",
958 .offset
= GLOBAL_VAR(bPreferredMaster
),
960 .enum_list
= enum_bool_auto
963 .label
= "prefered master",
966 .offset
= GLOBAL_VAR(bPreferredMaster
),
968 .enum_list
= enum_bool_auto
971 .label
= "local master",
974 .offset
= GLOBAL_VAR(bLocalMaster
),
979 .label
= "browseable",
982 .offset
= LOCAL_VAR(bBrowseable
),
987 .label
= "browsable",
990 .offset
= LOCAL_VAR(bBrowseable
),
996 .label
= "wins server",
999 .offset
= GLOBAL_VAR(szWINSservers
),
1004 .label
= "wins support",
1006 .p_class
= P_GLOBAL
,
1007 .offset
= GLOBAL_VAR(bWINSsupport
),
1012 .label
= "dns proxy",
1014 .p_class
= P_GLOBAL
,
1015 .offset
= GLOBAL_VAR(bWINSdnsProxy
),
1020 .label
= "wins hook",
1022 .p_class
= P_GLOBAL
,
1023 .offset
= GLOBAL_VAR(szWINSHook
),
1029 .label
= "csc policy",
1032 .offset
= LOCAL_VAR(iCSCPolicy
),
1034 .enum_list
= enum_csc_policy
1038 .label
= "strict locking",
1041 .offset
= LOCAL_VAR(iStrictLocking
),
1049 .offset
= LOCAL_VAR(bOpLocks
),
1055 .label
= "share backend",
1057 .p_class
= P_GLOBAL
,
1058 .offset
= GLOBAL_VAR(szShareBackend
),
1065 .p_class
= P_GLOBAL
,
1066 .offset
= GLOBAL_VAR(szAutoServices
),
1071 .label
= "auto services",
1073 .p_class
= P_GLOBAL
,
1074 .offset
= GLOBAL_VAR(szAutoServices
),
1079 .label
= "lock dir",
1081 .p_class
= P_GLOBAL
,
1082 .offset
= GLOBAL_VAR(szLockDir
),
1087 .label
= "lock directory",
1089 .p_class
= P_GLOBAL
,
1090 .offset
= GLOBAL_VAR(szLockDir
),
1095 .label
= "state directory",
1097 .p_class
= P_GLOBAL
,
1098 .offset
= GLOBAL_VAR(szStateDir
),
1103 .label
= "cache directory",
1105 .p_class
= P_GLOBAL
,
1106 .offset
= GLOBAL_VAR(szCacheDir
),
1111 .label
= "pid directory",
1113 .p_class
= P_GLOBAL
,
1114 .offset
= GLOBAL_VAR(szPidDir
),
1120 .label
= "socket address",
1122 .p_class
= P_GLOBAL
,
1123 .offset
= GLOBAL_VAR(szSocketAddress
),
1131 .offset
= LOCAL_VAR(szCopy
),
1132 .special
= handle_copy
,
1139 .offset
= LOCAL_VAR(szInclude
),
1140 .special
= handle_include
,
1145 .label
= "available",
1148 .offset
= LOCAL_VAR(bAvailable
),
1156 .offset
= LOCAL_VAR(volume
),
1164 .offset
= LOCAL_VAR(fstype
),
1170 .label
= "panic action",
1172 .p_class
= P_GLOBAL
,
1173 .offset
= GLOBAL_VAR(panic_action
),
1179 .label
= "msdfs root",
1182 .offset
= LOCAL_VAR(bMSDfsRoot
),
1187 .label
= "host msdfs",
1189 .p_class
= P_GLOBAL
,
1190 .offset
= GLOBAL_VAR(bHostMSDfs
),
1195 .label
= "winbind separator",
1197 .p_class
= P_GLOBAL
,
1198 .offset
= GLOBAL_VAR(szWinbindSeparator
),
1203 .label
= "winbindd socket directory",
1205 .p_class
= P_GLOBAL
,
1206 .offset
= GLOBAL_VAR(szWinbinddSocketDirectory
),
1211 .label
= "winbindd privileged socket directory",
1213 .p_class
= P_GLOBAL
,
1214 .offset
= GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory
),
1219 .label
= "winbind sealed pipes",
1221 .p_class
= P_GLOBAL
,
1222 .offset
= GLOBAL_VAR(bWinbindSealedPipes
),
1227 .label
= "template shell",
1229 .p_class
= P_GLOBAL
,
1230 .offset
= GLOBAL_VAR(szTemplateShell
),
1235 .label
= "template homedir",
1237 .p_class
= P_GLOBAL
,
1238 .offset
= GLOBAL_VAR(szTemplateHomedir
),
1243 .label
= "idmap trusted only",
1245 .p_class
= P_GLOBAL
,
1246 .offset
= GLOBAL_VAR(bIdmapTrustedOnly
),
1252 .label
= "ntp signd socket directory",
1254 .p_class
= P_GLOBAL
,
1255 .offset
= GLOBAL_VAR(szNTPSignDSocketDirectory
),
1260 .label
= "rndc command",
1262 .p_class
= P_GLOBAL
,
1263 .offset
= GLOBAL_VAR(szRNDCCommand
),
1268 .label
= "dns update command",
1270 .p_class
= P_GLOBAL
,
1271 .offset
= GLOBAL_VAR(szDNSUpdateCommand
),
1276 .label
= "spn update command",
1278 .p_class
= P_GLOBAL
,
1279 .offset
= GLOBAL_VAR(szSPNUpdateCommand
),
1284 .label
= "nsupdate command",
1286 .p_class
= P_GLOBAL
,
1287 .offset
= GLOBAL_VAR(szNSUpdateCommand
),
1292 {NULL
, P_BOOL
, P_NONE
, 0, NULL
, NULL
, 0}
1296 /* local variables */
1297 struct loadparm_context
{
1298 const char *szConfigFile
;
1299 struct loadparm_global
*globals
;
1300 struct loadparm_service
**services
;
1301 struct loadparm_service
*sDefault
;
1302 struct smb_iconv_handle
*iconv_handle
;
1304 struct loadparm_service
*currentService
;
1305 bool bInGlobalSection
;
1307 struct file_lists
*next
;
1312 unsigned int flags
[NUMPARAMETERS
];
1315 bool global
; /* Is this the global context, which may set
1316 * global variables such as debug level etc? */
1317 const struct loadparm_s3_context
*s3_fns
;
1321 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
1323 if (lp_ctx
->s3_fns
) {
1324 return lp_ctx
->s3_fns
->get_default_loadparm_service();
1326 return lp_ctx
->sDefault
;
1330 * Convenience routine to grab string parameters into temporary memory
1331 * and run standard_sub_basic on them.
1333 * The buffers can be written to by
1334 * callers without affecting the source string.
1337 static const char *lp_string(const char *s
)
1339 #if 0 /* until REWRITE done to make thread-safe */
1340 size_t len
= s
? strlen(s
) : 0;
1344 /* The follow debug is useful for tracking down memory problems
1345 especially if you have an inner loop that is calling a lp_*()
1346 function that returns a string. Perhaps this debug should be
1347 present all the time? */
1350 DEBUG(10, ("lp_string(%s)\n", s
));
1353 #if 0 /* until REWRITE done to make thread-safe */
1355 lp_talloc
= talloc_init("lp_talloc");
1357 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
1365 strlcpy(ret
, s
, len
);
1367 if (trim_string(ret
, "\"", "\"")) {
1368 if (strchr(ret
,'"') != NULL
)
1369 strlcpy(ret
, s
, len
);
1372 standard_sub_basic(ret
,len
+100);
1379 In this section all the functions that are used to access the
1380 parameters from the rest of the program are defined
1384 * the creation of separate lpcfg_*() and lp_*() functions is to allow
1385 * for code compatibility between existing Samba4 and Samba3 code.
1388 /* this global context supports the lp_*() function varients */
1389 static struct loadparm_context
*global_loadparm_context
;
1391 #define lpcfg_default_service global_loadparm_context->sDefault
1392 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1394 #define FN_GLOBAL_STRING(fn_name,var_name) \
1395 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1396 if (lp_ctx == NULL) return NULL; \
1397 if (lp_ctx->s3_fns) { \
1398 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1399 return lp_ctx->s3_fns->fn_name(); \
1401 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1404 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1405 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1406 if (lp_ctx == NULL) return NULL; \
1407 if (lp_ctx->s3_fns) { \
1408 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1409 return lp_ctx->s3_fns->fn_name(); \
1411 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1414 #define FN_GLOBAL_LIST(fn_name,var_name) \
1415 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1416 if (lp_ctx == NULL) return NULL; \
1417 if (lp_ctx->s3_fns) { \
1418 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1419 return lp_ctx->s3_fns->fn_name(); \
1421 return lp_ctx->globals->var_name; \
1424 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1425 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1426 if (lp_ctx == NULL) return false; \
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 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1435 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1436 if (lp_ctx->s3_fns) { \
1437 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
1438 return lp_ctx->s3_fns->fn_name(); \
1440 return lp_ctx->globals->var_name; \
1443 /* Local parameters don't need the ->s3_fns because the struct
1444 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1446 #define FN_LOCAL_STRING(fn_name,val) \
1447 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1448 struct loadparm_service *sDefault) { \
1449 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1452 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1454 #define FN_LOCAL_LIST(fn_name,val) \
1455 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1456 struct loadparm_service *sDefault) {\
1457 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1460 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1462 #define FN_LOCAL_BOOL(fn_name,val) \
1463 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1464 struct loadparm_service *sDefault) { \
1465 return((service != NULL)? service->val : sDefault->val); \
1468 #define FN_LOCAL_INTEGER(fn_name,val) \
1469 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1470 struct loadparm_service *sDefault) { \
1471 return((service != NULL)? service->val : sDefault->val); \
1474 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1476 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1478 #define FN_LOCAL_CHAR(fn_name,val) \
1479 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1480 struct loadparm_service *sDefault) { \
1481 return((service != NULL)? service->val : sDefault->val); \
1484 #include "lib/param/param_functions.c"
1486 FN_GLOBAL_INTEGER(server_role
, server_role
)
1487 FN_GLOBAL_LIST(smb_ports
, smb_ports
)
1488 FN_GLOBAL_INTEGER(nbt_port
, nbt_port
)
1489 FN_GLOBAL_INTEGER(dgram_port
, dgram_port
)
1490 FN_GLOBAL_INTEGER(cldap_port
, cldap_port
)
1491 FN_GLOBAL_INTEGER(krb5_port
, krb5_port
)
1492 FN_GLOBAL_INTEGER(kpasswd_port
, kpasswd_port
)
1493 FN_GLOBAL_INTEGER(web_port
, web_port
)
1494 FN_GLOBAL_BOOL(tls_enabled
, tls_enabled
)
1495 FN_GLOBAL_STRING(logfile
, logfile
)
1496 FN_GLOBAL_STRING(share_backend
, szShareBackend
)
1497 FN_GLOBAL_STRING(spoolss_url
, szSPOOLSS_URL
)
1498 FN_GLOBAL_STRING(wins_config_url
, szWINS_CONFIG_URL
)
1499 FN_GLOBAL_STRING(wins_url
, szWINS_URL
)
1500 FN_GLOBAL_CONST_STRING(winbind_separator
, szWinbindSeparator
)
1501 FN_GLOBAL_CONST_STRING(winbindd_socket_directory
, szWinbinddSocketDirectory
)
1502 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory
, szWinbinddPrivilegedSocketDirectory
)
1503 FN_GLOBAL_CONST_STRING(template_shell
, szTemplateShell
)
1504 FN_GLOBAL_CONST_STRING(template_homedir
, szTemplateHomedir
)
1505 FN_GLOBAL_BOOL(winbind_sealed_pipes
, bWinbindSealedPipes
)
1506 FN_GLOBAL_BOOL(idmap_trusted_only
, bIdmapTrustedOnly
)
1507 FN_GLOBAL_STRING(private_dir
, szPrivateDir
)
1508 FN_GLOBAL_STRING(serverstring
, szServerString
)
1509 FN_GLOBAL_STRING(lockdir
, szLockDir
)
1510 FN_GLOBAL_STRING(statedir
, szStateDir
)
1511 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
1512 FN_GLOBAL_STRING(ncalrpc_dir
, ncalrpc_dir
)
1513 FN_GLOBAL_STRING(dos_charset
, dos_charset
)
1514 FN_GLOBAL_STRING(unix_charset
, unix_charset
)
1515 FN_GLOBAL_STRING(piddir
, szPidDir
)
1516 FN_GLOBAL_LIST(rndc_command
, szRNDCCommand
)
1517 FN_GLOBAL_LIST(dns_update_command
, szDNSUpdateCommand
)
1518 FN_GLOBAL_LIST(spn_update_command
, szSPNUpdateCommand
)
1519 FN_GLOBAL_LIST(nsupdate_command
, szNSUpdateCommand
)
1520 FN_GLOBAL_LIST(dcerpc_endpoint_servers
, dcerpc_ep_servers
)
1521 FN_GLOBAL_LIST(server_services
, server_services
)
1522 FN_GLOBAL_STRING(ntptr_providor
, ntptr_providor
)
1523 FN_GLOBAL_STRING(passdb_backend
, passdb_backend
)
1524 FN_GLOBAL_STRING(auto_services
, szAutoServices
)
1525 FN_GLOBAL_STRING(passwd_chat
, szPasswdChat
)
1526 FN_GLOBAL_LIST(passwordserver
, szPasswordServers
)
1527 FN_GLOBAL_LIST(name_resolve_order
, szNameResolveOrder
)
1528 FN_GLOBAL_STRING(realm
, szRealm_upper
)
1529 FN_GLOBAL_STRING(dnsdomain
, szRealm_lower
)
1530 FN_GLOBAL_STRING(socket_options
, socket_options
)
1531 FN_GLOBAL_STRING(workgroup
, szWorkgroup
)
1532 FN_GLOBAL_STRING(netbios_name
, szNetbiosName
)
1533 FN_GLOBAL_STRING(netbios_scope
, szNetbiosScope
)
1534 FN_GLOBAL_LIST(wins_server_list
, szWINSservers
)
1535 FN_GLOBAL_LIST(interfaces
, szInterfaces
)
1536 FN_GLOBAL_STRING(socket_address
, szSocketAddress
)
1537 FN_GLOBAL_LIST(netbios_aliases
, szNetbiosAliases
)
1538 FN_GLOBAL_BOOL(disable_netbios
, bDisableNetbios
)
1539 FN_GLOBAL_BOOL(we_are_a_wins_server
, bWINSsupport
)
1540 FN_GLOBAL_BOOL(wins_dns_proxy
, bWINSdnsProxy
)
1541 FN_GLOBAL_STRING(wins_hook
, szWINSHook
)
1542 FN_GLOBAL_BOOL(local_master
, bLocalMaster
)
1543 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
1544 FN_GLOBAL_BOOL(large_readwrite
, bLargeReadwrite
)
1545 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
1546 FN_GLOBAL_BOOL(null_passwords
, bNullPasswords
)
1547 FN_GLOBAL_BOOL(obey_pam_restrictions
, bObeyPamRestrictions
)
1548 FN_GLOBAL_BOOL(encrypted_passwords
, bEncryptPasswords
)
1549 FN_GLOBAL_BOOL(time_server
, bTimeServer
)
1550 FN_GLOBAL_BOOL(bind_interfaces_only
, bBindInterfacesOnly
)
1551 FN_GLOBAL_BOOL(unicode
, bUnicode
)
1552 FN_GLOBAL_BOOL(nt_status_support
, bNTStatusSupport
)
1553 FN_GLOBAL_BOOL(lanman_auth
, bLanmanAuth
)
1554 FN_GLOBAL_BOOL(ntlm_auth
, bNTLMAuth
)
1555 FN_GLOBAL_BOOL(client_plaintext_auth
, bClientPlaintextAuth
)
1556 FN_GLOBAL_BOOL(client_lanman_auth
, bClientLanManAuth
)
1557 FN_GLOBAL_BOOL(client_ntlmv2_auth
, bClientNTLMv2Auth
)
1558 FN_GLOBAL_BOOL(client_use_spnego_principal
, client_use_spnego_principal
)
1559 FN_GLOBAL_BOOL(host_msdfs
, bHostMSDfs
)
1560 FN_GLOBAL_BOOL(unix_extensions
, bUnixExtensions
)
1561 FN_GLOBAL_BOOL(use_spnego
, bUseSpnego
)
1562 FN_GLOBAL_BOOL(rpc_big_endian
, bRpcBigEndian
)
1563 FN_GLOBAL_INTEGER(max_wins_ttl
, max_wins_ttl
)
1564 FN_GLOBAL_INTEGER(min_wins_ttl
, min_wins_ttl
)
1565 FN_GLOBAL_INTEGER(maxmux
, max_mux
)
1566 FN_GLOBAL_INTEGER(max_xmit
, max_xmit
)
1567 FN_GLOBAL_INTEGER(passwordlevel
, pwordlevel
)
1568 FN_GLOBAL_INTEGER(srv_maxprotocol
, srv_maxprotocol
)
1569 FN_GLOBAL_INTEGER(srv_minprotocol
, srv_minprotocol
)
1570 FN_GLOBAL_INTEGER(cli_maxprotocol
, cli_maxprotocol
)
1571 FN_GLOBAL_INTEGER(cli_minprotocol
, cli_minprotocol
)
1572 FN_GLOBAL_INTEGER(security
, security
)
1573 FN_GLOBAL_BOOL(paranoid_server_security
, paranoid_server_security
)
1575 FN_GLOBAL_INTEGER(server_signing
, server_signing
)
1576 FN_GLOBAL_INTEGER(client_signing
, client_signing
)
1578 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory
, szNTPSignDSocketDirectory
)
1580 /* local prototypes */
1581 static int map_parameter(const char *pszParmName
);
1582 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
1583 const char *pszServiceName
);
1584 static void copy_service(struct loadparm_service
*pserviceDest
,
1585 struct loadparm_service
*pserviceSource
,
1586 struct bitmap
*pcopymapDest
);
1587 static bool service_ok(struct loadparm_service
*service
);
1588 static bool do_section(const char *pszSectionName
, void *);
1589 static void init_copymap(struct loadparm_service
*pservice
);
1591 /* This is a helper function for parametrical options support. */
1592 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1593 /* Actual parametrical functions are quite simple */
1594 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
1595 struct loadparm_service
*service
,
1596 const char *type
, const char *option
)
1598 char *vfskey_tmp
= NULL
;
1599 char *vfskey
= NULL
;
1600 struct parmlist_entry
*data
;
1605 if (lp_ctx
->s3_fns
) {
1606 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
1609 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
1611 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
1612 if (vfskey_tmp
== NULL
) return NULL
;
1613 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
1614 talloc_free(vfskey_tmp
);
1617 if (strcmp(data
->key
, vfskey
) == 0) {
1618 talloc_free(vfskey
);
1624 if (service
!= NULL
) {
1625 /* Try to fetch the same option but from globals */
1626 /* but only if we are not already working with globals */
1627 for (data
= lp_ctx
->globals
->param_opt
; data
;
1628 data
= data
->next
) {
1629 if (strcmp(data
->key
, vfskey
) == 0) {
1630 talloc_free(vfskey
);
1636 talloc_free(vfskey
);
1643 * convenience routine to return int parameters.
1645 static int lp_int(const char *s
)
1649 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1653 return strtol(s
, NULL
, 0);
1657 * convenience routine to return unsigned long parameters.
1659 static int lp_ulong(const char *s
)
1663 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
1667 return strtoul(s
, NULL
, 0);
1671 * convenience routine to return unsigned long parameters.
1673 static double lp_double(const char *s
)
1677 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
1681 return strtod(s
, NULL
);
1685 * convenience routine to return boolean parameters.
1687 static bool lp_bool(const char *s
)
1692 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
1696 if (!set_boolean(s
, &ret
)) {
1697 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
1706 * Return parametric option from a given service. Type is a part of option before ':'
1707 * Parametric option has following syntax: 'Type: option = value'
1708 * Returned value is allocated in 'lp_talloc' context
1711 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
1712 struct loadparm_service
*service
, const char *type
,
1715 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1718 return lp_string(value
);
1724 * Return parametric option from a given service. Type is a part of option before ':'
1725 * Parametric option has following syntax: 'Type: option = value'
1726 * Returned value is allocated in 'lp_talloc' context
1729 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
1730 struct loadparm_context
*lp_ctx
,
1731 struct loadparm_service
*service
,
1733 const char *option
, const char *separator
)
1735 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1738 return (const char **)str_list_make(mem_ctx
, value
, separator
);
1744 * Return parametric option from a given service. Type is a part of option before ':'
1745 * Parametric option has following syntax: 'Type: option = value'
1748 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
1749 struct loadparm_service
*service
, const char *type
,
1750 const char *option
, int default_v
)
1752 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1755 return lp_int(value
);
1761 * Return parametric option from a given service. Type is a part of
1762 * option before ':'.
1763 * Parametric option has following syntax: 'Type: option = value'.
1766 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
1767 struct loadparm_service
*service
, const char *type
,
1768 const char *option
, int default_v
)
1772 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1774 if (value
&& conv_str_size_error(value
, &bval
)) {
1775 if (bval
<= INT_MAX
) {
1784 * Return parametric option from a given service.
1785 * Type is a part of option before ':'
1786 * Parametric option has following syntax: 'Type: option = value'
1788 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
1789 struct loadparm_service
*service
, const char *type
,
1790 const char *option
, unsigned long default_v
)
1792 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1795 return lp_ulong(value
);
1801 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
1802 struct loadparm_service
*service
, const char *type
,
1803 const char *option
, double default_v
)
1805 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1808 return lp_double(value
);
1814 * Return parametric option from a given service. Type is a part of option before ':'
1815 * Parametric option has following syntax: 'Type: option = value'
1818 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
1819 struct loadparm_service
*service
, const char *type
,
1820 const char *option
, bool default_v
)
1822 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
1825 return lp_bool(value
);
1832 * Initialise a service to the defaults.
1835 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
1837 struct loadparm_service
*pservice
=
1838 talloc_zero(mem_ctx
, struct loadparm_service
);
1839 copy_service(pservice
, sDefault
, NULL
);
1844 * Set a string value, deallocating any existing space, and allocing the space
1847 static bool string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1854 *dest
= talloc_strdup(mem_ctx
, src
);
1855 if ((*dest
) == NULL
) {
1856 DEBUG(0,("Out of memory in string_set\n"));
1864 * Set a string value, deallocating any existing space, and allocing the space
1867 static bool string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
1874 *dest
= strupper_talloc(mem_ctx
, src
);
1875 if ((*dest
) == NULL
) {
1876 DEBUG(0,("Out of memory in string_set_upper\n"));
1886 * Add a new service to the services array initialising it with the given
1890 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
1891 const struct loadparm_service
*pservice
,
1895 struct loadparm_service tservice
;
1896 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
1897 struct parmlist_entry
*data
, *pdata
;
1899 if (pservice
== NULL
) {
1900 pservice
= lp_ctx
->sDefault
;
1903 tservice
= *pservice
;
1905 /* it might already exist */
1907 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
1909 if (service
!= NULL
) {
1910 /* Clean all parametric options for service */
1911 /* They will be added during parsing again */
1912 data
= service
->param_opt
;
1918 service
->param_opt
= NULL
;
1923 /* find an invalid one */
1924 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
1925 if (lp_ctx
->services
[i
] == NULL
)
1928 /* if not, then create one */
1929 if (i
== lp_ctx
->iNumServices
) {
1930 struct loadparm_service
**tsp
;
1932 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
1935 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
1938 lp_ctx
->services
= tsp
;
1939 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
1942 lp_ctx
->iNumServices
++;
1945 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
1946 if (lp_ctx
->services
[i
] == NULL
) {
1947 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
1950 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
1952 string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
1953 return lp_ctx
->services
[i
];
1957 * Add a new home service, with the specified home directory, defaults coming
1958 * from service ifrom.
1961 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
1962 const char *pszHomename
,
1963 struct loadparm_service
*default_service
,
1964 const char *user
, const char *pszHomedir
)
1966 struct loadparm_service
*service
;
1968 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
1970 if (service
== NULL
)
1973 if (!(*(default_service
->szPath
))
1974 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
1975 service
->szPath
= talloc_strdup(service
, pszHomedir
);
1977 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
1980 if (!(*(service
->comment
))) {
1981 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
1983 service
->bAvailable
= default_service
->bAvailable
;
1984 service
->bBrowseable
= default_service
->bBrowseable
;
1986 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
1987 pszHomename
, user
, service
->szPath
));
1993 * Add a new printer service, with defaults coming from service iFrom.
1996 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
1997 const char *pszPrintername
,
1998 struct loadparm_service
*default_service
)
2000 const char *comment
= "From Printcap";
2001 struct loadparm_service
*service
;
2002 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
2004 if (service
== NULL
)
2007 /* note that we do NOT default the availability flag to True - */
2008 /* we take it from the default service passed. This allows all */
2009 /* dynamic printers to be disabled by disabling the [printers] */
2010 /* entry (if/when the 'available' keyword is implemented!). */
2012 /* the printer name is set to the service name. */
2013 string_set(service
, &service
->szPrintername
, pszPrintername
);
2014 string_set(service
, &service
->comment
, comment
);
2015 service
->bBrowseable
= default_service
->bBrowseable
;
2016 /* Printers cannot be read_only. */
2017 service
->bRead_only
= false;
2018 /* Printer services must be printable. */
2019 service
->bPrint_ok
= true;
2021 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
2027 * Map a parameter's string representation to something we can use.
2028 * Returns False if the parameter string is not recognised, else TRUE.
2031 static int map_parameter(const char *pszParmName
)
2035 if (*pszParmName
== '-')
2038 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
2039 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
2042 /* Warn only if it isn't parametric option */
2043 if (strchr(pszParmName
, ':') == NULL
)
2044 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
2045 /* We do return 'fail' for parametric options as well because they are
2046 stored in different storage
2053 return the parameter structure for a parameter
2055 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
2059 if (lp_ctx
->s3_fns
) {
2060 return lp_ctx
->s3_fns
->get_parm_struct(name
);
2063 parmnum
= map_parameter(name
);
2064 if (parmnum
== -1) return NULL
;
2065 return &parm_table
[parmnum
];
2069 return the parameter pointer for a parameter
2071 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
2072 struct loadparm_service
*service
, struct parm_struct
*parm
)
2074 if (lp_ctx
->s3_fns
) {
2075 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
2078 if (service
== NULL
) {
2079 if (parm
->p_class
== P_LOCAL
)
2080 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
2081 else if (parm
->p_class
== P_GLOBAL
)
2082 return ((char *)lp_ctx
->globals
)+parm
->offset
;
2085 return ((char *)service
) + parm
->offset
;
2090 * Find a service by name. Otherwise works like get_service.
2093 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
2094 const char *pszServiceName
)
2098 if (lp_ctx
->s3_fns
) {
2099 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
2102 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
2103 if (lp_ctx
->services
[iService
] != NULL
&&
2104 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
2105 return lp_ctx
->services
[iService
];
2112 * Copy a service structure to another.
2113 * If pcopymapDest is NULL then copy all fields
2116 static void copy_service(struct loadparm_service
*pserviceDest
,
2117 struct loadparm_service
*pserviceSource
,
2118 struct bitmap
*pcopymapDest
)
2121 bool bcopyall
= (pcopymapDest
== NULL
);
2122 struct parmlist_entry
*data
, *pdata
, *paramo
;
2125 for (i
= 0; parm_table
[i
].label
; i
++)
2126 if (parm_table
[i
].p_class
== P_LOCAL
&&
2127 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
2129 ((char *)pserviceSource
) + parm_table
[i
].offset
;
2131 ((char *)pserviceDest
) + parm_table
[i
].offset
;
2133 switch (parm_table
[i
].type
) {
2135 *(int *)dest_ptr
= *(int *)src_ptr
;
2141 *(int *)dest_ptr
= *(int *)src_ptr
;
2145 string_set(pserviceDest
,
2151 string_set_upper(pserviceDest
,
2156 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
2157 *(const char ***)src_ptr
);
2165 init_copymap(pserviceDest
);
2166 if (pserviceSource
->copymap
)
2167 bitmap_copy(pserviceDest
->copymap
,
2168 pserviceSource
->copymap
);
2171 data
= pserviceSource
->param_opt
;
2174 pdata
= pserviceDest
->param_opt
;
2175 /* Traverse destination */
2177 /* If we already have same option, override it */
2178 if (strcmp(pdata
->key
, data
->key
) == 0) {
2179 talloc_free(pdata
->value
);
2180 pdata
->value
= talloc_reference(pdata
,
2185 pdata
= pdata
->next
;
2188 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
2191 paramo
->key
= talloc_reference(paramo
, data
->key
);
2192 paramo
->value
= talloc_reference(paramo
, data
->value
);
2193 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
2200 * Check a service for consistency. Return False if the service is in any way
2201 * incomplete or faulty, else True.
2203 static bool service_ok(struct loadparm_service
*service
)
2208 if (service
->szService
[0] == '\0') {
2209 DEBUG(0, ("The following message indicates an internal error:\n"));
2210 DEBUG(0, ("No service name in service entry.\n"));
2214 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2215 /* I can't see why you'd want a non-printable printer service... */
2216 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
2217 if (!service
->bPrint_ok
) {
2218 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2219 service
->szService
));
2220 service
->bPrint_ok
= true;
2222 /* [printers] service must also be non-browsable. */
2223 if (service
->bBrowseable
)
2224 service
->bBrowseable
= false;
2227 /* If a service is flagged unavailable, log the fact at level 0. */
2228 if (!service
->bAvailable
)
2229 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2230 service
->szService
));
2236 /*******************************************************************
2237 Keep a linked list of all config files so we know when one has changed
2238 it's date and needs to be reloaded.
2239 ********************************************************************/
2241 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
2242 const char *fname
, const char *subfname
)
2244 struct file_lists
*f
= lp_ctx
->file_lists
;
2247 if (f
->name
&& !strcmp(f
->name
, fname
))
2253 f
= talloc(lp_ctx
, struct file_lists
);
2256 f
->next
= lp_ctx
->file_lists
;
2257 f
->name
= talloc_strdup(f
, fname
);
2262 f
->subfname
= talloc_strdup(f
, subfname
);
2267 lp_ctx
->file_lists
= f
;
2268 f
->modtime
= file_modtime(subfname
);
2270 time_t t
= file_modtime(subfname
);
2276 /*******************************************************************
2277 Check if a config file has changed date.
2278 ********************************************************************/
2279 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
2281 struct file_lists
*f
;
2282 DEBUG(6, ("lp_file_list_changed()\n"));
2284 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
2288 n2
= standard_sub_basic(lp_ctx
, f
->name
);
2290 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
2291 f
->name
, n2
, ctime(&f
->modtime
)));
2293 mod_time
= file_modtime(n2
);
2295 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
2296 DEBUGADD(6, ("file %s modified: %s\n", n2
,
2298 f
->modtime
= mod_time
;
2299 talloc_free(f
->subfname
);
2300 f
->subfname
= talloc_strdup(f
, n2
);
2307 /***************************************************************************
2308 Handle the "realm" parameter
2309 ***************************************************************************/
2311 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
2312 const char *pszParmValue
, char **ptr
)
2314 string_set(lp_ctx
, ptr
, pszParmValue
);
2316 talloc_free(lp_ctx
->globals
->szRealm_upper
);
2317 talloc_free(lp_ctx
->globals
->szRealm_lower
);
2319 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
2320 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
2325 /***************************************************************************
2326 Handle the include operation.
2327 ***************************************************************************/
2329 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
2330 const char *pszParmValue
, char **ptr
)
2332 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
2334 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
2336 string_set(lp_ctx
, ptr
, fname
);
2338 if (file_exist(fname
))
2339 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
2341 DEBUG(2, ("Can't find include file %s\n", fname
));
2346 /***************************************************************************
2347 Handle the interpretation of the copy parameter.
2348 ***************************************************************************/
2350 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
2351 const char *pszParmValue
, char **ptr
)
2354 struct loadparm_service
*serviceTemp
;
2356 string_set(lp_ctx
, ptr
, pszParmValue
);
2360 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
2362 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
2363 if (serviceTemp
== lp_ctx
->currentService
) {
2364 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
2366 copy_service(lp_ctx
->currentService
,
2368 lp_ctx
->currentService
->copymap
);
2372 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2380 static bool handle_debuglevel(struct loadparm_context
*lp_ctx
, int unused
,
2381 const char *pszParmValue
, char **ptr
)
2384 string_set(lp_ctx
, ptr
, pszParmValue
);
2385 if (lp_ctx
->global
) {
2386 return debug_parse_levels(pszParmValue
);
2391 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
2392 const char *pszParmValue
, char **ptr
)
2394 debug_set_logfile(pszParmValue
);
2395 if (lp_ctx
->global
) {
2396 string_set(lp_ctx
, ptr
, pszParmValue
);
2401 /***************************************************************************
2402 Initialise a copymap.
2403 ***************************************************************************/
2405 static void init_copymap(struct loadparm_service
*pservice
)
2409 TALLOC_FREE(pservice
->copymap
);
2411 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
2412 if (!pservice
->copymap
)
2414 ("Couldn't allocate copymap!! (size %d)\n",
2415 (int)NUMPARAMETERS
));
2417 for (i
= 0; i
< NUMPARAMETERS
; i
++)
2418 bitmap_set(pservice
->copymap
, i
);
2422 * Process a parametric option
2424 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
2425 struct loadparm_service
*service
,
2426 const char *pszParmName
,
2427 const char *pszParmValue
, int flags
)
2429 struct parmlist_entry
*paramo
, *data
;
2431 TALLOC_CTX
*mem_ctx
;
2433 while (isspace((unsigned char)*pszParmName
)) {
2437 name
= strlower_talloc(lp_ctx
, pszParmName
);
2438 if (!name
) return false;
2440 if (service
== NULL
) {
2441 data
= lp_ctx
->globals
->param_opt
;
2442 mem_ctx
= lp_ctx
->globals
;
2444 data
= service
->param_opt
;
2448 /* Traverse destination */
2449 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
2450 /* If we already have the option set, override it unless
2451 it was a command line option and the new one isn't */
2452 if (strcmp(paramo
->key
, name
) == 0) {
2453 if ((paramo
->priority
& FLAG_CMDLINE
) &&
2454 !(flags
& FLAG_CMDLINE
)) {
2459 talloc_free(paramo
->value
);
2460 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2461 paramo
->priority
= flags
;
2467 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
2470 paramo
->key
= talloc_strdup(paramo
, name
);
2471 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
2472 paramo
->priority
= flags
;
2473 if (service
== NULL
) {
2474 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
2476 DLIST_ADD(service
->param_opt
, paramo
);
2484 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
2485 const char *pszParmName
, const char *pszParmValue
,
2486 struct loadparm_context
*lp_ctx
, bool on_globals
)
2489 /* if it is a special case then go ahead */
2490 if (parm_table
[parmnum
].special
) {
2492 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
2497 goto mark_non_default
;
2500 /* now switch on the type of variable it is */
2501 switch (parm_table
[parmnum
].type
)
2505 if (!set_boolean(pszParmValue
, &b
)) {
2506 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2509 *(int *)parm_ptr
= b
;
2515 if (!set_boolean(pszParmValue
, &b
)) {
2516 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
2519 *(int *)parm_ptr
= !b
;
2524 *(int *)parm_ptr
= atoi(pszParmValue
);
2528 *(char *)parm_ptr
= *pszParmValue
;
2532 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
2538 if (conv_str_size_error(pszParmValue
, &val
)) {
2539 if (val
<= INT_MAX
) {
2540 *(int *)parm_ptr
= (int)val
;
2545 DEBUG(0,("lp_do_parameter(%s): value is not "
2546 "a valid size specifier!\n", pszParmValue
));
2551 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
2552 pszParmValue
, NULL
);
2556 char **new_list
= str_list_make(mem_ctx
,
2557 pszParmValue
, NULL
);
2558 for (i
=0; new_list
[i
]; i
++) {
2559 if (new_list
[i
][0] == '+' && new_list
[i
][1] &&
2560 (!str_list_check(*(const char ***)parm_ptr
,
2561 &new_list
[i
][1]))) {
2562 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
2564 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
2565 #if 0 /* This is commented out because we sometimes parse the list
2566 * twice, and so we can't assert on this */
2567 if (!str_list_check(*(const char ***)parm_ptr
,
2569 DEBUG(0, ("Unsupported value for: %s = %s, %s is not in the original list [%s]\n",
2570 pszParmName
, pszParmValue
, new_list
[i
],
2571 str_list_join_shell(mem_ctx
, *(const char ***)parm_ptr
, ' ')));
2576 str_list_remove(*(const char ***)parm_ptr
,
2580 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2581 pszParmName
, pszParmValue
));
2584 *(const char ***)parm_ptr
= (const char **) new_list
;
2591 string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2595 string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
2599 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
2602 parm_table
[parmnum
].enum_list
[i
].name
)) {
2604 parm_table
[parmnum
].
2609 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
2610 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
2611 pszParmValue
, pszParmName
));
2618 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
2619 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
2620 /* we have to also unset FLAG_DEFAULT on aliases */
2621 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2622 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2624 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2625 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
2632 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
2633 const char *pszParmName
, const char *pszParmValue
)
2635 int parmnum
= map_parameter(pszParmName
);
2639 if (strchr(pszParmName
, ':')) {
2640 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
2642 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2646 /* if the flag has been set on the command line, then don't allow override,
2647 but don't report an error */
2648 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2652 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
2654 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
2655 pszParmName
, pszParmValue
, lp_ctx
, true);
2658 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
2659 struct loadparm_service
*service
,
2660 const char *pszParmName
, const char *pszParmValue
)
2664 int parmnum
= map_parameter(pszParmName
);
2667 if (strchr(pszParmName
, ':')) {
2668 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
2670 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
2674 /* if the flag has been set on the command line, then don't allow override,
2675 but don't report an error */
2676 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
2680 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
2682 ("Global parameter %s found in service section!\n",
2686 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
2688 if (!service
->copymap
)
2689 init_copymap(service
);
2691 /* this handles the aliases - set the copymap for other
2692 * entries with the same data pointer */
2693 for (i
= 0; parm_table
[i
].label
; i
++)
2694 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
2695 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
2696 bitmap_clear(service
->copymap
, i
);
2698 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
2699 pszParmValue
, lp_ctx
, false);
2703 * Process a parameter.
2706 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
2709 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2711 if (lp_ctx
->bInGlobalSection
)
2712 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
2715 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
2716 pszParmName
, pszParmValue
);
2720 variable argument do parameter
2722 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
2723 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
2724 const char *pszParmName
, const char *fmt
, ...)
2731 s
= talloc_vasprintf(NULL
, fmt
, ap
);
2733 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
2740 set a parameter from the commandline - this is called from command line parameter
2741 parsing code. It sets the parameter then marks the parameter as unable to be modified
2742 by smb.conf processing
2744 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
2745 const char *pszParmValue
)
2750 if (lp_ctx
->s3_fns
) {
2751 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
2754 parmnum
= map_parameter(pszParmName
);
2756 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
2759 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
2760 /* set a parametric option */
2761 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
2762 pszParmValue
, FLAG_CMDLINE
);
2766 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
2770 /* reset the CMDLINE flag in case this has been called before */
2771 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
2773 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
2777 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
2779 /* we have to also set FLAG_CMDLINE on aliases */
2780 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
2781 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2783 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
2784 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
2791 set a option from the commandline in 'a=b' format. Use to support --option
2793 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
2811 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2817 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2820 * Print a parameter of the specified type.
2823 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2826 const char *list_sep
= ", "; /* For the seperation of lists values that we print below */
2830 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2831 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2833 p
->enum_list
[i
].name
);
2840 fprintf(f
, "%s", BOOLSTR((bool)*(int *)ptr
));
2844 fprintf(f
, "%s", BOOLSTR(!(bool)*(int *)ptr
));
2849 fprintf(f
, "%d", *(int *)ptr
);
2853 fprintf(f
, "%c", *(char *)ptr
);
2857 fprintf(f
, "0%o", *(int *)ptr
);
2864 if ((char ***)ptr
&& *(char ***)ptr
) {
2865 char **list
= *(char ***)ptr
;
2867 for (; *list
; list
++) {
2868 if (*(list
+1) == NULL
) {
2869 /* last item, print no extra seperator after */
2872 fprintf(f
, "%s%s", *list
, list_sep
);
2879 if (*(char **)ptr
) {
2880 fprintf(f
, "%s", *(char **)ptr
);
2887 * Check if two parameters are equal.
2890 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2895 return (*((int *)ptr1
) == *((int *)ptr2
));
2901 return (*((int *)ptr1
) == *((int *)ptr2
));
2904 return (*((char *)ptr1
) == *((char *)ptr2
));
2908 return str_list_equal((const char **)(*(char ***)ptr1
),
2909 (const char **)(*(char ***)ptr2
));
2914 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2919 return (p1
== p2
|| strequal(p1
, p2
));
2926 * Process a new section (service).
2928 * At this stage all sections are services.
2929 * Later we'll have special sections that permit server parameters to be set.
2930 * Returns True on success, False on failure.
2933 static bool do_section(const char *pszSectionName
, void *userdata
)
2935 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2937 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2938 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2941 /* if we've just struck a global section, note the fact. */
2942 lp_ctx
->bInGlobalSection
= isglobal
;
2944 /* check for multiple global sections */
2945 if (lp_ctx
->bInGlobalSection
) {
2946 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2950 /* if we have a current service, tidy it up before moving on */
2953 if (lp_ctx
->currentService
!= NULL
)
2954 bRetval
= service_ok(lp_ctx
->currentService
);
2956 /* if all is still well, move to the next record in the services array */
2958 /* We put this here to avoid an odd message order if messages are */
2959 /* issued by the post-processing of a previous section. */
2960 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2962 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2965 DEBUG(0, ("Failed to add a new service\n"));
2975 * Determine if a particular base parameter is currently set to the default value.
2978 static bool is_default(struct loadparm_service
*sDefault
, int i
)
2980 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
2981 if (!defaults_saved
)
2983 switch (parm_table
[i
].type
) {
2986 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
2987 (const char **)def_ptr
);
2990 return strequal(parm_table
[i
].def
.svalue
,
2994 return parm_table
[i
].def
.bvalue
==
3001 return parm_table
[i
].def
.ivalue
==
3008 *Display the contents of the global structure.
3011 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
3015 struct parmlist_entry
*data
;
3017 fprintf(f
, "# Global parameters\n[global]\n");
3019 for (i
= 0; parm_table
[i
].label
; i
++)
3020 if (parm_table
[i
].p_class
== P_GLOBAL
&&
3021 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
3022 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
3024 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3025 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
3028 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3029 for (data
= lp_ctx
->globals
->param_opt
; data
;
3030 data
= data
->next
) {
3031 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
3034 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3041 * Display the contents of a single services record.
3044 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
3045 unsigned int *flags
)
3048 struct parmlist_entry
*data
;
3050 if (pService
!= sDefault
)
3051 fprintf(f
, "\n[%s]\n", pService
->szService
);
3053 for (i
= 0; parm_table
[i
].label
; i
++) {
3054 if (parm_table
[i
].p_class
== P_LOCAL
&&
3055 (*parm_table
[i
].label
!= '-') &&
3056 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
3058 if (pService
== sDefault
) {
3059 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
3062 if (defaults_saved
) {
3063 if (is_default(sDefault
, i
)) {
3068 if (equal_parameter(parm_table
[i
].type
,
3069 ((char *)pService
) +
3070 parm_table
[i
].offset
,
3071 ((char *)sDefault
) +
3072 parm_table
[i
].offset
))
3076 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
3077 print_parameter(&parm_table
[i
],
3078 ((char *)pService
) + parm_table
[i
].offset
, f
);
3082 if (pService
->param_opt
!= NULL
) {
3083 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
3084 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
3089 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
3090 struct loadparm_service
*service
,
3091 const char *parm_name
, FILE * f
)
3093 struct parm_struct
*parm
;
3096 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
3101 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
3103 print_parameter(parm
, ptr
, f
);
3109 * Return info about the next parameter in a service.
3110 * snum==-1 gives the globals.
3111 * Return NULL when out of parameters.
3115 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
3119 /* do the globals */
3120 for (; parm_table
[*i
].label
; (*i
)++) {
3121 if ((*parm_table
[*i
].label
== '-'))
3125 && (parm_table
[*i
].offset
==
3126 parm_table
[(*i
) - 1].offset
)
3127 && (parm_table
[*i
].p_class
==
3128 parm_table
[(*i
) - 1].p_class
))
3131 return &parm_table
[(*i
)++];
3134 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
3136 for (; parm_table
[*i
].label
; (*i
)++) {
3137 if (parm_table
[*i
].p_class
== P_LOCAL
&&
3138 (*parm_table
[*i
].label
!= '-') &&
3140 (parm_table
[*i
].offset
!=
3141 parm_table
[(*i
) - 1].offset
)))
3143 if (allparameters
||
3144 !equal_parameter(parm_table
[*i
].type
,
3145 ((char *)pService
) +
3146 parm_table
[*i
].offset
,
3147 ((char *)lp_ctx
->sDefault
) +
3148 parm_table
[*i
].offset
))
3150 return &parm_table
[(*i
)++];
3161 * Auto-load some home services.
3163 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
3171 * Unload unused services.
3174 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
3175 struct smbsrv_connection
*smb
,
3176 bool (*snumused
) (struct smbsrv_connection
*, int))
3179 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
3180 if (lp_ctx
->services
[i
] == NULL
)
3183 if (!snumused
|| !snumused(smb
, i
)) {
3184 talloc_free(lp_ctx
->services
[i
]);
3185 lp_ctx
->services
[i
] = NULL
;
3191 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
3193 struct parmlist_entry
*data
;
3195 if (lp_ctx
->refuse_free
) {
3196 /* someone is trying to free the
3197 global_loadparm_context.
3198 We can't allow that. */
3202 if (lp_ctx
->globals
->param_opt
!= NULL
) {
3203 struct parmlist_entry
*next
;
3204 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
3206 if (data
->priority
& FLAG_CMDLINE
) continue;
3207 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
3216 * Initialise the global parameter structure.
3218 * Note that most callers should use loadparm_init_global() instead
3220 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
3224 struct loadparm_context
*lp_ctx
;
3225 struct parmlist_entry
*parm
;
3228 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
3232 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
3233 lp_ctx
->bInGlobalSection
= true;
3234 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
3235 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
3237 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
3238 lp_ctx
->sDefault
->bAvailable
= true;
3239 lp_ctx
->sDefault
->bBrowseable
= true;
3240 lp_ctx
->sDefault
->bRead_only
= true;
3241 lp_ctx
->sDefault
->bMap_archive
= true;
3242 lp_ctx
->sDefault
->iStrictLocking
= true;
3243 lp_ctx
->sDefault
->bOpLocks
= true;
3244 lp_ctx
->sDefault
->iCreate_mask
= 0744;
3245 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
3246 lp_ctx
->sDefault
->iDir_mask
= 0755;
3247 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
3249 DEBUG(3, ("Initialising global parameters\n"));
3251 for (i
= 0; parm_table
[i
].label
; i
++) {
3252 if ((parm_table
[i
].type
== P_STRING
||
3253 parm_table
[i
].type
== P_USTRING
) &&
3254 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3256 if (parm_table
[i
].p_class
== P_LOCAL
) {
3257 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
3259 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
3261 *r
= talloc_strdup(lp_ctx
, "");
3265 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
3266 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
3267 talloc_free(logfile
);
3269 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
3271 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3273 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
3275 lpcfg_do_global_parameter(lp_ctx
, "server role", "standalone");
3277 /* options that can be set on the command line must be initialised via
3278 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3280 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
3282 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
3283 myname
= get_myname(lp_ctx
);
3284 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
3285 talloc_free(myname
);
3286 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
3288 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
3290 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
3291 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
3293 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey");
3294 lpcfg_do_global_parameter(lp_ctx
, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3295 lpcfg_do_global_parameter(lp_ctx
, "ntptr providor", "simple_ldb");
3296 /* the winbind method for domain controllers is for both RODC
3297 auth forwarding and for trusted domains */
3298 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
3299 lpcfg_do_global_parameter(lp_ctx
, "spoolss database", "spoolss.ldb");
3300 lpcfg_do_global_parameter(lp_ctx
, "wins config database", "wins_config.ldb");
3301 lpcfg_do_global_parameter(lp_ctx
, "wins database", "wins.ldb");
3302 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3304 /* This hive should be dynamically generated by Samba using
3305 data from the sam, but for the moment leave it in a tdb to
3306 keep regedt32 from popping up an annoying dialog. */
3307 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
3309 /* using UTF8 by default allows us to support all chars */
3310 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
3312 /* Use codepage 850 as a default for the dos character set */
3313 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
3316 * Allow the default PASSWD_CHAT to be overridden in local.h.
3318 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
3320 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
3321 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
3322 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
3323 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
3324 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
3326 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
3327 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
3328 "Samba %s", SAMBA_VERSION_STRING
);
3330 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
3332 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
3333 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
3334 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
3335 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
3336 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
3337 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
3338 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
3339 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
3340 lpcfg_do_global_parameter(lp_ctx
, "security", "USER");
3341 lpcfg_do_global_parameter(lp_ctx
, "paranoid server security", "True");
3342 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
3343 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
3344 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
3345 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
3346 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
3348 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
3349 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
3350 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
3351 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
3352 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
3353 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
3354 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
3355 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
3357 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
3359 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
3360 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
3362 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
3363 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
3365 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
3366 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
3367 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
3368 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
3369 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
3370 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3371 lpcfg_do_global_parameter(lp_ctx
, "idmap trusted only", "False");
3373 lpcfg_do_global_parameter(lp_ctx
, "client signing", "Yes");
3374 lpcfg_do_global_parameter(lp_ctx
, "server signing", "auto");
3376 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
3378 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
3379 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
3380 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
3381 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
3382 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
3383 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
3384 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
3386 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
3388 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
3389 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
3391 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
3392 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
3393 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
3394 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
3395 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
3397 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
3398 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
3399 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
3400 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
3401 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
3403 for (i
= 0; parm_table
[i
].label
; i
++) {
3404 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
3405 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3409 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3410 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3411 parm
->priority
|= FLAG_DEFAULT
;
3419 * Initialise the global parameter structure.
3421 struct loadparm_context
*loadparm_init_global(bool load_default
)
3423 if (global_loadparm_context
== NULL
) {
3424 global_loadparm_context
= loadparm_init(NULL
);
3426 if (global_loadparm_context
== NULL
) {
3429 global_loadparm_context
->global
= true;
3430 if (load_default
&& !global_loadparm_context
->loaded
) {
3431 lpcfg_load_default(global_loadparm_context
);
3433 global_loadparm_context
->refuse_free
= true;
3434 return global_loadparm_context
;
3438 * Initialise the global parameter structure.
3440 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3441 const struct loadparm_s3_context
*s3_fns
)
3443 struct loadparm_context
*loadparm_context
= loadparm_init(mem_ctx
);
3444 if (!loadparm_context
) {
3447 loadparm_context
->s3_fns
= s3_fns
;
3448 return loadparm_context
;
3451 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3453 return lp_ctx
->szConfigFile
;
3456 const char *lp_default_path(void)
3458 if (getenv("SMB_CONF_PATH"))
3459 return getenv("SMB_CONF_PATH");
3461 return dyn_CONFIGFILE
;
3465 * Update the internal state of a loadparm context after settings
3468 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3470 struct debug_settings settings
;
3471 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
3473 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
3474 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3477 if (!lp_ctx
->global
) {
3481 panic_action
= lp_ctx
->globals
->panic_action
;
3483 reload_charcnv(lp_ctx
);
3485 ZERO_STRUCT(settings
);
3486 /* Add any more debug-related smb.conf parameters created in
3488 settings
.timestamp_logs
= true;
3489 debug_set_settings(&settings
);
3491 /* FIXME: This is a bit of a hack, but we can't use a global, since
3492 * not everything that uses lp also uses the socket library */
3493 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3494 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3496 unsetenv("SOCKET_TESTNONBLOCK");
3502 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3506 path
= lp_default_path();
3508 if (!file_exist(path
)) {
3509 /* We allow the default smb.conf file to not exist,
3510 * basically the equivalent of an empty file. */
3511 return lpcfg_update(lp_ctx
);
3514 return lpcfg_load(lp_ctx
, path
);
3518 * Load the services array from the services file.
3520 * Return True on success, False on failure.
3522 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3527 filename
= talloc_strdup(lp_ctx
, filename
);
3529 lp_ctx
->szConfigFile
= filename
;
3531 if (lp_ctx
->s3_fns
) {
3532 return lp_ctx
->s3_fns
->load(filename
);
3535 lp_ctx
->bInGlobalSection
= true;
3536 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3537 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3539 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
3541 /* We get sections first, so have to start 'behind' to make up */
3542 lp_ctx
->currentService
= NULL
;
3543 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
3545 /* finish up the last section */
3546 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3548 if (lp_ctx
->currentService
!= NULL
)
3549 bRetval
= service_ok(lp_ctx
->currentService
);
3551 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3553 /* we do this unconditionally, so that it happens even
3554 for a missing smb.conf */
3555 reload_charcnv(lp_ctx
);
3557 if (bRetval
== true) {
3558 /* set this up so that any child python tasks will
3559 find the right smb.conf */
3560 setenv("SMB_CONF_PATH", filename
, 1);
3562 /* set the context used by the lp_*() function
3564 global_loadparm_context
= lp_ctx
;
3565 lp_ctx
->loaded
= true;
3572 * Return the max number of services.
3575 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3577 if (lp_ctx
->s3_fns
) {
3578 return lp_ctx
->s3_fns
->get_numservices();
3581 return lp_ctx
->iNumServices
;
3585 * Display the contents of the services array in human-readable form.
3588 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3593 if (lp_ctx
->s3_fns
) {
3594 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3598 defaults_saved
= !show_defaults
;
3600 dump_globals(lp_ctx
, f
, show_defaults
);
3602 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
3604 for (iService
= 0; iService
< maxtoprint
; iService
++)
3605 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3609 * Display the contents of one service in human-readable form.
3611 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3613 if (service
!= NULL
) {
3614 if (service
->szService
[0] == '\0')
3616 dump_a_service(service
, sDefault
, f
, NULL
);
3620 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3623 if (lp_ctx
->s3_fns
) {
3624 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3627 return lp_ctx
->services
[snum
];
3630 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3631 const char *service_name
)
3636 if (lp_ctx
->s3_fns
) {
3637 return lp_ctx
->s3_fns
->get_service(service_name
);
3640 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3641 if (lp_ctx
->services
[iService
] &&
3642 lp_ctx
->services
[iService
]->szService
) {
3644 * The substitution here is used to support %U is
3647 serviceName
= standard_sub_basic(
3648 lp_ctx
->services
[iService
],
3649 lp_ctx
->services
[iService
]->szService
);
3650 if (strequal(serviceName
, service_name
)) {
3651 talloc_free(serviceName
);
3652 return lp_ctx
->services
[iService
];
3654 talloc_free(serviceName
);
3658 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3662 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3664 return lp_string((const char *)service
->szService
);
3668 * A useful volume label function.
3670 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3673 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3674 service
->volume
: sDefault
->volume
));
3676 return lpcfg_servicename(service
);
3681 * If we are PDC then prefer us as DMB
3683 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3686 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
3687 service
->szPrintername
: sDefault
->szPrintername
));
3688 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3689 ret
= lpcfg_servicename(service
);
3696 * Return the max print jobs per queue.
3698 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3700 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
3701 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3702 maxjobs
= PRINT_MAX_JOBID
- 1;
3707 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3709 if (lp_ctx
== NULL
) {
3710 return get_iconv_handle();
3712 return lp_ctx
->iconv_handle
;
3715 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3717 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3718 if (!lp_ctx
->global
) {
3722 if (old_ic
== NULL
) {
3723 old_ic
= global_iconv_handle
;
3725 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3726 global_iconv_handle
= lp_ctx
->iconv_handle
;
3729 void lpcfg_smbcli_options(struct loadparm_context
*lp_ctx
,
3730 struct smbcli_options
*options
)
3732 options
->max_xmit
= lpcfg_max_xmit(lp_ctx
);
3733 options
->max_mux
= lpcfg_maxmux(lp_ctx
);
3734 options
->use_spnego
= lpcfg_nt_status_support(lp_ctx
) && lpcfg_use_spnego(lp_ctx
);
3735 options
->signing
= lpcfg_client_signing(lp_ctx
);
3736 options
->request_timeout
= SMB_REQUEST_TIMEOUT
;
3737 options
->ntstatus_support
= lpcfg_nt_status_support(lp_ctx
);
3738 options
->max_protocol
= lpcfg_cli_maxprotocol(lp_ctx
);
3739 options
->unicode
= lpcfg_unicode(lp_ctx
);
3740 options
->use_oplocks
= true;
3741 options
->use_level2_oplocks
= true;
3744 void lpcfg_smbcli_session_options(struct loadparm_context
*lp_ctx
,
3745 struct smbcli_session_options
*options
)
3747 options
->lanman_auth
= lpcfg_client_lanman_auth(lp_ctx
);
3748 options
->ntlmv2_auth
= lpcfg_client_ntlmv2_auth(lp_ctx
);
3749 options
->plaintext_auth
= lpcfg_client_plaintext_auth(lp_ctx
);
3752 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3754 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
3757 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3759 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
3762 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3764 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
3767 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3769 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
3772 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3774 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
3777 _PUBLIC_
struct dcerpc_server_info
*lpcfg_dcerpc_server_info(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3779 struct dcerpc_server_info
*ret
= talloc_zero(mem_ctx
, struct dcerpc_server_info
);
3781 ret
->domain_name
= talloc_reference(mem_ctx
, lpcfg_workgroup(lp_ctx
));
3782 ret
->version_major
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_major", 5);
3783 ret
->version_minor
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_minor", 2);
3784 ret
->version_build
= lpcfg_parm_int(lp_ctx
, NULL
, "server_info", "version_build", 3790);
3789 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3791 struct gensec_settings
*settings
= talloc(mem_ctx
, struct gensec_settings
);
3792 if (settings
== NULL
)
3794 SMB_ASSERT(lp_ctx
!= NULL
);
3795 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3796 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");