]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
SLAPD compiles. Needs LDBM work to link.
[openldap] / servers / slapd / modrdn.c
1 /*
2  * Copyright (c) 1995 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 #include <ac/string.h>
19
20 #include "slap.h"
21
22 extern Backend  *select_backend();
23
24 extern char     *default_referral;
25
26 void
27 do_modrdn(
28     Connection  *conn,
29     Operation   *op
30 )
31 {
32         char    *dn, *odn, *newrdn;
33         int     deloldrdn;
34         Backend *be;
35
36         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
37
38         /*
39          * Parse the modrdn request.  It looks like this:
40          *
41          *      ModifyRDNRequest := SEQUENCE {
42          *              entry   DistinguishedName,
43          *              newrdn  RelativeDistinguishedName
44          *      }
45          */
46
47         if ( ber_scanf( op->o_ber, "{aab}", &dn, &newrdn, &deloldrdn )
48             == LBER_ERROR ) {
49                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
50                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
51                 return;
52         }
53         odn = strdup( dn );
54         dn_normalize( dn );
55
56         Debug( LDAP_DEBUG_ARGS,
57             "do_modrdn: dn (%s) newrdn (%s) deloldrdn (%d)\n", dn, newrdn,
58             deloldrdn );
59
60         Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
61             conn->c_connid, op->o_opid, dn, 0, 0 );
62
63         /*
64          * We could be serving multiple database backends.  Select the
65          * appropriate one, or send a referral to our "referral server"
66          * if we don't hold it.
67          */
68
69         if ( (be = select_backend( dn )) == NULL ) {
70                 free( dn );
71                 free( odn );
72                 free( newrdn );
73                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
74                     default_referral );
75                 return;
76         }
77
78         /*
79          * do the add if 1 && (2 || 3)
80          * 1) there is an add function implemented in this backend;
81          * 2) this backend is master for what it holds;
82          * 3) it's a replica and the dn supplied is the updatedn.
83          */
84         if ( be->be_modrdn != NULL ) {
85                 /* do the update here */
86                 if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
87                     op->o_dn ) == 0 ) {
88                         if ( (*be->be_modrdn)( be, conn, op, dn, newrdn,
89                             deloldrdn ) == 0 ) {
90                                 replog( be, LDAP_REQ_MODRDN, odn, newrdn,
91                                     deloldrdn );
92                         }
93                 } else {
94                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
95                             default_referral );
96                 }
97         } else {
98                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
99                     "Function not implemented" );
100         }
101
102         free( dn );
103         free( odn );
104         free( newrdn );
105 }