s3:rpc_client: add rpccli_is_connected()
[metze/samba/wip.git] / source3 / include / client.h
1 /*
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Luke Kenneth Casson Leighton 1996-1998
6    Copyright (C) Jeremy Allison 1998
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _CLIENT_H
23 #define _CLIENT_H
24
25 /* the client asks for a smaller buffer to save ram and also to get more
26    overlap on the wire. This size gives us a nice read/write size, which
27    will be a multiple of the page size on almost any system */
28 #define CLI_BUFFER_SIZE (0xFFFF)
29 #define CLI_SAMBA_MAX_LARGE_READX_SIZE (127*1024) /* Works for Samba servers */
30 #define CLI_SAMBA_MAX_LARGE_WRITEX_SIZE (127*1024) /* Works for Samba servers */
31 #define CLI_WINDOWS_MAX_LARGE_READX_SIZE ((64*1024)-2) /* Windows servers are broken.... */
32 #define CLI_WINDOWS_MAX_LARGE_WRITEX_SIZE ((64*1024)-2) /* Windows servers are broken.... */
33 #define CLI_SAMBA_MAX_POSIX_LARGE_READX_SIZE (0xFFFF00) /* 24-bit len. */
34 #define CLI_SAMBA_MAX_POSIX_LARGE_WRITEX_SIZE (0xFFFF00) /* 24-bit len. */
35
36 /*
37  * These definitions depend on smb.h
38  */
39
40 struct print_job_info {
41         uint16 id;
42         uint16 priority;
43         size_t size;
44         fstring user;
45         fstring name;
46         time_t t;
47 };
48
49 struct cli_pipe_auth_data {
50         enum pipe_auth_type auth_type; /* switch for the union below. Defined in ntdomain.h */
51         enum pipe_auth_level auth_level; /* defined in ntdomain.h */
52
53         char *domain;
54         char *user_name;
55         DATA_BLOB user_session_key;
56
57         union {
58                 struct schannel_auth_struct *schannel_auth;
59                 NTLMSSP_STATE *ntlmssp_state;
60                 struct kerberos_auth_struct *kerberos_auth;
61         } a_u;
62 };
63
64 /**
65  * rpc_cli_transport defines a transport mechanism to ship rpc requests
66  * asynchronously to a server and receive replies
67  */
68
69 struct rpc_cli_transport {
70
71         enum dcerpc_transport_t transport;
72
73         /**
74          * Trigger an async read from the server. May return a short read.
75          */
76         struct async_req *(*read_send)(TALLOC_CTX *mem_ctx,
77                                        struct event_context *ev,
78                                        uint8_t *data, size_t size,
79                                        void *priv);
80         /**
81          * Get the result from the read_send operation.
82          */
83         NTSTATUS (*read_recv)(struct async_req *req, ssize_t *preceived);
84
85         /**
86          * Trigger an async write to the server. May return a short write.
87          */
88         struct async_req *(*write_send)(TALLOC_CTX *mem_ctx,
89                                         struct event_context *ev,
90                                         const uint8_t *data, size_t size,
91                                         void *priv);
92         /**
93          * Get the result from the read_send operation.
94          */
95         NTSTATUS (*write_recv)(struct async_req *req, ssize_t *psent);
96
97         /**
98          * This is an optimization for the SMB transport. It models the
99          * TransactNamedPipe API call: Send and receive data in one round
100          * trip. The transport implementation is free to set this to NULL,
101          * cli_pipe.c will fall back to the explicit write/read routines.
102          */
103         struct async_req *(*trans_send)(TALLOC_CTX *mem_ctx,
104                                         struct event_context *ev,
105                                         uint8_t *data, size_t data_len,
106                                         uint32_t max_rdata_len,
107                                         void *priv);
108         /**
109          * Get the result from the trans_send operation.
110          */
111         NTSTATUS (*trans_recv)(struct async_req *req, TALLOC_CTX *mem_ctx,
112                                uint8_t **prdata, uint32_t *prdata_len);
113
114         bool (*is_connected)(void *priv);
115
116         void *priv;
117 };
118
119 struct rpc_pipe_client {
120         struct rpc_pipe_client *prev, *next;
121
122         struct rpc_cli_transport *transport;
123
124         struct ndr_syntax_id abstract_syntax;
125         struct ndr_syntax_id transfer_syntax;
126
127         NTSTATUS (*dispatch) (struct rpc_pipe_client *cli,
128                         TALLOC_CTX *mem_ctx,
129                         const struct ndr_interface_table *table,
130                         uint32_t opnum, void *r);
131
132         char *desthost;
133         char *srv_name_slash;
134
135         uint16 max_xmit_frag;
136         uint16 max_recv_frag;
137
138         struct cli_pipe_auth_data *auth;
139
140         /* The following is only non-null on a netlogon pipe. */
141         struct dcinfo *dc;
142
143         /* Used by internal rpc_pipe_client */
144         pipes_struct *pipes_struct;
145 };
146
147 /* Transport encryption state. */
148 enum smb_trans_enc_type {
149                 SMB_TRANS_ENC_NTLM
150 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
151                 , SMB_TRANS_ENC_GSS
152 #endif
153 };
154
155 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
156 struct smb_tran_enc_state_gss {
157         gss_ctx_id_t gss_ctx;
158         gss_cred_id_t creds;
159 };
160 #endif
161
162 struct smb_trans_enc_state {
163         enum smb_trans_enc_type smb_enc_type;
164         uint16 enc_ctx_num;
165         bool enc_on;
166         union {
167                 NTLMSSP_STATE *ntlmssp_state;
168 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
169                 struct smb_tran_enc_state_gss *gss_state;
170 #endif
171         } s;
172 };
173
174 struct cli_state {
175         /**
176          * A list of subsidiary connections for DFS.
177          */
178         struct cli_state *prev, *next;
179         int port;
180         int fd;
181         /* Last read or write error. */
182         enum smb_read_errors smb_rw_error;
183         uint16 cnum;
184         uint16 pid;
185         uint16 mid;
186         uint16 vuid;
187         int protocol;
188         int sec_mode;
189         int rap_error;
190         int privileges;
191
192         fstring desthost;
193
194         /* The credentials used to open the cli_state connection. */
195         char *domain;
196         char *user_name;
197         char *password; /* Can be null to force use of zero NTLMSSP session key. */
198
199         /*
200          * The following strings are the
201          * ones returned by the server if
202          * the protocol > NT1.
203          */
204         fstring server_type;
205         fstring server_os;
206         fstring server_domain;
207
208         fstring share;
209         fstring dev;
210         struct nmb_name called;
211         struct nmb_name calling;
212         fstring full_dest_host_name;
213         struct sockaddr_storage dest_ss;
214
215         DATA_BLOB secblob; /* cryptkey or negTokenInit */
216         uint32 sesskey;
217         int serverzone;
218         uint32 servertime;
219         int readbraw_supported;
220         int writebraw_supported;
221         int timeout; /* in milliseconds. */
222         size_t max_xmit;
223         size_t max_mux;
224         char *outbuf;
225         char *inbuf;
226         unsigned int bufsize;
227         int initialised;
228         int win95;
229         bool is_samba;
230         uint32 capabilities;
231         uint32 posix_capabilities;
232         bool dfsroot;
233
234 #if 0
235         TALLOC_CTX *longterm_mem_ctx;
236         TALLOC_CTX *call_mem_ctx;
237 #endif
238
239         smb_sign_info sign_info;
240
241         struct smb_trans_enc_state *trans_enc_state; /* Setup if we're encrypting SMB's. */
242
243         /* the session key for this CLI, outside
244            any per-pipe authenticaion */
245         DATA_BLOB user_session_key;
246
247         /* The list of pipes currently open on this connection. */
248         struct rpc_pipe_client *pipe_list;
249
250         bool use_kerberos;
251         bool fallback_after_kerberos;
252         bool use_spnego;
253         bool got_kerberos_mechanism; /* Server supports krb5 in SPNEGO. */
254
255         bool use_oplocks; /* should we use oplocks? */
256         bool use_level_II_oplocks; /* should we use level II oplocks? */
257
258         /* a oplock break request handler */
259         bool (*oplock_handler)(struct cli_state *cli, int fnum, unsigned char level);
260
261         bool force_dos_errors;
262         bool case_sensitive; /* False by default. */
263
264         /**
265          * fd_event is around while we have async requests outstanding or are
266          * building a chained request.
267          *
268          * (fd_event!=NULL) &&
269          *  ((outstanding_request!=NULL)||(chain_accumulator!=NULL))
270          *
271          * should always be true, as well as the reverse: If both cli_request
272          * pointers are NULL, no fd_event is around.
273          */
274         struct fd_event *fd_event;
275         char *evt_inbuf;
276
277         /**
278          * A linked list of requests that are waiting for a reply
279          */
280         struct cli_request *outstanding_requests;
281
282         /**
283          * The place to build up the list of chained requests. In CIFS, a
284          * single cli_request corresponds to a MID and can serve more than one
285          * chained async_req.
286          */
287         struct cli_request *chain_accumulator;
288
289         /* Where (if anywhere) this is mounted under DFS. */
290         char *dfs_mountpoint;
291 };
292
293 typedef struct file_info {
294         struct cli_state *cli;
295         uint64_t size;
296         uint16 mode;
297         uid_t uid;
298         gid_t gid;
299         /* these times are normally kept in GMT */
300         struct timespec mtime_ts;
301         struct timespec atime_ts;
302         struct timespec ctime_ts;
303         char *name;
304         char short_name[13*3]; /* the *3 is to cope with multi-byte */
305 } file_info;
306
307 #define CLI_FULL_CONNECTION_DONT_SPNEGO 0x0001
308 #define CLI_FULL_CONNECTION_USE_KERBEROS 0x0002
309 #define CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK 0x0004
310 #define CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS 0x0008
311
312 #endif /* _CLIENT_H */