Add Korean translations.
[wine] / dlls / wldap32 / compare.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_compareA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
44 {
45     ULONG ret = LDAP_NOT_SUPPORTED;
46 #ifdef HAVE_LDAP
47     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
48
49     ret = WLDAP32_LDAP_NO_MEMORY;
50
51     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
52            debugstr_a(value) );
53
54     if (!ld) return ~0UL;
55
56     if (dn) {
57         dnW = strAtoW( dn );
58         if (!dnW) goto exit;
59     }
60     if (attr) {
61         attrW = strAtoW( attr );
62         if (!attrW) goto exit;
63     }
64     if (value) {
65         valueW = strAtoW( value );
66         if (!valueW) goto exit;
67     }
68
69     ret = ldap_compareW( ld, dnW, attrW, valueW );
70
71 exit:
72     strfreeW( dnW );
73     strfreeW( attrW );
74     strfreeW( valueW );
75
76 #endif
77     return ret;
78 }
79
80 ULONG ldap_compareW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
81 {
82     ULONG ret = LDAP_NOT_SUPPORTED;
83 #ifdef HAVE_LDAP
84     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
85
86     ret = WLDAP32_LDAP_NO_MEMORY;
87
88     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
89            debugstr_w(value) );
90
91     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
92     if (!attr) return ~0UL;
93
94     if (dn) {
95         dnU = strWtoU( dn );
96         if (!dnU) goto exit;
97     }
98
99     attrU = strWtoU( attr );
100     if (!attrU) goto exit;
101
102     if (value) {
103         valueU = strWtoU( value );
104         if (!valueU) goto exit;
105     }
106
107     ret = ldap_compare( ld, dn ? dnU : "", attrU, value ? valueU : "" );
108
109 exit:
110     strfreeU( dnU );
111     strfreeU( attrU );
112     strfreeU( valueU );
113
114 #endif
115     return ret;
116 }
117
118 ULONG ldap_compare_extA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
119     struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls,
120     ULONG *message )
121 {
122     ULONG ret = LDAP_NOT_SUPPORTED;
123 #ifdef HAVE_LDAP
124     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
125     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
126
127     ret = WLDAP32_LDAP_NO_MEMORY;
128
129     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
130            debugstr_a(attr), debugstr_a(value), data, serverctrls,
131            clientctrls, message );
132
133     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
134
135     if (dn) {
136         dnW = strAtoW( dn );
137         if (!dnW) goto exit;
138     }
139     if (attr) {
140         attrW = strAtoW( attr );
141         if (!attrW) goto exit;
142     }
143     if (value) {
144         valueW = strAtoW( value );
145         if (!valueW) goto exit;
146     }
147     if (serverctrls) {
148         serverctrlsW = controlarrayAtoW( serverctrls );
149         if (!serverctrlsW) goto exit;
150     }
151     if (clientctrls) {
152         clientctrlsW = controlarrayAtoW( clientctrls );
153         if (!clientctrlsW) goto exit;
154     }
155
156     ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
157                              serverctrlsW, clientctrlsW, message );
158
159 exit:
160     strfreeW( dnW );
161     strfreeW( attrW );
162     strfreeW( valueW );
163     controlarrayfreeW( serverctrlsW );
164     controlarrayfreeW( clientctrlsW );
165
166 #endif
167     return ret;
168 }
169
170 ULONG ldap_compare_extW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
171     struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls,
172     ULONG *message )
173 {
174     ULONG ret = LDAP_NOT_SUPPORTED;
175 #ifdef HAVE_LDAP
176     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
177     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
178     struct berval berval;
179
180     ret = WLDAP32_LDAP_NO_MEMORY;
181
182     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
183            debugstr_w(attr), debugstr_w(value), data, serverctrls,
184            clientctrls, message );
185
186     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
187     if (!attr) return WLDAP32_LDAP_NO_MEMORY;
188
189     if (dn) {
190         dnU = strWtoU( dn );
191         if (!dnU) goto exit;
192     }
193
194     attrU = strWtoU( attr );
195     if (!attrU) goto exit;
196
197     if (!data) {
198         if (value) {
199             valueU = strWtoU( value );
200             if (!valueU) goto exit;
201         }
202         berval.bv_len = valueU ? strlen( valueU ) : 0;
203         berval.bv_val = valueU;
204     }
205     if (serverctrls) {
206         serverctrlsU = controlarrayWtoU( serverctrls );
207         if (!serverctrlsU) goto exit;
208     }
209     if (clientctrls) {
210         clientctrlsU = controlarrayWtoU( clientctrls );
211         if (!clientctrlsU) goto exit;
212     }
213
214     ret = ldap_compare_ext( ld, dn ? dnU : "", attrU, data ? (struct berval *)data : &berval,
215                             serverctrlsU, clientctrlsU, (int *)message );
216
217 exit:
218     strfreeU( dnU );
219     strfreeU( attrU );
220     strfreeU( valueU );
221     controlarrayfreeU( serverctrlsU );
222     controlarrayfreeU( clientctrlsU );
223
224 #endif
225     return ret;
226 }
227
228 ULONG ldap_compare_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
229     struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
230 {
231     ULONG ret = LDAP_NOT_SUPPORTED;
232 #ifdef HAVE_LDAP
233     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
234     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
235
236     ret = WLDAP32_LDAP_NO_MEMORY;
237
238     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_a(dn),
239            debugstr_a(attr), debugstr_a(value), data, serverctrls,
240            clientctrls );
241
242     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
243
244     if (dn) {
245         dnW = strAtoW( dn );
246         if (!dnW) goto exit;
247     }
248     if (attr) {
249         attrW = strAtoW( attr );
250         if (!attrW) goto exit;
251     }
252     if (value) {
253         valueW = strAtoW( value );
254         if (!valueW) goto exit;
255     }
256     if (serverctrls) {
257         serverctrlsW = controlarrayAtoW( serverctrls );
258         if (!serverctrlsW) goto exit;
259     }
260     if (clientctrls) {
261         clientctrlsW = controlarrayAtoW( clientctrls );
262         if (!clientctrlsW) goto exit;
263     }
264
265     ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
266                                clientctrlsW );
267
268 exit:
269     strfreeW( dnW );
270     strfreeW( attrW );
271     strfreeW( valueW );
272     controlarrayfreeW( serverctrlsW );
273     controlarrayfreeW( clientctrlsW );
274
275 #endif
276     return ret;
277 }
278
279 ULONG ldap_compare_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
280     struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
281 {
282     ULONG ret = LDAP_NOT_SUPPORTED;
283 #ifdef HAVE_LDAP
284     struct berval berval;
285     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
286     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
287
288     ret = WLDAP32_LDAP_NO_MEMORY;
289
290     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_w(dn),
291            debugstr_w(attr), debugstr_w(value), data, serverctrls,
292            clientctrls );
293
294     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
295
296     if (dn) {
297         dnU = strWtoU( dn );
298         if (!dnU) goto exit;
299     }
300     if (attr) {
301         attrU = strWtoU( attr );
302         if (!attrU) goto exit;
303     }
304     if (!data) {
305         if (value) {
306             valueU = strWtoU( value );
307             if (!valueU) goto exit;
308         }
309         berval.bv_len = valueU ? strlen( valueU ) : 0;
310         berval.bv_val = valueU;
311     }
312     if (serverctrls) {
313         serverctrlsU = controlarrayWtoU( serverctrls );
314         if (!serverctrlsU) goto exit;
315     }
316     if (clientctrls) {
317         clientctrlsU = controlarrayWtoU( clientctrls );
318         if (!clientctrlsU) goto exit;
319     }
320
321     ret = ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "", data ? (struct berval *)data : &berval,
322                               serverctrlsU, clientctrlsU );
323
324 exit:
325     strfreeU( dnU );
326     strfreeU( attrU );
327     strfreeU( valueU );
328     controlarrayfreeU( serverctrlsU );
329     controlarrayfreeU( clientctrlsU );
330
331 #endif
332     return ret;
333 }
334
335 ULONG ldap_compare_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
336 {
337     ULONG ret = LDAP_NOT_SUPPORTED;
338 #ifdef HAVE_LDAP
339     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
340
341     ret = WLDAP32_LDAP_NO_MEMORY;
342
343     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
344            debugstr_a(value) );
345
346     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
347
348     if (dn) {
349         dnW = strAtoW( dn );
350         if (!dnW) goto exit;
351     }
352     if (attr) {
353         attrW = strAtoW( attr );
354         if (!attrW) goto exit;
355     }
356     if (value) {
357         valueW = strAtoW( value );
358         if (!valueW) goto exit;
359     }
360
361     ret = ldap_compare_sW( ld, dnW, attrW, valueW );
362
363 exit:
364     strfreeW( dnW );
365     strfreeW( attrW );
366     strfreeW( valueW );
367
368 #endif
369     return ret;
370 }
371
372 ULONG ldap_compare_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
373 {
374     ULONG ret = LDAP_NOT_SUPPORTED;
375 #ifdef HAVE_LDAP
376     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
377
378     ret = WLDAP32_LDAP_NO_MEMORY;
379
380     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
381            debugstr_w(value) );
382
383     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
384
385     if (dn) {
386         dnU = strWtoU( dn );
387         if (!dnU) goto exit;
388     }
389     if (attr) {
390         attrU = strWtoU( attr );
391         if (!attrU) goto exit;
392     }
393     if (value) {
394         valueU = strWtoU( value );
395         if (!valueU) goto exit;
396     }
397
398     ret = ldap_compare_s( ld, dn ? dnU : "", attr ? attrU : "", value ? valueU : "" );
399
400 exit:
401     strfreeU( dnU );
402     strfreeU( attrU );
403     strfreeU( valueU );
404
405 #endif
406     return ret;
407 }