]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_unbind.c
Style changes, added cvs keywords
[openldap] / servers / slapd / back-tcl / tcl_unbind.c
1 /*
2  * unbind.c - tcl unbind 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_unbind (
24         Backend * be,
25         Connection * conn,
26         Operation * op
27 )
28 {
29         char *command, *suf_tcl, *results;
30         int i, code, err = 0;
31         struct tclinfo *ti = (struct tclinfo *) be->be_private;
32
33         if (ti->ti_unbind == NULL) {
34                 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
35                         "unbind not implemented");
36                 return;
37         }
38
39         for ( i = 0; be->be_suffix[i] != NULL; i++ )
40                 ;
41         suf_tcl = Tcl_Merge(i, be->be_suffix);
42
43         command = (char *) ch_malloc (strlen(ti->ti_unbind) + strlen(suf_tcl)
44                 + strlen(conn->c_dn ? conn->c_dn : "") + 64);
45         sprintf(command, "%s UNBIND {%ld} {%s} {%s}",
46                 ti->ti_unbind, op->o_msgid, suf_tcl, conn->c_dn ? conn->c_dn : "");
47         Tcl_Free(suf_tcl);
48
49         ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex );
50         code = Tcl_GlobalEval(ti->ti_ii->interp, command);
51         results = (char *) strdup(ti->ti_ii->interp->result);
52         ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex );
53         free(command);
54
55         if (code != TCL_OK) {
56                 Debug(LDAP_DEBUG_ANY, "tcl_unbind_error: %s\n", results, 0, 0);
57         }
58         return 0;
59 }