1 /* modify.c - shell backend modify function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2010 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>
47 struct shellinfo *si = (struct shellinfo *) op->o_bd->be_private;
48 AttributeDescription *entry = slap_schema.si_ad_entry;
49 Modifications *ml = op->orm_modlist;
54 if ( si->si_modify == NULL ) {
55 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
56 "modify not implemented" );
61 e.e_name = op->o_req_dn;
62 e.e_nname = op->o_req_ndn;
69 if ( ! access_allowed( op, &e,
70 entry, NULL, ACL_WRITE, NULL ) )
72 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
76 if ( forkandexec( si->si_modify, &rfp, &wfp ) == (pid_t)-1 ) {
77 send_ldap_error( op, rs, LDAP_OTHER,
78 "could not fork/exec" );
82 /* write out the request to the modify process */
83 fprintf( wfp, "MODIFY\n" );
84 fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
85 print_suffixes( wfp, op->o_bd );
86 fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
87 for ( ; ml != NULL; ml = ml->sml_next ) {
90 /* FIXME: should use LDIF routines to deal with binary data */
92 switch ( mod->sm_op ) {
94 fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
98 fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
101 case LDAP_MOD_REPLACE:
102 fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
106 if( mod->sm_values != NULL ) {
107 for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
108 fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
109 mod->sm_values[i].bv_val /* binary! */ );
113 fprintf( wfp, "-\n" );
117 /* read in the results and send them along */
118 read_and_send_results( op, rs, rfp );