]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move smb_set_file_unix_link() to smb1_trans2.c
authorVolker Lendecke <vl@samba.org>
Thu, 29 Dec 2022 09:44:33 +0000 (10:44 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 4 Jan 2023 08:54:32 +0000 (08:54 +0000)
Most of this is direct cut&paste without reformatting.

Don't pass SMB_SET_FILE_UNIX_LINK through smbd_do_setfilepathinfo(),
directly handle it in call_trans2setpathinfo() where we know we have a
path.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/smb1_trans2.c
source3/smbd/smb2_trans2.c

index 2cd855c0455cf6cf038c25bd28b84b662c453b7d..03eb0f18c37ad563aec5cb31e0992ad051ae2db6 100644 (file)
@@ -3045,6 +3045,81 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
        return close_file_free(req, &fsp, NORMAL_CLOSE);
 }
 
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_LINK (create a UNIX symlink).
+****************************************************************************/
+
+static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
+                                      struct smb_request *req,
+                                      const char *pdata,
+                                      int total_data,
+                                      struct smb_filename *new_smb_fname)
+{
+       char *link_target = NULL;
+       struct smb_filename target_fname;
+       TALLOC_CTX *ctx = talloc_tos();
+       NTSTATUS status;
+       int ret;
+       struct smb_filename *parent_fname = NULL;
+       struct smb_filename *base_name = NULL;
+
+       if (!CAN_WRITE(conn)) {
+               return NT_STATUS_DOS(ERRSRV, ERRaccess);
+       }
+
+       /* Set a symbolic link. */
+       /* Don't allow this if follow links is false. */
+
+       if (total_data == 0) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (!lp_follow_symlinks(SNUM(conn))) {
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
+       srvstr_pull_talloc(ctx, pdata, req->flags2, &link_target, pdata,
+                   total_data, STR_TERMINATE);
+
+       if (!link_target) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       target_fname = (struct smb_filename) {
+               .base_name = link_target,
+       };
+
+       /* Removes @GMT tokens if any */
+       status = canonicalize_snapshot_path(&target_fname, UCF_GMT_PATHNAME, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
+                       new_smb_fname->base_name, link_target ));
+
+       status = parent_pathref(talloc_tos(),
+                               conn->cwd_fsp,
+                               new_smb_fname,
+                               &parent_fname,
+                               &base_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       ret = SMB_VFS_SYMLINKAT(conn,
+                       &target_fname,
+                       parent_fname->fsp,
+                       base_name);
+       if (ret != 0) {
+               TALLOC_FREE(parent_fname);
+               return map_nt_error_from_unix(errno);
+       }
+
+       TALLOC_FREE(parent_fname);
+       return NT_STATUS_OK;
+}
+
 static void call_trans2setpathinfo(
        connection_struct *conn,
        struct smb_request *req,
@@ -3163,6 +3238,11 @@ static void call_trans2setpathinfo(
                status = smb_posix_unlink(
                        conn, req, *ppdata, total_data, smb_fname);
                break;
+
+       case SMB_SET_FILE_UNIX_LINK:
+               status = smb_set_file_unix_link(
+                       conn, req, *ppdata, total_data, smb_fname);
+               break;
        }
 
        if (info_level_handled) {
@@ -3196,7 +3276,6 @@ static void call_trans2setpathinfo(
         * These info levels do not require an existing object.
         */
        switch (info_level) {
-       case SMB_SET_FILE_UNIX_LINK:
        case SMB_SET_FILE_UNIX_BASIC:
        case SMB_SET_FILE_UNIX_INFO2:
                require_existing_object = false;
index e057da1885a2b4258f35bebc15029546b9b69af3..e6647a06d39636da408b32287902096e8846d459 100644 (file)
@@ -4946,77 +4946,6 @@ static NTSTATUS smb_file_mode_information(connection_struct *conn,
        return NT_STATUS_OK;
 }
 
-/****************************************************************************
- Deal with SMB_SET_FILE_UNIX_LINK (create a UNIX symlink).
-****************************************************************************/
-
-static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
-                                      struct smb_request *req,
-                                      const char *pdata,
-                                      int total_data,
-                                      struct smb_filename *new_smb_fname)
-{
-       char *link_target = NULL;
-       struct smb_filename target_fname;
-       TALLOC_CTX *ctx = talloc_tos();
-       NTSTATUS status;
-       int ret;
-       struct smb_filename *parent_fname = NULL;
-       struct smb_filename *base_name = NULL;
-
-       /* Set a symbolic link. */
-       /* Don't allow this if follow links is false. */
-
-       if (total_data == 0) {
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       if (!lp_follow_symlinks(SNUM(conn))) {
-               return NT_STATUS_ACCESS_DENIED;
-       }
-
-       srvstr_pull_talloc(ctx, pdata, req->flags2, &link_target, pdata,
-                   total_data, STR_TERMINATE);
-
-       if (!link_target) {
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       target_fname = (struct smb_filename) {
-               .base_name = link_target,
-       };
-
-       /* Removes @GMT tokens if any */
-       status = canonicalize_snapshot_path(&target_fname, UCF_GMT_PATHNAME, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
-                       new_smb_fname->base_name, link_target ));
-
-       status = parent_pathref(talloc_tos(),
-                               conn->cwd_fsp,
-                               new_smb_fname,
-                               &parent_fname,
-                               &base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       ret = SMB_VFS_SYMLINKAT(conn,
-                       &target_fname,
-                       parent_fname->fsp,
-                       base_name);
-       if (ret != 0) {
-               TALLOC_FREE(parent_fname);
-               return map_nt_error_from_unix(errno);
-       }
-
-       TALLOC_FREE(parent_fname);
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
 ****************************************************************************/
@@ -6361,17 +6290,6 @@ static NTSTATUS smbd_do_posix_setfilepathinfo(struct connection_struct *conn,
                        break;
                }
 
-               case SMB_SET_FILE_UNIX_LINK:
-               {
-                       if (smb_fname == NULL) {
-                               /* We must have a pathname for this. */
-                               return NT_STATUS_INVALID_LEVEL;
-                       }
-                       status = smb_set_file_unix_link(conn, req, pdata,
-                                                       total_data, smb_fname);
-                       break;
-               }
-
                case SMB_SET_FILE_UNIX_HLINK:
                {
                        if (smb_fname == NULL) {