/* nsdn.c - massage search entry DN */ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * * Copyright 2008 The OpenLDAP Foundation. * Portions Copyright 2008 Pierangelo Masarati. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in the file LICENSE in the * top-level directory of the distribution or, alternatively, at * . */ /* ACKNOWLEDGEMENTS: * This work was initially developed by Pierangelo Masarati * for interoperability with Samba4 */ #include "portable.h" #include "slap.h" static int nsdn_response( Operation *op, SlapReply *rs ) { LDAPDN dn = NULL; struct berval newpdn; int rc; Entry *e; slap_mask_t e_flags; int iRDN; /* only deal with resarch entries (and with referrals?) */ if ( op->o_tag != LDAP_REQ_SEARCH || rs->sr_type != REP_SEARCH || BER_BVISEMPTY( &rs->sr_entry->e_nname ) ) { return SLAP_CB_CONTINUE; } /* parse the DN */ rc = ldap_bv2dn_x( &rs->sr_entry->e_name, &dn, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ); if ( rc != LDAP_SUCCESS ) { /* FIXME: is this a critical error, or should we * just give up mucking with DN? */ return rc; } /* copy entry if required */ e = rs->sr_entry; e_flags = rs->sr_flags; if ( ! ( e_flags & REP_ENTRY_MODIFIABLE ) ) { e = entry_dup( e ); e_flags |= REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED; } /* uppercase all naming attributes - pretty only! */ for ( iRDN = 0; dn[ iRDN ] != NULL; iRDN++ ) { LDAPRDN rdn = dn[ iRDN ]; int iAVA; for ( iAVA = 0; rdn[ iAVA ] != NULL; iAVA++ ) { LDAPAVA *ava = rdn[ iAVA ]; ldap_pvt_str2upper( ava->la_attr.bv_val ); } } /* rebuild DN */ rc = ldap_dn2bv_x( dn, &newpdn, LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY, op->o_tmpmemctx ); ldap_dnfree_x( dn, op->o_tmpmemctx ); /* in case of success, dispose of original entry and set new one */ if ( rc == LDAP_SUCCESS ) { ber_memfree( e->e_name.bv_val ); e->e_name = newpdn; if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) { be_entry_release_rw( op, rs->sr_entry, 0 ); e_flags ^= REP_ENTRY_MUSTRELEASE; } rs->sr_flags = e_flags; rs->sr_entry = e; rc = SLAP_CB_CONTINUE; } else { if ( e != NULL ) { entry_free( e ); } } return rc; } slap_overinst nsdn; static int nsdn_initialize() { nsdn.on_bi.bi_type = "nsdn"; nsdn.on_response = nsdn_response; return overlay_register( &nsdn ); } int init_module( int argc, char *argv[] ) { return nsdn_initialize(); }