]> git.sur5r.net Git - openldap/blob - servers/ldapd/modrdn.c
Resync with HEAD
[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 <stdio.h>
14 #include <quipu/commonarg.h>
15 #include <quipu/attrvalue.h>
16 #include <quipu/ds_error.h>
17 #include <quipu/modifyrdn.h>
18 #include <quipu/dap2.h>
19 #include <quipu/dua.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include "lber.h"
23 #include "ldap.h"
24 #include "common.h"
25
26 #ifdef COMPAT20
27 extern int      ldap_compat;
28 #define MODRDNTAG       (ldap_compat == 20 ? OLD_LDAP_RES_MODRDN : LDAP_RES_MODRDN)
29 #else
30 #define MODRDNTAG       LDAP_RES_MODRDN
31 #endif
32
33 int
34 do_modrdn(
35     Sockbuf     *clientsb,
36     struct msg  *m,
37     BerElement  *ber
38 )
39 {
40         char                    *dn, *newrdn;
41         int                     rc, deleteoldrdn;
42         struct ds_modifyrdn_arg ma;
43         static CommonArgs       common = default_common_args;
44         extern DN               ldap_str2dn();
45         extern RDN              ldap_str2rdn();
46
47         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
48
49         /*
50          * Parse the modrdn request.  It looks like this:
51          *      ModifyRDNRequest := SEQUENCE {
52          *              entry   DistinguishedName,
53          *              newrdn  RelativeDistinguishedName
54          *      }
55          */
56
57 #if ISODEPACKAGE == IC
58 #if ICRELEASE > 2
59         DAS_ModifyDnArgument_INIT( &ma );
60 #endif
61 #endif
62
63         if ( ber_scanf( ber, "{aa", &dn, &newrdn ) == LBER_ERROR ) {
64                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
65                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
66                     LDAP_PROTOCOL_ERROR, NULL, "" );
67                 return( 0 );
68         }
69
70         deleteoldrdn = 1;
71         if ( ber_scanf( ber, "b", &deleteoldrdn ) == LBER_ERROR ) {
72                 Debug( LDAP_DEBUG_ANY, "found old modrdn\n", 0, 0, 0 );
73         }
74
75         Debug( LDAP_DEBUG_ARGS,
76             "do_modrdn: dn (%s) newrdn (%s) deleteoldrdn (%d)\n", dn, newrdn,
77             deleteoldrdn );
78
79         ma.mra_object = ldap_str2dn( dn );
80         free( dn );
81         if ( ma.mra_object == NULLDN ) {
82                 Debug( LDAP_DEBUG_ANY, "ldap_str2dn failed\n", 0, 0, 0 );
83                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
84                     LDAP_INVALID_DN_SYNTAX, NULL, "" );
85                 return( 0 );
86         }
87
88         ma.mra_newrdn = ldap_str2rdn( newrdn );
89         free( newrdn );
90         if ( ma.mra_newrdn == NULLRDN ) {
91                 Debug( LDAP_DEBUG_ANY, "str2rdn failed\n", 0, 0, 0 );
92                 send_ldap_msgresult( clientsb, MODRDNTAG, m,
93                     LDAP_INVALID_DN_SYNTAX, NULL, "Bad RDN" );
94                 return( 0 );
95         }
96         ma.deleterdn = (deleteoldrdn ? 1 : 0);
97
98         ma.mra_common = common; /* struct copy */
99
100         rc = initiate_dap_operation( OP_MODIFYRDN, m, &ma );
101
102         dn_free( ma.mra_object );
103         rdn_free( ma.mra_newrdn );
104
105         if ( rc != 0 ) {
106                 send_ldap_msgresult( clientsb, MODRDNTAG, m, rc, NULL, "" );
107                 return( 0 );
108         }
109
110         return( 1 );
111 }
112
113 void
114 modrdn_result( Sockbuf *sb, struct msg *m )
115 {
116         send_ldap_msgresult( sb, MODRDNTAG, m, LDAP_SUCCESS, NULL, "" );
117
118         return;
119 }