Back to index

openldap  2.4.31
modify.c
Go to the documentation of this file.
00001 /* modify.c - sock backend modify 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 #include "ldif.h"
00031 
00032 int
00033 sock_back_modify(
00034     Operation *op,
00035     SlapReply *rs )
00036 {
00037        Modification *mod;
00038        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00039        AttributeDescription *entry = slap_schema.si_ad_entry;
00040        Modifications *ml  = op->orm_modlist;
00041        Entry e;
00042        FILE                 *fp;
00043        int                  i;
00044 
00045        e.e_id = NOID;
00046        e.e_name = op->o_req_dn;
00047        e.e_nname = op->o_req_ndn;
00048        e.e_attrs = NULL;
00049        e.e_ocflags = 0;
00050        e.e_bv.bv_len = 0;
00051        e.e_bv.bv_val = NULL;
00052        e.e_private = NULL;
00053 
00054        if ( ! access_allowed( op, &e,
00055               entry, NULL, ACL_WRITE, NULL ) )
00056        {
00057               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
00058               return -1;
00059        }
00060 
00061        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00062               send_ldap_error( op, rs, LDAP_OTHER,
00063                   "could not open socket" );
00064               return( -1 );
00065        }
00066 
00067        /* write out the request to the modify process */
00068        fprintf( fp, "MODIFY\n" );
00069        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00070        sock_print_conn( fp, op->o_conn, si );
00071        sock_print_suffixes( fp, op->o_bd );
00072        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
00073        for ( ; ml != NULL; ml = ml->sml_next ) {
00074               mod = &ml->sml_mod;
00075 
00076               switch ( mod->sm_op ) {
00077               case LDAP_MOD_ADD:
00078                      fprintf( fp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
00079                      break;
00080 
00081               case LDAP_MOD_DELETE:
00082                      fprintf( fp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
00083                      break;
00084 
00085               case LDAP_MOD_REPLACE:
00086                      fprintf( fp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
00087                      break;
00088               }
00089 
00090               if( mod->sm_values != NULL ) {
00091                      for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
00092                             char *text = ldif_put_wrap( LDIF_PUT_VALUE,
00093                                    mod->sm_desc->ad_cname.bv_val,
00094                                    mod->sm_values[i].bv_val,
00095                                    mod->sm_values[i].bv_len, LDIF_LINE_WIDTH_MAX );
00096                             if ( text ) {
00097                                    fprintf( fp, "%s", text );
00098                                    ber_memfree( text );
00099                             } else {
00100                                    break;
00101                             }
00102                      }
00103               }
00104 
00105               fprintf( fp, "-\n" );
00106        }
00107        fprintf( fp, "\n" );
00108 
00109        /* read in the results and send them along */
00110        sock_read_and_send_results( op, rs, fp );
00111        fclose( fp );
00112        return( 0 );
00113 }