]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move SMB_QUERY_FILE_UNIX_LINK to smb1_trans2.c
authorVolker Lendecke <vl@samba.org>
Mon, 2 Jan 2023 08:47:05 +0000 (09:47 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 4 Jan 2023 08:54:32 +0000 (08:54 +0000)
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 538f60aeb9f8e31b1ac5e81ac71b9249c50af164..cadf223ed57dc6c66150c1a32fceb997453a3693 100644 (file)
@@ -2486,6 +2486,82 @@ static NTSTATUS smb_q_posix_acl(
 #endif
 }
 
+static NTSTATUS smb_q_posix_symlink(
+       struct connection_struct *conn,
+       struct smb_request *req,
+       struct smb_filename *smb_fname,
+       char **ppdata,
+       int *ptotal_data)
+{
+       char buffer[PATH_MAX+1];
+       size_t needed, len;
+       int link_len;
+       char *pdata = NULL;
+       struct smb_filename *parent_fname = NULL;
+       struct smb_filename *base_name = NULL;
+       NTSTATUS status;
+
+       DBG_DEBUG("SMB_QUERY_FILE_UNIX_LINK for file %s\n",
+                 smb_fname_str_dbg(smb_fname));
+
+       if (!S_ISLNK(smb_fname->st.st_ex_mode)) {
+               return NT_STATUS_DOS(ERRSRV, ERRbadlink);
+       }
+
+       status = parent_pathref(
+               talloc_tos(),
+               conn->cwd_fsp,
+               smb_fname,
+               &parent_fname,
+               &base_name);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_DEBUG("parent_pathref failed: %s\n", nt_errstr(status));
+               return status;
+       }
+
+       link_len = SMB_VFS_READLINKAT(
+               conn,
+               parent_fname->fsp,
+               base_name,
+               buffer,
+               sizeof(buffer)-1);
+       TALLOC_FREE(parent_fname);
+
+       if (link_len == -1) {
+               status = map_nt_error_from_unix(errno);
+               DBG_DEBUG("READLINKAT failed: %s\n", nt_errstr(status));
+               return status;
+       }
+       if (link_len >= sizeof(buffer)) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+       buffer[link_len] = 0;
+
+       needed = (link_len+1)*2;
+
+       pdata = SMB_REALLOC(*ppdata, needed);
+       if (pdata == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       *ppdata = pdata;
+
+       status = srvstr_push(
+               pdata,
+               req->flags2,
+               pdata,
+               buffer,
+               needed,
+               STR_TERMINATE,
+               &len);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       *ptotal_data = len;
+
+       return NT_STATUS_OK;
+}
+
 static void call_trans2qpathinfo(
        connection_struct *conn,
        struct smb_request *req,
@@ -2705,6 +2781,16 @@ static void call_trans2qpathinfo(
                        smb_fname->fsp,
                        ppdata,
                        &total_data);
+               break;
+
+       case SMB_QUERY_FILE_UNIX_LINK:
+               status = smb_q_posix_symlink(
+                       conn,
+                       req,
+                       smb_fname,
+                       ppdata,
+                       &total_data);
+               break;
        }
 
        if (info_level_handled) {
index 7b89c1dfe81f1bf8aa99da247ab592f61240706c..85c8aaccaca05312456e618a1a8b3126500c2672 100644 (file)
@@ -3099,73 +3099,6 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams,
        return NT_STATUS_OK;
 }
 
-static NTSTATUS smb_unix_read_symlink(connection_struct *conn,
-                               struct smb_request *req,
-                               struct smb_filename *smb_fname,
-                               char *pdata,
-                               unsigned int data_size_in,
-                               unsigned int *pdata_size_out)
-{
-       NTSTATUS status;
-       size_t len = 0;
-       int link_len = 0;
-       struct smb_filename *parent_fname = NULL;
-       struct smb_filename *base_name = NULL;
-
-       char *buffer = talloc_array(talloc_tos(), char, PATH_MAX+1);
-
-       if (!buffer) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       DBG_DEBUG("SMB_QUERY_FILE_UNIX_LINK for file %s\n",
-               smb_fname_str_dbg(smb_fname));
-
-       if(!S_ISLNK(smb_fname->st.st_ex_mode)) {
-               TALLOC_FREE(buffer);
-               return NT_STATUS_DOS(ERRSRV, ERRbadlink);
-       }
-
-       status = parent_pathref(talloc_tos(),
-                               conn->cwd_fsp,
-                               smb_fname,
-                               &parent_fname,
-                               &base_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(buffer);
-               return status;
-       }
-
-       link_len = SMB_VFS_READLINKAT(conn,
-                               parent_fname->fsp,
-                               base_name,
-                               buffer,
-                               PATH_MAX);
-
-       TALLOC_FREE(parent_fname);
-
-       if (link_len == -1) {
-               TALLOC_FREE(buffer);
-               return map_nt_error_from_unix(errno);
-       }
-
-       buffer[link_len] = 0;
-       status = srvstr_push(pdata,
-                       req->flags2,
-                       pdata,
-                       buffer,
-                       data_size_in,
-                       STR_TERMINATE,
-                       &len);
-       TALLOC_FREE(buffer);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-       *pdata_size_out = len;
-
-       return NT_STATUS_OK;
-}
-
 NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                               TALLOC_CTX *mem_ctx,
                               struct smb_request *req,
@@ -3849,24 +3782,6 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
                        *fixed_portion = 8;
                        break;
 
-               /*
-                * CIFS UNIX Extensions.
-                */
-
-               case SMB_QUERY_FILE_UNIX_LINK:
-                       {
-                               status = smb_unix_read_symlink(conn,
-                                                       req,
-                                                       smb_fname,
-                                                       pdata,
-                                                       data_size,
-                                                       &data_size);
-                               if (!NT_STATUS_IS_OK(status)) {
-                                       return status;
-                               }
-                               break;
-                       }
-
                /*
                 * SMB2 UNIX Extensions.
                 */