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
26 #include "wine/debug.h"
27 #include "winldap_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
31 /***********************************************************************
32 * ldap_parse_extended_resultA (WLDAP32.@)
34 ULONG CDECL
ldap_parse_extended_resultA( LDAP
*ld
, WLDAP32_LDAPMessage
*result
, char **oid
,
35 struct WLDAP32_berval
**data
, BOOLEAN free
)
40 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
42 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
43 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
45 ret
= ldap_parse_extended_resultW( ld
, result
, &oidW
, data
, free
);
49 if ((str
= strWtoA( oidW
))) *oid
= str
;
50 else ret
= WLDAP32_LDAP_NO_MEMORY
;
51 ldap_memfreeW( oidW
);
56 /***********************************************************************
57 * ldap_parse_extended_resultW (WLDAP32.@)
59 ULONG CDECL
ldap_parse_extended_resultW( LDAP
*ld
, WLDAP32_LDAPMessage
*result
, WCHAR
**oid
,
60 struct WLDAP32_berval
**data
, BOOLEAN free
)
64 struct berval
*dataU
= NULL
;
66 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
68 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
69 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
72 ret
= map_error( ldap_parse_extended_result( CTX(ld
), result
, &oidU
, &dataU
, free
) );
77 if ((str
= strUtoW( oidU
))) *oid
= str
;
78 else ret
= WLDAP32_LDAP_NO_MEMORY
;
83 struct WLDAP32_berval
*bv
;
84 if ((bv
= bervalUtoW( dataU
))) *data
= bv
;
85 else ret
= WLDAP32_LDAP_NO_MEMORY
;
92 /***********************************************************************
93 * ldap_parse_referenceA (WLDAP32.@)
95 ULONG CDECL
ldap_parse_referenceA( LDAP
*ld
, WLDAP32_LDAPMessage
*message
, char ***referrals
)
98 WCHAR
**referralsW
= NULL
;
100 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
104 ret
= ldap_parse_referenceW( ld
, message
, &referralsW
);
108 if ((ref
= strarrayWtoA( referralsW
))) *referrals
= ref
;
109 else ret
= WLDAP32_LDAP_NO_MEMORY
;
110 ldap_value_freeW( referralsW
);
115 /***********************************************************************
116 * ldap_parse_referenceW (WLDAP32.@)
118 ULONG CDECL
ldap_parse_referenceW( LDAP
*ld
, WLDAP32_LDAPMessage
*message
, WCHAR
***referrals
)
121 char **referralsU
= NULL
;
123 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
125 if (ld
) ret
= map_error( ldap_parse_reference( CTX(ld
), message
, &referralsU
, NULL
, 0 ) );
130 if ((ref
= strarrayUtoW( referralsU
))) *referrals
= ref
;
131 else ret
= WLDAP32_LDAP_NO_MEMORY
;
132 ldap_memfree( referralsU
);
137 /***********************************************************************
138 * ldap_parse_resultA (WLDAP32.@)
140 ULONG CDECL
ldap_parse_resultA( LDAP
*ld
, WLDAP32_LDAPMessage
*result
, ULONG
*retcode
, char **matched
, char **error
,
141 char ***referrals
, LDAPControlA
***serverctrls
, BOOLEAN free
)
144 WCHAR
*matchedW
= NULL
, *errorW
= NULL
, **referralsW
= NULL
;
145 LDAPControlW
**serverctrlsW
= NULL
;
147 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
, matched
, error
, referrals
, serverctrls
,
150 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
151 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
153 ret
= ldap_parse_resultW( ld
, result
, retcode
, &matchedW
, &errorW
, &referralsW
, &serverctrlsW
, free
);
155 if (matched
) *matched
= strWtoA( matchedW
);
156 if (error
) *error
= strWtoA( errorW
);
157 if (referrals
) *referrals
= strarrayWtoA( referralsW
);
158 if (serverctrls
) *serverctrls
= controlarrayWtoA( serverctrlsW
);
160 ldap_memfreeW( matchedW
);
161 ldap_memfreeW( errorW
);
162 ldap_value_freeW( referralsW
);
163 ldap_controls_freeW( serverctrlsW
);
167 /***********************************************************************
168 * ldap_parse_resultW (WLDAP32.@)
170 ULONG CDECL
ldap_parse_resultW( LDAP
*ld
, WLDAP32_LDAPMessage
*result
, ULONG
*retcode
, WCHAR
**matched
, WCHAR
**error
,
171 WCHAR
***referrals
, LDAPControlW
***serverctrls
, BOOLEAN free
)
174 char *matchedU
= NULL
, *errorU
= NULL
, **referralsU
= NULL
;
175 LDAPControl
**serverctrlsU
= NULL
;
177 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
, matched
, error
, referrals
, serverctrls
,
180 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
181 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
183 ret
= map_error( ldap_parse_result( CTX(ld
), MSG(result
), (int *)retcode
, &matchedU
, &errorU
, &referralsU
,
184 &serverctrlsU
, free
) );
186 if (matched
) *matched
= strUtoW( matchedU
);
187 if (error
) *error
= strUtoW( errorU
);
188 if (referrals
) *referrals
= strarrayUtoW( referralsU
);
189 if (serverctrls
) *serverctrls
= controlarrayUtoW( serverctrlsU
);
191 ldap_memfree( matchedU
);
192 ldap_memfree( errorU
);
193 ldap_memfree( referralsU
);
194 ldap_controls_free( serverctrlsU
);
198 /***********************************************************************
199 * ldap_parse_sort_controlA (WLDAP32.@)
201 ULONG CDECL
ldap_parse_sort_controlA( LDAP
*ld
, LDAPControlA
**control
, ULONG
*result
, char **attr
)
205 LDAPControlW
**controlW
= NULL
;
207 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
209 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
210 if (!control
) return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
211 if (!(controlW
= controlarrayAtoW( control
))) return WLDAP32_LDAP_NO_MEMORY
;
213 ret
= ldap_parse_sort_controlW( ld
, controlW
, result
, &attrW
);
215 *attr
= strWtoA( attrW
);
216 controlarrayfreeW( controlW
);
220 /***********************************************************************
221 * ldap_parse_sort_controlW (WLDAP32.@)
223 ULONG CDECL
ldap_parse_sort_controlW( LDAP
*ld
, LDAPControlW
**control
, ULONG
*result
, WCHAR
**attr
)
227 LDAPControl
**controlU
, *sortcontrol
= NULL
;
231 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
233 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
234 if (!control
) return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
235 if (!(controlU
= controlarrayWtoU( control
))) return WLDAP32_LDAP_NO_MEMORY
;
237 for (i
= 0; controlU
[i
]; i
++)
239 if (!strcmp( LDAP_SERVER_RESP_SORT_OID
, controlU
[i
]->ldctl_oid
))
240 sortcontrol
= controlU
[i
];
244 controlarrayfreeU( controlU
);
245 return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
248 ret
= map_error( ldap_parse_sortresponse_control( CTX(ld
), sortcontrol
, &res
, &attrU
) );
249 if (ret
== WLDAP32_LDAP_SUCCESS
)
252 if ((str
= strUtoW( attrU
)))
257 else ret
= WLDAP32_LDAP_NO_MEMORY
;
258 ldap_memfree( attrU
);
261 controlarrayfreeU( controlU
);
265 /***********************************************************************
266 * ldap_parse_vlv_controlA (WLDAP32.@)
268 int CDECL
ldap_parse_vlv_controlA( LDAP
*ld
, LDAPControlA
**control
, ULONG
*targetpos
, ULONG
*listcount
,
269 struct WLDAP32_berval
**context
, int *errcode
)
272 LDAPControlW
**controlW
= NULL
;
274 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
, listcount
, context
, errcode
);
278 if (control
&& !(controlW
= controlarrayAtoW( control
))) return WLDAP32_LDAP_NO_MEMORY
;
279 ret
= ldap_parse_vlv_controlW( ld
, controlW
, targetpos
, listcount
, context
, errcode
);
280 controlarrayfreeW( controlW
);
284 /***********************************************************************
285 * ldap_parse_vlv_controlW (WLDAP32.@)
287 int CDECL
ldap_parse_vlv_controlW( LDAP
*ld
, LDAPControlW
**control
, ULONG
*targetpos
, ULONG
*listcount
,
288 struct WLDAP32_berval
**context
, int *errcode
)
291 LDAPControl
**controlU
, *vlvcontrolU
= NULL
;
295 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
, listcount
, context
, errcode
);
297 if (!ld
|| !control
) return ~0u;
299 if (!(controlU
= controlarrayWtoU( control
))) return WLDAP32_LDAP_NO_MEMORY
;
301 for (i
= 0; controlU
[i
]; i
++)
303 if (!strcmp( LDAP_CONTROL_VLVRESPONSE
, controlU
[i
]->ldctl_oid
))
304 vlvcontrolU
= controlU
[i
];
308 controlarrayfreeU( controlU
);
309 return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
312 ret
= map_error( ldap_parse_vlvresponse_control( CTX(ld
), vlvcontrolU
, &pos
, &count
, &ctxU
, errcode
) );
313 if (ret
== WLDAP32_LDAP_SUCCESS
)
315 struct WLDAP32_berval
*bv
;
316 if ((bv
= bervalUtoW( ctxU
)))
322 else ret
= WLDAP32_LDAP_NO_MEMORY
;
326 controlarrayfreeU( controlU
);