Patch from Stefan Metzmacher to add default parameters to the lp_parm()
authorJelmer Vernooij <jelmer@samba.org>
Thu, 24 Apr 2003 03:54:54 +0000 (03:54 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 24 Apr 2003 03:54:54 +0000 (03:54 +0000)
smb.conf parameters along with some other small fixes. Binary
compatible with older modules.
(This used to be commit aa07b12fda732ca19d8dc41cebc7bb09e2549a30)

source3/include/smb_macros.h
source3/modules/mysql.c
source3/modules/vfs_recycle.c
source3/modules/xml.c
source3/param/loadparm.c
source3/sam/sam_ads.c

index 477940445c05e201b1a341c8b9a5ba8f829f9c98..8e2cb1c81856a054739d7f7b24537276d4d0b51c 100644 (file)
 #define ERROR_WAS_LOCK_DENIED(status) (NT_STATUS_EQUAL((status), NT_STATUS_LOCK_NOT_GRANTED) || \
                                NT_STATUS_EQUAL((status), NT_STATUS_FILE_LOCK_CONFLICT) )
 
+/* the service number for the [globals] defaults */ 
+#define GLOBAL_SECTION_SNUM    (-1)
 /* translates a connection number into a service number */
-#define SNUM(conn)         ((conn)?(conn)->service:-1)
+#define SNUM(conn)             ((conn)?(conn)->service:GLOBAL_SECTION_SNUM)
+
 
 /* access various service details */
 #define SERVICE(snum)      (lp_servicename(snum))
index 684eb96645ea6279dbf736988710adfb252cf302..ec8c6f9ab8a356c6f99e41844f5e2f903a9449a1 100644 (file)
 #define CONFIG_LOGON_TIME_DEFAULT                      "logon_time"
 #define CONFIG_LOGOFF_TIME_DEFAULT                     "logoff_time"
 #define CONFIG_KICKOFF_TIME_DEFAULT                    "kickoff_time"
-#define CONFIG_PASS_LAST_SET_TIME_DEFAULT      "pass_last_set_time"
-#define CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT    "pass_can_change_time"
-#define CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT "pass_must_change_time"
+#define CONFIG_PASS_LAST_SET_TIME_DEFAULT              "pass_last_set_time"
+#define CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT            "pass_can_change_time"
+#define CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT           "pass_must_change_time"
 #define CONFIG_USERNAME_DEFAULT                        "username"
 #define CONFIG_DOMAIN_DEFAULT                          "domain"
-#define CONFIG_NT_USERNAME_DEFAULT             "nt_username"
+#define CONFIG_NT_USERNAME_DEFAULT                     "nt_username"
 #define CONFIG_FULLNAME_DEFAULT                                "nt_fullname"
 #define CONFIG_HOME_DIR_DEFAULT                                "home_dir"
 #define CONFIG_DIR_DRIVE_DEFAULT                       "dir_drive"
@@ -40,8 +40,8 @@
 #define CONFIG_WORKSTATIONS_DEFAULT                    "workstations"
 #define CONFIG_UNKNOWN_STR_DEFAULT                     "unknown_str"
 #define CONFIG_MUNGED_DIAL_DEFAULT                     "munged_dial"
-#define CONFIG_UID_DEFAULT                                     "uid"
-#define CONFIG_GID_DEFAULT                                     "gid"
+#define CONFIG_UID_DEFAULT                             "uid"
+#define CONFIG_GID_DEFAULT                             "gid"
 #define CONFIG_USER_SID_DEFAULT                                "user_sid"
 #define CONFIG_GROUP_SID_DEFAULT                       "group_sid"
 #define CONFIG_LM_PW_DEFAULT                           "lm_pw"
 #define CONFIG_HOURS_LEN_DEFAULT                       "hours_len"
 #define CONFIG_UNKNOWN_5_DEFAULT                       "unknown_5"
 #define CONFIG_UNKNOWN_6_DEFAULT                       "unknown_6"
