]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/add.c
Don't reeval expression
[openldap] / servers / slapd / back-shell / add.c
1 /* add.c - shell backend add function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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         AttributeDescription *entry = slap_schema.si_ad_entry;
28         FILE                    *rfp, *wfp;
29         int                     len;
30
31         if ( si->si_add == NULL ) {
32                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
33                     "add not implemented", NULL, NULL );
34                 return( -1 );
35         }
36
37         if ( ! access_allowed( be, conn, op, e,
38                 entry, NULL, ACL_WRITE, NULL ) )
39         {
40                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
41                         NULL, NULL, NULL, NULL );
42                 return -1;
43         }
44
45         if ( (op->o_private = (void *) forkandexec( si->si_add, &rfp, &wfp )) == (void *) -1 ) {
46                 send_ldap_result( conn, op, LDAP_OTHER, NULL,
47                     "could not fork/exec", NULL, NULL );
48                 return( -1 );
49         }
50
51         /* write out the request to the add process */
52         fprintf( wfp, "ADD\n" );
53         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
54         print_suffixes( wfp, be );
55         ldap_pvt_thread_mutex_lock( &entry2str_mutex );
56         fprintf( wfp, "%s", entry2str( e, &len ) );
57         ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
58         fclose( wfp );
59
60         /* read in the result and send it along */
61         read_and_send_results( be, conn, op, rfp, NULL, 0 );
62
63         fclose( rfp );
64         return( 0 );
65 }