r23030: finally fixed up our asn1 code to use better memory allocation. This
[kamenim/samba.git] / source4 / libcli / cldap / cldap.h
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "libcli/util/asn_1.h"
24 #include "librpc/gen_ndr/nbt.h"
25
26 struct ldap_message;
27
28 enum cldap_request_state {CLDAP_REQUEST_SEND, 
29                           CLDAP_REQUEST_WAIT, 
30                           CLDAP_REQUEST_DONE,
31                           CLDAP_REQUEST_ERROR};
32
33 /*
34   a cldap request packet
35 */
36 struct cldap_request {
37         struct cldap_request *next, *prev;
38
39         struct cldap_socket *cldap;
40
41         enum cldap_request_state state;
42         NTSTATUS status;
43
44         /* where to send the request */
45         struct socket_address *dest;
46
47         /* timeout between retries (seconds) */
48         int timeout;
49         int num_retries;
50
51         BOOL is_reply;
52
53         /* the ldap message_id */
54         int message_id;
55
56         struct timed_event *te;
57
58         /* the encoded request */
59         DATA_BLOB encoded;
60
61         /* the reply data */
62         struct asn1_data *asn1;
63
64         /* information on what to do on completion */
65         struct {
66                 void (*fn)(struct cldap_request *);
67                 void *private;
68         } async;
69 };
70
71 /*
72   context structure for operations on cldap packets
73 */
74 struct cldap_socket {
75         struct socket_context *sock;
76         struct event_context *event_ctx;
77
78         /* the fd event */
79         struct fd_event *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;
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                 const char *filter;
103                 const char **attributes;
104                 int timeout;
105                 int retries;
106         } in;
107         struct {
108                 struct ldap_SearchResEntry *response;
109                 struct ldap_Result         *result;
110         } out;
111 };
112
113 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx, 
114                                        struct event_context *event_ctx);
115 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
116                                     void (*handler)(struct cldap_socket *, struct ldap_message *, 
117                                                     struct socket_address *),
118                                     void *private);
119 struct cldap_request *cldap_search_send(struct cldap_socket *cldap, 
120                                         struct cldap_search *io);
121 NTSTATUS cldap_search_recv(struct cldap_request *req, TALLOC_CTX *mem_ctx, 
122                            struct cldap_search *io);
123 NTSTATUS cldap_search(struct cldap_socket *cldap, TALLOC_CTX *mem_ctx, 
124                       struct cldap_search *io);
125
126
127 /*
128   a general cldap reply
129 */
130 struct cldap_reply {
131         uint32_t messageid;
132         struct socket_address *dest;
133         struct ldap_SearchResEntry *response;
134         struct ldap_Result         *result;
135 };
136
137 NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io);
138
139 NTSTATUS cldap_empty_reply(struct cldap_socket *cldap, 
140                            uint32_t message_id,
141                            struct socket_address *src);
142 NTSTATUS cldap_error_reply(struct cldap_socket *cldap, 
143                            uint32_t message_id,
144                            struct socket_address *src,
145                            int resultcode,
146                            const char *errormessage);
147
148 /*
149   a netlogon cldap request  
150 */
151 struct cldap_netlogon {
152         struct {
153                 const char *dest_address;
154                 const char *realm;
155                 const char *host;
156                 const char *user;
157                 const char *domain_guid;
158                 const char *domain_sid;
159                 int acct_control;
160                 uint32_t version;
161         } in;
162         struct {
163                 union nbt_cldap_netlogon netlogon;
164         } out;
165 };
166
167 struct cldap_request *cldap_netlogon_send(struct cldap_socket *cldap, 
168                                           struct cldap_netlogon *io);
169 NTSTATUS cldap_netlogon_recv(struct cldap_request *req, 
170                              TALLOC_CTX *mem_ctx, 
171                              struct cldap_netlogon *io);
172 NTSTATUS cldap_netlogon(struct cldap_socket *cldap, 
173                         TALLOC_CTX *mem_ctx, struct cldap_netlogon *io);
174 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap, 
175                               uint32_t message_id,
176                               struct socket_address *src,
177                               uint32_t version,
178                               union nbt_cldap_netlogon *netlogon);