s3-param Fix lp_set_cmdline() to set the flag on alias values too
[kai/samba.git] / source3 / param / loadparm.c
index b20b56578cd1b37c5acb89cc244403e2aff91c50..0bc27dca0337b55be513ce04377ad64b967ee20c 100644 (file)
 #include "ads.h"
 #include "../librpc/gen_ndr/svcctl.h"
 
+#include "smb_signing.h"
+#include "dbwrap.h"
+#include "smbldap.h"
+
 #ifdef HAVE_SYS_SYSCTL_H
 #include <sys/sysctl.h>
 #endif
@@ -114,6 +118,7 @@ struct param_opt_struct {
        char *key;
        char *value;
        char **list;
+       unsigned flags;
 };
 
 /*
@@ -258,7 +263,7 @@ struct global {
        int oplock_break_wait_time;
        int winbind_cache_time;
        int winbind_reconnect_delay;
-       int winbind_max_idle_children;
+       int winbind_max_clients;
        char **szWinbindNssInfo;
        int iLockSpinTime;
        char *szLdapMachineSuffix;
@@ -369,9 +374,11 @@ struct global {
        char *szSMBPerfcountModule;
        bool bMapUntrustedToDomain;
        bool bAsyncSMBEchoHandler;
+       bool bMulticastDnsRegister;
        int ismb2_max_read;
        int ismb2_max_write;
        int ismb2_max_trans;
+       char *ncalrpc_dir;
 };
 
 static struct global Globals;
@@ -702,6 +709,7 @@ static void set_allowed_client_auth(void);
 static void *lp_local_ptr(struct service *service, void *ptr);
 
 static void add_to_file_list(const char *fname, const char *subfname);
+static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue, bool store_values);
 
 static const struct enum_list enum_protocol[] = {
        {PROTOCOL_SMB2, "SMB2"},
@@ -1101,15 +1109,6 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_WIZARD,
        },
-       {
-               .label          = "update encrypted",
-               .type           = P_BOOL,
-               .p_class        = P_GLOBAL,
-               .ptr            = &Globals.bUpdateEncrypt,
-               .special        = NULL,
-               .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED,
-       },
        {
                .label          = "client schannel",
                .type           = P_ENUM,
@@ -4410,6 +4409,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
        },
+       {
+               .label          = "multicast dns register",
+               .type           = P_BOOL,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.bMulticastDnsRegister,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
+       },
        {
                .label          = "panic action",
                .type           = P_STRING,
@@ -4609,6 +4617,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "winbind max clients",
+               .type           = P_INTEGER,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.winbind_max_clients,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
        {
                .label          = "winbind enum users",
                .type           = P_BOOL,
@@ -4717,6 +4734,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "ncalrpc dir",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.ncalrpc_dir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
 
        {NULL,  P_BOOL,  P_NONE,  NULL,  NULL,  NULL,  0}
 };
@@ -4950,18 +4976,80 @@ static void free_global_parameters(void)
        free_parameters_by_snum(GLOBAL_SECTION_SNUM);
 }
 
+static int map_parameter(const char *pszParmName);
+
+struct lp_stored_option {
+       struct lp_stored_option *prev, *next;
+       const char *label;
+       const char *value;
+};
+
+static struct lp_stored_option *stored_options;
+
+/*
+  save options set by lp_set_cmdline() into a list. This list is
+  re-applied when we do a globals reset, so that cmdline set options
+  are sticky across reloads of smb.conf
+ */
+static bool store_lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
+{
+       struct lp_stored_option *entry, *entry_next;
+       for (entry = stored_options; entry != NULL; entry = entry_next) {
+               entry_next = entry->next;
+               if (strcmp(pszParmName, entry->label) == 0) {
+                       DLIST_REMOVE(stored_options, entry);
+                       talloc_free(entry);
+                       break;
+               }
+       }
+
+       entry = talloc(NULL, struct lp_stored_option);
+       if (!entry) {
+               return false;
+       }
+
+       entry->label = talloc_strdup(entry, pszParmName);
+       if (!entry->label) {
+               talloc_free(entry);
+               return false;
+       }
+
+       entry->value = talloc_strdup(entry, pszParmValue);
+       if (!entry->value) {
+               talloc_free(entry);
+               return false;
+       }
+
+       DLIST_ADD_END(stored_options, entry, struct lp_stored_option);
+
+       return true;
+}
+
+static bool apply_lp_set_cmdline(void)
+{
+       struct lp_stored_option *entry = NULL;
+       for (entry = stored_options; entry != NULL; entry = entry->next) {
+               if (!lp_set_cmdline_helper(entry->label, entry->value, false)) {
+                       DEBUG(0, ("Failed to re-apply cmdline parameter %s = %s\n",
+                                 entry->label, entry->value));
+                       return false;
+               }
+       }
+       return true;
+}
+
 /***************************************************************************
  Initialise the global parameter structure.
 ***************************************************************************/
 
