/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* Copyright (c) 1994 Regents of the University of Michigan.
* All rights reserved.
*/
/*
* getdn.c
*/
#if 0
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#endif
#include "ldap-int.h"
char *
{
char *dn;
if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
return( NULL ); /* punt */
}
if ( !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( entry )) {
return( NULL );
}
return( NULL );
}
return( dn );
}
char *
{
char *p, *ufn, *r;
int state;
dn = "";
}
return( nsldapi_strdup( (char *)dn ));
ufn = nsldapi_strdup( ++p );
plen = 1;
switch ( *p ) {
case '\\':
if ( *++p == '\0' )
plen=0;
else {
*r++ = '\\';
r += (plen = LDAP_UTF8COPY(r,p));
}
break;
case '"':
else
*r++ = *p;
break;
case ';':
case ',':
*r++ = ',';
else
*r++ = *p;
break;
case '=':
*r++ = *p;
else {
char *rsave = r;
LDAP_UTF8DEC(r);
*rsave = '\0';
while ( !ldap_utf8isspace( r ) && *r != ';'
&& *r != ',' && r > ufn )
LDAP_UTF8DEC(r);
LDAP_UTF8INC(r);
if ( strcasecmp( r, "c" )
&& strcasecmp( r, "o" )
&& strcasecmp( r, "ou" )
&& strcasecmp( r, "st" )
&& strcasecmp( r, "l" )
&& strcasecmp( r, "dc" )
&& strcasecmp( r, "uid" )
&& strcasecmp( r, "cn" ) ) {
r = rsave;
*r++ = '=';
}
}
break;
default:
r += (plen = LDAP_UTF8COPY(r,p));
break;
}
}
*r = '\0';
return( ufn );
}
char **
{
char *s, *cpydn;
char **rdns;
#ifdef HAVE_STRTOK_R /* defined in portable.h */
char *lasts;
#endif
dn = "";
}
return( NULL );
}
maxcomps = 8;
ncomps = 0;
maxcomps *= 2;
sizeof(char *) )) == NULL ) {
NSLDAPI_FREE( cpydn );
return( NULL );
}
}
}
NSLDAPI_FREE( cpydn );
return( rdns );
}
static char **
{
dn = "";
}
#if 0
if ( ldap_is_dns_dn( dn ) ) {
return( ldap_explode_dns( dn ) );
}
#endif
++dn;
}
goteq = 0;
do {
p += plen;
plen = 1;
switch ( *p ) {
case '\\':
if ( *++p == '\0' )
p--;
else
plen = LDAP_UTF8LEN(p);
break;
case '"':
else
break;
case ';':
case ',':
case '\0':
/*
* semicolon and comma are not valid RDN
* separators.
*/
return NULL;
}
/* If we get here, we have a case similar
* to <attr>=<value>,<string>,<attr>=<value>
* This is not a valid dn */
return NULL;
}
goteq = 0;
++count;
* sizeof( char *))) == NULL )
return( NULL );
} else if ( count >= 8 ) {
if (( rdns = (char **)NSLDAPI_REALLOC(
sizeof( char *))) == NULL )
return( NULL );
}
endquote = 0;
if ( notypes ) {
for ( q = rdnstart;
q < p && *q != '='; ++q ) {
;
}
if ( q < p ) { /* *q == '=' */
rdnstart = ++q;
}
if ( *rdnstart == '"' ) {
++rdnstart;
}
if ( *(p-1) == '"' ) {
endquote = 1;
--p;
}
}
len );
if ( !endquote ) {
/* trim trailing spaces */
while ( len > 0 &&
--len;
}
}
}
/*
* Don't forget to increment 'p' back to where
* it should be. If we don't, then we will
* never get past an "end quote."
*/
if ( endquote == 1 )
p++;
rdnstart = *p ? p + 1 : p;
while ( ldap_utf8isspace( rdnstart ))
++rdnstart;
}
break;
case '=':
goteq = 1;
}
/* FALL */
default:
plen = LDAP_UTF8LEN(p);
break;
}
} while ( *p );
return( rdns );
}
char **
{
}
char **
{
}
int
{
}
#ifdef _SOLARIS_SDK
/*
* Convert a DNS domain name into an X.500 distinguished name.
* For example, "sales.wiz.com" -> "dc=sales,dc=wiz,dc=com"
*
* If an error is encountered zero is returned, otherwise a string
* distinguished name and the number of nameparts is returned.
* The caller should free the returned string if it is non-zero.
*/
char *
char *dns_name,
int *nameparts
)
{
char *dn = 0;
char *cp;
/* check for NULL string, empty name and name ending in '.' */
*nameparts = 0;
while (*dns_name) {
*cp++ = 'd';
*cp++ = 'c';
*cp++ = '=';
}
if (*dns_name == '.') {
dns_name++;
*cp++ = ',';
}
(*nameparts)++;
}
*cp = '\0';
}
}
return (dn);
}
#endif