1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

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 4ae260adb9)
This commit is contained in:
Simo Sorce 2002-06-14 16:02:59 +00:00
parent a98d2b1e17
commit e69fba0984
10 changed files with 225 additions and 223 deletions

View 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;
}

View 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;
}
}

View 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);

View 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;
}

View 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.....
*****************************************************************/

View 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;
}

View 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);

View 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);
}
}

View 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:

View 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;
}