srvsvc: Collect file ids in enum_file_fn()
authorVolker Lendecke <vl@samba.org>
Tue, 21 Apr 2020 12:32:16 +0000 (14:32 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 14 May 2020 20:29:38 +0000 (20:29 +0000)
Will be used a few patches down

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>
source3/rpc_server/srvsvc/srv_srvsvc_nt.c

index 6140e852743c487e961c1b1a0e5fe09720f0bf68..c7bd28509fc0c7fc37a277f2312ba97e73fde8a4 100644 (file)
@@ -54,6 +54,7 @@ struct file_enum_count {
        TALLOC_CTX *ctx;
        const char *username;
        struct srvsvc_NetFileCtr3 *ctr3;
+       struct file_id *fids;
 };
 
 struct sess_file_info {
@@ -90,6 +91,7 @@ static int enum_file_fn(struct file_id id,
                (struct file_enum_count *)private_data;
        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;
@@ -121,10 +123,18 @@ static int enum_file_fn(struct file_id id,
        }
        ctr3->array = f;
 
+       fids = talloc_realloc(
+               fenum->ctx, fenum->fids, struct file_id, ctr3->count+1);
+       if (fids == NULL) {
+               DBG_ERR("realloc failed for %"PRIu32" items\n", ctr3->count+1);
+               return 0;
+       }
+       fids[ctr3->count] = id;
+       fenum->fids = fids;
+
        /* need to count the number of locks on a file */
 
-       ZERO_STRUCT( fsp );
-       fsp.file_id = id;
+       fsp = (struct files_struct) { .file_id = id, };
 
        if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
                num_locks = brl_num_locks(brl);