2 Unix SMB/CIFS implementation.
4 SMB client negotiate context management functions
6 Copyright (C) Andrew Tridgell 1994-2005
7 Copyright (C) James Myers 2003 <myersjj@samba.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "system/time.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/raw/raw_proto.h"
28 #include "../libcli/smb/smbXcli_base.h"
29 #include "../lib/util/tevent_ntstatus.h"
31 NTSTATUS smb_raw_negotiate_fill_transport(struct smbcli_transport *transport)
33 struct smbcli_negotiate *n = &transport->negotiate;
34 struct smbXcli_conn *c = transport->conn;
37 n->protocol = smbXcli_conn_protocol(c);
38 if (n->protocol > PROTOCOL_NT1) {
39 return NT_STATUS_REVISION_MISMATCH;
42 n->sec_mode = smb1cli_conn_server_security_mode(c);
43 n->max_mux = smbXcli_conn_max_requests(c);
44 n->max_xmit = smb1cli_conn_max_xmit(c);
45 n->sesskey = smb1cli_conn_server_session_key(c);
46 n->capabilities = smb1cli_conn_capabilities(c);;
48 /* this time arrives in real GMT */
49 ntt = smbXcli_conn_server_system_time(c);
50 n->server_time = nt_time_to_unix(ntt);
51 n->server_zone = smb1cli_conn_server_time_zone(c);
53 if (n->capabilities & CAP_EXTENDED_SECURITY) {
54 const DATA_BLOB *b = smbXcli_conn_server_gss_blob(c);
59 const uint8_t *p = smb1cli_conn_server_challenge(c);
61 n->secblob = data_blob_const(p, 8);
65 n->readbraw_supported = smb1cli_conn_server_readbraw(c);
66 n->readbraw_supported = smb1cli_conn_server_writebraw(c);
67 n->lockread_supported = smb1cli_conn_server_lockread(c);
72 struct smb_raw_negotiate_state {
73 struct smbcli_transport *transport;
76 static void smb_raw_negotiate_done(struct tevent_req *subreq);
78 struct tevent_req *smb_raw_negotiate_send(TALLOC_CTX *mem_ctx,
79 struct tevent_context *ev,
80 struct smbcli_transport *transport,
84 struct tevent_req *req;
85 struct smb_raw_negotiate_state *state;
86 struct tevent_req *subreq;
87 uint32_t timeout_msec = transport->options.request_timeout * 1000;
89 req = tevent_req_create(mem_ctx, &state,
90 struct smb_raw_negotiate_state);;
94 state->transport = transport;
96 if (maxprotocol > PROTOCOL_NT1) {
97 maxprotocol = PROTOCOL_NT1;
100 if (minprotocol > maxprotocol) {
101 minprotocol = maxprotocol;
104 subreq = smbXcli_negprot_send(state, ev,
109 transport->options.max_credits);
110 if (tevent_req_nomem(subreq, req)) {
111 return tevent_req_post(req, ev);
113 tevent_req_set_callback(subreq, smb_raw_negotiate_done, req);
118 static void smb_raw_negotiate_done(struct tevent_req *subreq)
120 struct tevent_req *req =
121 tevent_req_callback_data(subreq,
123 struct smb_raw_negotiate_state *state =
125 struct smb_raw_negotiate_state);
128 status = smbXcli_negprot_recv(subreq);
130 if (tevent_req_nterror(req, status)) {
134 status = smb_raw_negotiate_fill_transport(state->transport);
135 if (tevent_req_nterror(req, status)) {
139 tevent_req_done(req);
143 Send a negprot command.
145 NTSTATUS smb_raw_negotiate_recv(struct tevent_req *req)
147 return tevent_req_simple_recv_ntstatus(req);
152 Send a negprot command (sync interface)
154 NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, bool unicode,
155 int minprotocol, int maxprotocol)
158 struct tevent_req *subreq = NULL;
161 subreq = smb_raw_negotiate_send(transport,
166 if (subreq == NULL) {
167 status = NT_STATUS_NO_MEMORY;
171 ok = tevent_req_poll(subreq, transport->ev);
173 status = map_nt_error_from_unix_common(errno);
177 status = smb_raw_negotiate_recv(subreq);