1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-25 14:50:24 +03:00

Use common strlist implementation in Samba 3 and Samba 4.

This commit is contained in:
Jelmer Vernooij 2008-10-12 00:56:56 +02:00
parent cb78d4593b
commit 218f482fbf
23 changed files with 48 additions and 154 deletions

View File

@ -71,17 +71,17 @@ static bool test_list_copy(struct torture_context *tctx)
const char *empty_list[] = { NULL };
const char **null_list = NULL;
result = str_list_copy(tctx, list);
result = (const char **)str_list_copy(tctx, list);
torture_assert_int_equal(tctx, str_list_length(result), 2, "list length");
torture_assert_str_equal(tctx, result[0], "foo", "element 0");
torture_assert_str_equal(tctx, result[1], "bar", "element 1");
torture_assert_str_equal(tctx, result[2], NULL, "element 2");
result = str_list_copy(tctx, empty_list);
result = (const char **)str_list_copy(tctx, empty_list);
torture_assert_int_equal(tctx, str_list_length(result), 0, "list length");
torture_assert_str_equal(tctx, result[0], NULL, "element 0");
result = str_list_copy(tctx, null_list);
result = (const char **)str_list_copy(tctx, null_list);
torture_assert(tctx, result == NULL, "result NULL");
return true;

View File

