gp: Support more global trust directories
[Samba.git] / source4 / libcli / ldap / ldap_client.h
blobe2b1b30e49395227efd65e89181a6db4d68e838b
1 /*
2 Unix SMB/CIFS Implementation.
4 ldap client side header
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
23 #include "system/network.h" /* for struct iovec */
24 #include "libcli/ldap/libcli_ldap.h"
26 enum ldap_request_state { LDAP_REQUEST_SEND=1, LDAP_REQUEST_PENDING=2, LDAP_REQUEST_DONE=3, LDAP_REQUEST_ERROR=4 };
28 /* this is the handle that the caller gets when an async ldap message
29 is sent */
30 struct ldap_request {
31 struct ldap_request *next, *prev;
32 struct ldap_connection *conn;
34 enum ldap_request_tag type;
35 int messageid;
36 enum ldap_request_state state;
38 int num_replies;
39 struct ldap_message **replies;
41 NTSTATUS status;
42 DATA_BLOB data;
43 struct iovec write_iov;
45 struct {
46 void (*fn)(struct ldap_request *);
47 void *private_data;
48 } async;
50 struct tevent_timer *time_event;
54 /* main context for a ldap client connection */
55 struct ldap_connection {
56 struct {
57 struct tstream_context *raw;
58 struct tstream_context *tls;
59 struct tstream_context *sasl;
60 struct tstream_context *active;
62 struct tevent_queue *send_queue;
63 struct tevent_req *recv_subreq;
64 } sockets;
66 struct loadparm_context *lp_ctx;
68 char *host;
69 uint16_t port;
70 bool ldaps;
72 const char *auth_dn;
73 const char *simple_pw;
75 struct {
76 char *url;
77 int max_retries;
78 int retries;
79 time_t previous;
80 } reconnect;
82 struct {
83 enum { LDAP_BIND_SIMPLE, LDAP_BIND_SASL } type;
84 void *creds;
85 } bind;
87 /* next message id to assign */
88 unsigned next_messageid;
90 /* Outstanding LDAP requests that have not yet been replied to */
91 struct ldap_request *pending;
93 /* Let's support SASL */
94 struct gensec_security *gensec;
96 /* the default timeout for messages */
97 int timeout;
99 /* last error message */
100 char *last_error;
102 struct {
103 struct tevent_context *event_ctx;
104 } event;
107 struct ldap_connection *ldap4_new_connection(TALLOC_CTX *mem_ctx,
108 struct loadparm_context *lp_ctx,
109 struct tevent_context *ev);
111 NTSTATUS ldap_connect(struct ldap_connection *conn, const char *url);
112 struct composite_context *ldap_connect_send(struct ldap_connection *conn,
113 const char *url);
115 NTSTATUS ldap_rebind(struct ldap_connection *conn);
116 NTSTATUS ldap_bind_simple(struct ldap_connection *conn,
117 const char *userdn, const char *password);
118 NTSTATUS ldap_bind_sasl(struct ldap_connection *conn,
119 struct cli_credentials *creds,
120 struct loadparm_context *lp_ctx);
121 struct ldap_request *ldap_request_send(struct ldap_connection *conn,
122 struct ldap_message *msg);
123 NTSTATUS ldap_request_wait(struct ldap_request *req);
124 struct composite_context;
125 NTSTATUS ldap_connect_recv(struct composite_context *ctx);
126 NTSTATUS ldap_result_n(struct ldap_request *req, int n, struct ldap_message **msg);
127 NTSTATUS ldap_result_one(struct ldap_request *req, struct ldap_message **msg, int type);
128 NTSTATUS ldap_transaction(struct ldap_connection *conn, struct ldap_message *msg);
129 const char *ldap_errstr(struct ldap_connection *conn,
130 TALLOC_CTX *mem_ctx,
131 NTSTATUS status);
132 NTSTATUS ldap_check_response(struct ldap_connection *conn, struct ldap_Result *r);
133 void ldap_set_reconn_params(struct ldap_connection *conn, int max_retries);
134 int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res);
135 NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn,
136 int scope, struct ldb_parse_tree *tree,
137 const char * const *attrs, bool attributesonly,
138 struct ldb_control **control_req,
139 struct ldb_control ***control_res,
140 struct ldap_message ***results);
141 NTSTATUS ildap_search(struct ldap_connection *conn, const char *basedn,
142 int scope, const char *expression,
143 const char * const *attrs, bool attributesonly,
144 struct ldb_control **control_req,
145 struct ldb_control ***control_res,
146 struct ldap_message ***results);