r23792: convert Samba4 to GPLv3
[bbaumbach/samba-autobuild/.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 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 "libcli/util/asn_1.h"
23 #include "librpc/gen_ndr/nbt.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 timed_event *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;
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 event_context *event_ctx;
76
77         /* the fd event */
78         struct fd_event *fde;
79
80         /* a queue of outgoing requests */
81         struct cldap_request *send_queue;
82
83         /* mapping from message_id to pending request */
84         struct idr_context *idr;
85
86         /* what to do with incoming request packets */
87         struct {
88                 void (*handler)(struct cldap_socket *, struct ldap_message *, 
89                                 struct socket_address *);
90                 void *private;
91         } incoming;
92 };
93
94
95 /*
96  a general cldap search request  
97 */
98 struct cldap_search {
99         struct {
100                 const char *dest_address;
101                 const char *filter;
102                 const char **attributes;
103                 int timeout;
104                 int retries;
105         } in;
106         struct {
107                 struct ldap_SearchResEntry *response;
108                 struct ldap_Result         *result;
109         } out;
110 };
111
112 struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx, 
113                                        struct event_context *event_ctx);
114 NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
115                                     void (*handler)(struct cldap_socket *, struct ldap_message *, 
116                                                     struct socket_address *),
117                                     void *private);
118 struct cldap_request *cldap_search_send(struct cldap_socket *cldap, 
119                                         struct cldap_search *io);
120 NTSTATUS cldap_search_recv(struct cldap_request *req, TALLOC_CTX *mem_ctx, 
121                            struct cldap_search *io);
122 NTSTATUS cldap_search(struct cldap_socket *cldap, TALLOC_CTX *mem_ctx, 
123                       struct cldap_search *io);
124
125
126 /*
127   a general cldap reply
128 */
129 struct cldap_reply {
130         uint32_t messageid;
131         struct socket_address *dest;
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 NTSTATUS cldap_empty_reply(struct cldap_socket *cldap, 
139                            uint32_t message_id,
140                            struct socket_address *src);
141 NTSTATUS cldap_error_reply(struct cldap_socket *cldap, 
142                            uint32_t message_id,
143                            struct socket_address *src,
144                            int resultcode,
145                            const char *errormessage);
146
147 /*
148   a netlogon cldap request  
149 */
150 struct cldap_netlogon {
151         struct {
152                 const char *dest_address;
153                 const char *realm;
154                 const char *host;
155                 const char *user;
156                 const char *domain_guid;
157                 const char *domain_sid;
158                 int acct_control;
159                 uint32_t version;
160         } in;
161         struct {
162                 union nbt_cldap_netlogon netlogon;
163         } out;
164 };
165
166 struct cldap_request *cldap_netlogon_send(struct cldap_socket *cldap, 
167                                           struct cldap_netlogon *io);
168 NTSTATUS cldap_netlogon_recv(struct cldap_request *req, 
169                              TALLOC_CTX *mem_ctx, 
170                              struct cldap_netlogon *io);
171 NTSTATUS cldap_netlogon(struct cldap_socket *cldap, 
172                         TALLOC_CTX *mem_ctx, struct cldap_netlogon *io);
173 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap, 
174                               uint32_t message_id,
175                               struct socket_address *src,
176                               uint32_t version,
177                               union nbt_cldap_netlogon *netlogon);