libcli/smb: pass smbXcli_tcon to smb2cli_set_info*()
[Samba/gebeck_regimport.git] / libcli / smb / smb2cli_set_info.c
blobe33ba8367dba04cf40ca57f23252a20e78ef5b7e
1 /*
2 Unix SMB/CIFS implementation.
3 smb2 lib
4 Copyright (C) Stefan Metzmacher 2012
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "system/network.h"
22 #include "lib/util/tevent_ntstatus.h"
23 #include "smb_common.h"
24 #include "smbXcli_base.h"
26 struct smb2cli_set_info_state {
27 uint8_t fixed[0x20];
28 uint8_t dyn_pad[1];
31 static void smb2cli_set_info_done(struct tevent_req *subreq);
33 struct tevent_req *smb2cli_set_info_send(TALLOC_CTX *mem_ctx,
34 struct tevent_context *ev,
35 struct smbXcli_conn *conn,
36 uint32_t timeout_msec,
37 struct smbXcli_session *session,
38 struct smbXcli_tcon *tcon,
39 uint8_t in_info_type,
40 uint8_t in_file_info_class,
41 const DATA_BLOB *in_input_buffer,
42 uint32_t in_additional_info,
43 uint64_t in_fid_persistent,
44 uint64_t in_fid_volatile)
46 struct tevent_req *req, *subreq;
47 struct smb2cli_set_info_state *state;
48 uint8_t *fixed;
49 uint8_t *dyn;
50 size_t dyn_len;
51 uint16_t input_buffer_offset = 0;
52 uint32_t input_buffer_length = 0;
53 uint32_t tcon_id = 0;
55 req = tevent_req_create(mem_ctx, &state,
56 struct smb2cli_set_info_state);
57 if (req == NULL) {
58 return NULL;
61 if (in_input_buffer) {
62 input_buffer_offset = SMB2_HDR_BODY+0x20;
63 input_buffer_length = in_input_buffer->length;
66 fixed = state->fixed;
68 SSVAL(fixed, 0x00, 0x21);
69 SCVAL(fixed, 0x02, in_info_type);
70 SCVAL(fixed, 0x03, in_file_info_class);
71 SIVAL(fixed, 0x04, input_buffer_length);
72 SSVAL(fixed, 0x08, input_buffer_offset);
73 SSVAL(fixed, 0x0A, 0); /* reserved */
74 SIVAL(fixed, 0x0C, in_additional_info);
75 SBVAL(fixed, 0x10, in_fid_persistent);
76 SBVAL(fixed, 0x18, in_fid_volatile);
78 if (input_buffer_length > 0) {
79 dyn = in_input_buffer->data;
80 dyn_len = in_input_buffer->length;
81 } else {
82 dyn = state->dyn_pad;
83 dyn_len = sizeof(state->dyn_pad);
86 if (tcon) {
87 tcon_id = smb2cli_tcon_current_id(tcon);
90 subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_SETINFO,
91 0, 0, /* flags */
92 timeout_msec,
93 0xFEFF, /* pid */
94 tcon_id,
95 session,
96 state->fixed, sizeof(state->fixed),
97 dyn, dyn_len);
98 if (tevent_req_nomem(subreq, req)) {
99 return tevent_req_post(req, ev);
101 tevent_req_set_callback(subreq, smb2cli_set_info_done, req);
102 return req;
105 static void smb2cli_set_info_done(struct tevent_req *subreq)
107 struct tevent_req *req =
108 tevent_req_callback_data(subreq,
109 struct tevent_req);
110 NTSTATUS status;
111 static const struct smb2cli_req_expected_response expected[] = {
113 .status = NT_STATUS_OK,
114 .body_size = 0x02
118 status = smb2cli_req_recv(subreq, NULL, NULL,
119 expected, ARRAY_SIZE(expected));
120 if (tevent_req_nterror(req, status)) {
121 return;
124 tevent_req_done(req);
127 NTSTATUS smb2cli_set_info_recv(struct tevent_req *req)
129 NTSTATUS status;
131 if (tevent_req_is_nterror(req, &status)) {
132 tevent_req_received(req);
133 return status;
136 tevent_req_received(req);
137 return NT_STATUS_OK;
140 NTSTATUS smb2cli_set_info(struct smbXcli_conn *conn,
141 uint32_t timeout_msec,
142 struct smbXcli_session *session,
143 struct smbXcli_tcon *tcon,
144 uint8_t in_info_type,
145 uint8_t in_file_info_class,
146 const DATA_BLOB *in_input_buffer,
147 uint32_t in_additional_info,
148 uint64_t in_fid_persistent,
149 uint64_t in_fid_volatile)
151 TALLOC_CTX *frame = talloc_stackframe();
152 struct tevent_context *ev;
153 struct tevent_req *req;
154 NTSTATUS status = NT_STATUS_NO_MEMORY;
156 if (smbXcli_conn_has_async_calls(conn)) {
158 * Can't use sync call while an async call is in flight
160 status = NT_STATUS_INVALID_PARAMETER_MIX;
161 goto fail;
163 ev = tevent_context_init(frame);
164 if (ev == NULL) {
165 goto fail;
167 req = smb2cli_set_info_send(frame, ev,
168 conn, timeout_msec,
169 session, tcon,
170 in_info_type,
171 in_file_info_class,
172 in_input_buffer,
173 in_additional_info,
174 in_fid_persistent,
175 in_fid_volatile);
176 if (req == NULL) {
177 goto fail;
179 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
180 goto fail;
182 status = smb2cli_set_info_recv(req);
184 fail:
185 TALLOC_FREE(frame);
186 return status;