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