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
22 #include "wine/port.h"
29 #define LDAP_MAXINT 2147483647
36 #include "winldap_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
42 /***********************************************************************
43 * ldap_create_page_controlA (WLDAP32.@)
45 * See ldap_create_page_controlW.
47 ULONG CDECL
ldap_create_page_controlA( WLDAP32_LDAP
*ld
, ULONG pagesize
,
48 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlA
*control
)
50 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
52 LDAPControlW
*controlW
= NULL
;
54 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
57 if (!ld
|| !control
|| pagesize
> LDAP_MAXINT
)
58 return WLDAP32_LDAP_PARAM_ERROR
;
60 ret
= ldap_create_page_controlW( ld
, pagesize
, cookie
, critical
, &controlW
);
61 if (ret
== LDAP_SUCCESS
)
63 *control
= controlWtoA( controlW
);
64 ldap_control_freeW( controlW
);
73 /* create a page control by hand */
74 static ULONG
create_page_control( ULONG pagesize
, struct WLDAP32_berval
*cookie
,
75 UCHAR critical
, PLDAPControlW
*control
)
80 struct berval
*berval
, null_cookie
= { 0, NULL
};
84 ber
= ber_alloc_t( LBER_USE_DER
);
85 if (!ber
) return WLDAP32_LDAP_NO_MEMORY
;
88 tag
= ber_printf( ber
, "{iO}", (ber_int_t
)pagesize
, cookie
);
90 tag
= ber_printf( ber
, "{iO}", (ber_int_t
)pagesize
, &null_cookie
);
92 ret
= ber_flatten( ber
, &berval
);
95 if (tag
== LBER_ERROR
)
96 return WLDAP32_LDAP_ENCODING_ERROR
;
99 return WLDAP32_LDAP_NO_MEMORY
;
101 /* copy the berval so it can be properly freed by the caller */
102 if (!(val
= heap_alloc( berval
->bv_len
))) return WLDAP32_LDAP_NO_MEMORY
;
104 len
= berval
->bv_len
;
105 memcpy( val
, berval
->bv_val
, len
);
106 ber_bvfree( berval
);
108 if (!(ctrl
= heap_alloc( sizeof(LDAPControlW
) )))
111 return WLDAP32_LDAP_NO_MEMORY
;
114 ctrl
->ldctl_oid
= strAtoW( LDAP_PAGED_RESULT_OID_STRING
);
115 ctrl
->ldctl_value
.bv_len
= len
;
116 ctrl
->ldctl_value
.bv_val
= val
;
117 ctrl
->ldctl_iscritical
= critical
;
121 return WLDAP32_LDAP_SUCCESS
;
124 #endif /* HAVE_LDAP */
126 /***********************************************************************
127 * ldap_create_page_controlW (WLDAP32.@)
129 * Create a control for paged search results.
132 * ld [I] Pointer to an LDAP context.
133 * pagesize [I] Number of entries to return per page.
134 * cookie [I] Used by the server to track its location in the
136 * critical [I] Tells the server this control is critical to the
138 * control [O] LDAPControl created.
141 * Success: LDAP_SUCCESS
142 * Failure: An LDAP error code.
144 ULONG CDECL
ldap_create_page_controlW( WLDAP32_LDAP
*ld
, ULONG pagesize
,
145 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlW
*control
)
148 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
151 if (!ld
|| !control
|| pagesize
> LDAP_MAXINT
)
152 return WLDAP32_LDAP_PARAM_ERROR
;
154 return create_page_control( pagesize
, cookie
, critical
, control
);
157 return WLDAP32_LDAP_NOT_SUPPORTED
;
161 ULONG CDECL
ldap_get_next_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
, ULONG pagesize
,
164 FIXME( "(%p, %p, 0x%08x, %p)\n", ld
, search
, pagesize
, message
);
167 return WLDAP32_LDAP_NOT_SUPPORTED
;
170 ULONG CDECL
ldap_get_next_page_s( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
171 struct l_timeval
*timeout
, ULONG pagesize
, ULONG
*count
,
172 WLDAP32_LDAPMessage
**results
)
174 FIXME( "(%p, %p, %p, 0x%08x, %p, %p)\n", ld
, search
, timeout
,
175 pagesize
, count
, results
);
178 return WLDAP32_LDAP_NOT_SUPPORTED
;
181 ULONG CDECL
ldap_get_paged_count( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
182 ULONG
*count
, WLDAP32_LDAPMessage
*results
)
184 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
186 FIXME( "(%p, %p, %p, %p)\n", ld
, search
, count
, results
);
188 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
189 /* FIXME: save the cookie from the server here */
195 /***********************************************************************
196 * ldap_parse_page_controlA (WLDAP32.@)
198 ULONG CDECL
ldap_parse_page_controlA( WLDAP32_LDAP
*ld
, PLDAPControlA
*ctrls
,
199 ULONG
*count
, struct WLDAP32_berval
**cookie
)
201 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
203 LDAPControlW
**ctrlsW
= NULL
;
205 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
207 if (!ld
|| !ctrls
|| !count
|| !cookie
)
208 return WLDAP32_LDAP_PARAM_ERROR
;
210 ctrlsW
= controlarrayAtoW( ctrls
);
211 if (!ctrlsW
) return WLDAP32_LDAP_NO_MEMORY
;
213 ret
= ldap_parse_page_controlW( ld
, ctrlsW
, count
, cookie
);
214 controlarrayfreeW( ctrlsW
);
220 /***********************************************************************
221 * ldap_parse_page_controlW (WLDAP32.@)
223 ULONG CDECL
ldap_parse_page_controlW( WLDAP32_LDAP
*ld
, PLDAPControlW
*ctrls
,
224 ULONG
*count
, struct WLDAP32_berval
**cookie
)
226 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
228 LDAPControlW
*control
= NULL
;
233 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
235 if (!ld
|| !ctrls
|| !count
|| !cookie
)
236 return WLDAP32_LDAP_PARAM_ERROR
;
238 for (i
= 0; ctrls
[i
]; i
++)
240 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W
, ctrls
[i
]->ldctl_oid
))
245 return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
247 ber
= ber_init( &((LDAPControl
*)control
)->ldctl_value
);
249 return WLDAP32_LDAP_NO_MEMORY
;
251 tag
= ber_scanf( ber
, "{iO}", count
, cookie
);
252 if ( tag
== LBER_ERROR
)
253 ret
= WLDAP32_LDAP_DECODING_ERROR
;
255 ret
= WLDAP32_LDAP_SUCCESS
;
263 ULONG CDECL
ldap_search_abandon_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
)
265 FIXME( "(%p, %p)\n", ld
, search
);
268 return WLDAP32_LDAP_SUCCESS
;
271 PLDAPSearch CDECL
ldap_search_init_pageA( WLDAP32_LDAP
*ld
, PCHAR dn
, ULONG scope
,
272 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
273 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyA
*sortkeys
)
275 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_a(dn
),
276 scope
, debugstr_a(filter
), attrs
, attrsonly
);
280 PLDAPSearch CDECL
ldap_search_init_pageW( WLDAP32_LDAP
*ld
, PWCHAR dn
, ULONG scope
,
281 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
282 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyW
*sortkeys
)
284 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld
, debugstr_w(dn
),
285 scope
, debugstr_w(filter
), attrs
, attrsonly
);