s3-loadparm: fixed a memory leak in parametric options
[nivanova/samba-autobuild/.git] / source3 / param / loadparm.c
index 3409a34aa2158e8947f97f11bdf7d3bbbd1763fb..21fa662141bd69addc6f2ab8cbdba7081290c69c 100644 (file)
@@ -65,7 +65,7 @@
 #include "../librpc/gen_ndr/svcctl.h"
 #include "intl.h"
 #include "smb_signing.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
 #include "smbldap.h"
 #include "../lib/util/bitmap.h"
 
@@ -310,9 +310,11 @@ static void set_allowed_client_auth(void);
 
 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 void free_param_opts(struct parmlist_entry **popts);
 
 static const struct enum_list enum_protocol[] = {
-       {PROTOCOL_SMB2_02, "SMB2"},
+       {PROTOCOL_SMB2_02, "SMB2"}, /* for now keep PROTOCOL_SMB2_02 */
+       {PROTOCOL_SMB2_10, "SMB2_10"},
        {PROTOCOL_SMB2_02, "SMB2_02"},
        {PROTOCOL_NT1, "NT1"},
        {PROTOCOL_LANMAN2, "LANMAN2"},
@@ -4604,6 +4606,7 @@ static void free_parameters_by_snum(int snum)
  */
 static void free_global_parameters(void)
 {
+       free_param_opts(&Globals.param_opt);
        free_parameters_by_snum(GLOBAL_SECTION_SNUM);
 }
 
@@ -4700,7 +4703,7 @@ static void init_globals(bool reinit_globals)
         * 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));
+       ZERO_STRUCT(Globals);
 
        for (i = 0; parm_table[i].label; i++) {
                if ((parm_table[i].type == P_STRING ||
@@ -5419,7 +5422,6 @@ static bool do_section(const char *pszSectionName, void *userdata);
 static void init_copymap(struct loadparm_service *pservice);
 static bool hash_a_service(const char *name, int number);
 static void free_service_byindex(int iService);
-static void free_param_opts(struct parmlist_entry **popts);
 static void show_parameter(int parmIndex);
 static bool is_synonym_of(int parm1, int parm2, bool *inverse);
 
@@ -8940,7 +8942,7 @@ void gfree_loadparm(void)
 /***************************************************************************
  Allow client apps to specify that they are a client
 ***************************************************************************/
-void lp_set_in_client(bool b)
+static void lp_set_in_client(bool b)
 {
     in_client = b;
 }
@@ -9139,7 +9141,33 @@ bool lp_load_client(const char *file_name)
 {
        lp_set_in_client(true);
 
-       return lp_load_global_only(file_name);
+       return lp_load_global(file_name);
+}
+
+/**
+ * lp_load wrapper, loading only globals, but intended
+ * for subsequent calls, not reinitializing the globals
+ * to default values
+ */
+bool lp_load_global_no_reinit(const char *file_name)
+{
+       return lp_load_ex(file_name,
+                         true,   /* global_only */
+                         false,  /* save_defaults */
+                         false,  /* add_ipc */
+                         false,  /* initialize_globals */
+                         true,   /* allow_include_registry */
+                         false); /* load_all_shares*/
+}
+
+/**
+ * lp_load wrapper, especially for clients, no reinitialization
+ */
+bool lp_load_client_no_reinit(const char *file_name)
+{
+       lp_set_in_client(true);
+
+       return lp_load_global_no_reinit(file_name);
 }
 
 bool lp_load_with_registry_shares(const char *pszFname,