2 Unix SMB2 implementation.
4 Copyright (C) Stefan Metzmacher 2006
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "libcli/smb2/smb2.h"
23 #include "libcli/smb2/smb2_calls.h"
24 #include "smb_server/smb_server.h"
25 #include "smb_server/service_smb_proto.h"
26 #include "smb_server/smb2/smb2_server.h"
27 #include "ntvfs/ntvfs.h"
28 #include "librpc/gen_ndr/ndr_security.h"
30 struct smb2srv_getinfo_op {
31 struct smb2srv_request *req;
32 struct smb2_getinfo *info;
34 NTSTATUS (*send_fn)(struct smb2srv_getinfo_op *op);
37 static void smb2srv_getinfo_send(struct ntvfs_request *ntvfs)
39 struct smb2srv_getinfo_op *op;
40 struct smb2srv_request *req;
43 * SMB2 uses NT_STATUS_INVALID_INFO_CLASS
44 * so we need to translated it here
46 if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, ntvfs->async_states->status)) {
47 ntvfs->async_states->status = NT_STATUS_INVALID_INFO_CLASS;
50 SMB2SRV_CHECK_ASYNC_STATUS(op, struct smb2srv_getinfo_op);
52 ZERO_STRUCT(op->info->out);
54 SMB2SRV_CHECK(op->send_fn(op));
57 SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x08, True, op->info->out.blob.length));
59 /* TODO: this is maybe a o16s32_blob */
60 SMB2SRV_CHECK(smb2_push_o16s16_blob(&req->out, 0x02, op->info->out.blob));
61 SSVAL(req->out.body, 0x06, 0);
63 smb2srv_send_reply(req);
66 static NTSTATUS smb2srv_getinfo_file_send(struct smb2srv_getinfo_op *op)
68 union smb_fileinfo *io = talloc_get_type(op->io_ptr, union smb_fileinfo);
71 status = smbsrv_push_passthru_fileinfo(op->req,
73 io->generic.level, io,
75 NT_STATUS_NOT_OK_RETURN(status);
80 static NTSTATUS smb2srv_getinfo_file(struct smb2srv_getinfo_op *op, uint8_t smb2_level)
82 union smb_fileinfo *io;
84 io = talloc(op, union smb_fileinfo);
85 NT_STATUS_HAVE_NO_MEMORY(io);
87 switch (op->info->in.level) {
88 case RAW_FILEINFO_SMB2_ALL_EAS:
89 io->all_eas.level = op->info->in.level;
90 io->all_eas.in.file.ntvfs = op->info->in.file.ntvfs;
91 io->all_eas.in.continue_flags = op->info->in.flags2;
94 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
95 io->all_info2.level = op->info->in.level;
96 io->all_info2.in.file.ntvfs = op->info->in.file.ntvfs;
100 /* the rest directly maps to the passthru levels */
101 io->generic.level = smb2_level + 1000;
102 io->generic.in.file.ntvfs = op->info->in.file.ntvfs;
107 op->send_fn = smb2srv_getinfo_file_send;
109 return ntvfs_qfileinfo(op->req->ntvfs, io);
112 static NTSTATUS smb2srv_getinfo_fs_send(struct smb2srv_getinfo_op *op)
114 union smb_fsinfo *io = talloc_get_type(op->io_ptr, union smb_fsinfo);
117 status = smbsrv_push_passthru_fsinfo(op->req,
119 io->generic.level, io,
121 NT_STATUS_NOT_OK_RETURN(status);
126 static NTSTATUS smb2srv_getinfo_fs(struct smb2srv_getinfo_op *op, uint8_t smb2_level)
128 union smb_fsinfo *io;
130 io = talloc(op, union smb_fsinfo);
131 NT_STATUS_HAVE_NO_MEMORY(io);
133 /* the rest directly maps to the passthru levels */
134 io->generic.level = smb2_level + 1000;
136 /* TODO: allow qfsinfo only the share root directory handle */
139 op->send_fn = smb2srv_getinfo_fs_send;
141 return ntvfs_fsinfo(op->req->ntvfs, io);
144 static NTSTATUS smb2srv_getinfo_security_send(struct smb2srv_getinfo_op *op)
146 union smb_fileinfo *io = talloc_get_type(op->io_ptr, union smb_fileinfo);
149 status = ndr_push_struct_blob(&op->info->out.blob, op->req,
150 io->query_secdesc.out.sd,
151 (ndr_push_flags_fn_t)ndr_push_security_descriptor);
152 NT_STATUS_NOT_OK_RETURN(status);
157 static NTSTATUS smb2srv_getinfo_security(struct smb2srv_getinfo_op *op, uint8_t smb2_level)
159 union smb_fileinfo *io;
161 switch (smb2_level) {
163 io = talloc(op, union smb_fileinfo);
164 NT_STATUS_HAVE_NO_MEMORY(io);
166 io->query_secdesc.level = RAW_FILEINFO_SEC_DESC;
167 io->query_secdesc.in.file.ntvfs = op->info->in.file.ntvfs;
168 io->query_secdesc.in.secinfo_flags = op->info->in.flags;
171 op->send_fn = smb2srv_getinfo_security_send;
173 return ntvfs_qfileinfo(op->req->ntvfs, io);
176 return NT_STATUS_INVALID_PARAMETER;
179 static NTSTATUS smb2srv_getinfo_backend(struct smb2srv_getinfo_op *op)
184 smb2_class = 0xFF & op->info->in.level;
185 smb2_level = 0xFF & (op->info->in.level>>8);
187 switch (smb2_class) {
188 case SMB2_GETINFO_FILE:
189 return smb2srv_getinfo_file(op, smb2_level);
191 case SMB2_GETINFO_FS:
192 return smb2srv_getinfo_fs(op, smb2_level);
194 case SMB2_GETINFO_SECURITY:
195 return smb2srv_getinfo_security(op, smb2_level);
198 return NT_STATUS_NOT_SUPPORTED;
201 return NT_STATUS_INVALID_PARAMETER;
204 void smb2srv_getinfo_recv(struct smb2srv_request *req)
206 struct smb2_getinfo *info;
207 struct smb2srv_getinfo_op *op;
209 SMB2SRV_CHECK_BODY_SIZE(req, 0x28, True);
210 SMB2SRV_TALLOC_IO_PTR(info, struct smb2_getinfo);
211 /* this overwrites req->io_ptr !*/
212 SMB2SRV_TALLOC_IO_PTR(op, struct smb2srv_getinfo_op);
217 SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_getinfo_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
219 info->in.level = SVAL(req->in.body, 0x02);
220 info->in.max_response_size = IVAL(req->in.body, 0x04);
221 info->in.unknown1 = IVAL(req->in.body, 0x08);
222 info->in.unknown2 = IVAL(req->in.body, 0x0C);
223 info->in.flags = IVAL(req->in.body, 0x10);
224 info->in.flags2 = IVAL(req->in.body, 0x14);
225 info->in.file.ntvfs = smb2srv_pull_handle(req, req->in.body, 0x18);
227 SMB2SRV_CHECK_FILE_HANDLE(info->in.file.ntvfs);
228 SMB2SRV_CALL_NTVFS_BACKEND(smb2srv_getinfo_backend(op));
231 struct smb2srv_setinfo_op {
232 struct smb2srv_request *req;
233 struct smb2_setinfo *info;
236 static void smb2srv_setinfo_send(struct ntvfs_request *ntvfs)
238 struct smb2srv_setinfo_op *op;
239 struct smb2srv_request *req;
242 * SMB2 uses NT_STATUS_INVALID_INFO_CLASS
243 * so we need to translated it here
245 if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, ntvfs->async_states->status)) {
246 ntvfs->async_states->status = NT_STATUS_INVALID_INFO_CLASS;
249 SMB2SRV_CHECK_ASYNC_STATUS(op, struct smb2srv_setinfo_op);
251 SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x02, False, 0));
253 smb2srv_send_reply(req);
256 static NTSTATUS smb2srv_setinfo_file(struct smb2srv_setinfo_op *op, uint8_t smb2_level)
258 union smb_setfileinfo *io;
261 io = talloc(op, union smb_setfileinfo);
262 NT_STATUS_HAVE_NO_MEMORY(io);
264 /* the levels directly map to the passthru levels */
265 io->generic.level = smb2_level + 1000;
266 io->generic.in.file.ntvfs = op->info->in.file.ntvfs;
268 status = smbsrv_pull_passthru_sfileinfo(io, io->generic.level, io,
271 NT_STATUS_NOT_OK_RETURN(status);
273 return ntvfs_setfileinfo(op->req->ntvfs, io);
276 static NTSTATUS smb2srv_setinfo_fs(struct smb2srv_setinfo_op *op, uint8_t smb2_level)
278 switch (smb2_level) {
280 return NT_STATUS_NOT_IMPLEMENTED;
283 return NT_STATUS_ACCESS_DENIED;
286 return NT_STATUS_ACCESS_DENIED;
289 return NT_STATUS_ACCESS_DENIED;
292 return NT_STATUS_INVALID_INFO_CLASS;
295 static NTSTATUS smb2srv_setinfo_security(struct smb2srv_setinfo_op *op, uint8_t smb2_level)
297 union smb_setfileinfo *io;
300 switch (smb2_level) {
302 io = talloc(op, union smb_setfileinfo);
303 NT_STATUS_HAVE_NO_MEMORY(io);
305 io->set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
306 io->set_secdesc.in.file.ntvfs = op->info->in.file.ntvfs;
307 io->set_secdesc.in.secinfo_flags = op->info->in.flags;
309 io->set_secdesc.in.sd = talloc(io, struct security_descriptor);
310 NT_STATUS_HAVE_NO_MEMORY(io->set_secdesc.in.sd);
312 status = ndr_pull_struct_blob(&op->info->in.blob, io,
313 io->set_secdesc.in.sd,
314 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
315 NT_STATUS_NOT_OK_RETURN(status);
317 return ntvfs_setfileinfo(op->req->ntvfs, io);
320 return NT_STATUS_INVALID_INFO_CLASS;
323 static NTSTATUS smb2srv_setinfo_backend(struct smb2srv_setinfo_op *op)
328 smb2_class = 0xFF & op->info->in.level;
329 smb2_level = 0xFF & (op->info->in.level>>8);
331 switch (smb2_class) {
332 case SMB2_GETINFO_FILE:
333 return smb2srv_setinfo_file(op, smb2_level);
335 case SMB2_GETINFO_FS:
336 return smb2srv_setinfo_fs(op, smb2_level);
338 case SMB2_GETINFO_SECURITY:
339 return smb2srv_setinfo_security(op, smb2_level);
342 return NT_STATUS_NOT_SUPPORTED;
345 return NT_STATUS_INVALID_PARAMETER;
348 void smb2srv_setinfo_recv(struct smb2srv_request *req)
350 struct smb2_setinfo *info;
351 struct smb2srv_setinfo_op *op;
353 SMB2SRV_CHECK_BODY_SIZE(req, 0x20, True);
354 SMB2SRV_TALLOC_IO_PTR(info, struct smb2_setinfo);
355 /* this overwrites req->io_ptr !*/
356 SMB2SRV_TALLOC_IO_PTR(op, struct smb2srv_setinfo_op);
359 SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_setinfo_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
361 info->in.level = SVAL(req->in.body, 0x02);
362 SMB2SRV_CHECK(smb2_pull_s32o32_blob(&req->in, info, req->in.body+0x04, &info->in.blob));
363 info->in.flags = IVAL(req->in.body, 0x0C);
364 info->in.file.ntvfs = smb2srv_pull_handle(req, req->in.body, 0x10);
366 SMB2SRV_CHECK_FILE_HANDLE(info->in.file.ntvfs);
367 SMB2SRV_CALL_NTVFS_BACKEND(smb2srv_setinfo_backend(op));