moved lp_list_* functions away from param/loadparm.c, put int lib/util_str.c
authorSimo Sorce <idra@samba.org>
Fri, 14 Jun 2002 16:02:59 +0000 (16:02 +0000)
committerSimo Sorce <idra@samba.org>
Fri, 14 Jun 2002 16:02:59 +0000 (16:02 +0000)
and renamed to str_list_* as it is a better name.
Elrond should be satisfied now :)
(This used to be commit 4ae260adb9505384fcccfb4c9929cb60a45f2e84)

source3/auth/auth.c
source3/lib/debug.c
source3/lib/username.c
source3/lib/util_str.c
source3/param/loadparm.c
source3/passdb/pdb_interface.c
source3/smbd/password.c
source3/smbd/service.c
source3/web/swat.c
source3/wrepld/process.c

index 1919a69df24564238eccc594ab5310bba83482ff..3bd36da15b14cfded3cd79b01a10945fd367d60a 100644 (file)
@@ -384,7 +384,7 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
        char **auth_method_list = NULL; 
        NTSTATUS nt_status;
 
-       if (lp_auth_methods() && !lp_list_copy(&auth_method_list, lp_auth_methods())) {
+       if (lp_auth_methods() && !str_list_copy(&auth_method_list, lp_auth_methods())) {
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -393,33 +393,33 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
                {
                case SEC_DOMAIN:
                        DEBUG(5,("Making default auth method list for security=domain\n"));
-                       auth_method_list = lp_list_make("guest samstrict ntdomain");
+                       auth_method_list = str_list_make("guest samstrict ntdomain");
                        break;
                case SEC_SERVER:
                        DEBUG(5,("Making default auth method list for security=server\n"));
-                       auth_method_list = lp_list_make("guest samstrict smbserver");
+                       auth_method_list = str_list_make("guest samstrict smbserver");
                        break;
                case SEC_USER:
                        if (lp_encrypted_passwords()) { 
                                DEBUG(5,("Making default auth method list for security=user, encrypt passwords = yes\n"));
-                               auth_method_list = lp_list_make("guest sam");
+                               auth_method_list = str_list_make("guest sam");
                        } else {
                                DEBUG(5,("Making default auth method list for security=user, encrypt passwords = no\n"));
-                               auth_method_list = lp_list_make("guest unix");
+                               auth_method_list = str_list_make("guest unix");
                        }
                        break;
                case SEC_SHARE:
                        if (lp_encrypted_passwords()) {
                                DEBUG(5,("Making default auth method list for security=share, encrypt passwords = yes\n"));
-                               auth_method_list = lp_list_make("guest sam");
+                               auth_method_list = str_list_make("guest sam");
                        } else {
                                DEBUG(5,("Making default auth method list for security=share, encrypt passwords = no\n"));
-                               auth_method_list = lp_list_make("guest unix");
+                               auth_method_list = str_list_make("guest unix");
                        }
                        break;
                case SEC_ADS:
                        DEBUG(5,("Making default auth method list for security=ADS\n"));
-                       auth_method_list = lp_list_make("guest samstrict ads ntdomain");
+                       auth_method_list = str_list_make("guest samstrict ads ntdomain");
                        break;
                default:
                        DEBUG(5,("Unknown auth method!\n"));
@@ -430,11 +430,11 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
        }
        
        if (!NT_STATUS_IS_OK(nt_status = make_auth_context_text_list(auth_context, auth_method_list))) {
-               lp_list_free(&auth_method_list);
+               str_list_free(&auth_method_list);
                return nt_status;
        }
        
-       lp_list_free(&auth_method_list);
+       str_list_free(&auth_method_list);
        return nt_status;
 }
 
index 255b0568f145e0dd6115e9a6d7ec33d183f72147..487b4957feac856944ff53516c6ea707718ee9fc 100644 (file)
@@ -423,16 +423,16 @@ BOOL debug_parse_levels(const char *params_str)
        if (AllowDebugChange == False)
                return True;
 
-       params = lp_list_make(params_str);
+       params = str_list_make(params_str);
 
        if (debug_parse_params(params, DEBUGLEVEL_CLASS,
                               DEBUGLEVEL_CLASS_ISSET))
        {
                debug_dump_status(5);
-               lp_list_free(&params);
+               str_list_free(&params);
                return True;
        } else {
-               lp_list_free(&params);
+               str_list_free(&params);
                return False;
        }
 }
