/* [<][>][^][v][top][bottom][index][help] */
1 /*
2 Unix SMB/CIFS implementation.
3
4 a async CLDAP library
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 #include "../lib/util/asn1.h"
23 #include "../libcli/netlogon.h"
24
25 struct ldap_message;
26
27 enum cldap_request_state {CLDAP_REQUEST_SEND,
28 CLDAP_REQUEST_WAIT,
29 CLDAP_REQUEST_DONE,
30 CLDAP_REQUEST_ERROR};
31
32 /*
33 a cldap request packet
34 */
35 struct cldap_request {
36 struct cldap_request *next, *prev;
37
38 struct cldap_socket *cldap;
39
40 enum cldap_request_state state;
41 NTSTATUS status;
42
43 /* where to send the request */
44 struct socket_address *dest;
45
46 /* timeout between retries (seconds) */
47 int timeout;
48 int num_retries;
49
50 bool is_reply;
51
52 /* the ldap message_id */
53 int message_id;
54
55 struct tevent_timer *te;
56
57 /* the encoded request */
58 DATA_BLOB encoded;
59
60 /* the reply data */
61 struct asn1_data *asn1;
62
63 /* information on what to do on completion */
64 struct {
65 void (*fn)(struct cldap_request *);
66 void *private_data;
67 } async;
68 };
69
70 /*
71 context structure for operations on cldap packets
72 */
73 struct cldap_socket {
74 struct socket_context *sock;
75 struct tevent_context *event_ctx;
76 struct smb_iconv_convenience *iconv_convenience;
77
78 /* the fd event */
79 struct tevent_fd *fde;
80
81 /* a queue of outgoing requests */
82 struct cldap_request *send_queue;
83
84 /* mapping from message_id to pending request */
85 struct idr_context *idr;
86
87 /* what to do with incoming request packets */
88 struct {
89 void (*handler)(struct cldap_socket *, struct ldap_message *,
90 struct socket_address *);
91 void *private_data;
92 } incoming;
93 };
94
95
96 /*
97 a general cldap search request
98 */
99 struct cldap_search {
100 struct {
101 const char *dest_address;
102 uint16_t dest_port;
103 const char *filter;
104 const char **attributes;
105 int timeout;
106 int retries;
107 } in;
108 struct {
109 struct ldap_SearchResEntry *response;
110 struct ldap_Result *result;
111 } out;
112 };
113
114 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx,
115 struct tevent_context *event_ctx,
116 struct smb_iconv_convenience *iconv_convenience);
117 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
118 void (*handler)(struct cldap_socket *, struct ldap_message *,
119 struct socket_address *),
120 void *private_data);
121 struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
122 struct cldap_search *io);
123 NTSTATUS cldap_search_recv(struct cldap_request *req, TALLOC_CTX *mem_ctx,
124 struct cldap_search *io);
125 NTSTATUS cldap_search(struct cldap_socket *cldap, TALLOC_CTX *mem_ctx,
126 struct cldap_search *io);
127
128
129 /*
130 a general cldap reply
131 */
132 struct cldap_reply {
133 uint32_t messageid;
134 struct socket_address *dest;
135 struct ldap_SearchResEntry *response;
136 struct ldap_Result *result;
137 };
138
139 NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io);
140
141 NTSTATUS cldap_empty_reply(struct cldap_socket *cldap,
142 uint32_t message_id,
143 struct socket_address *src);
144 NTSTATUS cldap_error_reply(struct cldap_socket *cldap,
145 uint32_t message_id,
146 struct socket_address *src,
147 int resultcode,
148 const char *errormessage);
149
150 /*
151 a netlogon cldap request
152 */
153 struct cldap_netlogon {
154 struct {
155 const char *dest_address;
156 uint16_t dest_port;
157 const char *realm;
158 const char *host;
159 const char *user;
160 const char *domain_guid;
161 const char *domain_sid;
162 int acct_control;
163 uint32_t version;
164 bool map_response;
165 } in;
166 struct {
167 struct netlogon_samlogon_response netlogon;
168 } out;
169 };
170
171 struct cldap_request *cldap_netlogon_send(struct cldap_socket *cldap,
172 struct cldap_netlogon *io);
173 NTSTATUS cldap_netlogon_recv(struct cldap_request *req,
174 TALLOC_CTX *mem_ctx,
175 struct cldap_netlogon *io);
176 NTSTATUS cldap_netlogon(struct cldap_socket *cldap,
177 TALLOC_CTX *mem_ctx, struct cldap_netlogon *io);
178 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
179 uint32_t message_id,
180 struct socket_address *src,
181 uint32_t version,
182 struct netlogon_samlogon_response *netlogon);