]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modrdn.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / back-shell / modrdn.c
1 /* modrdn.c - shell backend modrdn function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 /*
9  * LDAP v3 newSuperior support.
10  *
11  * Copyright 1999, Juan C. Gomez, All rights reserved.
12  * This software is not subject to any license of Silicon Graphics 
13  * Inc. or Purdue University.
14  *
15  * Redistribution and use in source and binary forms are permitted
16  * without restriction or fee of any kind as long as this notice
17  * is preserved.
18  *
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/socket.h>
26 #include <ac/string.h>
27
28 #include "slap.h"
29 #include "shell.h"
30
31 int
32 shell_back_modrdn(
33     Operation   *op,
34     SlapReply   *rs )
35 {
36         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
37         AttributeDescription *entry = slap_schema.si_ad_entry;
38         Entry e;
39         FILE                    *rfp, *wfp;
40
41         if ( si->si_modrdn == NULL ) {
42                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
43                     "modrdn not implemented" );
44                 return( -1 );
45         }
46
47         e.e_id = NOID;
48         e.e_name = op->o_req_dn;
49         e.e_nname = op->o_req_ndn;
50         e.e_attrs = NULL;
51         e.e_ocflags = 0;
52         e.e_bv.bv_len = 0;
53         e.e_bv.bv_val = NULL;
54         e.e_private = NULL;
55
56         if ( ! access_allowed( op, &e,
57                 entry, NULL, ACL_WRITE, NULL ) )
58         {
59                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
60                 return -1;
61         }
62
63         if ( (op->o_private = (void *) forkandexec( si->si_modrdn, &rfp, &wfp ))
64             == (void *) -1 ) {
65                 send_ldap_error( op, rs, LDAP_OTHER,
66                     "could not fork/exec" );
67                 return( -1 );
68         }
69
70         /* write out the request to the modrdn process */
71         fprintf( wfp, "MODRDN\n" );
72         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
73         print_suffixes( wfp, op->o_bd );
74         fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
75         fprintf( wfp, "newrdn: %s\n", op->oq_modrdn.rs_newrdn.bv_val );
76         fprintf( wfp, "deleteoldrdn: %d\n", op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
77         if (op->oq_modrdn.rs_newSup != NULL) {
78                 fprintf( wfp, "newSuperior: %s\n", op->oq_modrdn.rs_newSup->bv_val );
79         }
80         fclose( wfp );
81
82         /* read in the results and send them along */
83         read_and_send_results( op, rs, rfp );
84         fclose( rfp );
85         return( 0 );
86 }