]> git.sur5r.net Git - openldap/blob - servers/ldapd/modrdn.c
Fix modlist bug in last commit
[openldap] / servers / ldapd / modrdn.c
1 /*
2  * Copyright (c) 1990 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/socket.h>
18
19 #include <quipu/commonarg.h>
20 #include <quipu/attrvalue.h>
21 #include <quipu/ds_error.h>
22 #include <quipu/modifyrdn.h>
23 #include <quipu/dap2.h>
24 #include <quipu/dua.h>
25
26 #include "lber.h"
27 #include "ldap.h"
28 #include "common.h"
29
30 #ifdef LDAP_COMPAT20
31 #define MODRDNTAG       (ldap_compat == 20 ? OLD_LDAP_RES_MODRDN : LDAP_RES_MODRDN)
32 #else
33 #define MODRDNTAG       LDAP_RES_MODRDN
34 #endif
35
36 int
37 do_modrdn(
38     Sockbuf     *clientsb,
39     struct msg  *m,
40     BerElement  *ber
41 )
42 {
43         char                    *dn, *newrdn;
44         int                     rc, deleteoldrdn;
45         struct ds_modifyrdn_arg ma;
46         static CommonArgs       common = default_common_args;
47
48         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
49
50         /*
51          * Parse the modrdn request.  It looks like this:
52          *      ModifyRDNRequest := SEQUENCE {
53          *              entry   DistinguishedName,
54          *              newrdn  RelativeDistinguishedName
55          *      }
56          */
57
58 #if ISODEPACKAGE == IC
59 #if ICRELEASE > 2
60         DAS_ModifyDnArgument_INIT( &ma );
61 #endif
62 #endif
63
64         if ( ber_scanf( ber, "{aa", &dn, &newrdn ) == LBER_ERROR ) {
65                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
66                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
67                     LDAP_PROTOCOL_ERROR, NULL, "" );
68                 return( 0 );
69         }
70
71         deleteoldrdn = 1;
72         if ( ber_scanf( ber, "b", &deleteoldrdn ) == LBER_ERROR ) {
73                 Debug( LDAP_DEBUG_ANY, "found old modrdn\n", 0, 0, 0 );
74         }
75
76         Debug( LDAP_DEBUG_ARGS,
77             "do_modrdn: dn (%s) newrdn (%s) deleteoldrdn (%d)\n", dn, newrdn,
78             deleteoldrdn );
79
80         ma.mra_object = ldap_str2dn( dn );
81         free( dn );
82         if ( ma.mra_object == NULLDN ) {
83                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
84                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
85                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
86                 return( 0 );
87         }
88
89         ma.mra_newrdn = ldap_str2rdn( newrdn );
90         free( newrdn );
91         if ( ma.mra_newrdn == NULLRDN ) {
92                 Debug( LDAP_DEBUG_ANY, "str2rdn failed\n", 0, 0, 0 );
93                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
94                     LDAP_INVALID_DN_SYNTAX, NULL, "Bad RDN" );
95                 return( 0 );
96         }
97         ma.deleterdn = (deleteoldrdn ? 1 : 0);
98
99         ma.mra_common = common; /* struct copy */
100
101         rc = initiate_dap_operation( OP_MODIFYRDN, m, &ma );
102
103         dn_free( ma.mra_object );
104         rdn_free( ma.mra_newrdn );
105
106         if ( rc != 0 ) {
107                 send_ldap_msgresult( clientsb, MODRDNTAG, m, rc, NULL, "" );
108                 return( 0 );
109         }
110
111         return( 1 );
112 }
113
114 void
115 modrdn_result( Sockbuf *sb, struct msg *m )
116 {
117         send_ldap_msgresult( sb, MODRDNTAG, m, LDAP_SUCCESS, NULL, "" );
118
119         return;
120 }