smbXcli: rework smb2cli_req to smbXcli_conn/smbXcli_req
[gd/samba-autobuild/.git] / libcli / smb / smbXcli_base.h
1 /*
2    Unix SMB/CIFS implementation.
3    Infrastructure for async SMB client requests
4    Copyright (C) Volker Lendecke 2008
5    Copyright (C) Stefan Metzmacher 2011
6
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.
11
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.
16
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/>.
19 */
20
21 #ifndef _SMBXCLI_BASE_H_
22 #define _SMBXCLI_BASE_H_
23
24 struct smbXcli_conn;
25 struct smb_trans_enc_state;
26
27 struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx,
28                                          int fd,
29                                          const char *remote_name,
30                                          enum smb_signing_setting signing_state,
31                                          uint32_t smb1_capabilities);
32
33 bool smbXcli_conn_is_connected(struct smbXcli_conn *conn);
34 void smbXcli_conn_disconnect(struct smbXcli_conn *conn, NTSTATUS status);
35
36 bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn);
37
38 enum protocol_types smbXcli_conn_protocol(struct smbXcli_conn *conn);
39 bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn);
40
41 void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options);
42 const struct sockaddr_storage *smbXcli_conn_local_sockaddr(struct smbXcli_conn *conn);
43 const struct sockaddr_storage *smbXcli_conn_remote_sockaddr(struct smbXcli_conn *conn);
44 const char *smbXcli_conn_remote_name(struct smbXcli_conn *conn);
45
46 void smbXcli_req_unset_pending(struct tevent_req *req);
47 bool smbXcli_req_set_pending(struct tevent_req *req);
48
49 bool smb1cli_conn_activate_signing(struct smbXcli_conn *conn,
50                                    const DATA_BLOB user_session_key,
51                                    const DATA_BLOB response);
52 bool smb1cli_conn_check_signing(struct smbXcli_conn *conn,
53                                 const uint8_t *buf, uint32_t seqnum);
54 bool smb1cli_conn_signing_is_active(struct smbXcli_conn *conn);
55
56 void smb1cli_conn_set_encryption(struct smbXcli_conn *conn,
57                                  struct smb_trans_enc_state *es);
58 bool smb1cli_conn_encryption_on(struct smbXcli_conn *conn);
59
60 bool smb1cli_is_andx_req(uint8_t cmd);
61 size_t smb1cli_req_wct_ofs(struct tevent_req **reqs, int num_reqs);
62
63 uint16_t smb1cli_req_mid(struct tevent_req *req);
64 void smb1cli_req_set_mid(struct tevent_req *req, uint16_t mid);
65
66 uint32_t smb1cli_req_seqnum(struct tevent_req *req);
67 void smb1cli_req_set_seqnum(struct tevent_req *req, uint32_t seqnum);
68
69 struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx,
70                                       struct tevent_context *ev,
71                                       struct smbXcli_conn *conn,
72                                       uint8_t smb_command,
73                                       uint8_t additional_flags,
74                                       uint8_t clear_flags,
75                                       uint16_t additional_flags2,
76                                       uint16_t clear_flags2,
77                                       uint32_t timeout_msec,
78                                       uint32_t pid,
79                                       uint16_t tid,
80                                       uint16_t uid,
81                                       uint8_t wct, uint16_t *vwv,
82                                       int iov_count,
83                                       struct iovec *bytes_iov);
84 NTSTATUS smb1cli_req_chain_submit(struct tevent_req **reqs, int num_reqs);
85
86 struct tevent_req *smb1cli_req_send(TALLOC_CTX *mem_ctx,
87                                     struct tevent_context *ev,
88                                     struct smbXcli_conn *conn,
89                                     uint8_t smb_command,
90                                     uint8_t additional_flags,
91                                     uint8_t clear_flags,
92                                     uint16_t additional_flags2,
93                                     uint16_t clear_flags2,
94                                     uint32_t timeout_msec,
95                                     uint32_t pid,
96                                     uint16_t tid,
97                                     uint16_t uid,
98                                     uint8_t wct, uint16_t *vwv,
99                                     uint32_t num_bytes,
100                                     const uint8_t *bytes);
101 NTSTATUS smb1cli_req_recv(struct tevent_req *req,
102                           TALLOC_CTX *mem_ctx, uint8_t **pinbuf,
103                           uint8_t min_wct, uint8_t *pwct, uint16_t **pvwv,
104                           uint32_t *pnum_bytes, uint8_t **pbytes);
105
106 struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
107                                       struct tevent_context *ev,
108                                       struct smbXcli_conn *conn,
109                                       uint16_t cmd,
110                                       uint32_t additional_flags,
111                                       uint32_t clear_flags,
112                                       uint32_t timeout_msec,
113                                       uint32_t pid,
114                                       uint32_t tid,
115                                       uint64_t uid,
116                                       const uint8_t *fixed,
117                                       uint16_t fixed_len,
118                                       const uint8_t *dyn,
119                                       uint32_t dyn_len);
120 NTSTATUS smb2cli_req_compound_submit(struct tevent_req **reqs,
121                                      int num_reqs);
122
123 struct smb2cli_req_expected_response {
124         NTSTATUS status;
125         uint16_t body_size;
126 };
127
128 struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
129                                     struct tevent_context *ev,
130                                     struct smbXcli_conn *conn,
131                                     uint16_t cmd,
132                                     uint32_t additional_flags,
133                                     uint32_t clear_flags,
134                                     uint32_t timeout_msec,
135                                     uint32_t pid,
136                                     uint32_t tid,
137                                     uint64_t uid,
138                                     const uint8_t *fixed,
139                                     uint16_t fixed_len,
140                                     const uint8_t *dyn,
141                                     uint32_t dyn_len);
142 NTSTATUS smb2cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
143                           struct iovec **piov,
144                           const struct smb2cli_req_expected_response *expected,
145                           size_t num_expected);
146
147 #endif /* _SMBXCLI_BASE_H_ */