modrdn.c 8.58 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_modrdnA     (WLDAP32.@)
 *
 * See ldap_modrdnW.
 */
46
ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
47
{
48
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
49 50 51 52 53 54 55
#ifdef HAVE_LDAP
    WCHAR *dnW = NULL, *newdnW = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );

56
    if (!ld || !newdn) return ~0u;
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

    if (dn) {
        dnW = strAtoW( dn );
        if (!dnW) goto exit;
    }

    newdnW = strAtoW( newdn );
    if (!newdnW) goto exit;

    ret = ldap_modrdnW( ld, dnW, newdnW );

exit:
    strfreeW( dnW );
    strfreeW( newdnW );

#endif
    return ret;
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/***********************************************************************
 *      ldap_modrdnW     (WLDAP32.@)
 *
 * Change the RDN of a directory entry (asynchronous operation).
 *
 * PARAMS
 *  ld      [I] Pointer to an LDAP context.
 *  dn      [I] DN of the entry to change.
 *  newdn   [I] New DN for the entry. 
 *
 * RETURNS
 *  Success: Message ID of the modrdn operation.
 *  Failure: An LDAP error code.
 *
 * NOTES
 *  Call ldap_result with the message ID to get the result of
 *  the operation. Cancel the operation by calling ldap_abandon
 *  with the message ID.
 */
95
ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
96
{
97
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
98 99
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;
100
    int msg;
101 102 103 104 105

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );

106
    if (!ld || !newdn) return ~0u;
107 108 109 110 111 112 113 114 115

    if (dn) {
        dnU = strWtoU( dn );
        if (!dnU) goto exit;
    }

    newdnU = strWtoU( newdn );
    if (!newdnU) goto exit;

116 117 118 119 120
    ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );

    if (ret == LDAP_SUCCESS)
        ret = msg;
    else
121
        ret = ~0u;
122 123 124 125 126 127 128 129 130

exit:
    strfreeU( dnU );
    strfreeU( newdnU );

#endif
    return ret;
}

131 132 133 134 135
/***********************************************************************
 *      ldap_modrdn2A     (WLDAP32.@)
 *
 * See ldap_modrdn2W.
 */
136
ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
137
{
138
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 140 141 142 143 144 145
#ifdef HAVE_LDAP
    WCHAR *dnW = NULL, *newdnW = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );

146
    if (!ld || !newdn) return ~0u;
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

    if (dn) {
        dnW = strAtoW( dn );
        if (!dnW) goto exit;
    }

    newdnW = strAtoW( newdn );
    if (!newdnW) goto exit;

    ret = ldap_modrdn2W( ld, dnW, newdnW, delete );

exit:
    strfreeW( dnW );
    strfreeW( newdnW );

#endif
    return ret;
}

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
/***********************************************************************
 *      ldap_modrdn2W     (WLDAP32.@)
 *
 * Change the RDN of a directory entry (asynchronous operation).
 *
 * PARAMS
 *  ld      [I] Pointer to an LDAP context.
 *  dn      [I] DN of the entry to change.
 *  newdn   [I] New DN for the entry. 
 *  delete  [I] Delete old DN?
 *
 * RETURNS
 *  Success: Message ID of the modrdn operation.
 *  Failure: An LDAP error code.
 *
 * NOTES
 *  Call ldap_result with the message ID to get the result of
 *  the operation. Cancel the operation by calling ldap_abandon
 *  with the message ID.
 */
186
ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
187
{
188
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
189 190
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;
191
    int msg;
192 193 194 195 196

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );

197
    if (!ld || !newdn) return ~0u;
198 199 200 201 202 203 204 205 206

    if (dn) {
        dnU = strWtoU( dn );
        if (!dnU) goto exit;
    }

    newdnU = strWtoU( newdn );
    if (!newdnU) goto exit;

207 208 209 210 211
    ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );

    if (ret == LDAP_SUCCESS)
        ret = msg;
    else
212
        ret = ~0u;
213 214 215 216 217 218 219 220 221

exit:
    strfreeU( dnU );
    strfreeU( newdnU );

#endif
    return ret;
}

222 223 224 225 226
/***********************************************************************
 *      ldap_modrdn2_sA     (WLDAP32.@)
 *
 * See ldap_modrdn2_sW.
 */
227
ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
228
{
229
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
#ifdef HAVE_LDAP
    WCHAR *dnW = NULL, *newdnW = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );

    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;

    if (dn) {
        dnW = strAtoW( dn );
        if (!dnW) goto exit;
    }

    newdnW = strAtoW( newdn );
    if (!newdnW) goto exit;

    ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );

exit:
    strfreeW( dnW );
    strfreeW( newdnW );

#endif
    return ret;
}

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
/***********************************************************************
 *      ldap_modrdn2_sW     (WLDAP32.@)
 *
 * Change the RDN of a directory entry (synchronous operation).
 *
 * PARAMS
 *  ld      [I] Pointer to an LDAP context.
 *  dn      [I] DN of the entry to change.
 *  newdn   [I] New DN for the entry. 
 *  delete  [I] Delete old DN?
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 */
272
ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
273
{
274
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );

    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;

    if (dn) {
        dnU = strWtoU( dn );
        if (!dnU) goto exit;
    }

    newdnU = strWtoU( newdn );
    if (!newdnU) goto exit;

292
    ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL ));
293 294 295 296 297 298 299 300 301

exit:
    strfreeU( dnU );
    strfreeU( newdnU );

#endif
    return ret;
}

302 303 304 305 306
/***********************************************************************
 *      ldap_modrdn_sA     (WLDAP32.@)
 *
 * See ldap_modrdn_sW.
 */
307
ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
308
{
309
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
#ifdef HAVE_LDAP
    WCHAR *dnW = NULL, *newdnW = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );

    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;

    if (dn) {
        dnW = strAtoW( dn );
        if (!dnW) goto exit;
    }

    newdnW = strAtoW( newdn );
    if (!newdnW) goto exit;

    ret = ldap_modrdn_sW( ld, dnW, newdnW );

exit:
    strfreeW( dnW );
    strfreeW( newdnW );

#endif
    return ret;
}

337 338 339 340 341 342 343 344 345 346 347 348 349 350
/***********************************************************************
 *      ldap_modrdn_sW     (WLDAP32.@)
 *
 * Change the RDN of a directory entry (synchronous operation).
 *
 * PARAMS
 *  ld      [I] Pointer to an LDAP context.
 *  dn      [I] DN of the entry to change.
 *  newdn   [I] New DN for the entry. 
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 */
351
ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
352
{
353
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;

    ret = WLDAP32_LDAP_NO_MEMORY;

    TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );

    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;

    if (dn) {
        dnU = strWtoU( dn );
        if (!dnU) goto exit;
    }

    newdnU = strWtoU( newdn );
    if (!newdnU) goto exit;

371
    ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL ));
372 373 374 375 376 377 378 379

exit:
    strfreeU( dnU );
    strfreeU( newdnU );

#endif
    return ret;
}