]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/abandon.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / back-shell / abandon.c
1 /* abandon.c - shell backend abandon 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/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 int
19 shell_back_abandon(
20     Operation   *op,
21     SlapReply   *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         FILE                    *rfp, *wfp;
25         pid_t                   pid;
26         Operation               *o;
27
28         /* no abandon command defined - just kill the process handling it */
29         if ( si->si_abandon == NULL ) {
30                 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
31                 pid = -1;
32                 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
33                         if ( o->o_msgid == op->oq_abandon.rs_msgid ) {
34                                 pid = (pid_t) o->o_private;
35                                 break;
36                         }
37                 }
38                 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
39         }
40
41         if ( pid == -1 ) {
42                 Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n", op->oq_abandon.rs_msgid, 0, 0 );
43                 return 0;
44         }
45
46         if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
47                 return 0;
48         }
49
50         /* write out the request to the abandon process */
51         fprintf( wfp, "ABANDON\n" );
52         fprintf( wfp, "msgid: %d\n", op->oq_abandon.rs_msgid );
53         print_suffixes( wfp, op->o_bd );
54         fprintf( wfp, "pid: %ld\n", (long) pid );
55         fclose( wfp );
56
57         /* no result from abandon */
58         fclose( rfp );
59
60         return 0;
61 }