xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-sock/delete.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1 /*	$NetBSD: delete.c,v 1.3 2021/08/14 16:15:01 christos Exp $	*/
2 
3 /* delete.c - sock backend delete function */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 2007-2021 The OpenLDAP Foundation.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by Brian Candler for inclusion
20  * in OpenLDAP Software.
21  */
22 
23 #include <sys/cdefs.h>
24 __RCSID("$NetBSD: delete.c,v 1.3 2021/08/14 16:15:01 christos Exp $");
25 
26 #include "portable.h"
27 
28 #include <stdio.h>
29 
30 #include <ac/string.h>
31 #include <ac/socket.h>
32 
33 #include "slap.h"
34 #include "back-sock.h"
35 
36 int
sock_back_delete(Operation * op,SlapReply * rs)37 sock_back_delete(
38     Operation	*op,
39     SlapReply	*rs )
40 {
41 	struct sockinfo	*si = (struct sockinfo *) op->o_bd->be_private;
42 	AttributeDescription *entry = slap_schema.si_ad_entry;
43 	Entry e;
44 	FILE			*fp;
45 
46 	e.e_id = NOID;
47 	e.e_name = op->o_req_dn;
48 	e.e_nname = op->o_req_ndn;
49 	e.e_attrs = NULL;
50 	e.e_ocflags = 0;
51 	e.e_bv.bv_len = 0;
52 	e.e_bv.bv_val = NULL;
53 	e.e_private = NULL;
54 
55 	if ( ! access_allowed( op, &e,
56 		entry, NULL, ACL_WDEL, NULL ) )
57 	{
58 		send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
59 		return -1;
60 	}
61 
62 	if ( (fp = opensock( si->si_sockpath )) == NULL ) {
63 		send_ldap_error( op, rs, LDAP_OTHER,
64 		    "could not open socket" );
65 		return( -1 );
66 	}
67 
68 	/* write out the request to the delete process */
69 	fprintf( fp, "DELETE\n" );
70 	fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
71 	sock_print_conn( fp, op->o_conn, si );
72 	sock_print_suffixes( fp, op->o_bd );
73 	fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
74 	fprintf( fp, "\n" );
75 
76 	/* read in the results and send them along */
77 	sock_read_and_send_results( op, rs, fp );
78 	fclose( fp );
79 	return( 0 );
80 }
81