summaryrefslogtreecommitdiffstats
path: root/src/lib-ldap/ldap-private.h
blob: fa724f40df966e985ac9dab3899e6aac4ce085f1 (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
#ifndef LDAP_PRIVATE_H
#define LDAP_PRIVATE_H

#include "iostream-ssl.h"
#include "ldap-client.h"

#include <ldap.h>

#define DOVE_LDAP_CONTINUE 0
#define DOVE_LDAP_COMPLETE 1
#define DOVE_LDAP_REQUEUE 2

struct ldap_connection;
struct ldap_result;

struct ldap_op_queue_entry;
/* Handle an LDAP response. Returns 0 on success, otherwise the OpenLDAP error
   number. */
typedef int ldap_response_callback_t(struct ldap_connection *conn,
				     struct ldap_op_queue_entry *entry,
				     LDAPMessage *msg, bool *finished_r);
/* Send the request. Returns 0 on success, otherwise the OpenLDAP error number
   and sets error_r string. */
typedef int ldap_send_request_t(struct ldap_connection *conn,
				struct ldap_op_queue_entry *entry,
				const char **error_r);

struct ldap_op_queue_entry {
	pool_t pool;
	struct ldap_connection *conn;
	ldap_response_callback_t *internal_response_cb;
	void *ctx;

	int msgid;

	unsigned int timeout_secs;
	struct timeout *to_abort;

	ldap_send_request_t *send_request_cb;

	ldap_result_callback_t *result_callback;
	void *result_callback_ctx;

	struct {
		struct ldap_search_input search;
		struct ldap_compare_input compare;
	} input;
};

struct ldap_connection {
	pool_t pool;
	struct ldap_client *client;

	LDAP *conn;
	enum {
		LDAP_STATE_DISCONNECT,
		LDAP_STATE_TLS,
		LDAP_STATE_AUTH,
		LDAP_STATE_CONNECT
	} state;

	BerValue cred; /* needed for SASL */
	BerVarray scred;

	struct ldap_client_settings set;
	struct ssl_iostream_settings ssl_set;

	struct aqueue *request_queue;
	ARRAY(struct ldap_op_queue_entry *) request_array;

	unsigned int sent;
	unsigned int pending;

	struct io *io;
	struct timeout *to_disconnect;
	struct timeout *to_reconnect;
};

struct ldap_attribute {
	const char *name;
	ARRAY_TYPE(const_string) values;
};

struct ldap_entry {
	struct ldap_result *result;
	char *dn;
	ARRAY(struct ldap_attribute) attributes;
	const char *const *attr_names;
};

struct ldap_result {
	pool_t pool;
	struct ldap_connection *conn;

	ARRAY(struct ldap_entry) entries;
	int openldap_ret;
	bool compare_true;
	const char *error_string;
};

struct ldap_search_iterator {
	unsigned int idx;
	struct ldap_result *result;
};

int ldap_connection_init(struct ldap_client *client,
			 const struct ldap_client_settings *set,
			 struct ldap_connection **conn_r, const char **error_r);
void ldap_connection_deinit(struct ldap_connection **_conn);
void ldap_connection_switch_ioloop(struct ldap_connection *conn);
bool ldap_connection_have_settings(struct ldap_connection *conn,
				   const struct ldap_client_settings *set);

void ldap_connection_search_start(struct ldap_connection *conn,
				  const struct ldap_search_input *input,
				  ldap_result_callback_t *callback,
				  void *context);
void ldap_connection_compare_start(struct ldap_connection *conn,
				   const struct ldap_compare_input *input,
				   ldap_result_callback_t *callback,
				   void *context);

void ldap_connection_kill(struct ldap_connection *conn);
int ldap_connection_check(struct ldap_connection *conn);
void ldap_connection_queue_request(struct ldap_connection *conn, struct ldap_op_queue_entry *req);

int ldap_entry_init(struct ldap_entry *obj, struct ldap_result *result, LDAPMessage *message);

#endif