1/*	$NetBSD: modify.c,v 1.3 2021/08/14 16:15:01 christos Exp $	*/
2
3/* $OpenLDAP$ */
4/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 1999-2021 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#include <ac/string.h>
22
23int
24perl_back_modify(
25	Operation	*op,
26	SlapReply	*rs )
27{
28	PerlBackend *perl_back = (PerlBackend *)op->o_bd->be_private;
29	Modifications *modlist = op->orm_modlist;
30	int count;
31	int i;
32
33	PERL_SET_CONTEXT( PERL_INTERPRETER );
34	ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
35
36	{
37		dSP; ENTER; SAVETMPS;
38
39		PUSHMARK(sp);
40		XPUSHs( perl_back->pb_obj_ref );
41		XPUSHs(sv_2mortal(newSVpv( op->o_req_dn.bv_val , 0)));
42
43		for (; modlist != NULL; modlist = modlist->sml_next ) {
44			Modification *mods = &modlist->sml_mod;
45
46			switch ( mods->sm_op & ~LDAP_MOD_BVALUES ) {
47			case LDAP_MOD_ADD:
48				XPUSHs(sv_2mortal(newSVpv("ADD", STRLENOF("ADD") )));
49				break;
50
51			case LDAP_MOD_DELETE:
52				XPUSHs(sv_2mortal(newSVpv("DELETE", STRLENOF("DELETE") )));
53				break;
54
55			case LDAP_MOD_REPLACE:
56				XPUSHs(sv_2mortal(newSVpv("REPLACE", STRLENOF("REPLACE") )));
57				break;
58			}
59
60
61			XPUSHs(sv_2mortal(newSVpv( mods->sm_desc->ad_cname.bv_val,
62				mods->sm_desc->ad_cname.bv_len )));
63
64			for ( i = 0;
65				mods->sm_values != NULL && mods->sm_values[i].bv_val != NULL;
66				i++ )
67			{
68				XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, mods->sm_values[i].bv_len )));
69			}
70
71			/* Fix delete attrib without value. */
72			if ( i == 0) {
73				XPUSHs(sv_newmortal());
74			}
75		}
76
77		PUTBACK;
78
79		count = call_method("modify", G_SCALAR);
80
81		SPAGAIN;
82
83		if (count != 1) {
84			croak("Big trouble in back_modify\n");
85		}
86
87		rs->sr_err = POPi;
88
89		PUTBACK; FREETMPS; LEAVE;
90	}
91
92	ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
93
94	send_ldap_result( op, rs );
95
96	Debug( LDAP_DEBUG_ANY, "Perl MODIFY\n" );
97	return( 0 );
98}
99
100