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