]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
Don't reeval expression
[openldap] / servers / slapd / back-shell / modify.c
1 /* modify.c - shell backend modify function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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     Backend     *be,
21     Connection  *conn,
22     Operation   *op,
23     struct berval *dn,
24     struct berval *ndn,
25     Modifications       *ml
26 )
27 {
28         Modification *mod;
29         struct shellinfo        *si = (struct shellinfo *) be->be_private;
30         AttributeDescription *entry = slap_schema.si_ad_entry;
31         Entry e;
32         FILE                    *rfp, *wfp;
33         int                     i;
34
35         if ( si->si_modify == NULL ) {
36                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
37                     "modify not implemented", NULL, NULL );
38                 return( -1 );
39         }
40
41         e.e_id = NOID;
42         e.e_name = *dn;
43         e.e_nname = *ndn;
44         e.e_attrs = NULL;
45         e.e_ocflags = 0;
46         e.e_bv.bv_len = 0;
47         e.e_bv.bv_val = NULL;
48         e.e_private = NULL;
49
50         if ( ! access_allowed( be, conn, op, &e,
51                 entry, NULL, ACL_WRITE, NULL ) )
52         {
53                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
54                         NULL, NULL, NULL, NULL );
55                 return -1;
56         }
57
58         if ( (op->o_private = (void *) forkandexec( si->si_modify, &rfp, &wfp ))
59             == (void *) -1 ) {
60                 send_ldap_result( conn, op, LDAP_OTHER, NULL,
61                     "could not fork/exec", NULL, NULL );
62                 return( -1 );
63         }
64
65         /* write out the request to the modify process */
66         fprintf( wfp, "MODIFY\n" );
67         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
68         print_suffixes( wfp, be );
69         fprintf( wfp, "dn: %s\n", dn->bv_val );
70         for ( ; ml != NULL; ml = ml->sml_next ) {
71                 mod = &ml->sml_mod;
72
73                 /* FIXME: should use LDIF routines to deal with binary data */
74
75                 switch ( mod->sm_op ) {
76                 case LDAP_MOD_ADD:
77                         fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
78                         break;
79
80                 case LDAP_MOD_DELETE:
81                         fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
82                         break;
83
84                 case LDAP_MOD_REPLACE:
85                         fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
86                         break;
87                 }
88
89                 if( mod->sm_bvalues != NULL ) {
90                         for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
91                                 fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
92                                         mod->sm_bvalues[i].bv_val /* binary! */ );
93                         }
94                 }
95
96                 fprintf( wfp, "-\n" );
97         }
98         fclose( wfp );
99
100         /* read in the results and send them along */
101         read_and_send_results( be, conn, op, rfp, NULL, 0 );
102         fclose( rfp );
103         return( 0 );
104 }