2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
28 #include "winldap_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
32 /***********************************************************************
33 * ldap_close_extended_op (WLDAP32.@)
35 * Close an extended operation.
38 * ld [I] Pointer to an LDAP context.
39 * msgid [I] Message ID of the operation to be closed.
42 * Success: LDAP_SUCCESS
43 * Failure: An LDAP error code.
46 * Contrary to native, OpenLDAP does not require us to close
47 * extended operations, so this is a no-op.
49 ULONG CDECL
ldap_close_extended_op( LDAP
*ld
, ULONG msgid
)
51 TRACE( "(%p, %#lx)\n", ld
, msgid
);
53 if (!ld
) return LDAP_PARAM_ERROR
;
57 /***********************************************************************
58 * ldap_extended_operationA (WLDAP32.@)
60 * See ldap_extended_operationW.
62 ULONG CDECL
ldap_extended_operationA( LDAP
*ld
, char *oid
, struct berval
*data
, LDAPControlA
**serverctrls
,
63 LDAPControlA
**clientctrls
, ULONG
*message
)
65 ULONG ret
= LDAP_NO_MEMORY
;
67 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
69 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(oid
), data
, serverctrls
, clientctrls
, message
);
71 if (!ld
|| !message
) return LDAP_PARAM_ERROR
;
73 if (oid
&& !(oidW
= strAtoW( oid
))) goto exit
;
74 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
75 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
77 ret
= ldap_extended_operationW( ld
, oidW
, data
, serverctrlsW
, clientctrlsW
, message
);
81 controlarrayfreeW( serverctrlsW
);
82 controlarrayfreeW( clientctrlsW
);
86 /***********************************************************************
87 * ldap_extended_operationW (WLDAP32.@)
89 * Perform an extended operation (asynchronous mode).
92 * ld [I] Pointer to an LDAP context.
93 * oid [I] OID of the extended operation.
94 * data [I] Data needed by the operation.
95 * serverctrls [I] Array of LDAP server controls.
96 * clientctrls [I] Array of LDAP client controls.
97 * message [O] Message ID of the extended operation.
100 * Success: LDAP_SUCCESS
101 * Failure: An LDAP error code.
104 * The data parameter should be set to NULL if the operation
105 * requires no data. Call ldap_result with the message ID to
106 * get the result of the operation or ldap_abandon to cancel
107 * the operation. The serverctrls and clientctrls parameters
108 * are optional and should be set to NULL if not used. Call
109 * ldap_close_extended_op to close the operation.
111 ULONG CDECL
ldap_extended_operationW( LDAP
*ld
, WCHAR
*oid
, struct berval
*data
, LDAPControlW
**serverctrls
,
112 LDAPControlW
**clientctrls
, ULONG
*message
)
114 ULONG ret
= LDAP_NO_MEMORY
;
116 LDAPControlU
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
117 struct bervalU
*dataU
= NULL
;
119 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(oid
), data
, serverctrls
, clientctrls
, message
);
121 if (!ld
|| !message
) return LDAP_PARAM_ERROR
;
123 if (oid
&& !(oidU
= strWtoU( oid
))) goto exit
;
124 if (data
&& !(dataU
= bervalWtoU( data
))) goto exit
;
125 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
126 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
129 struct ldap_extended_operation_params params
= { CTX(ld
), oidU
, dataU
, serverctrlsU
, clientctrlsU
, message
};
130 ret
= map_error( LDAP_CALL( ldap_extended_operation
, ¶ms
));
136 controlarrayfreeU( serverctrlsU
);
137 controlarrayfreeU( clientctrlsU
);
141 /***********************************************************************
142 * ldap_extended_operation_sA (WLDAP32.@)
144 * See ldap_extended_operation_sW.
146 ULONG CDECL
ldap_extended_operation_sA( LDAP
*ld
, char *oid
, struct berval
*data
, LDAPControlA
**serverctrls
,
147 LDAPControlA
**clientctrls
, char **retoid
, struct berval
**retdata
)
149 ULONG ret
= LDAP_NO_MEMORY
;
150 WCHAR
*oidW
= NULL
, *retoidW
= NULL
;
151 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
153 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld
, debugstr_a(oid
), data
, serverctrls
, clientctrls
, retoid
, retdata
);
155 if (!ld
) return LDAP_PARAM_ERROR
;
157 if (oid
&& !(oidW
= strAtoW( oid
))) goto exit
;
158 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
159 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
161 ret
= ldap_extended_operation_sW( ld
, oidW
, data
, serverctrlsW
, clientctrlsW
, &retoidW
, retdata
);
162 if (retoid
&& retoidW
)
164 char *str
= strWtoA( retoidW
);
165 if (str
) *retoid
= str
;
166 else ret
= LDAP_NO_MEMORY
;
167 ldap_memfreeW( retoidW
);
172 controlarrayfreeW( serverctrlsW
);
173 controlarrayfreeW( clientctrlsW
);
177 /***********************************************************************
178 * ldap_extended_operation_sW (WLDAP32.@)
180 * Perform an extended operation (synchronous mode).
183 * ld [I] Pointer to an LDAP context.
184 * oid [I] OID of the extended operation.
185 * data [I] Data needed by the operation.
186 * serverctrls [I] Array of LDAP server controls.
187 * clientctrls [I] Array of LDAP client controls.
188 * retoid [O] OID of the server response message.
189 * retdata [O] Data returned by the server.
192 * Success: LDAP_SUCCESS
193 * Failure: An LDAP error code.
196 * The data parameter should be set to NULL if the operation
197 * requires no data. The serverctrls, clientctrls, retoid and
198 * and retdata parameters are also optional. Set to NULL if not
199 * used. Free retoid and retdata after use with ldap_memfree.
201 ULONG CDECL
ldap_extended_operation_sW( LDAP
*ld
, WCHAR
*oid
, struct berval
*data
, LDAPControlW
**serverctrls
,
202 LDAPControlW
**clientctrls
, WCHAR
**retoid
, struct berval
**retdata
)
204 ULONG ret
= LDAP_NO_MEMORY
;
205 char *oidU
= NULL
, *retoidU
= NULL
;
206 LDAPControlU
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
207 struct bervalU
*retdataU
, *dataU
= NULL
;
209 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld
, debugstr_w(oid
), data
, serverctrls
, clientctrls
, retoid
, retdata
);
211 if (!ld
) return LDAP_PARAM_ERROR
;
213 if (oid
&& !(oidU
= strWtoU( oid
))) goto exit
;
214 if (data
&& !(dataU
= bervalWtoU( data
))) goto exit
;
215 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
216 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
219 struct ldap_extended_operation_s_params params
= { CTX(ld
), oidU
, dataU
, serverctrlsU
, clientctrlsU
, &retoidU
, &retdataU
};
220 ret
= map_error( LDAP_CALL( ldap_extended_operation_s
, ¶ms
));
223 if (retoid
&& retoidU
)
225 WCHAR
*str
= strUtoW( retoidU
);
226 if (str
) *retoid
= str
;
227 else ret
= LDAP_NO_MEMORY
;
228 LDAP_CALL( ldap_memfree
, retoidU
);
230 if (retdata
&& retdataU
)
232 struct berval
*bv
= bervalUtoW( retdataU
);
233 if (bv
) *retdata
= bv
;
234 else ret
= LDAP_NO_MEMORY
;
235 LDAP_CALL( ber_bvfree
, retdataU
);
241 controlarrayfreeU( serverctrlsU
);
242 controlarrayfreeU( clientctrlsU
);