1145510Sdarrenr/*	$NetBSD$	*/
2145510Sdarrenr
3145510Sdarrenr/* modify.c - monitor backend modify routine */
4145510Sdarrenr/* OpenLDAP: pkg/ldap/servers/slapd/back-monitor/modify.c,v 1.24.2.6 2010/04/13 20:23:33 kurt Exp */
5145510Sdarrenr/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6145510Sdarrenr *
7145510Sdarrenr * Copyright 2001-2010 The OpenLDAP Foundation.
8145510Sdarrenr * Portions Copyright 2001-2003 Pierangelo Masarati.
9145510Sdarrenr * All rights reserved.
10145510Sdarrenr *
11145510Sdarrenr * Redistribution and use in source and binary forms, with or without
12145510Sdarrenr * modification, are permitted only as authorized by the OpenLDAP
13145510Sdarrenr * Public License.
14145510Sdarrenr *
15145510Sdarrenr * A copy of this license is available in file LICENSE in the
16145510Sdarrenr * top-level directory of the distribution or, alternatively, at
17145510Sdarrenr * <http://www.OpenLDAP.org/license.html>.
18145510Sdarrenr */
19145510Sdarrenr/* ACKNOWLEDGEMENTS:
20145510Sdarrenr * This work was initially developed by Pierangelo Masarati for inclusion
21145510Sdarrenr * in OpenLDAP Software.
22145510Sdarrenr */
23145510Sdarrenr
24145510Sdarrenr#include "portable.h"
25145510Sdarrenr
26145510Sdarrenr#include <stdio.h>
27145510Sdarrenr
28145510Sdarrenr#include <ac/string.h>
29145510Sdarrenr#include <ac/socket.h>
30145510Sdarrenr
31145510Sdarrenr#include "slap.h"
32145510Sdarrenr#include "back-monitor.h"
33145510Sdarrenr#include "proto-back-monitor.h"
34145510Sdarrenr
35145510Sdarrenrint
36145510Sdarrenrmonitor_back_modify( Operation *op, SlapReply *rs )
37145510Sdarrenr{
38145510Sdarrenr	int 		rc = 0;
39145510Sdarrenr	monitor_info_t	*mi = ( monitor_info_t * )op->o_bd->be_private;
40145510Sdarrenr	Entry		*matched;
41145510Sdarrenr	Entry		*e;
42145510Sdarrenr
43145510Sdarrenr	Debug(LDAP_DEBUG_ARGS, "monitor_back_modify:\n", 0, 0, 0);
44145510Sdarrenr
45145510Sdarrenr	/* acquire and lock entry */
46145510Sdarrenr	monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
47145510Sdarrenr	if ( e == NULL ) {
48145510Sdarrenr		rs->sr_err = LDAP_NO_SUCH_OBJECT;
49145510Sdarrenr		if ( matched ) {
50145510Sdarrenr			if ( !access_allowed_mask( op, matched,
51145510Sdarrenr					slap_schema.si_ad_entry,
52145510Sdarrenr					NULL, ACL_DISCLOSE, NULL, NULL ) )
53145510Sdarrenr			{
54145510Sdarrenr				/* do nothing */ ;
55145510Sdarrenr			} else {
56145510Sdarrenr				rs->sr_matched = matched->e_dn;
57145510Sdarrenr			}
58145510Sdarrenr		}
59145510Sdarrenr		send_ldap_result( op, rs );
60145510Sdarrenr		if ( matched != NULL ) {
61			rs->sr_matched = NULL;
62			monitor_cache_release( mi, matched );
63		}
64		return rs->sr_err;
65	}
66
67	if ( !acl_check_modlist( op, e, op->orm_modlist )) {
68		rc = LDAP_INSUFFICIENT_ACCESS;
69
70	} else {
71		assert( !SLAP_SHADOW( op->o_bd ) );
72		slap_mods_opattrs( op, &op->orm_modlist, 0 );
73
74		rc = monitor_entry_modify( op, rs, e );
75	}
76
77	if ( rc != LDAP_SUCCESS ) {
78		if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
79				NULL, ACL_DISCLOSE, NULL, NULL ) )
80		{
81			rc = LDAP_NO_SUCH_OBJECT;
82		}
83	}
84
85	rs->sr_err = rc;
86	send_ldap_result( op, rs );
87
88	monitor_cache_release( mi, e );
89
90	return rs->sr_err;
91}
92
93