modrdn.c 6.93 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 <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
25
#include "winldap.h"
26

27
#include "wine/debug.h"
28
#include "winldap_private.h"
29 30 31

WINE_DEFAULT_DEBUG_CHANNEL(wldap32);

32 33 34 35 36
/***********************************************************************
 *      ldap_modrdnA     (WLDAP32.@)
 *
 * See ldap_modrdnW.
 */
37
ULONG CDECL ldap_modrdnA( LDAP *ld, char *dn, char *newdn )
38
{
39
    ULONG ret = LDAP_NO_MEMORY;
40 41 42 43
    WCHAR *dnW = NULL, *newdnW = NULL;

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

44
    if (!ld || !newdn) return ~0u;
45

46 47
    if (dn && !(dnW = strAtoW( dn ))) goto exit;
    if (!(newdnW = strAtoW( newdn ))) goto exit;
48 49 50 51

    ret = ldap_modrdnW( ld, dnW, newdnW );

exit:
52 53
    free( dnW );
    free( newdnW );
54 55 56
    return ret;
}

57 58 59 60 61 62 63 64
/***********************************************************************
 *      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.
65
 *  newdn   [I] New DN for the entry.
66 67 68 69 70 71 72 73 74 75
 *
 * 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.
 */
76
ULONG CDECL ldap_modrdnW( LDAP *ld, WCHAR *dn, WCHAR *newdn )
77 78
{
    TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
79
    return ldap_modrdn2W( ld, dn, newdn, 1 );
80 81
}

82 83 84 85 86
/***********************************************************************
 *      ldap_modrdn2A     (WLDAP32.@)
 *
 * See ldap_modrdn2W.
 */
87
ULONG CDECL ldap_modrdn2A( LDAP *ld, char *dn, char *newdn, int delete )
88
{
89
    ULONG ret = LDAP_NO_MEMORY;
90 91 92 93
    WCHAR *dnW = NULL, *newdnW = NULL;

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

94
    if (!ld || !newdn) return ~0u;
95

96 97
    if (dn && !(dnW = strAtoW( dn ))) goto exit;
    if (!(newdnW = strAtoW( newdn ))) goto exit;
98 99 100 101

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

exit:
102 103
    free( dnW );
    free( newdnW );
104 105 106
    return ret;
}

107 108 109 110 111 112 113 114
/***********************************************************************
 *      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.
115
 *  newdn   [I] New DN for the entry.
116 117 118 119 120 121 122 123 124 125 126
 *  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.
 */
127
ULONG CDECL ldap_modrdn2W( LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
128
{
129
    ULONG ret = LDAP_NO_MEMORY;
130
    char *dnU = NULL, *newdnU = NULL;
131
    ULONG msg;
132 133 134

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

135
    if (!ld || !newdn) return ~0u;
136

137 138 139 140 141 142 143 144 145 146 147 148
    if (dn && !(dnU = strWtoU( dn ))) return LDAP_NO_MEMORY;

    if ((newdnU = strWtoU( newdn )))
    {
        struct ldap_rename_params params = { CTX(ld), dnU, newdnU, NULL, delete, NULL, NULL, &msg };
        ret = LDAP_CALL( ldap_rename, &params );
        if (ret == LDAP_SUCCESS)
            ret = msg;
        else
            ret = ~0u;
        free( newdnU );
    }
149
    free( dnU );
150 151 152
    return ret;
}

153 154 155 156 157
/***********************************************************************
 *      ldap_modrdn2_sA     (WLDAP32.@)
 *
 * See ldap_modrdn2_sW.
 */
158
ULONG CDECL ldap_modrdn2_sA( LDAP *ld, char *dn, char *newdn, int delete )
159
{
160
    ULONG ret = LDAP_NO_MEMORY;
161 162 163 164
    WCHAR *dnW = NULL, *newdnW = NULL;

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

165
    if (!ld || !newdn) return LDAP_PARAM_ERROR;
166

167 168
    if (dn && !(dnW = strAtoW( dn ))) goto exit;
    if (!(newdnW = strAtoW( newdn ))) goto exit;
169 170 171 172

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

exit:
173 174
    free( dnW );
    free( newdnW );
175 176 177
    return ret;
}

178 179 180 181 182 183 184 185
/***********************************************************************
 *      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.
186
 *  newdn   [I] New DN for the entry.
187 188 189 190 191 192
 *  delete  [I] Delete old DN?
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 */
193
ULONG CDECL ldap_modrdn2_sW( LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
194
{
195
    ULONG ret = LDAP_NO_MEMORY;
196 197 198 199
    char *dnU = NULL, *newdnU = NULL;

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

200
    if (!ld || !newdn) return LDAP_PARAM_ERROR;
201

202
    if (dn && !(dnU = strWtoU( dn ))) return LDAP_NO_MEMORY;
203

204 205 206 207 208 209
    if ((newdnU = strWtoU( newdn )))
    {
        struct ldap_rename_s_params params = { CTX(ld), dnU, newdnU, NULL, delete, NULL, NULL };
        ret = map_error( LDAP_CALL( ldap_rename_s, &params ));
        free( newdnU );
    }
210
    free( dnU );
211 212 213
    return ret;
}

214 215 216 217 218
/***********************************************************************
 *      ldap_modrdn_sA     (WLDAP32.@)
 *
 * See ldap_modrdn_sW.
 */
219
ULONG CDECL ldap_modrdn_sA( LDAP *ld, char *dn, char *newdn )
220
{
221
    ULONG ret = LDAP_NO_MEMORY;
222 223 224 225
    WCHAR *dnW = NULL, *newdnW = NULL;

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

226
    if (!ld || !newdn) return LDAP_PARAM_ERROR;
227

228 229
    if (dn && !(dnW = strAtoW( dn ))) goto exit;
    if (!(newdnW = strAtoW( newdn ))) goto exit;
230 231 232 233

    ret = ldap_modrdn_sW( ld, dnW, newdnW );

exit:
234 235
    free( dnW );
    free( newdnW );
236 237 238
    return ret;
}

239 240 241 242 243 244 245 246
/***********************************************************************
 *      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.
247
 *  newdn   [I] New DN for the entry.
248 249 250 251 252
 *
 * RETURNS
 *  Success: LDAP_SUCCESS
 *  Failure: An LDAP error code.
 */
253
ULONG CDECL ldap_modrdn_sW( LDAP *ld, WCHAR *dn, WCHAR *newdn )
254 255
{
    TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
256
    return ldap_modrdn2_sW( ld, dn, newdn, 1 );
257
}