]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add smbd_dirptr_push_overflow()
authorVolker Lendecke <vl@samba.org>
Sat, 27 May 2023 11:20:56 +0000 (13:20 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 13 Jun 2023 23:33:39 +0000 (23:33 +0000)
This saves the result of smbd_dirptr_get_entry() for later retrieval
in case we could not marshall it to the output buffer. Return this
entry when calling smbd_dirptr_get_entry() again.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/dir.c
source3/smbd/globals.h

index b1d595d46f11a190be62b6e5218f17d0043356cc..89c3ea053d78d41530f01db9cd8d0faf134a781c 100644 (file)
@@ -70,6 +70,12 @@ struct dptr_struct {
        bool did_stat; /* Optimisation for non-wcard searches. */
        bool priv;     /* Directory handle opened with privilege. */
        uint32_t counter;
+
+       struct {
+               char *fname;
+               struct smb_filename *smb_fname;
+               uint32_t mode;
+       } overflow;
 };
 
 static NTSTATUS OpenDir_fsp(
@@ -361,12 +367,16 @@ void dptr_RewindDir(struct dptr_struct *dptr)
        long offset;
        RewindDir(dptr->dir_hnd, &offset);
        dptr->did_stat = false;
+       TALLOC_FREE(dptr->overflow.fname);
+       TALLOC_FREE(dptr->overflow.smb_fname);
 }
 
 void dptr_SeekDir(struct dptr_struct *dptr, long offset)
 {
        SeekDir(dptr->dir_hnd, offset);
        dptr->did_stat = false;
+       TALLOC_FREE(dptr->overflow.fname);
+       TALLOC_FREE(dptr->overflow.smb_fname);
 }
 
 long dptr_TellDir(struct dptr_struct *dptr)
@@ -575,6 +585,13 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
        *_smb_fname = NULL;
        *_mode = 0;
 
+       if (dirptr->overflow.smb_fname != NULL) {
+               *_fname = talloc_move(ctx, &dirptr->overflow.fname);
+               *_smb_fname = talloc_move(ctx, &dirptr->overflow.smb_fname);
+               *_mode = dirptr->overflow.mode;
+               return true;
+       }
+
        pathlen = strlen(dpath);
        slashlen = ( dpath[pathlen-1] != '/') ? 1 : 0;
 
@@ -887,6 +904,19 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
        return false;
 }
 
+void smbd_dirptr_push_overflow(struct dptr_struct *dirptr,
+                              char **_fname,
+                              struct smb_filename **_smb_fname,
+                              uint32_t mode)
+{
+       SMB_ASSERT(dirptr->overflow.fname == NULL);
+       SMB_ASSERT(dirptr->overflow.smb_fname == NULL);
+
+       dirptr->overflow.fname = talloc_move(dirptr, _fname);
+       dirptr->overflow.smb_fname = talloc_move(dirptr, _smb_fname);
+       dirptr->overflow.mode = mode;
+}
+
 /*******************************************************************
  Check to see if a user can read an fsp . This is only approximate,
  it is used as part of the "hide unreadable" option. Don't
index 837d3c8acd2aae328ca1360996cd12410416bd59..c58123ee501d33ea81805aa4bd938a7c370f14d4 100644 (file)
@@ -183,6 +183,10 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                           struct smb_filename **_smb_fname,
                           uint32_t *_mode,
                           long *_prev_offset);
+void smbd_dirptr_push_overflow(struct dptr_struct *dirptr,
+                              char **_fname,
+                              struct smb_filename **_smb_fname,
+                              uint32_t mode);
 
 NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
                               connection_struct *conn,