loadparm: fix init_globals() to re-init all options event when called 2nd time.
authorMichael Adam <obnox@samba.org>
Mon, 10 Mar 2008 16:16:01 +0000 (17:16 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 10 Mar 2008 16:22:41 +0000 (17:22 +0100)
Up to the globals had only been fully reset when init_globals() was called
for the first time. But a full restart is needed for use with
"config backend = registry". (And should be with "config file = ...", but
in this case the restart is outsourced to the daemons.) This left
some options (like e.g. "realm") set to values that were set in smb.conf
before the occurence of "config backend = registry".

Now this misbehaviour is fixed with this change.

Michael

source/param/loadparm.c

index d17fa16cbbfb2864ad046defadbea35207f60475..aaeafac21eae7dd6c7dd17a785bdc256cf3caadb 100644 (file)
@@ -4535,6 +4535,7 @@ static void init_globals(bool first_time_only)
 {
        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) {
@@ -4543,30 +4544,39 @@ static void init_globals(bool first_time_only)
         }
 
        if (!done_init) {
-               int i;
-
                /* The logfile can be set before this is invoked. Free it if so. */
                if (Globals.szLogFile != NULL) {
                        string_free(&Globals.szLogFile);
                        Globals.szLogFile = NULL;
                }
-
-               memset((void *)&Globals, '\0', sizeof(Globals));
-
-               for (i = 0; parm_table[i].label; i++)
+               done_init = True;
+       } else {
+               for (i = 0; parm_table[i].label; i++) {
                        if ((parm_table[i].type == P_STRING ||
                             parm_table[i].type == P_USTRING) &&
                            parm_table[i].ptr)
-                               string_set((char **)parm_table[i].ptr, "");
-
-               string_set(&sDefault.fstype, FSTYPE_STRING);
-               string_set(&sDefault.szPrintjobUsername, "%U");
+                       {
+                               string_free((char **)parm_table[i].ptr);
+                       }
+               }
+       }
 
-               init_printer_values(&sDefault);
+       memset((void *)&Globals, '\0', sizeof(Globals));
 
-               done_init = True;
+       for (i = 0; parm_table[i].label; i++) {
+               if ((parm_table[i].type == P_STRING ||
+                    parm_table[i].type == P_USTRING) &&
+                   parm_table[i].ptr)
+               {
+                       string_set((char **)parm_table[i].ptr, "");
+               }
        }
 
+       string_set(&sDefault.fstype, FSTYPE_STRING);
+       string_set(&sDefault.szPrintjobUsername, "%U");
+
+       init_printer_values(&sDefault);
+
 
        DEBUG(3, ("Initialising global parameters\n"));