summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2002-06-14 16:02:59 +0000
committerSimo Sorce <idra@samba.org>2002-06-14 16:02:59 +0000
commite69fba09846f9bfd1564c4c684bb5d4fc059b02d (patch)
tree310c7e9a06c443aadb560a62f60809784db48218
parenta98d2b1e1788d3207278340330052fc09245e8d2 (diff)
downloadsamba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.tar.gz
samba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.tar.bz2
samba-e69fba09846f9bfd1564c4c684bb5d4fc059b02d.zip
moved lp_list_* functions away from param/loadparm.c, put int lib/util_str.c
and renamed to str_list_* as it is a better name. Elrond should be satisfied now :) (This used to be commit 4ae260adb9505384fcccfb4c9929cb60a45f2e84)
-rw-r--r--source3/auth/auth.c20
-rw-r--r--source3/lib/debug.c6
-rw-r--r--source3/lib/username.c6
-rw-r--r--source3/lib/util_str.c182
-rw-r--r--source3/param/loadparm.c194
-rw-r--r--source3/passdb/pdb_interface.c4
-rw-r--r--source3/smbd/password.c18
-rw-r--r--source3/smbd/service.c12
-rw-r--r--source3/web/swat.c2
-rw-r--r--source3/wrepld/process.c4
10 files changed, 225 insertions, 223 deletions
diff --git a/source3/auth/auth.c b/source3/auth/auth.c
index 1919a69df2..3bd36da15b 100644
--- a/source3/auth/auth.c
+++ b/source3/auth/auth.c
@@ -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;
}
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 255b0568f1..487b4957fe 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -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;
}
}
diff --git a/source3/lib/username.c b/source3/lib/username.c
index be8acfb4d6..c83b4eea28 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -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);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index ff3559ce14..eac3ebe929 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -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;
+}
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 2507e8a798..ed0656ed5f 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -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.....
*****************************************************************/
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index da013f6851..3b0f54b2b3 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -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;
}
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index e50ba4ec1b..b2cf3106cb 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -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);
diff --git a/source3/smbd/service.c b/source3/smbd/service.c
index 32ceb63154..af70e7839e 100644
--- a/source3/smbd/service.c
+++ b/source3/smbd/service.c
@@ -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);
}
}
diff --git a/source3/web/swat.c b/source3/web/swat.c
index 955cbb0748..ad91033f4c 100644
--- a/source3/web/swat.c
+++ b/source3/web/swat.c
@@ -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:
diff --git a/source3/wrepld/process.c b/source3/wrepld/process.c
index e07496ed1d..7615b8c78a 100644
--- a/source3/wrepld/process.c
+++ b/source3/wrepld/process.c
@@ -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;
}