]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: smbd: Convert reply_search() to use filename_convert_smb1_search_path().
authorJeremy Allison <jra@samba.org>
Fri, 3 Dec 2021 19:22:03 +0000 (11:22 -0800)
committerRalph Boehme <slow@samba.org>
Sat, 11 Dec 2021 07:17:28 +0000 (07:17 +0000)
Cleans up this code path nicely !

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/reply.c

index 203105014d8e8b0f4943209e12ebb634db453460..d7c5b962ca79657a6b8ff5bed53acabe73714d91 100644 (file)
@@ -1748,15 +1748,17 @@ void reply_search(struct smb_request *req)
        /* dirtype &= ~FILE_ATTRIBUTE_DIRECTORY; */
 
        if (status_len == 0) {
-               int ret;
+               const char *dirpath;
                struct smb_filename *smb_dname = NULL;
-               uint32_t ucf_flags = UCF_ALWAYS_ALLOW_WCARD_LCOMP |
-                       ucf_flags_from_smb_request(req);
-               nt_status = filename_convert(ctx, conn,
-                                            path,
-                                            ucf_flags,
-                                            0,
-                                            &smb_fname);
+               uint32_t ucf_flags = ucf_flags_from_smb_request(req);
+
+               nt_status = filename_convert_smb1_search_path(ctx,
+                                       conn,
+                                       path,
+                                       ucf_flags,
+                                       &smb_dname,
+                                       &mask);
+
                if (!NT_STATUS_IS_OK(nt_status)) {
                        if (NT_STATUS_EQUAL(nt_status,NT_STATUS_PATH_NOT_COVERED)) {
                                reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
@@ -1767,56 +1769,9 @@ void reply_search(struct smb_request *req)
                        goto out;
                }
 
-               directory = smb_fname->base_name;
-
-               p = strrchr_m(directory,'/');
-               if ((p != NULL) && (*directory != '/')) {
-                       mask = talloc_strdup(ctx, p + 1);
-                       directory = talloc_strndup(ctx, directory,
-                                                  PTR_DIFF(p, directory));
-               } else {
-                       mask = talloc_strdup(ctx, directory);
-                       directory = talloc_strdup(ctx,".");
-               }
-
-               if (!directory) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                       goto out;
-               }
-
                memset((char *)status,'\0',21);
                SCVAL(status,0,(dirtype & 0x1F));
 
-               smb_dname = synthetic_smb_fname(talloc_tos(),
-                                       directory,
-                                       NULL,
-                                       NULL,
-                                       smb_fname->twrp,
-                                       smb_fname->flags);
-               if (smb_dname == NULL) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-                       goto out;
-               }
-
-               /*
-                * As we've cut off the last component from
-                * smb_fname we need to re-stat smb_dname
-                * so FILE_OPEN disposition knows the directory
-                * exists.
-                */
-               ret = vfs_stat(conn, smb_dname);
-               if (ret == -1) {
-                       nt_status = map_nt_error_from_unix(errno);
-                       reply_nterror(req, nt_status);
-                       goto out;
-               }
-
-               nt_status = openat_pathref_fsp(conn->cwd_fsp, smb_dname);
-               if (!NT_STATUS_IS_OK(nt_status)) {
-                       reply_nterror(req, nt_status);
-                       goto out;
-               }
-
                /*
                 * Open an fsp on this directory for the dptr.
                 */
@@ -1873,6 +1828,12 @@ void reply_search(struct smb_request *req)
                }
 
                dptr_num = dptr_dnum(fsp->dptr);
+               dirpath = dptr_path(sconn, dptr_num);
+               directory = talloc_strdup(ctx, dirpath);
+               if (!directory) {
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
+                       goto out;
+               }
 
        } else {
                int status_dirtype;