ReactOS  0.4.13-dev-479-gec9c8fd
page.c
Go to the documentation of this file.
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "config.h"
22 #include "wine/port.h"
23 
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
28 #ifndef LDAP_MAXINT
29 #define LDAP_MAXINT 2147483647
30 #endif
31 
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnls.h"
35 
36 #include "winldap_private.h"
37 #include "wldap32.h"
38 #include "wine/debug.h"
39 
41 
42 /***********************************************************************
43  * ldap_create_page_controlA (WLDAP32.@)
44  *
45  * See ldap_create_page_controlW.
46  */
48  struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
49 {
51 #ifdef HAVE_LDAP
53 
54  TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
55  critical, control );
56 
57  if (!ld || !control || pagesize > LDAP_MAXINT)
59 
60  ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
61  if (ret == LDAP_SUCCESS)
62  {
63  *control = controlWtoA( controlW );
65  }
66 
67 #endif
68  return ret;
69 }
70 
71 #ifdef HAVE_LDAP
72 
73 /* create a page control by hand */
74 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
75  UCHAR critical, PLDAPControlW *control )
76 {
78  BerElement *ber;
79  ber_tag_t tag;
80  struct berval *berval, null_cookie = { 0, NULL };
81  INT ret, len;
82  char *val;
83 
84  ber = ber_alloc_t( LBER_USE_DER );
85  if (!ber) return WLDAP32_LDAP_NO_MEMORY;
86 
87  if (cookie)
88  tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, cookie );
89  else
90  tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, &null_cookie );
91 
92  ret = ber_flatten( ber, &berval );
93  ber_free( ber, 1 );
94 
95  if (tag == LBER_ERROR)
97 
98  if (ret == -1)
100 
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;
103 
104  len = berval->bv_len;
105  memcpy( val, berval->bv_val, len );
106  ber_bvfree( berval );
107 
108  if (!(ctrl = heap_alloc( sizeof(LDAPControlW) )))
109  {
110  heap_free( val );
111  return WLDAP32_LDAP_NO_MEMORY;
112  }
113 
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;
118 
119  *control = ctrl;
120 
121  return WLDAP32_LDAP_SUCCESS;
122 }
123 
124 #endif /* HAVE_LDAP */
125 
126 /***********************************************************************
127  * ldap_create_page_controlW (WLDAP32.@)
128  *
129  * Create a control for paged search results.
130  *
131  * PARAMS
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
135  * search results.
136  * critical [I] Tells the server this control is critical to the
137  * search operation.
138  * control [O] LDAPControl created.
139  *
140  * RETURNS
141  * Success: LDAP_SUCCESS
142  * Failure: An LDAP error code.
143  */
145  struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
146 {
147 #ifdef HAVE_LDAP
148  TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
149  critical, control );
150 
151  if (!ld || !control || pagesize > LDAP_MAXINT)
153 
154  return create_page_control( pagesize, cookie, critical, control );
155 
156 #else
158 #endif
159 }
160 
162  ULONG *message )
163 {
164  FIXME( "(%p, %p, 0x%08x, %p)\n", ld, search, pagesize, message );
165 
166  if (!ld) return ~0u;
168 }
169 
171  struct l_timeval *timeout, ULONG pagesize, ULONG *count,
173 {
174  FIXME( "(%p, %p, %p, 0x%08x, %p, %p)\n", ld, search, timeout,
175  pagesize, count, results );
176 
177  if (!ld) return ~0u;
179 }
180 
183 {
185 #ifdef HAVE_LDAP
186  FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
187 
188  if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
189  /* FIXME: save the cookie from the server here */
190 
191 #endif
192  return ret;
193 }
194 
195 /***********************************************************************
196  * ldap_parse_page_controlA (WLDAP32.@)
197  */
199  ULONG *count, struct WLDAP32_berval **cookie )
200 {
202 #ifdef HAVE_LDAP
203  LDAPControlW **ctrlsW = NULL;
204 
205  TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
206 
207  if (!ld || !ctrls || !count || !cookie)
209 
210  ctrlsW = controlarrayAtoW( ctrls );
211  if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
212 
213  ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
214  controlarrayfreeW( ctrlsW );
215 
216 #endif
217  return ret;
218 }
219 
220 /***********************************************************************
221  * ldap_parse_page_controlW (WLDAP32.@)
222  */
224  ULONG *count, struct WLDAP32_berval **cookie )
225 {
227 #ifdef HAVE_LDAP
228  LDAPControlW *control = NULL;
229  BerElement *ber;
230  ber_tag_t tag;
231  ULONG i;
232 
233  TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
234 
235  if (!ld || !ctrls || !count || !cookie)
237 
238  for (i = 0; ctrls[i]; i++)
239  {
240  if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
241  control = ctrls[i];
242  }
243 
244  if (!control)
246 
247  ber = ber_init( &((LDAPControl *)control)->ldctl_value );
248  if (!ber)
249  return WLDAP32_LDAP_NO_MEMORY;
250 
251  tag = ber_scanf( ber, "{iO}", count, cookie );
252  if ( tag == LBER_ERROR )
254  else
256 
257  ber_free( ber, 1 );
258 
259 #endif
260  return ret;
261 }
262 
264 {
265  FIXME( "(%p, %p)\n", ld, search );
266 
267  if (!ld) return ~0u;
268  return WLDAP32_LDAP_SUCCESS;
269 }
270 
272  PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
273  PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
274 {
275  FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_a(dn),
276  scope, debugstr_a(filter), attrs, attrsonly );
277  return NULL;
278 }
279 
281  PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
282  PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
283 {
284  FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(dn),
285  scope, debugstr_w(filter), attrs, attrsonly );
286  return NULL;
287 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
ULONG CDECL ldap_create_page_controlW(WLDAP32_LDAP *ld, ULONG pagesize, struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control)
Definition: page.c:144
signed char * PCHAR
Definition: retypes.h:7
static short search(int val, const short *table, int size)
Definition: msg711.c:255
Definition: tftpd.h:59
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
static const WCHAR controlW[]
Definition: actctx.c:621
GLuint GLuint GLsizei count
Definition: gl.h:1545
ULONG CDECL ldap_get_next_page(WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize, ULONG *message)
Definition: page.c:161
ULONG CDECL ldap_get_next_page_s(WLDAP32_LDAP *ld, PLDAPSearch search, struct l_timeval *timeout, ULONG pagesize, ULONG *count, WLDAP32_LDAPMessage **results)
Definition: page.c:170
#define LDAPControl
Definition: winldap.h:620
char * bv_val
Definition: winber.h:34
WINBERAPI BerElement * ber_alloc_t(int)
WINBERAPI ber_tag_t ber_scanf(BerElement *, const char *,...)
Definition: ecma_167.h:138
#define LDAP_MAXINT
Definition: page.c:29
Definition: dhcpd.h:245
uint16_t * PWCHAR
Definition: typedefs.h:54
int32_t INT
Definition: typedefs.h:56
#define LBER_USE_DER
Definition: winber.h:45
Definition: winber.h:32
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
ULONG CDECL ldap_create_page_controlA(WLDAP32_LDAP *ld, ULONG pagesize, struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control)
Definition: page.c:47
WINBERAPI BerElement * ber_init(const BerValue *)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
WINBERAPI int ber_flatten(BerElement *, BerValue **)
#define LDAP_PAGED_RESULT_OID_STRING
WINBERAPI int ber_printf(BerElement *, const char *,...)
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
INT ber_int_t
Definition: winber.h:39
smooth NULL
Definition: ftsmooth.c:416
#define ctrl
Definition: input.c:1669
GLuint GLfloat * val
Definition: glext.h:7180
#define LBER_ERROR
Definition: ber.c:32
#define TRACE(s)
Definition: solgame.cpp:4
PLDAPSearch CDECL ldap_search_init_pageW(WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope, PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys)
Definition: page.c:280
#define debugstr_a
Definition: kernel32.h:31
#define LDAP_PAGED_RESULT_OID_STRING_W
struct _test_info results[8]
Definition: SetCursorPos.c:29
ULONG CDECL ldap_parse_page_controlA(WLDAP32_LDAP *ld, PLDAPControlA *ctrls, ULONG *count, struct WLDAP32_berval **cookie)
Definition: page.c:198
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
static LPWSTR strAtoW(const char *str)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
PLDAPSearch CDECL ldap_search_init_pageA(WLDAP32_LDAP *ld, PCHAR dn, ULONG scope, PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys)
Definition: page.c:271
ULONG CDECL ldap_control_freeW(LDAPControlW *control)
Definition: control.c:67
struct ldapsearch * PLDAPSearch
WINE_DEFAULT_DEBUG_CHANNEL(wldap32)
WINBERAPI void ber_bvfree(BerValue *)
#define CDECL
Definition: compat.h:21
ULONG CDECL ldap_parse_page_controlW(WLDAP32_LDAP *ld, PLDAPControlW *ctrls, ULONG *count, struct WLDAP32_berval **cookie)
Definition: page.c:223
ULONG CDECL ldap_search_abandon_page(WLDAP32_LDAP *ld, PLDAPSearch search)
Definition: page.c:263
#define LDAP_SUCCESS
Definition: winldap.h:59
unsigned int ULONG
Definition: retypes.h:1
ULONG CDECL ldap_get_paged_count(WLDAP32_LDAP *ld, PLDAPSearch search, ULONG *count, WLDAP32_LDAPMessage *results)
Definition: page.c:181
ber_len_t bv_len
Definition: winber.h:33
ULONG ber_tag_t
Definition: winber.h:38
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
WINBERAPI void ber_free(BerElement *, int)
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
char * tag
Definition: main.c:59