lib/param: Add .flags to wins parameters to match s3
[mat/samba.git] / lib / param / loadparm.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Parameter loading functions
4    Copyright (C) Karl Auer 1993-1998
5
6    Largely re-written by Andrew Tridgell, September 1994
7
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
14
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.
19
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.
24
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/>.
27 */
28
29 /*
30  *  Load parameters.
31  *
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.
35  *
36  * To add a parameter:
37  *
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
43  *
44  *
45  * Notes:
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
51  *   careful!
52  *
53  */
54
55 #include "includes.h"
56 #include "version.h"
57 #include "dynconfig/dynconfig.h"
58 #include "system/time.h"
59 #include "system/locale.h"
60 #include "system/network.h" /* needed for TCP_NODELAY */
61 #include "../lib/util/dlinklist.h"
62 #include "lib/param/param.h"
63 #include "lib/param/loadparm.h"
64 #include "auth/gensec/gensec.h"
65 #include "s3_param.h"
66 #include "lib/util/bitmap.h"
67 #include "libcli/smb/smb_constants.h"
68 #include "source4/dns_server/dns_update.h"
69
70 #define standard_sub_basic talloc_strdup
71
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved = false;
74
75 #define LOADPARM_EXTRA_GLOBALS \
76         struct parmlist_entry *param_opt;                               \
77         char *szRealm;                                                  \
78         char *tls_keyfile;                                              \
79         char *tls_certfile;                                             \
80         char *tls_cafile;                                               \
81         char *tls_crlfile;                                              \
82         char *tls_dhpfile;                                              \
83         char *loglevel;                                                 \
84         char *panic_action;                                             \
85         int server_role;                                                \
86         int security;                                                   \
87         int domain_master;                                              \
88         int domain_logons;                                              \
89         int bPreferredMaster;
90
91 #include "param_global.h"
92
93 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
94
95
96 /* prototypes for the special type handlers */
97 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
98                            const char *pszParmValue, char **ptr);
99 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
100                          const char *pszParmValue, char **ptr);
101 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
102                         const char *pszParmValue, char **ptr);
103 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
104                               const char *pszParmValue, char **ptr);
105 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
106                            const char *pszParmValue, char **ptr);
107
108 #include "param_enums.c"
109
110 #define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
111 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
112
113 static struct parm_struct parm_table[] = {
114         {
115                 .label          = "server role",
116                 .type           = P_ENUM,
117                 .p_class        = P_GLOBAL,
118                 .offset         = GLOBAL_VAR(server_role),
119                 .special        = NULL,
120                 .enum_list      = enum_server_role
121         },
122         {
123                 .label          = "domain logons",
124                 .type           = P_ENUM,
125                 .p_class        = P_GLOBAL,
126                 .offset         = GLOBAL_VAR(domain_logons),
127                 .special        = NULL,
128                 .enum_list      = enum_bool_auto
129         },
130         {
131                 .label          = "domain master",
132                 .type           = P_ENUM,
133                 .p_class        = P_GLOBAL,
134                 .offset         = GLOBAL_VAR(domain_master),
135                 .special        = NULL,
136                 .enum_list      = enum_bool_auto
137         },
138         {
139                 .label          = "dos charset",
140                 .type           = P_STRING,
141                 .p_class        = P_GLOBAL,
142                 .offset         = GLOBAL_VAR(dos_charset),
143                 .special        = NULL,
144                 .enum_list      = NULL
145         },
146         {
147                 .label          = "unix charset",
148                 .type           = P_STRING,
149                 .p_class        = P_GLOBAL,
150                 .offset         = GLOBAL_VAR(unix_charset),
151                 .special        = NULL,
152                 .enum_list      = NULL
153         },
154         {
155                 .label          = "ncalrpc dir",
156                 .type           = P_STRING,
157                 .p_class        = P_GLOBAL,
158                 .offset         = GLOBAL_VAR(ncalrpc_dir),
159                 .special        = NULL,
160                 .enum_list      = NULL
161         },
162         {
163                 .label          = "comment",
164                 .type           = P_STRING,
165                 .p_class        = P_LOCAL,
166                 .offset         = LOCAL_VAR(comment),
167                 .special        = NULL,
168                 .enum_list      = NULL,
169                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT
170         },
171         {
172                 .label          = "path",
173                 .type           = P_STRING,
174                 .p_class        = P_LOCAL,
175                 .offset         = LOCAL_VAR(szPath),
176                 .special        = NULL,
177                 .enum_list      = NULL,
178                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
179         },
180         {
181                 .label          = "directory",
182                 .type           = P_STRING,
183                 .p_class        = P_LOCAL,
184                 .offset         = LOCAL_VAR(szPath),
185                 .special        = NULL,
186                 .enum_list      = NULL,
187                 .flags          = FLAG_HIDE,
188         },
189         {
190                 .label          = "workgroup",
191                 .type           = P_USTRING,
192                 .p_class        = P_GLOBAL,
193                 .offset         = GLOBAL_VAR(szWorkgroup),
194                 .special        = NULL,
195                 .enum_list      = NULL,
196                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
197         },
198         {
199                 .label          = "realm",
200                 .type           = P_STRING,
201                 .p_class        = P_GLOBAL,
202                 .offset         = GLOBAL_VAR(szRealm),
203                 .special        = handle_realm,
204                 .enum_list      = NULL,
205                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
206         },
207         {
208                 .label          = "netbios name",
209                 .type           = P_USTRING,
210                 .p_class        = P_GLOBAL,
211                 .offset         = GLOBAL_VAR(szNetbiosName),
212                 .special        = NULL,
213                 .enum_list      = NULL,
214                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
215         },
216         {
217                 .label          = "netbios aliases",
218                 .type           = P_LIST,
219                 .p_class        = P_GLOBAL,
220                 .offset         = GLOBAL_VAR(szNetbiosAliases),
221                 .special        = NULL,
222                 .enum_list      = NULL
223         },
224         {
225                 .label          = "netbios scope",
226                 .type           = P_USTRING,
227                 .p_class        = P_GLOBAL,
228                 .offset         = GLOBAL_VAR(szNetbiosScope),
229                 .special        = NULL,
230                 .enum_list      = NULL,
231                 .flags          = FLAG_ADVANCED,
232         },
233         {
234                 .label          = "server string",
235                 .type           = P_STRING,
236                 .p_class        = P_GLOBAL,
237                 .offset         = GLOBAL_VAR(szServerString),
238                 .special        = NULL,
239                 .enum_list      = NULL,
240                 .flags          = FLAG_BASIC | FLAG_ADVANCED,
241         },
242         {
243                 .label          = "interfaces",
244                 .type           = P_LIST,
245                 .p_class        = P_GLOBAL,
246                 .offset         = GLOBAL_VAR(szInterfaces),
247                 .special        = NULL,
248                 .enum_list      = NULL,
249                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
250         },
251         {
252                 .label          = "bind interfaces only",
253                 .type           = P_BOOL,
254                 .p_class        = P_GLOBAL,
255                 .offset         = GLOBAL_VAR(bBindInterfacesOnly),
256                 .special        = NULL,
257                 .enum_list      = NULL,
258                 .flags          = FLAG_ADVANCED | FLAG_WIZARD,
259         },
260         {
261                 .label          = "ntvfs handler",
262                 .type           = P_LIST,
263                 .p_class        = P_LOCAL,
264                 .offset         = LOCAL_VAR(ntvfs_handler),
265                 .special        = NULL,
266                 .enum_list      = NULL
267         },
268         {
269                 .label          = "ntptr providor",
270                 .type           = P_STRING,
271                 .p_class        = P_GLOBAL,
272                 .offset         = GLOBAL_VAR(ntptr_providor),
273                 .special        = NULL,
274                 .enum_list      = NULL
275         },
276         {
277                 .label          = "passdb backend",
278                 .type           = P_STRING,
279                 .p_class        = P_GLOBAL,
280                 .offset         = GLOBAL_VAR(passdb_backend),
281                 .special        = NULL,
282                 .enum_list      = NULL
283         },
284         {
285                 .label          = "dcerpc endpoint servers",
286                 .type           = P_LIST,
287                 .p_class        = P_GLOBAL,
288                 .offset         = GLOBAL_VAR(dcerpc_ep_servers),
289                 .special        = NULL,
290                 .enum_list      = NULL
291         },
292         {
293                 .label          = "server services",
294                 .type           = P_LIST,
295                 .p_class        = P_GLOBAL,
296                 .offset         = GLOBAL_VAR(server_services),
297                 .special        = NULL,
298                 .enum_list      = NULL
299         },
300
301         {
302                 .label          = "security",
303                 .type           = P_ENUM,
304                 .p_class        = P_GLOBAL,
305                 .offset         = GLOBAL_VAR(security),
306                 .special        = NULL,
307                 .enum_list      = enum_security
308         },
309         {
310                 .label          = "encrypt passwords",
311                 .type           = P_BOOL,
312                 .p_class        = P_GLOBAL,
313                 .offset         = GLOBAL_VAR(bEncryptPasswords),
314                 .special        = NULL,
315                 .enum_list      = NULL
316         },
317         {
318                 .label          = "null passwords",
319                 .type           = P_BOOL,
320                 .p_class        = P_GLOBAL,
321                 .offset         = GLOBAL_VAR(bNullPasswords),
322                 .special        = NULL,
323                 .enum_list      = NULL,
324                 .flags          = FLAG_ADVANCED | FLAG_DEPRECATED,
325         },
326         {
327                 .label          = "obey pam restrictions",
328                 .type           = P_BOOL,
329                 .p_class        = P_GLOBAL,
330                 .offset         = GLOBAL_VAR(bObeyPamRestrictions),
331                 .special        = NULL,
332                 .enum_list      = NULL,
333                 .flags          = FLAG_ADVANCED,
334         },
335         {
336                 .label          = "password server",
337                 .type           = P_STRING,
338                 .p_class        = P_GLOBAL,
339                 .offset         = GLOBAL_VAR(szPasswordServer),
340                 .special        = NULL,
341                 .enum_list      = NULL
342         },
343         {
344                 .label          = "private dir",
345                 .type           = P_STRING,
346                 .p_class        = P_GLOBAL,
347                 .offset         = GLOBAL_VAR(szPrivateDir),
348                 .special        = NULL,
349                 .enum_list      = NULL
350         },
351         {
352                 .label          = "passwd chat",
353                 .type           = P_STRING,
354                 .p_class        = P_GLOBAL,
355                 .offset         = GLOBAL_VAR(szPasswdChat),
356                 .special        = NULL,
357                 .enum_list      = NULL
358         },
359         {
360                 .label          = "password level",
361                 .type           = P_INTEGER,
362                 .p_class        = P_GLOBAL,
363                 .offset         = GLOBAL_VAR(pwordlevel),
364                 .special        = NULL,
365                 .enum_list      = NULL
366         },
367         {
368                 .label          = "lanman auth",
369                 .type           = P_BOOL,
370                 .p_class        = P_GLOBAL,
371                 .offset         = GLOBAL_VAR(bLanmanAuth),
372                 .special        = NULL,
373                 .enum_list      = NULL,
374                 .flags          = FLAG_ADVANCED,
375         },
376         {
377                 .label          = "ntlm auth",
378                 .type           = P_BOOL,
379                 .p_class        = P_GLOBAL,
380                 .offset         = GLOBAL_VAR(bNTLMAuth),
381                 .special        = NULL,
382                 .enum_list      = NULL,
383                 .flags          = FLAG_ADVANCED,
384         },
385         {
386                 .label          = "client NTLMv2 auth",
387                 .type           = P_BOOL,
388                 .p_class        = P_GLOBAL,
389                 .offset         = GLOBAL_VAR(bClientNTLMv2Auth),
390                 .special        = NULL,
391                 .enum_list      = NULL,
392                 .flags          = FLAG_ADVANCED,
393         },
394         {
395                 .label          = "client lanman auth",
396                 .type           = P_BOOL,
397                 .p_class        = P_GLOBAL,
398                 .offset         = GLOBAL_VAR(bClientLanManAuth),
399                 .special        = NULL,
400                 .enum_list      = NULL,
401                 .flags          = FLAG_ADVANCED,
402         },
403         {
404                 .label          = "client plaintext auth",
405                 .type           = P_BOOL,
406                 .p_class        = P_GLOBAL,
407                 .offset         = GLOBAL_VAR(bClientPlaintextAuth),
408                 .special        = NULL,
409                 .enum_list      = NULL,
410                 .flags          = FLAG_ADVANCED,
411         },
412         {
413                 .label          = "client use spnego principal",
414                 .type           = P_BOOL,
415                 .p_class        = P_GLOBAL,
416                 .offset         = GLOBAL_VAR(client_use_spnego_principal),
417                 .special        = NULL,
418                 .enum_list      = NULL
419         },
420
421         {
422                 .label          = "read only",
423                 .type           = P_BOOL,
424                 .p_class        = P_LOCAL,
425                 .offset         = LOCAL_VAR(bRead_only),
426                 .special        = NULL,
427                 .enum_list      = NULL
428         },
429
430         {
431                 .label          = "create mask",
432                 .type           = P_OCTAL,
433                 .p_class        = P_LOCAL,
434                 .offset         = LOCAL_VAR(iCreate_mask),
435                 .special        = NULL,
436                 .enum_list      = NULL
437         },
438         {
439                 .label          = "force create mode",
440                 .type           = P_OCTAL,
441                 .p_class        = P_LOCAL,
442                 .offset         = LOCAL_VAR(iCreate_force_mode),
443                 .special        = NULL,
444                 .enum_list      = NULL
445         },
446         {
447                 .label          = "directory mask",
448                 .type           = P_OCTAL,
449                 .p_class        = P_LOCAL,
450                 .offset         = LOCAL_VAR(iDir_mask),
451                 .special        = NULL,
452                 .enum_list      = NULL
453         },
454         {
455                 .label          = "force directory mode",
456                 .type           = P_OCTAL,
457                 .p_class        = P_LOCAL,
458                 .offset         = LOCAL_VAR(iDir_force_mode),
459                 .special        = NULL,
460                 .enum_list      = NULL
461         },
462
463         {
464                 .label          = "hosts allow",
465                 .type           = P_LIST,
466                 .p_class        = P_LOCAL,
467                 .offset         = LOCAL_VAR(szHostsallow),
468                 .special        = NULL,
469                 .enum_list      = NULL
470         },
471         {
472                 .label          = "hosts deny",
473                 .type           = P_LIST,
474                 .p_class        = P_LOCAL,
475                 .offset         = LOCAL_VAR(szHostsdeny),
476                 .special        = NULL,
477                 .enum_list      = NULL
478         },
479
480         {
481                 .label          = "log level",
482                 .type           = P_STRING,
483                 .p_class        = P_GLOBAL,
484                 .offset         = GLOBAL_VAR(loglevel),
485                 .special        = handle_debuglevel,
486                 .enum_list      = NULL
487         },
488         {
489                 .label          = "debuglevel",
490                 .type           = P_STRING,
491                 .p_class        = P_GLOBAL,
492                 .offset         = GLOBAL_VAR(loglevel),
493                 .special        = handle_debuglevel,
494                 .enum_list      = NULL
495         },
496         {
497                 .label          = "log file",
498                 .type           = P_STRING,
499                 .p_class        = P_GLOBAL,
500                 .offset         = GLOBAL_VAR(logfile),
501                 .special        = handle_logfile,
502                 .enum_list      = NULL,
503                 .flags          = FLAG_ADVANCED,
504         },
505
506         {
507                 .label          = "smb ports",
508                 .type           = P_LIST,
509                 .p_class        = P_GLOBAL,
510                 .offset         = GLOBAL_VAR(smb_ports),
511                 .special        = NULL,
512                 .enum_list      = NULL
513         },
514         {
515                 .label          = "nbt port",
516                 .type           = P_INTEGER,
517                 .p_class        = P_GLOBAL,
518                 .offset         = GLOBAL_VAR(nbt_port),
519                 .special        = NULL,
520                 .enum_list      = NULL
521         },
522         {
523                 .label          = "dgram port",
524                 .type           = P_INTEGER,
525                 .p_class        = P_GLOBAL,
526                 .offset         = GLOBAL_VAR(dgram_port),
527                 .special        = NULL,
528                 .enum_list      = NULL
529         },
530         {
531                 .label          = "cldap port",
532                 .type           = P_INTEGER,
533                 .p_class        = P_GLOBAL,
534                 .offset         = GLOBAL_VAR(cldap_port),
535                 .special        = NULL,
536                 .enum_list      = NULL
537         },
538         {
539                 .label          = "krb5 port",
540                 .type           = P_INTEGER,
541                 .p_class        = P_GLOBAL,
542                 .offset         = GLOBAL_VAR(krb5_port),
543                 .special        = NULL,
544                 .enum_list      = NULL
545         },
546         {
547                 .label          = "kpasswd port",
548                 .type           = P_INTEGER,
549                 .p_class        = P_GLOBAL,
550                 .offset         = GLOBAL_VAR(kpasswd_port),
551                 .special        = NULL,
552                 .enum_list      = NULL
553         },
554         {
555                 .label          = "web port",
556                 .type           = P_INTEGER,
557                 .p_class        = P_GLOBAL,
558                 .offset         = GLOBAL_VAR(web_port),
559                 .special        = NULL,
560                 .enum_list      = NULL
561         },
562         {
563                 .label          = "tls enabled",
564                 .type           = P_BOOL,
565                 .p_class        = P_GLOBAL,
566                 .offset         = GLOBAL_VAR(tls_enabled),
567                 .special        = NULL,
568                 .enum_list      = NULL
569         },
570         {
571                 .label          = "tls keyfile",
572                 .type           = P_STRING,
573                 .p_class        = P_GLOBAL,
574                 .offset         = GLOBAL_VAR(tls_keyfile),
575                 .special        = NULL,
576                 .enum_list      = NULL
577         },
578         {
579                 .label          = "tls certfile",
580                 .type           = P_STRING,
581                 .p_class        = P_GLOBAL,
582                 .offset         = GLOBAL_VAR(tls_certfile),
583                 .special        = NULL,
584                 .enum_list      = NULL
585         },
586         {
587                 .label          = "tls cafile",
588                 .type           = P_STRING,
589                 .p_class        = P_GLOBAL,
590                 .offset         = GLOBAL_VAR(tls_cafile),
591                 .special        = NULL,
592                 .enum_list      = NULL
593         },
594         {
595                 .label          = "tls crlfile",
596                 .type           = P_STRING,
597                 .p_class        = P_GLOBAL,
598                 .offset         = GLOBAL_VAR(tls_crlfile),
599                 .special        = NULL,
600                 .enum_list      = NULL
601         },
602         {
603                 .label          = "tls dh params file",
604                 .type           = P_STRING,
605                 .p_class        = P_GLOBAL,
606                 .offset         = GLOBAL_VAR(tls_dhpfile),
607                 .special        = NULL,
608                 .enum_list      = NULL
609         },
610         {
611                 .label          = "large readwrite",
612                 .type           = P_BOOL,
613                 .p_class        = P_GLOBAL,
614                 .offset         = GLOBAL_VAR(bLargeReadwrite),
615                 .special        = NULL,
616                 .enum_list      = NULL,
617                 .flags          = FLAG_ADVANCED,
618         },
619         {
620                 .label          = "server max protocol",
621                 .type           = P_ENUM,
622                 .p_class        = P_GLOBAL,
623                 .offset         = GLOBAL_VAR(srv_maxprotocol),
624                 .special        = NULL,
625                 .enum_list      = enum_protocol
626         },
627         {
628                 .label          = "max protocol",
629                 .type           = P_ENUM,
630                 .p_class        = P_GLOBAL,
631                 .offset         = GLOBAL_VAR(srv_maxprotocol),
632                 .special        = NULL,
633                 .enum_list      = enum_protocol
634         },
635         {
636                 .label          = "protocol",
637                 .type           = P_ENUM,
638                 .p_class        = P_GLOBAL,
639                 .offset         = GLOBAL_VAR(srv_maxprotocol),
640                 .special        = NULL,
641                 .enum_list      = enum_protocol,
642                 .flags          = FLAG_ADVANCED,
643         },
644         {
645                 .label          = "server min protocol",
646                 .type           = P_ENUM,
647                 .p_class        = P_GLOBAL,
648                 .offset         = GLOBAL_VAR(srv_minprotocol),
649                 .special        = NULL,
650                 .enum_list      = enum_protocol
651         },
652         {
653                 .label          = "min protocol",
654                 .type           = P_ENUM,
655                 .p_class        = P_GLOBAL,
656                 .offset         = GLOBAL_VAR(srv_minprotocol),
657                 .special        = NULL,
658                 .enum_list      = enum_protocol
659         },
660         {
661                 .label          = "client max protocol",
662                 .type           = P_ENUM,
663                 .p_class        = P_GLOBAL,
664                 .offset         = GLOBAL_VAR(cli_maxprotocol),
665                 .special        = NULL,
666                 .enum_list      = enum_protocol
667         },
668         {
669                 .label          = "client min protocol",
670                 .type           = P_ENUM,
671                 .p_class        = P_GLOBAL,
672                 .offset         = GLOBAL_VAR(cli_minprotocol),
673                 .special        = NULL,
674                 .enum_list      = enum_protocol
675         },
676         {
677                 .label          = "unicode",
678                 .type           = P_BOOL,
679                 .p_class        = P_GLOBAL,
680                 .offset         = GLOBAL_VAR(bUnicode),
681                 .special        = NULL,
682                 .enum_list      = NULL
683         },
684         {
685                 .label          = "read raw",
686                 .type           = P_BOOL,
687                 .p_class        = P_GLOBAL,
688                 .offset         = GLOBAL_VAR(bReadRaw),
689                 .special        = NULL,
690                 .enum_list      = NULL
691         },
692         {
693                 .label          = "write raw",
694                 .type           = P_BOOL,
695                 .p_class        = P_GLOBAL,
696                 .offset         = GLOBAL_VAR(bWriteRaw),
697                 .special        = NULL,
698                 .enum_list      = NULL
699         },
700         {
701                 .label          = "disable netbios",
702                 .type           = P_BOOL,
703                 .p_class        = P_GLOBAL,
704                 .offset         = GLOBAL_VAR(bDisableNetbios),
705                 .special        = NULL,
706                 .enum_list      = NULL
707         },
708
709         {
710                 .label          = "nt status support",
711                 .type           = P_BOOL,
712                 .p_class        = P_GLOBAL,
713                 .offset         = GLOBAL_VAR(bNTStatusSupport),
714                 .special        = NULL,
715                 .enum_list      = NULL
716         },
717
718         {
719                 .label          = "max mux",
720                 .type           = P_INTEGER,
721                 .p_class        = P_GLOBAL,
722                 .offset         = GLOBAL_VAR(max_mux),
723                 .special        = NULL,
724                 .enum_list      = NULL,
725                 .flags          = FLAG_ADVANCED,
726         },
727         {
728                 .label          = "max xmit",
729                 .type           = P_BYTES,
730                 .p_class        = P_GLOBAL,
731                 .offset         = GLOBAL_VAR(max_xmit),
732                 .special        = NULL,
733                 .enum_list      = NULL,
734                 .flags          = FLAG_ADVANCED,
735         },
736
737         {
738                 .label          = "name resolve order",
739                 .type           = P_LIST,
740                 .p_class        = P_GLOBAL,
741                 .offset         = GLOBAL_VAR(szNameResolveOrder),
742                 .special        = NULL,
743                 .enum_list      = NULL
744         },
745         {
746                 .label          = "max wins ttl",
747                 .type           = P_INTEGER,
748                 .p_class        = P_GLOBAL,
749                 .offset         = GLOBAL_VAR(max_wins_ttl),
750                 .special        = NULL,
751                 .enum_list      = NULL,
752                 .flags          = FLAG_ADVANCED,
753         },
754         {
755                 .label          = "min wins ttl",
756                 .type           = P_INTEGER,
757                 .p_class        = P_GLOBAL,
758                 .offset         = GLOBAL_VAR(min_wins_ttl),
759                 .special        = NULL,
760                 .enum_list      = NULL,
761                 .flags          = FLAG_ADVANCED,
762         },
763         {
764                 .label          = "time server",
765                 .type           = P_BOOL,
766                 .p_class        = P_GLOBAL,
767                 .offset         = GLOBAL_VAR(bTimeServer),
768                 .special        = NULL,
769                 .enum_list      = NULL,
770                 .flags          = FLAG_ADVANCED,
771         },
772         {
773                 .label          = "unix extensions",
774                 .type           = P_BOOL,
775                 .p_class        = P_GLOBAL,
776                 .offset         = GLOBAL_VAR(bUnixExtensions),
777                 .special        = NULL,
778                 .enum_list      = NULL,
779                 .flags          = FLAG_ADVANCED,
780         },
781         {
782                 .label          = "use spnego",
783                 .type           = P_BOOL,
784                 .p_class        = P_GLOBAL,
785                 .offset         = GLOBAL_VAR(bUseSpnego),
786                 .special        = NULL,
787                 .enum_list      = NULL
788         },
789         {
790                 .label          = "server signing",
791                 .type           = P_ENUM,
792                 .p_class        = P_GLOBAL,
793                 .offset         = GLOBAL_VAR(server_signing),
794                 .special        = NULL,
795                 .enum_list      = enum_smb_signing_vals,
796                 .flags          = FLAG_ADVANCED,
797         },
798         {
799                 .label          = "client signing",
800                 .type           = P_ENUM,
801                 .p_class        = P_GLOBAL,
802                 .offset         = GLOBAL_VAR(client_signing),
803                 .special        = NULL,
804                 .enum_list      = enum_smb_signing_vals
805         },
806         {
807                 .label          = "rpc big endian",
808                 .type           = P_BOOL,
809                 .p_class        = P_GLOBAL,
810                 .offset         = GLOBAL_VAR(bRpcBigEndian),
811                 .special        = NULL,
812                 .enum_list      = NULL
813         },
814
815         {
816                 .label          = "max connections",
817                 .type           = P_INTEGER,
818                 .p_class        = P_LOCAL,
819                 .offset         = LOCAL_VAR(iMaxConnections),
820                 .special        = NULL,
821                 .enum_list      = NULL,
822                 .flags          = FLAG_ADVANCED | FLAG_SHARE,
823         },
824         {
825                 .label          = "paranoid server security",
826                 .type           = P_BOOL,
827                 .p_class        = P_GLOBAL,
828                 .offset         = GLOBAL_VAR(paranoid_server_security),
829                 .special        = NULL,
830                 .enum_list      = NULL
831         },
832         {
833                 .label          = "socket options",
834                 .type           = P_STRING,
835                 .p_class        = P_GLOBAL,
836                 .offset         = GLOBAL_VAR(socket_options),
837                 .special        = NULL,
838                 .enum_list      = NULL
839         },
840
841         {
842                 .label          = "strict sync",
843                 .type           = P_BOOL,
844                 .p_class        = P_LOCAL,
845                 .offset         = LOCAL_VAR(bStrictSync),
846                 .special        = NULL,
847                 .enum_list      = NULL
848         },
849         {
850                 .label          = "use mmap",
851                 .type           = P_BOOL,
852                 .p_class        = P_GLOBAL,
853                 .offset         = GLOBAL_VAR(bUseMmap),
854                 .special        = NULL,
855                 .enum_list      = NULL,
856                 .flags          = FLAG_ADVANCED,
857         },
858         {
859                 .label          = "case insensitive filesystem",
860                 .type           = P_BOOL,
861                 .p_class        = P_LOCAL,
862                 .offset         = LOCAL_VAR(bCIFileSystem),
863                 .special        = NULL,
864                 .enum_list      = NULL
865         },
866
867         {
868                 .label          = "max print jobs",
869                 .type           = P_INTEGER,
870                 .p_class        = P_LOCAL,
871                 .offset         = LOCAL_VAR(iMaxPrintJobs),
872                 .special        = NULL,
873                 .enum_list      = NULL
874         },
875         {
876                 .label          = "printable",
877                 .type           = P_BOOL,
878                 .p_class        = P_LOCAL,
879                 .offset         = LOCAL_VAR(bPrint_ok),
880                 .special        = NULL,
881                 .enum_list      = NULL
882         },
883         {
884                 .label          = "print ok",
885                 .type           = P_BOOL,
886                 .p_class        = P_LOCAL,
887                 .offset         = LOCAL_VAR(bPrint_ok),
888                 .special        = NULL,
889                 .enum_list      = NULL
890         },
891
892         {
893                 .label          = "printer name",
894                 .type           = P_STRING,
895                 .p_class        = P_LOCAL,
896                 .offset         = LOCAL_VAR(szPrintername),
897                 .special        = NULL,
898                 .enum_list      = NULL,
899                 .flags          = FLAG_ADVANCED | FLAG_PRINT,
900         },
901         {
902                 .label          = "printer",
903                 .type           = P_STRING,
904                 .p_class        = P_LOCAL,
905                 .offset         = LOCAL_VAR(szPrintername),
906                 .special        = NULL,
907                 .enum_list      = NULL,
908                 .flags          = FLAG_HIDE,
909         },
910
911         {
912                 .label          = "map system",
913                 .type           = P_BOOL,
914                 .p_class        = P_LOCAL,
915                 .offset         = LOCAL_VAR(bMap_system),
916                 .special        = NULL,
917                 .enum_list      = NULL
918         },
919         {
920                 .label          = "map hidden",
921                 .type           = P_BOOL,
922                 .p_class        = P_LOCAL,
923                 .offset         = LOCAL_VAR(bMap_hidden),
924                 .special        = NULL,
925                 .enum_list      = NULL
926         },
927         {
928                 .label          = "map archive",
929                 .type           = P_BOOL,
930                 .p_class        = P_LOCAL,
931                 .offset         = LOCAL_VAR(bMap_archive),
932                 .special        = NULL,
933                 .enum_list      = NULL
934         },
935
936         {
937                 .label          = "preferred master",
938                 .type           = P_ENUM,
939                 .p_class        = P_GLOBAL,
940                 .offset         = GLOBAL_VAR(bPreferredMaster),
941                 .special        = NULL,
942                 .enum_list      = enum_bool_auto,
943                 .flags          = FLAG_BASIC | FLAG_ADVANCED,
944         },
945         {
946                 .label          = "prefered master",
947                 .type           = P_ENUM,
948                 .p_class        = P_GLOBAL,
949                 .offset         = GLOBAL_VAR(bPreferredMaster),
950                 .special        = NULL,
951                 .enum_list      = enum_bool_auto,
952                 .flags          = FLAG_HIDE,
953         },
954         {
955                 .label          = "local master",
956                 .type           = P_BOOL,
957                 .p_class        = P_GLOBAL,
958                 .offset         = GLOBAL_VAR(bLocalMaster),
959                 .special        = NULL,
960                 .enum_list      = NULL
961         },
962         {
963                 .label          = "browseable",
964                 .type           = P_BOOL,
965                 .p_class        = P_LOCAL,
966                 .offset         = LOCAL_VAR(bBrowseable),
967                 .special        = NULL,
968                 .enum_list      = NULL,
969                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
970         },
971         {
972                 .label          = "browsable",
973                 .type           = P_BOOL,
974                 .p_class        = P_LOCAL,
975                 .offset         = LOCAL_VAR(bBrowseable),
976                 .special        = NULL,
977                 .enum_list      = NULL
978         },
979
980         {
981                 .label          = "dns proxy",
982                 .type           = P_BOOL,
983                 .p_class        = P_GLOBAL,
984                 .offset         = GLOBAL_VAR(bWINSdnsProxy),
985                 .special        = NULL,
986                 .enum_list      = NULL
987         },
988         {
989                 .label          = "wins server",
990                 .type           = P_LIST,
991                 .p_class        = P_GLOBAL,
992                 .offset         = GLOBAL_VAR(szWINSservers),
993                 .special        = NULL,
994                 .enum_list      = NULL,
995                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
996         },
997         {
998                 .label          = "wins support",
999                 .type           = P_BOOL,
1000                 .p_class        = P_GLOBAL,
1001                 .offset         = GLOBAL_VAR(bWINSsupport),
1002                 .special        = NULL,
1003                 .enum_list      = NULL,
1004                 .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
1005         },
1006         {
1007                 .label          = "wins hook",
1008                 .type           = P_STRING,
1009                 .p_class        = P_GLOBAL,
1010                 .offset         = GLOBAL_VAR(szWINSHook),
1011                 .special        = NULL,
1012                 .enum_list      = NULL,
1013                 .flags          = FLAG_ADVANCED,
1014         },
1015
1016         {
1017                 .label          = "csc policy",
1018                 .type           = P_ENUM,
1019                 .p_class        = P_LOCAL,
1020                 .offset         = LOCAL_VAR(iCSCPolicy),
1021                 .special        = NULL,
1022                 .enum_list      = enum_csc_policy,
1023                 .flags          = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
1024         },
1025
1026         {
1027                 .label          = "strict locking",
1028                 .type           = P_BOOL,
1029                 .p_class        = P_LOCAL,
1030                 .offset         = LOCAL_VAR(iStrictLocking),
1031                 .special        = NULL,
1032                 .enum_list      = NULL
1033         },
1034         {
1035                 .label          = "oplocks",
1036                 .type           = P_BOOL,
1037                 .p_class        = P_LOCAL,
1038                 .offset         = LOCAL_VAR(bOpLocks),
1039                 .special        = NULL,
1040                 .enum_list      = NULL
1041         },
1042
1043         {
1044                 .label          = "share backend",
1045                 .type           = P_STRING,
1046                 .p_class        = P_GLOBAL,
1047                 .offset         = GLOBAL_VAR(szShareBackend),
1048                 .special        = NULL,
1049                 .enum_list      = NULL
1050         },
1051         {
1052                 .label          = "preload",
1053                 .type           = P_STRING,
1054                 .p_class        = P_GLOBAL,
1055                 .offset         = GLOBAL_VAR(szAutoServices),
1056                 .special        = NULL,
1057                 .enum_list      = NULL,
1058                 .flags          = FLAG_ADVANCED,
1059         },
1060         {
1061                 .label          = "auto services",
1062                 .type           = P_STRING,
1063                 .p_class        = P_GLOBAL,
1064                 .offset         = GLOBAL_VAR(szAutoServices),
1065                 .special        = NULL,
1066                 .enum_list      = NULL,
1067                 .flags          = FLAG_ADVANCED,
1068         },
1069         {
1070                 .label          = "lock directory",
1071                 .type           = P_STRING,
1072                 .p_class        = P_GLOBAL,
1073                 .offset         = GLOBAL_VAR(szLockDir),
1074                 .special        = NULL,
1075                 .enum_list      = NULL,
1076                 .flags          = FLAG_ADVANCED,
1077         },
1078         {
1079                 .label          = "lock dir",
1080                 .type           = P_STRING,
1081                 .p_class        = P_GLOBAL,
1082                 .offset         = GLOBAL_VAR(szLockDir),
1083                 .special        = NULL,
1084                 .enum_list      = NULL,
1085                 .flags          = FLAG_HIDE,
1086         },
1087         {
1088                 .label          = "state directory",
1089                 .type           = P_STRING,
1090                 .p_class        = P_GLOBAL,
1091                 .offset         = GLOBAL_VAR(szStateDir),
1092                 .special        = NULL,
1093                 .enum_list      = NULL,
1094                 .flags          = FLAG_ADVANCED,
1095         },
1096         {
1097                 .label          = "cache directory",
1098                 .type           = P_STRING,
1099                 .p_class        = P_GLOBAL,
1100                 .offset         = GLOBAL_VAR(szCacheDir),
1101                 .special        = NULL,
1102                 .enum_list      = NULL,
1103                 .flags          = FLAG_ADVANCED,
1104         },
1105         {
1106                 .label          = "pid directory",
1107                 .type           = P_STRING,
1108                 .p_class        = P_GLOBAL,
1109                 .offset         = GLOBAL_VAR(szPidDir),
1110                 .special        = NULL,
1111                 .enum_list      = NULL
1112         },
1113
1114         {
1115                 .label          = "socket address",
1116                 .type           = P_STRING,
1117                 .p_class        = P_GLOBAL,
1118                 .offset         = GLOBAL_VAR(szSocketAddress),
1119                 .special        = NULL,
1120                 .enum_list      = NULL
1121         },
1122         {
1123                 .label          = "copy",
1124                 .type           = P_STRING,
1125                 .p_class        = P_LOCAL,
1126                 .offset         = LOCAL_VAR(szCopy),
1127                 .special        = handle_copy,
1128                 .enum_list      = NULL,
1129                 .flags          = FLAG_HIDE,
1130         },
1131         {
1132                 .label          = "include",
1133                 .type           = P_STRING,
1134                 .p_class        = P_LOCAL,
1135                 .offset         = LOCAL_VAR(szInclude),
1136                 .special        = handle_include,
1137                 .enum_list      = NULL
1138         },
1139
1140         {
1141                 .label          = "available",
1142                 .type           = P_BOOL,
1143                 .p_class        = P_LOCAL,
1144                 .offset         = LOCAL_VAR(bAvailable),
1145                 .special        = NULL,
1146                 .enum_list      = NULL
1147         },
1148         {
1149                 .label          = "volume",
1150                 .type           = P_STRING,
1151                 .p_class        = P_LOCAL,
1152                 .offset         = LOCAL_VAR(volume),
1153                 .special        = NULL,
1154                 .enum_list      = NULL,
1155                 .flags          = FLAG_ADVANCED | FLAG_SHARE,
1156         },
1157         {
1158                 .label          = "fstype",
1159                 .type           = P_STRING,
1160                 .p_class        = P_LOCAL,
1161                 .offset         = LOCAL_VAR(fstype),
1162                 .special        = NULL,
1163                 .enum_list      = NULL
1164         },
1165
1166         {
1167                 .label          = "panic action",
1168                 .type           = P_STRING,
1169                 .p_class        = P_GLOBAL,
1170                 .offset         = GLOBAL_VAR(panic_action),
1171                 .special        = NULL,
1172                 .enum_list      = NULL
1173         },
1174
1175         {
1176                 .label          = "msdfs root",
1177                 .type           = P_BOOL,
1178                 .p_class        = P_LOCAL,
1179                 .offset         = LOCAL_VAR(bMSDfsRoot),
1180                 .special        = NULL,
1181                 .enum_list      = NULL
1182         },
1183         {
1184                 .label          = "host msdfs",
1185                 .type           = P_BOOL,
1186                 .p_class        = P_GLOBAL,
1187                 .offset         = GLOBAL_VAR(bHostMSDfs),
1188                 .special        = NULL,
1189                 .enum_list      = NULL,
1190                 .flags          = FLAG_ADVANCED,
1191         },
1192         {
1193                 .label          = "winbind separator",
1194                 .type           = P_STRING,
1195                 .p_class        = P_GLOBAL,
1196                 .offset         = GLOBAL_VAR(szWinbindSeparator),
1197                 .special        = NULL,
1198                 .enum_list      = NULL
1199         },
1200         {
1201                 .label          = "winbindd socket directory",
1202                 .type           = P_STRING,
1203                 .p_class        = P_GLOBAL,
1204                 .offset         = GLOBAL_VAR(szWinbinddSocketDirectory),
1205                 .special        = NULL,
1206                 .enum_list      = NULL,
1207                 .flags          = FLAG_ADVANCED,
1208         },
1209         {
1210                 .label          = "winbindd privileged socket directory",
1211                 .type           = P_STRING,
1212                 .p_class        = P_GLOBAL,
1213                 .offset         = GLOBAL_VAR(szWinbinddPrivilegedSocketDirectory),
1214                 .special        = NULL,
1215                 .enum_list      = NULL,
1216                 .flags          = FLAG_ADVANCED,
1217         },
1218         {
1219                 .label          = "winbind sealed pipes",
1220                 .type           = P_BOOL,
1221                 .p_class        = P_GLOBAL,
1222                 .offset         = GLOBAL_VAR(bWinbindSealedPipes),
1223                 .special        = NULL,
1224                 .enum_list      = NULL,
1225                 .flags          = FLAG_ADVANCED,
1226         },
1227         {
1228                 .label          = "template shell",
1229                 .type           = P_STRING,
1230                 .p_class        = P_GLOBAL,
1231                 .offset         = GLOBAL_VAR(szTemplateShell),
1232                 .special        = NULL,
1233                 .enum_list      = NULL,
1234                 .flags          = FLAG_ADVANCED,
1235         },
1236         {
1237                 .label          = "template homedir",
1238                 .type           = P_STRING,
1239                 .p_class        = P_GLOBAL,
1240                 .offset         = GLOBAL_VAR(szTemplateHomedir),
1241                 .special        = NULL,
1242                 .enum_list      = NULL,
1243                 .flags          = FLAG_ADVANCED,
1244         },
1245         {
1246                 .label          = "idmap trusted only",
1247                 .type           = P_BOOL,
1248                 .p_class        = P_GLOBAL,
1249                 .offset         = GLOBAL_VAR(bIdmapTrustedOnly),
1250                 .special        = NULL,
1251                 .enum_list      = NULL,
1252                 .flags          = FLAG_ADVANCED,
1253         },
1254
1255         {
1256                 .label          = "ntp signd socket directory",
1257                 .type           = P_STRING,
1258                 .p_class        = P_GLOBAL,
1259                 .offset         = GLOBAL_VAR(szNTPSignDSocketDirectory),
1260                 .special        = NULL,
1261                 .enum_list      = NULL,
1262                 .flags          = FLAG_ADVANCED,
1263         },
1264         {
1265                 .label          = "rndc command",
1266                 .type           = P_CMDLIST,
1267                 .p_class        = P_GLOBAL,
1268                 .offset         = GLOBAL_VAR(szRNDCCommand),
1269                 .special        = NULL,
1270                 .enum_list      = NULL,
1271                 .flags          = FLAG_ADVANCED,
1272         },
1273         {
1274                 .label          = "dns update command",
1275                 .type           = P_CMDLIST,
1276                 .p_class        = P_GLOBAL,
1277                 .offset         = GLOBAL_VAR(szDNSUpdateCommand),
1278                 .special        = NULL,
1279                 .enum_list      = NULL,
1280                 .flags          = FLAG_ADVANCED,
1281         },
1282         {
1283                 .label          = "spn update command",
1284                 .type           = P_CMDLIST,
1285                 .p_class        = P_GLOBAL,
1286                 .offset         = GLOBAL_VAR(szSPNUpdateCommand),
1287                 .special        = NULL,
1288                 .enum_list      = NULL,
1289                 .flags          = FLAG_ADVANCED,
1290         },
1291         {
1292                 .label          = "samba kcc command",
1293                 .type           = P_CMDLIST,
1294                 .p_class        = P_GLOBAL,
1295                 .offset         = GLOBAL_VAR(szSambaKCCCommand),
1296                 .special        = NULL,
1297                 .enum_list      = NULL,
1298                 .flags          = FLAG_ADVANCED,
1299         },
1300         {
1301                 .label          = "nsupdate command",
1302                 .type           = P_CMDLIST,
1303                 .p_class        = P_GLOBAL,
1304                 .offset         = GLOBAL_VAR(szNSUpdateCommand),
1305                 .special        = NULL,
1306                 .enum_list      = NULL,
1307                 .flags          = FLAG_ADVANCED,
1308         },
1309         {
1310                 .label          = "allow dns updates",
1311                 .type           = P_ENUM,
1312                 .p_class        = P_GLOBAL,
1313                 .offset         = GLOBAL_VAR(allow_dns_updates),
1314                 .special        = NULL,
1315                 .enum_list      = enum_dns_update_settings,
1316                 .flags          = FLAG_ADVANCED,
1317         },
1318         {
1319                 .label          = "dns forwarder",
1320                 .type           = P_STRING,
1321                 .p_class        = P_GLOBAL,
1322                 .offset         = GLOBAL_VAR(dns_forwarder),
1323                 .special        = NULL,
1324                 .enum_list      = NULL,
1325                 .flags          = FLAG_ADVANCED,
1326         },
1327         {
1328                 .label          = "dns recursive queries",
1329                 .type           = P_BOOL,
1330                 .p_class        = P_GLOBAL,
1331                 .offset         = GLOBAL_VAR(dns_recursive_queries),
1332                 .special        = NULL,
1333                 .enum_list      = NULL
1334         },
1335
1336         {NULL,  P_BOOL,  P_NONE,  0,  NULL,  NULL,  0}
1337 };
1338
1339
1340 /* local variables */
1341 struct loadparm_context {
1342         const char *szConfigFile;
1343         struct loadparm_global *globals;
1344         struct loadparm_service **services;
1345         struct loadparm_service *sDefault;
1346         struct smb_iconv_handle *iconv_handle;
1347         int iNumServices;
1348         struct loadparm_service *currentService;
1349         bool bInGlobalSection;
1350         struct file_lists {
1351                 struct file_lists *next;
1352                 char *name;
1353                 char *subfname;
1354                 time_t modtime;
1355         } *file_lists;
1356         unsigned int flags[NUMPARAMETERS];
1357         bool loaded;
1358         bool refuse_free;
1359         bool global; /* Is this the global context, which may set
1360                       * global variables such as debug level etc? */
1361         const struct loadparm_s3_context *s3_fns;
1362 };
1363
1364
1365 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
1366 {
1367         if (lp_ctx->s3_fns) {
1368                 return lp_ctx->s3_fns->get_default_loadparm_service();
1369         }
1370         return lp_ctx->sDefault;
1371 }
1372
1373 /**
1374  * Convenience routine to grab string parameters into temporary memory
1375  * and run standard_sub_basic on them.
1376  *
1377  * The buffers can be written to by
1378  * callers without affecting the source string.
1379  */
1380
1381 static const char *lp_string(const char *s)
1382 {
1383 #if 0  /* until REWRITE done to make thread-safe */
1384         size_t len = s ? strlen(s) : 0;
1385         char *ret;
1386 #endif
1387
1388         /* The follow debug is useful for tracking down memory problems
1389            especially if you have an inner loop that is calling a lp_*()
1390            function that returns a string.  Perhaps this debug should be
1391            present all the time? */
1392
1393 #if 0
1394         DEBUG(10, ("lp_string(%s)\n", s));
1395 #endif
1396
1397 #if 0  /* until REWRITE done to make thread-safe */
1398         if (!lp_talloc)
1399                 lp_talloc = talloc_init("lp_talloc");
1400
1401         ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
1402
1403         if (!ret)
1404                 return NULL;
1405
1406         if (!s)
1407                 *ret = 0;
1408         else
1409                 strlcpy(ret, s, len);
1410
1411         if (trim_string(ret, "\"", "\"")) {
1412                 if (strchr(ret,'"') != NULL)
1413                         strlcpy(ret, s, len);
1414         }
1415
1416         standard_sub_basic(ret,len+100);
1417         return (ret);
1418 #endif
1419         return s;
1420 }
1421
1422 /*
1423    In this section all the functions that are used to access the
1424    parameters from the rest of the program are defined
1425 */
1426
1427 /*
1428  * the creation of separate lpcfg_*() and lp_*() functions is to allow
1429  * for code compatibility between existing Samba4 and Samba3 code.
1430  */
1431
1432 /* this global context supports the lp_*() function varients */
1433 static struct loadparm_context *global_loadparm_context;
1434
1435 #define lpcfg_default_service global_loadparm_context->sDefault
1436 #define lpcfg_global_service(i) global_loadparm_context->services[i]
1437
1438 #define FN_GLOBAL_STRING(fn_name,var_name)                              \
1439  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1440         if (lp_ctx == NULL) return NULL;                                \
1441         if (lp_ctx->s3_fns) {                                           \
1442                 SMB_ASSERT(lp_ctx->s3_fns->fn_name);                    \
1443                 return lp_ctx->s3_fns->fn_name();                       \
1444         }                                                               \
1445         return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1446 }
1447
1448 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
1449  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1450          if (lp_ctx == NULL) return NULL;                               \
1451          if (lp_ctx->s3_fns) {                                          \
1452                  SMB_ASSERT(lp_ctx->s3_fns->fn_name);                   \
1453                  return lp_ctx->s3_fns->fn_name();                      \
1454          }                                                              \
1455          return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
1456  }
1457
1458 #define FN_GLOBAL_LIST(fn_name,var_name)                                \
1459  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1460          if (lp_ctx == NULL) return NULL;                               \
1461          if (lp_ctx->s3_fns) {                                          \
1462                  SMB_ASSERT(lp_ctx->s3_fns->fn_name);                   \
1463                  return lp_ctx->s3_fns->fn_name();                      \
1464          }                                                              \
1465          return lp_ctx->globals->var_name;                              \
1466  }
1467
1468 #define FN_GLOBAL_BOOL(fn_name,var_name) \
1469  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
1470          if (lp_ctx == NULL) return false;                              \
1471          if (lp_ctx->s3_fns) {                                          \
1472                  SMB_ASSERT(lp_ctx->s3_fns->fn_name);                   \
1473                  return lp_ctx->s3_fns->fn_name();                      \
1474          }                                                              \
1475          return lp_ctx->globals->var_name;                              \
1476 }
1477
1478 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
1479  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
1480          if (lp_ctx->s3_fns) {                                          \
1481                  SMB_ASSERT(lp_ctx->s3_fns->fn_name);                   \
1482                  return lp_ctx->s3_fns->fn_name();                      \
1483          }                                                              \
1484          return lp_ctx->globals->var_name;                              \
1485  }
1486
1487 /* Local parameters don't need the ->s3_fns because the struct
1488  * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
1489  * hook */
1490 #define FN_LOCAL_STRING(fn_name,val) \
1491  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
1492                                         struct loadparm_service *sDefault) { \
1493          return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
1494  }
1495
1496 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
1497
1498 #define FN_LOCAL_LIST(fn_name,val) \
1499  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
1500                                          struct loadparm_service *sDefault) {\
1501          return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
1502  }
1503
1504 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
1505
1506 #define FN_LOCAL_BOOL(fn_name,val) \
1507  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
1508                                  struct loadparm_service *sDefault) {   \
1509          return((service != NULL)? service->val : sDefault->val); \
1510  }
1511
1512 #define FN_LOCAL_INTEGER(fn_name,val) \
1513  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
1514                                 struct loadparm_service *sDefault) {    \
1515          return((service != NULL)? service->val : sDefault->val); \
1516  }
1517
1518 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
1519
1520 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
1521
1522 #define FN_LOCAL_CHAR(fn_name,val) \
1523  _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
1524                                 struct loadparm_service *sDefault) {    \
1525          return((service != NULL)? service->val : sDefault->val); \
1526  }
1527
1528 #include "lib/param/param_functions.c"
1529
1530 FN_GLOBAL_LIST(smb_ports, smb_ports)
1531 FN_GLOBAL_INTEGER(nbt_port, nbt_port)
1532 FN_GLOBAL_INTEGER(dgram_port, dgram_port)
1533 FN_GLOBAL_INTEGER(cldap_port, cldap_port)
1534 FN_GLOBAL_INTEGER(krb5_port, krb5_port)
1535 FN_GLOBAL_INTEGER(kpasswd_port, kpasswd_port)
1536 FN_GLOBAL_INTEGER(web_port, web_port)
1537 FN_GLOBAL_BOOL(tls_enabled, tls_enabled)
1538 FN_GLOBAL_STRING(logfile, logfile)
1539 FN_GLOBAL_STRING(share_backend, szShareBackend)
1540 FN_GLOBAL_CONST_STRING(winbind_separator, szWinbindSeparator)
1541 FN_GLOBAL_CONST_STRING(winbindd_socket_directory, szWinbinddSocketDirectory)
1542 FN_GLOBAL_CONST_STRING(winbindd_privileged_socket_directory, szWinbinddPrivilegedSocketDirectory)
1543 FN_GLOBAL_CONST_STRING(template_shell, szTemplateShell)
1544 FN_GLOBAL_CONST_STRING(template_homedir, szTemplateHomedir)
1545 FN_GLOBAL_BOOL(winbind_sealed_pipes, bWinbindSealedPipes)
1546 FN_GLOBAL_BOOL(idmap_trusted_only, bIdmapTrustedOnly)
1547 FN_GLOBAL_STRING(private_dir, szPrivateDir)
1548 FN_GLOBAL_STRING(serverstring, szServerString)
1549 FN_GLOBAL_STRING(lockdir, szLockDir)
1550 FN_GLOBAL_STRING(statedir, szStateDir)
1551 FN_GLOBAL_STRING(cachedir, szCacheDir)
1552 FN_GLOBAL_STRING(ncalrpc_dir, ncalrpc_dir)
1553 FN_GLOBAL_STRING(dos_charset, dos_charset)
1554 FN_GLOBAL_STRING(unix_charset, unix_charset)
1555 FN_GLOBAL_STRING(piddir, szPidDir)
1556 FN_GLOBAL_LIST(rndc_command, szRNDCCommand)
1557 FN_GLOBAL_LIST(dns_update_command, szDNSUpdateCommand)
1558 FN_GLOBAL_LIST(spn_update_command, szSPNUpdateCommand)
1559 FN_GLOBAL_LIST(samba_kcc_command, szSambaKCCCommand)
1560 FN_GLOBAL_LIST(nsupdate_command, szNSUpdateCommand)
1561 FN_GLOBAL_LIST(dcerpc_endpoint_servers, dcerpc_ep_servers)
1562 FN_GLOBAL_LIST(server_services, server_services)
1563 FN_GLOBAL_STRING(ntptr_providor, ntptr_providor)
1564 FN_GLOBAL_STRING(passdb_backend, passdb_backend)
1565 FN_GLOBAL_STRING(auto_services, szAutoServices)
1566 FN_GLOBAL_STRING(passwd_chat, szPasswdChat)
1567 FN_GLOBAL_CONST_STRING(passwordserver, szPasswordServer)
1568 FN_GLOBAL_LIST(name_resolve_order, szNameResolveOrder)
1569 FN_GLOBAL_STRING(realm, szRealm_upper)
1570 FN_GLOBAL_STRING(dnsdomain, szRealm_lower)
1571 FN_GLOBAL_STRING(socket_options, socket_options)
1572 FN_GLOBAL_STRING(workgroup, szWorkgroup)
1573 FN_GLOBAL_STRING(netbios_name, szNetbiosName)
1574 FN_GLOBAL_STRING(netbios_scope, szNetbiosScope)
1575 FN_GLOBAL_LIST(wins_server_list, szWINSservers)
1576 FN_GLOBAL_LIST(interfaces, szInterfaces)
1577 FN_GLOBAL_STRING(socket_address, szSocketAddress)
1578 FN_GLOBAL_LIST(netbios_aliases, szNetbiosAliases)
1579 FN_GLOBAL_BOOL(disable_netbios, bDisableNetbios)
1580 FN_GLOBAL_BOOL(we_are_a_wins_server, bWINSsupport)
1581 FN_GLOBAL_BOOL(wins_dns_proxy, bWINSdnsProxy)
1582 FN_GLOBAL_STRING(wins_hook, szWINSHook)
1583 FN_GLOBAL_BOOL(local_master, bLocalMaster)
1584 FN_GLOBAL_BOOL(readraw, bReadRaw)
1585 FN_GLOBAL_BOOL(large_readwrite, bLargeReadwrite)
1586 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
1587 FN_GLOBAL_BOOL(null_passwords, bNullPasswords)
1588 FN_GLOBAL_BOOL(obey_pam_restrictions, bObeyPamRestrictions)
1589 FN_GLOBAL_BOOL(encrypted_passwords, bEncryptPasswords)
1590 FN_GLOBAL_BOOL(time_server, bTimeServer)
1591 FN_GLOBAL_BOOL(bind_interfaces_only, bBindInterfacesOnly)
1592 FN_GLOBAL_BOOL(unicode, bUnicode)
1593 FN_GLOBAL_BOOL(nt_status_support, bNTStatusSupport)
1594 FN_GLOBAL_BOOL(lanman_auth, bLanmanAuth)
1595 FN_GLOBAL_BOOL(ntlm_auth, bNTLMAuth)
1596 FN_GLOBAL_BOOL(client_plaintext_auth, bClientPlaintextAuth)
1597 FN_GLOBAL_BOOL(client_lanman_auth, bClientLanManAuth)
1598 FN_GLOBAL_BOOL(client_ntlmv2_auth, bClientNTLMv2Auth)
1599 FN_GLOBAL_BOOL(client_use_spnego_principal, client_use_spnego_principal)
1600 FN_GLOBAL_BOOL(host_msdfs, bHostMSDfs)
1601 FN_GLOBAL_BOOL(unix_extensions, bUnixExtensions)
1602 FN_GLOBAL_BOOL(use_spnego, bUseSpnego)
1603 FN_GLOBAL_BOOL(use_mmap, bUseMmap)
1604 FN_GLOBAL_BOOL(rpc_big_endian, bRpcBigEndian)
1605 FN_GLOBAL_INTEGER(max_wins_ttl, max_wins_ttl)
1606 FN_GLOBAL_INTEGER(min_wins_ttl, min_wins_ttl)
1607 FN_GLOBAL_INTEGER(maxmux, max_mux)
1608 FN_GLOBAL_INTEGER(max_xmit, max_xmit)
1609 FN_GLOBAL_INTEGER(passwordlevel, pwordlevel)
1610 FN_GLOBAL_INTEGER(srv_maxprotocol, srv_maxprotocol)
1611 FN_GLOBAL_INTEGER(srv_minprotocol, srv_minprotocol)
1612 FN_GLOBAL_INTEGER(cli_maxprotocol, cli_maxprotocol)
1613 FN_GLOBAL_INTEGER(cli_minprotocol, cli_minprotocol)
1614 FN_GLOBAL_BOOL(paranoid_server_security, paranoid_server_security)
1615
1616 FN_GLOBAL_INTEGER(allow_dns_updates, allow_dns_updates)
1617 FN_GLOBAL_CONST_STRING(dns_forwarder, dns_forwarder)
1618 FN_GLOBAL_BOOL(dns_recursive_queries, dns_recursive_queries)
1619
1620 FN_GLOBAL_INTEGER(server_signing, server_signing)
1621 FN_GLOBAL_INTEGER(client_signing, client_signing)
1622
1623 FN_GLOBAL_CONST_STRING(ntp_signd_socket_directory, szNTPSignDSocketDirectory)
1624
1625 /* local prototypes */
1626 static int map_parameter(const char *pszParmName);
1627 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
1628                                         const char *pszServiceName);
1629 static void copy_service(struct loadparm_service *pserviceDest,
1630                          struct loadparm_service *pserviceSource,
1631                          struct bitmap *pcopymapDest);
1632 static bool lpcfg_service_ok(struct loadparm_service *service);
1633 static bool do_section(const char *pszSectionName, void *);
1634 static void init_copymap(struct loadparm_service *pservice);
1635
1636 /* This is a helper function for parametrical options support. */
1637 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
1638 /* Actual parametrical functions are quite simple */
1639 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
1640                               struct loadparm_service *service,
1641                               const char *type, const char *option)
1642 {
1643         char *vfskey_tmp = NULL;
1644         char *vfskey = NULL;
1645         struct parmlist_entry *data;
1646
1647         if (lp_ctx == NULL)
1648                 return NULL;
1649
1650         if (lp_ctx->s3_fns) {
1651                 return lp_ctx->s3_fns->get_parametric(service, type, option);
1652         }
1653
1654         data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
1655
1656         vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
1657         if (vfskey_tmp == NULL) return NULL;
1658         vfskey = strlower_talloc(NULL, vfskey_tmp);
1659         talloc_free(vfskey_tmp);
1660
1661         while (data) {
1662                 if (strcmp(data->key, vfskey) == 0) {
1663                         talloc_free(vfskey);
1664                         return data->value;
1665                 }
1666                 data = data->next;
1667         }
1668
1669         if (service != NULL) {
1670                 /* Try to fetch the same option but from globals */
1671                 /* but only if we are not already working with globals */
1672                 for (data = lp_ctx->globals->param_opt; data;
1673                      data = data->next) {
1674                         if (strcmp(data->key, vfskey) == 0) {
1675                                 talloc_free(vfskey);
1676                                 return data->value;
1677                         }
1678                 }
1679         }
1680
1681         talloc_free(vfskey);
1682
1683         return NULL;
1684 }
1685
1686
1687 /**
1688  * convenience routine to return int parameters.
1689  */
1690 static int lp_int(const char *s)
1691 {
1692
1693         if (!s) {
1694                 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
1695                 return -1;
1696         }
1697
1698         return strtol(s, NULL, 0);
1699 }
1700
1701 /**
1702  * convenience routine to return unsigned long parameters.
1703  */
1704 static unsigned long lp_ulong(const char *s)
1705 {
1706
1707         if (!s) {
1708                 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
1709                 return -1;
1710         }
1711
1712         return strtoul(s, NULL, 0);
1713 }
1714
1715 /**
1716  * convenience routine to return unsigned long parameters.
1717  */
1718 static long lp_long(const char *s)
1719 {
1720
1721         if (!s) {
1722                 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
1723                 return -1;
1724         }
1725
1726         return strtol(s, NULL, 0);
1727 }
1728
1729 /**
1730  * convenience routine to return unsigned long parameters.
1731  */
1732 static double lp_double(const char *s)
1733 {
1734
1735         if (!s) {
1736                 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
1737                 return -1;
1738         }
1739
1740         return strtod(s, NULL);
1741 }
1742
1743 /**
1744  * convenience routine to return boolean parameters.
1745  */
1746 static bool lp_bool(const char *s)
1747 {
1748         bool ret = false;
1749
1750         if (!s) {
1751                 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
1752                 return false;
1753         }
1754
1755         if (!set_boolean(s, &ret)) {
1756                 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
1757                 return false;
1758         }
1759
1760         return ret;
1761 }
1762
1763
1764 /**
1765  * Return parametric option from a given service. Type is a part of option before ':'
1766  * Parametric option has following syntax: 'Type: option = value'
1767  * Returned value is allocated in 'lp_talloc' context
1768  */
1769
1770 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
1771                               struct loadparm_service *service, const char *type,
1772                               const char *option)
1773 {
1774         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1775
1776         if (value)
1777                 return lp_string(value);
1778
1779         return NULL;
1780 }
1781
1782 /**
1783  * Return parametric option from a given service. Type is a part of option before ':'
1784  * Parametric option has following syntax: 'Type: option = value'
1785  * Returned value is allocated in 'lp_talloc' context
1786  */
1787
1788 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
1789                                     struct loadparm_context *lp_ctx,
1790                                     struct loadparm_service *service,
1791                                     const char *type,
1792                                     const char *option, const char *separator)
1793 {
1794         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1795
1796         if (value != NULL)
1797                 return (const char **)str_list_make(mem_ctx, value, separator);
1798
1799         return NULL;
1800 }
1801
1802 /**
1803  * Return parametric option from a given service. Type is a part of option before ':'
1804  * Parametric option has following syntax: 'Type: option = value'
1805  */
1806
1807 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
1808                    struct loadparm_service *service, const char *type,
1809                    const char *option, int default_v)
1810 {
1811         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1812
1813         if (value)
1814                 return lp_int(value);
1815
1816         return default_v;
1817 }
1818
1819 /**
1820  * Return parametric option from a given service. Type is a part of
1821  * option before ':'.
1822  * Parametric option has following syntax: 'Type: option = value'.
1823  */
1824
1825 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
1826                   struct loadparm_service *service, const char *type,
1827                   const char *option, int default_v)
1828 {
1829         uint64_t bval;
1830
1831         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1832
1833         if (value && conv_str_size_error(value, &bval)) {
1834                 if (bval <= INT_MAX) {
1835                         return (int)bval;
1836                 }
1837         }
1838
1839         return default_v;
1840 }
1841
1842 /**
1843  * Return parametric option from a given service.
1844  * Type is a part of option before ':'
1845  * Parametric option has following syntax: 'Type: option = value'
1846  */
1847 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
1848                             struct loadparm_service *service, const char *type,
1849                             const char *option, unsigned long default_v)
1850 {
1851         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1852
1853         if (value)
1854                 return lp_ulong(value);
1855
1856         return default_v;
1857 }
1858
1859 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
1860                      struct loadparm_service *service, const char *type,
1861                      const char *option, long default_v)
1862 {
1863         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1864
1865         if (value)
1866                 return lp_long(value);
1867
1868         return default_v;
1869 }
1870
1871 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
1872                       struct loadparm_service *service, const char *type,
1873                       const char *option, double default_v)
1874 {
1875         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1876
1877         if (value != NULL)
1878                 return lp_double(value);
1879
1880         return default_v;
1881 }
1882
1883 /**
1884  * Return parametric option from a given service. Type is a part of option before ':'
1885  * Parametric option has following syntax: 'Type: option = value'
1886  */
1887
1888 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
1889                      struct loadparm_service *service, const char *type,
1890                      const char *option, bool default_v)
1891 {
1892         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
1893
1894         if (value != NULL)
1895                 return lp_bool(value);
1896
1897         return default_v;
1898 }
1899
1900
1901 /**
1902  * Initialise a service to the defaults.
1903  */
1904
1905 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
1906 {
1907         struct loadparm_service *pservice =
1908                 talloc_zero(mem_ctx, struct loadparm_service);
1909         copy_service(pservice, sDefault, NULL);
1910         return pservice;
1911 }
1912
1913 /**
1914  * Set a string value, deallocating any existing space, and allocing the space
1915  * for the string
1916  */
1917 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1918 {
1919         talloc_free(*dest);
1920
1921         if (src == NULL)
1922                 src = "";
1923
1924         *dest = talloc_strdup(mem_ctx, src);
1925         if ((*dest) == NULL) {
1926                 DEBUG(0,("Out of memory in string_set\n"));
1927                 return false;
1928         }
1929
1930         return true;
1931 }
1932
1933 /**
1934  * Set a string value, deallocating any existing space, and allocing the space
1935  * for the string
1936  */
1937 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
1938 {
1939         talloc_free(*dest);
1940
1941         if (src == NULL)
1942                 src = "";
1943
1944         *dest = strupper_talloc(mem_ctx, src);
1945         if ((*dest) == NULL) {
1946                 DEBUG(0,("Out of memory in string_set_upper\n"));
1947                 return false;
1948         }
1949
1950         return true;
1951 }
1952
1953
1954
1955 /**
1956  * Add a new service to the services array initialising it with the given
1957  * service.
1958  */
1959
1960 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
1961                                            const struct loadparm_service *pservice,
1962                                            const char *name)
1963 {
1964         int i;
1965         struct loadparm_service tservice;
1966         int num_to_alloc = lp_ctx->iNumServices + 1;
1967         struct parmlist_entry *data, *pdata;
1968
1969         if (pservice == NULL) {
1970                 pservice = lp_ctx->sDefault;
1971         }
1972
1973         tservice = *pservice;
1974
1975         /* it might already exist */
1976         if (name) {
1977                 struct loadparm_service *service = getservicebyname(lp_ctx,
1978                                                                     name);
1979                 if (service != NULL) {
1980                         /* Clean all parametric options for service */
1981                         /* They will be added during parsing again */
1982                         data = service->param_opt;
1983                         while (data) {
1984                                 pdata = data->next;
1985                                 talloc_free(data);
1986                                 data = pdata;
1987                         }
1988                         service->param_opt = NULL;
1989                         return service;
1990                 }
1991         }
1992
1993         /* find an invalid one */
1994         for (i = 0; i < lp_ctx->iNumServices; i++)
1995                 if (lp_ctx->services[i] == NULL)
1996                         break;
1997
1998         /* if not, then create one */
1999         if (i == lp_ctx->iNumServices) {
2000                 struct loadparm_service **tsp;
2001
2002                 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
2003
2004                 if (!tsp) {
2005                         DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
2006                         return NULL;
2007                 } else {
2008                         lp_ctx->services = tsp;
2009                         lp_ctx->services[lp_ctx->iNumServices] = NULL;
2010                 }
2011
2012                 lp_ctx->iNumServices++;
2013         }
2014
2015         lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
2016         if (lp_ctx->services[i] == NULL) {
2017                 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
2018                 return NULL;
2019         }
2020         copy_service(lp_ctx->services[i], &tservice, NULL);
2021         if (name != NULL)
2022                 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
2023         return lp_ctx->services[i];
2024 }
2025
2026 /**
2027  * Add a new home service, with the specified home directory, defaults coming
2028  * from service ifrom.
2029  */
2030
2031 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
2032                  const char *pszHomename,
2033                  struct loadparm_service *default_service,
2034                  const char *user, const char *pszHomedir)
2035 {
2036         struct loadparm_service *service;
2037
2038         service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
2039
2040         if (service == NULL)
2041                 return false;
2042
2043         if (!(*(default_service->szPath))
2044             || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
2045                 service->szPath = talloc_strdup(service, pszHomedir);
2046         } else {
2047                 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
2048         }
2049
2050         if (!(*(service->comment))) {
2051                 service->comment = talloc_asprintf(service, "Home directory of %s", user);
2052         }
2053         service->bAvailable = default_service->bAvailable;
2054         service->bBrowseable = default_service->bBrowseable;
2055
2056         DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
2057                   pszHomename, user, service->szPath));
2058
2059         return true;
2060 }
2061
2062 /**
2063  * Add a new printer service, with defaults coming from service iFrom.
2064  */
2065
2066 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
2067                        const char *pszPrintername,
2068                        struct loadparm_service *default_service)
2069 {
2070         const char *comment = "From Printcap";
2071         struct loadparm_service *service;
2072         service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
2073
2074         if (service == NULL)
2075                 return false;
2076
2077         /* note that we do NOT default the availability flag to True - */
2078         /* we take it from the default service passed. This allows all */
2079         /* dynamic printers to be disabled by disabling the [printers] */
2080         /* entry (if/when the 'available' keyword is implemented!).    */
2081
2082         /* the printer name is set to the service name. */
2083         lpcfg_string_set(service, &service->szPrintername, pszPrintername);
2084         lpcfg_string_set(service, &service->comment, comment);
2085         service->bBrowseable = default_service->bBrowseable;
2086         /* Printers cannot be read_only. */
2087         service->bRead_only = false;
2088         /* Printer services must be printable. */
2089         service->bPrint_ok = true;
2090
2091         DEBUG(3, ("adding printer service %s\n", pszPrintername));
2092
2093         return true;
2094 }
2095
2096 /**
2097  * Map a parameter's string representation to something we can use.
2098  * Returns False if the parameter string is not recognised, else TRUE.
2099  */
2100
2101 static int map_parameter(const char *pszParmName)
2102 {
2103         int iIndex;
2104
2105         if (*pszParmName == '-')
2106                 return -1;
2107
2108         for (iIndex = 0; parm_table[iIndex].label; iIndex++)
2109                 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
2110                         return iIndex;
2111
2112         /* Warn only if it isn't parametric option */
2113         if (strchr(pszParmName, ':') == NULL)
2114                 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
2115         /* We do return 'fail' for parametric options as well because they are
2116            stored in different storage
2117          */
2118         return -1;
2119 }
2120
2121
2122 /**
2123   return the parameter structure for a parameter
2124 */
2125 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
2126 {
2127         int parmnum;
2128
2129         if (lp_ctx->s3_fns) {
2130                 return lp_ctx->s3_fns->get_parm_struct(name);
2131         }
2132
2133         parmnum = map_parameter(name);
2134         if (parmnum == -1) return NULL;
2135         return &parm_table[parmnum];
2136 }
2137
2138 /**
2139   return the parameter pointer for a parameter
2140 */
2141 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
2142                   struct loadparm_service *service, struct parm_struct *parm)
2143 {
2144         if (lp_ctx->s3_fns) {
2145                 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
2146         }
2147
2148         if (service == NULL) {
2149                 if (parm->p_class == P_LOCAL)
2150                         return ((char *)lp_ctx->sDefault)+parm->offset;
2151                 else if (parm->p_class == P_GLOBAL)
2152                         return ((char *)lp_ctx->globals)+parm->offset;
2153                 else return NULL;
2154         } else {
2155                 return ((char *)service) + parm->offset;
2156         }
2157 }
2158
2159 /**
2160   return the parameter pointer for a parameter
2161 */
2162 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
2163 {
2164         int parmnum;
2165
2166         if (lp_ctx->s3_fns) {
2167                 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
2168                 if (parm) {
2169                         return parm->flags & FLAG_CMDLINE;
2170                 }
2171                 return false;
2172         }
2173
2174         parmnum = map_parameter(name);
2175         if (parmnum == -1) return false;
2176
2177         return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
2178 }
2179
2180 /**
2181  * Find a service by name. Otherwise works like get_service.
2182  */
2183
2184 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
2185                                         const char *pszServiceName)
2186 {
2187         int iService;
2188
2189         if (lp_ctx->s3_fns) {
2190                 return lp_ctx->s3_fns->get_service(pszServiceName);
2191         }
2192
2193         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
2194                 if (lp_ctx->services[iService] != NULL &&
2195                     strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
2196                         return lp_ctx->services[iService];
2197                 }
2198
2199         return NULL;
2200 }
2201
2202 /**
2203  * Copy a service structure to another.
2204  * If pcopymapDest is NULL then copy all fields
2205  */
2206
2207 static void copy_service(struct loadparm_service *pserviceDest,
2208                          struct loadparm_service *pserviceSource,
2209                          struct bitmap *pcopymapDest)
2210 {
2211         int i;
2212         bool bcopyall = (pcopymapDest == NULL);
2213         struct parmlist_entry *data, *pdata, *paramo;
2214         bool not_added;
2215
2216         for (i = 0; parm_table[i].label; i++)
2217                 if (parm_table[i].p_class == P_LOCAL &&
2218                     (bcopyall || bitmap_query(pcopymapDest, i))) {
2219                         void *src_ptr =
2220                                 ((char *)pserviceSource) + parm_table[i].offset;
2221                         void *dest_ptr =
2222                                 ((char *)pserviceDest) + parm_table[i].offset;
2223
2224                         switch (parm_table[i].type) {
2225                                 case P_BOOL:
2226                                         *(bool *)dest_ptr = *(bool *)src_ptr;
2227                                         break;
2228
2229                                 case P_INTEGER:
2230                                 case P_BYTES:
2231                                 case P_OCTAL:
2232                                 case P_ENUM:
2233                                         *(int *)dest_ptr = *(int *)src_ptr;
2234                                         break;
2235
2236                                 case P_STRING:
2237                                         lpcfg_string_set(pserviceDest,
2238                                                    (char **)dest_ptr,
2239                                                    *(char **)src_ptr);
2240                                         break;
2241
2242                                 case P_USTRING:
2243                                         lpcfg_string_set_upper(pserviceDest,
2244                                                          (char **)dest_ptr,
2245                                                          *(char **)src_ptr);
2246                                         break;
2247                                 case P_LIST:
2248                                         *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest, 
2249                                                                                   *(const char ***)src_ptr);
2250                                         break;
2251                                 default:
2252                                         break;
2253                         }
2254                 }
2255
2256         if (bcopyall) {
2257                 init_copymap(pserviceDest);
2258                 if (pserviceSource->copymap)
2259                         bitmap_copy(pserviceDest->copymap,
2260                                     pserviceSource->copymap);
2261         }
2262
2263         data = pserviceSource->param_opt;
2264         while (data) {
2265                 not_added = true;
2266                 pdata = pserviceDest->param_opt;
2267                 /* Traverse destination */
2268                 while (pdata) {
2269                         /* If we already have same option, override it */
2270                         if (strcmp(pdata->key, data->key) == 0) {
2271                                 talloc_free(pdata->value);
2272                                 pdata->value = talloc_strdup(pdata,
2273                                                              data->value);
2274                                 not_added = false;
2275                                 break;
2276                         }
2277                         pdata = pdata->next;
2278                 }
2279                 if (not_added) {
2280                         paramo = talloc_zero(pserviceDest, struct parmlist_entry);
2281                         if (paramo == NULL)
2282                                 smb_panic("OOM");
2283                         paramo->key = talloc_strdup(paramo, data->key);
2284                         paramo->value = talloc_strdup(paramo, data->value);
2285                         DLIST_ADD(pserviceDest->param_opt, paramo);
2286                 }
2287                 data = data->next;
2288         }
2289 }
2290
2291 /**
2292  * Check a service for consistency. Return False if the service is in any way
2293  * incomplete or faulty, else True.
2294  */
2295 static bool lpcfg_service_ok(struct loadparm_service *service)
2296 {
2297         bool bRetval;
2298
2299         bRetval = true;
2300         if (service->szService[0] == '\0') {
2301                 DEBUG(0, ("The following message indicates an internal error:\n"));
2302                 DEBUG(0, ("No service name in service entry.\n"));
2303                 bRetval = false;
2304         }
2305
2306         /* The [printers] entry MUST be printable. I'm all for flexibility, but */
2307         /* I can't see why you'd want a non-printable printer service...        */
2308         if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
2309                 if (!service->bPrint_ok) {
2310                         DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
2311                                service->szService));
2312                         service->bPrint_ok = true;
2313                 }
2314                 /* [printers] service must also be non-browsable. */
2315                 if (service->bBrowseable)
2316                         service->bBrowseable = false;
2317         }
2318
2319         /* If a service is flagged unavailable, log the fact at level 0. */
2320         if (!service->bAvailable)
2321                 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
2322                           service->szService));
2323
2324         return bRetval;
2325 }
2326
2327
2328 /*******************************************************************
2329  Keep a linked list of all config files so we know when one has changed
2330  it's date and needs to be reloaded.
2331 ********************************************************************/
2332
2333 static void add_to_file_list(struct loadparm_context *lp_ctx,
2334                              const char *fname, const char *subfname)
2335 {
2336         struct file_lists *f = lp_ctx->file_lists;
2337
2338         while (f) {
2339                 if (f->name && !strcmp(f->name, fname))
2340                         break;
2341                 f = f->next;
2342         }
2343
2344         if (!f) {
2345                 f = talloc(lp_ctx, struct file_lists);
2346                 if (!f)
2347                         return;
2348                 f->next = lp_ctx->file_lists;
2349                 f->name = talloc_strdup(f, fname);
2350                 if (!f->name) {
2351                         talloc_free(f);
2352                         return;
2353                 }
2354                 f->subfname = talloc_strdup(f, subfname);
2355                 if (!f->subfname) {
2356                         talloc_free(f);
2357                         return;
2358                 }
2359                 lp_ctx->file_lists = f;
2360                 f->modtime = file_modtime(subfname);
2361         } else {
2362                 time_t t = file_modtime(subfname);
2363                 if (t)
2364                         f->modtime = t;
2365         }
2366 }
2367
2368 /*******************************************************************
2369  Check if a config file has changed date.
2370 ********************************************************************/
2371 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
2372 {
2373         struct file_lists *f;
2374         DEBUG(6, ("lp_file_list_changed()\n"));
2375
2376         for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
2377                 char *n2;
2378                 time_t mod_time;
2379
2380                 n2 = standard_sub_basic(lp_ctx, f->name);
2381
2382                 DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
2383                              f->name, n2, ctime(&f->modtime)));
2384
2385                 mod_time = file_modtime(n2);
2386
2387                 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
2388                         DEBUGADD(6, ("file %s modified: %s\n", n2,
2389                                   ctime(&mod_time)));
2390                         f->modtime = mod_time;
2391                         talloc_free(f->subfname);
2392                         f->subfname = talloc_strdup(f, n2);
2393                         return true;
2394                 }
2395         }
2396         return false;
2397 }
2398
2399 /***************************************************************************
2400  Handle the "realm" parameter
2401 ***************************************************************************/
2402
2403 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
2404                          const char *pszParmValue, char **ptr)
2405 {
2406         lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2407
2408         talloc_free(lp_ctx->globals->szRealm_upper);
2409         talloc_free(lp_ctx->globals->szRealm_lower);
2410
2411         lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
2412         lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
2413
2414         return true;
2415 }
2416
2417 /***************************************************************************
2418  Handle the include operation.
2419 ***************************************************************************/
2420
2421 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
2422                            const char *pszParmValue, char **ptr)
2423 {
2424         char *fname = standard_sub_basic(lp_ctx, pszParmValue);
2425
2426         add_to_file_list(lp_ctx, pszParmValue, fname);
2427
2428         lpcfg_string_set(lp_ctx, ptr, fname);
2429
2430         if (file_exist(fname))
2431                 return pm_process(fname, do_section, do_parameter, lp_ctx);
2432
2433         DEBUG(2, ("Can't find include file %s\n", fname));
2434
2435         return false;
2436 }
2437
2438 /***************************************************************************
2439  Handle the interpretation of the copy parameter.
2440 ***************************************************************************/
2441
2442 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
2443                         const char *pszParmValue, char **ptr)
2444 {
2445         bool bRetval;
2446         struct loadparm_service *serviceTemp;
2447
2448         lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2449
2450         bRetval = false;
2451
2452         DEBUG(3, ("Copying service from service %s\n", pszParmValue));
2453
2454         if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
2455                 if (serviceTemp == lp_ctx->currentService) {
2456                         DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
2457                 } else {
2458                         copy_service(lp_ctx->currentService,
2459                                      serviceTemp,
2460                                      lp_ctx->currentService->copymap);
2461                         bRetval = true;
2462                 }
2463         } else {
2464                 DEBUG(0, ("Unable to copy service - source not found: %s\n",
2465                           pszParmValue));
2466                 bRetval = false;
2467         }
2468
2469         return bRetval;
2470 }
2471
2472 static bool handle_debuglevel(struct loadparm_context *lp_ctx, int unused,
2473                         const char *pszParmValue, char **ptr)
2474 {
2475
2476         lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2477         if (lp_ctx->global) {
2478                 return debug_parse_levels(pszParmValue);
2479         }
2480         return true;
2481 }
2482
2483 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
2484                         const char *pszParmValue, char **ptr)
2485 {
2486         debug_set_logfile(pszParmValue);
2487         if (lp_ctx->global) {
2488                 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
2489         }
2490         return true;
2491 }
2492
2493 /***************************************************************************
2494  Initialise a copymap.
2495 ***************************************************************************/
2496
2497 static void init_copymap(struct loadparm_service *pservice)
2498 {
2499         int i;
2500
2501         TALLOC_FREE(pservice->copymap);
2502
2503         pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
2504         if (!pservice->copymap)
2505                 DEBUG(0,
2506                       ("Couldn't allocate copymap!! (size %d)\n",
2507                        (int)NUMPARAMETERS));
2508         else
2509                 for (i = 0; i < NUMPARAMETERS; i++)
2510                         bitmap_set(pservice->copymap, i);
2511 }
2512
2513 /**
2514  * Process a parametric option
2515  */
2516 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
2517                                        struct loadparm_service *service,
2518                                        const char *pszParmName,
2519                                        const char *pszParmValue, int flags)
2520 {
2521         struct parmlist_entry *paramo, *data;
2522         char *name;
2523         TALLOC_CTX *mem_ctx;
2524
2525         while (isspace((unsigned char)*pszParmName)) {
2526                 pszParmName++;
2527         }
2528
2529         name = strlower_talloc(lp_ctx, pszParmName);
2530         if (!name) return false;
2531
2532         if (service == NULL) {
2533                 data = lp_ctx->globals->param_opt;
2534                 mem_ctx = lp_ctx->globals;
2535         } else {
2536                 data = service->param_opt;
2537                 mem_ctx = service;
2538         }
2539
2540         /* Traverse destination */
2541         for (paramo=data; paramo; paramo=paramo->next) {
2542                 /* If we already have the option set, override it unless
2543                    it was a command line option and the new one isn't */
2544                 if (strcmp(paramo->key, name) == 0) {
2545                         if ((paramo->priority & FLAG_CMDLINE) &&
2546                             !(flags & FLAG_CMDLINE)) {
2547                                 talloc_free(name);
2548                                 return true;
2549                         }
2550
2551                         talloc_free(paramo->value);
2552                         paramo->value = talloc_strdup(paramo, pszParmValue);
2553                         paramo->priority = flags;
2554                         talloc_free(name);
2555                         return true;
2556                 }
2557         }
2558
2559         paramo = talloc_zero(mem_ctx, struct parmlist_entry);
2560         if (!paramo)
2561                 smb_panic("OOM");
2562         paramo->key = talloc_strdup(paramo, name);
2563         paramo->value = talloc_strdup(paramo, pszParmValue);
2564         paramo->priority = flags;
2565         if (service == NULL) {
2566                 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
2567         } else {
2568                 DLIST_ADD(service->param_opt, paramo);
2569         }
2570
2571         talloc_free(name);
2572
2573         return true;
2574 }
2575
2576 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
2577                          const char *pszParmName, const char *pszParmValue,
2578                          struct loadparm_context *lp_ctx, bool on_globals)
2579 {
2580         int i;
2581         /* if it is a special case then go ahead */
2582         if (parm_table[parmnum].special) {
2583                 bool ret;
2584                 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
2585                                                   (char **)parm_ptr);
2586                 if (!ret) {
2587                         return false;
2588                 }
2589                 goto mark_non_default;
2590         }
2591
2592         /* now switch on the type of variable it is */
2593         switch (parm_table[parmnum].type)
2594         {
2595                 case P_BOOL: {
2596                         bool b;
2597                         if (!set_boolean(pszParmValue, &b)) {
2598                                 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2599                                 return false;
2600                         }
2601                         *(bool *)parm_ptr = b;
2602                         }
2603                         break;
2604
2605                 case P_BOOLREV: {
2606                         bool b;
2607                         if (!set_boolean(pszParmValue, &b)) {
2608                                 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
2609                                 return false;
2610                         }
2611                         *(bool *)parm_ptr = !b;
2612                         }
2613                         break;
2614
2615                 case P_INTEGER:
2616                         *(int *)parm_ptr = atoi(pszParmValue);
2617                         break;
2618
2619                 case P_CHAR:
2620                         *(char *)parm_ptr = *pszParmValue;
2621                         break;
2622
2623                 case P_OCTAL:
2624                         *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
2625                         break;
2626
2627                 case P_BYTES:
2628                 {
2629                         uint64_t val;
2630                         if (conv_str_size_error(pszParmValue, &val)) {
2631                                 if (val <= INT_MAX) {
2632                                         *(int *)parm_ptr = (int)val;
2633                                         break;
2634                                 }
2635                         }
2636
2637                         DEBUG(0,("lp_do_parameter(%s): value is not "
2638                             "a valid size specifier!\n", pszParmValue));
2639                         return false;
2640                 }
2641
2642                 case P_CMDLIST:
2643                         *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
2644                                                                   pszParmValue, NULL);
2645                         break;
2646                 case P_LIST:
2647                 {
2648                         char **new_list = str_list_make(mem_ctx,
2649                                                         pszParmValue, NULL);
2650                         for (i=0; new_list[i]; i++) {
2651                                 if (new_list[i][0] == '+' && new_list[i][1]) {
2652                                         if (!str_list_check(*(const char ***)parm_ptr,
2653                                                             &new_list[i][1])) {
2654                                                 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
2655                                                                                          &new_list[i][1]);
2656                                         }
2657                                 } else if (new_list[i][0] == '-' && new_list[i][1]) {
2658                                         str_list_remove(*(const char ***)parm_ptr,
2659                                                         &new_list[i][1]);
2660                                 } else {
2661                                         if (i != 0) {
2662                                                 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
2663                                                           pszParmName, pszParmValue));
2664                                                 return false;
2665                                         }
2666                                         *(const char ***)parm_ptr = (const char **) new_list;
2667                                         break;
2668                                 }
2669                         }
2670                         break;
2671                 }
2672                 case P_STRING:
2673                         lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
2674                         break;
2675
2676                 case P_USTRING:
2677                         lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
2678                         break;
2679
2680                 case P_ENUM:
2681                         for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
2682                                 if (strequal
2683                                     (pszParmValue,
2684                                      parm_table[parmnum].enum_list[i].name)) {
2685                                         *(int *)parm_ptr =
2686                                                 parm_table[parmnum].
2687                                                 enum_list[i].value;
2688                                         break;
2689                                 }
2690                         }
2691                         if (!parm_table[parmnum].enum_list[i].name) {
2692                                 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n", 
2693                                          pszParmValue, pszParmName));
2694                                 return false;
2695                         }
2696                         break;
2697
2698                 case P_SEP:
2699                         break;
2700         }
2701
2702 mark_non_default:
2703         if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
2704                 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
2705                 /* we have to also unset FLAG_DEFAULT on aliases */
2706                 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2707                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2708                 }
2709                 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2710                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
2711                 }
2712         }
2713         return true;
2714 }
2715
2716
2717 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
2718                                const char *pszParmName, const char *pszParmValue)
2719 {
2720         int parmnum = map_parameter(pszParmName);
2721         void *parm_ptr;
2722
2723         if (parmnum < 0) {
2724                 if (strchr(pszParmName, ':')) {
2725                         return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
2726                 }
2727                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2728                 return true;
2729         }
2730
2731         /* if the flag has been set on the command line, then don't allow override,
2732            but don't report an error */
2733         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2734                 return true;
2735         }
2736
2737         parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
2738
2739         return set_variable(lp_ctx->globals, parmnum, parm_ptr,
2740                             pszParmName, pszParmValue, lp_ctx, true);
2741 }
2742
2743 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
2744                                 struct loadparm_service *service,
2745                                 const char *pszParmName, const char *pszParmValue)
2746 {
2747         void *parm_ptr;
2748         int i;
2749         int parmnum = map_parameter(pszParmName);
2750
2751         if (parmnum < 0) {
2752                 if (strchr(pszParmName, ':')) {
2753                         return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
2754                 }
2755                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
2756                 return true;
2757         }
2758
2759         /* if the flag has been set on the command line, then don't allow override,
2760            but don't report an error */
2761         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
2762                 return true;
2763         }
2764
2765         if (parm_table[parmnum].p_class == P_GLOBAL) {
2766                 DEBUG(0,
2767                       ("Global parameter %s found in service section!\n",
2768                        pszParmName));
2769                 return true;
2770         }
2771         parm_ptr = ((char *)service) + parm_table[parmnum].offset;
2772
2773         if (!service->copymap)
2774                 init_copymap(service);
2775
2776         /* this handles the aliases - set the copymap for other
2777          * entries with the same data pointer */
2778         for (i = 0; parm_table[i].label; i++)
2779                 if (parm_table[i].offset == parm_table[parmnum].offset &&
2780                     parm_table[i].p_class == parm_table[parmnum].p_class)
2781                         bitmap_clear(service->copymap, i);
2782
2783         return set_variable(service, parmnum, parm_ptr, pszParmName,
2784                             pszParmValue, lp_ctx, false);
2785 }
2786
2787 /**
2788  * Process a parameter.
2789  */
2790
2791 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
2792                          void *userdata)
2793 {
2794         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2795
2796         if (lp_ctx->bInGlobalSection)
2797                 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
2798                                               pszParmValue);
2799         else
2800                 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
2801                                                   pszParmName, pszParmValue);
2802 }
2803
2804 /*
2805   variable argument do parameter
2806 */
2807 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2808 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2809                                 const char *pszParmName, const char *fmt, ...)
2810 {
2811         char *s;
2812         bool ret;
2813         va_list ap;
2814
2815         va_start(ap, fmt);
2816         s = talloc_vasprintf(NULL, fmt, ap);
2817         va_end(ap);
2818         ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2819         talloc_free(s);
2820         return ret;
2821 }
2822
2823
2824 /*
2825   set a parameter from the commandline - this is called from command line parameter
2826   parsing code. It sets the parameter then marks the parameter as unable to be modified
2827   by smb.conf processing
2828 */
2829 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2830                        const char *pszParmValue)
2831 {
2832         int parmnum;
2833         int i;
2834
2835         if (lp_ctx->s3_fns) {
2836                 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
2837         }
2838
2839         parmnum = map_parameter(pszParmName);
2840
2841         while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2842
2843
2844         if (parmnum < 0 && strchr(pszParmName, ':')) {
2845                 /* set a parametric option */
2846                 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2847                                                   pszParmValue, FLAG_CMDLINE);
2848         }
2849
2850         if (parmnum < 0) {
2851                 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2852                 return false;
2853         }
2854
2855         /* reset the CMDLINE flag in case this has been called before */
2856         lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2857
2858         if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2859                 return false;
2860         }
2861
2862         lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2863
2864         /* we have to also set FLAG_CMDLINE on aliases */
2865         for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
2866                 lp_ctx->flags[i] |= FLAG_CMDLINE;
2867         }
2868         for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
2869                 lp_ctx->flags[i] |= FLAG_CMDLINE;
2870         }
2871
2872         return true;
2873 }
2874
2875 /*
2876   set a option from the commandline in 'a=b' format. Use to support --option
2877 */
2878 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2879 {
2880         char *p, *s;
2881         bool ret;
2882
2883         s = talloc_strdup(NULL, option);
2884         if (!s) {
2885                 return false;
2886         }
2887
2888         p = strchr(s, '=');
2889         if (!p) {
2890                 talloc_free(s);
2891                 return false;
2892         }
2893
2894         *p = 0;
2895
2896         ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2897         talloc_free(s);
2898         return ret;
2899 }
2900
2901
2902 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2903
2904 /**
2905  * Print a parameter of the specified type.
2906  */
2907
2908 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2909 {
2910         /* For the seperation of lists values that we print below */
2911         const char *list_sep = ", ";
2912         int i;
2913         switch (p->type)
2914         {
2915                 case P_ENUM:
2916                         for (i = 0; p->enum_list[i].name; i++) {
2917                                 if (*(int *)ptr == p->enum_list[i].value) {
2918                                         fprintf(f, "%s",
2919                                                 p->enum_list[i].name);
2920                                         break;
2921                                 }
2922                         }
2923                         break;
2924
2925                 case P_BOOL:
2926                         fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2927                         break;
2928
2929                 case P_BOOLREV:
2930                         fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2931                         break;
2932
2933                 case P_INTEGER:
2934                 case P_BYTES:
2935                         fprintf(f, "%d", *(int *)ptr);
2936                         break;
2937
2938                 case P_CHAR:
2939                         fprintf(f, "%c", *(char *)ptr);
2940                         break;
2941
2942                 case P_OCTAL: {
2943                         int val = *(int *)ptr; 
2944                         if (val == -1) {
2945                                 fprintf(f, "-1");
2946                         } else {
2947                                 fprintf(f, "0%o", val);
2948                         }
2949                         break;
2950                 }
2951
2952                 case P_CMDLIST:
2953                         list_sep = " ";
2954                         /* fall through */
2955                 case P_LIST:
2956                         if ((char ***)ptr && *(char ***)ptr) {
2957                                 char **list = *(char ***)ptr;
2958                                 for (; *list; list++) {
2959                                         /* surround strings with whitespace in double quotes */
2960                                         if (*(list+1) == NULL) {
2961                                                 /* last item, no extra separator */
2962                                                 list_sep = "";
2963                                         }
2964                                         if ( strchr_m( *list, ' ' ) ) {
2965                                                 fprintf(f, "\"%s\"%s", *list, list_sep);
2966                                         } else {
2967                                                 fprintf(f, "%s%s", *list, list_sep);
2968                                         }
2969                                 }
2970                         }
2971                         break;
2972
2973                 case P_STRING:
2974                 case P_USTRING:
2975                         if (*(char **)ptr) {
2976                                 fprintf(f, "%s", *(char **)ptr);
2977                         }
2978                         break;
2979                 case P_SEP:
2980                         break;
2981         }
2982 }
2983
2984 /**
2985  * Check if two parameters are equal.
2986  */
2987
2988 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
2989 {
2990         switch (type) {
2991                 case P_BOOL:
2992                 case P_BOOLREV:
2993                         return (*((bool *)ptr1) == *((bool *)ptr2));
2994
2995                 case P_INTEGER:
2996                 case P_ENUM:
2997                 case P_OCTAL:
2998                 case P_BYTES:
2999                         return (*((int *)ptr1) == *((int *)ptr2));
3000
3001                 case P_CHAR:
3002                         return (*((char *)ptr1) == *((char *)ptr2));
3003
3004                 case P_LIST:
3005                 case P_CMDLIST:
3006                         return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
3007
3008                 case P_STRING:
3009                 case P_USTRING:
3010                 {
3011                         char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
3012                         if (p1 && !*p1)
3013                                 p1 = NULL;
3014                         if (p2 && !*p2)
3015                                 p2 = NULL;
3016                         return (p1 == p2 || strequal(p1, p2));
3017                 }
3018                 case P_SEP:
3019                         break;
3020         }
3021         return false;
3022 }
3023
3024 /**
3025  * Process a new section (service).
3026  *
3027  * At this stage all sections are services.
3028  * Later we'll have special sections that permit server parameters to be set.
3029  * Returns True on success, False on failure.
3030  */
3031
3032 static bool do_section(const char *pszSectionName, void *userdata)
3033 {
3034         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
3035         bool bRetval;
3036         bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
3037                          (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
3038         bRetval = false;
3039
3040         /* if we've just struck a global section, note the fact. */
3041         lp_ctx->bInGlobalSection = isglobal;
3042
3043         /* check for multiple global sections */
3044         if (lp_ctx->bInGlobalSection) {
3045                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3046                 return true;
3047         }
3048
3049         /* if we have a current service, tidy it up before moving on */
3050         bRetval = true;
3051
3052         if (lp_ctx->currentService != NULL)
3053                 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3054
3055         /* if all is still well, move to the next record in the services array */
3056         if (bRetval) {
3057                 /* We put this here to avoid an odd message order if messages are */
3058                 /* issued by the post-processing of a previous section. */
3059                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
3060
3061                 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
3062                                                                    pszSectionName))
3063                     == NULL) {
3064                         DEBUG(0, ("Failed to add a new service\n"));
3065                         return false;
3066                 }
3067         }
3068
3069         return bRetval;
3070 }
3071
3072
3073 /**
3074  * Determine if a particular base parameter is currently set to the default value.
3075  */
3076
3077 static bool is_default(struct loadparm_service *sDefault, int i)
3078 {
3079         void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
3080         if (!defaults_saved)
3081                 return false;
3082         switch (parm_table[i].type) {
3083                 case P_CMDLIST:
3084                 case P_LIST:
3085                         return str_list_equal((const char **)parm_table[i].def.lvalue, 
3086                                               (const char **)def_ptr);
3087                 case P_STRING:
3088                 case P_USTRING:
3089                         return strequal(parm_table[i].def.svalue,
3090                                         *(char **)def_ptr);
3091                 case P_BOOL:
3092                 case P_BOOLREV:
3093                         return parm_table[i].def.bvalue ==
3094                                 *(bool *)def_ptr;
3095                 case P_INTEGER:
3096                 case P_CHAR:
3097                 case P_OCTAL:
3098                 case P_BYTES:
3099                 case P_ENUM:
3100                         return parm_table[i].def.ivalue ==
3101                                 *(int *)def_ptr;
3102                 case P_SEP:
3103                         break;
3104         }
3105         return false;
3106 }
3107
3108 /**
3109  *Display the contents of the global structure.
3110  */
3111
3112 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
3113                          bool show_defaults)
3114 {
3115         int i;
3116         struct parmlist_entry *data;
3117
3118         fprintf(f, "# Global parameters\n[global]\n");
3119
3120         for (i = 0; parm_table[i].label; i++)
3121                 if (parm_table[i].p_class == P_GLOBAL &&
3122                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
3123                         if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
3124                                 continue;
3125                         fprintf(f, "\t%s = ", parm_table[i].label);
3126                         print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
3127                         fprintf(f, "\n");
3128         }
3129         if (lp_ctx->globals->param_opt != NULL) {
3130                 for (data = lp_ctx->globals->param_opt; data;
3131                      data = data->next) {
3132                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
3133                                 continue;
3134                         }
3135                         fprintf(f, "\t%s = %s\n", data->key, data->value);
3136                 }
3137         }
3138
3139 }
3140
3141 /**
3142  * Display the contents of a single services record.
3143  */
3144
3145 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
3146                            unsigned int *flags)
3147 {
3148         int i;
3149         struct parmlist_entry *data;
3150
3151         if (pService != sDefault)
3152                 fprintf(f, "\n[%s]\n", pService->szService);
3153
3154         for (i = 0; parm_table[i].label; i++) {
3155                 if (parm_table[i].p_class == P_LOCAL &&
3156                     (*parm_table[i].label != '-') &&
3157                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
3158                 {
3159                         if (pService == sDefault) {
3160                                 if (flags && (flags[i] & FLAG_DEFAULT)) {
3161                                         continue;
3162                                 }
3163                                 if (defaults_saved) {
3164                                         if (is_default(sDefault, i)) {
3165                                                 continue;
3166                                         }
3167                                 }
3168                         } else {
3169                                 if (equal_parameter(parm_table[i].type,
3170                                                     ((char *)pService) +
3171                                                     parm_table[i].offset,
3172                                                     ((char *)sDefault) +
3173                                                     parm_table[i].offset))
3174                                         continue;
3175                         }
3176
3177                         fprintf(f, "\t%s = ", parm_table[i].label);
3178                         print_parameter(&parm_table[i],
3179                                         ((char *)pService) + parm_table[i].offset, f);
3180                         fprintf(f, "\n");
3181                 }
3182         }
3183         if (pService->param_opt != NULL) {
3184                 for (data = pService->param_opt; data; data = data->next) {
3185                         fprintf(f, "\t%s = %s\n", data->key, data->value);
3186                 }
3187         }
3188 }
3189
3190 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
3191                             struct loadparm_service *service,
3192                             const char *parm_name, FILE * f)
3193 {
3194         struct parm_struct *parm;
3195         void *ptr;
3196
3197         parm = lpcfg_parm_struct(lp_ctx, parm_name);
3198         if (!parm) {
3199                 return false;
3200         }
3201
3202         ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
3203
3204         print_parameter(parm, ptr, f);
3205         fprintf(f, "\n");
3206         return true;
3207 }
3208
3209 /**
3210  * Return info about the next parameter in a service.
3211  * snum==-1 gives the globals.
3212  * Return NULL when out of parameters.
3213  */
3214
3215
3216 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
3217                                          int allparameters)
3218 {
3219         if (snum == -1) {
3220                 /* do the globals */
3221                 for (; parm_table[*i].label; (*i)++) {
3222                         if ((*parm_table[*i].label == '-'))
3223                                 continue;
3224
3225                         if ((*i) > 0
3226                             && (parm_table[*i].offset ==
3227                                 parm_table[(*i) - 1].offset)
3228                             && (parm_table[*i].p_class ==
3229                                 parm_table[(*i) - 1].p_class))
3230                                 continue;
3231
3232                         return &parm_table[(*i)++];
3233                 }
3234         } else {
3235                 struct loadparm_service *pService = lp_ctx->services[snum];
3236
3237                 for (; parm_table[*i].label; (*i)++) {
3238                         if (parm_table[*i].p_class == P_LOCAL &&
3239                             (*parm_table[*i].label != '-') &&
3240                             ((*i) == 0 ||
3241                              (parm_table[*i].offset !=
3242                               parm_table[(*i) - 1].offset)))
3243                         {
3244                                 if (allparameters ||
3245                                     !equal_parameter(parm_table[*i].type,
3246                                                      ((char *)pService) +
3247                                                      parm_table[*i].offset,
3248                                                      ((char *)lp_ctx->sDefault) +
3249                                                      parm_table[*i].offset))
3250                                 {
3251                                         return &parm_table[(*i)++];
3252                                 }
3253                         }
3254                 }
3255         }
3256
3257         return NULL;
3258 }
3259
3260
3261 /**
3262  * Auto-load some home services.
3263  */
3264 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
3265                                     const char *str)
3266 {
3267         return;
3268 }
3269
3270
3271 /**
3272  * Unload unused services.
3273  */
3274
3275 void lpcfg_killunused(struct loadparm_context *lp_ctx,
3276                    struct smbsrv_connection *smb,
3277                    bool (*snumused) (struct smbsrv_connection *, int))
3278 {
3279         int i;
3280         for (i = 0; i < lp_ctx->iNumServices; i++) {
3281                 if (lp_ctx->services[i] == NULL)
3282                         continue;
3283
3284                 if (!snumused || !snumused(smb, i)) {
3285                         talloc_free(lp_ctx->services[i]);
3286                         lp_ctx->services[i] = NULL;
3287                 }
3288         }
3289 }
3290
3291
3292 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
3293 {
3294         struct parmlist_entry *data;
3295
3296         if (lp_ctx->refuse_free) {
3297                 /* someone is trying to free the
3298                    global_loadparm_context.
3299                    We can't allow that. */
3300                 return -1;
3301         }
3302
3303         if (lp_ctx->globals->param_opt != NULL) {
3304                 struct parmlist_entry *next;
3305                 for (data = lp_ctx->globals->param_opt; data; data=next) {
3306                         next = data->next;
3307                         if (data->priority & FLAG_CMDLINE) continue;
3308                         DLIST_REMOVE(lp_ctx->globals->param_opt, data);
3309                         talloc_free(data);
3310                 }
3311         }
3312
3313         return 0;
3314 }
3315
3316 /**
3317  * Initialise the global parameter structure.
3318  *
3319  * Note that most callers should use loadparm_init_global() instead
3320  */
3321 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
3322 {
3323         int i;
3324         char *myname;
3325         struct loadparm_context *lp_ctx;
3326         struct parmlist_entry *parm;
3327         char *logfile;
3328
3329         lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
3330         if (lp_ctx == NULL)
3331                 return NULL;
3332
3333         talloc_set_destructor(lp_ctx, lpcfg_destructor);
3334         lp_ctx->bInGlobalSection = true;
3335         lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
3336         lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
3337
3338         lp_ctx->sDefault->iMaxPrintJobs = 1000;
3339         lp_ctx->sDefault->bAvailable = true;
3340         lp_ctx->sDefault->bBrowseable = true;
3341         lp_ctx->sDefault->bRead_only = true;
3342         lp_ctx->sDefault->bMap_archive = true;
3343         lp_ctx->sDefault->iStrictLocking = true;
3344         lp_ctx->sDefault->bOpLocks = true;
3345         lp_ctx->sDefault->iCreate_mask = 0744;
3346         lp_ctx->sDefault->iCreate_force_mode = 0000;
3347         lp_ctx->sDefault->iDir_mask = 0755;
3348         lp_ctx->sDefault->iDir_force_mode = 0000;
3349
3350         DEBUG(3, ("Initialising global parameters\n"));
3351
3352         for (i = 0; parm_table[i].label; i++) {
3353                 if ((parm_table[i].type == P_STRING ||
3354                      parm_table[i].type == P_USTRING) &&
3355                     !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3356                         char **r;
3357                         if (parm_table[i].p_class == P_LOCAL) {
3358                                 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
3359                         } else {
3360                                 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
3361                         }
3362                         *r = talloc_strdup(lp_ctx, "");
3363                 }
3364         }
3365
3366         logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
3367         lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
3368         talloc_free(logfile);
3369
3370         lpcfg_do_global_parameter(lp_ctx, "log level", "0");
3371
3372         lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
3373
3374         lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
3375         lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
3376         lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
3377
3378         /* options that can be set on the command line must be initialised via
3379            the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
3380 #ifdef TCP_NODELAY
3381         lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
3382 #endif
3383         lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
3384         myname = get_myname(lp_ctx);
3385         lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
3386         talloc_free(myname);
3387         lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
3388
3389         lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
3390
3391         lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
3392         lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
3393
3394         lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo browser eventlog6 backupkey dnsserver");
3395         lpcfg_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
3396         lpcfg_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
3397         /* the winbind method for domain controllers is for both RODC
3398            auth forwarding and for trusted domains */
3399         lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
3400         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
3401
3402         /* This hive should be dynamically generated by Samba using
3403            data from the sam, but for the moment leave it in a tdb to
3404            keep regedt32 from popping up an annoying dialog. */
3405         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
3406
3407         /* using UTF8 by default allows us to support all chars */
3408         lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
3409
3410         /* Use codepage 850 as a default for the dos character set */
3411         lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
3412
3413         /*
3414          * Allow the default PASSWD_CHAT to be overridden in local.h.
3415          */
3416         lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
3417
3418         lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
3419         lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
3420         lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
3421         lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
3422         lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
3423
3424         lpcfg_do_global_parameter(lp_ctx, "socket address", "");
3425         lpcfg_do_global_parameter_var(lp_ctx, "server string",
3426                                    "Samba %s", SAMBA_VERSION_STRING);
3427
3428         lpcfg_do_global_parameter(lp_ctx, "password server", "*");
3429
3430         lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
3431         lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
3432         lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
3433
3434         lpcfg_do_global_parameter(lp_ctx, "password level", "0");
3435         lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
3436         lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
3437         lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
3438         lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
3439         lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
3440         lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
3441         lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
3442         lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
3443         lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
3444         lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
3445         lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
3446         lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
3447
3448         lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
3449         lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
3450         lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
3451         lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
3452         lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
3453         lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
3454         lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
3455         lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
3456
3457         lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
3458
3459         lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
3460         lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
3461
3462         lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
3463         lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
3464
3465         lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
3466         lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
3467         lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
3468 #if _SAMBA_BUILD_ >= 4
3469         lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
3470         lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
3471         lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
3472         lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
3473         lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
3474                                         "%s/samba_kcc", dyn_SCRIPTSBINDIR);
3475 #endif
3476         lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
3477         lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
3478         lpcfg_do_global_parameter(lp_ctx, "idmap trusted only", "False");
3479
3480         lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
3481         lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
3482
3483         lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
3484
3485         lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
3486
3487         lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
3488         lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
3489         lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
3490         lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
3491         lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
3492         lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
3493         lpcfg_do_global_parameter(lp_ctx, "web port", "901");
3494
3495         lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
3496
3497         lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
3498         lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
3499
3500         lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
3501         lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
3502         lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
3503         lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
3504         lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
3505
3506         lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
3507         lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
3508
3509         lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
3510         lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
3511         lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
3512
3513         for (i = 0; parm_table[i].label; i++) {
3514                 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3515                         lp_ctx->flags[i] |= FLAG_DEFAULT;
3516                 }
3517         }
3518
3519         for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3520                 if (!(parm->priority & FLAG_CMDLINE)) {
3521                         parm->priority |= FLAG_DEFAULT;
3522                 }
3523         }
3524
3525         return lp_ctx;
3526 }
3527
3528 /**
3529  * Initialise the global parameter structure.
3530  */
3531 struct loadparm_context *loadparm_init_global(bool load_default)
3532 {
3533         if (global_loadparm_context == NULL) {
3534                 global_loadparm_context = loadparm_init(NULL);
3535         }
3536         if (global_loadparm_context == NULL) {
3537                 return NULL;
3538         }
3539         global_loadparm_context->global = true;
3540         if (load_default && !global_loadparm_context->loaded) {
3541                 lpcfg_load_default(global_loadparm_context);
3542         }
3543         global_loadparm_context->refuse_free = true;
3544         return global_loadparm_context;
3545 }
3546
3547 /**
3548  * Initialise the global parameter structure.
3549  */
3550 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx, 
3551                                           const struct loadparm_s3_context *s3_fns)
3552 {
3553         struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3554         if (!loadparm_context) {
3555                 return NULL;
3556         }
3557         loadparm_context->s3_fns = s3_fns;
3558         return loadparm_context;
3559 }
3560
3561 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3562 {
3563         return lp_ctx->szConfigFile;
3564 }
3565
3566 const char *lp_default_path(void)
3567 {
3568     if (getenv("SMB_CONF_PATH"))
3569         return getenv("SMB_CONF_PATH");
3570     else
3571         return dyn_CONFIGFILE;
3572 }
3573
3574 /**
3575  * Update the internal state of a loadparm context after settings 
3576  * have changed.
3577  */
3578 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3579 {
3580         struct debug_settings settings;
3581         lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
3582
3583         if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
3584                 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3585         }
3586
3587         if (!lp_ctx->global) {
3588                 return true;
3589         }
3590
3591         panic_action = lp_ctx->globals->panic_action;
3592
3593         reload_charcnv(lp_ctx);
3594
3595         ZERO_STRUCT(settings);
3596         /* Add any more debug-related smb.conf parameters created in
3597          * future here */
3598         settings.timestamp_logs = true;
3599         debug_set_settings(&settings);
3600
3601         /* FIXME: This is a bit of a hack, but we can't use a global, since 
3602          * not everything that uses lp also uses the socket library */
3603         if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3604                 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3605         } else {
3606                 unsetenv("SOCKET_TESTNONBLOCK");
3607         }
3608
3609         return true;
3610 }
3611
3612 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3613 {
3614     const char *path;
3615
3616     path = lp_default_path();
3617
3618     if (!file_exist(path)) {
3619             /* We allow the default smb.conf file to not exist, 
3620              * basically the equivalent of an empty file. */
3621             return lpcfg_update(lp_ctx);
3622     }
3623
3624     return lpcfg_load(lp_ctx, path);
3625 }
3626
3627 /**
3628  * Load the services array from the services file.
3629  *
3630  * Return True on success, False on failure.
3631  */
3632 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3633 {
3634         char *n2;
3635         bool bRetval;
3636
3637         filename = talloc_strdup(lp_ctx, filename);
3638
3639         lp_ctx->szConfigFile = filename;
3640
3641         if (lp_ctx->s3_fns) {
3642                 return lp_ctx->s3_fns->load(filename);
3643         }
3644
3645         lp_ctx->bInGlobalSection = true;
3646         n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3647         DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3648
3649         add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
3650
3651         /* We get sections first, so have to start 'behind' to make up */
3652         lp_ctx->currentService = NULL;
3653         bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
3654
3655         /* finish up the last section */
3656         DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3657         if (bRetval)
3658                 if (lp_ctx->currentService != NULL)
3659                         bRetval = lpcfg_service_ok(lp_ctx->currentService);
3660
3661         bRetval = bRetval && lpcfg_update(lp_ctx);
3662
3663         /* we do this unconditionally, so that it happens even
3664            for a missing smb.conf */
3665         reload_charcnv(lp_ctx);
3666
3667         if (bRetval == true) {
3668                 /* set this up so that any child python tasks will
3669                    find the right smb.conf */
3670                 setenv("SMB_CONF_PATH", filename, 1);
3671
3672                 /* set the context used by the lp_*() function
3673                    varients */
3674                 global_loadparm_context = lp_ctx;
3675                 lp_ctx->loaded = true;
3676         }
3677
3678         return bRetval;
3679 }
3680
3681 /**
3682  * Return the max number of services.
3683  */
3684
3685 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3686 {
3687         if (lp_ctx->s3_fns) {
3688                 return lp_ctx->s3_fns->get_numservices();
3689         }
3690
3691         return lp_ctx->iNumServices;
3692 }
3693
3694 /**
3695  * Display the contents of the services array in human-readable form.
3696  */
3697
3698 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3699              int maxtoprint)
3700 {
3701         int iService;
3702
3703         if (lp_ctx->s3_fns) {
3704                 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3705                 return;
3706         }
3707
3708         defaults_saved = !show_defaults;
3709
3710         dump_globals(lp_ctx, f, show_defaults);
3711
3712         dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
3713
3714         for (iService = 0; iService < maxtoprint; iService++)
3715                 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3716 }
3717
3718 /**
3719  * Display the contents of one service in human-readable form.
3720  */
3721 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3722 {
3723         if (service != NULL) {
3724                 if (service->szService[0] == '\0')
3725                         return;
3726                 dump_a_service(service, sDefault, f, NULL);
3727         }
3728 }
3729
3730 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3731                                             int snum)
3732 {
3733         if (lp_ctx->s3_fns) {
3734                 return lp_ctx->s3_fns->get_servicebynum(snum);
3735         }
3736
3737         return lp_ctx->services[snum];
3738 }
3739
3740 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3741                                     const char *service_name)
3742 {
3743         int iService;
3744         char *serviceName;
3745
3746         if (lp_ctx->s3_fns) {
3747                 return lp_ctx->s3_fns->get_service(service_name);
3748         }
3749
3750         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3751                 if (lp_ctx->services[iService] &&
3752                     lp_ctx->services[iService]->szService) {
3753                         /*
3754                          * The substitution here is used to support %U is
3755                          * service names
3756                          */
3757                         serviceName = standard_sub_basic(
3758                                         lp_ctx->services[iService],
3759                                         lp_ctx->services[iService]->szService);
3760                         if (strequal(serviceName, service_name)) {
3761                                 talloc_free(serviceName);
3762                                 return lp_ctx->services[iService];
3763                         }
3764                         talloc_free(serviceName);
3765                 }
3766         }
3767
3768         DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3769         return NULL;
3770 }
3771
3772 const char *lpcfg_servicename(const struct loadparm_service *service)
3773 {
3774         return lp_string((const char *)service->szService);
3775 }
3776
3777 /**
3778  * A useful volume label function.
3779  */
3780 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3781 {
3782         const char *ret;
3783         ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
3784                                        service->volume : sDefault->volume));
3785         if (!*ret)
3786                 return lpcfg_servicename(service);
3787         return ret;
3788 }
3789
3790 /**
3791  * If we are PDC then prefer us as DMB
3792  */
3793 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3794 {
3795         const char *ret;
3796         ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
3797                                        service->szPrintername : sDefault->szPrintername));
3798         if (ret == NULL || (ret != NULL && *ret == '\0'))
3799                 ret = lpcfg_servicename(service);
3800
3801         return ret;
3802 }
3803
3804
3805 /**
3806  * Return the max print jobs per queue.
3807  */
3808 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3809 {
3810         int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3811         if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3812                 maxjobs = PRINT_MAX_JOBID - 1;
3813
3814         return maxjobs;
3815 }
3816
3817 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3818 {
3819         if (lp_ctx == NULL) {
3820                 return get_iconv_handle();
3821         }
3822         return lp_ctx->iconv_handle;
3823 }
3824
3825 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3826 {
3827         struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3828         if (!lp_ctx->global) {
3829                 return;
3830         }
3831
3832         if (old_ic == NULL) {
3833                 old_ic = global_iconv_handle;
3834         }
3835         lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3836         global_iconv_handle = lp_ctx->iconv_handle;
3837 }
3838
3839 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3840 {
3841         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
3842 }
3843
3844 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3845 {
3846         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
3847 }
3848
3849 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3850 {
3851         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
3852 }
3853
3854 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3855 {
3856         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
3857 }
3858
3859 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3860 {
3861         return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
3862 }
3863
3864 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3865 {
3866         struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3867         if (settings == NULL)
3868                 return NULL;
3869         SMB_ASSERT(lp_ctx != NULL);
3870         settings->lp_ctx = talloc_reference(settings, lp_ctx);
3871         settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3872         return settings;
3873 }
3874
3875 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3876 {
3877         if (lp_ctx->s3_fns) {
3878                 return lp_ctx->s3_fns->server_role();
3879         }
3880
3881         return lp_find_server_role(lp_ctx->globals->server_role,
3882                                    lp_ctx->globals->security,
3883                                    lp_ctx->globals->domain_logons,
3884                                    (lp_ctx->globals->domain_master == true) ||
3885                                    (lp_ctx->globals->domain_master == Auto));
3886 }
3887
3888 int lpcfg_security(struct loadparm_context *lp_ctx)
3889 {
3890         if (lp_ctx->s3_fns) {
3891                 return lp_ctx->s3_fns->security();
3892         }
3893
3894         return lp_find_security(lp_ctx->globals->server_role,
3895                                 lp_ctx->globals->security);
3896 }