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
23 #include "wine/port.h"
24 #include "wine/debug.h"
36 #include "winldap_private.h"
40 #define LDAP_MAXINT 2147483647
43 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
45 /***********************************************************************
46 * ldap_create_page_controlA (WLDAP32.@)
48 * See ldap_create_page_controlW.
50 ULONG CDECL
ldap_create_page_controlA( WLDAP32_LDAP
*ld
, ULONG pagesize
,
51 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlA
*control
)
53 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
55 LDAPControlW
*controlW
= NULL
;
57 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
60 if (!ld
|| !control
|| pagesize
> LDAP_MAXINT
)
61 return WLDAP32_LDAP_PARAM_ERROR
;
63 ret
= ldap_create_page_controlW( ld
, pagesize
, cookie
, critical
, &controlW
);
64 if (ret
== LDAP_SUCCESS
)
66 *control
= controlWtoA( controlW
);
67 ldap_control_freeW( controlW
);
76 /* create a page control by hand */
77 static ULONG
create_page_control( ULONG pagesize
, struct WLDAP32_berval
*cookie
,
78 UCHAR critical
, PLDAPControlW
*control
)
83 struct berval
*berval
, null_cookie
= { 0, NULL
};
87 ber
= ber_alloc_t( LBER_USE_DER
);
88 if (!ber
) return WLDAP32_LDAP_NO_MEMORY
;
91 tag
= ber_printf( ber
, "{iO}", (ber_int_t
)pagesize
, cookie
);
93 tag
= ber_printf( ber
, "{iO}", (ber_int_t
)pagesize
, &null_cookie
);
95 ret
= ber_flatten( ber
, &berval
);
98 if (tag
== LBER_ERROR
)
99 return WLDAP32_LDAP_ENCODING_ERROR
;
102 return WLDAP32_LDAP_NO_MEMORY
;
104 /* copy the berval so it can be properly freed by the caller */
105 val
= HeapAlloc( GetProcessHeap(), 0, berval
->bv_len
);
106 if (!val
) return WLDAP32_LDAP_NO_MEMORY
;
108 len
= berval
->bv_len
;
109 memcpy( val
, berval
->bv_val
, len
);
110 ber_bvfree( berval
);
112 ctrl
= HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW
) );
115 HeapFree( GetProcessHeap(), 0, val
);
116 return WLDAP32_LDAP_NO_MEMORY
;
119 ctrl
->ldctl_oid
= strAtoW( LDAP_PAGED_RESULT_OID_STRING
);
120 ctrl
->ldctl_value
.bv_len
= len
;
121 ctrl
->ldctl_value
.bv_val
= val
;
122 ctrl
->ldctl_iscritical
= critical
;
126 return WLDAP32_LDAP_SUCCESS
;
129 #endif /* HAVE_LDAP */
131 /***********************************************************************
132 * ldap_create_page_controlW (WLDAP32.@)
134 * Create a control for paged search results.
137 * ld [I] Pointer to an LDAP context.
138 * pagesize [I] Number of entries to return per page.
139 * cookie [I] Used by the server to track its location in the
141 * critical [I] Tells the server this control is critical to the
143 * control [O] LDAPControl created.
146 * Success: LDAP_SUCCESS
147 * Failure: An LDAP error code.
149 ULONG CDECL
ldap_create_page_controlW( WLDAP32_LDAP
*ld
, ULONG pagesize
,
150 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlW
*control
)
153 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
156 if (!ld
|| !control
|| pagesize
> LDAP_MAXINT
)
157 return WLDAP32_LDAP_PARAM_ERROR
;
159 return create_page_control( pagesize
, cookie
, critical
, control
);
162 return WLDAP32_LDAP_NOT_SUPPORTED
;
166 ULONG CDECL
ldap_get_next_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
, ULONG pagesize
,
169 FIXME( "(%p, %p, 0x%08x, %p)\n", ld
, search
, pagesize
, message
);
171 if (!ld
) return ~0UL;
172 return WLDAP32_LDAP_NOT_SUPPORTED
;
175 ULONG CDECL
ldap_get_next_page_s( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
176 struct l_timeval
*timeout
, ULONG pagesize
, ULONG
*count
,
177 WLDAP32_LDAPMessage
**results
)
179 FIXME( "(%p, %p, %p, 0x%08x, %p, %p)\n", ld
, search
, timeout
,
180 pagesize
, count
, results
);
182 if (!ld
) return ~0UL;
183 return WLDAP32_LDAP_NOT_SUPPORTED
;
186 ULONG CDECL
ldap_get_paged_count( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
187 ULONG
*count
, WLDAP32_LDAPMessage
*results
)
189 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
191 FIXME( "(%p, %p, %p, %p)\n", ld
, search
, count
, results
);
193 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
194 /* FIXME: save the cookie from the server here */
200 /***********************************************************************
201 * ldap_parse_page_controlA (WLDAP32.@)
203 ULONG CDECL
ldap_parse_page_controlA( WLDAP32_LDAP
*ld
, PLDAPControlA
*ctrls
,
204 ULONG
*count
, struct WLDAP32_berval
**cookie
)
206 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
208 LDAPControlW
**ctrlsW
= NULL
;
210 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
212 if (!ld
|| !ctrls
|| !count
|| !cookie
)
213 return WLDAP32_LDAP_PARAM_ERROR
;
215 ctrlsW
= controlarrayAtoW( ctrls
);
216 if (!ctrlsW
) return WLDAP32_LDAP_NO_MEMORY
;
218 ret
= ldap_parse_page_controlW( ld
, ctrlsW
, count
, cookie
);
219 controlarrayfreeW( ctrlsW
);
225 /***********************************************************************
226 * ldap_parse_page_controlW (WLDAP32.@)
228 ULONG CDECL
ldap_parse_page_controlW( WLDAP32_LDAP
*ld
, PLDAPControlW
*ctrls
,
229 ULONG
*count
, struct WLDAP32_berval
**cookie
)
231 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
233 LDAPControlW
*control
= NULL
;
238 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
240 if (!ld
|| !ctrls
|| !count
|| !cookie
)
241 return WLDAP32_LDAP_PARAM_ERROR
;
243 for (i
= 0; ctrls
[i
]; i
++)
245 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W
, ctrls
[i
]->ldctl_oid
))
250 return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
252 ber
= ber_init( &((LDAPControl
*)control
)->ldctl_value
);
254 return WLDAP32_LDAP_NO_MEMORY
;
256 tag
= ber_scanf( ber
, "{iO}", count
, cookie
);
257 if ( tag
== LBER_ERROR
)
258 ret
= WLDAP32_LDAP_DECODING_ERROR
;
260 ret
= WLDAP32_LDAP_SUCCESS
;
268 ULONG CDECL
ldap_search_abandon_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
)
270 FIXME( "(%p, %p)\n", ld
, search
);
272 if (!ld
) return ~0UL;
273 return WLDAP32_LDAP_SUCCESS
;
276 PLDAPSearch CDECL
ldap_search_init_pageA( WLDAP32_LDAP
*ld
, PCHAR dn
, ULONG scope
,
277 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
278 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyA
*sortkeys
)
280 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
),
281 scope
, debugstr_a(filter
), attrs
, attrsonly
);
285 PLDAPSearch CDECL
ldap_search_init_pageW( WLDAP32_LDAP
*ld
, PWCHAR dn
, ULONG scope
,
286 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
287 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyW
*sortkeys
)
289 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
),
290 scope
, debugstr_w(filter
), attrs
, attrsonly
);