]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modrdn.c
Don't reeval expression
[openldap] / servers / slapd / back-shell / modrdn.c
1 /* modrdn.c - shell backend modrdn function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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     Backend     *be,
34     Connection  *conn,
35     Operation   *op,
36     struct berval *dn,
37     struct berval *ndn,
38     struct berval *newrdn,
39     struct berval *nnewrdn,
40     int         deleteoldrdn,
41     struct berval *newSuperior,
42     struct berval *nnewSuperior
43 )
44 {
45         struct shellinfo        *si = (struct shellinfo *) be->be_private;
46         AttributeDescription *entry = slap_schema.si_ad_entry;
47         Entry e;
48         FILE                    *rfp, *wfp;
49
50         if ( si->si_modrdn == NULL ) {
51                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
52                     "modrdn not implemented", NULL, NULL );
53                 return( -1 );
54         }
55
56         e.e_id = NOID;
57         e.e_name = *dn;
58         e.e_nname = *ndn;
59         e.e_attrs = NULL;
60         e.e_ocflags = 0;
61         e.e_bv.bv_len = 0;
62         e.e_bv.bv_val = NULL;
63         e.e_private = NULL;
64
65         if ( ! access_allowed( be, conn, op, &e,
66                 entry, NULL, ACL_WRITE, NULL ) )
67         {
68                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
69                         NULL, NULL, NULL, NULL );
70                 return -1;
71         }
72
73         if ( (op->o_private = (void *) forkandexec( si->si_modrdn, &rfp, &wfp ))
74             == (void *) -1 ) {
75                 send_ldap_result( conn, op, LDAP_OTHER, NULL,
76                     "could not fork/exec", NULL, NULL );
77                 return( -1 );
78         }
79
80         /* write out the request to the modrdn process */
81         fprintf( wfp, "MODRDN\n" );
82         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
83         print_suffixes( wfp, be );
84         fprintf( wfp, "dn: %s\n", dn->bv_val );
85         fprintf( wfp, "newrdn: %s\n", newrdn->bv_val );
86         fprintf( wfp, "deleteoldrdn: %d\n", deleteoldrdn ? 1 : 0 );
87         if (newSuperior != NULL) {
88                 fprintf( wfp, "newSuperior: %s\n", newSuperior->bv_val );
89         }
90         fclose( wfp );
91
92         /* read in the results and send them along */
93         read_and_send_results( be, conn, op, rfp, NULL, 0 );
94         fclose( rfp );
95         return( 0 );
96 }