]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sock/modrdn.c
back-sock by Brian Candler (B.Candler@pobox.com) ITS#4094 (untested)
[openldap] / servers / slapd / back-sock / modrdn.c
1 /* modrdn.c - sock backend modrdn function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2007 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/socket.h>
22 #include <ac/string.h>
23
24 #include "slap.h"
25 #include "back-sock.h"
26
27 int
28 sock_back_modrdn(
29     Operation   *op,
30     SlapReply   *rs )
31 {
32         struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
33         AttributeDescription *entry = slap_schema.si_ad_entry;
34         Entry e;
35         FILE                    *fp;
36
37         e.e_id = NOID;
38         e.e_name = op->o_req_dn;
39         e.e_nname = op->o_req_ndn;
40         e.e_attrs = NULL;
41         e.e_ocflags = 0;
42         e.e_bv.bv_len = 0;
43         e.e_bv.bv_val = NULL;
44         e.e_private = NULL;
45
46         if ( ! access_allowed( op, &e, entry, NULL,
47                         op->oq_modrdn.rs_newSup ? ACL_WDEL : ACL_WRITE,
48                         NULL ) )
49         {
50                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
51                 return -1;
52         }
53
54         if ( (fp = opensock( si->si_sockpath )) == NULL ) {
55                 send_ldap_error( op, rs, LDAP_OTHER,
56                     "could not open socket" );
57                 return( -1 );
58         }
59
60         /* write out the request to the modrdn process */
61         fprintf( fp, "MODRDN\n" );
62         fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
63         sock_print_conn( fp, op->o_conn, si );
64         sock_print_suffixes( fp, op->o_bd );
65         fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
66         fprintf( fp, "newrdn: %s\n", op->oq_modrdn.rs_newrdn.bv_val );
67         fprintf( fp, "deleteoldrdn: %d\n", op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
68         if ( op->oq_modrdn.rs_newSup != NULL ) {
69                 fprintf( fp, "newSuperior: %s\n", op->oq_modrdn.rs_newSup->bv_val );
70         }
71         fprintf( fp, "\n" );
72
73         /* read in the results and send them along */
74         sock_read_and_send_results( op, rs, fp );
75         fclose( fp );
76         return( 0 );
77 }