d6ca29f8a7dac13ef2ca5cd427fd3c5e6825b732
[ira/wip.git] / source4 / libcli / ldap / ldap_client.h
1 /* 
2    Unix SMB/CIFS Implementation.
3
4    ldap client side header
5
6    Copyright (C) Andrew Tridgell 2005
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
23 #include "libcli/ldap/ldap.h"
24
25 enum ldap_request_state { LDAP_REQUEST_SEND=1, LDAP_REQUEST_PENDING=2, LDAP_REQUEST_DONE=3, LDAP_REQUEST_ERROR=4 };
26
27 /* this is the handle that the caller gets when an async ldap message
28    is sent */
29 struct ldap_request {
30         struct ldap_request *next, *prev;
31         struct ldap_connection *conn;
32
33         enum ldap_request_tag type;
34         int messageid;
35         enum ldap_request_state state;
36
37         int num_replies;
38         struct ldap_message **replies;
39
40         /* mark while we are processing replies
41          * in request of type LDAP_TAG_SearchRequest */
42         bool in_dispatch_replies;
43
44         NTSTATUS status;
45         DATA_BLOB data;
46         struct {
47                 void (*fn)(struct ldap_request *);
48                 void *private_data;
49         } async;
50
51         struct tevent_timer *time_event;
52 };
53
54
55 /* main context for a ldap client connection */
56 struct ldap_connection {
57         struct socket_context *sock;
58         struct loadparm_context *lp_ctx;
59
60         char *host;
61         uint16_t port;
62         bool ldaps;
63
64         const char *auth_dn;
65         const char *simple_pw;
66
67         struct {
68                 char *url;
69                 int max_retries;
70                 int retries;
71                 time_t previous;
72         } reconnect;
73
74         struct {
75                 enum { LDAP_BIND_SIMPLE, LDAP_BIND_SASL } type;
76                 void *creds;
77         } bind;
78
79         /* next message id to assign */
80         unsigned next_messageid;
81
82         /* Outstanding LDAP requests that have not yet been replied to */
83         struct ldap_request *pending;
84
85         /* Let's support SASL */
86         struct gensec_security *gensec;
87
88         /* the default timeout for messages */
89         int timeout;
90
91         /* last error message */
92         char *last_error;
93
94         struct {
95                 struct tevent_context *event_ctx;
96                 struct tevent_fd *fde;
97         } event;
98
99         struct packet_context *packet;
100 };
101
102 struct ldap_connection *ldap4_new_connection(TALLOC_CTX *mem_ctx, 
103                                              struct loadparm_context *lp_ctx,
104                                              struct tevent_context *ev);
105
106 NTSTATUS ldap_connect(struct ldap_connection *conn, const char *url);
107 struct composite_context *ldap_connect_send(struct ldap_connection *conn,
108                                             const char *url);
109
110 NTSTATUS ldap_rebind(struct ldap_connection *conn);
111 NTSTATUS ldap_bind_simple(struct ldap_connection *conn, 
112                           const char *userdn, const char *password);
113 NTSTATUS ldap_bind_sasl(struct ldap_connection *conn, 
114                         struct cli_credentials *creds,
115                         struct loadparm_context *lp_ctx);
116 struct ldap_request *ldap_request_send(struct ldap_connection *conn,
117                                        struct ldap_message *msg);
118 NTSTATUS ldap_request_wait(struct ldap_request *req);
119 struct composite_context;
120 NTSTATUS ldap_connect_recv(struct composite_context *ctx);
121 NTSTATUS ldap_result_n(struct ldap_request *req, int n, struct ldap_message **msg);
122 NTSTATUS ldap_result_one(struct ldap_request *req, struct ldap_message **msg, int type);
123 NTSTATUS ldap_transaction(struct ldap_connection *conn, struct ldap_message *msg);
124 const char *ldap_errstr(struct ldap_connection *conn, 
125                         TALLOC_CTX *mem_ctx, 
126                         NTSTATUS status);
127 NTSTATUS ldap_check_response(struct ldap_connection *conn, struct ldap_Result *r);
128 void ldap_set_reconn_params(struct ldap_connection *conn, int max_retries);
129 int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res);
130 NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn, 
131                              int scope, struct ldb_parse_tree *tree,
132                              const char * const *attrs, bool attributesonly, 
133                              struct ldb_control **control_req,
134                              struct ldb_control ***control_res,
135                              struct ldap_message ***results);
136 NTSTATUS ildap_search(struct ldap_connection *conn, const char *basedn, 
137                       int scope, const char *expression, 
138                       const char * const *attrs, bool attributesonly, 
139                       struct ldb_control **control_req,
140                       struct ldb_control ***control_res,
141                       struct ldap_message ***results);
142
143
144