/*
* 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) 1990 Regents of the University of Michigan.
* All rights reserved.
*/
/*
* ufn.c
*/
#if 0
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#endif
#include "ldap-int.h"
/*
* ldap_ufn_search_ctx - do user friendly searching; provide cancel feature;
* specify ldapfilter.conf tags for each phase of search
*
* ld LDAP descriptor
* ufncomp the exploded user friendly name to look for
* ncomp number of elements in ufncomp
* prefix where to start searching
* attrs list of attribute types to return for matches
* attrsonly 1 => attributes only 0 => attributes and values
* res will contain the result of the search
* cancelproc routine that returns non-zero if operation should be
* cancelled. This can be NULL. If it is non-NULL, the
* routine will be called periodically.
* cancelparm void * that is passed to cancelproc
* tag[123] the ldapfilter.conf tag that will be used in phases
* 1, 2, and 3 of the search, respectively
*
* Example:
* char *attrs[] = { "mail", "title", 0 };
* char *ufncomp[] = { "howes", "umich", "us", 0 }
* LDAPMessage *res;
* error = ldap_ufn_search_ctx( ld, ufncomp, 3, NULL, attrs, attrsonly,
* &res, acancelproc, along, "ufn first",
* "ufn intermediate", "ufn last" );
*/
static int
char **ufncomp,
int ncomp,
char *prefix,
char **attrs,
int attrsonly,
LDAPMessage **res,
void *cancelparm,
char *tag1,
char *tag2,
char *tag3
)
{
/*
* look up ufn components from most to least significant.
* there are 3 phases.
* phase 1 search the root for orgs or countries
* phase 2 search for orgs
* phase 3 search for a person
* in phases 1 and 2, we are building a list of candidate DNs,
* below which we will search for the final component of the ufn.
* for each component we try the filters listed in the
* filterconfig file, first one-level (except the last compoment),
* then subtree. if any of them produce any results, we go on to
* the next component.
*/
candidates = NULL;
phase = 1;
char *quote;
*quote = '\0';
}
if ( ncomp == 0 )
phase = 3;
switch ( phase ) {
case 1:
break;
case 2:
break;
case 3:
break;
}
/*
* construct an array of DN's to search below from the
* list of candidates.
*/
if ( candidates == NULL ) {
if ( (dns = (char **)NSLDAPI_MALLOC(
sizeof(char *) * 2 )) == NULL ) {
return( err );
}
} else {
}
} else {
i = 0, max = 0;
{
continue;
if ( (dns = (char **)NSLDAPI_MALLOC(
sizeof(char *) * 8 )) == NULL ) {
return( err );
}
max = 8;
} else if ( i >= max ) {
if ( (dns = (char **)NSLDAPI_REALLOC(
== NULL ) {
return( err );
}
max *= 2;
}
}
candidates = NULL;
}
tries = 0;
tries++;
{
{
break;
}
ldap_value_free( dns );
}
return( err );
}
}
if ( candidates == NULL ) {
goto tryagain;
} else {
ldap_value_free( dns );
}
return( err );
}
}
/* go on to the next component */
if ( phase == 1 )
phase++;
ldap_value_free( dns );
}
}
*res = candidates;
return( err );
}
int
{
char *pbuf;
/* getfilter stuff must be inited before we are called */
return( err );
}
/* call ldap_explode_dn() to break the ufn into its components */
return( err );
}
; /* NULL */
/* more than two components => try it fully qualified first */
return( err );
} else {
ldap_msgfree( *res );
}
}
return( err );
}
/* if that failed, or < 2 components, use the prefix */
return( err );
}
; /* NULL */
== NULL ) {
return( err );
}
for ( i = 0; i < pcomp; i++ ) {
int j;
*pbuf = '\0';
for ( j = i; j < pcomp; j++ ) {
if ( j + 1 < pcomp )
}
break;
} else {
ldap_msgfree( *res );
}
}
NSLDAPI_FREE( pbuf );
return( err );
}
/*
* same as ldap_ufn_search_ct, except without the ability to specify
* ldapfilter.conf tags.
*/
int
{
}
/*
* same as ldap_ufn_search_c without the cancel function
*/
int
LDAPMessage **res )
{
"ufn first", "ufn intermediate", "ufn last" ) );
}
/*
* ldap_msg_merge - merge two ldap search result chains. the more
* serious of the two error result codes is kept.
*/
static LDAPMessage *
{
if ( a == NULL )
return( b );
if ( b == NULL )
return( a );
/* find the ends of the a and b chains */
/* keep result a */
/* remove result b */
ldap_msgfree( bend );
else
b = NULL;
else
a = NULL;
/* keep result b */
} else {
/* remove result a */
ldap_msgfree( aend );
else
a = NULL;
else
b = NULL;
}
return( end );
if ( a == NULL ) {
return( b );
} else if ( b == NULL ) {
return( a );
} else {
return( a );
}
}
static LDAPMessage *
{
char *dn;
int i, msgid;
/* search for this component below the current candidates */
i = 0;
do {
else
dn = "";
aonly )) == -1 ) {
ldap_msgfree( tmpcand );
return( NULL );
}
do {
(*cancelproc)( cancelparm ) != 0 ) {
}
} while ( *err == 0 );
ldap_msgfree( tmpcand );
return( NULL );
}
i++;
return( tmpcand );
} else {
ldap_msgfree( tmpcand );
return( NULL );
}
}
/*
* ldap_ufn_setfilter - set the filter config file used in ufn searching
*/
{
}
void
{
}
int
{
}
}