No change in behaviour.
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
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);
};
struct name_compare_entry {
- char *name;
+ const char *name;
bool is_wild;
};
+++ /dev/null
-/*
- 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 <jmcd@us.ibm.com> 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 <http://www.gnu.org/licenses/>.
-*/
-
-#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);
-}
#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 <sys/prctl.h>
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;
}
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(
config->backend->fns->disconnect(handle);
}
- free_namearray(config->exclude_files);
virusfilter_io_disconnect(config->io_h);
SMB_VFS_NEXT_DISCONNECT(handle);
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);
}
/* 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,
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(),
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