testprogs: Update the kpasswd setpassword test
[Samba.git] / source4 / libcli / raw / rawnegotiate.c
blob73c9123411d6101710ee0168e2234b0032dc9dec
1 /*
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/>.
23 #include "includes.h"
24 #include <tevent.h>
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 struct smb_raw_negotiate_state {
32 struct smbcli_transport *transport;
35 static void smb_raw_negotiate_done(struct tevent_req *subreq);
37 struct tevent_req *smb_raw_negotiate_send(TALLOC_CTX *mem_ctx,
38 struct tevent_context *ev,
39 struct smbcli_transport *transport,
40 int minprotocol,
41 int maxprotocol)
43 struct tevent_req *req;
44 struct smb_raw_negotiate_state *state;
45 struct tevent_req *subreq;
46 uint32_t timeout_msec = transport->options.request_timeout * 1000;
48 req = tevent_req_create(mem_ctx, &state,
49 struct smb_raw_negotiate_state);;
50 if (req == NULL) {
51 return NULL;
53 state->transport = transport;
55 if (maxprotocol > PROTOCOL_NT1) {
56 maxprotocol = PROTOCOL_NT1;
59 if (minprotocol > maxprotocol) {
60 minprotocol = maxprotocol;
63 subreq = smbXcli_negprot_send(state, ev,
64 transport->conn,
65 timeout_msec,
66 minprotocol,
67 maxprotocol,
68 transport->options.max_credits);
69 if (tevent_req_nomem(subreq, req)) {
70 return tevent_req_post(req, ev);
72 tevent_req_set_callback(subreq, smb_raw_negotiate_done, req);
74 return req;
77 static void smb_raw_negotiate_done(struct tevent_req *subreq)
79 struct tevent_req *req =
80 tevent_req_callback_data(subreq,
81 struct tevent_req);
82 struct smb_raw_negotiate_state *state =
83 tevent_req_data(req,
84 struct smb_raw_negotiate_state);
85 struct smbcli_negotiate *n = &state->transport->negotiate;
86 struct smbXcli_conn *c = state->transport->conn;
87 NTSTATUS status;
88 NTTIME ntt;
90 status = smbXcli_negprot_recv(subreq);
91 TALLOC_FREE(subreq);
92 if (tevent_req_nterror(req, status)) {
93 return;
96 n->protocol = smbXcli_conn_protocol(c);
98 n->sec_mode = smb1cli_conn_server_security_mode(c);
99 n->max_mux = smbXcli_conn_max_requests(c);
100 n->max_xmit = smb1cli_conn_max_xmit(c);
101 n->sesskey = smb1cli_conn_server_session_key(c);
102 n->capabilities = smb1cli_conn_capabilities(c);;
104 /* this time arrives in real GMT */
105 ntt = smbXcli_conn_server_system_time(c);
106 n->server_time = nt_time_to_unix(ntt);
107 n->server_zone = smb1cli_conn_server_time_zone(c);
109 if (n->capabilities & CAP_EXTENDED_SECURITY) {
110 const DATA_BLOB *b = smbXcli_conn_server_gss_blob(c);
111 if (b) {
112 n->secblob = *b;
114 } else {
115 const uint8_t *p = smb1cli_conn_server_challenge(c);
116 if (p) {
117 n->secblob = data_blob_const(p, 8);
121 n->readbraw_supported = smb1cli_conn_server_readbraw(c);
122 n->readbraw_supported = smb1cli_conn_server_writebraw(c);
123 n->lockread_supported = smb1cli_conn_server_lockread(c);
125 tevent_req_done(req);
129 Send a negprot command.
131 NTSTATUS smb_raw_negotiate_recv(struct tevent_req *req)
133 return tevent_req_simple_recv_ntstatus(req);
138 Send a negprot command (sync interface)
140 NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, bool unicode,
141 int minprotocol, int maxprotocol)
143 NTSTATUS status = NT_STATUS_INTERNAL_ERROR;
144 struct tevent_req *subreq = NULL;
145 bool ok;
147 subreq = smb_raw_negotiate_send(transport,
148 transport->ev,
149 transport,
150 minprotocol,
151 maxprotocol);
152 if (subreq == NULL) {
153 return NT_STATUS_NO_MEMORY;
156 ok = tevent_req_poll(subreq, transport->ev);
157 if (!ok) {
158 status = map_nt_error_from_unix_common(errno);
159 goto failed;
162 status = smb_raw_negotiate_recv(subreq);
164 failed:
165 TALLOC_FREE(subreq);
166 return status;