From: Ralph Boehme Date: Fri, 11 Oct 2024 13:30:46 +0000 (+0200) Subject: smbd: split out smb_check_file_disposition_info() X-Git-Tag: tdb-1.4.13~743 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67f560133744eaee9793562f0b48a67ea4221243;p=thirdparty%2Fsamba.git smbd: split out smb_check_file_disposition_info() BUG: https://bugzilla.samba.org/show_bug.cgi?id=13458 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15608 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 8ff937a8e4f..8437b4d140e 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1043,6 +1043,10 @@ char *store_file_unix_basic_info2(connection_struct *conn, char *pdata, files_struct *fsp, const SMB_STRUCT_STAT *psbuf); +NTSTATUS smb_check_file_disposition_info(struct files_struct *fsp, + const char *data, + int total_data, + bool *_delete_on_close); NTSTATUS smb_set_file_disposition_info(connection_struct *conn, const char *pdata, int total_data, diff --git a/source3/smbd/smb2_trans2.c b/source3/smbd/smb2_trans2.c index 885776a72be..7e5dd9efe1d 100644 --- a/source3/smbd/smb2_trans2.c +++ b/source3/smbd/smb2_trans2.c @@ -4170,15 +4170,14 @@ static NTSTATUS smb_set_file_full_ea_info(connection_struct *conn, Deal with SMB_SET_FILE_DISPOSITION_INFO. ****************************************************************************/ -NTSTATUS smb_set_file_disposition_info(connection_struct *conn, - const char *pdata, - int total_data, - files_struct *fsp, - struct smb_filename *smb_fname) +NTSTATUS smb_check_file_disposition_info(struct files_struct *fsp, + const char *data, + int total_data, + bool *_delete_on_close) { - NTSTATUS status = NT_STATUS_OK; bool delete_on_close; uint32_t dosmode = 0; + NTSTATUS status; if (total_data < 1) { return NT_STATUS_INVALID_PARAMETER; @@ -4188,20 +4187,43 @@ NTSTATUS smb_set_file_disposition_info(connection_struct *conn, return NT_STATUS_INVALID_HANDLE; } - delete_on_close = (CVAL(pdata,0) ? True : False); + delete_on_close = (PULL_LE_U8(data, 0) ? true : false); + *_delete_on_close = delete_on_close; + dosmode = fdos_mode(fsp); - DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, " - "delete_on_close = %u\n", - smb_fname_str_dbg(smb_fname), - (unsigned int)dosmode, - (unsigned int)delete_on_close )); + DBG_DEBUG("file [%s] dosmode = %u, delete_on_close = %s\n", + fsp_str_dbg(fsp), + (unsigned int)dosmode, + delete_on_close ? "yes" : "no"); - if (delete_on_close) { - status = can_set_delete_on_close(fsp, dosmode); - if (!NT_STATUS_IS_OK(status)) { - return status; - } + if (!delete_on_close) { + return NT_STATUS_OK; + } + + status = can_set_delete_on_close(fsp, dosmode); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + return NT_STATUS_OK; +} + +NTSTATUS smb_set_file_disposition_info(connection_struct *conn, + const char *pdata, + int total_data, + files_struct *fsp, + struct smb_filename *smb_fname) +{ + NTSTATUS status; + bool delete_on_close; + + status = smb_check_file_disposition_info(fsp, + pdata, + total_data, + &delete_on_close); + if (!NT_STATUS_IS_OK(status)) { + return status; } /* The set is across all open files on this dev/inode pair. */