]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/add.c
Round 2 of connection management changes.
[openldap] / servers / slapd / back-shell / add.c
1 /* add.c - shell backend add 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 int
14 shell_back_add(
15     Backend     *be,
16     Connection  *conn,
17     Operation   *op,
18     Entry       *e
19 )
20 {
21         struct shellinfo        *si = (struct shellinfo *) be->be_private;
22         FILE                    *rfp, *wfp;
23         int                     len;
24
25         if ( si->si_add == NULL ) {
26                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
27                     "add not implemented" );
28                 return( -1 );
29         }
30
31         if ( (op->o_private = (void *) forkandexec( si->si_add, &rfp, &wfp )) == (void *) -1 ) {
32                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
33                     "could not fork/exec" );
34                 return( -1 );
35         }
36
37         /* write out the request to the add process */
38         fprintf( wfp, "ADD\n" );
39         fprintf( wfp, "msgid: %ld\n", op->o_msgid );
40         print_suffixes( wfp, be );
41         ldap_pvt_thread_mutex_lock( &entry2str_mutex );
42         fprintf( wfp, "%s", entry2str( e, &len, 0 ) );
43         ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
44         fclose( wfp );
45
46         /* read in the result and send it along */
47         read_and_send_results( be, conn, op, rfp, NULL, 0 );
48
49         fclose( rfp );
50         return( 0 );
51 }