control.c 9.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * WLDAP32 - LDAP support for Wine
 *
 * Copyright 2005 Hans Leidekker
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 */

#include "config.h"

#include "wine/port.h"
#include "wine/debug.h"

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winnls.h"

#ifdef HAVE_LDAP_H
#include <ldap.h>
#endif

#include "winldap_private.h"
#include "wldap32.h"

WINE_DEFAULT_DEBUG_CHANNEL(wldap32);

41 42 43 44 45
/***********************************************************************
 *      ldap_control_freeA     (WLDAP32.@)
 *
 * See ldap_control_freeW.
 */
46
ULONG CDECL ldap_control_freeA( LDAPControlA *control )
47
{
48
    ULONG ret = WLDAP32_LDAP_SUCCESS;
49 50 51 52 53 54 55 56 57
#ifdef HAVE_LDAP

    TRACE( "(%p)\n", control );
    controlfreeA( control );

#endif
    return ret;
}

58 59 60 61 62
/***********************************************************************
 *      ldap_control_freeW     (WLDAP32.@)
 *
 * Free an LDAPControl structure.
 *
63
 * PARAMS
64 65 66 67 68
 *  control  [I] LDAPControl structure to free.
 *
 * RETURNS
 *  LDAP_SUCCESS
 */
69
ULONG CDECL ldap_control_freeW( LDAPControlW *control )
70
{
71
    ULONG ret = WLDAP32_LDAP_SUCCESS;
72 73 74 75 76 77 78 79 80
#ifdef HAVE_LDAP

    TRACE( "(%p)\n", control );
    controlfreeW( control );

#endif
    return ret;
}

81 82 83 84 85
/***********************************************************************
 *      ldap_controls_freeA     (WLDAP32.@)
 *
 * See ldap_controls_freeW.
 */
86
ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
87
{
88
    ULONG ret = WLDAP32_LDAP_SUCCESS;
89 90 91 92 93 94 95 96 97
#ifdef HAVE_LDAP

    TRACE( "(%p)\n", controls );
    controlarrayfreeA( controls );

#endif
    return ret;
}

98 99 100 101 102
/***********************************************************************
 *      ldap_controls_freeW     (WLDAP32.@)
 *
 * Free an array of LDAPControl structures.
 *
103
 * PARAMS
104 105 106 107 108
 *  controls  [I] Array of LDAPControl structures to free.
 *
 * RETURNS
 *  LDAP_SUCCESS
 */
109
ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
110
{
111
    ULONG ret = WLDAP32_LDAP_SUCCESS;
112 113 114 115 116 117 118 119 120
#ifdef HAVE_LDAP

    TRACE( "(%p)\n", controls );
    controlarrayfreeW( controls );

#endif
    return ret;
}

121 122 123 124 125
/***********************************************************************
 *      ldap_create_sort_controlA     (WLDAP32.@)
 *
 * See ldap_create_sort_controlW.
 */
126
ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkey,
127 128
    UCHAR critical, PLDAPControlA *control )
{
129
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
#ifdef HAVE_LDAP
    LDAPSortKeyW **sortkeyW = NULL;
    LDAPControlW *controlW = NULL;

    TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );

    if (!ld || !sortkey || !control)
        return WLDAP32_LDAP_PARAM_ERROR;

    sortkeyW = sortkeyarrayAtoW( sortkey );
    if (!sortkeyW) return WLDAP32_LDAP_NO_MEMORY;

    ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );

    *control = controlWtoA( controlW );
    if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;

    ldap_control_freeW( controlW );
    sortkeyarrayfreeW( sortkeyW );

#endif
    return ret;
}

154 155 156 157 158
/***********************************************************************
 *      ldap_create_sort_controlW     (WLDAP32.@)
 *
 * Create a control for server sorted search results.
 *
159
 * PARAMS
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
 *  ld       [I] Pointer to an LDAP context.
 *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
 *               attribute to use as a sort key, a matching rule and
 *               the sort order (ascending or descending).
 *  critical [I] Tells the server this control is critical to the
 *               search operation.
 *  control  [O] LDAPControl created.
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 *
 * NOTES
 *  Pass the created control as a server control in subsequent calls
 *  to ldap_search_ext(_s) to obtain sorted search results.
 */
176
ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkey,
177 178
    UCHAR critical, PLDAPControlW *control )
{
179
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
#ifdef HAVE_LDAP
    LDAPSortKey **sortkeyU = NULL;
    LDAPControl *controlU = NULL;

    TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );

    if (!ld || !sortkey || !control)
        return WLDAP32_LDAP_PARAM_ERROR;

    sortkeyU = sortkeyarrayWtoU( sortkey );
    if (!sortkeyU) return WLDAP32_LDAP_NO_MEMORY;

    ret = ldap_create_sort_control( ld, sortkeyU, critical, &controlU );

    *control = controlUtoW( controlU );
    if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;

    ldap_control_free( controlU );
    sortkeyarrayfreeU( sortkeyU );

