Better stick to the PSDK types.
[wine] / dlls / wldap32 / extended.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_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_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
45 {
46     TRACE( "(%p, 0x%08lx)\n", ld, msgid );
47
48     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
49     return LDAP_SUCCESS;
50 }
51
52 ULONG ldap_extended_operationA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
53     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
54 {
55     ULONG ret = LDAP_NOT_SUPPORTED;
56 #ifdef HAVE_LDAP
57     WCHAR *oidW = NULL;
58     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
59
60     ret = WLDAP32_LDAP_NO_MEMORY;
61
62     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
63            clientctrls, message );
64
65     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
66
67     if (oid) {
68         oidW = strAtoW( oid );
69         if (!oidW) goto exit;
70     }
71     if (serverctrls) {
72         serverctrlsW = controlarrayAtoW( serverctrls );
73         if (!serverctrlsW) goto exit;
74     }
75     if (clientctrls) {
76         clientctrlsW = controlarrayAtoW( clientctrls );
77         if (!clientctrlsW) goto exit;
78     }
79
80     ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
81
82 exit:
83     strfreeW( oidW );
84     controlarrayfreeW( serverctrlsW );
85     controlarrayfreeW( clientctrlsW );
86
87 #endif
88     return ret;
89 }
90
91 ULONG ldap_extended_operationW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
92     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
93 {
94     ULONG ret = LDAP_NOT_SUPPORTED;
95 #ifdef HAVE_LDAP
96     char *oidU = NULL;
97     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
98
99     ret = WLDAP32_LDAP_NO_MEMORY;
100
101     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
102            clientctrls, message );
103
104     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
105
106     if (oid) {
107         oidU = strWtoU( oid );
108         if (!oidU) goto exit;
109     }
110     if (serverctrls) {
111         serverctrlsU = controlarrayWtoU( serverctrls );
112         if (!serverctrlsU) goto exit;
113     }
114     if (clientctrls) {
115         clientctrlsU = controlarrayWtoU( clientctrls );
116         if (!clientctrlsU) goto exit;
117     }
118
119     ret = ldap_extended_operation( ld, oid ? oidU : "", (struct berval *)data,
120                                    serverctrlsU, clientctrlsU, (int *)message );
121
122 exit:
123     strfreeU( oidU );
124     controlarrayfreeU( serverctrlsU );
125     controlarrayfreeU( clientctrlsU );
126
127 #endif
128     return ret;
129 }
130
131 ULONG ldap_extended_operation_sA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
132     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, PCHAR *retoid,
133     struct WLDAP32_berval **retdata )
134 {
135     ULONG ret = LDAP_NOT_SUPPORTED;
136 #ifdef HAVE_LDAP
137     WCHAR *oidW = NULL, *retoidW = NULL;
138     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
139
140     ret = WLDAP32_LDAP_NO_MEMORY;
141
142     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
143            clientctrls, retoid, retdata );
144
145     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
146
147     if (oid) {
148         oidW = strAtoW( oid );
149         if (!oidW) goto exit;
150     }
151     if (serverctrls) {
152         serverctrlsW = controlarrayAtoW( serverctrls );
153         if (!serverctrlsW) goto exit;
154     }
155     if (clientctrls) {
156         clientctrlsW = controlarrayAtoW( clientctrls );
157         if (!clientctrlsW) goto exit;
158     }
159
160     ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW,
161                                       &retoidW, retdata );
162
163     if (retoid && retoidW) {
164         *retoid = strWtoA( retoidW );
165         if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
166         ldap_memfreeW( retoidW );
167     }
168
169 exit:
170     strfreeW( oidW );
171     controlarrayfreeW( serverctrlsW );
172     controlarrayfreeW( clientctrlsW );
173
174 #endif
175     return ret;
176 }
177
178 ULONG ldap_extended_operation_sW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
179     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, PWCHAR *retoid,
180     struct WLDAP32_berval **retdata )
181 {
182     ULONG ret = LDAP_NOT_SUPPORTED;
183 #ifdef HAVE_LDAP
184     char *oidU = NULL, *retoidU = NULL;
185     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
186
187     ret = WLDAP32_LDAP_NO_MEMORY;
188
189     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
190            clientctrls, retoid, retdata );
191
192     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
193
194     if (oid) {
195         oidU = strWtoU( oid );
196         if (!oidU) goto exit;
197     }
198     if (serverctrls) {
199         serverctrlsU = controlarrayWtoU( serverctrls );
200         if (!serverctrlsU) goto exit;
201     }
202     if (clientctrls) {
203         clientctrlsU = controlarrayWtoU( clientctrls );
204         if (!clientctrlsU) goto exit;
205     }
206
207     ret = ldap_extended_operation_s( ld, oid ? oidU : "", (struct berval *)data, serverctrlsU,
208                                      clientctrlsU, &retoidU, (struct berval **)retdata );
209
210     if (retoid && retoidU) {
211         *retoid = strUtoW( retoidU );
212         if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
213         ldap_memfree( retoidU );
214     }
215
216 exit:
217     strfreeU( oidU );
218     controlarrayfreeU( serverctrlsU );
219     controlarrayfreeU( clientctrlsU );
220
221 #endif
222     return ret;
223 }