-static void init_globals(bool first_time_only)
+static void init_globals(bool reinit_globals)
 {
        static bool done_init = False;
        char *s = NULL;
        int i;
 
         /* If requested to initialize only once and we've already done it... */
-        if (first_time_only && done_init) {
+        if (!reinit_globals && done_init) {
                 /* ... then we have nothing more to do */
                 return;
         }
@@ -4977,6 +5065,10 @@ static void init_globals(bool first_time_only)
                free_global_parameters();
        }
 
+       /* This memset and the free_global_parameters() above will
+        * wipe out smb.conf options set with lp_set_cmdline().  The
+        * apply_lp_set_cmdline() call puts these values back in the
+        * table once the defaults are set */
        memset((void *)&Globals, '\0', sizeof(Globals));
 
        for (i = 0; parm_table[i].label; i++) {
@@ -5238,13 +5330,14 @@ static void init_globals(bool first_time_only)
 
        Globals.winbind_cache_time = 300;       /* 5 minutes */
        Globals.winbind_reconnect_delay = 30;   /* 30 seconds */
+       Globals.winbind_max_clients = 200;
        Globals.bWinbindEnumUsers = False;
        Globals.bWinbindEnumGroups = False;
        Globals.bWinbindUseDefaultDomain = False;
        Globals.bWinbindTrustedDomainsOnly = False;
        Globals.bWinbindNestedGroups = True;
        Globals.winbind_expand_groups = 1;
-       Globals.szWinbindNssInfo = str_list_make_v3(talloc_autofree_context(), "template", NULL);
+       Globals.szWinbindNssInfo = str_list_make_v3(NULL, "template", NULL);
        Globals.bWinbindRefreshTickets = False;
        Globals.bWinbindOfflineLogon = False;
 
@@ -5289,10 +5382,16 @@ static void init_globals(bool first_time_only)
        Globals.iminreceivefile = 0;
 
        Globals.bMapUntrustedToDomain = false;
+       Globals.bMulticastDnsRegister = true;
 
        Globals.ismb2_max_read = 1024*1024;
        Globals.ismb2_max_write = 1024*1024;
        Globals.ismb2_max_trans = 1024*1024;
+
+       string_set(&Globals.ncalrpc_dir, get_dyn_NCALRPCDIR());
+
+       /* Now put back the settings that were set with lp_set_cmdline() */
+       apply_lp_set_cmdline();
 }
 
 /*******************************************************************
@@ -5367,8 +5466,6 @@ static char *lp_string(const char *s)
  bool fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 #define FN_LOCAL_PARM_INTEGER(fn_name,val) \
  int fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
-#define FN_LOCAL_PARM_STRING(fn_name,val) \
- char *fn_name(const struct share_params *p) {return(lp_string((LP_SNUM_OK(p->service) && ServicePtrs[(p->service)]->val) ? ServicePtrs[(p->service)]->val : sDefault.val));}
 #define FN_LOCAL_CHAR(fn_name,val) \
  char fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 
@@ -5577,7 +5674,6 @@ FN_GLOBAL_BOOL(_lp_writeraw, &Globals.bWriteRaw)
 FN_GLOBAL_BOOL(lp_null_passwords, &Globals.bNullPasswords)
 FN_GLOBAL_BOOL(lp_obey_pam_restrictions, &Globals.bObeyPamRestrictions)
 FN_GLOBAL_BOOL(lp_encrypted_passwords, &Globals.bEncryptPasswords)
-FN_GLOBAL_BOOL(lp_update_encrypted, &Globals.bUpdateEncrypt)
 FN_GLOBAL_INTEGER(lp_client_schannel, &Globals.clientSchannel)
 FN_GLOBAL_INTEGER(lp_server_schannel, &Globals.serverSchannel)
 FN_GLOBAL_BOOL(lp_syslog_only, &Globals.bSyslogOnly)
@@ -5772,6 +5868,7 @@ FN_LOCAL_BOOL(lp_dos_filetimes, bDosFiletimes)
 FN_LOCAL_BOOL(lp_dos_filetime_resolution, bDosFiletimeResolution)
 FN_LOCAL_BOOL(lp_fake_dir_create_times, bFakeDirCreateTimes)
 FN_GLOBAL_BOOL(lp_async_smb_echo_handler, &Globals.bAsyncSMBEchoHandler)
+FN_GLOBAL_BOOL(lp_multicast_dns_register, &Globals.bMulticastDnsRegister)
 FN_LOCAL_BOOL(lp_blocking_locks, bBlockingLocks)
 FN_LOCAL_BOOL(lp_inherit_perms, bInheritPerms)
 FN_LOCAL_BOOL(lp_inherit_acls, bInheritACLS)
@@ -5816,6 +5913,7 @@ FN_LOCAL_INTEGER(lp_smb_encrypt, ismb_encrypt)
 FN_LOCAL_CHAR(lp_magicchar, magic_char)
 FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time)
 FN_GLOBAL_INTEGER(lp_winbind_reconnect_delay, &Globals.winbind_reconnect_delay)
+FN_GLOBAL_INTEGER(lp_winbind_max_clients, &Globals.winbind_max_clients)
 FN_GLOBAL_LIST(lp_winbind_nss_info, &Globals.szWinbindNssInfo)
 FN_GLOBAL_INTEGER(lp_algorithmic_rid_base, &Globals.AlgorithmicRidBase)
 FN_GLOBAL_INTEGER(lp_name_cache_timeout, &Globals.name_cache_timeout)
@@ -5823,9 +5921,10 @@ FN_GLOBAL_INTEGER(lp_client_signing, &Globals.client_signing)
 FN_GLOBAL_INTEGER(lp_server_signing, &Globals.server_signing)
 FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, &Globals.client_ldap_sasl_wrapping)
 
+FN_GLOBAL_STRING(lp_ncalrpc_dir, &Globals.ncalrpc_dir)
+
 /* local prototypes */
 
-static int map_parameter(const char *pszParmName);
 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
 static const char *get_boolean(bool bool_value);
 static int getservicebyname(const char *pszServiceName,
@@ -6023,7 +6122,7 @@ const char **lp_parm_string_list(int snum, const char *type, const char *option,
                return (const char **)def;
 
        if (data->list==NULL) {
-               data->list = str_list_make_v3(talloc_autofree_context(), data->value, NULL);
+               data->list = str_list_make_v3(NULL, data->value, NULL);
        }
 
        return (const char **)data->list;
@@ -6191,9 +6290,6 @@ static int add_a_service(const struct service *pservice, const char *name)
        if (name) {
                i = getservicebyname(name, NULL);
                if (i >= 0) {
-                       /* Clean all parametric options for service */
-                       /* They will be added during parsing again */
-                       free_param_opts(&ServicePtrs[i]->param_opt);
                        return (i);
                }
        }
@@ -6828,7 +6924,8 @@ static int getservicebyname(const char *pszServiceName, struct service *pservice
  */
 static void set_param_opt(struct param_opt_struct **opt_list,
                          const char *opt_name,
-                         const char *opt_value)
+                         const char *opt_value,
+                         unsigned flags)
 {
        struct param_opt_struct *new_opt, *opt;
        bool not_added;
@@ -6844,9 +6941,16 @@ static void set_param_opt(struct param_opt_struct **opt_list,
        while (opt) {
                /* If we already have same option, override it */
                if (strwicmp(opt->key, opt_name) == 0) {
+                       if ((opt->flags & FLAG_CMDLINE) &&
+                           !(flags & FLAG_CMDLINE)) {
+                               /* it's been marked as not to be
+                                  overridden */
+                               return;
+                       }
                        string_free(&opt->value);
                        TALLOC_FREE(opt->list);
                        opt->value = SMB_STRDUP(opt_value);
+                       opt->flags = flags;
                        not_added = false;
                        break;
                }
@@ -6857,6 +6961,7 @@ static void set_param_opt(struct param_opt_struct **opt_list,
            new_opt->key = SMB_STRDUP(opt_name);
            new_opt->value = SMB_STRDUP(opt_value);
            new_opt->list = NULL;
+           new_opt->flags = flags;
            DLIST_ADD(*opt_list, new_opt);
        }
 }
@@ -6924,7 +7029,7 @@ static void copy_service(struct service *pserviceDest, struct service *pserviceS
 
        data = pserviceSource->param_opt;
        while (data) {
-               set_param_opt(&pserviceDest->param_opt, data->key, data->value);
+               set_param_opt(&pserviceDest->param_opt, data->key, data->value, data->flags);
                data = data->next;
        }
 }
@@ -7325,7 +7430,7 @@ static bool handle_netbios_scope(int snum, const char *pszParmValue, char **ptr)
 static bool handle_netbios_aliases(int snum, const char *pszParmValue, char **ptr)
 {
        TALLOC_FREE(Globals.szNetbiosAliases);
-       Globals.szNetbiosAliases = str_list_make_v3(talloc_autofree_context(), pszParmValue, NULL);
+       Globals.szNetbiosAliases = str_list_make_v3(NULL, pszParmValue, NULL);
        return set_netbios_aliases((const char **)Globals.szNetbiosAliases);
 }
 
@@ -7623,8 +7728,7 @@ static void init_copymap(struct service *pservice)
 
        TALLOC_FREE(pservice->copymap);
 
-       pservice->copymap = bitmap_talloc(talloc_autofree_context(),
-                                         NUMPARAMETERS);
+       pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
        if (!pservice->copymap)
                DEBUG(0,
                      ("Couldn't allocate copymap!! (size %d)\n",
@@ -7681,11 +7785,17 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 
                opt_list = (snum < 0)
                        ? &Globals.param_opt : &ServicePtrs[snum]->param_opt;
-               set_param_opt(opt_list, pszParmName, pszParmValue);
+               set_param_opt(opt_list, pszParmName, pszParmValue, 0);
 
                return (True);
        }
 
+       /* if it's already been set by the command line, then we don't
+          override here */
+       if (parm_table[parmnum].flags & FLAG_CMDLINE) {
+               return true;
+       }
+
        if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
                DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
                          pszParmName));
@@ -7752,7 +7862,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                case P_LIST:
                        TALLOC_FREE(*((char ***)parm_ptr));
                        *(char ***)parm_ptr = str_list_make_v3(
-                               talloc_autofree_context(), pszParmValue, NULL);
+                               NULL, pszParmValue, NULL);
                        break;
 
                case P_STRING:
@@ -7774,6 +7884,56 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
        return (True);
 }
 
+/***************************************************************************
+set a parameter, marking it with FLAG_CMDLINE. Parameters marked as
+FLAG_CMDLINE won't be overridden by loads from smb.conf.
+***************************************************************************/
+
+static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue, bool store_values)
+{
+       int parmnum, i;
+       parmnum = map_parameter(pszParmName);
+       if (parmnum >= 0) {
+               parm_table[parmnum].flags &= ~FLAG_CMDLINE;
+               if (!lp_do_parameter(-1, pszParmName, pszParmValue)) {
+                       return false;
+               }
+               parm_table[parmnum].flags |= FLAG_CMDLINE;
+
+               /* we have to also set FLAG_CMDLINE on aliases.  Aliases must
+                * be grouped in the table, so we don't have to search the
+                * whole table */
+               for (i=parmnum-1;i>=0 && parm_table[i].ptr == parm_table[parmnum].ptr;i--) {
+                       parm_table[i].flags |= FLAG_CMDLINE;
+               }
+               for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].ptr == parm_table[parmnum].ptr;i++) {
+                       parm_table[i].flags |= FLAG_CMDLINE;
+               }
+
+               if (store_values) {
+                       store_lp_set_cmdline(pszParmName, pszParmValue);
+               }
+               return true;
+       }
+
+       /* it might be parametric */
+       if (strchr(pszParmName, ':') != NULL) {
+               set_param_opt(&Globals.param_opt, pszParmName, pszParmValue, FLAG_CMDLINE);
+               if (store_values) {
+                       store_lp_set_cmdline(pszParmName, pszParmValue);
+               }
+               return true;
+       }
+
+       DEBUG(0, ("Ignoring unknown parameter \"%s\"\n",  pszParmName));
+       return true;
+}
+
+bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
+{
+       return lp_set_cmdline_helper(pszParmName, pszParmValue, true);
+}
+
 /***************************************************************************
  Process a parameter.
 ***************************************************************************/
