From: Ralph Boehme Date: Sat, 20 Jan 2024 11:58:52 +0000 (+0100) Subject: s3/lib: modernize set_namearray() X-Git-Tag: tdb-1.4.11~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7fc74c7883ca9a9682b809e37b724bfe3bb4c64d;p=thirdparty%2Fsamba.git s3/lib: modernize set_namearray() No change in behaviour. Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 639f93c237f..b25b1177841 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -318,9 +318,9 @@ const char *readdirname(DIR *p); bool is_in_path(const char *name, struct name_compare_entry *namelist, bool case_sensitive); -void set_namearray(struct name_compare_entry **ppname_array, - const char *namelist); -void free_namearray(struct name_compare_entry *name_array); +void set_namearray(TALLOC_CTX *mem_ctx, + const char *namelist, + struct name_compare_entry **_name_array); bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type); bool fcntl_getlock(int fd, int op, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid); int map_process_lock_to_ofd_lock(int op); diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 56fe0a69195..a0974a49d49 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -703,7 +703,7 @@ struct vuid_cache { }; struct name_compare_entry { - char *name; + const char *name; bool is_wild; }; diff --git a/source3/lib/namearray.c b/source3/lib/namearray.c deleted file mode 100644 index f66dd0ae46b..00000000000 --- a/source3/lib/namearray.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Jeremy Allison 2001-2007 - Copyright (C) Simo Sorce 2001 - Copyright (C) Jim McDonough 2003 - Copyright (C) James Peach 2006 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -/**************************************************************************** - Routine to free a namearray. -****************************************************************************/ - -void free_namearray(struct name_compare_entry *name_array) -{ - int i; - - if(name_array == NULL) - return; - - for(i=0; name_array[i].name!=NULL; i++) - SAFE_FREE(name_array[i].name); - SAFE_FREE(name_array); -} diff --git a/source3/lib/util.c b/source3/lib/util.c index d7d1c48aa98..3246294261a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -44,6 +44,7 @@ #include "lib/dbwrap/dbwrap_ctdb.h" #include "lib/gencache.h" #include "lib/util/string_wrappers.h" +#include "lib/util/strv.h" #ifdef HAVE_SYS_PRCTL_H #include @@ -802,106 +803,55 @@ bool is_in_path(const char *name, if possible. ********************************************************************/ -void set_namearray(struct name_compare_entry **ppname_array, const char *namelist_in) +void set_namearray(TALLOC_CTX *mem_ctx, + const char *namelist_in, + struct name_compare_entry **_name_array) { - char *name_end; - char *namelist; - char *namelist_end; - char *nameptr; - int num_entries = 0; - int i; + struct name_compare_entry *name_array = NULL; + struct name_compare_entry *e = NULL; + char *namelist = NULL; + const char *p = NULL; + size_t num_entries; - (*ppname_array) = NULL; + *_name_array = NULL; - if((namelist_in == NULL ) || ((namelist_in != NULL) && (*namelist_in == '\0'))) + if ((namelist_in == NULL) || (namelist_in[0] == '\0')) { return; + } - namelist = talloc_strdup(talloc_tos(), namelist_in); + namelist = path_to_strv(mem_ctx, namelist_in); if (namelist == NULL) { - DEBUG(0,("set_namearray: talloc fail\n")); + DBG_ERR("path_to_strv failed\n"); return; } - nameptr = namelist; - - namelist_end = &namelist[strlen(namelist)]; - - /* We need to make two passes over the string. The - first to count the number of elements, the second - to split it. - */ - - while(nameptr <= namelist_end) { - if ( *nameptr == '/' ) { - /* cope with multiple (useless) /s) */ - nameptr++; - continue; - } - /* anything left? */ - if ( *nameptr == '\0' ) - break; - /* find the next '/' or consume remaining */ - name_end = strchr_m(nameptr, '/'); - if (name_end == NULL) { - /* Point nameptr at the terminating '\0' */ - nameptr += strlen(nameptr); - } else { - /* next segment please */ - nameptr = name_end + 1; - } - num_entries++; - } + num_entries = strv_count(namelist); - if(num_entries == 0) { - talloc_free(namelist); + name_array = talloc_zero_array(mem_ctx, + struct name_compare_entry, + num_entries + 1); + if (name_array == NULL) { + DBG_ERR("talloc failed\n"); + TALLOC_FREE(namelist); return; } - if(( (*ppname_array) = SMB_MALLOC_ARRAY(struct name_compare_entry, num_entries + 1)) == NULL) { - DEBUG(0,("set_namearray: malloc fail\n")); - talloc_free(namelist); - return; - } + namelist = talloc_reparent(mem_ctx, name_array, namelist); - /* Now copy out the names */ - nameptr = namelist; - i = 0; - while(nameptr <= namelist_end) { - if ( *nameptr == '/' ) { + e = &name_array[0]; + + while ((p = strv_next(namelist, p)) != NULL) { + if (*p == '\0') { /* cope with multiple (useless) /s) */ - nameptr++; continue; } - /* anything left? */ - if ( *nameptr == '\0' ) - break; - - /* find the next '/' or consume remaining */ - name_end = strchr_m(nameptr, '/'); - if (name_end != NULL) { - *name_end = '\0'; - } - - (*ppname_array)[i].is_wild = ms_has_wild(nameptr); - if(((*ppname_array)[i].name = SMB_STRDUP(nameptr)) == NULL) { - DEBUG(0,("set_namearray: malloc fail (1)\n")); - talloc_free(namelist); - return; - } - if (name_end == NULL) { - /* Point nameptr at the terminating '\0' */ - nameptr += strlen(nameptr); - } else { - /* next segment please */ - nameptr = name_end + 1; - } - i++; + e->name = p; + e->is_wild = ms_has_wild(e->name); + e++; } - (*ppname_array)[i].name = NULL; - - talloc_free(namelist); + *_name_array = name_array; return; } diff --git a/source3/modules/vfs_virusfilter.c b/source3/modules/vfs_virusfilter.c index ea1886d85c8..471eff94e89 100644 --- a/source3/modules/vfs_virusfilter.c +++ b/source3/modules/vfs_virusfilter.c @@ -255,13 +255,17 @@ static int virusfilter_vfs_connect( exclude_files = lp_parm_const_string( snum, "virusfilter", "exclude files", NULL); if (exclude_files != NULL) { - set_namearray(&config->exclude_files, exclude_files); + set_namearray(config, + exclude_files, + &config->exclude_files); } infected_files = lp_parm_const_string( snum, "virusfilter", "infected files", NULL); if (infected_files != NULL) { - set_namearray(&config->infected_files, infected_files); + set_namearray(config, + infected_files, + &config->infected_files); } config->cache_entry_limit = lp_parm_int( @@ -579,7 +583,6 @@ static void virusfilter_vfs_disconnect(struct vfs_handle_struct *handle) config->backend->fns->disconnect(handle); } - free_namearray(config->exclude_files); virusfilter_io_disconnect(config->io_h); SMB_VFS_NEXT_DISCONNECT(handle); diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c index b7a745a951e..6694147c225 100644 --- a/source3/smbd/conn.c +++ b/source3/smbd/conn.c @@ -250,11 +250,6 @@ static void conn_free_internal(connection_struct *conn) SAFE_FREE(state->data); } - free_namearray(conn->veto_list); - free_namearray(conn->hide_list); - free_namearray(conn->veto_oplock_list); - free_namearray(conn->aio_write_behind_list); - ZERO_STRUCTP(conn); } diff --git a/source3/smbd/smb2_service.c b/source3/smbd/smb2_service.c index e7f5d9ed358..f832008a698 100644 --- a/source3/smbd/smb2_service.c +++ b/source3/smbd/smb2_service.c @@ -753,14 +753,18 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn, /* Add veto/hide lists */ if (!IS_IPC(conn) && !IS_PRINT(conn)) { - set_namearray( &conn->veto_list, - lp_veto_files(talloc_tos(), lp_sub, snum)); - set_namearray( &conn->hide_list, - lp_hide_files(talloc_tos(), lp_sub, snum)); - set_namearray( &conn->veto_oplock_list, - lp_veto_oplock_files(talloc_tos(), lp_sub, snum)); - set_namearray( &conn->aio_write_behind_list, - lp_aio_write_behind(talloc_tos(), lp_sub, snum)); + set_namearray(conn, + lp_veto_oplock_files(talloc_tos(), lp_sub, snum), + &conn->veto_oplock_list); + set_namearray(conn, + lp_aio_write_behind(talloc_tos(), lp_sub, snum), + &conn->aio_write_behind_list); + set_namearray(conn, + lp_veto_oplock_files(talloc_tos(), lp_sub, snum), + &conn->veto_oplock_list); + set_namearray(conn, + lp_aio_write_behind(talloc_tos(), lp_sub, snum), + &conn->aio_write_behind_list); } smb_fname_cpath = synthetic_smb_fname(talloc_tos(), conn->connectpath, diff --git a/source3/torture/test_matching.c b/source3/torture/test_matching.c index 5c2f75bfbfe..2b867fb37de 100644 --- a/source3/torture/test_matching.c +++ b/source3/torture/test_matching.c @@ -66,7 +66,7 @@ bool run_str_match_mswild(int dummy) d_fprintf(stderr, "namelist: %s\n", namelist); - set_namearray(&name_entries, namelist); + set_namearray(talloc_tos(), namelist, &name_entries); SMB_ASSERT(name_entries != NULL); status = samba_path_matching_mswild_create(talloc_tos(), diff --git a/source3/wscript_build b/source3/wscript_build index 59b65f41239..cb68e7fffad 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -990,7 +990,6 @@ bld.SAMBA3_LIBRARY('samba3-util', lib/util_str.c lib/adt_tree.c lib/util_malloc.c - lib/namearray.c lib/file_id.c lib/cbuf.c lib/per_thread_cwd.c