]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_bind.c
rework objectClass mucking to use syntax "pretty" routine
[openldap] / servers / slapd / back-tcl / tcl_bind.c
1 /* $OpenLDAP$ */
2 /* bind.c - tcl bind 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 #include "portable.h"
13
14 #include <stdio.h>
15
16 #include "slap.h"
17 #include "tcl_back.h"
18
19 int
20 tcl_back_bind (
21         Operation * op,
22         SlapReply * rs )
23 {
24         char *command, *results;
25         struct berval suf_tcl;
26         int code;
27         struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
28
29         if (ti->ti_bind.bv_len == 0) {
30                 send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
31                         "bind not implemented" );
32                 return (-1);
33         }
34
35         if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
36                 send_ldap_error (op, rs, LDAP_OTHER, NULL );
37                 return (-1);
38         }
39
40         command = (char *) ch_malloc (ti->ti_bind.bv_len + suf_tcl.bv_len +
41                 op->o_req_dn.bv_len + op->oq_bind.rb_cred.bv_len + 84);
42         sprintf (command, "%s BIND {%ld/%ld} {%s} {%s} {%d} {%lu} {%s}",
43                 ti->ti_bind.bv_val, op->o_connid, (long) op->o_msgid,
44                 suf_tcl.bv_val, 
45                 op->o_req_dn.bv_val, op->oq_bind.rb_method, op->oq_bind.rb_cred.bv_len, op->oq_bind.rb_cred.bv_val);
46         Tcl_Free (suf_tcl.bv_val);
47
48         ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
49         code = Tcl_GlobalEval (ti->ti_ii->interp, command);
50         results = (char *) ch_strdup (ti->ti_ii->interp->result);
51         ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
52         free (command);
53
54         if (code != TCL_OK) {
55                 rs->sr_err = LDAP_OTHER;
56                 Debug (LDAP_DEBUG_SHELL, "tcl_bind_error: %s\n", results, 0, 0);
57         } else {
58                 rs->sr_err = interp_send_results (op, rs, results);
59         }
60
61         if (rs->sr_err != LDAP_SUCCESS) {
62                 rs->sr_text = "internal backend error";
63                 send_ldap_result (op, rs);
64         }
65
66         free (results);
67         return (rs->sr_err);
68 }