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
 */

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

#include <stdarg.h>
25 26 27
#ifdef HAVE_LDAP_H
#include <ldap.h>
#endif
28 29 30 31 32 33 34

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

#include "winldap_private.h"
#include "wldap32.h"
35
#include "wine/debug.h"
36 37 38

WINE_DEFAULT_DEBUG_CHANNEL(wldap32);

39 40 41 42 43
/***********************************************************************
 *      ldap_modrdnA     (WLDAP32.@)
 *
 * See ldap_modrdnW.
 */
44
ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
45
{
46
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
47 48 49 50 51 52 53
#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) );

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

    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;
}

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/***********************************************************************
 *      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.
 */
93
ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
94
{
95
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
96 97
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;
98
    int msg;
99 100 101 102 103

    ret = WLDAP32_LDAP_NO_MEMORY;

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

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

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

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

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

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

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

#endif
    return ret;
}

129 130 131 132 133
/***********************************************************************
 *      ldap_modrdn2A     (WLDAP32.@)
 *
 * See ldap_modrdn2W.
 */
134
ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
135
{
136
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
137 138 139 140 141 142 143
#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 );

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

    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;
}

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
/***********************************************************************
 *      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.
 */
184
ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
185
{
186
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
187 188
#ifdef HAVE_LDAP
    char *dnU = NULL, *newdnU = NULL;
189
    int msg;
190 191 192 193 194

    ret = WLDAP32_LDAP_NO_MEMORY;

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

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

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

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

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

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

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

#endif
    return ret;
}

220 221 222 223 224
/***********************************************************************
 *      ldap_modrdn2_sA     (WLDAP32.@)
 *
 * See ldap_modrdn2_sW.
 */
225
ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
226
{
227
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
228 229 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
#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;
}

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
/***********************************************************************
 *      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.
 */
270
ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
271
{
272
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
#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;

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

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

#endif
    return ret;
}

300 301 302 303 304
/***********************************************************************
 *      ldap_modrdn_sA     (WLDAP32.@)
 *
 * See ldap_modrdn_sW.
 */
305
ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
306
{
307
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
308 309 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
#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;
}

335 336 337 338 339 340 341 342 343 344 345 346 347 348
/***********************************************************************
 *      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.
 */
349
ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
350
{
351
    ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
#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;

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

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

#endif
    return ret;
}