]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sock/add.c
New access_allowed()
[openldap] / servers / slapd / back-sock / add.c
1 /* add.c - sock backend add function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2007-2009 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Brian Candler for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/string.h>
26 #include <ac/socket.h>
27
28 #include "slap.h"
29 #include "back-sock.h"
30
31 int
32 sock_back_add(
33     Operation   *op,
34     SlapReply   *rs )
35 {
36         struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
37         FILE                    *fp;
38         int                     len;
39         AclCheck        ak = { op->ora_e, slap_schema.si_ad_entry, NULL, ACL_WADD, NULL };
40
41         if ( ! access_allowed( op, &ak ))
42         {
43                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
44                 return -1;
45         }
46
47         if ( (fp = opensock( si->si_sockpath )) == NULL ) {
48                 send_ldap_error( op, rs, LDAP_OTHER,
49                     "could not open socket" );
50                 return( -1 );
51         }
52
53         /* write out the request to the add process */
54         fprintf( fp, "ADD\n" );
55         fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
56         sock_print_conn( fp, op->o_conn, si );
57         sock_print_suffixes( fp, op->o_bd );
58         ldap_pvt_thread_mutex_lock( &entry2str_mutex );
59         fprintf( fp, "%s", entry2str( op->oq_add.rs_e, &len ) );
60         ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
61         fprintf (fp, "\n" );
62
63         /* read in the result and send it along */
64         sock_read_and_send_results( op, rs, fp );
65
66         fclose( fp );
67         return( 0 );
68 }