s3/aio_fork: fix build on irix
[Samba/id10ts.git] / libcli / smb / smb2cli_set_info.c
blob41fe83e211e6df5a759be3ae6a95633c5e1c5936
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;
54 req = tevent_req_create(mem_ctx, &state,
55 struct smb2cli_set_info_state);
56 if (req == NULL) {
57 return NULL;
60 if (in_input_buffer) {
61 input_buffer_offset = SMB2_HDR_BODY+0x20;
62 input_buffer_length = in_input_buffer->length;
65 fixed = state->fixed;
67 SSVAL(fixed, 0x00, 0x21);
68 SCVAL(fixed, 0x02, in_info_type);
69 SCVAL(fixed, 0x03, in_file_info_class);
70 SIVAL(fixed, 0x04, input_buffer_length);
71 SSVAL(fixed, 0x08, input_buffer_offset);
72 SSVAL(fixed, 0x0A, 0); /* reserved */
73 SIVAL(fixed, 0x0C, in_additional_info);
74 SBVAL(fixed, 0x10, in_fid_persistent);
75 SBVAL(fixed, 0x18, in_fid_volatile);
77 if (input_buffer_length > 0) {
78 dyn = in_input_buffer->data;
79 dyn_len = in_input_buffer->length;
80 } else {
81 dyn = state->dyn_pad;
82 dyn_len = sizeof(state->dyn_pad);
85 subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_SETINFO,
86 0, 0, /* flags */
87 timeout_msec,
88 tcon,
89 session,
90 state->fixed, sizeof(state->fixed),
91 dyn, dyn_len);
92 if (tevent_req_nomem(subreq, req)) {
93 return tevent_req_post(req, ev);
95 tevent_req_set_callback(subreq, smb2cli_set_info_done, req);
96 return req;
99 static void smb2cli_set_info_done(struct tevent_req *subreq)
101 struct tevent_req *req =
102 tevent_req_callback_data(subreq,
103 struct tevent_req);
104 NTSTATUS status;
105 static const struct smb2cli_req_expected_response expected[] = {
107 .status = NT_STATUS_OK,
108 .body_size = 0x02
112 status = smb2cli_req_recv(subreq, NULL, NULL,
113 expected, ARRAY_SIZE(expected));
114 if (tevent_req_nterror(req, status)) {
115 return;
118 tevent_req_done(req);
121 NTSTATUS smb2cli_set_info_recv(struct tevent_req *req)
123 NTSTATUS status;
125 if (tevent_req_is_nterror(req, &status)) {
126 tevent_req_received(req);
127 return status;
130 tevent_req_received(req);
131 return NT_STATUS_OK;
134 NTSTATUS smb2cli_set_info(struct smbXcli_conn *conn,
135 uint32_t timeout_msec,
136 struct smbXcli_session *session,
137 struct smbXcli_tcon *tcon,
138 uint8_t in_info_type,
139 uint8_t in_file_info_class,
140 const DATA_BLOB *in_input_buffer,
141 uint32_t in_additional_info,
142 uint64_t in_fid_persistent,
143 uint64_t in_fid_volatile)
145 TALLOC_CTX *frame = talloc_stackframe();
146 struct tevent_context *ev;
147 struct tevent_req *req;
148 NTSTATUS status = NT_STATUS_NO_MEMORY;
150 if (smbXcli_conn_has_async_calls(conn)) {
152 * Can't use sync call while an async call is in flight
154 status = NT_STATUS_INVALID_PARAMETER_MIX;
155 goto fail;
157 ev = tevent_context_init(frame);
158 if (ev == NULL) {
159 goto fail;
161 req = smb2cli_set_info_send(frame, ev,
162 conn, timeout_msec,
163 session, tcon,
164 in_info_type,
165 in_file_info_class,
166 in_input_buffer,
167 in_additional_info,
168 in_fid_persistent,
169 in_fid_volatile);
170 if (req == NULL) {
171 goto fail;
173 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
174 goto fail;
176 status = smb2cli_set_info_recv(req);
178 fail:
179 TALLOC_FREE(frame);
180 return status;