Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-sock / modrdn.c
blobad519452a5303aa4555e3e93a30e8c066de6e239
1 /* modrdn.c - sock backend modrdn function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-sock/modrdn.c,v 1.3.2.1 2008/02/09 00:46:09 quanah Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2007-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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>.
16 /* ACKNOWLEDGEMENTS:
17 * This work was initially developed by Brian Candler for inclusion
18 * in OpenLDAP Software.
21 #include "portable.h"
23 #include <stdio.h>
25 #include <ac/socket.h>
26 #include <ac/string.h>
28 #include "slap.h"
29 #include "back-sock.h"
31 int
32 sock_back_modrdn(
33 Operation *op,
34 SlapReply *rs )
36 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
37 AttributeDescription *entry = slap_schema.si_ad_entry;
38 Entry e;
39 FILE *fp;
41 e.e_id = NOID;
42 e.e_name = op->o_req_dn;
43 e.e_nname = op->o_req_ndn;
44 e.e_attrs = NULL;
45 e.e_ocflags = 0;
46 e.e_bv.bv_len = 0;
47 e.e_bv.bv_val = NULL;
48 e.e_private = NULL;
50 if ( ! access_allowed( op, &e, entry, NULL,
51 op->oq_modrdn.rs_newSup ? ACL_WDEL : ACL_WRITE,
52 NULL ) )
54 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
55 return -1;
58 if ( (fp = opensock( si->si_sockpath )) == NULL ) {
59 send_ldap_error( op, rs, LDAP_OTHER,
60 "could not open socket" );
61 return( -1 );
64 /* write out the request to the modrdn process */
65 fprintf( fp, "MODRDN\n" );
66 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
67 sock_print_conn( fp, op->o_conn, si );
68 sock_print_suffixes( fp, op->o_bd );
69 fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
70 fprintf( fp, "newrdn: %s\n", op->oq_modrdn.rs_newrdn.bv_val );
71 fprintf( fp, "deleteoldrdn: %d\n", op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
72 if ( op->oq_modrdn.rs_newSup != NULL ) {
73 fprintf( fp, "newSuperior: %s\n", op->oq_modrdn.rs_newSup->bv_val );
75 fprintf( fp, "\n" );
77 /* read in the results and send them along */
78 sock_read_and_send_results( op, rs, fp );
79 fclose( fp );
80 return( 0 );