From: Volker Lendecke Date: Thu, 2 Feb 2023 16:01:16 +0000 (+0100) Subject: smbd: Simplify SeekDir() with an early return X-Git-Tag: talloc-2.4.1~1619 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c19e6ca756fda9dd66fa2cd484e54d0e3e221f0;p=thirdparty%2Fsamba.git smbd: Simplify SeekDir() with an early return Review with git show -w Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index f7ca390ea8b..db940161e1a 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1686,31 +1686,36 @@ void RewindDir(struct smb_Dir *dir_hnd, long *poffset) void SeekDir(struct smb_Dir *dirp, long offset) { - if (offset != dirp->offset) { - if (offset == START_OF_DIRECTORY_OFFSET) { - RewindDir(dirp, &offset); - /* - * Ok we should really set the file number here - * to 1 to enable ".." to be returned next. Trouble - * is I'm worried about callers using SeekDir(dirp,0) - * as equivalent to RewindDir(). So leave this alone - * for now. - */ - } else if (offset == DOT_DOT_DIRECTORY_OFFSET) { - RewindDir(dirp, &offset); - /* - * Set the file number to 2 - we want to get the first - * real file entry (the one we return after "..") - * on the next ReadDir. - */ - dirp->file_number = 2; - } else if (offset == END_OF_DIRECTORY_OFFSET) { - ; /* Don't seek in this case. */ - } else { - SMB_VFS_SEEKDIR(dirp->conn, dirp->dir, offset); - } - dirp->offset = offset; + if (offset == dirp->offset) { + /* + * Nothing to do + */ + return; + } + + if (offset == START_OF_DIRECTORY_OFFSET) { + RewindDir(dirp, &offset); + /* + * Ok we should really set the file number here + * to 1 to enable ".." to be returned next. Trouble + * is I'm worried about callers using SeekDir(dirp,0) + * as equivalent to RewindDir(). So leave this alone + * for now. + */ + } else if (offset == DOT_DOT_DIRECTORY_OFFSET) { + RewindDir(dirp, &offset); + /* + * Set the file number to 2 - we want to get the first + * real file entry (the one we return after "..") + * on the next ReadDir. + */ + dirp->file_number = 2; + } else if (offset == END_OF_DIRECTORY_OFFSET) { + ; /* Don't seek in this case. */ + } else { + SMB_VFS_SEEKDIR(dirp->conn, dirp->dir, offset); } + dirp->offset = offset; } /*******************************************************************