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