Back to index

openldap  2.4.31
modrdn.c
Go to the documentation of this file.
00001 /* modrdn.c - sock backend modrdn function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2007-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Brian Candler for inclusion
00018  * in OpenLDAP Software.
00019  */
00020 
00021 #include "portable.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include <ac/socket.h>
00026 #include <ac/string.h>
00027 
00028 #include "slap.h"
00029 #include "back-sock.h"
00030 
00031 int
00032 sock_back_modrdn(
00033     Operation *op,
00034     SlapReply *rs )
00035 {
00036        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00037        AttributeDescription *entry = slap_schema.si_ad_entry;
00038        Entry e;
00039        FILE                 *fp;
00040 
00041        e.e_id = NOID;
00042        e.e_name = op->o_req_dn;
00043        e.e_nname = op->o_req_ndn;
00044        e.e_attrs = NULL;
00045        e.e_ocflags = 0;
00046        e.e_bv.bv_len = 0;
00047        e.e_bv.bv_val = NULL;
00048        e.e_private = NULL;
00049 
00050        if ( ! access_allowed( op, &e, entry, NULL,
00051                      op->oq_modrdn.rs_newSup ? ACL_WDEL : ACL_WRITE,
00052                      NULL ) )
00053        {
00054               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
00055               return -1;
00056        }
00057 
00058        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00059               send_ldap_error( op, rs, LDAP_OTHER,
00060                   "could not open socket" );
00061               return( -1 );
00062        }
00063 
00064        /* write out the request to the modrdn process */
00065        fprintf( fp, "MODRDN\n" );
00066        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00067        sock_print_conn( fp, op->o_conn, si );
00068        sock_print_suffixes( fp, op->o_bd );
00069        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
00070        fprintf( fp, "newrdn: %s\n", op->oq_modrdn.rs_newrdn.bv_val );
00071        fprintf( fp, "deleteoldrdn: %d\n", op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
00072        if ( op->oq_modrdn.rs_newSup != NULL ) {
00073               fprintf( fp, "newSuperior: %s\n", op->oq_modrdn.rs_newSup->bv_val );
00074        }
00075        fprintf( fp, "\n" );
00076 
00077        /* read in the results and send them along */
00078        sock_read_and_send_results( op, rs, fp );
00079        fclose( fp );
00080        return( 0 );
00081 }