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