]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/add.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / back-shell / add.c
1 /* add.c - shell backend add function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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     Operation   *op,
21     SlapReply   *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         AttributeDescription *entry = slap_schema.si_ad_entry;
25         FILE                    *rfp, *wfp;
26         int                     len;
27
28         if ( si->si_add == NULL ) {
29                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
30                     "add not implemented" );
31                 return( -1 );
32         }
33
34         if ( ! access_allowed( op, op->oq_add.rs_e,
35                 entry, NULL, ACL_WRITE, NULL ) )
36         {
37                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
38                 return -1;
39         }
40
41         if ( (op->o_private = (void *) forkandexec( si->si_add, &rfp, &wfp )) == (void *) -1 ) {
42                 send_ldap_error( op, rs, LDAP_OTHER,
43                     "could not fork/exec" );
44                 return( -1 );
45         }
46
47         /* write out the request to the add process */
48         fprintf( wfp, "ADD\n" );
49         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
50         print_suffixes( wfp, op->o_bd );
51         ldap_pvt_thread_mutex_lock( &entry2str_mutex );
52         fprintf( wfp, "%s", entry2str( op->oq_add.rs_e, &len ) );
53         ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
54         fclose( wfp );
55
56         /* read in the result and send it along */
57         read_and_send_results( op, rs, rfp );
58
59         fclose( rfp );
60         return( 0 );
61 }