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_compareA (WLDAP32.@)
37 ULONG CDECL
ldap_compareA( LDAP
*ld
, char *dn
, char *attr
, char *value
)
40 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
42 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
), debugstr_a(value
) );
44 if (!ld
|| !attr
) return ~0u;
46 if (dn
&& !(dnW
= strAtoW( dn
))) goto exit
;
47 if (!(attrW
= strAtoW( attr
))) goto exit
;
48 if (value
&& !(valueW
= strAtoW( value
))) goto exit
;
50 ret
= ldap_compareW( ld
, dnW
, attrW
, valueW
);
59 /***********************************************************************
60 * ldap_compareW (WLDAP32.@)
62 * Check if an attribute has a certain value (asynchronous operation).
65 * ld [I] Pointer to an LDAP context.
66 * dn [I] DN of entry to compare value for.
67 * attr [I] Attribute to compare value for.
68 * value [I] Value to compare.
71 * Success: Message ID of the compare operation.
72 * Failure: An LDAP error code.
74 ULONG CDECL
ldap_compareW( LDAP
*ld
, WCHAR
*dn
, WCHAR
*attr
, WCHAR
*value
)
78 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
), debugstr_w(value
) );
80 ret
= ldap_compare_extW( ld
, dn
, attr
, value
, NULL
, NULL
, NULL
, &msg
);
81 if (ret
== LDAP_SUCCESS
) return msg
;
85 /***********************************************************************
86 * ldap_compare_extA (WLDAP32.@)
88 * See ldap_compare_extW.
90 ULONG CDECL
ldap_compare_extA( LDAP
*ld
, char *dn
, char *attr
, char *value
,
91 struct berval
*data
, LDAPControlA
**serverctrls
, LDAPControlA
**clientctrls
,
94 ULONG ret
= LDAP_NO_MEMORY
;
95 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
96 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
98 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
), debugstr_a(attr
), debugstr_a(value
),
99 data
, serverctrls
, clientctrls
, message
);
101 if (!ld
|| !message
) return LDAP_PARAM_ERROR
;
103 if (dn
&& !(dnW
= strAtoW( dn
))) goto exit
;
104 if (attr
&& !(attrW
= strAtoW( attr
))) goto exit
;
105 if (value
&& !(valueW
= strAtoW( value
))) goto exit
;
106 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
107 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
109 ret
= ldap_compare_extW( ld
, dnW
, attrW
, valueW
, data
, serverctrlsW
, clientctrlsW
, message
);
115 controlarrayfreeW( serverctrlsW
);
116 controlarrayfreeW( clientctrlsW
);
120 /***********************************************************************
121 * ldap_compare_extW (WLDAP32.@)
123 * Check if an attribute has a certain value (asynchronous operation).
126 * ld [I] Pointer to an LDAP context.
127 * dn [I] DN of entry to compare value for.
128 * attr [I] Attribute to compare value for.
129 * value [I] string encoded value to compare.
130 * data [I] berval encoded value to compare.
131 * serverctrls [I] Array of LDAP server controls.
132 * clientctrls [I] Array of LDAP client controls.
133 * message [O] Message ID of the compare operation.
136 * Success: LDAP_SUCCESS
137 * Failure: An LDAP error code.
140 * Set value to compare strings or data to compare binary values. If
141 * both are non-NULL, data will be used. The serverctrls and clientctrls
142 * parameters are optional and should be set to NULL if not used.
144 ULONG CDECL
ldap_compare_extW( LDAP
*ld
, WCHAR
*dn
, WCHAR
*attr
, WCHAR
*value
, struct berval
*data
,
145 LDAPControlW
**serverctrls
, LDAPControlW
**clientctrls
, ULONG
*message
)
147 ULONG ret
= LDAP_NO_MEMORY
;
148 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
149 LDAPControlU
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
150 struct bervalU
*dataU
= NULL
, val
= { 0, NULL
};
152 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
), debugstr_w(attr
), debugstr_w(value
),
153 data
, serverctrls
, clientctrls
, message
);
155 if (!ld
|| !message
) return LDAP_PARAM_ERROR
;
156 if (!attr
) return LDAP_NO_MEMORY
;
158 if (dn
&& !(dnU
= strWtoU( dn
))) goto exit
;
159 if (!(attrU
= strWtoU( attr
))) goto exit
;
164 if (!(valueU
= strWtoU( value
))) goto exit
;
165 val
.bv_len
= strlen( valueU
);
169 else if (!(dataU
= bervalWtoU( data
))) goto exit
;
171 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
172 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
174 ret
= map_error( ldap_funcs
->fn_ldap_compare_ext( CTX(ld
), dnU
, attrU
, dataU
? dataU
: &val
, serverctrlsU
,
175 clientctrlsU
, message
) );
181 controlarrayfreeU( serverctrlsU
);
182 controlarrayfreeU( clientctrlsU
);
186 /***********************************************************************
187 * ldap_compare_ext_sA (WLDAP32.@)
189 * See ldap_compare_ext_sW.
191 ULONG CDECL
ldap_compare_ext_sA( LDAP
*ld
, char *dn
, char *attr
, char *value
, struct berval
*data
,
192 LDAPControlA
**serverctrls
, LDAPControlA
**clientctrls
)
194 ULONG ret
= LDAP_NO_MEMORY
;
195 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
196 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
198 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_a(dn
), debugstr_a(attr
), debugstr_a(value
),
199 data
, serverctrls
, clientctrls
);
201 if (!ld
) return LDAP_PARAM_ERROR
;
203 if (dn
&& !(dnW
= strAtoW( dn
))) goto exit
;
204 if (attr
&& !(attrW
= strAtoW( attr
))) goto exit
;
205 if (value
&& !(valueW
= strAtoW( value
))) goto exit
;
206 if (serverctrls
&& !(serverctrlsW
= controlarrayAtoW( serverctrls
))) goto exit
;
207 if (clientctrls
&& !(clientctrlsW
= controlarrayAtoW( clientctrls
))) goto exit
;
209 ret
= ldap_compare_ext_sW( ld
, dnW
, attrW
, valueW
, data
, serverctrlsW
, clientctrlsW
);
215 controlarrayfreeW( serverctrlsW
);
216 controlarrayfreeW( clientctrlsW
);
220 /***********************************************************************
221 * ldap_compare_ext_sW (WLDAP32.@)
223 * Check if an attribute has a certain value (synchronous operation).
226 * ld [I] Pointer to an LDAP context.
227 * dn [I] DN of entry to compare value for.
228 * attr [I] Attribute to compare value for.
229 * value [I] string encoded value to compare.
230 * data [I] berval encoded value to compare.
231 * serverctrls [I] Array of LDAP server controls.
232 * clientctrls [I] Array of LDAP client controls.
235 * Success: LDAP_SUCCESS
236 * Failure: An LDAP error code.
239 * Set value to compare strings or data to compare binary values. If
240 * both are non-NULL, data will be used. The serverctrls and clientctrls
241 * parameters are optional and should be set to NULL if not used.
243 ULONG CDECL
ldap_compare_ext_sW( LDAP
*ld
, WCHAR
*dn
, WCHAR
*attr
, WCHAR
*value
, struct berval
*data
,
244 LDAPControlW
**serverctrls
, LDAPControlW
**clientctrls
)
246 ULONG ret
= LDAP_NO_MEMORY
;
247 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
248 LDAPControlU
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
249 struct bervalU
*dataU
= NULL
, val
= { 0, NULL
};
251 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_w(dn
), debugstr_w(attr
), debugstr_w(value
), data
,
252 serverctrls
, clientctrls
);
254 if (!ld
) return LDAP_PARAM_ERROR
;
256 if (dn
&& !(dnU
= strWtoU( dn
))) goto exit
;
257 if (attr
&& !(attrU
= strWtoU( attr
))) goto exit
;
262 if (!(valueU
= strWtoU( value
))) goto exit
;
263 val
.bv_len
= strlen( valueU
);
267 else if (!(dataU
= bervalWtoU( data
))) goto exit
;
269 if (serverctrls
&& !(serverctrlsU
= controlarrayWtoU( serverctrls
))) goto exit
;
270 if (clientctrls
&& !(clientctrlsU
= controlarrayWtoU( clientctrls
))) goto exit
;
272 ret
= map_error( ldap_funcs
->fn_ldap_compare_ext_s( CTX(ld
), dnU
, attrU
, dataU
? dataU
: &val
, serverctrlsU
,
279 controlarrayfreeU( serverctrlsU
);
280 controlarrayfreeU( clientctrlsU
);
284 /***********************************************************************
285 * ldap_compare_sA (WLDAP32.@)
287 * See ldap_compare_sW.
289 ULONG CDECL
ldap_compare_sA( LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
291 ULONG ret
= LDAP_NO_MEMORY
;
292 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
294 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
), debugstr_a(value
) );
296 if (!ld
) return LDAP_PARAM_ERROR
;
298 if (dn
&& !(dnW
= strAtoW( dn
))) goto exit
;
299 if (attr
&& !(attrW
= strAtoW( attr
))) goto exit
;
300 if (value
&& !(valueW
= strAtoW( value
))) goto exit
;
302 ret
= ldap_compare_sW( ld
, dnW
, attrW
, valueW
);
311 /***********************************************************************
312 * ldap_compare_sW (WLDAP32.@)
314 * Check if an attribute has a certain value (synchronous operation).
317 * ld [I] Pointer to an LDAP context.
318 * dn [I] DN of entry to compare value for.
319 * attr [I] Attribute to compare value for.
320 * value [I] Value to compare.
323 * Success: LDAP_SUCCESS
324 * Failure: An LDAP error code.
326 ULONG CDECL
ldap_compare_sW( LDAP
*ld
, WCHAR
*dn
, WCHAR
*attr
, WCHAR
*value
)
328 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
), debugstr_w(value
) );
329 return ldap_compare_ext_sW( ld
, dn
, attr
, value
, NULL
, NULL
, NULL
);