s3-build: Fix inotify detection (bug 8580)
[Samba.git] / source3 / smbd / smb2_negprot.c
blob2f45b8c756a509c1e98824d59bd413c27a8f11a9
1 /*
2 Unix SMB/CIFS implementation.
3 Core SMB2 server
5 Copyright (C) Stefan Metzmacher 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/smb/smb_common.h"
27 * this is the entry point if SMB2 is selected via
28 * the SMB negprot
30 void reply_smb2002(struct smb_request *req, uint16_t choice)
32 uint8_t *smb2_inbuf;
33 uint8_t *smb2_hdr;
34 uint8_t *smb2_body;
35 uint8_t *smb2_dyn;
36 size_t len = 4 + SMB2_HDR_BODY + 0x24 + 2;
38 smb2_inbuf = talloc_zero_array(talloc_tos(), uint8_t, len);
39 if (smb2_inbuf == NULL) {
40 DEBUG(0, ("Could not push spnego blob\n"));
41 reply_nterror(req, NT_STATUS_NO_MEMORY);
42 return;
44 smb2_hdr = smb2_inbuf + 4;
45 smb2_body = smb2_hdr + SMB2_HDR_BODY;
46 smb2_dyn = smb2_body + 0x24;
48 SIVAL(smb2_hdr, SMB2_HDR_PROTOCOL_ID, SMB2_MAGIC);
49 SIVAL(smb2_hdr, SMB2_HDR_LENGTH, SMB2_HDR_BODY);
51 SSVAL(smb2_body, 0x00, 0x0024); /* struct size */
52 SSVAL(smb2_body, 0x02, 0x0001); /* dialect count */
54 SSVAL(smb2_dyn, 0x00, 0x0202); /* dialect 2.002 */
56 req->outbuf = NULL;
58 smbd_smb2_first_negprot(req->sconn, smb2_inbuf, len);
59 return;
62 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
64 NTSTATUS status;
65 const uint8_t *inbody;
66 const uint8_t *indyn = NULL;
67 int i = req->current_idx;
68 DATA_BLOB outbody;
69 DATA_BLOB outdyn;
70 DATA_BLOB negprot_spnego_blob;
71 uint16_t security_offset;
72 DATA_BLOB security_buffer;
73 size_t expected_dyn_size = 0;
74 size_t c;
75 uint16_t security_mode;
76 uint16_t dialect_count;
77 uint16_t dialect = 0;
78 uint32_t capabilities;
79 uint32_t max_limit;
80 uint32_t max_trans = lp_smb2_max_trans();
81 uint32_t max_read = lp_smb2_max_read();
82 uint32_t max_write = lp_smb2_max_write();
84 status = smbd_smb2_request_verify_sizes(req, 0x24);
85 if (!NT_STATUS_IS_OK(status)) {
86 return smbd_smb2_request_error(req, status);
88 inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
90 dialect_count = SVAL(inbody, 0x02);
91 if (dialect_count == 0) {
92 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
95 expected_dyn_size = dialect_count * 2;
96 if (req->in.vector[i+2].iov_len < expected_dyn_size) {
97 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
99 indyn = (const uint8_t *)req->in.vector[i+2].iov_base;
101 for (c=0; c < dialect_count; c++) {
102 dialect = SVAL(indyn, c*2);
103 if (dialect == SMB2_DIALECT_REVISION_202) {
104 break;
108 if (dialect != SMB2_DIALECT_REVISION_202) {
109 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
112 set_Protocol(PROTOCOL_SMB2);
114 if (get_remote_arch() != RA_SAMBA) {
115 set_remote_arch(RA_VISTA);
118 /* negprot_spnego() returns a the server guid in the first 16 bytes */
119 negprot_spnego_blob = negprot_spnego(req, req->sconn);
120 if (negprot_spnego_blob.data == NULL) {
121 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
124 if (negprot_spnego_blob.length < 16) {
125 return smbd_smb2_request_error(req, NT_STATUS_INTERNAL_ERROR);
128 security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED;
129 if (lp_server_signing() == Required) {
130 security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
133 capabilities = 0;
134 if (lp_host_msdfs()) {
135 capabilities |= SMB2_CAP_DFS;
139 * Unless we implement SMB2_CAP_LARGE_MTU,
140 * 0x10000 (65536) is the maximum allowed message size
142 max_limit = 0x10000;
144 max_trans = MIN(max_limit, max_trans);
145 max_read = MIN(max_limit, max_read);
146 max_write = MIN(max_limit, max_write);
148 security_offset = SMB2_HDR_BODY + 0x40;
150 #if 1
151 /* Try SPNEGO auth... */
152 security_buffer = data_blob_const(negprot_spnego_blob.data + 16,
153 negprot_spnego_blob.length - 16);
154 #else
155 /* for now we want raw NTLMSSP */
156 security_buffer = data_blob_const(NULL, 0);
157 #endif
159 outbody = data_blob_talloc(req->out.vector, NULL, 0x40);
160 if (outbody.data == NULL) {
161 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
164 SSVAL(outbody.data, 0x00, 0x40 + 1); /* struct size */
165 SSVAL(outbody.data, 0x02,
166 security_mode); /* security mode */
167 SSVAL(outbody.data, 0x04, dialect); /* dialect revision */
168 SSVAL(outbody.data, 0x06, 0); /* reserved */
169 memcpy(outbody.data + 0x08,
170 negprot_spnego_blob.data, 16); /* server guid */
171 SIVAL(outbody.data, 0x18,
172 capabilities); /* capabilities */
173 SIVAL(outbody.data, 0x1C, max_trans); /* max transact size */
174 SIVAL(outbody.data, 0x20, max_trans); /* max read size */
175 SIVAL(outbody.data, 0x24, max_trans); /* max write size */
176 SBVAL(outbody.data, 0x28, 0); /* system time */
177 SBVAL(outbody.data, 0x30, 0); /* server start time */
178 SSVAL(outbody.data, 0x38,
179 security_offset); /* security buffer offset */
180 SSVAL(outbody.data, 0x3A,
181 security_buffer.length); /* security buffer length */
182 SIVAL(outbody.data, 0x3C, 0); /* reserved */
184 outdyn = security_buffer;
186 req->sconn->using_smb2 = true;
187 req->sconn->smb2.max_trans = max_trans;
188 req->sconn->smb2.max_read = max_read;
189 req->sconn->smb2.max_write = max_write;
191 return smbd_smb2_request_done(req, outbody, &outdyn);