-#define CONFIG_HOST_DEFAULT                                    "localhost"
-#define CONFIG_USER_DEFAULT                                    "samba"
-#define CONFIG_PASS_DEFAULT                                    ""
-#define CONFIG_PORT_DEFAULT                                    "3306"
-#define CONFIG_DB_DEFAULT                                      "samba"
+#define CONFIG_HOST_DEFAULT                            "localhost"
+#define CONFIG_USER_DEFAULT                            "samba"
+#define CONFIG_PASS_DEFAULT                            ""
+#define CONFIG_PORT_DEFAULT                            "3306"
+#define CONFIG_DB_DEFAULT                              "samba"
 
 static int mysqlsam_debug_level = DBGC_ALL;
 
@@ -91,7 +91,7 @@ typedef struct pdb_mysql_query {
 }
 
 static void pdb_mysql_int_field(struct pdb_methods *m,
-                                       struct pdb_mysql_query *q, char *name, int value)
+                                       struct pdb_mysql_query *q, const char *name, int value)
 {
        if (!name || strchr(name, '\''))
                return;                 /* This field shouldn't be set by us */
@@ -110,7 +110,7 @@ static void pdb_mysql_int_field(struct pdb_methods *m,
 
 static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods,
                                           struct pdb_mysql_query *q,
-                                          char *name, const char *value)
+                                          const char *name, const char *value)
 {
        char *esc_value;
        struct pdb_mysql_data *data;
@@ -145,20 +145,17 @@ static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods,
        return NT_STATUS_OK;
 }
 
