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