srvsvc: Move brl_get_locks() out of enum_file_fn()
authorVolker Lendecke <vl@samba.org>
Tue, 21 Apr 2020 12:54:25 +0000 (14:54 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 14 May 2020 22:06:32 +0000 (22:06 +0000)
With share_infos.tdb this is a locking order violation:
share_infos.tdb is level 4, brlock.tdb is level 2. Avoid this by first
walking the share_infos.tdb and then fetching all the brlock entries.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu May 14 22:06:32 UTC 2020 on sn-devel-184

selftest/knownfail.d/netfileenum [deleted file]
source3/rpc_server/srvsvc/srv_srvsvc_nt.c

diff --git a/selftest/knownfail.d/netfileenum b/selftest/knownfail.d/netfileenum
deleted file mode 100644 (file)
index 2d3b6fa..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba3.blackbox.netfileenum.netfileenum\(simpleserver:local\)
index c7bd28509fc0c7fc37a277f2312ba97e73fde8a4..3fb8427693ba04631e49b66e429abeff7dd03bde 100644 (file)
@@ -92,9 +92,6 @@ static int enum_file_fn(struct file_id id,
        struct srvsvc_NetFileCtr3 *ctr3 = fenum->ctr3;
        struct srvsvc_NetFileInfo3 *f;
        struct file_id *fids = NULL;
-       files_struct fsp;
-       struct byte_range_lock *brl;
-       int num_locks = 0;
        char *fullpath = NULL;
        uint32_t permissions;
        const char *username;
@@ -132,15 +129,6 @@ static int enum_file_fn(struct file_id id,
        fids[ctr3->count] = id;
        fenum->fids = fids;
 
-       /* need to count the number of locks on a file */
-
-       fsp = (struct files_struct) { .file_id = id, };
-
-       if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
-               num_locks = brl_num_locks(brl);
-               TALLOC_FREE(brl);
-       }
-
        if ( strcmp(d->base_name, "." ) == 0 ) {
                fullpath = talloc_asprintf(
                        fenum->ctx,
@@ -168,7 +156,6 @@ static int enum_file_fn(struct file_id id,
                .fid            = (((uint32_t)(procid_to_pid(&e->pid))<<16) |
                                   e->share_file_id),
                .permissions    = permissions,
-               .num_locks      = num_locks,
                .path           = fullpath,
                .user           = username,
        };
@@ -189,11 +176,28 @@ static WERROR net_enum_files(TALLOC_CTX *ctx,
        struct file_enum_count f_enum_cnt = {
                .ctx = ctx, .username = username, .ctr3 = *ctr3,
        };
+       uint32_t i;
 
        share_entry_forall(enum_file_fn, (void *)&f_enum_cnt );
 
        *ctr3 = f_enum_cnt.ctr3;
 
+       /* need to count the number of locks on a file */
+
+       for (i=0; i<(*ctr3)->count; i++) {
+               struct files_struct fsp = { .file_id = f_enum_cnt.fids[i], };
+               struct byte_range_lock *brl = NULL;
+
+               brl = brl_get_locks(ctx, &fsp);
+               if (brl == NULL) {
+                       continue;
+               }
+
+               (*ctr3)->array[i].num_locks = brl_num_locks(brl);
+
+               TALLOC_FREE(brl);
+       }
+
        return WERR_OK;
 }