Export functions by ordinal, cryptnet.dll at least depends on it.
[wine] / dlls / wldap32 / add.c
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 static LDAPMod *nullattrs[] = { NULL };
35 #else
36 #define LDAP_NOT_SUPPORTED  0x5c
37 #endif
38
39 #include "winldap_private.h"
40 #include "wldap32.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43
44 ULONG ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
45 {
46     ULONG ret = LDAP_NOT_SUPPORTED;
47 #ifdef HAVE_LDAP
48     WCHAR *dnW = NULL;
49     LDAPModW **attrsW = NULL;
50
51     ret = WLDAP32_LDAP_NO_MEMORY;
52
53     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
54
55     if (!ld) return ~0UL;
56
57     if (dn) {
58         dnW = strAtoW( dn );
59         if (!dnW) goto exit;
60     }
61     if (attrs) {
62         attrsW = modarrayAtoW( attrs );
63         if (!attrsW) goto exit;
64     }
65
66     ret = ldap_addW( ld, dnW, attrsW );
67
68 exit:
69     strfreeW( dnW );
70     modarrayfreeW( attrsW );
71
72 #endif
73     return ret;
74 }
75
76 ULONG ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
77 {
78     ULONG ret = LDAP_NOT_SUPPORTED;
79 #ifdef HAVE_LDAP
80     char *dnU = NULL;
81     LDAPMod **attrsU = NULL;
82  
83     ret = WLDAP32_LDAP_NO_MEMORY;
84
85     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
86
87     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
88
89     if (dn) {
90         dnU = strWtoU( dn );
91         if (!dnU) goto exit;
92     }
93     if (attrs) {
94         attrsU = modarrayWtoU( attrs );
95         if (!attrsU) goto exit;
96     }
97
98     ret = ldap_add( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
99
100 exit:
101     strfreeU( dnU );
102     modarrayfreeU( attrsU );
103
104 #endif
105     return ret;
106 }
107
108 ULONG ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
109     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
110 {
111     ULONG ret = LDAP_NOT_SUPPORTED;
112 #ifdef HAVE_LDAP
113     WCHAR *dnW = NULL;
114     LDAPModW **attrsW = NULL;
115     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
116
117     ret = WLDAP32_LDAP_NO_MEMORY;
118
119     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
120            serverctrls, clientctrls, message );
121
122     if (!ld) return ~0UL;
123
124     if (dn) {
125         dnW = strAtoW( dn );
126         if (!dnW) goto exit;
127     }
128     if (attrs) {
129         attrsW = modarrayAtoW( attrs );
130         if (!attrsW) goto exit;
131     }
132     if (serverctrls) {
133         serverctrlsW = controlarrayAtoW( serverctrls );
134         if (!serverctrlsW) goto exit;
135     }
136     if (clientctrls) {
137         clientctrlsW = controlarrayAtoW( clientctrls );
138         if (!clientctrlsW) goto exit;
139     }
140
141     ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
142
143 exit:
144     strfreeW( dnW );
145     modarrayfreeW( attrsW );
146     controlarrayfreeW( serverctrlsW );
147     controlarrayfreeW( clientctrlsW );
148
149 #endif
150     return ret;
151 }
152
153 ULONG ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
154     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
155 {
156     ULONG ret = LDAP_NOT_SUPPORTED;
157 #ifdef HAVE_LDAP
158     char *dnU = NULL;
159     LDAPMod **attrsU = NULL;
160     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
161     int dummy;
162
163     ret = WLDAP32_LDAP_NO_MEMORY;
164
165     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
166            serverctrls, clientctrls, message );
167
168     if (!ld) return ~0UL;
169     if (!attrs) return LDAP_PROTOCOL_ERROR;
170
171     if (dn) {
172         dnU = strWtoU( dn );
173         if (!dnU) goto exit;
174     }
175     if (attrs) {
176         attrsU = modarrayWtoU( attrs );
177         if (!attrsU) goto exit;
178     }
179     if (serverctrls) {
180         serverctrlsU = controlarrayWtoU( serverctrls );
181         if (!serverctrlsU) goto exit;
182     }
183     if (clientctrls) {
184         clientctrlsU = controlarrayWtoU( clientctrls );
185         if (!clientctrlsU) goto exit;
186     }
187
188     ret = ldap_add_ext( ld, dn ? dnU : "", attrs? attrsU : nullattrs, serverctrlsU,
189                         clientctrlsU, message ? (int *)message : &dummy );
190
191 exit:
192     strfreeU( dnU );
193     modarrayfreeU( attrsU );
194     controlarrayfreeU( serverctrlsU );
195     controlarrayfreeU( clientctrlsU );
196
197 #endif
198     return ret;
199 }
200
201 ULONG ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
202     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
203 {
204     ULONG ret = LDAP_NOT_SUPPORTED;
205 #ifdef HAVE_LDAP
206     WCHAR *dnW = NULL;
207     LDAPModW **attrsW = NULL;
208     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
209
210     ret = WLDAP32_LDAP_NO_MEMORY;
211
212     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
213            serverctrls, clientctrls );
214
215     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
216
217     if (dn) {
218         dnW = strAtoW( dn );
219         if (!dnW) goto exit;
220     }
221     if (attrs) {
222         attrsW = modarrayAtoW( attrs );
223         if (!attrsW) goto exit;
224     }
225     if (serverctrls) {
226         serverctrlsW = controlarrayAtoW( serverctrls );
227         if (!serverctrlsW) goto exit;
228     }
229     if (clientctrls) {
230         clientctrlsW = controlarrayAtoW( clientctrls );
231         if (!clientctrlsW) goto exit;
232     }
233
234     ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
235
236 exit:
237     strfreeW( dnW );
238     modarrayfreeW( attrsW );
239     controlarrayfreeW( serverctrlsW );
240     controlarrayfreeW( clientctrlsW );
241
242 #endif
243     return ret;
244 }
245
246 ULONG ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
247     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
248 {
249     ULONG ret = LDAP_NOT_SUPPORTED;
250 #ifdef HAVE_LDAP
251     char *dnU = NULL;
252     LDAPMod **attrsU = NULL;
253     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
254
255     ret = WLDAP32_LDAP_NO_MEMORY;
256
257     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
258            serverctrls, clientctrls );
259
260     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
261     if (!attrs) return LDAP_PROTOCOL_ERROR;
262
263     if (dn) {
264         dnU = strWtoU( dn );
265         if (!dnU) goto exit;
266     }
267     if (attrs) {
268         attrsU = modarrayWtoU( attrs );
269         if (!attrsU) goto exit;
270     }
271     if (serverctrls) {
272         serverctrlsU = controlarrayWtoU( serverctrls );
273         if (!serverctrlsU) goto exit;
274     }
275     if (clientctrls) {
276         clientctrlsU = controlarrayWtoU( clientctrls );
277         if (!clientctrlsU) goto exit;
278     }
279
280     ret = ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
281                           serverctrlsU, clientctrlsU );
282
283 exit:
284     strfreeU( dnU );
285     modarrayfreeU( attrsU );
286     controlarrayfreeU( serverctrlsU );
287     controlarrayfreeU( clientctrlsU );
288
289 #endif
290     return ret;
291 }
292
293 ULONG ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
294 {
295     ULONG ret = LDAP_NOT_SUPPORTED;
296 #ifdef HAVE_LDAP
297     WCHAR *dnW = NULL;
298     LDAPModW **attrsW = NULL;
299
300     ret = WLDAP32_LDAP_NO_MEMORY;
301
302     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
303
304     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
305
306     if (dn) {
307         dnW = strAtoW( dn );
308         if (!dnW) goto exit;
309     }
310     if (attrs) {
311         attrsW = modarrayAtoW( attrs );
312         if (!attrsW) goto exit;
313     }
314
315     ret = ldap_add_sW( ld, dnW, attrsW );
316
317 exit:
318     strfreeW( dnW );
319     modarrayfreeW( attrsW );
320
321 #endif
322     return ret;
323 }
324
325 ULONG ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
326 {
327     ULONG ret = LDAP_NOT_SUPPORTED;
328 #ifdef HAVE_LDAP
329     char *dnU = NULL;
330     LDAPMod **attrsU = NULL;
331
332     ret = WLDAP32_LDAP_NO_MEMORY;
333
334     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
335
336     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
337
338     if (dn) {
339         dnU = strWtoU( dn );
340         if (!dnU) goto exit;
341     }
342     if (attrs) {
343         attrsU = modarrayWtoU( attrs );
344         if (!attrsU) goto exit;
345     }
346
347     ret = ldap_add_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
348
349 exit:
350     strfreeU( dnU );
351     modarrayfreeU( attrsU );
352
353 #endif
354     return ret;
355 }