@ -21,10 +21,9 @@
#ifndef _SAMBA_UTIL_H_
#define _SAMBA_UTIL_H_
#include "lib/charset/charset.h"
#include "../lib/util/attr.h"
#include "charset/charset.h"
/* for TALLOC_CTX */
#include <talloc.h>
@ -452,7 +451,7 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2);
separator list. The separator list must contain characters less than
or equal to 0x2f for this to work correctly on multi-byte strings
*/
_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
_PUBLIC_ char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
/**
* build a null terminated list of strings from an argv-like input string
@ -473,12 +472,12 @@ _PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char
/**
return the number of elements in a string list
*/
_PUBLIC_ size_t str_list_length(const char **list);
_PUBLIC_ size_t str_list_length(const char * const *list);
/**
copy a string list
*/
_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
/**
Return true if all the elements of the list match exactly.

View File

@ -21,6 +21,8 @@
#include "includes.h"
#include "system/locale.h"
#undef strcasecmp
/**
* @file
* @brief String list manipulation
@ -31,30 +33,30 @@
separator list. The separator list must contain characters less than
or equal to 0x2f for this to work correctly on multi-byte strings
*/
_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
_PUBLIC_ char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
{
int num_elements = 0;
const char **ret = NULL;
char **ret = NULL;
if (sep == NULL) {
sep = LIST_SEP;
}
ret = talloc_array(mem_ctx, const char *, 1);
ret = talloc_array(mem_ctx, char *, 1);
if (ret == NULL) {
return NULL;
}
while (string && *string) {
size_t len = strcspn(string, sep);
const char **ret2;
char **ret2;
if (len == 0) {
string += strspn(string, sep);
continue;
}
ret2 = talloc_realloc(mem_ctx, ret, const char *, num_elements+2);
ret2 = talloc_realloc(mem_ctx, ret, char *, num_elements+2);
if (ret2 == NULL) {
talloc_free(ret);
return NULL;
@ -196,15 +198,15 @@ _PUBLIC_ size_t str_list_length(const char **list)
/**
copy a string list
*/
_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
{
int i;
const char **ret;
char **ret;
if (list == NULL)
return NULL;
ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1);
ret = talloc_array(mem_ctx, char *, str_list_length(list)+1);
if (ret == NULL)
return NULL;

View File

@ -234,11 +234,11 @@ _PUBLIC_ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_so
if (state->io == NULL) goto failed;
state->wins_port = io->in.wins_port;
state->wins_servers = str_list_copy(state, io->in.wins_servers);
state->wins_servers = (const char **)str_list_copy(state, io->in.wins_servers);
if (state->wins_servers == NULL ||
state->wins_servers[0] == NULL) goto failed;
state->addresses = str_list_copy(state, io->in.addresses);
state->addresses = (const char **)str_list_copy(state, io->in.addresses);
if (state->addresses == NULL ||
state->addresses[0] == NULL) goto failed;

View File

@ -372,11 +372,11 @@ _PUBLIC_ struct composite_context *nbt_name_register_wins_send(struct nbt_name_s
if (state->io == NULL) goto failed;
state->wins_port = io->in.wins_port;
state->wins_servers = str_list_copy(state, io->in.wins_servers);
state->wins_servers = (const char **)str_list_copy(state, io->in.wins_servers);
if (state->wins_servers == NULL ||
state->wins_servers[0] == NULL) goto failed;
state->addresses = str_list_copy(state, io->in.addresses);
state->addresses = (const char **)str_list_copy(state, io->in.addresses);
if (state->addresses == NULL ||
state->addresses[0] == NULL) goto failed;

View File

@ -323,8 +323,8 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) \
../lib/util/time.o \
lib/ufc.o lib/genrand.o lib/username.o \
lib/util_pw.o lib/access.o lib/smbrun.o \
lib/bitmap.o ../lib/crypto/crc32.o lib/dprintf.o \
../lib/util/xfile.o lib/wins_srv.o $(UTIL_REG_OBJ) \
lib/bitmap.o ../lib/crypto/crc32.o lib/dprintf.o $(UTIL_REG_OBJ) \
../lib/util/xfile.o ../lib/util/util_strlist.o lib/wins_srv.o \
lib/util_str.o lib/clobber.o lib/util_sid.o lib/util_uuid.o \
lib/util_unistr.o lib/util_file.o lib/data_blob.o \
lib/util.o lib/util_sock.o lib/sock_exec.o lib/util_sec.o \

View File

@ -459,8 +459,8 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
NTSTATUS nt_status;
if (lp_auth_methods()
&& !str_list_copy(talloc_tos(), &auth_method_list,
lp_auth_methods())) {
&& !(auth_method_list = str_list_copy(talloc_tos(),
lp_auth_methods()))) {
return NT_STATUS_NO_MEMORY;
}

View File

@ -1672,9 +1672,9 @@ char *binary_string_rfc2254(char *buf, int len);
char *binary_string(char *buf, int len);
int fstr_sprintf(fstring s, const char *fmt, ...);
char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src);
char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
bool str_list_compare(char **list1, char **list2);
int str_list_count( const char **list );
size_t str_list_length( const char **list );
bool str_list_sub_basic( char **list, const char *smb_name,
const char *domain_name );
bool str_list_substitute(char **list, const char *pattern, const char *insert);

View File

@ -1843,97 +1843,6 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
#define S_LIST_ABS 16 /* List Allocation Block Size */
char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
{
char **list;
const char *str;
char *s;
int num, lsize;
char *tok;
if (!string || !*string)
return NULL;
list = TALLOC_ARRAY(mem_ctx, char *, S_LIST_ABS+1);
if (list == NULL) {
return NULL;
}
lsize = S_LIST_ABS;
s = talloc_strdup(list, string);
if (s == NULL) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
TALLOC_FREE(list);
return NULL;
}
if (!sep) sep = LIST_SEP;
num = 0;
str = s;
while (next_token_talloc(list, &str, &tok, sep)) {
if (num == lsize) {
char **tmp;
lsize += S_LIST_ABS;
tmp = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *,
lsize + 1);
if (tmp == NULL) {
DEBUG(0,("str_list_make: "
"Unable to allocate memory"));
TALLOC_FREE(list);
return NULL;
}
list = tmp;
memset (&list[num], 0,
((sizeof(char**)) * (S_LIST_ABS +1)));
}
list[num] = tok;
num += 1;
}
list[num] = NULL;
TALLOC_FREE(s);
return list;
}
bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src)
{
char **list;
int i, num;
*dest = NULL;
if (!src)
return false;
num = 0;
while (src[num] != NULL) {
num += 1;
}
list = TALLOC_ARRAY(mem_ctx, char *, num+1);
if (list == NULL) {
return false;
}
for (i=0; i<num; i++) {
list[i] = talloc_strdup(list, src[i]);
if (list[i] == NULL) {
TALLOC_FREE(list);
return false;
}
}
list[i] = NULL;
*dest = list;
return true;
}
/**
* Return true if all the elements of the list match exactly.
**/
@ -1956,22 +1865,6 @@ bool str_list_compare(char **list1, char **list2)
return true;
}
/******************************************************************************
*****************************************************************************/
int str_list_count( const char **list )
{
int i = 0;
if ( ! list )
return 0;
/* count the number of list members */
for ( i=0; *list; i++, list++ );
return i;
}
/******************************************************************************
version of standard_sub_basic() for string lists; uses talloc_sub_basic()

View File

@ -832,7 +832,7 @@ static ADS_STATUS ads_do_paged_search_args(ADS_STRUCT *ads,
else {
/* This would be the utf8-encoded version...*/
/* if (!(search_attrs = ads_push_strvals(ctx, attrs))) */
if (!(str_list_copy(talloc_tos(), &search_attrs, attrs))) {
if (!(search_attrs = str_list_copy(talloc_tos(), attrs))) {
rc = LDAP_NO_MEMORY;
goto done;
}
@ -1144,7 +1144,7 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
else {
/* This would be the utf8-encoded version...*/
/* if (!(search_attrs = ads_push_strvals(ctx, attrs))) */
if (!(str_list_copy(talloc_tos(), &search_attrs, attrs)))
if (!(search_attrs = str_list_copy(talloc_tos(), attrs)))
{
DEBUG(1,("ads_do_search: str_list_copy() failed!"));
rc = LDAP_NO_MEMORY;

View File

@ -61,7 +61,7 @@ static const struct generic_mapping svc_generic_map =
bool init_service_op_table( void )
{
const char **service_list = lp_svcctl_list();
int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_count( service_list );
int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_length( service_list );
int i;
if ( !(svcctl_ops = TALLOC_ARRAY( NULL, struct service_control_op, num_services+1)) ) {

View File

@ -545,7 +545,7 @@ static bool user_ok(const char *user, int snum)
ret = True;
if (lp_invalid_users(snum)) {
str_list_copy(talloc_tos(), &invalid, lp_invalid_users(snum));
invalid = str_list_copy(talloc_tos(), lp_invalid_users(snum));
if (invalid &&
str_list_substitute(invalid, "%S", lp_servicename(snum))) {
@ -561,7 +561,7 @@ static bool user_ok(const char *user, int snum)
TALLOC_FREE(invalid);
if (ret && lp_valid_users(snum)) {
str_list_copy(talloc_tos(), &valid, lp_valid_users(snum));
valid = str_list_copy(talloc_tos(), lp_valid_users(snum));
if ( valid &&
str_list_substitute(valid, "%S", lp_servicename(snum)) ) {

View File

@ -207,7 +207,7 @@ _PUBLIC_ NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
if (logon_workstation && workstation_list && *workstation_list) {
bool invalid_ws = true;
int i;
const char **workstations = str_list_make(mem_ctx, workstation_list, ",");
const char **workstations = (const char **)str_list_make(mem_ctx, workstation_list, ",");
for (i = 0; workstations && workstations[i]; i++) {
DEBUG(10,("sam_account_ok: checking for workstation match '%s' and '%s'\n",

View File

@ -2754,7 +2754,7 @@ process a -c command string
****************************************************************************/
static int process_command_string(struct smbclient_context *ctx, const char *cmd)
{
const char **lines;
char **lines;
int i, rc = 0;
lines = str_list_make(NULL, cmd, ";");

View File

@ -1912,7 +1912,7 @@ struct ldb_dn *samdb_dns_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_c
return NULL;
}
split_realm = str_list_make(tmp_ctx, dns_domain, ".");
split_realm = (const char **)str_list_make(tmp_ctx, dns_domain, ".");
if (!split_realm) {
talloc_free(tmp_ctx);
return NULL;

View File

@ -79,7 +79,7 @@ NTSTATUS resolve_name_wins(struct nbt_name *name,
bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **address_list, struct interface *ifaces, uint16_t nbt_port, int nbt_timeout)
{
struct resolve_wins_data *wins_data = talloc(ctx, struct resolve_wins_data);
wins_data->address_list = str_list_copy(wins_data, address_list);
wins_data->address_list = (const char **)str_list_copy(wins_data, address_list);
wins_data->ifaces = talloc_reference(wins_data, ifaces);
wins_data->nbt_port = nbt_port;
wins_data->nbt_timeout = nbt_timeout;

View File

@ -129,7 +129,7 @@ NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
if (NT_STATUS_IS_OK(status)) {
s = talloc_get_type(c->private_data, struct lookup_state);
io->out.address = str_list_make(mem_ctx, s->address, NULL);
io->out.address = (const char **)str_list_make(mem_ctx, s->address, NULL);
NT_STATUS_HAVE_NO_MEMORY(io->out.address);
}

View File

@ -140,7 +140,7 @@ static void nbtd_wins_refresh(struct event_context *ev, struct timed_event *te,
/* setup a wins name refresh request */
io.in.name = iname->name;
io.in.wins_servers = str_list_make(tmp_ctx, iname->wins_server, NULL);
io.in.wins_servers = (const char **)str_list_make(tmp_ctx, iname->wins_server, NULL);
io.in.wins_port = lp_nbt_port(iface->nbtsrv->task->lp_ctx);
io.in.addresses = nbtd_address_list(iface, tmp_ctx);
io.in.nb_flags = iname->nb_flags;

View File

@ -130,7 +130,7 @@ const char **param_get_string_list(struct param_context *ctx, const char *param,
if (separator == NULL)
separator = LIST_SEP;
return str_list_make(ctx, p->value, separator);
return (const char **)str_list_make(ctx, p->value, separator);
}
int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section)

View File

@ -885,7 +885,7 @@ const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,
const char *value = lp_get_parametric(lp_ctx, service, type, option);
if (value != NULL)
return str_list_make(mem_ctx, value, separator);
return (const char **)str_list_make(mem_ctx, value, separator);
return NULL;
}
@ -1299,7 +1299,7 @@ static void copy_service(struct loadparm_service *pserviceDest,
strupper(*(char **)dest_ptr);
break;
case P_LIST:
*(const char ***)dest_ptr = str_list_copy(pserviceDest,
*(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
*(const char ***)src_ptr);
break;
default:
@ -1653,7 +1653,7 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
}
case P_LIST:
*(const char ***)parm_ptr = str_list_make(mem_ctx,
*(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
pszParmValue, NULL);
break;

View File

@ -225,7 +225,7 @@ static NTSTATUS remote_register_one_iface(struct dcesrv_context *dce_ctx, const
static NTSTATUS remote_op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
{
int i;
const char **ifaces = str_list_make(dce_ctx, lp_parm_string(dce_ctx->lp_ctx, NULL, "dcerpc_remote", "interfaces"),NULL);
const char **ifaces = (const char **)str_list_make(dce_ctx, lp_parm_string(dce_ctx->lp_ctx, NULL, "dcerpc_remote", "interfaces"),NULL);
if (!ifaces) {
DEBUG(3,("remote_op_init_server: no interfaces configured\n"));

View File

@ -95,8 +95,8 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address
torture_comment(tctx, "register the name\n");
io.in.name = *name;
io.in.wins_port = lp_nbt_port(tctx->lp_ctx);
io.in.wins_servers = str_list_make(tctx, address, NULL);
io.in.addresses = str_list_make(tctx, myaddress, NULL);
io.in.wins_servers = (const char **)str_list_make(tctx, address, NULL);
io.in.addresses = (const char **)str_list_make(tctx, myaddress, NULL);
io.in.nb_flags = nb_flags;
io.in.ttl = 300000;
@ -168,8 +168,8 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address
torture_comment(tctx, "refresh the name\n");
refresh.in.name = *name;
refresh.in.wins_port = lp_nbt_port(tctx->lp_ctx);
refresh.in.wins_servers = str_list_make(tctx, address, NULL);
refresh.in.addresses = str_list_make(tctx, myaddress, NULL);
refresh.in.wins_servers = (const char **)str_list_make(tctx, address, NULL);
refresh.in.addresses = (const char **)str_list_make(tctx, myaddress, NULL);
refresh.in.nb_flags = nb_flags;
refresh.in.ttl = 12345;

View File

@ -113,7 +113,7 @@ NTSTATUS wbsrv_samba3_netbios_name(struct wbsrv_samba3_call *s3call)
NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
{
char *path = s3call->wbconn->listen_socket->service->priv_socket_path;
const char *path = s3call->wbconn->listen_socket->service->priv_socket_path;
s3call->response.result = WINBINDD_OK;
s3call->response.extra_data.data = path;