Implement ldap_add* functions.
[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 #else
35 #define LDAP_NOT_SUPPORTED  0x5c
36 #endif
37
38 #include "winldap_private.h"
39 #include "wldap32.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
42
43 ULONG ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
44 {
45     ULONG ret = LDAP_NOT_SUPPORTED;
46 #ifdef HAVE_LDAP
47     WCHAR *dnW = NULL;
48     LDAPModW **attrsW = NULL;
49
50     ret = WLDAP32_LDAP_NO_MEMORY;
51
52     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
53
54     if (!ld) return ~0UL;
55     if (!attrs) return LDAP_PROTOCOL_ERROR;
56
57     if (dn) {
58         dnW = strAtoW( dn );
59         if (!dnW) goto exit;
60     }
61
62     attrsW = modarrayAtoW( attrs );
63     if (!attrsW) goto exit;
64
65     ret = ldap_addW( ld, dnW, attrsW );
66
67 exit:
68     strfreeW( dnW );
69     modarrayfreeW( attrsW );
70
71 #endif
72     return ret;
73 }
74
75 ULONG ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
76 {
77     ULONG ret = LDAP_NOT_SUPPORTED;
78 #ifdef HAVE_LDAP
79     char *dnU = NULL;
80     LDAPMod **attrsU = NULL;
81  
82     ret = WLDAP32_LDAP_NO_MEMORY;
83
84     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
85
86     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
87     if (!attrs) return LDAP_PROTOCOL_ERROR;
88
89     if (dn) {
90         dnU = strWtoU( dn );
91         if (!dnU) goto exit;
92     }
93
94     attrsU = modarrayWtoU( attrs );
95     if (!attrsU) goto exit;
96
97     ret = ldap_add( ld, dn ? dnU : "", attrsU );
98
99 exit:
100     strfreeU( dnU );
101     modarrayfreeU( attrsU );
102
103 #endif
104     return ret;
105 }
106
107 ULONG ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
108     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
109 {
110     ULONG ret = LDAP_NOT_SUPPORTED;
111 #ifdef HAVE_LDAP
112     WCHAR *dnW = NULL;
113     LDAPModW **attrsW = NULL;
114     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
115
116     ret = WLDAP32_LDAP_NO_MEMORY;
117
118     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
119            serverctrls, clientctrls, message );
120
121     if (!ld) return ~0UL;
122     if (!attrs) return LDAP_PROTOCOL_ERROR;
123
124     if (dn) {
125         dnW = strAtoW( dn );
126         if (!dnW) goto exit;
127     }
128
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
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 : "", attrsU, serverctrlsU, clientctrlsU,
189                         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     if (!attrs) return LDAP_PROTOCOL_ERROR;
217
218     if (dn) {
219         dnW = strAtoW( dn );
220         if (!dnW) goto exit;
221     }
222
223     attrsW = modarrayAtoW( attrs );
224     if (!attrsW) goto exit;
225
226     if (serverctrls) {
227         serverctrlsW = controlarrayAtoW( serverctrls );
228         if (!serverctrlsW) goto exit;
229     }
230     if (clientctrls) {
231         clientctrlsW = controlarrayAtoW( clientctrls );
232         if (!clientctrlsW) goto exit;
233     }
234
235     ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
236
237 exit:
238     strfreeW( dnW );
239     modarrayfreeW( attrsW );
240     controlarrayfreeW( serverctrlsW );
241     controlarrayfreeW( clientctrlsW );
242
243 #endif
244     return ret;
245 }
246
247 ULONG ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
248     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
249 {
250     ULONG ret = LDAP_NOT_SUPPORTED;
251 #ifdef HAVE_LDAP
252     char *dnU = NULL;
253     LDAPMod **attrsU = NULL;
254     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
255
256     ret = WLDAP32_LDAP_NO_MEMORY;
257
258     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
259            serverctrls, clientctrls );
260
261     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
262     if (!attrs) return LDAP_PROTOCOL_ERROR;
263
264     if (dn) {
265         dnU = strWtoU( dn );
266         if (!dnU) goto exit;
267     }
268
269     attrsU = modarrayWtoU( attrs );
270     if (!attrsU) goto exit;
271
272     if (serverctrls) {
273         serverctrlsU = controlarrayWtoU( serverctrls );
274         if (!serverctrlsU) goto exit;
275     }
276     if (clientctrls) {
277         clientctrlsU = controlarrayWtoU( clientctrls );
278         if (!clientctrlsU) goto exit;
279     }
280
281     ret = ldap_add_ext_s( ld, dn ? dnU : "", attrsU, 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     if (!attrs) return LDAP_PROTOCOL_ERROR;
306
307     if (dn) {
308         dnW = strAtoW( dn );
309         if (!dnW) goto exit;
310     }
311
312     attrsW = modarrayAtoW( attrs );
313     if (!attrsW) goto exit;
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     if (!attrs) return LDAP_PROTOCOL_ERROR;
338
339     if (dn) {
340         dnU = strWtoU( dn );
341         if (!dnU) goto exit;
342     }
343
344     attrsU = modarrayWtoU( attrs );
345     if (!attrsU) goto exit;
346
347     ret = ldap_add_s( ld, dn ? dnU : "", attrsU );
348
349 exit:
350     strfreeU( dnU );
351     modarrayfreeU( attrsU );
352
353 #endif
354     return ret;
355 }