]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: smbd: Factor out the SMB1 UNIX extensions read symlink code into a function.
authorJeremy Allison <jra@samba.org>
Wed, 10 Feb 2021 21:34:42 +0000 (13:34 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 13 Feb 2021 00:17:31 +0000 (00:17 +0000)
Will make it much easier to convert to a dirfsp later.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
source3/smbd/trans2.c

index 92856163ac524834e417ed54ad77fb70881a480f..7ac6204f9c4ecc290bae5278230ab44c5655b9e2 100644 (file)
@@ -4947,6 +4947,58 @@ 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;
+       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);
+       }
+
+       link_len = SMB_VFS_READLINKAT(conn,
+                               conn->cwd_fsp,
+                               smb_fname,
+                               buffer,
+                               PATH_MAX);
+
+       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;
+}
+
 #if defined(HAVE_POSIX_ACLS)
 static NTSTATUS smb_query_posix_acl(connection_struct *conn,
                                struct smb_request *req,
@@ -5875,41 +5927,15 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
 
                case SMB_QUERY_FILE_UNIX_LINK:
                        {
-                               int link_len = 0;
-                               char *buffer = talloc_array(mem_ctx, char, PATH_MAX+1);
-
-                               if (!buffer) {
-                                       return NT_STATUS_NO_MEMORY;
-                               }
-
-                               DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
-#ifdef S_ISLNK
-                               if(!S_ISLNK(psbuf->st_ex_mode)) {
-                                       return NT_STATUS_DOS(ERRSRV, ERRbadlink);
-                               }
-#else
-                               return NT_STATUS_DOS(ERRDOS, ERRbadlink);
-#endif
-                               link_len = SMB_VFS_READLINKAT(conn,
-                                                       conn->cwd_fsp,
+                               status = smb_unix_read_symlink(conn,
+                                                       req,
                                                        smb_fname,
-                                                       buffer,
-                                                       PATH_MAX);
-
-                               if (link_len == -1) {
-                                       return map_nt_error_from_unix(errno);
-                               }
-                               buffer[link_len] = 0;
-                               status = srvstr_push(dstart, flags2,
-                                                 pdata, buffer,
-                                                 PTR_DIFF(dend, pdata),
-                                                 STR_TERMINATE, &len);
+                                                       pdata,
+                                                       data_size,
+                                                       &data_size);
                                if (!NT_STATUS_IS_OK(status)) {
                                        return status;
                                }
-                               pdata += len;
-                               data_size = PTR_DIFF(pdata,(*ppdata));
-
                                break;
                        }