]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_modrdn.c
Style changes, added cvs keywords
[openldap] / servers / slapd / back-tcl / tcl_modrdn.c
1 /*
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  * $Id$
12  *
13  * $Log$
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include "slap.h"
21 #include "tcl_back.h"
22
23 int tcl_back_modrdn (
24         Backend * be,
25         Connection * conn,
26         Operation * op,
27         char *dn,
28         char *newrdn,
29         int deleteoldrdn
30 )
31 {
32         char *command, *suf_tcl, *results;
33         int i, code, err = 0;
34         struct tclinfo *ti = (struct tclinfo *) be->be_private;
35
36         if (ti->ti_modrdn == NULL) {
37                 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
38                         "modrdn not implemented");
39                 return (-1);
40         }
41
42         for ( i = 0; be->be_suffix[i] != NULL; i++ )
43                 ;
44         suf_tcl = Tcl_Merge(i, be->be_suffix);
45
46         command = (char *) ch_malloc (strlen(ti->ti_modrdn) + strlen(suf_tcl)
47                 + strlen(dn) + strlen(newrdn) + 64);
48         sprintf(command, "%s MODRDN {%ld} {%s} {%s} {%s} %d",
49                 ti->ti_add, op->o_msgid, suf_tcl, dn, newrdn, deleteoldrdn ? 1 : 0);
50         Tcl_Free(suf_tcl);
51
52         ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex );
53         code = Tcl_GlobalEval(ti->ti_ii->interp, command);
54         results = (char *) strdup(ti->ti_ii->interp->result);
55         ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex );
56         free(command);
57
58         if (code != TCL_OK) {
59                 err = LDAP_OPERATIONS_ERROR;
60                 Debug(LDAP_DEBUG_ANY, "tcl_modrdn_error: %s\n", results, 0, 0);
61         } else {
62                 interp_send_results ( be, conn, op, results, NULL, 0 );
63         }
64
65         if (err != LDAP_SUCCESS)
66                 send_ldap_result (conn, op, err, NULL, "internal backend error");
67
68         return (0);
69 }