Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-sock / add.c
blob5c5d7acb5171755e3658292aabfba9f1b16406d1
1 /* add.c - sock backend add function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-sock/add.c,v 1.3.2.1 2008/02/09 00:46:09 quanah Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2007-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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>.
16 /* ACKNOWLEDGEMENTS:
17 * This work was initially developed by Brian Candler for inclusion
18 * in OpenLDAP Software.
21 #include "portable.h"
23 #include <stdio.h>
25 #include <ac/string.h>
26 #include <ac/socket.h>
28 #include "slap.h"
29 #include "back-sock.h"
31 int
32 sock_back_add(
33 Operation *op,
34 SlapReply *rs )
36 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
37 AttributeDescription *entry = slap_schema.si_ad_entry;
38 FILE *fp;
39 int len;
41 if ( ! access_allowed( op, op->oq_add.rs_e,
42 entry, NULL, ACL_WADD, NULL ) )
44 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
45 return -1;
48 if ( (fp = opensock( si->si_sockpath )) == NULL ) {
49 send_ldap_error( op, rs, LDAP_OTHER,
50 "could not open socket" );
51 return( -1 );
54 /* write out the request to the add process */
55 fprintf( fp, "ADD\n" );
56 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
57 sock_print_conn( fp, op->o_conn, si );
58 sock_print_suffixes( fp, op->o_bd );
59 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
60 fprintf( fp, "%s", entry2str( op->oq_add.rs_e, &len ) );
61 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
62 fprintf (fp, "\n" );
64 /* read in the result and send it along */
65 sock_read_and_send_results( op, rs, fp );
67 fclose( fp );
68 return( 0 );