summaryrefslogtreecommitdiff
path: root/source3/libsmb/cli_smb2_fnum.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2016-12-21 13:55:50 -0800
committerVolker Lendecke <vl@samba.org>2017-01-04 12:22:12 +0100
commite0f1ed9f450851bf5b7fec84577b50047309db3f (patch)
treea1d5fdb4b7b4047f4805a5b6e350bc5025c0f21c /source3/libsmb/cli_smb2_fnum.c
parent98bcdca632c7e508af2ecb3e8d6e005d04523c83 (diff)
downloadsamba-e0f1ed9f450851bf5b7fec84577b50047309db3f.tar.gz
s3: libsmb: Add cli_smb2_ftruncate(), plumb into cli_ftruncate().
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12479 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Uri Simchoni <uri@samba.org>
Diffstat (limited to 'source3/libsmb/cli_smb2_fnum.c')
-rw-r--r--source3/libsmb/cli_smb2_fnum.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 266f2d32fd7..848e077162c 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -3574,3 +3574,68 @@ NTSTATUS cli_smb2_shadow_copy_data(TALLOC_CTX *mem_ctx,
TALLOC_FREE(frame);
return status;
}
+
+/***************************************************************
+ Wrapper that allows SMB2 to truncate a file.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_ftruncate(struct cli_state *cli,
+ uint16_t fnum,
+ uint64_t newsize)
+{
+ NTSTATUS status;
+ DATA_BLOB inbuf = data_blob_null;
+ struct smb2_hnd *ph = NULL;
+ TALLOC_CTX *frame = talloc_stackframe();
+
+ if (smbXcli_conn_has_async_calls(cli->conn)) {
+ /*
+ * Can't use sync call while an async call is in flight
+ */
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
+ if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
+ status = map_fnum_to_smb2_handle(cli,
+ fnum,
+ &ph);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
+
+ inbuf = data_blob_talloc_zero(frame, 8);
+ if (inbuf.data == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ SBVAL(inbuf.data, 0, newsize);
+
+ /* setinfo on the handle with info_type SMB2_SETINFO_FILE (1),
+ level 20 (SMB_FILE_END_OF_FILE_INFORMATION - 1000). */
+
+ status = smb2cli_set_info(cli->conn,
+ cli->timeout,
+ cli->smb2.session,
+ cli->smb2.tcon,
+ 1, /* in_info_type */
+ /* in_file_info_class */
+ SMB_FILE_END_OF_FILE_INFORMATION - 1000,
+ &inbuf, /* in_input_buffer */
+ 0, /* in_additional_info */
+ ph->fid_persistent,
+ ph->fid_volatile);
+
+ fail:
+
+ cli->raw_status = status;
+
+ TALLOC_FREE(frame);
+ return status;
+}