]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/add.c
Latest changes from HEAD.
[openldap] / servers / slapd / back-shell / add.c
1 /* add.c - shell backend add function */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include "slap.h"
8 #include "shell.h"
9
10 extern pthread_mutex_t  entry2str_mutex;
11 extern char             *entry2str();
12
13 void
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;
29         }
30
31         if ( (op->o_private = forkandexec( si->si_add, &rfp, &wfp )) == -1 ) {
32                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
33                     "could not fork/exec" );
34                 return;
35         }
36
37         /* write out the request to the add process */
38         fprintf( wfp, "ADD\n" );
39         fprintf( wfp, "msgid: %d\n", op->o_msgid );
40         print_suffixes( wfp, be );
41         pthread_mutex_lock( &entry2str_mutex );
42         fprintf( wfp, "%s", entry2str( e, &len, 0 ) );
43         pthread_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 }