1 /* $NetBSD: add.c,v 1.1.1.4 2014/05/28 09:58:51 tron Exp $ */ 2 3 /* add.c - sock backend add function */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2007-2014 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 "portable.h" 24 25 #include <stdio.h> 26 27 #include <ac/string.h> 28 #include <ac/socket.h> 29 30 #include "slap.h" 31 #include "back-sock.h" 32 33 int 34 sock_back_add( 35 Operation *op, 36 SlapReply *rs ) 37 { 38 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private; 39 AttributeDescription *entry = slap_schema.si_ad_entry; 40 FILE *fp; 41 int len; 42 43 if ( ! access_allowed( op, op->oq_add.rs_e, 44 entry, NULL, ACL_WADD, NULL ) ) 45 { 46 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL ); 47 return -1; 48 } 49 50 if ( (fp = opensock( si->si_sockpath )) == NULL ) { 51 send_ldap_error( op, rs, LDAP_OTHER, 52 "could not open socket" ); 53 return( -1 ); 54 } 55 56 /* write out the request to the add process */ 57 fprintf( fp, "ADD\n" ); 58 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid ); 59 sock_print_conn( fp, op->o_conn, si ); 60 sock_print_suffixes( fp, op->o_bd ); 61 ldap_pvt_thread_mutex_lock( &entry2str_mutex ); 62 fprintf( fp, "%s", entry2str( op->oq_add.rs_e, &len ) ); 63 ldap_pvt_thread_mutex_unlock( &entry2str_mutex ); 64 fprintf (fp, "\n" ); 65 66 /* read in the result and send it along */ 67 sock_read_and_send_results( op, rs, fp ); 68 69 fclose( fp ); 70 return( 0 ); 71 } 72