smbd: Make reply_search() easier to understand
authorVolker Lendecke <vl@samba.org>
Thu, 8 Jun 2023 10:37:43 +0000 (12:37 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 8 Jun 2023 17:39:39 +0000 (17:39 +0000)
commit6578dc9a51293ee545196b497910097a8adf62ad
treed496a0923dbb873b565a682f4157b3a3d4ab44d4
parent73ebbb7244d0ae77da3d73331125d5d585b95232
smbd: Make reply_search() easier to understand

reply_search() is the only place in the code where we have to deal
with [MS-CIFS] 2.2.4.59.1 ResumeKey structures. This concentrates the
formatting of this to pure SMB1 code in reply_search(), moving away
knowledge about the format from smbd/dir.c's dptr_fill() and
dptr_fetch_fsp().

With this code we just count up the FileIndex from behaviour note
110. If the client is sane and sends us the last FileIndex we returned
to it in a subsequent search, we can completely avoid any
telldir/seekdir. If it skips back, with the new code we rewind and
re-readdir the directory. This will be slower for a very special
corner case, but it's a lot simpler to understand (at least to
me). Also, it avoids calling telldir/seekdir for every entry.

Tested both cases (sane and insane clients) manually with a modified
cli_list_old_done(). Not doing automated tests. If this breaks real
users, we'll fix it and write tests then.

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