1 /* $NetBSD: modify.c,v 1.1.1.3 2010/12/12 15:23:21 adam Exp $ */ 2 3 /* OpenLDAP: pkg/ldap/servers/slapd/back-perl/modify.c,v 1.23.2.6 2010/04/13 20:23:37 kurt Exp */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1999-2010 The OpenLDAP Foundation. 7 * Portions Copyright 1999 John C. Quillan. 8 * Portions Copyright 2002 myinternet Limited. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted only as authorized by the OpenLDAP 13 * Public License. 14 * 15 * A copy of this license is available in file LICENSE in the 16 * top-level directory of the distribution or, alternatively, at 17 * <http://www.OpenLDAP.org/license.html>. 18 */ 19 20 #include "perl_back.h" 21 22 int 23 perl_back_modify( 24 Operation *op, 25 SlapReply *rs ) 26 { 27 PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private; 28 Modifications *modlist = op->orm_modlist; 29 int count; 30 int i; 31 32 #if defined(HAVE_WIN32_ASPERL) || defined(USE_ITHREADS) 33 PERL_SET_CONTEXT( PERL_INTERPRETER ); 34 #endif 35 36 ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex ); 37 38 { 39 dSP; ENTER; SAVETMPS; 40 41 PUSHMARK(sp); 42 XPUSHs( perl_back->pb_obj_ref ); 43 XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , 0))); 44 45 for (; modlist != NULL; modlist = modlist->sml_next ) { 46 Modification *mods = &modlist->sml_mod; 47 48 switch ( mods->sm_op & ~LDAP_MOD_BVALUES ) { 49 case LDAP_MOD_ADD: 50 XPUSHs(sv_2mortal(newSVpv("ADD", 0 ))); 51 break; 52 53 case LDAP_MOD_DELETE: 54 XPUSHs(sv_2mortal(newSVpv("DELETE", 0 ))); 55 break; 56 57 case LDAP_MOD_REPLACE: 58 XPUSHs(sv_2mortal(newSVpv("REPLACE", 0 ))); 59 break; 60 } 61 62 63 XPUSHs(sv_2mortal(newSVpv( mods->sm_desc->ad_cname.bv_val, 0 ))); 64 65 for ( i = 0; 66 mods->sm_values != NULL && mods->sm_values[i].bv_val != NULL; 67 i++ ) 68 { 69 XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, 0 ))); 70 } 71 72 /* Fix delete attrib without value. */ 73 if ( i == 0) { 74 XPUSHs(sv_newmortal()); 75 } 76 } 77 78 PUTBACK; 79 80 #ifdef PERL_IS_5_6 81 count = call_method("modify", G_SCALAR); 82 #else 83 count = perl_call_method("modify", G_SCALAR); 84 #endif 85 86 SPAGAIN; 87 88 if (count != 1) { 89 croak("Big trouble in back_modify\n"); 90 } 91 92 rs->sr_err = POPi; 93 94 PUTBACK; FREETMPS; LEAVE; 95 } 96 97 ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex ); 98 99 send_ldap_result( op, rs ); 100 101 Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n", 0, 0, 0 ); 102 return( 0 ); 103 } 104 105