]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
Berkeley DB 4.2 support (DB 4.2 required by default)
[openldap] / servers / slapd / back-shell / modify.c
1 /* modify.c - shell backend modify function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 int
19 shell_back_modify(
20     Operation   *op,
21     SlapReply   *rs )
22 {
23         Modification *mod;
24         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
25         AttributeDescription *entry = slap_schema.si_ad_entry;
26         Modifications *ml  = op->oq_modify.rs_modlist;
27         Entry e;
28         FILE                    *rfp, *wfp;
29         int                     i;
30
31         if ( si->si_modify == NULL ) {
32                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
33                     "modify not implemented" );
34                 return( -1 );
35         }
36
37         e.e_id = NOID;
38         e.e_name = op->o_req_dn;
39         e.e_nname = op->o_req_ndn;
40         e.e_attrs = NULL;
41         e.e_ocflags = 0;
42         e.e_bv.bv_len = 0;
43         e.e_bv.bv_val = NULL;
44         e.e_private = NULL;
45
46         if ( ! access_allowed( op, &e,
47                 entry, NULL, ACL_WRITE, NULL ) )
48         {
49                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
50                 return -1;
51         }
52
53         if ( forkandexec( si->si_modify, &rfp, &wfp ) == (pid_t)-1 ) {
54                 send_ldap_error( op, rs, LDAP_OTHER,
55                     "could not fork/exec" );
56                 return( -1 );
57         }
58
59         /* write out the request to the modify process */
60         fprintf( wfp, "MODIFY\n" );
61         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
62         print_suffixes( wfp, op->o_bd );
63         fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
64         for ( ; ml != NULL; ml = ml->sml_next ) {
65                 mod = &ml->sml_mod;
66
67                 /* FIXME: should use LDIF routines to deal with binary data */
68
69                 switch ( mod->sm_op ) {
70                 case LDAP_MOD_ADD:
71                         fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
72                         break;
73
74                 case LDAP_MOD_DELETE:
75                         fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
76                         break;
77
78                 case LDAP_MOD_REPLACE:
79                         fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
80                         break;
81                 }
82
83                 if( mod->sm_bvalues != NULL ) {
84                         for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
85                                 fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
86                                         mod->sm_bvalues[i].bv_val /* binary! */ );
87                         }
88                 }
89
90                 fprintf( wfp, "-\n" );
91         }
92         fclose( wfp );
93
94         /* read in the results and send them along */
95         read_and_send_results( op, rs, rfp );
96         fclose( rfp );
97         return( 0 );
98 }