index be8acfb4d6af89ac092a97bb718ad26e28082105..c83b4eea28947d6d30d0bf763e3c77d811697a85 100644 (file)
@@ -197,7 +197,7 @@ BOOL map_username(char *user)
                        }
                }
 
-               dosuserlist = lp_list_make(dosname);
+               dosuserlist = str_list_make(dosname);
                if (!dosuserlist) {
                        DEBUG(0,("Unable to build user list\n"));
                        return False;
@@ -210,13 +210,13 @@ BOOL map_username(char *user)
                        sscanf(unixname,"%s",user);
                        fstrcpy(last_to,user);
                        if(return_if_mapped) {
-                               lp_list_free (&dosuserlist);
+                               str_list_free (&dosuserlist);
                                x_fclose(f);
                                return True;
                        }
                }
     
-               lp_list_free (&dosuserlist);
+               str_list_free (&dosuserlist);
        }
 
        x_fclose(f);
index ff3559ce1484b7c1d9e3409b3f86ab93125d72eb..eac3ebe929b519902e1edf9c27c0e3d436e74835 100644 (file)
@@ -1013,3 +1013,185 @@ some platforms don't have strnlen
        return i;
 }
 #endif
+
+
+
+/***********************************************************
+ List of Strings manipulation functions
+***********************************************************/
+
+#define S_LIST_ABS 16 /* List Allocation Block Size */
+
+char **str_list_make(const char *string)
+{
+       char **list, **rlist;
+       char *str, *s;
+       int num, lsize;
+       pstring tok;
+       
+       if (!string || !*string) return NULL;
+       s = strdup(string);
+       if (!s) {
+               DEBUG(0,("str_list_make: Unable to allocate memory"));
+               return NULL;
+       }
+       
+       num = lsize = 0;
+       list = NULL;
+       
+       str = s;
+       while (next_token(&str, tok, LIST_SEP, sizeof(tok)))
+       {               
+               if (num == lsize) {
+                       lsize += S_LIST_ABS;
+                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+                       if (!rlist) {
+                               DEBUG(0,("str_list_make: Unable to allocate memory"));
+                               str_list_free(&list);
+                               SAFE_FREE(s);
+                               return NULL;
+                       }
+                       else list = rlist;
+                       memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
+               }
+               
+               list[num] = strdup(tok);
+               if (!list[num]) {
+                       DEBUG(0,("str_list_make: Unable to allocate memory"));
+                       str_list_free(&list);
+                       SAFE_FREE(s);
+                       return NULL;
+               }
+       
+               num++;  
+       }
+       
+       SAFE_FREE(s);
+       return list;
+}
+
+BOOL str_list_copy(char ***dest, char **src)
+{
+       char **list, **rlist;
+       int num, lsize;
+       
+       *dest = NULL;
+       if (!src) return False;
+       
+       num = lsize = 0;
+       list = NULL;
+               
+       while (src[num])
+       {
+               if (num == lsize) {
+                       lsize += S_LIST_ABS;
+                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+                       if (!rlist) {
+                               DEBUG(0,("str_list_copy: Unable to allocate memory"));
+                               str_list_free(&list);
+                               return False;
+                       }
+                       else list = rlist;
+                       memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
+               }
+               
+               list[num] = strdup(src[num]);
+               if (!list[num]) {
+                       DEBUG(0,("str_list_copy: Unable to allocate memory"));
+                       str_list_free(&list);
+                       return False;
+               }
+
+               num++;
+       }
+       
+       *dest = list;
+       return True;    
+}
+
+/* return true if all the elemnts of the list matches exactly */
+BOOL str_list_compare(char **list1, char **list2)
+{
+       int num;
+       
+       if (!list1 || !list2) return (list1 == list2); 
+       
+       for (num = 0; list1[num]; num++) {
+               if (!list2[num]) return False;
+               if (!strcsequal(list1[num], list2[num])) return False;
+       }
+       if (list2[num]) return False; /* if list2 has more elements than list1 fail */
+       
+       return True;
+}
+
+void str_list_free(char ***list)
+{
+       char **tlist;
+       
+       if (!list || !*list) return;
+       tlist = *list;
+       for(; *tlist; tlist++) SAFE_FREE(*tlist);
+       SAFE_FREE(*list);
+}
+
+BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
+{
+       char *p, *s, *t;
+       ssize_t ls, lp, li, ld, i, d;
+
+       if (!list) return False;
+       if (!pattern) return False;
+       if (!insert) return False;
+
+       lp = (ssize_t)strlen(pattern);
+       li = (ssize_t)strlen(insert);
+       ld = li -lp;
+                       
+       while (*list)
+       {
+               s = *list;
+               ls = (ssize_t)strlen(s);
+
+               while ((p = strstr(s, pattern)))
+               {
+                       t = *list;
+                       d = p -t;
+                       if (ld)
+                       {
+                               t = (char *) malloc(ls +ld +1);
+                               if (!t) {
+                                       DEBUG(0,("str_list_substitute: Unable to allocate memory"));
+                                       return False;
+                               }
+                               memcpy(t, *list, d);
+                               memcpy(t +d +li, p +lp, ls -d -lp +1);
+                               SAFE_FREE(*list);
+                               *list = t;
+                               ls += ld;
+                               s = t +d +li;
+                       }
+                       
+                       for (i = 0; i < li; i++) {
+                               switch (insert[i]) {
+                                       case '`':
+                                       case '"':
+                                       case '\'':
+                                       case ';':
+                                       case '$':
+                                       case '%':
+                                       case '\r':
+                                       case '\n':
+                                               t[d +i] = '_';
+                                               break;
+                                       default:
+                                               t[d +i] = insert[i];
+                               }
+                       }       
+               }
+               
+               list++;
+       }
+       
+       return True;
+}
index 2507e8a79820119e7e92d9a9025e0313fe5e9232..ed0656ed5f08d9a78d368d71bbc89b35d3106445 100644 (file)
@@ -1186,7 +1186,7 @@ static void init_globals(void)
 
        string_set(&Globals.szSMBPasswdFile, dyn_SMB_PASSWD_FILE);
        string_set(&Globals.szPrivateDir, dyn_PRIVATE_DIR);
