summaryrefslogtreecommitdiffstats
path: root/source4/libcli/ldap/ldap_client.h
blob: e2b1b30e49395227efd65e89181a6db4d68e838b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* 
   Unix SMB/CIFS Implementation.

   ldap client side header

   Copyright (C) Andrew Tridgell 2005
    
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "system/network.h" /* for struct iovec */
#include "libcli/ldap/libcli_ldap.h"

enum ldap_request_state { LDAP_REQUEST_SEND=1, LDAP_REQUEST_PENDING=2, LDAP_REQUEST_DONE=3, LDAP_REQUEST_ERROR=4 };

/* this is the handle that the caller gets when an async ldap message
   is sent */
struct ldap_request {
	struct ldap_request *next, *prev;
	struct ldap_connection *conn;

	enum ldap_request_tag type;
	int messageid;
	enum ldap_request_state state;

	int num_replies;
	struct ldap_message **replies;

	NTSTATUS status;
	DATA_BLOB data;
	struct iovec write_iov;

	struct {
		void (*fn)(struct ldap_request *);
		void *private_data;
	} async;

	struct tevent_timer *time_event;
};


/* main context for a ldap client connection */
struct ldap_connection {
	struct {
		struct tstream_context *raw;
		struct tstream_context *tls;
		struct tstream_context *sasl;
		struct tstream_context *active;

		struct tevent_queue *send_queue;
		struct tevent_req *recv_subreq;
	} sockets;

	struct loadparm_context *lp_ctx;

	char *host;
	uint16_t port;
	bool ldaps;

	const char *auth_dn;
	const char *simple_pw;

	struct {
		char *url;
		int max_retries;
		int retries;
		time_t previous;
	} reconnect;

	struct {
		enum { LDAP_BIND_SIMPLE, LDAP_BIND_SASL } type;
		void *creds;
	} bind;

	/* next message id to assign */
	unsigned next_messageid;

	/* Outstanding LDAP requests that have not yet been replied to */
	struct ldap_request *pending;

	/* Let's support SASL */
	struct gensec_security *gensec;

	/* the default timeout for messages */
	int timeout;

	/* last error message */
	char *last_error;

	struct {
		struct tevent_context *event_ctx;
	} event;
};

struct ldap_connection *ldap4_new_connection(TALLOC_CTX *mem_ctx, 
					     struct loadparm_context *lp_ctx,
					     struct tevent_context *ev);

NTSTATUS ldap_connect(struct ldap_connection *conn, const char *url);
struct composite_context *ldap_connect_send(struct ldap_connection *conn,
					    const char *url);

NTSTATUS ldap_rebind(struct ldap_connection *conn);
NTSTATUS ldap_bind_simple(struct ldap_connection *conn, 
			  const char *userdn, const char *password);
NTSTATUS ldap_bind_sasl(struct ldap_connection *conn, 
			struct cli_credentials *creds,
			struct loadparm_context *lp_ctx);
struct ldap_request *ldap_request_send(struct ldap_connection *conn,
				       struct ldap_message *msg);
NTSTATUS ldap_request_wait(struct ldap_request *req);
struct composite_context;
NTSTATUS ldap_connect_recv(struct composite_context *ctx);
NTSTATUS ldap_result_n(struct ldap_request *req, int n, struct ldap_message **msg);
NTSTATUS ldap_result_one(struct ldap_request *req, struct ldap_message **msg, int type);
NTSTATUS ldap_transaction(struct ldap_connection *conn, struct ldap_message *msg);
const char *ldap_errstr(struct ldap_connection *conn, 
			TALLOC_CTX *mem_ctx, 
			NTSTATUS status);
NTSTATUS ldap_check_response(struct ldap_connection *conn, struct ldap_Result *r);
void ldap_set_reconn_params(struct ldap_connection *conn, int max_retries);
int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res);
NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn, 
			     int scope, struct ldb_parse_tree *tree,
			     const char * const *attrs, bool attributesonly, 
			     struct ldb_control **control_req,
			     struct ldb_control ***control_res,
			     struct ldap_message ***results);
NTSTATUS ildap_search(struct ldap_connection *conn, const char *basedn, 
		      int scope, const char *expression, 
		      const char * const *attrs, bool attributesonly, 
		      struct ldb_control **control_req,
		      struct ldb_control ***control_res,
		      struct ldap_message ***results);