]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/delete.c
Commit of the Proxy Cache contribution (ITS#2062)
[openldap] / servers / slapd / back-shell / delete.c
1 /* delete.c - shell backend delete function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 int
19 shell_back_delete(
20     Backend     *be,
21     Connection  *conn,
22     Operation   *op,
23     struct berval *dn,
24     struct berval *ndn
25 )
26 {
27         struct shellinfo        *si = (struct shellinfo *) be->be_private;
28         AttributeDescription *entry = slap_schema.si_ad_entry;
29         Entry e;
30         FILE                    *rfp, *wfp;
31
32         if ( si->si_delete == NULL ) {
33                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
34                     "delete not implemented", NULL, NULL );
35                 return( -1 );
36         }
37
38         e.e_id = NOID;
39         e.e_name = *dn;
40         e.e_nname = *ndn;
41         e.e_attrs = NULL;
42         e.e_ocflags = 0;
43         e.e_bv.bv_len = 0;
44         e.e_bv.bv_val = NULL;
45         e.e_private = NULL;
46
47         if ( ! access_allowed( be, conn, op, &e,
48                 entry, NULL, ACL_WRITE, NULL ) )
49         {
50                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
51                         NULL, NULL, NULL, NULL );
52                 return -1;
53         }
54
55         if ( (op->o_private = (void *) forkandexec( si->si_delete, &rfp, &wfp ))
56             == (void *) -1 ) {
57                 send_ldap_result( conn, op, LDAP_OTHER, NULL,
58                     "could not fork/exec", NULL, NULL );
59                 return( -1 );
60         }
61
62         /* write out the request to the delete process */
63         fprintf( wfp, "DELETE\n" );
64         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
65         print_suffixes( wfp, be );
66         fprintf( wfp, "dn: %s\n", dn->bv_val );
67         fclose( wfp );
68
69         /* read in the results and send them along */
70         read_and_send_results( be, conn, op, rfp, NULL, 0 );
71         fclose( rfp );
72         return( 0 );
73 }