-       Globals.szPassdbBackend = lp_list_make("smbpasswd unixsam");
+       Globals.szPassdbBackend = str_list_make("smbpasswd unixsam");
 
        /* use the new 'hash2' method by default */
        string_set(&Globals.szManglingMethod, "hash2");
@@ -1801,7 +1801,7 @@ static void free_service(service * pservice)
                                     PTR_DIFF(parm_table[i].ptr, &sDefault)));
                else if (parm_table[i].type == P_LIST &&
                         parm_table[i].class == P_LOCAL)
-                            lp_list_free((char ***)
+                            str_list_free((char ***)
                                            (((char *)pservice) +
                                             PTR_DIFF(parm_table[i].ptr, &sDefault)));
        }
@@ -2115,7 +2115,7 @@ static void copy_service(service * pserviceDest,
                                        strupper(*(char **)dest_ptr);
                                        break;
                                case P_LIST:
-                                       lp_list_copy((char ***)dest_ptr, *(char ***)src_ptr);
+                                       str_list_copy((char ***)dest_ptr, *(char ***)src_ptr);
                                        break;
                                default:
                                        break;
@@ -2835,7 +2835,7 @@ BOOL lp_do_parameter(int snum, char *pszParmName, char *pszParmValue)
                        break;
 
                case P_LIST:
-                       *(char ***)parm_ptr = lp_list_make(pszParmValue);
+                       *(char ***)parm_ptr = str_list_make(pszParmValue);
                        break;
 
                case P_STRING:
@@ -2982,7 +2982,7 @@ static BOOL equal_parameter(parm_type type, void *ptr1, void *ptr2)
                        return (*((char *)ptr1) == *((char *)ptr2));
                
                case P_LIST:
-                       return lp_list_compare(*(char ***)ptr1, *(char ***)ptr2);
+                       return str_list_compare(*(char ***)ptr1, *(char ***)ptr2);
 
                case P_GSTRING:
                case P_UGSTRING:
@@ -3083,7 +3083,7 @@ static BOOL is_default(int i)
        switch (parm_table[i].type)
        {
                case P_LIST:
-                       return lp_list_compare (parm_table[i].def.lvalue, 
+                       return str_list_compare (parm_table[i].def.lvalue, 
                                                *(char ***)parm_table[i].ptr);
                case P_STRING:
                case P_USTRING:
@@ -3417,7 +3417,7 @@ static void lp_save_defaults(void)
                        continue;
                switch (parm_table[i].type) {
                        case P_LIST:
-                               lp_list_copy(&(parm_table[i].def.lvalue),
+                               str_list_copy(&(parm_table[i].def.lvalue),
                                            *(char ***)parm_table[i].ptr);
                                break;
                        case P_STRING:
@@ -3882,186 +3882,6 @@ char *lp_printername(int snum)
 }
 
 
-/***********************************************************
- List Parameters manipulation functions
-***********************************************************/
-
-#define P_LIST_ABS 16 /* P_LIST Allocation Block Size */
-
-char **lp_list_make(const char *string)
-{
-       char **list, **rlist;
-       char *str, *s;
-       int num, lsize;
-       pstring tok;
-       
-       if (!string || !*string) return NULL;
-       s = strdup(string);
-       if (!s) {
-               DEBUG(0,("lp_list_make: Unable to allocate memory"));
-               return NULL;
-       }
-       
-       num = lsize = 0;
-       list = NULL;
-       
-       str = s;
-       while (next_token(&str, tok, LIST_SEP, sizeof(tok)))
-       {               
-               if (num == lsize) {
-                       lsize += P_LIST_ABS;
-                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
-                       if (!rlist) {
-                               DEBUG(0,("lp_list_make: Unable to allocate memory"));
-                               lp_list_free(&list);
-                               SAFE_FREE(s);
-                               return NULL;
-                       }
-                       else list = rlist;
-                       memset (&list[num], 0, ((sizeof(char**)) * (P_LIST_ABS +1)));
-               }
-               
-               list[num] = strdup(tok);
-               if (!list[num]) {
-                       DEBUG(0,("lp_list_make: Unable to allocate memory"));
-                       lp_list_free(&list);
-                       SAFE_FREE(s);
-                       return NULL;
-               }
-       
-               num++;  
-       }
-       
-       SAFE_FREE(s);
-       return list;
-}
-
-BOOL lp_list_copy(char ***dest, char **src)
-{
-       char **list, **rlist;
-       int num, lsize;
-       
-       *dest = NULL;
-       if (!src) return False;
-       
-       num = lsize = 0;
-       list = NULL;
-               
-       while (src[num])
-       {
-               if (num == lsize) {
-                       lsize += P_LIST_ABS;
-                       rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
-                       if (!rlist) {
-                               DEBUG(0,("lp_list_copy: Unable to allocate memory"));
-                               lp_list_free(&list);
-                               return False;
-                       }
-                       else list = rlist;
-                       memset (&list[num], 0, ((sizeof(char **)) * (P_LIST_ABS +1)));
-               }
-               
-               list[num] = strdup(src[num]);
-               if (!list[num]) {
-                       DEBUG(0,("lp_list_copy: Unable to allocate memory"));
-                       lp_list_free(&list);
-                       return False;
-               }
-
-               num++;
-       }
-       
-       *dest = list;
-       return True;    
-}
-
-/* return true if all the elemnts of the list matches exactly */
-BOOL lp_list_compare(char **list1, char **list2)
-{
-       int num;
-       
-       if (!list1 || !list2) return (list1 == list2); 
-       
-       for (num = 0; list1[num]; num++) {
-               if (!list2[num]) return False;
-               if (!strcsequal(list1[num], list2[num])) return False;
-       }
-       if (list2[num]) return False; /* if list2 has more elements than list1 fail */
-       
-       return True;
-}
-
-void lp_list_free(char ***list)
-{
-       char **tlist;
-       
-       if (!list || !*list) return;
-       tlist = *list;
-       for(; *tlist; tlist++) SAFE_FREE(*tlist);
-       SAFE_FREE(*list);
-}
-
-BOOL lp_list_substitute(char **list, const char *pattern, const char *insert)
-{
-       char *p, *s, *t;
-       ssize_t ls, lp, li, ld, i, d;
-
-       if (!list) return False;
-       if (!pattern) return False;
-       if (!insert) return False;
-
-       lp = (ssize_t)strlen(pattern);
-       li = (ssize_t)strlen(insert);
-       ld = li -lp;
-                       
-       while (*list)
-       {
-               s = *list;
-               ls = (ssize_t)strlen(s);
-
-               while ((p = strstr(s, pattern)))
-               {
-                       t = *list;
-                       d = p -t;
-                       if (ld)
-                       {
-                               t = (char *) malloc(ls +ld +1);
-                               if (!t) {
-                                       DEBUG(0,("lp_list_substitute: Unable to allocate memory"));
-                                       return False;
-                               }
-                               memcpy(t, *list, d);
-                               memcpy(t +d +li, p +lp, ls -d -lp +1);
-                               SAFE_FREE(*list);
-                               *list = t;
-                               ls += ld;
-                               s = t +d +li;
-                       }
-                       
-                       for (i = 0; i < li; i++) {
-                               switch (insert[i]) {
-                                       case '`':
-                                       case '"':
-                                       case '\'':
-                                       case ';':
-                                       case '$':
-                                       case '%':
-                                       case '\r':
-                                       case '\n':
-                                               t[d +i] = '_';
-                                               break;
-                                       default:
-                                               t[d +i] = insert[i];
-                               }
-                       }       
-               }
-               
-               list++;
-       }
-       
-       return True;
-}
-
 /****************************************************************
  Compatibility fn. for 2.2.2 code.....
 *****************************************************************/
index da013f6851e703622883f6e5175c9d2d0b427183..3b0f54b2b3ac037d3126d969fefc30436fe18639 100644 (file)
@@ -353,9 +353,9 @@ NTSTATUS make_pdb_context_list(struct pdb_context **context, char **selected)
 NTSTATUS make_pdb_context_string(struct pdb_context **context, const char *selected) 
 {
        NTSTATUS ret;
-       char **newsel = lp_list_make(selected);
+       char **newsel = str_list_make(selected);
        ret = make_pdb_context_list(context, newsel);
-       lp_list_free(&newsel);
+       str_list_free(&newsel);
        return ret;
 }
 
index e50ba4ec1b54756c1d134e01fd2dd9d3f43db411..b2cf3106cbd6864082c03b04f19460bcf0bd61c6 100644 (file)
@@ -355,27 +355,27 @@ BOOL user_ok(const char *user,int snum)
        ret = True;
 
        if (lp_invalid_users(snum)) {
-               lp_list_copy(&invalid, lp_invalid_users(snum));
-               if (invalid && lp_list_substitute(invalid, "%S", lp_servicename(snum))) {
+               str_list_copy(&invalid, lp_invalid_users(snum));
+               if (invalid && str_list_substitute(invalid, "%S", lp_servicename(snum))) {
                        ret = !user_in_list(user, invalid);
                }
        }
-       if (invalid) lp_list_free (&invalid);
+       if (invalid) str_list_free (&invalid);
 
        if (ret && lp_valid_users(snum)) {
-               lp_list_copy(&valid, lp_valid_users(snum));
-               if (valid && lp_list_substitute(valid, "%S", lp_servicename(snum))) {
+               str_list_copy(&valid, lp_valid_users(snum));
+               if (valid && str_list_substitute(valid, "%S", lp_servicename(snum))) {
                        ret = user_in_list(user,valid);
                }
        }
-       if (valid) lp_list_free (&valid);
+       if (valid) str_list_free (&valid);
 
        if (ret && lp_onlyuser(snum)) {
-               char **user_list = lp_list_make (lp_username(snum));
-               if (user_list && lp_list_substitute(user_list, "%S", lp_servicename(snum))) {
+               char **user_list = str_list_make (lp_username(snum));
+               if (user_list && str_list_substitute(user_list, "%S", lp_servicename(snum))) {
                        ret = user_in_list(user, user_list);
                }
-               if (user_list) lp_list_free (&user_list);
+               if (user_list) str_list_free (&user_list);
        }
 
        return(ret);
index 32ceb63154317da16b93ed9d1c6fb04b0ef49912..af70e7839e0ec9c4328ac4060f9b132a0fe2f943 100644 (file)
@@ -266,24 +266,24 @@ static void set_read_only(connection_struct *conn)
 
        if (!service) return;
 
-       lp_list_copy(&list, lp_readlist(conn->service));
+       str_list_copy(&list, lp_readlist(conn->service));
        if (list) {
-               if (!lp_list_substitute(list, "%S", service)) {
+               if (!str_list_substitute(list, "%S", service)) {
                        DEBUG(0, ("ERROR: read list substitution failed\n"));
                }
                if (user_in_list(conn->user, list))
                        conn->read_only = True;
-               lp_list_free(&list);
+               str_list_free(&list);
        }
        
-       lp_list_copy(&list, lp_writelist(conn->service));
+       str_list_copy(&list, lp_writelist(conn->service));
        if (list) {
-               if (!lp_list_substitute(list, "%S", service)) {
+               if (!str_list_substitute(list, "%S", service)) {
                        DEBUG(0, ("ERROR: write list substitution failed\n"));
                }
                if (user_in_list(conn->user, list))
                        conn->read_only = False;
-               lp_list_free(&list);
+               str_list_free(&list);
        }
 }
 
index 955cbb0748b3b15269bca89a7b029d5532bba798..ad91033f4cbf957261c16fbb6460d08cc7f20a9b 100644 (file)
@@ -329,7 +329,7 @@ static void show_parameters(int snum, int allparameters, int advanced, int print
                                        break;
 
                                case P_LIST:
-                                       if (!lp_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
+                                       if (!str_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
                                        break;
 
                                case P_STRING:
index e07496ed1d1084ccd8c542763cf1ee570fc5dfac..7615b8c78a1372a64736abfcd0f1b7ac231c3be6 100644 (file)
@@ -152,7 +152,7 @@ initialise and fill the in-memory partner table.
 int init_wins_partner_table(void)
 {
        int i=1,j=0,k;
-       char **partner = lp_list_make(lp_wins_partners());
+       char **partner = str_list_make(lp_wins_partners());
 
        if (partner==NULL) {
                DEBUG(0,("wrepld: no partner list in smb.conf, exiting\n"));
@@ -185,7 +185,7 @@ int init_wins_partner_table(void)
                for (j=0; j<i; j++)
                        global_wins_table[k][j]=global_wins_table[0][j];
        
-       lp_list_free (&partner);
+       str_list_free (&partner);
        
        return i;
 }