]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
Add comments
[openldap] / servers / slapd / back-shell / modify.c
1 /* modify.c - shell backend modify function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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     const char  *dn,
24     const char  *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, "msgid: %ld\n", (long) op->o_msgid );
49         print_suffixes( wfp, be );
50         fprintf( wfp, "dn: %s\n", dn );
51         for ( ; ml != NULL; ml = ml->sml_next ) {
52                 mod = &ml->sml_mod;
53
54                 /* FIXME: should use LDIF routines to deal with binary data */
55
56                 switch ( mod->sm_op ) {
57                 case LDAP_MOD_ADD:
58                         fprintf( wfp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
59                         break;
60
61                 case LDAP_MOD_DELETE:
62                         fprintf( wfp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
63                         break;
64
65                 case LDAP_MOD_REPLACE:
66                         fprintf( wfp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
67                         break;
68                 }
69
70                 if( mod->sm_bvalues != NULL ) {
71                         for ( i = 0; mod->sm_bvalues[i] != NULL; i++ ) {
72                                 fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
73                                         mod->sm_bvalues[i]->bv_val /* binary! */ );
74                         }
75                 }
76
77                 fprintf( wfp, "-\n" );
78         }
79         fclose( wfp );
80
81         /* read in the results and send them along */
82         read_and_send_results( be, conn, op, rfp, NULL, 0 );
83         fclose( rfp );
84         return( 0 );
85 }