]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Convert store_smb2_posix_info() to use an existing blob
authorVolker Lendecke <vl@samba.org>
Thu, 1 Sep 2022 12:49:33 +0000 (14:49 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 2 Sep 2022 13:31:38 +0000 (13:31 +0000)
Less malloc

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

index 4c92913a6daf31df1e265f58dbecf7131a5dc9c7..4842ff8bb641722de09e8102d73e40707532dcdd 100644 (file)
@@ -1266,10 +1266,12 @@ ssize_t smb2_posix_cc_info(
        const struct dom_sid *group,
        uint8_t *buf,
        size_t buflen);
-DATA_BLOB store_smb2_posix_info(TALLOC_CTX *mem_ctx,
-                               connection_struct *conn,
-                               const SMB_STRUCT_STAT *psbuf,
-                               uint32_t reparse_tag,
-                               uint32_t dos_attributes);
+ssize_t store_smb2_posix_info(
+       connection_struct *conn,
+       const SMB_STRUCT_STAT *psbuf,
+       uint32_t reparse_tag,
+       uint32_t dos_attributes,
+       uint8_t *buf,
+       size_t buflen);
 
 #endif /* _SMBD_PROTO_H_ */
index 54b5e87845d799111b9fad78623f3d72b24a7509..6f7f106726f91ae7dd19675da651483067ec4478 100644 (file)
@@ -84,14 +84,15 @@ ssize_t smb2_posix_cc_info(
 /*
  * SMB2 POSIX info level.
  */
-DATA_BLOB store_smb2_posix_info(TALLOC_CTX *mem_ctx,
-                               connection_struct *conn,
-                               const SMB_STRUCT_STAT *psbuf,
-                               uint32_t reparse_tag,
-                               uint32_t dos_attributes)
+ssize_t store_smb2_posix_info(
+       connection_struct *conn,
+       const SMB_STRUCT_STAT *psbuf,
+       uint32_t reparse_tag,
+       uint32_t dos_attributes,
+       uint8_t *buf,
+       size_t buflen)
 {
        uint64_t file_id = SMB_VFS_FS_FILE_ID(conn, psbuf);
-       DATA_BLOB ret_blob = data_blob_null;
        struct dom_sid owner = { .sid_rev_num = 0, };
        struct dom_sid group = { .sid_rev_num = 0, };
        ssize_t cc_len;
@@ -103,66 +104,59 @@ DATA_BLOB store_smb2_posix_info(TALLOC_CTX *mem_ctx,
                conn, reparse_tag, psbuf, &owner, &group, NULL, 0);
 
        if (cc_len == -1) {
-               return data_blob_null;
+               return -1;
        }
 
        if (cc_len + 68 < 68) {
-               return data_blob_null;
+               return -1;
        }
 
-       ret_blob = data_blob_talloc(mem_ctx,
-                               NULL,
-                               cc_len + 68);
-       if (ret_blob.data == NULL) {
-               return data_blob_null;
+       if (cc_len + 68 < buflen) {
+               return cc_len + 68;
        }
 
        /* Timestamps. */
 
        /* Birth (creation) time. */
        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,
-                              (char *)ret_blob.data+0,
+                              (char *)buf+0,
                               psbuf->st_ex_btime);
        /* Access time. */
        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,
-                              (char *)ret_blob.data+8,
+                              (char *)buf+8,
                               psbuf->st_ex_atime);
        /* Last write time. */
        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,
-                              (char *)ret_blob.data+16,
+                              (char *)buf+16,
                               psbuf->st_ex_mtime);
        /* Change time. */
        put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,
-                              (char *)ret_blob.data+24,
+                              (char *)buf+24,
                               psbuf->st_ex_ctime);
 
        /* File size 64 Bit */
-       SOFF_T(ret_blob.data,32, get_file_size_stat(psbuf));
+       SOFF_T(buf,32, get_file_size_stat(psbuf));
 
        /* Number of bytes used on disk - 64 Bit */
-       SOFF_T(ret_blob.data,40,SMB_VFS_GET_ALLOC_SIZE(conn,NULL,psbuf));
+       SOFF_T(buf,40,SMB_VFS_GET_ALLOC_SIZE(conn,NULL,psbuf));
 
        /* DOS attributes */
        if (S_ISREG(psbuf->st_ex_mode)) {
-               PUSH_LE_U32(ret_blob.data, 48, dos_attributes);
+               PUSH_LE_U32(buf, 48, dos_attributes);
        } else if (S_ISDIR(psbuf->st_ex_mode)) {
-               PUSH_LE_U32(ret_blob.data,
-                           48,
-                           dos_attributes|FILE_ATTRIBUTE_DIRECTORY);
+               PUSH_LE_U32(buf, 48, dos_attributes|FILE_ATTRIBUTE_DIRECTORY);
        } else {
                /*
                 * All non-directory or regular files are reported
                 * as reparse points. Client may or may not be able
                 * to access these.
                 */
-               PUSH_LE_U32(ret_blob.data,
-                           48,
-                           FILE_ATTRIBUTE_REPARSE_POINT);
+               PUSH_LE_U32(buf, 48, FILE_ATTRIBUTE_REPARSE_POINT);
        }
 
        /* Add the inode and dev (16 bytes). */
-       PUSH_LE_U64(ret_blob.data, 52, file_id);
-       PUSH_LE_U64(ret_blob.data, 60, psbuf->st_ex_dev);
+       PUSH_LE_U64(buf, 52, file_id);
+       PUSH_LE_U64(buf, 60, psbuf->st_ex_dev);
 
        /*
         * Append a POSIX create context (variable bytes).
@@ -173,8 +167,8 @@ DATA_BLOB store_smb2_posix_info(TALLOC_CTX *mem_ctx,
                psbuf,
                &owner,
                &group,
-               ret_blob.data + 68,
+               buf + 68,
                cc_len);
 
-       return ret_blob;
+       return cc_len + 68;
 }