2 Unix SMB/CIFS implementation.
3 Infrastructure for async SMB client requests
4 Copyright (C) Volker Lendecke 2008
5 Copyright (C) Stefan Metzmacher 2011
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 #ifndef _SMBXCLI_BASE_H_
22 #define _SMBXCLI_BASE_H_
25 struct smbXcli_session
;
27 struct smb_trans_enc_state
;
30 struct smbXcli_conn
*smbXcli_conn_create(TALLOC_CTX
*mem_ctx
,
32 const char *remote_name
,
33 enum smb_signing_setting signing_state
,
34 uint32_t smb1_capabilities
,
35 struct GUID
*client_guid
,
36 uint32_t smb2_capabilities
);
38 bool smbXcli_conn_is_connected(struct smbXcli_conn
*conn
);
39 void smbXcli_conn_disconnect(struct smbXcli_conn
*conn
, NTSTATUS status
);
41 bool smbXcli_conn_has_async_calls(struct smbXcli_conn
*conn
);
43 enum protocol_types
smbXcli_conn_protocol(struct smbXcli_conn
*conn
);
44 bool smbXcli_conn_use_unicode(struct smbXcli_conn
*conn
);
46 void smbXcli_conn_set_sockopt(struct smbXcli_conn
*conn
, const char *options
);
47 const struct sockaddr_storage
*smbXcli_conn_local_sockaddr(struct smbXcli_conn
*conn
);
48 const struct sockaddr_storage
*smbXcli_conn_remote_sockaddr(struct smbXcli_conn
*conn
);
49 const char *smbXcli_conn_remote_name(struct smbXcli_conn
*conn
);
51 uint16_t smbXcli_conn_max_requests(struct smbXcli_conn
*conn
);
52 NTTIME
smbXcli_conn_server_system_time(struct smbXcli_conn
*conn
);
53 const DATA_BLOB
*smbXcli_conn_server_gss_blob(struct smbXcli_conn
*conn
);
54 const struct GUID
*smbXcli_conn_server_guid(struct smbXcli_conn
*conn
);
56 struct tevent_req
*smbXcli_conn_samba_suicide_send(TALLOC_CTX
*mem_ctx
,
57 struct tevent_context
*ev
,
58 struct smbXcli_conn
*conn
,
60 NTSTATUS
smbXcli_conn_samba_suicide_recv(struct tevent_req
*req
);
61 NTSTATUS
smbXcli_conn_samba_suicide(struct smbXcli_conn
*conn
,
64 void smbXcli_req_unset_pending(struct tevent_req
*req
);
65 bool smbXcli_req_set_pending(struct tevent_req
*req
);
67 uint32_t smb1cli_conn_capabilities(struct smbXcli_conn
*conn
);
68 uint32_t smb1cli_conn_max_xmit(struct smbXcli_conn
*conn
);
69 uint32_t smb1cli_conn_server_session_key(struct smbXcli_conn
*conn
);
70 const uint8_t *smb1cli_conn_server_challenge(struct smbXcli_conn
*conn
);
71 uint16_t smb1cli_conn_server_security_mode(struct smbXcli_conn
*conn
);
72 bool smb1cli_conn_server_readbraw(struct smbXcli_conn
*conn
);
73 bool smb1cli_conn_server_writebraw(struct smbXcli_conn
*conn
);
74 bool smb1cli_conn_server_lockread(struct smbXcli_conn
*conn
);
75 bool smb1cli_conn_server_writeunlock(struct smbXcli_conn
*conn
);
76 int smb1cli_conn_server_time_zone(struct smbXcli_conn
*conn
);
78 bool smb1cli_conn_activate_signing(struct smbXcli_conn
*conn
,
79 const DATA_BLOB user_session_key
,
80 const DATA_BLOB response
);
81 bool smb1cli_conn_check_signing(struct smbXcli_conn
*conn
,
82 const uint8_t *buf
, uint32_t seqnum
);
83 bool smb1cli_conn_signing_is_active(struct smbXcli_conn
*conn
);
85 void smb1cli_conn_set_encryption(struct smbXcli_conn
*conn
,
86 struct smb_trans_enc_state
*es
);
87 bool smb1cli_conn_encryption_on(struct smbXcli_conn
*conn
);
89 bool smb1cli_is_andx_req(uint8_t cmd
);
90 size_t smb1cli_req_wct_ofs(struct tevent_req
**reqs
, int num_reqs
);
92 uint16_t smb1cli_req_mid(struct tevent_req
*req
);
93 void smb1cli_req_set_mid(struct tevent_req
*req
, uint16_t mid
);
95 uint32_t smb1cli_req_seqnum(struct tevent_req
*req
);
96 void smb1cli_req_set_seqnum(struct tevent_req
*req
, uint32_t seqnum
);
98 struct smb1cli_req_expected_response
{
103 struct tevent_req
*smb1cli_req_create(TALLOC_CTX
*mem_ctx
,
104 struct tevent_context
*ev
,
105 struct smbXcli_conn
*conn
,
107 uint8_t additional_flags
,
109 uint16_t additional_flags2
,
110 uint16_t clear_flags2
,
111 uint32_t timeout_msec
,
113 struct smbXcli_tcon
*tcon
,
114 struct smbXcli_session
*session
,
115 uint8_t wct
, uint16_t *vwv
,
117 struct iovec
*bytes_iov
);
118 NTSTATUS
smb1cli_req_chain_submit(struct tevent_req
**reqs
, int num_reqs
);
120 struct tevent_req
*smb1cli_req_send(TALLOC_CTX
*mem_ctx
,
121 struct tevent_context
*ev
,
122 struct smbXcli_conn
*conn
,
124 uint8_t additional_flags
,
126 uint16_t additional_flags2
,
127 uint16_t clear_flags2
,
128 uint32_t timeout_msec
,
130 struct smbXcli_tcon
*tcon
,
131 struct smbXcli_session
*session
,
132 uint8_t wct
, uint16_t *vwv
,
134 const uint8_t *bytes
);
135 NTSTATUS
smb1cli_req_recv(struct tevent_req
*req
,
141 uint32_t *pvwv_offset
,
142 uint32_t *pnum_bytes
,
144 uint32_t *pbytes_offset
,
146 const struct smb1cli_req_expected_response
*expected
,
147 size_t num_expected
);
149 struct tevent_req
*smb1cli_trans_send(
150 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
151 struct smbXcli_conn
*conn
, uint8_t cmd
,
152 uint8_t additional_flags
, uint8_t clear_flags
,
153 uint16_t additional_flags2
, uint16_t clear_flags2
,
154 uint32_t timeout_msec
,
156 struct smbXcli_tcon
*tcon
,
157 struct smbXcli_session
*session
,
158 const char *pipe_name
, uint16_t fid
, uint16_t function
, int flags
,
159 uint16_t *setup
, uint8_t num_setup
, uint8_t max_setup
,
160 uint8_t *param
, uint32_t num_param
, uint32_t max_param
,
161 uint8_t *data
, uint32_t num_data
, uint32_t max_data
);
162 NTSTATUS
smb1cli_trans_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
163 uint16_t *recv_flags2
,
164 uint16_t **setup
, uint8_t min_setup
,
166 uint8_t **param
, uint32_t min_param
,
168 uint8_t **data
, uint32_t min_data
,
170 NTSTATUS
smb1cli_trans(TALLOC_CTX
*mem_ctx
, struct smbXcli_conn
*conn
,
172 uint8_t additional_flags
, uint8_t clear_flags
,
173 uint16_t additional_flags2
, uint16_t clear_flags2
,
174 uint32_t timeout_msec
,
176 struct smbXcli_tcon
*tcon
,
177 struct smbXcli_session
*session
,
178 const char *pipe_name
, uint16_t fid
, uint16_t function
,
180 uint16_t *setup
, uint8_t num_setup
, uint8_t max_setup
,
181 uint8_t *param
, uint32_t num_param
, uint32_t max_param
,
182 uint8_t *data
, uint32_t num_data
, uint32_t max_data
,
183 uint16_t *recv_flags2
,
184 uint16_t **rsetup
, uint8_t min_rsetup
, uint8_t *num_rsetup
,
185 uint8_t **rparam
, uint32_t min_rparam
, uint32_t *num_rparam
,
186 uint8_t **rdata
, uint32_t min_rdata
, uint32_t *num_rdata
);
188 uint32_t smb2cli_conn_server_capabilities(struct smbXcli_conn
*conn
);
189 uint16_t smb2cli_conn_server_security_mode(struct smbXcli_conn
*conn
);
190 uint32_t smb2cli_conn_max_trans_size(struct smbXcli_conn
*conn
);
191 uint32_t smb2cli_conn_max_read_size(struct smbXcli_conn
*conn
);
192 uint32_t smb2cli_conn_max_write_size(struct smbXcli_conn
*conn
);
193 void smb2cli_conn_set_max_credits(struct smbXcli_conn
*conn
,
194 uint16_t max_credits
);
196 struct tevent_req
*smb2cli_req_create(TALLOC_CTX
*mem_ctx
,
197 struct tevent_context
*ev
,
198 struct smbXcli_conn
*conn
,
200 uint32_t additional_flags
,
201 uint32_t clear_flags
,
202 uint32_t timeout_msec
,
205 struct smbXcli_session
*session
,
206 const uint8_t *fixed
,
210 void smb2cli_req_set_notify_async(struct tevent_req
*req
);
211 NTSTATUS
smb2cli_req_compound_submit(struct tevent_req
**reqs
,
213 void smb2cli_req_set_credit_charge(struct tevent_req
*req
, uint16_t charge
);
215 struct smb2cli_req_expected_response
{
220 struct tevent_req
*smb2cli_req_send(TALLOC_CTX
*mem_ctx
,
221 struct tevent_context
*ev
,
222 struct smbXcli_conn
*conn
,
224 uint32_t additional_flags
,
225 uint32_t clear_flags
,
226 uint32_t timeout_msec
,
229 struct smbXcli_session
*session
,
230 const uint8_t *fixed
,
234 NTSTATUS
smb2cli_req_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
236 const struct smb2cli_req_expected_response
*expected
,
237 size_t num_expected
);
239 struct tevent_req
*smbXcli_negprot_send(TALLOC_CTX
*mem_ctx
,
240 struct tevent_context
*ev
,
241 struct smbXcli_conn
*conn
,
242 uint32_t timeout_msec
,
243 enum protocol_types min_protocol
,
244 enum protocol_types max_protocol
);
245 NTSTATUS
smbXcli_negprot_recv(struct tevent_req
*req
);
246 NTSTATUS
smbXcli_negprot(struct smbXcli_conn
*conn
,
247 uint32_t timeout_msec
,
248 enum protocol_types min_protocol
,
249 enum protocol_types max_protocol
);
251 struct smbXcli_session
*smbXcli_session_create(TALLOC_CTX
*mem_ctx
,
252 struct smbXcli_conn
*conn
);
253 uint16_t smb1cli_session_current_id(struct smbXcli_session
* session
);
254 void smb1cli_session_set_id(struct smbXcli_session
* session
,
255 uint16_t session_id
);
256 uint8_t smb2cli_session_security_mode(struct smbXcli_session
*session
);
257 uint64_t smb2cli_session_current_id(struct smbXcli_session
*session
);
258 uint16_t smb2cli_session_get_flags(struct smbXcli_session
*session
);
259 NTSTATUS
smb2cli_session_application_key(struct smbXcli_session
*session
,
262 void smb2cli_session_set_id_and_flags(struct smbXcli_session
*session
,
264 uint16_t session_flags
);
265 NTSTATUS
smb2cli_session_set_session_key(struct smbXcli_session
*session
,
266 const DATA_BLOB session_key
,
267 const struct iovec
*recv_iov
);
268 NTSTATUS
smb2cli_session_create_channel(TALLOC_CTX
*mem_ctx
,
269 struct smbXcli_session
*session1
,
270 struct smbXcli_conn
*conn
,
271 struct smbXcli_session
**_session2
);
272 NTSTATUS
smb2cli_session_set_channel_key(struct smbXcli_session
*session
,
273 const DATA_BLOB channel_key
,
274 const struct iovec
*recv_iov
);
276 struct smbXcli_tcon
*smbXcli_tcon_create(TALLOC_CTX
*mem_ctx
);
277 uint16_t smb1cli_tcon_current_id(struct smbXcli_tcon
*tcon
);
278 void smb1cli_tcon_set_id(struct smbXcli_tcon
*tcon
, uint16_t tcon_id
);
279 bool smb1cli_tcon_set_values(struct smbXcli_tcon
*tcon
,
281 uint16_t optional_support
,
282 uint32_t maximal_access
,
283 uint32_t guest_maximal_access
,
285 const char *fs_type
);
286 uint32_t smb2cli_tcon_current_id(struct smbXcli_tcon
*tcon
);
287 uint32_t smb2cli_tcon_capabilities(struct smbXcli_tcon
*tcon
);
288 void smb2cli_tcon_set_values(struct smbXcli_tcon
*tcon
,
292 uint32_t capabilities
,
293 uint32_t maximal_access
);
295 struct tevent_req
*smb2cli_session_setup_send(TALLOC_CTX
*mem_ctx
,
296 struct tevent_context
*ev
,
297 struct smbXcli_conn
*conn
,
298 uint32_t timeout_msec
,
299 struct smbXcli_session
*session
,
301 uint32_t in_capabilities
,
303 uint64_t in_previous_session_id
,
304 const DATA_BLOB
*in_security_buffer
);
305 NTSTATUS
smb2cli_session_setup_recv(struct tevent_req
*req
,
307 struct iovec
**recv_iov
,
308 DATA_BLOB
*out_security_buffer
);
310 struct tevent_req
*smb2cli_logoff_send(TALLOC_CTX
*mem_ctx
,
311 struct tevent_context
*ev
,
312 struct smbXcli_conn
*conn
,
313 uint32_t timeout_msec
,
314 struct smbXcli_session
*session
);
315 NTSTATUS
smb2cli_logoff_recv(struct tevent_req
*req
);
316 NTSTATUS
smb2cli_logoff(struct smbXcli_conn
*conn
,
317 uint32_t timeout_msec
,
318 struct smbXcli_session
*session
);
320 struct tevent_req
*smb2cli_create_send(
322 struct tevent_context
*ev
,
323 struct smbXcli_conn
*conn
,
324 uint32_t timeout_msec
,
325 struct smbXcli_session
*session
,
326 struct smbXcli_tcon
*tcon
,
327 const char *filename
,
328 uint8_t oplock_level
, /* SMB2_OPLOCK_LEVEL_* */
329 uint32_t impersonation_level
, /* SMB2_IMPERSONATION_* */
330 uint32_t desired_access
,
331 uint32_t file_attributes
,
332 uint32_t share_access
,
333 uint32_t create_disposition
,
334 uint32_t create_options
,
335 struct smb2_create_blobs
*blobs
);
336 NTSTATUS
smb2cli_create_recv(struct tevent_req
*req
,
337 uint64_t *fid_persistent
,
338 uint64_t *fid_volatile
);
339 NTSTATUS
smb2cli_create(struct smbXcli_conn
*conn
,
340 uint32_t timeout_msec
,
341 struct smbXcli_session
*session
,
342 struct smbXcli_tcon
*tcon
,
343 const char *filename
,
344 uint8_t oplock_level
, /* SMB2_OPLOCK_LEVEL_* */
345 uint32_t impersonation_level
, /* SMB2_IMPERSONATION_* */
346 uint32_t desired_access
,
347 uint32_t file_attributes
,
348 uint32_t share_access
,
349 uint32_t create_disposition
,
350 uint32_t create_options
,
351 struct smb2_create_blobs
*blobs
,
352 uint64_t *fid_persistent
,
353 uint64_t *fid_volatile
);
355 struct tevent_req
*smb2cli_close_send(TALLOC_CTX
*mem_ctx
,
356 struct tevent_context
*ev
,
357 struct smbXcli_conn
*conn
,
358 uint32_t timeout_msec
,
359 struct smbXcli_session
*session
,
360 struct smbXcli_tcon
*tcon
,
362 uint64_t fid_persistent
,
363 uint64_t fid_volatile
);
364 NTSTATUS
smb2cli_close_recv(struct tevent_req
*req
);
365 NTSTATUS
smb2cli_close(struct smbXcli_conn
*conn
,
366 uint32_t timeout_msec
,
367 struct smbXcli_session
*session
,
368 struct smbXcli_tcon
*tcon
,
370 uint64_t fid_persistent
,
371 uint64_t fid_volatile
);
373 struct tevent_req
*smb2cli_read_send(TALLOC_CTX
*mem_ctx
,
374 struct tevent_context
*ev
,
375 struct smbXcli_conn
*conn
,
376 uint32_t timeout_msec
,
377 struct smbXcli_session
*session
,
378 struct smbXcli_tcon
*tcon
,
381 uint64_t fid_persistent
,
382 uint64_t fid_volatile
,
383 uint64_t minimum_count
,
384 uint64_t remaining_bytes
);
385 NTSTATUS
smb2cli_read_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
386 uint8_t **data
, uint32_t *data_length
);
387 NTSTATUS
smb2cli_read(struct smbXcli_conn
*conn
,
388 uint32_t timeout_msec
,
389 struct smbXcli_session
*session
,
390 struct smbXcli_tcon
*tcon
,
393 uint64_t fid_persistent
,
394 uint64_t fid_volatile
,
395 uint64_t minimum_count
,
396 uint64_t remaining_bytes
,
399 uint32_t *data_length
);
401 struct tevent_req
*smb2cli_write_send(TALLOC_CTX
*mem_ctx
,
402 struct tevent_context
*ev
,
403 struct smbXcli_conn
*conn
,
404 uint32_t timeout_msec
,
405 struct smbXcli_session
*session
,
406 struct smbXcli_tcon
*tcon
,
409 uint64_t fid_persistent
,
410 uint64_t fid_volatile
,
411 uint32_t remaining_bytes
,
413 const uint8_t *data
);
414 NTSTATUS
smb2cli_write_recv(struct tevent_req
*req
);
415 NTSTATUS
smb2cli_write(struct smbXcli_conn
*conn
,
416 uint32_t timeout_msec
,
417 struct smbXcli_session
*session
,
418 struct smbXcli_tcon
*tcon
,
421 uint64_t fid_persistent
,
422 uint64_t fid_volatile
,
423 uint32_t remaining_bytes
,
425 const uint8_t *data
);
427 struct tevent_req
*smb2cli_flush_send(TALLOC_CTX
*mem_ctx
,
428 struct tevent_context
*ev
,
429 struct smbXcli_conn
*conn
,
430 uint32_t timeout_msec
,
431 struct smbXcli_session
*session
,
432 struct smbXcli_tcon
*tcon
,
433 uint64_t fid_persistent
,
434 uint64_t fid_volatile
);
435 NTSTATUS
smb2cli_flush_recv(struct tevent_req
*req
);
436 NTSTATUS
smb2cli_flush(struct smbXcli_conn
*conn
,
437 uint32_t timeout_msec
,
438 struct smbXcli_session
*session
,
439 struct smbXcli_tcon
*tcon
,
440 uint64_t fid_persistent
,
441 uint64_t fid_volatile
);
443 struct tevent_req
*smb2cli_set_info_send(TALLOC_CTX
*mem_ctx
,
444 struct tevent_context
*ev
,
445 struct smbXcli_conn
*conn
,
446 uint32_t timeout_msec
,
447 struct smbXcli_session
*session
,
448 struct smbXcli_tcon
*tcon
,
449 uint8_t in_info_type
,
450 uint8_t in_file_info_class
,
451 const DATA_BLOB
*in_input_buffer
,
452 uint32_t in_additional_info
,
453 uint64_t in_fid_persistent
,
454 uint64_t in_fid_volatile
);
455 NTSTATUS
smb2cli_set_info_recv(struct tevent_req
*req
);
456 NTSTATUS
smb2cli_set_info(struct smbXcli_conn
*conn
,
457 uint32_t timeout_msec
,
458 struct smbXcli_session
*session
,
459 struct smbXcli_tcon
*tcon
,
460 uint8_t in_info_type
,
461 uint8_t in_file_info_class
,
462 const DATA_BLOB
*in_input_buffer
,
463 uint32_t in_additional_info
,
464 uint64_t in_fid_persistent
,
465 uint64_t in_fid_volatile
);
467 struct tevent_req
*smb2cli_query_info_send(TALLOC_CTX
*mem_ctx
,
468 struct tevent_context
*ev
,
469 struct smbXcli_conn
*conn
,
470 uint32_t timeout_msec
,
471 struct smbXcli_session
*session
,
472 struct smbXcli_tcon
*tcon
,
473 uint8_t in_info_type
,
474 uint8_t in_file_info_class
,
475 uint32_t in_max_output_length
,
476 const DATA_BLOB
*in_input_buffer
,
477 uint32_t in_additional_info
,
479 uint64_t in_fid_persistent
,
480 uint64_t in_fid_volatile
);
481 NTSTATUS
smb2cli_query_info_recv(struct tevent_req
*req
,
483 DATA_BLOB
*out_output_buffer
);
484 NTSTATUS
smb2cli_query_info(struct smbXcli_conn
*conn
,
485 uint32_t timeout_msec
,
486 struct smbXcli_session
*session
,
487 struct smbXcli_tcon
*tcon
,
488 uint8_t in_info_type
,
489 uint8_t in_file_info_class
,
490 uint32_t in_max_output_length
,
491 const DATA_BLOB
*in_input_buffer
,
492 uint32_t in_additional_info
,
494 uint64_t in_fid_persistent
,
495 uint64_t in_fid_volatile
,
497 DATA_BLOB
*out_output_buffer
);
499 struct tevent_req
*smb2cli_query_directory_send(TALLOC_CTX
*mem_ctx
,
500 struct tevent_context
*ev
,
501 struct smbXcli_conn
*conn
,
502 uint32_t timeout_msec
,
503 struct smbXcli_session
*session
,
504 struct smbXcli_tcon
*tcon
,
508 uint64_t fid_persistent
,
509 uint64_t fid_volatile
,
511 uint32_t outbuf_len
);
512 NTSTATUS
smb2cli_query_directory_recv(struct tevent_req
*req
,
515 uint32_t *data_length
);
516 NTSTATUS
smb2cli_query_directory(struct smbXcli_conn
*conn
,
517 uint32_t timeout_msec
,
518 struct smbXcli_session
*session
,
519 struct smbXcli_tcon
*tcon
,
523 uint64_t fid_persistent
,
524 uint64_t fid_volatile
,
529 uint32_t *data_length
);
531 struct tevent_req
*smb2cli_ioctl_send(TALLOC_CTX
*mem_ctx
,
532 struct tevent_context
*ev
,
533 struct smbXcli_conn
*conn
,
534 uint32_t timeout_msec
,
535 struct smbXcli_session
*session
,
536 struct smbXcli_tcon
*tcon
,
537 uint64_t in_fid_persistent
,
538 uint64_t in_fid_volatile
,
539 uint32_t in_ctl_code
,
540 uint32_t in_max_input_length
,
541 const DATA_BLOB
*in_input_buffer
,
542 uint32_t in_max_output_length
,
543 const DATA_BLOB
*in_output_buffer
,
545 NTSTATUS
smb2cli_ioctl_recv(struct tevent_req
*req
,
547 DATA_BLOB
*out_input_buffer
,
548 DATA_BLOB
*out_output_buffer
);
549 NTSTATUS
smb2cli_ioctl(struct smbXcli_conn
*conn
,
550 uint32_t timeout_msec
,
551 struct smbXcli_session
*session
,
552 struct smbXcli_tcon
*tcon
,
553 uint64_t in_fid_persistent
,
554 uint64_t in_fid_volatile
,
555 uint32_t in_ctl_code
,
556 uint32_t in_max_input_length
,
557 const DATA_BLOB
*in_input_buffer
,
558 uint32_t in_max_output_length
,
559 const DATA_BLOB
*in_output_buffer
,
562 DATA_BLOB
*out_input_buffer
,
563 DATA_BLOB
*out_output_buffer
);
565 #endif /* _SMBXCLI_BASE_H_ */