-static char * config_value(pdb_mysql_data * data, char *name, char *default_value)
-{
-       if (lp_parm_string(NULL, data->location, name))
-               return lp_parm_string(NULL, data->location, name);
+#define config_value(data,name,default_value) \
+       lp_parm_const_string(GLOBAL_SECTION_SNUM, (data)->location, name, default_value)
 
-       return default_value;
-}
+static const char * config_value_write(pdb_mysql_data * data, const char *name, const char *default_value) {
+       char const *v = NULL;
+       char const *swrite = NULL;
 
-static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) {
-       char *v = config_value(data, name, NULL);
-       char *swrite;
+       v = lp_parm_const_string(GLOBAL_SECTION_SNUM, data->location, name, default_value);
 
        if (!v)
-               return default_value;
+               return NULL;
 
        swrite = strchr(v, ':');
 
@@ -176,13 +173,15 @@ static char * config_value_write(pdb_mysql_data * data, char *name, char *defaul
        return swrite;
 }
 
-static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value)
+static const char * config_value_read(pdb_mysql_data * data, const char *name, const char *default_value)
 {
-       char *v = config_value(data, name, NULL);
+       char *v = NULL;
        char *swrite;
 
+       v = lp_parm_talloc_string(GLOBAL_SECTION_SNUM, data->location, name, default_value);
+
        if (!v)
-               return default_value;
+               return "NULL";
 
        swrite = strchr(v, ':');
 
@@ -190,7 +189,7 @@ static const char * config_value_read(pdb_mysql_data * data, char *name, char *d
        if (!swrite) {
                if (strlen(v) == 0)
                        return "NULL";
-               return v;
+               return (const char *)v;
        }
 
        /* Otherwise, we have to cut the ':write_part' */
@@ -198,11 +197,11 @@ static const char * config_value_read(pdb_mysql_data * data, char *name, char *d
        if (strlen(v) == 0)
                return "NULL";
 
-       return v;
+       return (const char *)v;
 }
 
 /* Wrapper for atol that returns 0 if 'a' points to NULL */
-static long xatol(char *a)
+static long xatol(const char *a)
 {
        long ret = 0;
 
@@ -369,7 +368,7 @@ static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update)
        }
        
        DEBUG(5,
-               ("mysqlsam_setsampwent succeeded(%lu results)!\n",
+               ("mysqlsam_setsampwent succeeded(%llu results)!\n",
                                mysql_num_rows(data->pwent)));
        
        return NT_STATUS_OK;
index 3a23e1a3655ec7a9efbdb2f5496428ebefb4e397..85ce257c026448e5bd15692e11efe75220ac8bd0 100644 (file)
@@ -126,7 +126,7 @@ static int recycle_connect(struct connection_struct *conn, const char *service,
        recycle_bin_connections *recconn;
        recycle_bin_connections *recconnbase;
        recycle_bin_private_data *recdata;
-       char *tmp_str;
+       const char *tmp_str;
 
        DEBUG(10, ("Called for service %s (%d) as user %s\n", service, SNUM(conn), user));
 
@@ -142,42 +142,34 @@ static int recycle_connect(struct connection_struct *conn, const char *service,
                return -1;
        }
 
-       recbin = talloc(ctx, sizeof(recycle_bin_struct));
+       recbin = talloc_zero(ctx, sizeof(recycle_bin_struct));
        if (recbin == NULL) {
                DEBUG(0, ("Failed to allocate memory in VFS module recycle_bin\n"));
                return -1;
        }
        recbin->mem_ctx = ctx;
 
-       /* Set defaults */
-       recbin->repository = talloc_strdup(recbin->mem_ctx, ".recycle");
-       ALLOC_CHECK(recbin->repository, error);
-       recbin->keep_dir_tree = False;
-       recbin->versions = False;
-       recbin->touch = False;
-       recbin->exclude = "";
-       recbin->exclude_dir = "";
-       recbin->noversions = "";
-       recbin->maxsize = 0;
-
        /* parse configuration options */
-       if ((tmp_str = lp_parm_string(SNUM(conn), "vfs_recycle_bin", "repository")) != NULL) {
+       if ((tmp_str = lp_parm_const_string(SNUM(conn), "vfs_recycle_bin", "repository", ".recycle")) != NULL) {
                recbin->repository = talloc_sub_conn(recbin->mem_ctx, conn, tmp_str);
                ALLOC_CHECK(recbin->repository, error);
                trim_string(recbin->repository, "/", "/");
                DEBUG(5, ("recycle.bin: repository = %s\n", recbin->repository));
+       } else {
+               DEBUG(0,("recycle.bin: no repository found (fail) !\n"));
+               goto error;
        }
        
-       recbin->keep_dir_tree = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "keeptree");
+       recbin->keep_dir_tree = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "keeptree", False);
        DEBUG(5, ("recycle.bin: keeptree = %d\n", recbin->keep_dir_tree));
        
-       recbin->versions = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "versions");
+       recbin->versions = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "versions", False);
        DEBUG(5, ("recycle.bin: versions = %d\n", recbin->versions));
        
-       recbin->touch = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "touch");
+       recbin->touch = lp_parm_bool(SNUM(conn), "vfs_recycle_bin", "touch", False);
        DEBUG(5, ("recycle.bin: touch = %d\n", recbin->touch));
 
