1/* modify.c - sock backend modify function */ 2/* $OpenLDAP$ */ 3/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 * 5 * Copyright 2007-2011 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#include "ldif.h" 31 32int 33sock_back_modify( 34 Operation *op, 35 SlapReply *rs ) 36{ 37 Modification *mod; 38 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private; 39 AttributeDescription *entry = slap_schema.si_ad_entry; 40 Modifications *ml = op->orm_modlist; 41 Entry e; 42 FILE *fp; 43 int i; 44 45 e.e_id = NOID; 46 e.e_name = op->o_req_dn; 47 e.e_nname = op->o_req_ndn; 48 e.e_attrs = NULL; 49 e.e_ocflags = 0; 50 e.e_bv.bv_len = 0; 51 e.e_bv.bv_val = NULL; 52 e.e_private = NULL; 53 54 if ( ! access_allowed( op, &e, 55 entry, NULL, ACL_WRITE, NULL ) ) 56 { 57 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL ); 58 return -1; 59 } 60 61 if ( (fp = opensock( si->si_sockpath )) == NULL ) { 62 send_ldap_error( op, rs, LDAP_OTHER, 63 "could not open socket" ); 64 return( -1 ); 65 } 66 67 /* write out the request to the modify process */ 68 fprintf( fp, "MODIFY\n" ); 69 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid ); 70 sock_print_conn( fp, op->o_conn, si ); 71 sock_print_suffixes( fp, op->o_bd ); 72 fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val ); 73 for ( ; ml != NULL; ml = ml->sml_next ) { 74 mod = &ml->sml_mod; 75 76 switch ( mod->sm_op ) { 77 case LDAP_MOD_ADD: 78 fprintf( fp, "add: %s\n", mod->sm_desc->ad_cname.bv_val ); 79 break; 80 81 case LDAP_MOD_DELETE: 82 fprintf( fp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val ); 83 break; 84 85 case LDAP_MOD_REPLACE: 86 fprintf( fp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val ); 87 break; 88 } 89 90 if( mod->sm_values != NULL ) { 91 for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) { 92 char *text = ldif_put_wrap( LDIF_PUT_VALUE, 93 mod->sm_desc->ad_cname.bv_val, 94 mod->sm_values[i].bv_val, 95 mod->sm_values[i].bv_len, LDIF_LINE_WIDTH_MAX ); 96 if ( text ) { 97 fprintf( fp, "%s", text ); 98 ber_memfree( text ); 99 } else { 100 break; 101 } 102 } 103 } 104 105 fprintf( fp, "-\n" ); 106 } 107 fprintf( fp, "\n" ); 108 109 /* read in the results and send them along */ 110 sock_read_and_send_results( op, rs, fp ); 111 fclose( fp ); 112 return( 0 ); 113} 114