1998-10-24 11:49:07 +08:00
|
|
|
/*
|
1999-01-20 03:26:09 +08:00
|
|
|
* Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
*
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
|
|
|
|
* directory of this package.
|
|
|
|
*/
|
|
|
|
/* Portions
|
1998-10-24 11:49:07 +08:00
|
|
|
* Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to ITSD, Government of BC. The name of ITSD
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
1998-11-05 13:05:05 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-10-24 11:49:07 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1998-11-05 13:05:05 +08:00
|
|
|
#include <ac/socket.h> /* Get struct sockaddr for slap.h */
|
1998-10-24 11:49:07 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
|
|
|
/*
|
1999-01-20 03:26:09 +08:00
|
|
|
* given a normalized uppercased dn (or root part), return an aliased dn if any of the
|
1998-10-24 11:49:07 +08:00
|
|
|
* alias suffixes match
|
|
|
|
*/
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
char *suffixAlias (char *dn, Operation *op, Backend *be)
|
1998-10-24 11:49:07 +08:00
|
|
|
{
|
|
|
|
int i, dnLength;
|
|
|
|
|
1999-01-09 05:48:09 +08:00
|
|
|
if(dn == NULL) return NULL;
|
|
|
|
|
1998-10-24 11:49:07 +08:00
|
|
|
dnLength = strlen ( dn );
|
|
|
|
for ( i = 0;
|
|
|
|
be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
|
|
|
|
i += 2) {
|
|
|
|
int aliasLength = strlen (be->be_suffixAlias[i]);
|
1999-01-20 03:26:09 +08:00
|
|
|
int diff = dnLength - aliasLength;
|
|
|
|
|
|
|
|
if ( diff < 0 ) {
|
|
|
|
/* alias is longer than dn */
|
|
|
|
continue;
|
|
|
|
} else if ( diff > 0 ) {
|
|
|
|
if ( ! DNSEPARATOR(dn[diff-1]) ) {
|
|
|
|
/* boundary is not at a DN separator */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* At a DN Separator */
|
|
|
|
/* XXX or an escaped separator... oh well */
|
|
|
|
}
|
1998-10-24 11:49:07 +08:00
|
|
|
|
1999-01-20 03:26:09 +08:00
|
|
|
if (!strcmp(be->be_suffixAlias[i], &dn[diff])) {
|
1998-10-24 11:49:07 +08:00
|
|
|
char *oldDN = dn;
|
1999-01-20 03:26:09 +08:00
|
|
|
dn = ch_malloc( diff + strlen(be->be_suffixAlias[i+1]) + 1 );
|
|
|
|
strncpy( dn, oldDN, diff );
|
|
|
|
strcpy( &dn[diff], be->be_suffixAlias[i+1] );
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "SuffixAlias: converted \"%s\" to \"%s\"",
|
|
|
|
oldDN, dn, 0);
|
1998-10-24 11:49:07 +08:00
|
|
|
free (oldDN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dn;
|
|
|
|
}
|