-       recbin->maxsize = lp_parm_ulong(SNUM(conn), "vfs_recycle_bin", "maxsize");
+       recbin->maxsize = lp_parm_ulong(SNUM(conn), "vfs_recycle_bin", "maxsize" , 0);
        if (recbin->maxsize == 0) {
                recbin->maxsize = -1;
                DEBUG(5, ("recycle.bin: maxsize = -infinite-\n"));
@@ -185,17 +177,17 @@ static int recycle_connect(struct connection_struct *conn, const char *service,
                DEBUG(5, ("recycle.bin: maxsize = %ld\n", (long int)recbin->maxsize));
        }
 
-       if ((tmp_str = lp_parm_string(SNUM(conn), "vfs_recycle_bin", "exclude")) != NULL) {
+       if ((tmp_str = lp_parm_const_string(SNUM(conn), "vfs_recycle_bin", "exclude", "")) != NULL) {
                recbin->exclude = talloc_strdup(recbin->mem_ctx, tmp_str);
                ALLOC_CHECK(recbin->exclude, error);
                DEBUG(5, ("recycle.bin: exclude = %s\n", recbin->exclude));
        }
-       if ((tmp_str = lp_parm_string(SNUM(conn), "vfs_recycle_bin", "exclude_dir")) != NULL) {
+       if ((tmp_str = lp_parm_const_string(SNUM(conn), "vfs_recycle_bin", "exclude_dir", "")) != NULL) {
                recbin->exclude_dir = talloc_strdup(recbin->mem_ctx, tmp_str);
                ALLOC_CHECK(recbin->exclude_dir, error);
                DEBUG(5, ("recycle.bin: exclude_dir = %s\n", recbin->exclude_dir));
        }
-       if ((tmp_str = lp_parm_string(SNUM(conn), "vfs_recycle_bin", "noversions")) != NULL) {
+       if ((tmp_str = lp_parm_const_string(SNUM(conn), "vfs_recycle_bin", "noversions", "")) != NULL) {
                recbin->noversions = talloc_strdup(recbin->mem_ctx, tmp_str);
                ALLOC_CHECK(recbin->noversions, error);
                DEBUG(5, ("recycle.bin: noversions = %s\n", recbin->noversions));
index d018175d38954a46956043d0310568a22f427da3..42503c3d3974c64ce76398447ba1fb4814f8dd68 100644 (file)
@@ -512,7 +512,7 @@ static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT
        return NT_STATUS_OK;
 }
 
-NTSTATUS xmlsam_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
+static NTSTATUS xmlsam_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
                 const char *location)
 {
        NTSTATUS nt_status;
@@ -553,8 +553,7 @@ NTSTATUS xmlsam_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
        (*pdb_method)->enum_group_mapping = NULL;
 
        data = talloc(pdb_context->mem_ctx, sizeof(pdb_xml));
-       data->location =
-               (location ? talloc_strdup(pdb_context->mem_ctx, location) : "passdb.xml");
+       data->location = talloc_strdup(pdb_context->mem_ctx, (location ? location : "passdb.xml"));
        data->pwent = NULL;
        data->written = 0;
        (*pdb_method)->private_data = data;
index 4394c4df1a43a840f5911f7381f7a34f0e22c75e..c80c71d98dbb831e5253dd2366b34c2a164cf3d8 100644 (file)
@@ -87,6 +87,7 @@ struct _param_opt_struct {
        param_opt_struct *prev, *next;
        char *key;
        char *value;
+       char **list;
 };
 
 /* 
@@ -1889,39 +1890,49 @@ static void init_copymap(service * pservice);
 /* This is a helper function for parametrical options support. */
 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
 /* Actual parametrical functions are quite simple */
-static const char *get_parametrics(int lookup_service, const char *type, const char *option)
+static param_opt_struct *get_parametrics(int snum, const char *type, const char *option)
 {
-       char* vfskey;
+       BOOL global_section = False;
+       char* param_key;
         param_opt_struct *data;
        
-       if (lookup_service >= iNumServices) return NULL;
+       if (snum >= iNumServices) return NULL;
        
-       data = (lookup_service < 0) ? 
-               Globals.param_opt : ServicePtrs[lookup_service]->param_opt;
+       if (snum < 0) { 
+               data = Globals.param_opt;
+               global_section = True;
+       } else {
+               data = ServicePtrs[snum]->param_opt;
+       }
     
-       asprintf(&vfskey, "%s:%s", type, option);
+       asprintf(&param_key, "%s:%s", type, option);
+       if (!param_key) {
+               DEBUG(0,("asprintf failed!\n"));
+               return NULL;
+       }
+
        while (data) {
-               if (strcmp(data->key, vfskey) == 0) {
-                       string_free(&vfskey);
-                       return data->value;
+               if (strcmp(data->key, param_key) == 0) {
+                       string_free(&param_key);
+                       return data;
                }
                data = data->next;
        }
 
-       if (lookup_service >= 0) {
+       if (!global_section) {
                /* Try to fetch the same option but from globals */
                /* but only if we are not already working with Globals */
                data = Globals.param_opt;
                while (data) {
-                       if (strcmp(data->key, vfskey) == 0) {
-                               string_free(&vfskey);
-                               return data->value;
+                       if (strcmp(data->key, param_key) == 0) {
+                               string_free(&param_key);
+                               return data;
                        }
                        data = data->next;
                }
        }
 
-       string_free(&vfskey);
+       string_free(&param_key);
        
        return NULL;
 }
@@ -1984,7 +1995,7 @@ static int lp_enum(const char *s,const struct enum_list *_enum)
 
        if (!s || !_enum) {
                DEBUG(0,("lp_enum(%s,enum): is called with NULL!\n",s));
-               return False;
+               return (-1);
        }
        
        for (i=0; _enum[i].name; i++) {
@@ -1996,86 +2007,116 @@ static int lp_enum(const char *s,const struct enum_list *_enum)
        return (-1);
 }
 
+
+/* DO NOT USE lp_parm_string ANYMORE!!!!
+ * use lp_parm_const_string or lp_parm_talloc_string
+ *
+ * lp_parm_string is only used to let old modules find this symbol
+ */
+#undef lp_parm_string
+ char *lp_parm_string(const char *servicename, const char *type, const char *option)
+{
+       return lp_parm_talloc_string(lp_servicenumber(servicename), type, option, NULL);
+}
+
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
-/* Returned value is allocated in 'lp_talloc' context */
-
-char *lp_parm_string(int lookup_service, const char *type, const char *option)
+/* the returned value is talloced in lp_talloc */
+char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return lp_string(value);
+       if (data == NULL||data->value==NULL) {
+               if (def) {
+                       return lp_string(def);
+               } else {
+                       return NULL;
+               }
+       }
 
-       return NULL;
+       return lp_string(data->value);
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
-/* Returned value is allocated in 'lp_talloc' context */
-
-char **lp_parm_string_list(int lookup_service, const char *type, const char *option,
-                          const char *separator)
+const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return str_list_make(value, separator);
+       if (data == NULL||data->value==NULL)
+               return def;
+               
+       return data->value;
+}
 
-       return NULL;
+/* Return parametric option from a given service. Type is a part of option before ':' */
+/* Parametric option has following syntax: 'Type: option = value' */
+
+const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def)
+{
+       param_opt_struct *data = get_parametrics(snum, type, option);
+
+       if (data == NULL||data->value==NULL)
+               return (const char **)def;
+               
+       if (data->list==NULL) {
+               data->list = str_list_make(data->value, NULL);
+       }
+
+       return (const char **)data->list;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-int lp_parm_int(int lookup_service, const char *type, const char *option)
+int lp_parm_int(int snum, const char *type, const char *option, int def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return lp_int(value);
+       if (data && data->value && *data->value)
+               return lp_int(data->value);
 
-       return (-1);
+       return def;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-unsigned long lp_parm_ulong(int lookup_service, const char *type, const char *option)
+unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return lp_ulong(value);
+       if (data && data->value && *data->value)
+               return lp_ulong(data->value);
 
-       return (0);
+       return def;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-BOOL lp_parm_bool(int lookup_service, const char *type, const char *option)
+BOOL lp_parm_bool(int snum, const char *type, const char *option, BOOL def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return lp_bool(value);
+       if (data && data->value && *data->value)
+               return lp_bool(data->value);
 
-       return False;
+       return def;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-int lp_parm_enum(int lookup_service, const char *type, const char *option,
-                const struct enum_list *_enum)
+int lp_parm_enum(int snum, const char *type, const char *option,
+                const struct enum_list *_enum, int def)
 {
-       const char *value = get_parametrics(lookup_service, type, option);
+       param_opt_struct *data = get_parametrics(snum, type, option);
        
-       if (value)
-               return lp_enum(value, _enum);
+       if (data && data->value && *data->value && _enum)
+               return lp_enum(data->value, _enum);
 
-       return (-1);
+       return def;
 }
 
 
@@ -2120,13 +2161,15 @@ static void free_service(service *pservice)
                                            (((char *)pservice) +
                                             PTR_DIFF(parm_table[i].ptr, &sDefault)));
        }
-                               
-       DEBUG(5,("Freeing parametrics:\n"));
+
        data = pservice->param_opt;
+       if (data)
+               DEBUG(5,("Freeing parametrics:\n"));
        while (data) {
                DEBUG(5,("[%s = %s]\n", data->key, data->value));
                string_free(&data->key);
                string_free(&data->value);
+               str_list_free(&data->list);
                pdata = data->next;
                SAFE_FREE(data);
                data = pdata;
@@ -2159,6 +2202,7 @@ static int add_a_service(const service *pservice, const char *name)
                        while (data) {
                                string_free(&data->key);
                                string_free(&data->value);
+                               str_list_free(&data->list);
                                pdata = data->next;
                                SAFE_FREE(data);
                                data = pdata;
@@ -2225,7 +2269,7 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
                return (False);
 
        if (!(*(ServicePtrs[iDefaultService]->szPath))
-           || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(-1))) {
+           || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(GLOBAL_SECTION_SNUM))) {
                pstrcpy(newHomedir, pszHomedir);
        } else {
                pstrcpy(newHomedir, lp_pathname(iDefaultService));
@@ -2473,6 +2517,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
                        /* If we already have same option, override it */
                        if (strcmp(pdata->key, data->key) == 0) {
                                string_free(&pdata->value);
+                               str_list_free(&data->list);
                                pdata->value = strdup(data->value);
                                not_added = False;
                                break;
@@ -2483,6 +2528,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
                    paramo = smb_xmalloc(sizeof(param_opt_struct));
                    paramo->key = strdup(data->key);
                    paramo->value = strdup(data->value);
+                   paramo->list = NULL;
                    DLIST_ADD(pserviceDest->param_opt, paramo);
                }
                data = data->next;
@@ -3083,7 +3129,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
        int parmnum, i, slen;
        void *parm_ptr = NULL;  /* where we are going to store the result */
        void *def_ptr = NULL;
-       pstring vfskey;
+       pstring param_key;
        char *sep;
        param_opt_struct *paramo, *data;
        BOOL not_added;
@@ -3092,20 +3138,21 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 
        if (parmnum < 0) {
                if ((sep=strchr(pszParmName, ':')) != NULL) {
-                       *sep = 0;
-                       ZERO_STRUCT(vfskey);
-                       pstr_sprintf(vfskey, "%s:", pszParmName);
-                       slen = strlen(vfskey);
-                       pstrcat(vfskey, sep+1);
-                       trim_string(vfskey+slen, " ", " ");
+                       *sep = '\0';
+                       ZERO_STRUCT(param_key);
+                       pstr_sprintf(param_key, "%s:", pszParmName);
+                       slen = strlen(param_key);
+                       pstrcat(param_key, sep+1);
+                       trim_string(param_key+slen, " ", " ");
                        not_added = True;
                        data = (snum < 0) ? Globals.param_opt : 
                                ServicePtrs[snum]->param_opt;
                        /* Traverse destination */
                        while (data) {
                                /* If we already have same option, override it */
-                               if (strcmp(data->key, vfskey) == 0) {
+                               if (strcmp(data->key, param_key) == 0) {
                                        string_free(&data->value);
+                                       str_list_free(&data->list);
                                        data->value = strdup(pszParmValue);
                                        not_added = False;
                                        break;
@@ -3114,8 +3161,9 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        }
                        if (not_added) {
                                paramo = smb_xmalloc(sizeof(param_opt_struct));
-                               paramo->key = strdup(vfskey);
+                               paramo->key = strdup(param_key);
                                paramo->value = strdup(pszParmValue);
+                               paramo->list = NULL;
                                if (snum < 0) {
                                        DLIST_ADD(Globals.param_opt, paramo);
                                } else {
@@ -3555,13 +3603,13 @@ static void dump_a_service(service * pService, FILE * f)
 
 
 /***************************************************************************
- Return info about the next service  in a service. snum==-1 gives the globals.
+ Return info about the next service  in a service. snum==GLOBAL_SECTION_SNUM gives the globals.
  Return NULL when out of parameters.
 ***************************************************************************/
 
 struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
 {
-       if (snum == -1) {
+       if (snum < 0) {
                /* do the globals */
                for (; parm_table[*i].label; (*i)++) {
                        if (parm_table[*i].class == P_SEPARATOR)
@@ -3899,6 +3947,7 @@ BOOL lp_load(const char *pszFname, BOOL global_only, BOOL save_defaults,
                while (data) {
                        string_free(&data->key);
                        string_free(&data->value);
+                       str_list_free(&data->list);
                        pdata = data->next;
                        SAFE_FREE(data);
                        data = pdata;
@@ -3933,7 +3982,7 @@ BOOL lp_load(const char *pszFname, BOOL global_only, BOOL save_defaults,
        /* Now we check bWINSsupport and set szWINSserver to 127.0.0.1 */
        /* if bWINSsupport is true and we are in the client            */
        if (in_client && Globals.bWINSsupport) {
-               lp_do_parameter(-1, "wins server", "127.0.0.1");
+               lp_do_parameter(GLOBAL_SECTION_SNUM, "wins server", "127.0.0.1");
        }
 
        init_iconv();
@@ -4002,8 +4051,10 @@ int lp_servicenumber(const char *pszServiceName)
 {
        int iService;
         fstring serviceName;
+        
+        if (!pszServiceName)
+               return GLOBAL_SECTION_SNUM;
+        
        for (iService = iNumServices - 1; iService >= 0; iService--) {
                if (VALID(iService) && ServicePtrs[iService]->szService) {
                        /*
@@ -4017,8 +4068,10 @@ int lp_servicenumber(const char *pszServiceName)
                }
        }
 
-       if (iService < 0)
+       if (iService < 0) {
                DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName));
+               return GLOBAL_SECTION_SNUM;
+       }
 
        return (iService);
 }
index 13e03690049abd1a2672ebe271649c4b0fe1d3b7..79b107e41750c5cc378d6d7e168d68e4cc1a723b 100755 (executable)
@@ -1328,10 +1328,10 @@ NTSTATUS sam_init_ads(SAM_METHODS *sam_method, const char *module_params)
                return NT_STATUS_NO_MEMORY;
        }
 
-       sam_ads_state->ads_bind_dn = talloc_strdup(sam_ads_state->mem_ctx, lp_parm_string(NULL,"sam_ads","bind as"));
-       sam_ads_state->ads_bind_pw = talloc_strdup(sam_ads_state->mem_ctx, lp_parm_string(NULL,"sam_ads","bind pw"));
+       sam_ads_state->ads_bind_dn = talloc_strdup(sam_ads_state->mem_ctx, lp_parm_const_string(GLOBAL_SECTION_SNUM,"sam_ads","bind as", ""));
+       sam_ads_state->ads_bind_pw = talloc_strdup(sam_ads_state->mem_ctx, lp_parm_const_string(GLOBAL_SECTION_SNUM,"sam_ads","bind pw", ""));
 
-       sam_ads_state->bind_plaintext = strequal(lp_parm_string(NULL, "sam_ads", "plaintext bind"), "yes");
+       sam_ads_state->bind_plaintext = lp_parm_bool(GLOBAL_SECTION_SNUM, "sam_ads", "plaintext bind" , True);
 
        if (!sam_ads_state->ads_bind_dn || !sam_ads_state->ads_bind_pw) {
                DEBUG(0, ("talloc_strdup() failed for bind dn or password\n"));