delete.c 2.42 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
/* delete.c - shell backend delete function */
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
 * Copyright 1998-2009 The OpenLDAP Foundation.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */
/* ACKNOWLEDGEMENTS:
 * This work was originally developed by the University of Michigan
 * (as part of U-MICH LDAP).
Kurt Zeilenga's avatar
Kurt Zeilenga committed
29
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
30

Kurt Zeilenga's avatar
Kurt Zeilenga committed
31
32
#include "portable.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
33
#include <stdio.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
34
35
36
37

#include <ac/string.h>
#include <ac/socket.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
38
39
40
#include "slap.h"
#include "shell.h"

41
int
Kurt Zeilenga's avatar
Kurt Zeilenga committed
42
43
shell_back_delete(
    Operation	*op,
44
    SlapReply	*rs )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
45
{
46
	struct shellinfo	*si = (struct shellinfo *) op->o_bd->be_private;
47
	Entry e;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
48
	FILE			*rfp, *wfp;
Howard Chu's avatar
Howard Chu committed
49
	AclCheck	ak = { &e, slap_schema.si_ad_entry, NULL, ACL_WDEL, NULL };
Kurt Zeilenga's avatar
Kurt Zeilenga committed
50

51
	if ( si->si_delete == NULL ) {
52
53
		send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
		    "delete not implemented" );
54
		return( -1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
55
56
	}

57
	e.e_id = NOID;
58
59
	e.e_name = op->o_req_dn;
	e.e_nname = op->o_req_ndn;
60
61
62
63
64
65
	e.e_attrs = NULL;
	e.e_ocflags = 0;
	e.e_bv.bv_len = 0;
	e.e_bv.bv_val = NULL;
	e.e_private = NULL;

Howard Chu's avatar
Howard Chu committed
66
	if ( ! access_allowed( op, &ak ))
67
	{
68
		send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
69
70
71
		return -1;
	}

72
	if ( forkandexec( si->si_delete, &rfp, &wfp ) == (pid_t)-1 ) {
73
74
		send_ldap_error( op, rs, LDAP_OTHER,
		    "could not fork/exec" );
75
		return( -1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
76
77
78
79
	}

	/* write out the request to the delete process */
	fprintf( wfp, "DELETE\n" );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
80
	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
81
82
	print_suffixes( wfp, op->o_bd );
	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
83
84
85
	fclose( wfp );

	/* read in the results and send them along */
86
	read_and_send_results( op, rs, rfp );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
87
	fclose( rfp );
88
	return( 0 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
89
}