smbd: Move filename_convert_smb1_search_path() to smb1-only code
authorVolker Lendecke <vl@samba.org>
Tue, 10 Oct 2023 13:36:56 +0000 (15:36 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 1 Nov 2023 18:55:32 +0000 (18:55 +0000)
Just general cleanup.

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

index 29e3d9d19cfc213cf21d2cee449066f30ff6a7ac..7032d218e523a17971b2dbc82607b1d25bff58d7 100644 (file)
@@ -483,93 +483,6 @@ char *get_original_lcomp(TALLOC_CTX *ctx,
        return orig_lcomp;
 }
 
-/*
- * Deal with the SMB1 semantics of sending a pathname with a
- * wildcard as the terminal component for a SMB1search or
- * trans2 findfirst.
- */
-
-NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx,
-                                          connection_struct *conn,
-                                          char *name_in,
-                                          uint32_t ucf_flags,
-                                          struct files_struct **_dirfsp,
-                                          struct smb_filename **_smb_fname_out,
-                                          char **_mask_out)
-{
-       NTSTATUS status;
-       char *p = NULL;
-       char *mask = NULL;
-       struct smb_filename *smb_fname = NULL;
-       NTTIME twrp = 0;
-
-       *_smb_fname_out = NULL;
-       *_dirfsp = NULL;
-       *_mask_out = NULL;
-
-       DBG_DEBUG("name_in: %s\n", name_in);
-
-       if (ucf_flags & UCF_GMT_PATHNAME) {
-               extract_snapshot_token(name_in, &twrp);
-               ucf_flags &= ~UCF_GMT_PATHNAME;
-       }
-
-       /* Get the original lcomp. */
-       mask = get_original_lcomp(ctx,
-                                 conn,
-                                 name_in,
-                                 ucf_flags);
-       if (mask == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       if (mask[0] == '\0') {
-               /* Windows and OS/2 systems treat search on the root as * */
-               TALLOC_FREE(mask);
-               mask = talloc_strdup(ctx, "*");
-               if (mask == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-       }
-
-       DBG_DEBUG("mask = %s\n", mask);
-
-       /*
-        * Remove the terminal component so
-        * filename_convert_dirfsp never sees the mask.
-        */
-       p = strrchr_m(name_in,'/');
-       if (p == NULL) {
-               /* filename_convert_dirfsp handles a '\0' name. */
-               name_in[0] = '\0';
-       } else {
-               *p = '\0';
-       }
-
-       DBG_DEBUG("For filename_convert_dirfsp: name_in = %s\n",
-               name_in);
-
-       /* Convert the parent directory path. */
-       status = filename_convert_dirfsp(ctx,
-                                        conn,
-                                        name_in,
-                                        ucf_flags,
-                                        twrp,
-                                        _dirfsp,
-                                        &smb_fname);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("filename_convert error for %s: %s\n",
-                       name_in,
-                       nt_errstr(status));
-       }
-
-       *_smb_fname_out = talloc_move(ctx, &smb_fname);
-       *_mask_out = talloc_move(ctx, &mask);
-
-       return status;
-}
-
 /*
  * Get the correct capitalized stream name hanging off
  * base_fsp. Equivalent of get_real_filename(), but for streams.
index 0200c39778d2977262cf42fb79b1fb5bd8ff2807..ad8f52efbff2387604857cf320408880f3702441 100644 (file)
@@ -343,13 +343,6 @@ char *get_original_lcomp(TALLOC_CTX *ctx,
                        connection_struct *conn,
                        const char *filename_in,
                        uint32_t ucf_flags);
-NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx,
-                                          connection_struct *conn,
-                                          char *name_in,
-                                          uint32_t ucf_flags,
-                                          struct files_struct **_dirfsp,
-                                          struct smb_filename **_smb_fname_out,
-                                          char **_mask_out);
 NTSTATUS get_real_filename_at(struct files_struct *dirfsp,
                              const char *name,
                              TALLOC_CTX *mem_ctx,
index 5092aa519299828264419914960b028370e80ae7..bdd842c504fd3c6b553a668902114dc6f737891a 100644 (file)
@@ -176,3 +176,86 @@ ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags)
 
        return result;
 }
+
+/*
+ * Deal with the SMB1 semantics of sending a pathname with a
+ * wildcard as the terminal component for a SMB1search or
+ * trans2 findfirst.
+ */
+
+NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx,
+                                          connection_struct *conn,
+                                          char *name_in,
+                                          uint32_t ucf_flags,
+                                          struct files_struct **_dirfsp,
+                                          struct smb_filename **_smb_fname_out,
+                                          char **_mask_out)
+{
+       NTSTATUS status;
+       char *p = NULL;
+       char *mask = NULL;
+       struct smb_filename *smb_fname = NULL;
+       NTTIME twrp = 0;
+
+       *_smb_fname_out = NULL;
+       *_dirfsp = NULL;
+       *_mask_out = NULL;
+
+       DBG_DEBUG("name_in: %s\n", name_in);
+
+       if (ucf_flags & UCF_GMT_PATHNAME) {
+               extract_snapshot_token(name_in, &twrp);
+               ucf_flags &= ~UCF_GMT_PATHNAME;
+       }
+
+       /* Get the original lcomp. */
+       mask = get_original_lcomp(ctx, conn, name_in, ucf_flags);
+       if (mask == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (mask[0] == '\0') {
+               /* Windows and OS/2 systems treat search on the root as * */
+               TALLOC_FREE(mask);
+               mask = talloc_strdup(ctx, "*");
+               if (mask == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+
+       DBG_DEBUG("mask = %s\n", mask);
+
+       /*
+        * Remove the terminal component so
+        * filename_convert_dirfsp never sees the mask.
+        */
+       p = strrchr_m(name_in, '/');
+       if (p == NULL) {
+               /* filename_convert_dirfsp handles a '\0' name. */
+               name_in[0] = '\0';
+       } else {
+               *p = '\0';
+       }
+
+       DBG_DEBUG("For filename_convert_dirfsp: name_in = %s\n", name_in);
+
+       /* Convert the parent directory path. */
+       status = filename_convert_dirfsp(ctx,
+                                        conn,
+                                        name_in,
+                                        ucf_flags,
+                                        twrp,
+                                        _dirfsp,
+                                        &smb_fname);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_DEBUG("filename_convert error for %s: %s\n",
+                         name_in,
+                         nt_errstr(status));
+       }
+
+       *_smb_fname_out = talloc_move(ctx, &smb_fname);
+       *_mask_out = talloc_move(ctx, &mask);
+
+       return status;
+}
index 6f791e2ff801868381c392e474c3ed821c47de77..539648e28cad9e6e49c0d42e89f3d857eba12c9c 100644 (file)
@@ -35,5 +35,12 @@ struct files_struct *fcb_or_dos_open(
        uint32_t private_flags);
 bool send_keepalive(int client);
 ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
+NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx,
+                                          connection_struct *conn,
+                                          char *name_in,
+                                          uint32_t ucf_flags,
+                                          struct files_struct **_dirfsp,
+                                          struct smb_filename **_smb_fname_out,
+                                          char **_mask_out);
 
 #endif