auth/credentials: don't ignore "client use kerberos" and --use-kerberos for machine...
[Samba.git] / source4 / libcli / smb2 / getinfo.c
blob5ffb988267a2fb78ac8aa1839be3e42791f7653d
1 /*
2 Unix SMB/CIFS implementation.
4 SMB2 client getinfo calls
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/raw/raw_proto.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
29 send a getinfo request
31 struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
33 struct smb2_request *req;
34 NTSTATUS status;
35 size_t max_payload;
37 req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, true,
38 io->in.input_buffer.length);
39 if (req == NULL) return NULL;
41 SCVAL(req->out.body, 0x02, io->in.info_type);
42 SCVAL(req->out.body, 0x03, io->in.info_class);
43 SIVAL(req->out.body, 0x04, io->in.output_buffer_length);
45 * uint16_t input_buffer_offset
46 * uint16_t reserved
47 * uint32_t input_buffer_length
49 * We use smb2_push_o32s32_blob() which would
50 * expect uint32_t offset, uint32_t length.
52 * Everything is little endian, we can just
53 * overwrite the reserved field later.
55 SIVAL(req->out.body, 0x10, io->in.additional_information);
56 SIVAL(req->out.body, 0x14, io->in.getinfo_flags);
57 smb2_push_handle(req->out.body+0x18, &io->in.file.handle);
59 /* this blob is used for quota queries */
60 status = smb2_push_o32s32_blob(&req->out, 0x08, io->in.input_buffer);
61 if (!NT_STATUS_IS_OK(status)) {
62 talloc_free(req);
63 return NULL;
65 SSVAL(req->out.body, 0x0C, io->in.reserved);
67 max_payload = MAX(io->in.output_buffer_length, io->in.input_buffer.length);
68 req->credit_charge = (MAX(max_payload, 1) - 1)/ 65536 + 1;
70 smb2_transport_send(req);
72 return req;
77 recv a getinfo reply
79 NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
80 struct smb2_getinfo *io)
82 NTSTATUS status;
84 if (!smb2_request_receive(req) ||
85 smb2_request_is_error(req)) {
86 return smb2_request_destroy(req);
89 SMB2_CHECK_PACKET_RECV(req, 0x08, true);
91 status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
92 if (!NT_STATUS_IS_OK(status)) {
93 return status;
96 return smb2_request_destroy(req);
100 sync getinfo request
102 NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
103 struct smb2_getinfo *io)
105 struct smb2_request *req = smb2_getinfo_send(tree, io);
106 return smb2_getinfo_recv(req, mem_ctx, io);
111 map a generic info level to a SMB2 info level
113 uint16_t smb2_getinfo_map_level(uint16_t level, uint8_t info_class)
115 if (info_class == SMB2_0_INFO_FILE &&
116 level == RAW_FILEINFO_SEC_DESC) {
117 return SMB2_0_INFO_SECURITY;
119 if ((level & 0xFF) == info_class) {
120 return level;
121 } else if (level > 1000) {
122 return ((level-1000)<<8) | info_class;
124 DEBUG(0,("Unable to map SMB2 info level 0x%04x of class %d\n",
125 level, info_class));
126 return 0;
130 level specific getinfo call - async send
132 struct smb2_request *smb2_getinfo_file_send(struct smb2_tree *tree, union smb_fileinfo *io)
134 struct smb2_getinfo b;
135 uint16_t smb2_level = smb2_getinfo_map_level(
136 io->generic.level, SMB2_0_INFO_FILE);
138 if (smb2_level == 0) {
139 return NULL;
142 ZERO_STRUCT(b);
143 b.in.info_type = smb2_level & 0xFF;
144 b.in.info_class = smb2_level >> 8;
145 b.in.output_buffer_length = 0x10000;
146 b.in.input_buffer = data_blob_null;
147 b.in.file.handle = io->generic.in.file.handle;
149 if (io->generic.level == RAW_FILEINFO_SEC_DESC) {
150 b.in.additional_information = io->query_secdesc.in.secinfo_flags;
152 if (io->generic.level == RAW_FILEINFO_SMB2_ALL_EAS) {
153 b.in.getinfo_flags = io->all_eas.in.continue_flags;
156 return smb2_getinfo_send(tree, &b);
160 recv a getinfo reply and parse the level info
162 NTSTATUS smb2_getinfo_file_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
163 union smb_fileinfo *io)
165 struct smb2_getinfo b;
166 NTSTATUS status;
168 status = smb2_getinfo_recv(req, mem_ctx, &b);
169 NT_STATUS_NOT_OK_RETURN(status);
171 status = smb_raw_fileinfo_passthru_parse(&b.out.blob, mem_ctx, io->generic.level, io);
172 data_blob_free(&b.out.blob);
174 return status;
178 level specific getinfo call
180 NTSTATUS smb2_getinfo_file(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
181 union smb_fileinfo *io)
183 struct smb2_request *req = smb2_getinfo_file_send(tree, io);
184 return smb2_getinfo_file_recv(req, mem_ctx, io);
189 level specific getinfo call - async send
191 struct smb2_request *smb2_getinfo_fs_send(struct smb2_tree *tree, union smb_fsinfo *io)
193 struct smb2_getinfo b;
194 uint16_t smb2_level = smb2_getinfo_map_level(
195 io->generic.level, SMB2_0_INFO_FILESYSTEM);
197 if (smb2_level == 0) {
198 return NULL;
201 ZERO_STRUCT(b);
202 b.in.output_buffer_length = 0x10000;
203 b.in.file.handle = io->generic.handle;
204 b.in.info_type = smb2_level & 0xFF;
205 b.in.info_class = smb2_level >> 8;
207 return smb2_getinfo_send(tree, &b);
211 recv a getinfo reply and parse the level info
213 NTSTATUS smb2_getinfo_fs_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
214 union smb_fsinfo *io)
216 struct smb2_getinfo b = {
217 .in = {0},
219 NTSTATUS status;
221 status = smb2_getinfo_recv(req, mem_ctx, &b);
222 NT_STATUS_NOT_OK_RETURN(status);
224 status = smb_raw_fsinfo_passthru_parse(b.out.blob, mem_ctx, io->generic.level, io);
225 data_blob_free(&b.out.blob);
227 return status;
231 level specific getinfo call
233 NTSTATUS smb2_getinfo_fs(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
234 union smb_fsinfo *io)
236 struct smb2_request *req = smb2_getinfo_fs_send(tree, io);
237 return smb2_getinfo_fs_recv(req, mem_ctx, io);