1 /* modify.c - shell backend modify function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2014 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
35 #include <ac/string.h>
36 #include <ac/socket.h>
48 struct shellinfo *si = (struct shellinfo *) op->o_bd->be_private;
49 AttributeDescription *entry = slap_schema.si_ad_entry;
50 Modifications *ml = op->orm_modlist;
55 if ( si->si_modify == NULL ) {
56 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
57 "modify not implemented" );
62 e.e_name = op->o_req_dn;
63 e.e_nname = op->o_req_ndn;
70 if ( ! access_allowed( op, &e,
71 entry, NULL, ACL_WRITE, NULL ) )
73 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
77 if ( forkandexec( si->si_modify, &rfp, &wfp ) == (pid_t)-1 ) {
78 send_ldap_error( op, rs, LDAP_OTHER,
79 "could not fork/exec" );
83 /* write out the request to the modify process */
84 fprintf( wfp, "MODIFY\n" );
85 fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
86 print_suffixes( wfp, op->o_bd );
87 fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
88 for ( ; ml != NULL; ml = ml->sml_next ) {
91 switch ( mod->sm_op ) {
93 fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
97 fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
100 case LDAP_MOD_REPLACE:
101 fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
105 if( mod->sm_values != NULL ) {
106 for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
107 char *out = ldif_put( LDIF_PUT_VALUE,
108 mod->sm_desc->ad_cname.bv_val,
109 mod->sm_values[i].bv_val,
110 mod->sm_values[i].bv_len );
112 fprintf( wfp, "%s", out );
118 fprintf( wfp, "-\n" );
122 /* read in the results and send them along */
123 read_and_send_results( op, rs, rfp );