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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
24 #include "wine/debug.h"
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
44 /***********************************************************************
45 * ldap_create_page_controlA (WLDAP32.@)
47 * See ldap_create_page_controlW.
49 ULONG
ldap_create_page_controlA( WLDAP32_LDAP
*ld
, ULONG pagesize
,
50 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlA
*control
)
52 ULONG ret
= LDAP_NOT_SUPPORTED
;
54 LDAPControlW
*controlW
= NULL
;
56 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
59 if (!ld
|| !control
) return WLDAP32_LDAP_PARAM_ERROR
;
61 ret
= ldap_create_page_controlW( ld
, pagesize
, cookie
, critical
, &controlW
);
62 if (ret
== LDAP_SUCCESS
)
64 *control
= controlWtoA( controlW
);
65 ldap_control_freeW( controlW
);
74 /* create a page control by hand */
75 static ULONG
create_page_control( ULONG pagesize
, struct WLDAP32_berval
*cookie
,
76 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 ber_printf( ber
, "{iO}", pagesize
, cookie
);
90 ber_printf( ber
, "{iO}", pagesize
, &null_cookie
);
92 ret
= ber_flatten( ber
, &berval
);
96 return WLDAP32_LDAP_NO_MEMORY
;
98 /* copy the berval so it can be properly freed by the caller */
99 val
= HeapAlloc( GetProcessHeap(), 0, berval
->bv_len
);
100 if (!val
) return WLDAP32_LDAP_NO_MEMORY
;
102 len
= berval
->bv_len
;
103 memcpy( val
, berval
->bv_val
, len
);
104 ber_bvfree( berval
);
106 ctrl
= HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW
) );
108 return WLDAP32_LDAP_NO_MEMORY
;
110 ctrl
->ldctl_oid
= strAtoW( LDAP_PAGED_RESULT_OID_STRING
);
111 ctrl
->ldctl_value
.bv_len
= len
;
112 ctrl
->ldctl_value
.bv_val
= val
;
113 ctrl
->ldctl_iscritical
= critical
;
120 #endif /* HAVE_LDAP */
122 /***********************************************************************
123 * ldap_create_page_controlW (WLDAP32.@)
125 * Create a control for paged search results.
128 * ld [I] Pointer to an LDAP context.
129 * pagesize [I] Number of entries to return per page.
130 * cookie [I] Used by the server to track its location in the
132 * critical [I] Tells the server this control is critical to the
134 * control [O] LDAPControl created.
137 * Success: LDAP_SUCCESS
138 * Failure: An LDAP error code.
140 ULONG
ldap_create_page_controlW( WLDAP32_LDAP
*ld
, ULONG pagesize
,
141 struct WLDAP32_berval
*cookie
, UCHAR critical
, PLDAPControlW
*control
)
143 ULONG ret
= LDAP_NOT_SUPPORTED
;
146 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld
, pagesize
, cookie
,
149 if (!ld
|| !control
) return WLDAP32_LDAP_PARAM_ERROR
;
150 return create_page_control( pagesize
, cookie
, critical
, control
);
156 ULONG
ldap_get_next_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
, ULONG pagesize
,
159 FIXME( "(%p, %p, 0x%08lx, %p)\n", ld
, search
, pagesize
, message
);
161 if (!ld
) return ~0UL;
162 return LDAP_NOT_SUPPORTED
;
165 ULONG
ldap_get_next_page_s( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
166 struct l_timeval
*timeout
, ULONG pagesize
, ULONG
*count
,
167 WLDAP32_LDAPMessage
**results
)
169 FIXME( "(%p, %p, %p, 0x%08lx, %p, %p)\n", ld
, search
, timeout
,
170 pagesize
, count
, results
);
172 if (!ld
) return ~0UL;
173 return LDAP_NOT_SUPPORTED
;
176 ULONG
ldap_get_paged_count( WLDAP32_LDAP
*ld
, PLDAPSearch search
,
177 ULONG
*count
, WLDAP32_LDAPMessage
*results
)
179 ULONG ret
= LDAP_NOT_SUPPORTED
;
181 FIXME( "(%p, %p, %p, %p)\n", ld
, search
, count
, results
);
183 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
184 /* FIXME: save the cookie from the server here */
190 /***********************************************************************
191 * ldap_parse_page_controlA (WLDAP32.@)
193 ULONG
ldap_parse_page_controlA( WLDAP32_LDAP
*ld
, PLDAPControlA
*ctrls
,
194 ULONG
*count
, struct WLDAP32_berval
**cookie
)
196 ULONG ret
= LDAP_NOT_SUPPORTED
;
198 LDAPControlW
**ctrlsW
= NULL
;
200 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
202 if (!ld
|| !ctrls
|| !count
|| !cookie
)
203 return WLDAP32_LDAP_PARAM_ERROR
;
205 ctrlsW
= controlarrayAtoW( ctrls
);
206 if (!ctrlsW
) return WLDAP32_LDAP_NO_MEMORY
;
208 ret
= ldap_parse_page_controlW( ld
, ctrlsW
, count
, cookie
);
209 controlarrayfreeW( ctrlsW
);
215 /***********************************************************************
216 * ldap_parse_page_controlW (WLDAP32.@)
218 ULONG
ldap_parse_page_controlW( WLDAP32_LDAP
*ld
, PLDAPControlW
*ctrls
,
219 ULONG
*count
, struct WLDAP32_berval
**cookie
)
221 ULONG ret
= LDAP_NOT_SUPPORTED
;
223 LDAPControlW
*control
= NULL
;
228 TRACE( "(%p, %p, %p, %p)\n", ld
, ctrls
, count
, cookie
);
230 if (!ld
|| !ctrls
|| !count
|| !cookie
)
231 return WLDAP32_LDAP_PARAM_ERROR
;
233 for (i
= 0; ctrls
[i
]; i
++)
235 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W
, ctrls
[i
]->ldctl_oid
))
240 return WLDAP32_LDAP_CONTROL_NOT_FOUND
;
242 ber
= ber_init( &((LDAPControl
*)control
)->ldctl_value
);
244 return WLDAP32_LDAP_NO_MEMORY
;
246 tag
= ber_scanf( ber
, "{iO}", count
, cookie
);
247 if ( tag
== LBER_ERROR
)
248 ret
= WLDAP32_LDAP_DECODING_ERROR
;
258 ULONG
ldap_search_abandon_page( WLDAP32_LDAP
*ld
, PLDAPSearch search
)
260 FIXME( "(%p, %p)\n", ld
, search
);
262 if (!ld
) return ~0UL;
266 PLDAPSearch
ldap_search_init_pageA( WLDAP32_LDAP
*ld
, PCHAR dn
, ULONG scope
,
267 PCHAR filter
, PCHAR attrs
[], ULONG attrsonly
, PLDAPControlA
*serverctrls
,
268 PLDAPControlA
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyA
*sortkeys
)
270 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld
, debugstr_a(dn
),
271 scope
, debugstr_a(filter
), attrs
, attrsonly
);
275 PLDAPSearch
ldap_search_init_pageW( WLDAP32_LDAP
*ld
, PWCHAR dn
, ULONG scope
,
276 PWCHAR filter
, PWCHAR attrs
[], ULONG attrsonly
, PLDAPControlW
*serverctrls
,
277 PLDAPControlW
*clientctrls
, ULONG timelimit
, ULONG sizelimit
, PLDAPSortKeyW
*sortkeys
)
279 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld
, debugstr_w(dn
),
280 scope
, debugstr_w(filter
), attrs
, attrsonly
);