From: Volker Lendecke Date: Sat, 27 May 2023 11:20:56 +0000 (+0200) Subject: smbd: Add smbd_dirptr_push_overflow() X-Git-Tag: talloc-2.4.1~424 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b27175764c8b7718f85a455beda84f345243cd6;p=thirdparty%2Fsamba.git smbd: Add smbd_dirptr_push_overflow() 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index b1d595d46f1..89c3ea053d7 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -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 diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 837d3c8acd2..c58123ee501 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -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,