]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/add.c
e9840e9eaa72194f17202752e39471e1e845a316
[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 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include "slap.h"
10 #include "shell.h"
11
12 extern pthread_mutex_t  entry2str_mutex;
13 extern char             *entry2str();
14
15 void
16 shell_back_add(
17     Backend     *be,
18     Connection  *conn,
19     Operation   *op,
20     Entry       *e
21 )
22 {
23         struct shellinfo        *si = (struct shellinfo *) be->be_private;
24         FILE                    *rfp, *wfp;
25         int                     len;
26
27         if ( si->si_add == NULL ) {
28                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
29                     "add not implemented" );
30                 return;
31         }
32
33         if ( (op->o_private = forkandexec( si->si_add, &rfp, &wfp )) == -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 add process */
40         fprintf( wfp, "ADD\n" );
41         fprintf( wfp, "msgid: %d\n", op->o_msgid );
42         print_suffixes( wfp, be );
43         pthread_mutex_lock( &entry2str_mutex );
44         fprintf( wfp, "%s", entry2str( e, &len, 0 ) );
45         pthread_mutex_unlock( &entry2str_mutex );
46         fclose( wfp );
47
48         /* read in the result and send it along */
49         read_and_send_results( be, conn, op, rfp, NULL, 0 );
50
51         fclose( rfp );
52 }