r12694: Move some headers to the directory of the subsystem they belong to.
[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/ndr_nbt.h"
25
26 enum cldap_request_state {CLDAP_REQUEST_SEND, 
27                           CLDAP_REQUEST_WAIT, 
28                           CLDAP_REQUEST_DONE,
29                           CLDAP_REQUEST_TIMEOUT};
30
31 /*
32   a cldap request packet
33 */
34 struct cldap_request {
35         struct cldap_request *next, *prev;
36
37         struct cldap_socket *cldap;
38
39         enum cldap_request_state state;
40
41         /* where to send the request */
42         const char *dest_addr;
43         int dest_port;
44
45         /* timeout between retries (seconds) */
46         int timeout;
47         int num_retries;
48
49         BOOL is_reply;
50
51         /* the ldap message_id */
52         int message_id;
53
54         struct timed_event *te;
55
56         /* the encoded request */
57         DATA_BLOB encoded;
58
59         /* the reply data */
60         struct asn1_data asn1;
61
62         /* information on what to do on completion */
63         struct {
64                 void (*fn)(struct cldap_request *);
65                 void *private;
66         } async;
67 };
68
69 /*
70   context structure for operations on cldap packets
71 */
72 struct cldap_socket {
73         struct socket_context *sock;
74         struct event_context *event_ctx;
75
76         /* the fd event */
77         struct fd_event *fde;
78
79         /* a queue of outgoing requests */
80         struct cldap_request *send_queue;
81
82         /* mapping from message_id to pending request */
83         struct idr_context *idr;
84
85         /* what to do with incoming request packets */
86         struct {
87                 void (*handler)(struct cldap_socket *, struct ldap_message *, 
88                                 const char *, int );
89                 void *private;
90         } incoming;
91 };
92
93
94 /*
95  a general cldap search request  
96 */
97 struct cldap_search {
98         struct {
99                 const char *dest_address;
100                 const char *filter;
101                 const char **attributes;
102                 int timeout;
103                 int retries;
104         } in;
105         struct {
106                 struct ldap_SearchResEntry *response;
107                 struct ldap_Result         *result;
108         } out;
109 };
110
111 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx, 
112                                        struct event_context *event_ctx);
113 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
114                                     void (*handler)(struct cldap_socket *, struct ldap_message *, 
115                                                     const char *, int ),
116                                     void *private);
117 struct cldap_request *cldap_search_send(struct cldap_socket *cldap, 
118                                         struct cldap_search *io);
119 NTSTATUS cldap_search_recv(struct cldap_request *req, TALLOC_CTX *mem_ctx, 
120                            struct cldap_search *io);
121 NTSTATUS cldap_search(struct cldap_socket *cldap, TALLOC_CTX *mem_ctx, 
122                       struct cldap_search *io);
123
124
125 /*
126   a general cldap reply
127 */
128 struct cldap_reply {
129         uint32_t messageid;
130         const char *dest_address;
131         int dest_port;
132         struct ldap_SearchResEntry *response;
133         struct ldap_Result         *result;
134 };
135
136 NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io);
137
138 /*
139   a netlogon cldap request  
140 */
141 struct cldap_netlogon {
142         struct {
143                 const char *dest_address;
144                 const char *realm;
145                 const char *host;
146                 const char *user;
147                 const char *domain_guid;
148                 const char *domain_sid;
149                 int acct_control;
150                 uint32_t version;
151         } in;
152         struct {
153                 union nbt_cldap_netlogon netlogon;
154         } out;
155 };
156
157 struct cldap_request *cldap_netlogon_send(struct cldap_socket *cldap, 
158                                           struct cldap_netlogon *io);
159 NTSTATUS cldap_netlogon_recv(struct cldap_request *req, 
160                              TALLOC_CTX *mem_ctx, 
161                              struct cldap_netlogon *io);
162 NTSTATUS cldap_netlogon(struct cldap_socket *cldap, 
163                         TALLOC_CTX *mem_ctx, struct cldap_netlogon *io);
164
165
166 NTSTATUS cldap_empty_reply(struct cldap_socket *cldap, 
167                            uint32_t message_id,
168                            const char *src_address, int src_port);
169 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap, 
170                               uint32_t message_id,
171                               const char *src_address, int src_port,
172                               uint32_t version,
173                               union nbt_cldap_netlogon *netlogon);