Implement ldap_search* functions.
[wine] / dlls / wldap32 / search.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
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS        0x00
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_searchA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
45     PCHAR attrs[], ULONG attrsonly )
46 {
47     ULONG ret = LDAP_NOT_SUPPORTED;
48 #ifdef HAVE_LDAP
49     WCHAR *baseW, *filterW, **attrsW;
50
51     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(base),
52            scope, debugstr_a(filter), attrs, attrsonly );
53
54     baseW = strAtoW( base );
55     if (!baseW) return LDAP_NO_MEMORY;
56
57     filterW = strAtoW( filter );
58     if (!filterW) return LDAP_NO_MEMORY;
59
60     attrsW = strarrayAtoW( attrs );
61     if (!attrsW) return LDAP_NO_MEMORY;
62
63     ret = ldap_searchW( ld, baseW, scope, filterW, attrsW, attrsonly );
64
65     strfreeW( baseW );
66     strfreeW( filterW );
67     strarrayfreeW( attrsW );
68
69 #endif
70     return ret;
71 }
72
73 ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
74     PWCHAR attrs[], ULONG attrsonly )
75 {
76     ULONG ret = LDAP_NOT_SUPPORTED;
77 #ifdef HAVE_LDAP
78     char *baseU, *filterU, **attrsU;
79
80     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(base),
81            scope, debugstr_w(filter), attrs, attrsonly );
82
83     baseU = strWtoU( base );
84     if (!baseU) return LDAP_NO_MEMORY;
85
86     filterU = strWtoU( filter );
87     if (!filterU) return LDAP_NO_MEMORY;
88
89     attrsU = strarrayWtoU( attrs );
90     if (!attrsU) return LDAP_NO_MEMORY;
91
92     ret = ldap_search( ld, baseU, scope, filterU, attrsU, attrsonly );
93
94     strfreeU( baseU );
95     strfreeU( filterU );
96     strarrayfreeU( attrsU );
97
98 #endif
99     return ret;
100 }
101
102 ULONG ldap_search_sA( WLDAP32_LDAP *ld, PCHAR base, ULONG scope, PCHAR filter,
103     PCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
104 {
105     ULONG ret = LDAP_NOT_SUPPORTED;
106 #ifdef HAVE_LDAP
107     WCHAR *baseW, *filterW, **attrsW;
108
109     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_a(base),
110            scope, debugstr_a(filter), attrs, attrsonly, res );
111
112     baseW = strAtoW( base );
113     if (!baseW) return LDAP_NO_MEMORY;
114
115     filterW = strAtoW( filter );
116     if (!filterW) return LDAP_NO_MEMORY;
117
118     attrsW = strarrayAtoW( attrs );
119     if (!attrsW) return LDAP_NO_MEMORY;
120
121     ret = ldap_search_sW( ld, baseW, scope, filterW, attrsW, attrsonly, res );
122
123     strfreeW( baseW );
124     strfreeW( filterW );
125     strarrayfreeW( attrsW );
126
127 #endif
128     return ret;
129 }
130
131 ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
132     PWCHAR attrs[], ULONG attrsonly, WLDAP32_LDAPMessage **res )
133 {
134     ULONG ret = LDAP_NOT_SUPPORTED;
135 #ifdef HAVE_LDAP
136     char *baseU, *filterU, **attrsU;
137
138     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p)\n", ld, debugstr_w(base),
139            scope, debugstr_w(filter), attrs, attrsonly, res );
140
141     baseU = strWtoU( base );
142     if (!baseU) return LDAP_NO_MEMORY;
143
144     filterU = strWtoU( filter );
145     if (!filterU) return LDAP_NO_MEMORY;
146
147     attrsU = strarrayWtoU( attrs );
148     if (!attrsU) return LDAP_NO_MEMORY;
149
150     ret = ldap_search_s( ld, baseU, scope, filterU, attrsU, attrsonly, res );
151
152     strfreeU( baseU );
153     strfreeU( filterU );
154     strarrayfreeU( attrsU );
155
156 #endif
157     return ret;
158 }
159
160 ULONG ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope,
161     const PCHAR filter, PCHAR attrs[], ULONG attrsonly,
162     struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
163 {
164     ULONG ret = LDAP_NOT_SUPPORTED;
165 #ifdef HAVE_LDAP
166     WCHAR *baseW, *filterW, **attrsW;
167
168     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
169            debugstr_a(base), scope, debugstr_a(filter), attrs,
170            attrsonly, timeout, res );
171
172     baseW = strAtoW( base );
173     if (!baseW) return LDAP_NO_MEMORY;
174
175     filterW = strAtoW( filter );
176     if (!filterW) return LDAP_NO_MEMORY;
177
178     attrsW = strarrayAtoW( attrs );
179     if (!attrsW) return LDAP_NO_MEMORY;
180
181     ret = ldap_search_stW( ld, baseW, scope, filterW, attrsW, attrsonly,
182                            timeout, res );
183
184     strfreeW( baseW );
185     strfreeW( filterW );
186     strarrayfreeW( attrsW );
187
188 #endif
189     return ret;
190 }
191
192 ULONG ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
193     const PWCHAR filter, PWCHAR attrs[], ULONG attrsonly,
194     struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
195 {
196     ULONG ret = LDAP_NOT_SUPPORTED;
197 #ifdef HAVE_LDAP
198     char *baseU, *filterU, **attrsU;
199
200     TRACE( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx, %p, %p)\n", ld,
201            debugstr_w(base), scope, debugstr_w(filter), attrs,
202            attrsonly, timeout, res );
203
204     baseU = strWtoU( base );
205     if (!baseU) return LDAP_NO_MEMORY;
206
207     filterU = strWtoU( filter );
208     if (!filterU) return LDAP_NO_MEMORY;
209
210     attrsU = strarrayWtoU( attrs );
211     if (!attrsU) return LDAP_NO_MEMORY;
212
213     ret = ldap_search_st( ld, baseU, scope, filterU, attrsU, attrsonly,
214                           (struct timeval *)timeout, res );
215
216     strfreeU( baseU );
217     strfreeU( filterU );
218     strarrayfreeU( attrsU );
219
220 #endif
221     return ret;
222 }