2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2011
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "async_smb.h"
23 #include "smb2cli_base.h"
25 #include "libsmb/proto.h"
26 #include "lib/util/tevent_ntstatus.h"
28 struct smb2cli_tcon_state
{
29 struct cli_state
*cli
;
33 static void smb2cli_tcon_done(struct tevent_req
*subreq
);
35 struct tevent_req
*smb2cli_tcon_send(TALLOC_CTX
*mem_ctx
,
36 struct tevent_context
*ev
,
37 struct cli_state
*cli
,
40 struct tevent_req
*req
, *subreq
;
41 struct smb2cli_tcon_state
*state
;
43 char srv_ip
[INET6_ADDRSTRLEN
];
44 const char *tcon_share
;
48 req
= tevent_req_create(mem_ctx
, &state
, struct smb2cli_tcon_state
);
54 print_sockaddr(srv_ip
, sizeof(srv_ip
), &cli
->dest_ss
);
56 tcon_share
= talloc_asprintf(talloc_tos(), "\\\\%s\\%s",
58 if (tevent_req_nomem(tcon_share
, req
)) {
59 return tevent_req_post(req
, ev
);
61 if (!convert_string_talloc(state
, CH_UNIX
, CH_UTF16
,
62 tcon_share
, talloc_get_size(tcon_share
),
64 tevent_req_nomem(NULL
, req
);
65 return tevent_req_post(req
, ev
);
70 SSVAL(fixed
, 4, SMB2_HDR_BODY
+ 8);
71 SSVAL(fixed
, 6, dyn_len
);
73 subreq
= smb2cli_req_send(state
, ev
, cli
, SMB2_OP_TCON
, 0,
74 state
->fixed
, sizeof(state
->fixed
),
76 if (tevent_req_nomem(subreq
, req
)) {
77 return tevent_req_post(req
, ev
);
79 tevent_req_set_callback(subreq
, smb2cli_tcon_done
, req
);
83 static void smb2cli_tcon_done(struct tevent_req
*subreq
)
85 struct tevent_req
*req
= tevent_req_callback_data(
86 subreq
, struct tevent_req
);
87 struct smb2cli_tcon_state
*state
= tevent_req_data(
88 req
, struct smb2cli_tcon_state
);
89 struct cli_state
*cli
= state
->cli
;
94 status
= smb2cli_req_recv(subreq
, talloc_tos(), &iov
, 16);
95 if (!NT_STATUS_IS_OK(status
)) {
97 tevent_req_nterror(req
, status
);
101 cli
->smb2
.tid
= IVAL(iov
[0].iov_base
, SMB2_HDR_TID
);
103 body
= (uint8_t *)iov
[1].iov_base
;
104 cli
->smb2
.share_type
= CVAL(body
, 2);
105 cli
->smb2
.share_flags
= IVAL(body
, 4);
106 cli
->capabilities
= IVAL(body
, 8);
107 cli
->smb2
.maximal_access
= IVAL(body
, 12);
110 tevent_req_done(req
);
113 NTSTATUS
smb2cli_tcon_recv(struct tevent_req
*req
)
115 return tevent_req_simple_recv_ntstatus(req
);
118 NTSTATUS
smb2cli_tcon(struct cli_state
*cli
, const char *share
)
120 TALLOC_CTX
*frame
= talloc_stackframe();
121 struct event_context
*ev
;
122 struct tevent_req
*req
;
123 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
125 if (cli_has_async_calls(cli
)) {
127 * Can't use sync call while an async call is in flight
129 status
= NT_STATUS_INVALID_PARAMETER
;
132 ev
= event_context_init(frame
);
136 req
= smb2cli_tcon_send(frame
, ev
, cli
, share
);
140 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
143 status
= smb2cli_tcon_recv(req
);
149 struct smb2cli_tdis_state
{
153 static void smb2cli_tdis_done(struct tevent_req
*subreq
);
155 struct tevent_req
*smb2cli_tdis_send(TALLOC_CTX
*mem_ctx
,
156 struct tevent_context
*ev
,
157 struct cli_state
*cli
)
159 struct tevent_req
*req
, *subreq
;
160 struct smb2cli_tdis_state
*state
;
162 req
= tevent_req_create(mem_ctx
, &state
,
163 struct smb2cli_tdis_state
);
167 SSVAL(state
->fixed
, 0, 4);
169 subreq
= smb2cli_req_send(state
, ev
, cli
, SMB2_OP_TDIS
, 0,
170 state
->fixed
, sizeof(state
->fixed
),
172 if (tevent_req_nomem(subreq
, req
)) {
173 return tevent_req_post(req
, ev
);
175 tevent_req_set_callback(subreq
, smb2cli_tdis_done
, req
);
179 static void smb2cli_tdis_done(struct tevent_req
*subreq
)
181 struct tevent_req
*req
=
182 tevent_req_callback_data(subreq
,
187 status
= smb2cli_req_recv(subreq
, talloc_tos(), &iov
, 4);
189 if (tevent_req_nterror(req
, status
)) {
192 tevent_req_done(req
);
195 NTSTATUS
smb2cli_tdis_recv(struct tevent_req
*req
)
197 return tevent_req_simple_recv_ntstatus(req
);
200 NTSTATUS
smb2cli_tdis(struct cli_state
*cli
)
202 TALLOC_CTX
*frame
= talloc_stackframe();
203 struct event_context
*ev
;
204 struct tevent_req
*req
;
205 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
207 if (cli_has_async_calls(cli
)) {
209 * Can't use sync call while an async call is in flight
211 status
= NT_STATUS_INVALID_PARAMETER
;
214 ev
= event_context_init(frame
);
218 req
= smb2cli_tdis_send(frame
, ev
, cli
);
222 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
225 status
= smb2cli_tdis_recv(req
);