@@ -7790,7 +7950,33 @@ static bool do_parameter(const char *pszParmName, const char *pszParmValue,
                                pszParmName, pszParmValue));
 }
 
-/***************************************************************************
+/*
+  set a option from the commandline in 'a=b' format. Use to support --option
+*/
+bool lp_set_option(const char *option)
+{
+       char *p, *s;
+       bool ret;
+
+       s = talloc_strdup(NULL, option);
+       if (!s) {
+               return false;
+       }
+
+       p = strchr(s, '=');
+       if (!p) {
+               talloc_free(s);
+               return false;
+       }
+
+       *p = 0;
+
+       ret = lp_set_cmdline(s, p+1);
+       talloc_free(s);
+       return ret;
+}
+
+/**************************************************************************
  Print a parameter of the specified type.
 ***************************************************************************/
 
@@ -7949,6 +8135,9 @@ static bool do_section(const char *pszSectionName, void *userdata)
                        DEBUG(0, ("Failed to add a new service\n"));
                        return (False);
                }
+               /* Clean all parametric options for service */
+               /* They will be added during parsing again */
+               free_param_opts(&ServicePtrs[iServiceIndex]->param_opt);
        }
 
        return (bRetval);
@@ -9170,13 +9359,13 @@ bool lp_is_in_client(void)
  False on failure.
 ***************************************************************************/
 
