]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modify.c
SLAPD compiles. Needs LDBM work to link.
[openldap] / servers / slapd / back-shell / modify.c
1 /* modify.c - shell backend modify function */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "shell.h"
12
13 void
14 shell_back_modify(
15     Backend     *be,
16     Connection  *conn,
17     Operation   *op,
18     char        *dn,
19     LDAPMod     *mods
20 )
21 {
22         struct shellinfo        *si = (struct shellinfo *) be->be_private;
23         FILE                    *rfp, *wfp;
24         int                     i;
25
26         if ( si->si_modify == NULL ) {
27                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
28                     "modify not implemented" );
29                 return;
30         }
31
32         if ( (op->o_private = forkandexec( si->si_modify, &rfp, &wfp ))
33             == -1 ) {
34                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
35                     "could not fork/exec" );
36                 return;
37         }
38
39         /* write out the request to the modify process */
40         fprintf( wfp, "MODIFY\n" );
41         fprintf( wfp, "msgid: %d\n", op->o_msgid );
42         print_suffixes( wfp, be );
43         fprintf( wfp, "dn: %s\n", dn );
44         for ( ; mods != NULL; mods = mods->mod_next ) {
45                 switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
46                 case LDAP_MOD_ADD:
47                         fprintf( wfp, "add: %s", mods->mod_type );
48                         break;
49
50                 case LDAP_MOD_DELETE:
51                         fprintf( wfp, "delete: %s", mods->mod_type );
52                         break;
53
54                 case LDAP_MOD_REPLACE:
55                         fprintf( wfp, "replace: %s", mods->mod_type );
56                         break;
57                 }
58
59                 for ( i = 0; mods->mod_bvalues != NULL && mods->mod_bvalues[i]
60                     != NULL; i++ ) {
61                         fprintf( wfp, "%s: %s\n", mods->mod_type,
62                             mods->mod_bvalues[i]->bv_val );
63                 }
64         }
65         fclose( wfp );
66
67         /* read in the results and send them along */
68         read_and_send_results( be, conn, op, rfp, NULL, 0 );
69         fclose( rfp );
70 }