]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/lib: move set_namearray() to util_namearray.c
authorRalph Boehme <slow@samba.org>
Wed, 7 Feb 2024 09:21:33 +0000 (10:21 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 26 Jul 2024 10:06:30 +0000 (10:06 +0000)
Needed to fix circular dependencies between samba-passdb, secrets3 and
samba3util (iirc).

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/util.c
source3/lib/util_namearray.c [new file with mode: 0644]
source3/wscript_build

index 3246294261a5cb37b9c0afbffb894a2b197feaaf..5561aa815ceb10dd55602abebb04bb429806c690 100644 (file)
@@ -792,69 +792,6 @@ bool is_in_path(const char *name,
        return False;
 }
 
-/*******************************************************************
- Strip a '/' separated list into an array of
- name_compare_enties structures suitable for
- passing to is_in_path(). We do this for
- speed so we can pre-parse all the names in the list
- and don't do it for each call to is_in_path().
- We also check if the entry contains a wildcard to
- remove a potentially expensive call to mask_match
- if possible.
-********************************************************************/
-
-void set_namearray(TALLOC_CTX *mem_ctx,
-                  const char *namelist_in,
-                  struct name_compare_entry **_name_array)
-{
-       struct name_compare_entry *name_array = NULL;
-       struct name_compare_entry *e = NULL;
-       char *namelist = NULL;
-       const char *p = NULL;
-       size_t num_entries;
-
-       *_name_array = NULL;
-
-       if ((namelist_in == NULL) || (namelist_in[0] == '\0')) {
-               return;
-       }
-
-       namelist = path_to_strv(mem_ctx, namelist_in);
-       if (namelist == NULL) {
-               DBG_ERR("path_to_strv failed\n");
-               return;
-       }
-
-       num_entries = strv_count(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;
-       }
-
-       namelist = talloc_reparent(mem_ctx, name_array, namelist);
-
-       e = &name_array[0];
-
-       while ((p = strv_next(namelist, p)) != NULL) {
-               if (*p == '\0') {
-                       /* cope with multiple (useless) /s) */
-                       continue;
-               }
-
-               e->name = p;
-               e->is_wild = ms_has_wild(e->name);
-               e++;
-       }
-
-       *_name_array = name_array;
-       return;
-}
-
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_LOCKING
 
diff --git a/source3/lib/util_namearray.c b/source3/lib/util_namearray.c
new file mode 100644 (file)
index 0000000..43cf3e2
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Ralph Boehme 2024
+
+   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"
+#include "lib/util/strv.h"
+
+/*******************************************************************
+ Strip a '/' separated list into an array of
+ name_compare_enties structures suitable for
+ passing to is_in_path(). We do this for
+ speed so we can pre-parse all the names in the list
+ and don't do it for each call to is_in_path().
+ We also check if the entry contains a wildcard to
+ remove a potentially expensive call to mask_match
+ if possible.
+********************************************************************/
+
+void set_namearray(TALLOC_CTX *mem_ctx,
+                  const char *namelist_in,
+                  struct name_compare_entry **_name_array)
+{
+       struct name_compare_entry *name_array = NULL;
+       struct name_compare_entry *e = NULL;
+       char *namelist = NULL;
+       const char *p = NULL;
+       size_t num_entries;
+
+       *_name_array = NULL;
+
+       if ((namelist_in == NULL) || (namelist_in[0] == '\0')) {
+               return;
+       }
+
+       namelist = path_to_strv(mem_ctx, namelist_in);
+       if (namelist == NULL) {
+               DBG_ERR("path_to_strv failed\n");
+               return;
+       }
+
+       num_entries = strv_count(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;
+       }
+
+       namelist = talloc_reparent(mem_ctx, name_array, namelist);
+
+       e = &name_array[0];
+
+       while ((p = strv_next(namelist, p)) != NULL) {
+               if (*p == '\0') {
+                       /* cope with multiple (useless) /s) */
+                       continue;
+               }
+
+               e->name = p;
+               e->is_wild = ms_has_wild(e->name);
+               e++;
+       }
+
+       *_name_array = name_array;
+       return;
+}
index cb68e7fffadd3cdab4a79392cb2512daea72b932..64969dbbefa73bf3f6586dccf402aa68d6f9cd7e 100644 (file)
@@ -313,6 +313,13 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
                         iov_buf
                         ''')
 
+bld.SAMBA3_SUBSYSTEM('samba3-namearray',
+                   source='''
+                          lib/util_namearray.c
+                          ''',
+                   deps='''
+                        ''')
+
 if bld.env.with_ctdb:
     SAMBA_CLUSTER_SUPPORT_SOURCES='''
                      lib/cluster_support.c
@@ -742,6 +749,7 @@ bld.SAMBA3_LIBRARY('smbd_base',
                         GNUTLS_HELPERS
                         fd_handle
                         cli_spoolss
+                        samba3-namearray
                    ''' +
                    bld.env['dmapi_lib'] +
                    bld.env['legacy_quota_libs'] +