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, 0));
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_INFO_CLASS;
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_FOOBAR;
201 void smb2srv_getinfo_recv(struct smb2srv_request *req)
203 struct smb2_getinfo *info;
204 struct smb2srv_getinfo_op *op;
206 SMB2SRV_CHECK_BODY_SIZE(req, 0x28, True);
207 SMB2SRV_TALLOC_IO_PTR(info, struct smb2_getinfo);
208 /* this overwrites req->io_ptr !*/
209 SMB2SRV_TALLOC_IO_PTR(op, struct smb2srv_getinfo_op);
214 SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_getinfo_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
216 info->in.level = SVAL(req->in.body, 0x02);
217 info->in.max_response_size = IVAL(req->in.body, 0x04);
218 info->in.unknown1 = IVAL(req->in.body, 0x08);
219 info->in.unknown2 = IVAL(req->in.body, 0x0C);
220 info->in.flags = IVAL(req->in.body, 0x10);
221 info->in.flags2 = IVAL(req->in.body, 0x14);
222 info->in.file.ntvfs = smb2srv_pull_handle(req, req->in.body, 0x18);
224 SMB2SRV_CHECK_FILE_HANDLE(info->in.file.ntvfs);
225 SMB2SRV_CALL_NTVFS_BACKEND(smb2srv_getinfo_backend(op));
228 void smb2srv_setinfo_recv(struct smb2srv_request *req)
230 smb2srv_send_error(req, NT_STATUS_NOT_IMPLEMENTED);