]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
7da9c212512a3ae36782bdb13bd6ff3911b41948
[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     LDAPModList *ml
26 )
27 {
28         struct shellinfo        *si = (struct shellinfo *) be->be_private;
29         FILE                    *rfp, *wfp;
30         int                     i;
31
32         if ( si->si_modify == NULL ) {
33                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
34                     "modify not implemented", NULL, NULL );
35                 return( -1 );
36         }
37
38         if ( (op->o_private = (void *) forkandexec( si->si_modify, &rfp, &wfp ))
39             == (void *) -1 ) {
40                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
41                     "could not fork/exec", NULL, NULL );
42                 return( -1 );
43         }
44
45         /* write out the request to the modify process */
46         fprintf( wfp, "MODIFY\n" );
47         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
48         print_suffixes( wfp, be );
49         fprintf( wfp, "dn: %s\n", dn );
50         for ( ; ml != NULL; ml = ml->ml_next ) {
51                 switch ( ml->ml_op ) {
52                 case LDAP_MOD_ADD:
53                         fprintf( wfp, "add: %s\n", ml->ml_type );
54                         break;
55
56                 case LDAP_MOD_DELETE:
57                         fprintf( wfp, "delete: %s\n", ml->ml_type );
58                         break;
59
60                 case LDAP_MOD_REPLACE:
61                         fprintf( wfp, "replace: %s\n", ml->ml_type );
62                         break;
63                 }
64
65                 for ( i = 0; ml->ml_bvalues != NULL && ml->ml_bvalues[i]
66                     != NULL; i++ ) {
67                         fprintf( wfp, "%s: %s\n", ml->ml_type,
68                             ml->ml_bvalues[i]->bv_val );
69                 }
70         }
71         fclose( wfp );
72
73         /* read in the results and send them along */
74         read_and_send_results( be, conn, op, rfp, NULL, 0 );
75         fclose( rfp );
76         return( 0 );
77 }