2003-12-06 17:53:41 +08:00
|
|
|
/* rwmdn.c - massages dns */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2014-01-25 21:21:25 +08:00
|
|
|
* Copyright 1999-2014 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 1999-2003 Howard Chu.
|
|
|
|
* Portions Copyright 2000-2003 Pierangelo Masarati.
|
2003-12-06 17:53:41 +08:00
|
|
|
* 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
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
2005-01-22 19:17:14 +08:00
|
|
|
* This work was initially developed by Howard Chu for inclusion
|
2003-12-06 17:53:41 +08:00
|
|
|
* in OpenLDAP Software and subsequently enhanced by Pierangelo
|
|
|
|
* Masarati.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2003-12-10 07:50:10 +08:00
|
|
|
#ifdef SLAPD_OVER_RWM
|
|
|
|
|
2003-12-06 17:53:41 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "rwm.h"
|
|
|
|
|
|
|
|
/* FIXME: after rewriting, we should also remap attributes ... */
|
|
|
|
|
2005-01-02 00:11:38 +08:00
|
|
|
/*
|
|
|
|
* massages "in" and normalizes it into "ndn"
|
|
|
|
*
|
|
|
|
* "ndn" may be untouched if no massaging occurred and its value was not null
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rwm_dn_massage_normalize(
|
|
|
|
dncookie *dc,
|
|
|
|
struct berval *in,
|
|
|
|
struct berval *ndn )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct berval mdn = BER_BVNULL;
|
|
|
|
|
|
|
|
/* massage and normalize a DN */
|
|
|
|
rc = rwm_dn_massage( dc, in, &mdn );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mdn.bv_val == in->bv_val && !BER_BVISNULL( ndn ) ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dnNormalize( 0, NULL, NULL, &mdn, ndn, NULL );
|
|
|
|
|
|
|
|
if ( mdn.bv_val != in->bv_val ) {
|
|
|
|
ch_free( mdn.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* massages "in" and prettifies it into "pdn"
|
|
|
|
*
|
|
|
|
* "pdn" may be untouched if no massaging occurred and its value was not null
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rwm_dn_massage_pretty(
|
|
|
|
dncookie *dc,
|
|
|
|
struct berval *in,
|
|
|
|
struct berval *pdn )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct berval mdn = BER_BVNULL;
|
|
|
|
|
|
|
|
/* massage and pretty a DN */
|
|
|
|
rc = rwm_dn_massage( dc, in, &mdn );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mdn.bv_val == in->bv_val && !BER_BVISNULL( pdn ) ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dnPretty( NULL, &mdn, pdn, NULL );
|
|
|
|
|
|
|
|
if ( mdn.bv_val != in->bv_val ) {
|
|
|
|
ch_free( mdn.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* massages "in" and prettifies and normalizes it into "pdn" and "ndn"
|
|
|
|
*
|
|
|
|
* "pdn" may be untouched if no massaging occurred and its value was not null;
|
|
|
|
* "ndn" may be untouched if no massaging occurred and its value was not null;
|
|
|
|
* if no massage occurred and "ndn" value was not null, it is filled
|
|
|
|
* with the normaized value of "pdn", much like ndn = dnNormalize( pdn )
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rwm_dn_massage_pretty_normalize(
|
|
|
|
dncookie *dc,
|
|
|
|
struct berval *in,
|
|
|
|
struct berval *pdn,
|
|
|
|
struct berval *ndn )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct berval mdn = BER_BVNULL;
|
|
|
|
|
|
|
|
/* massage, pretty and normalize a DN */
|
|
|
|
rc = rwm_dn_massage( dc, in, &mdn );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mdn.bv_val == in->bv_val && !BER_BVISNULL( pdn ) ) {
|
|
|
|
if ( BER_BVISNULL( ndn ) ) {
|
|
|
|
rc = dnNormalize( 0, NULL, NULL, &mdn, ndn, NULL );
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dnPrettyNormal( NULL, &mdn, pdn, ndn, NULL );
|
|
|
|
|
|
|
|
if ( mdn.bv_val != in->bv_val ) {
|
|
|
|
ch_free( mdn.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* massages "in" into "dn"
|
|
|
|
*
|
|
|
|
* "dn" may contain the value of "in" if no massage occurred
|
|
|
|
*/
|
2003-12-06 17:53:41 +08:00
|
|
|
int
|
|
|
|
rwm_dn_massage(
|
|
|
|
dncookie *dc,
|
2004-07-12 06:57:51 +08:00
|
|
|
struct berval *in,
|
2005-01-02 00:11:38 +08:00
|
|
|
struct berval *dn
|
2003-12-06 17:53:41 +08:00
|
|
|
)
|
|
|
|
{
|
2004-07-12 06:57:51 +08:00
|
|
|
int rc = 0;
|
|
|
|
struct berval mdn;
|
2005-04-26 08:33:43 +08:00
|
|
|
static char *dmy = "";
|
2007-09-01 21:35:34 +08:00
|
|
|
char *in_val;
|
2003-12-06 17:53:41 +08:00
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( dc != NULL );
|
|
|
|
assert( in != NULL );
|
|
|
|
assert( dn != NULL );
|
2004-07-26 07:16:40 +08:00
|
|
|
|
2007-09-01 21:35:34 +08:00
|
|
|
/* protect from NULL berval */
|
|
|
|
in_val = in->bv_val ? in->bv_val : dmy;
|
|
|
|
|
2004-03-11 05:41:02 +08:00
|
|
|
rc = rewrite_session( dc->rwmap->rwm_rw, dc->ctx,
|
2007-09-01 21:35:34 +08:00
|
|
|
in_val, dc->conn, &mdn.bv_val );
|
2004-03-11 05:41:02 +08:00
|
|
|
switch ( rc ) {
|
2003-12-06 17:53:41 +08:00
|
|
|
case REWRITE_REGEXEC_OK:
|
2007-09-01 21:35:34 +08:00
|
|
|
if ( !BER_BVISNULL( &mdn ) && mdn.bv_val != in_val ) {
|
2004-07-12 06:57:51 +08:00
|
|
|
mdn.bv_len = strlen( mdn.bv_val );
|
2005-01-02 00:11:38 +08:00
|
|
|
*dn = mdn;
|
2003-12-06 17:53:41 +08:00
|
|
|
} else {
|
2007-09-01 21:35:34 +08:00
|
|
|
dn->bv_len = in->bv_len;
|
|
|
|
dn->bv_val = in_val;
|
2003-12-06 17:53:41 +08:00
|
|
|
}
|
2005-01-02 00:11:38 +08:00
|
|
|
rc = LDAP_SUCCESS;
|
2004-07-12 06:57:51 +08:00
|
|
|
|
2003-12-06 17:53:41 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
2004-03-11 05:41:02 +08:00
|
|
|
"[rw] %s: \"%s\" -> \"%s\"\n",
|
2007-09-01 21:35:34 +08:00
|
|
|
dc->ctx, in_val, dn->bv_val );
|
2003-12-06 17:53:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_REGEXEC_UNWILLING:
|
|
|
|
if ( dc->rs ) {
|
|
|
|
dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
dc->rs->sr_text = "Operation not allowed";
|
|
|
|
}
|
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REWRITE_REGEXEC_ERR:
|
|
|
|
if ( dc->rs ) {
|
|
|
|
dc->rs->sr_err = LDAP_OTHER;
|
|
|
|
dc->rs->sr_text = "Rewrite error";
|
|
|
|
}
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-11 05:41:02 +08:00
|
|
|
|
2005-04-26 08:33:43 +08:00
|
|
|
if ( mdn.bv_val == dmy ) {
|
|
|
|
BER_BVZERO( &mdn );
|
|
|
|
}
|
|
|
|
|
2005-12-06 06:41:25 +08:00
|
|
|
if ( dn->bv_val == dmy ) {
|
|
|
|
BER_BVZERO( dn );
|
|
|
|
}
|
|
|
|
|
2003-12-06 17:53:41 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2003-12-10 07:50:10 +08:00
|
|
|
#endif /* SLAPD_OVER_RWM */
|