-
Notifications
You must be signed in to change notification settings - Fork 0
/
LdapWrapper.h
executable file
·302 lines (208 loc) · 6.55 KB
/
LdapWrapper.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
============================================================================
Name : LdapWrapper.h
Author : Diego Marafetti
Version : 0.1
Copyright : Your copyright notice
Description : OpenLDAP Wrapper declaration file
============================================================================
*/
#include <errno.h>
#include <stdarg.h>
#include <ldap.h>
#include <stdlib.h>
#include <stdio.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef CONST
#define CONST const
#endif
typedef unsigned long ULONG;
typedef ULONG *PULONG;
typedef unsigned short USHORT;
typedef USHORT *PUSHORT;
typedef unsigned char UCHAR;
typedef UCHAR *PUCHAR;
typedef char *PSZ;
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
typedef FLOAT *PFLOAT;
typedef void VOID, *PVOID;
typedef char CHAR, *PCHAR;
typedef int INT;
typedef unsigned int UINT;
typedef unsigned int *PUINT;
typedef short SHORT;
typedef long LONG;
typedef double LONGLONG;
typedef double ULONGLONG;
typedef BYTE BOOLEAN;
typedef char **PPCHAR;
typedef LDAP *PLDAP;
typedef LDAPMessage *PLDAPMessage;
/**
* Objeto que representa una contexto
* de ejecucion LDAP
*
*/
typedef struct __LDAP_CONTEXT {
PCHAR host;
INT errorCode;
PLDAP ldap;
} LDAP_CONTEXT, *PLDAP_CONTEXT;
/**
* Objeto que representa una sesion LDAP
*
*/
typedef struct __LDAP_SESSION {
PLDAP_CONTEXT context;
PCHAR dn;
PCHAR password;
BOOLEAN started;
INT errorCode;
} LDAP_SESSION, *PLDAP_SESSION;
/**
* Attributo de una entry y operaciones sobre un
* atributo
*
*/
typedef struct __LDAP_ATTRIBUTE LDAP_ATTRIBUTE, *PLDAP_ATTRIBUTE;
struct __LDAP_ATTRIBUTE {
LDAPMod *modObj;
PLDAP_ATTRIBUTE next;
};
typedef PLDAP_ATTRIBUTE (* ATOP_CREATE_ATTRIB) (PCHAR, INT, ...);
typedef struct __LDAP_ATTRIBUTE_OP {
ATOP_CREATE_ATTRIB createAttribute;
} LDAP_ATTRIBUTE_OP, *PLDAP_ATTRIBUTE_OP;
/**
* Objeto que representa una entry
* con valores y atributos
*/
typedef struct __LDAP_ENTRY_OBJ {
PCHAR dn;
LDAPMod **ldapMod;
PLDAP_ATTRIBUTE firstAttribute;
PLDAP_ATTRIBUTE lastAttribute;
DWORD actualSize;
} LDAP_ENTRY, *PLDAP_ENTRY;
typedef PLDAP_ENTRY (* EOP_CREATE_ENTRY) ();
typedef VOID (* EOP_ADD_PARAM) (PLDAP_ENTRY, PLDAP_ATTRIBUTE);
typedef VOID (* EOP_DEL_PARAM) (PLDAP_ENTRY, PLDAP_ATTRIBUTE);
typedef VOID (* EOP_MOD_PARAM) (PLDAP_ENTRY, PLDAP_ATTRIBUTE);
typedef struct __LDAP_ENTRY_OBJ_OPERATIONS {
EOP_CREATE_ENTRY createEntry;
EOP_ADD_PARAM addAttribute;
EOP_DEL_PARAM deleteAttribute;
EOP_MOD_PARAM editAttribute;
} LDAP_ENTRY_OP, *PLDAP_ENTRY_OP;
/**
* Objetos implicados en busquedas. Iterador
* sobre resultados.
*/
typedef struct __LDAP_RESULT_SET LDAP_RESULT_SET, *PLDAP_RESULT_SET;
typedef struct __LDAP_RECORD LDAP_RECORD, *PLDAP_RECORD;
typedef struct __LDAP_ITERATOR LDAP_ITERATOR, *PLDAP_ITERATOR;
typedef struct __LDAP_RECORD_OP LDAP_RECORD_OP, *PLDAP_RECORD_OP;
typedef struct __LDAP_FIELD LDAP_FIELD, *PLDAP_FIELD;
typedef BOOLEAN (* IOP_HAS_NEXT) (PLDAP_RESULT_SET);
typedef PLDAP_RECORD (* IOP_NEXT_ENTRY) (PLDAP_RESULT_SET);
typedef BOOLEAN (* RCOP_FIELD_HAS_NEXT) (PLDAP_RECORD);
typedef PLDAP_FIELD (*RCOP_FIELD_NEXT) (PLDAP_RECORD);
struct __LDAP_FIELD {
PCHAR name;
DWORD valuesSize;
PPCHAR values;
};
struct __LDAP_RECORD {
PLDAP ldap;
PCHAR dn;
PLDAPMessage message;
BerElement *ber;
PCHAR next;
};
struct __LDAP_ITERATOR {
IOP_HAS_NEXT hasNext;
IOP_NEXT_ENTRY next;
};
struct __LDAP_RESULT_SET {
PLDAPMessage results;
PLDAPMessage next;
PLDAP_SESSION session;
PLDAP_ITERATOR iterator;
DWORD count;
};
struct __LDAP_RECORD_OP {
RCOP_FIELD_HAS_NEXT hasNextField;
RCOP_FIELD_NEXT nextField;
};
/**
* Operaciones definidas sobre una session
* LDAP.
*
*/
typedef VOID (* SOP_START_SESSION) (PLDAP_SESSION);
typedef VOID (* SOP_END_SESSION) (PLDAP_SESSION);
typedef INT (* SOP_IS_STARTED) (PLDAP_SESSION);
typedef VOID (* SOP_ADD_ENTRY) (PLDAP_SESSION, PLDAP_ENTRY);
typedef VOID (* SOP_DEL_ENTRY_DN) (PLDAP_SESSION, PCHAR);
typedef VOID (* SOP_DEL_ENTRY_OBJ) (PLDAP_SESSION, PLDAP_ENTRY);
typedef VOID (* SOP_EDIT_ENTRY) (PLDAP_SESSION, PLDAP_ENTRY);
typedef PLDAP_RESULT_SET (* SOP_SEARCH_ENTRY) (PLDAP_SESSION, PCHAR, PCHAR);
typedef VOID (* SOP_ASYN_SEARCH_ENTRY) (PLDAP_SESSION, PCHAR, PCHAR);
typedef struct __LDAP_SESSION_OPERATIONS {
SOP_START_SESSION startSession;
SOP_END_SESSION endSession;
SOP_IS_STARTED isStarted;
SOP_ADD_ENTRY addEntry;
SOP_DEL_ENTRY_DN deleteEntryDn;
SOP_DEL_ENTRY_OBJ deleteEntryObj;
SOP_EDIT_ENTRY editEntry;
SOP_SEARCH_ENTRY searchEntry;
SOP_ASYN_SEARCH_ENTRY searchEntryAsync;
} LDAP_SESSION_OP, * PLDAP_SESSION_OP;
/**
* Operaciones definidas sobre una contexto
* LDAP.
*
*/
typedef VOID (* COP_SET_OPTION) (PLDAP_CONTEXT, INT, PVOID);
typedef PVOID (* COP_GET_OPTION) (PLDAP_CONTEXT, INT);
typedef VOID (* COP_INIT_CTX) (PLDAP_CONTEXT, PCHAR);
typedef PLDAP_SESSION (* COP_NEW_SESSION) (PLDAP_CONTEXT, PCHAR, PCHAR);
typedef struct __LDAP_CONTEXT_OPERATIONS {
COP_SET_OPTION setOption;
COP_GET_OPTION getOption;
COP_INIT_CTX initialize;
COP_NEW_SESSION newSession;
} LDAP_CONTEXT_OP, *PLDAP_CONTEXT_OP;
/**
* Construtores para objetos y objetos con
* operaciones
*/
PLDAP_CONTEXT newLDAPContext();
PLDAP_SESSION newLDAPSession();
PLDAP_CONTEXT_OP newLDAPContextOperations();
PLDAP_SESSION_OP newLDAPSessionOperations();
PLDAP_ENTRY_OP newLDAPEntryOperations();
PLDAP_ATTRIBUTE_OP newLDAPAttributeOperations();
PLDAP_ITERATOR newLDAPIterator();
PLDAP_RECORD_OP newLDAPRecordOperations();
/**
* Destructores de objetos
*/
VOID freeLDAPContextOperations(PLDAP_CONTEXT_OP);
VOID freeLDAPSessionOperations(PLDAP_SESSION_OP);
VOID freeLDAPContext(PLDAP_CONTEXT);
VOID freeLDAPSession(PLDAP_SESSION);
VOID freeLDAPIterator(PLDAP_ITERATOR);
VOID freeLDAPRecordOperations(PLDAP_RECORD_OP);
VOID freeLDAPRecord(PLDAP_RECORD);
VOID freeLDAPField(PLDAP_FIELD);