]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_modrdn.c
#ifdef for slap_auxprop_store
[openldap] / servers / slapd / back-tcl / tcl_modrdn.c
1 /* $OpenLDAP$ */
2 /* modrdn.c - tcl modify rdn routines
3  *
4  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11
12 /*
13  * LDAP v3 newSuperior support.
14  *
15  * Copyright 1999, Juan C. Gomez, All rights reserved.
16  * This software is not subject to any license of Silicon Graphics 
17  * Inc. or Purdue University.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * without restriction or fee of any kind as long as this notice
21  * is preserved.
22  *
23  */
24
25 #include "portable.h"
26
27 #include <stdio.h>
28
29 #include "slap.h"
30 #include "tcl_back.h"
31
32 int
33 tcl_back_modrdn (
34         Operation * op,
35         SlapReply * rs
36 )
37 {
38         char *command, *results;
39         struct berval suf_tcl;
40         int code;
41         struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
42
43         if (ti->ti_modrdn.bv_len == 0) {
44                 send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
45                         "modrdn not implemented" );
46                 return (-1);
47         }
48
49         if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
50                 send_ldap_error (op, rs, LDAP_OTHER, NULL);
51                 return (-1);
52         }
53
54         command = (char *) ch_malloc (ti->ti_modrdn.bv_len + suf_tcl.bv_len
55                 + op->o_req_dn.bv_len + op->oq_modrdn.rs_newrdn.bv_len
56                 + (op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_len : 0) + 84);
57         if ( op->oq_modrdn.rs_newSup ) {
58                 sprintf (command, "%s MODRDN {%ld/%ld} {%s} {%s} {%s} %d {%s}",
59                          ti->ti_modrdn.bv_val,
60                          op->o_connid, (long) op->o_msgid, 
61                          suf_tcl.bv_val, op->o_req_dn.bv_val,
62                          op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_deleteoldrdn ? 1 : 0, 
63                          op->oq_modrdn.rs_newSup->bv_val );
64         } else {
65                 sprintf (command, "%s MODRDN {%ld} {%s} {%s} {%s} %d",
66                          ti->ti_modrdn.bv_val, (long) op->o_msgid, 
67                          suf_tcl.bv_val, op->o_req_dn.bv_val,
68                          op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
69         }       
70         Tcl_Free (suf_tcl.bv_val);
71
72         ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
73         code = Tcl_GlobalEval (ti->ti_ii->interp, command);
74         results = (char *) ch_strdup (ti->ti_ii->interp->result);
75         ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
76         free (command);
77
78         if (code != TCL_OK) {
79                 rs->sr_err = LDAP_OTHER;
80                 Debug (LDAP_DEBUG_SHELL, "tcl_modrdn_error: %s\n", results,
81                         0, 0);
82         } else {
83                 interp_send_results (op, rs, results);
84         }
85
86         if (rs->sr_err != LDAP_SUCCESS) {
87                 rs->sr_text = "internal backend error";
88                 send_ldap_result (op, rs);
89         }
90
91         free (results);
92         return (rs->sr_err);
93 }