#endif
    return ret;
}

204 205 206 207 208
/***********************************************************************
 *      ldap_create_vlv_controlA     (WLDAP32.@)
 *
 * See ldap_create_vlv_controlW.
 */
209
INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
210
    UCHAR critical, LDAPControlA **control )
211
{
212
    INT ret = WLDAP32_LDAP_NOT_SUPPORTED;
213
#ifdef HAVE_LDAP
214
    LDAPControlW *controlW = NULL;
215 216 217

    TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );

218
    if (!ld || !control) return ~0UL;
219

220
    ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
221

222
    if (ret == WLDAP32_LDAP_SUCCESS)
223 224 225 226 227
    {
        *control = controlWtoA( controlW );
        if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
        ldap_control_freeW( controlW );
    }
228 229 230 231 232

#endif
    return ret;
}

233 234 235 236 237
/***********************************************************************
 *      ldap_create_vlv_controlW     (WLDAP32.@)
 *
 * Create a virtual list view control.
 *
238
 * PARAMS
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
 *  ld       [I] Pointer to an LDAP context.
 *  info     [I] LDAPVLVInfo structure specifying a list view window.
 *  critical [I] Tells the server this control is critical to the
 *               search operation.
 *  control  [O] LDAPControl created.
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 *
 * NOTES
 *  Pass the created control in conjuction with a sort control as
 *  server controls in subsequent calls to ldap_search_ext(_s). The
 *  server will then return a sorted, contiguous subset of results
 *  that meets the criteria specified in the LDAPVLVInfo structure.
 */
255
INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
256
    UCHAR critical, LDAPControlW **control )
257
{
258
    INT ret = WLDAP32_LDAP_NOT_SUPPORTED;
259
#ifdef HAVE_LDAP
260
    LDAPControl *controlU = NULL;
261 262 263

    TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );

264
    if (!ld || !control) return ~0UL;
265

266
    ret = ldap_create_vlv_control( ld, (LDAPVLVInfo *)info, &controlU );
267

268 269 270 271 272 273
    if (ret == LDAP_SUCCESS)
    {
        *control = controlUtoW( controlU );
        if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
        ldap_control_free( controlU );
    }
274 275 276 277 278

#endif
    return ret;
}

279 280 281 282 283
/***********************************************************************
 *      ldap_encode_sort_controlA     (WLDAP32.@)
 *
 * See ldap_encode_sort_controlW.
 */
284
ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys,
285 286 287 288 289
    PLDAPControlA control, BOOLEAN critical )
{
    return ldap_create_sort_controlA( ld, sortkeys, critical, &control );
}

290 291 292 293 294
/***********************************************************************
 *      ldap_encode_sort_controlW     (WLDAP32.@)
 *
 * Create a control for server sorted search results.
 *
295
 * PARAMS
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
 *  ld       [I] Pointer to an LDAP context.
 *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
 *               attribute to use as a sort key, a matching rule and
 *               the sort order (ascending or descending).
 *  critical [I] Tells the server this control is critical to the
 *               search operation.
 *  control  [O] LDAPControl created.
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 *
 * NOTES
 *  This function is obsolete. Use its equivalent
 *  ldap_create_sort_control instead.
 */
312
ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys,
313 314 315 316 317
    PLDAPControlW control, BOOLEAN critical )
{
    return ldap_create_sort_controlW( ld, sortkeys, critical, &control );
}

318 319 320 321 322
/***********************************************************************
 *      ldap_free_controlsA     (WLDAP32.@)
 *
 * See ldap_free_controlsW.
 */
323
ULONG CDECL ldap_free_controlsA( LDAPControlA **controls )
324 325 326 327
{
    return ldap_controls_freeA( controls );
}

328 329 330 331 332
/***********************************************************************
 *      ldap_free_controlsW     (WLDAP32.@)
 *
 * Free an array of LDAPControl structures.
 *
333
 * PARAMS
334 335 336 337 338 339 340 341
 *  controls  [I] Array of LDAPControl structures to free.
 *
 * RETURNS
 *  LDAP_SUCCESS
 *  
 * NOTES
 *  Obsolete, use ldap_controls_freeW.
 */
342
ULONG CDECL ldap_free_controlsW( LDAPControlW **controls )
343 344 345
{
    return ldap_controls_freeW( controls );
}