1998-08-09 08:43:13 +08:00
|
|
|
/* dn.c - routines for dealing with distinguished names */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-07 07:07:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1999-08-25 14:44:08 +08:00
|
|
|
#include "ldap_pvt.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
1999-07-23 01:14:42 +08:00
|
|
|
#define B4LEADTYPE 0
|
|
|
|
#define B4TYPE 1
|
1999-07-23 03:06:56 +08:00
|
|
|
#define INOIDTYPE 2
|
|
|
|
#define INKEYTYPE 3
|
|
|
|
#define B4EQUAL 4
|
|
|
|
#define B4VALUE 5
|
|
|
|
#define INVALUE 6
|
|
|
|
#define INQUOTEDVALUE 7
|
|
|
|
#define B4SEPARATOR 8
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
/*
|
|
|
|
* dn_validate - validate and compress dn. the dn is
|
|
|
|
* compressed in place are returned if valid.
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
*/
|
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
char *
|
|
|
|
dn_validate( char *dn_in )
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
{
|
2001-07-22 06:44:55 +08:00
|
|
|
char *d, *s;
|
|
|
|
int state, gotesc;
|
|
|
|
char *dn = dn_in;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
gotesc = 0;
|
|
|
|
state = B4LEADTYPE;
|
|
|
|
for ( d = s = dn; *s; s++ ) {
|
|
|
|
switch ( state ) {
|
|
|
|
case B4LEADTYPE:
|
|
|
|
case B4TYPE:
|
|
|
|
if ( OID_LEADCHAR(*s) ) {
|
|
|
|
state = INOIDTYPE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( ATTR_LEADCHAR(*s) ) {
|
|
|
|
state = INKEYTYPE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( ! ASCII_SPACE( *s ) ) {
|
|
|
|
dn = NULL;
|
|
|
|
state = INKEYTYPE;
|
|
|
|
*d++ = *s;
|
1999-07-23 03:06:56 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
1999-07-23 03:06:56 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case INOIDTYPE:
|
|
|
|
if ( OID_CHAR(*s) ) {
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( *s == '=' ) {
|
|
|
|
state = B4VALUE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( ASCII_SPACE( *s ) ) {
|
|
|
|
state = B4EQUAL;
|
|
|
|
} else {
|
|
|
|
dn = NULL;
|
|
|
|
*d++ = *s;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
1999-07-23 03:06:56 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case INKEYTYPE:
|
|
|
|
if ( ATTR_CHAR(*s) ) {
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( *s == '=' ) {
|
|
|
|
state = B4VALUE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( ASCII_SPACE( *s ) ) {
|
|
|
|
state = B4EQUAL;
|
|
|
|
} else {
|
|
|
|
dn = NULL;
|
|
|
|
*d++ = *s;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
1999-07-23 03:06:56 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case B4EQUAL:
|
|
|
|
if ( *s == '=' ) {
|
|
|
|
state = B4VALUE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( ! ASCII_SPACE( *s ) ) {
|
|
|
|
/* not a valid dn - but what can we do here? */
|
|
|
|
*d++ = *s;
|
|
|
|
dn = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
1999-07-23 03:06:56 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case B4VALUE:
|
|
|
|
if ( *s == '"' ) {
|
|
|
|
state = INQUOTEDVALUE;
|
|
|
|
*d++ = *s;
|
2001-07-22 07:45:04 +08:00
|
|
|
} else if ( ! ASCII_SPACE( *s ) ) {
|
2001-07-22 06:44:55 +08:00
|
|
|
state = INVALUE;
|
|
|
|
*d++ = *s;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
2000-06-15 05:11:56 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case INVALUE:
|
|
|
|
if ( !gotesc && RDN_SEPARATOR( *s ) ) {
|
|
|
|
while ( ASCII_SPACE( *(d - 1) ) )
|
|
|
|
d--;
|
|
|
|
state = B4TYPE;
|
|
|
|
if ( *s == '+' ) {
|
|
|
|
*d++ = *s;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
} else {
|
2001-07-22 06:44:55 +08:00
|
|
|
*d++ = ',';
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
} else if ( gotesc && !RDN_NEEDSESCAPE( *s ) &&
|
2001-07-22 07:45:04 +08:00
|
|
|
!RDN_SEPARATOR( *s ) )
|
|
|
|
{
|
2001-07-22 06:44:55 +08:00
|
|
|
*--d = *s;
|
|
|
|
d++;
|
|
|
|
} else if( !ASCII_SPACE( *s ) || !ASCII_SPACE( *(d - 1) ) ) {
|
|
|
|
*d++ = *s;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case INQUOTEDVALUE:
|
|
|
|
if ( !gotesc && *s == '"' ) {
|
|
|
|
state = B4SEPARATOR;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( gotesc && !RDN_NEEDSESCAPE( *s ) ) {
|
|
|
|
*--d = *s;
|
|
|
|
d++;
|
|
|
|
} else if( !ASCII_SPACE( *s ) || !ASCII_SPACE( *(d - 1) ) ) {
|
|
|
|
*d++ = *s;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
case B4SEPARATOR:
|
|
|
|
if ( RDN_SEPARATOR( *s ) ) {
|
|
|
|
state = B4TYPE;
|
|
|
|
*d++ = *s;
|
|
|
|
} else if ( !ASCII_SPACE( *s ) ) {
|
|
|
|
dn = NULL;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
break;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
default:
|
|
|
|
dn = NULL;
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
|
2001-07-22 07:45:04 +08:00
|
|
|
"dn_validate: unknown state %d for dn \"%s\".\n",
|
|
|
|
state, dn_in ));
|
2001-07-22 06:44:55 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2001-07-22 07:45:04 +08:00
|
|
|
"dn_validate - unknown state %d\n", state, 0, 0 );
|
2001-07-22 06:44:55 +08:00
|
|
|
#endif
|
|
|
|
break;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
if ( *s == '\\' ) {
|
|
|
|
gotesc = 1;
|
|
|
|
} else {
|
|
|
|
gotesc = 0;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
}
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
/* trim trailing spaces */
|
|
|
|
while( d > dn_in && ASCII_SPACE( *(d-1) ) ) {
|
|
|
|
--d;
|
|
|
|
}
|
|
|
|
*d = '\0';
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
if( gotesc ) {
|
|
|
|
/* shouldn't be left in escape */
|
|
|
|
dn = NULL;
|
|
|
|
}
|
1999-07-23 01:14:42 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
/* check end state */
|
|
|
|
switch( state ) {
|
|
|
|
case B4LEADTYPE: /* looking for first type */
|
|
|
|
case B4SEPARATOR: /* looking for separator */
|
|
|
|
case INVALUE: /* inside value */
|
1999-07-23 01:14:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-07-22 06:44:55 +08:00
|
|
|
dn = NULL;
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
return( dn );
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
}
|
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
/*
|
|
|
|
* dn_normalize - put dn into a canonical form suitable for storing
|
|
|
|
* in a hash database. this involves normalizing the case as well as
|
|
|
|
* the format. the dn is normalized in place as well as returned if valid.
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
*/
|
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
char *
|
|
|
|
dn_normalize( char *dn )
|
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
struct berval *bvdn, *nbvdn;
|
dn_validate/dn_normalize has been rewritten by
David A. Cooper <david.cooper@nist.gov> (ITS#1232)
according to draft-ietf-ldapbis-dn-05.txt
A copyright statement follows:
The functions normalize_unicode(), get_hexpair(), write_hex_pair(),
get_next_byte(), get_next_char(), get_ber_length(),
ber_parse_primitive_string(), ber_parse_string(), String_normalize(),
DirectoryString_normalize(), PrintableString_normalize(),
IA5String_normalize(), ber_parse_primitive_bitstring(),
ber_parse_bitstring(), getNext8bits(), bitString_normalize(), match_oid(),
match_key(), get_validated_av_in_dn(), get_validated_rdn_in_dn(),
and get_validated_dn() in this file were developed at the National Institute
of Standards and Technology by employees of the Federal Government in the
course of their official duties. Pursuant to title 17 Section 105 of the
United States Code the code in these functions is not subject to copyright
protection and is in the public domain. The copyright for all other code in
this file is as specified below.
2001-07-13 16:21:14 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
out = NULL;
|
|
|
|
bvdn = ber_bvstr( dn );
|
|
|
|
|
|
|
|
if ( dnNormalize( NULL, bvdn, &nbvdn ) == LDAP_SUCCESS ) {
|
|
|
|
if ( nbvdn->bv_len <= bvdn->bv_len ) {
|
|
|
|
out = dn;
|
|
|
|
strcpy( out, nbvdn->bv_val );
|
|
|
|
}
|
|
|
|
ber_bvfree( nbvdn );
|
2000-10-29 07:38:14 +08:00
|
|
|
}
|
2001-07-22 06:44:55 +08:00
|
|
|
bvdn->bv_val = NULL; /* prevent bvfree from freeing dn */
|
|
|
|
ber_bvfree( bvdn );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-07-22 06:44:55 +08:00
|
|
|
return( out );
|
1999-04-02 11:45:33 +08:00
|
|
|
}
|
1999-04-02 11:23:20 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* dn_parent - return a copy of the dn of dn's parent
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
dn_parent(
|
2001-07-22 07:45:04 +08:00
|
|
|
Backend *be,
|
|
|
|
const char *dn
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
1999-08-21 03:00:44 +08:00
|
|
|
const char *s;
|
1999-03-09 15:15:35 +08:00
|
|
|
int inquote;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-24 03:34:02 +08:00
|
|
|
if( dn == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-15 04:57:34 +08:00
|
|
|
while(*dn != '\0' && ASCII_SPACE(*dn)) {
|
1999-01-24 03:34:02 +08:00
|
|
|
dn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *dn == '\0' ) {
|
2000-09-29 10:50:34 +08:00
|
|
|
return NULL;
|
1999-01-24 03:34:02 +08:00
|
|
|
}
|
|
|
|
|
1999-04-29 14:50:00 +08:00
|
|
|
if ( be != NULL && be_issuffix( be, dn ) ) {
|
2000-09-29 10:50:34 +08:00
|
|
|
return NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-02-15 04:57:34 +08:00
|
|
|
* assume it is an X.500-style name, which looks like
|
1998-08-09 08:43:13 +08:00
|
|
|
* foo=bar,sha=baz,...
|
|
|
|
*/
|
|
|
|
|
|
|
|
inquote = 0;
|
|
|
|
for ( s = dn; *s; s++ ) {
|
|
|
|
if ( *s == '\\' ) {
|
1999-01-24 03:34:02 +08:00
|
|
|
if ( *(s + 1) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
s++;
|
1999-01-24 03:34:02 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( inquote ) {
|
1999-01-24 03:34:02 +08:00
|
|
|
if ( *s == '"' ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
inquote = 0;
|
1999-01-24 03:34:02 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1999-01-24 03:34:02 +08:00
|
|
|
if ( *s == '"' ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
inquote = 1;
|
2000-02-15 04:57:34 +08:00
|
|
|
} else if ( DN_SEPARATOR( *s ) ) {
|
2000-09-29 10:50:34 +08:00
|
|
|
return ch_strdup( &s[1] );
|
1999-01-24 03:34:02 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-29 10:50:34 +08:00
|
|
|
return ch_strdup( "" );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2001-07-22 07:45:04 +08:00
|
|
|
char * dn_rdn(
|
|
|
|
Backend *be,
|
|
|
|
const char *dn_in )
|
1999-01-29 05:40:04 +08:00
|
|
|
{
|
2000-05-22 11:46:57 +08:00
|
|
|
char *dn, *s;
|
1999-03-09 15:15:35 +08:00
|
|
|
int inquote;
|
1999-01-29 05:40:04 +08:00
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
if( dn_in == NULL ) {
|
1999-01-29 05:40:04 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
while(*dn_in && ASCII_SPACE(*dn_in)) {
|
2000-06-14 11:59:19 +08:00
|
|
|
dn_in++;
|
1999-01-29 05:40:04 +08:00
|
|
|
}
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
if( *dn_in == '\0' ) {
|
1999-01-29 05:40:04 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
if ( be != NULL && be_issuffix( be, dn_in ) ) {
|
1999-01-29 05:40:04 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
dn = ch_strdup( dn_in );
|
1999-01-29 05:40:04 +08:00
|
|
|
|
|
|
|
inquote = 0;
|
|
|
|
|
|
|
|
for ( s = dn; *s; s++ ) {
|
|
|
|
if ( *s == '\\' ) {
|
|
|
|
if ( *(s + 1) ) {
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( inquote ) {
|
|
|
|
if ( *s == '"' ) {
|
|
|
|
inquote = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( *s == '"' ) {
|
|
|
|
inquote = 1;
|
2000-02-15 04:57:34 +08:00
|
|
|
} else if ( DN_SEPARATOR( *s ) ) {
|
1999-01-29 05:40:04 +08:00
|
|
|
*s = '\0';
|
|
|
|
return( dn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( dn );
|
|
|
|
}
|
|
|
|
|
1999-08-12 04:59:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* return a charray of all subtrees to which the DN resides in
|
|
|
|
*/
|
|
|
|
char **dn_subtree(
|
|
|
|
Backend *be,
|
2001-07-22 07:45:04 +08:00
|
|
|
const char *dn )
|
1999-08-12 04:59:28 +08:00
|
|
|
{
|
1999-08-12 12:20:32 +08:00
|
|
|
char *child, *parent;
|
|
|
|
char **subtree = NULL;
|
|
|
|
|
1999-08-21 03:00:44 +08:00
|
|
|
child = ch_strdup( dn );
|
1999-08-12 12:20:32 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
charray_add( &subtree, child );
|
|
|
|
|
|
|
|
parent = dn_parent( be, child );
|
|
|
|
|
1999-08-21 03:00:44 +08:00
|
|
|
free( child );
|
1999-08-12 12:20:32 +08:00
|
|
|
|
|
|
|
child = parent;
|
|
|
|
} while ( child != NULL );
|
|
|
|
|
|
|
|
return subtree;
|
1999-08-12 04:59:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
2001-07-22 07:45:04 +08:00
|
|
|
* dn_issuffix - tells whether suffix is a suffix of dn. Both dn
|
1998-08-09 08:43:13 +08:00
|
|
|
* and suffix must be normalized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
dn_issuffix(
|
2001-07-22 07:45:04 +08:00
|
|
|
const char *dn,
|
|
|
|
const char *suffix
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int dnlen, suffixlen;
|
|
|
|
|
|
|
|
if ( dn == NULL ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
suffixlen = strlen( suffix );
|
|
|
|
dnlen = strlen( dn );
|
|
|
|
|
|
|
|
if ( suffixlen > dnlen ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
1999-01-20 11:05:35 +08:00
|
|
|
return( strcmp( dn + dnlen - suffixlen, suffix ) == 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-03-04 08:31:19 +08:00
|
|
|
/*
|
1999-03-25 04:26:43 +08:00
|
|
|
* get_next_substring(), rdn_attr_type(), rdn_attr_value(), and
|
|
|
|
* build_new_dn().
|
2001-07-22 07:45:04 +08:00
|
|
|
*
|
1999-03-04 08:31:19 +08:00
|
|
|
* Copyright 1999, Juan C. Gomez, All rights reserved.
|
2001-07-22 07:45:04 +08:00
|
|
|
* This software is not subject to any license of Silicon Graphics
|
1999-03-04 08:31:19 +08:00
|
|
|
* Inc. or Purdue University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* without restriction or fee of any kind as long as this notice
|
|
|
|
* is preserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get_next_substring:
|
|
|
|
*
|
2001-07-22 07:45:04 +08:00
|
|
|
* Gets next substring in s, using d (or the end of the string '\0') as a
|
|
|
|
* string delimiter, and places it in a duplicated memory space. Leading
|
1999-03-04 08:31:19 +08:00
|
|
|
* spaces are ignored. String s **must** be null-terminated.
|
2001-07-22 07:45:04 +08:00
|
|
|
*/
|
1999-03-04 08:31:19 +08:00
|
|
|
|
2001-07-22 07:45:04 +08:00
|
|
|
static char *
|
2000-05-22 11:46:57 +08:00
|
|
|
get_next_substring( const char * s, char d )
|
1999-03-04 08:31:19 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
char *str, *r;
|
|
|
|
|
|
|
|
r = str = ch_malloc( strlen(s) + 1 );
|
|
|
|
|
|
|
|
/* Skip leading spaces */
|
|
|
|
|
2000-02-15 04:57:34 +08:00
|
|
|
while ( *s && ASCII_SPACE(*s) ) {
|
1999-03-04 08:31:19 +08:00
|
|
|
s++;
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
/* Copy word */
|
|
|
|
|
|
|
|
while ( *s && (*s != d) ) {
|
|
|
|
|
|
|
|
/* Don't stop when you see trailing spaces may be a multi-word
|
|
|
|
* string, i.e. name=John Doe!
|
|
|
|
*/
|
|
|
|
|
|
|
|
*str++ = *s++;
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
*str = '\0';
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* rdn_attr_type:
|
|
|
|
*
|
|
|
|
* Given a string (i.e. an rdn) of the form:
|
|
|
|
* "attribute_type = attribute_value"
|
2001-07-22 07:45:04 +08:00
|
|
|
* this function returns the type of an attribute, that is the
|
|
|
|
* string "attribute_type" which is placed in newly allocated
|
1999-03-04 08:31:19 +08:00
|
|
|
* memory. The returned string will be null-terminated.
|
|
|
|
*/
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
char * rdn_attr_type( const char * s )
|
1999-03-04 08:31:19 +08:00
|
|
|
{
|
|
|
|
return get_next_substring( s, '=' );
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* rdn_attr_value:
|
|
|
|
*
|
|
|
|
* Given a string (i.e. an rdn) of the form:
|
|
|
|
* "attribute_type = attribute_value"
|
2001-07-22 07:45:04 +08:00
|
|
|
* this function returns "attribute_type" which is placed in newly allocated
|
|
|
|
* memory. The returned string will be null-terminated and may contain
|
1999-03-04 08:31:19 +08:00
|
|
|
* spaces (i.e. "John Doe\0").
|
|
|
|
*/
|
|
|
|
|
2001-07-22 07:45:04 +08:00
|
|
|
char *
|
2000-05-22 11:46:57 +08:00
|
|
|
rdn_attr_value( const char * rdn )
|
1999-03-04 08:31:19 +08:00
|
|
|
{
|
|
|
|
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *str;
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
if ( (str = strchr( rdn, '=' )) != NULL ) {
|
|
|
|
return get_next_substring(++str, '\0');
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-04 08:31:19 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 20:22:01 +08:00
|
|
|
/* rdn_attrs:
|
|
|
|
*
|
|
|
|
* Given a string (i.e. an rdn) of the form:
|
2001-07-22 07:45:04 +08:00
|
|
|
* "attribute_type=attribute_value[+attribute_type=attribute_value[...]]"
|
|
|
|
* this function stores the types of the attributes in ptypes, that is the
|
|
|
|
* array of strings "attribute_type" which is placed in newly allocated
|
2001-07-06 20:22:01 +08:00
|
|
|
* memory, and the values of the attributes in pvalues, that is the
|
|
|
|
* array of strings "attribute_value" which is placed in newly allocated
|
2001-07-11 02:19:22 +08:00
|
|
|
* memory. Returns 0 on success, -1 on failure.
|
2001-07-06 20:22:01 +08:00
|
|
|
*
|
|
|
|
* note: got part of the code from dn_validate
|
|
|
|
*/
|
2001-07-11 02:19:22 +08:00
|
|
|
|
2001-07-06 20:22:01 +08:00
|
|
|
int
|
|
|
|
rdn_attrs( const char * rdn_in, char ***ptypes, char ***pvalues)
|
|
|
|
{
|
2001-07-11 02:19:22 +08:00
|
|
|
char **parts, **p;
|
2001-07-06 20:22:01 +08:00
|
|
|
|
|
|
|
*ptypes = NULL;
|
|
|
|
*pvalues = NULL;
|
|
|
|
|
2001-07-11 02:19:22 +08:00
|
|
|
/*
|
|
|
|
* explode the rdn in parts
|
|
|
|
*/
|
|
|
|
parts = ldap_explode_rdn( rdn_in, 0 );
|
2001-07-06 20:22:01 +08:00
|
|
|
|
2001-07-11 02:19:22 +08:00
|
|
|
if ( parts == NULL ) {
|
|
|
|
return( -1 );
|
2001-07-06 20:22:01 +08:00
|
|
|
}
|
|
|
|
|
2001-07-11 02:19:22 +08:00
|
|
|
for ( p = parts; p[0]; p++ ) {
|
|
|
|
char *s, *e, *d;
|
|
|
|
|
|
|
|
/* split each rdn part in type value */
|
|
|
|
s = strchr( p[0], '=' );
|
|
|
|
if ( s == NULL ) {
|
|
|
|
charray_free( *ptypes );
|
|
|
|
charray_free( *pvalues );
|
|
|
|
charray_free( parts );
|
|
|
|
return( -1 );
|
2001-07-06 20:22:01 +08:00
|
|
|
}
|
2001-07-11 02:19:22 +08:00
|
|
|
|
|
|
|
/* type should be fine */
|
|
|
|
charray_add_n( ptypes, p[0], ( s-p[0] ) );
|
|
|
|
|
2001-07-22 07:45:04 +08:00
|
|
|
/* value needs to be unescaped
|
2001-07-11 02:19:22 +08:00
|
|
|
* (maybe this should be moved to ldap_explode_rdn?) */
|
|
|
|
for ( e = d = s + 1; e[0]; e++ ) {
|
|
|
|
if ( *e != '\\' ) {
|
|
|
|
*d++ = *e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d[0] = '\0';
|
|
|
|
charray_add( pvalues, s + 1 );
|
2001-07-06 20:22:01 +08:00
|
|
|
}
|
|
|
|
|
2001-07-11 02:19:22 +08:00
|
|
|
/* free array */
|
|
|
|
charray_free( parts );
|
2001-07-06 20:22:01 +08:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-05 16:40:40 +08:00
|
|
|
/* rdn_validate:
|
2001-07-22 07:45:04 +08:00
|
|
|
*
|
|
|
|
* 1 if rdn is a legal rdn;
|
2001-07-05 16:40:40 +08:00
|
|
|
* 0 otherwise (including a sequence of rdns)
|
2001-07-06 04:33:15 +08:00
|
|
|
*
|
2001-07-22 07:45:04 +08:00
|
|
|
* note: got it from dn_rdn; it should be rewritten
|
2001-07-06 04:33:15 +08:00
|
|
|
* according to dn_validate
|
2001-07-05 16:40:40 +08:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
rdn_validate( const char * rdn )
|
1999-07-23 01:14:42 +08:00
|
|
|
{
|
2001-07-05 16:40:40 +08:00
|
|
|
int inquote;
|
|
|
|
|
|
|
|
if ( rdn == NULL ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strchr( rdn, '=' ) == NULL ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( *rdn && ASCII_SPACE( *rdn ) ) {
|
|
|
|
rdn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *rdn == '\0' ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
inquote = 0;
|
|
|
|
|
|
|
|
for ( ; *rdn; rdn++ ) {
|
|
|
|
if ( *rdn == '\\' ) {
|
|
|
|
if ( *(rdn + 1) ) {
|
|
|
|
rdn++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( inquote ) {
|
|
|
|
if ( *rdn == '"' ) {
|
|
|
|
inquote = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( *rdn == '"' ) {
|
|
|
|
inquote = 1;
|
|
|
|
} else if ( DN_SEPARATOR( *rdn ) ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 1 );
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|
1999-03-25 04:26:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* build_new_dn:
|
|
|
|
*
|
2001-07-22 07:45:04 +08:00
|
|
|
* Used by ldbm/bdb2 back_modrdn to create the new dn of entries being
|
1999-03-25 04:26:43 +08:00
|
|
|
* renamed.
|
|
|
|
*
|
2001-07-22 07:45:04 +08:00
|
|
|
* new_dn = parent (p_dn) + separator(s) + rdn (newrdn) + null.
|
1999-03-25 04:26:43 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1999-08-21 03:00:44 +08:00
|
|
|
build_new_dn( char ** new_dn,
|
|
|
|
const char *e_dn,
|
|
|
|
const char * p_dn,
|
|
|
|
const char * newrdn )
|
1999-03-25 04:26:43 +08:00
|
|
|
{
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2001-07-22 07:45:04 +08:00
|
|
|
if ( p_dn == NULL ) {
|
|
|
|
*new_dn = ch_strdup( newrdn );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn ) + 3 );
|
1999-03-25 04:26:43 +08:00
|
|
|
|
|
|
|
strcpy( *new_dn, newrdn );
|
1999-03-25 05:45:15 +08:00
|
|
|
strcat( *new_dn, "," );
|
1999-03-25 04:26:43 +08:00
|
|
|
strcat( *new_dn, p_dn );
|
1999-07-23 01:14:42 +08:00
|
|
|
}
|