-bool lp_load_ex(const char *pszFname,
-               bool global_only,
-               bool save_defaults,
-               bool add_ipc,
-               bool initialize_globals,
-               bool allow_include_registry,
-               bool allow_registry_shares)
+static bool lp_load_ex(const char *pszFname,
+                      bool global_only,
+                      bool save_defaults,
+                      bool add_ipc,
+                      bool initialize_globals,
+                      bool allow_include_registry,
+                      bool allow_registry_shares)
 {
        char *n2 = NULL;
        bool bRetval;
@@ -9189,7 +9378,7 @@ bool lp_load_ex(const char *pszFname,
        bGlobalOnly = global_only;
        bAllowIncludeRegistry = allow_include_registry;
 
-       init_globals(initialize_globals);
+       init_globals(initialize_globals);
        debug_init();
 
        free_file_list();
@@ -9237,7 +9426,7 @@ bool lp_load_ex(const char *pszFname,
                        /* start over */
                        DEBUG(1, ("lp_load_ex: changing to config backend "
                                  "registry\n"));
-                       init_globals(false);
+                       init_globals(true);
                        lp_kill_all_services();
                        return lp_load_ex(pszFname, global_only, save_defaults,
                                          add_ipc, initialize_globals,
@@ -9441,17 +9630,11 @@ struct share_params *get_share_params(TALLOC_CTX *mem_ctx,
                                      const char *sharename)
 {
        struct share_params *result;
-       char *sname;
+       char *sname = NULL;
        int snum;
 
-       if (!(sname = SMB_STRDUP(sharename))) {
-               return NULL;
-       }
-
-       snum = find_service(sname);
-       SAFE_FREE(sname);
-
-       if (snum < 0) {
+       snum = find_service(mem_ctx, sharename, &sname);
+       if (snum < 0 || sname == NULL) {
                return NULL;
        }