2 * modify.c - tcl modify routines
4 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
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.
27 char *command, *suf_tcl, *bp, *tcl_mods, *results;
28 int i, code, err = 0, len, bsize;
29 struct tclinfo *ti = (struct tclinfo *) be->be_private;
31 if (ti->ti_modify == NULL) {
32 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
33 "modify not implemented");
37 for ( i = 0; be->be_suffix[i] != NULL; i++ )
39 suf_tcl = Tcl_Merge(i, be->be_suffix);
41 tcl_mods = (char *) ch_malloc( BUFSIZ );
46 for ( ; modlist != NULL; modlist = modlist->ml_next ) {
47 LDAPMod *mods = &modlist->ml_mod;
50 switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
57 case LDAP_MOD_REPLACE:
62 len = strlen( mods->mod_type ) + strlen ( op ) + 7;
63 while ( bp + len - tcl_mods > bsize ) {
65 tcl_mods = (char *) ch_realloc( tcl_mods, bsize );
67 sprintf(bp, "{ {%s: %s} ", op, mods->mod_type);
70 mods->mod_bvalues != NULL && mods->mod_bvalues[i] != NULL;
73 len = strlen( mods->mod_type ) + strlen (
74 mods->mod_bvalues[i]->bv_val ) + 5 +
75 (mods->mod_bvalues[i+1] == NULL ? 2 : 0);
76 while ( bp + len - tcl_mods > bsize ) {
78 tcl_mods = (char *) ch_realloc( tcl_mods, bsize );
80 sprintf(bp, "{%s: %s} %s", mods->mod_type,
81 mods->mod_bvalues[i]->bv_val, mods->mod_bvalues[i+1] ==
87 command = (char *) ch_malloc (strlen(ti->ti_modify) + strlen(suf_tcl)
88 + strlen(dn) + strlen(tcl_mods) + 64);
89 /* This space is simply for aesthetics--\ */
90 sprintf(command, "%s MODIFY {%ld} {%s} {%s} { %s}",
91 ti->ti_modify, op->o_msgid, suf_tcl, dn, tcl_mods);
95 ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex );
96 code = Tcl_GlobalEval(ti->ti_ii->interp, command);
97 results = (char *) strdup(ti->ti_ii->interp->result);
98 ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex );
101 if (code != TCL_OK) {
102 err = LDAP_OPERATIONS_ERROR;
103 Debug(LDAP_DEBUG_ANY, "tcl_modify_error: %s\n", results, 0, 0);
105 interp_send_results ( be, conn, op, results, NULL, 0 );
108 if (err != LDAP_SUCCESS)
109 send_ldap_result (conn, op, err, NULL, "internal backend error");