Back to index

openldap  2.4.31
add.c
Go to the documentation of this file.
00001 /* add.c - sock backend add function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2007-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Brian Candler for inclusion
00018  * in OpenLDAP Software.
00019  */
00020 
00021 #include "portable.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include <ac/string.h>
00026 #include <ac/socket.h>
00027 
00028 #include "slap.h"
00029 #include "back-sock.h"
00030 
00031 int
00032 sock_back_add(
00033     Operation *op,
00034     SlapReply *rs )
00035 {
00036        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00037        AttributeDescription *entry = slap_schema.si_ad_entry;
00038        FILE                 *fp;
00039        int                  len;
00040 
00041        if ( ! access_allowed( op, op->oq_add.rs_e,
00042               entry, NULL, ACL_WADD, NULL ) )
00043        {
00044               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
00045               return -1;
00046        }
00047 
00048        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00049               send_ldap_error( op, rs, LDAP_OTHER,
00050                   "could not open socket" );
00051               return( -1 );
00052        }
00053 
00054        /* write out the request to the add process */
00055        fprintf( fp, "ADD\n" );
00056        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00057        sock_print_conn( fp, op->o_conn, si );
00058        sock_print_suffixes( fp, op->o_bd );
00059        ldap_pvt_thread_mutex_lock( &entry2str_mutex );
00060        fprintf( fp, "%s", entry2str( op->oq_add.rs_e, &len ) );
00061        ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
00062        fprintf (fp, "\n" );
00063 
00064        /* read in the result and send it along */
00065        sock_read_and_send_results( op, rs, fp );
00066 
00067        fclose( fp );
00068        return( 0 );
00069 }