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