]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
91d7149eca03354dda942276c916ae4df77407e8
[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         FILE                    *rfp, *wfp;
31         int                     i;
32
33         if ( si->si_modify == NULL ) {
34                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
35                     "modify not implemented", NULL, NULL );
36                 return( -1 );
37         }
38
39         if ( (op->o_private = (void *) forkandexec( si->si_modify, &rfp, &wfp ))
40             == (void *) -1 ) {
41                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
42                     "could not fork/exec", NULL, NULL );
43                 return( -1 );
44         }
45
46         /* write out the request to the modify process */
47         fprintf( wfp, "MODIFY\n" );
48         fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid );
49         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
50         print_suffixes( wfp, be );
51         fprintf( wfp, "dn: %s\n", dn->bv_val );
52         for ( ; ml != NULL; ml = ml->sml_next ) {
53                 mod = &ml->sml_mod;
54
55                 /* FIXME: should use LDIF routines to deal with binary data */
56
57                 switch ( mod->sm_op ) {
58                 case LDAP_MOD_ADD:
59                         fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
60                         break;
61
62                 case LDAP_MOD_DELETE:
63                         fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
64                         break;
65
66                 case LDAP_MOD_REPLACE:
67                         fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
68                         break;
69                 }
70
71                 if( mod->sm_bvalues != NULL ) {
72                         for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
73                                 fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
74                                         mod->sm_bvalues[i].bv_val /* binary! */ );
75                         }
76                 }
77
78                 fprintf( wfp, "-\n" );
79         }
80         fclose( wfp );
81
82         /* read in the results and send them along */
83         read_and_send_results( be, conn, op, rfp, NULL, 0 );
84         fclose( rfp );
85         return( 0 );
86 }