xref: /onnv-gate/usr/src/lib/libldap5/sources/ldap/common/srchpref.c (revision 1914:8a8c5f225b1b)
1*1914Scasper /*
2*1914Scasper  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3*1914Scasper  * Use is subject to license terms.
4*1914Scasper  */
50Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
60Sstevel@tonic-gate 
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
90Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
100Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
110Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
140Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
150Sstevel@tonic-gate  * implied. See the License for the specific language governing
160Sstevel@tonic-gate  * rights and limitations under the License.
170Sstevel@tonic-gate  *
180Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
190Sstevel@tonic-gate  * March 31, 1998.
200Sstevel@tonic-gate  *
210Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
220Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
230Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
240Sstevel@tonic-gate  * Rights Reserved.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * Contributor(s):
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Copyright (c) 1993, 1994 Regents of the University of Michigan.
300Sstevel@tonic-gate  * All rights reserved.
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
330Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
340Sstevel@tonic-gate  * to the University of Michigan at Ann Arbor. The name of the University
350Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
360Sstevel@tonic-gate  * software without specific prior written permission. This software
370Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
380Sstevel@tonic-gate  *
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * searchpref.c:  search preferences library routines for LDAP clients
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #include "ldap-int.h"
450Sstevel@tonic-gate #include "srchpref.h"
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static void free_searchobj( struct ldap_searchobj *so );
480Sstevel@tonic-gate static int read_next_searchobj( char **bufp, long *blenp,
490Sstevel@tonic-gate 	struct ldap_searchobj **sop, int soversion );
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static char		*sobjoptions[] = {
530Sstevel@tonic-gate     "internal",
540Sstevel@tonic-gate     NULL
550Sstevel@tonic-gate };
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate static unsigned long	sobjoptvals[] = {
590Sstevel@tonic-gate     LDAP_SEARCHOBJ_OPT_INTERNAL,
600Sstevel@tonic-gate };
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
630Sstevel@tonic-gate int
640Sstevel@tonic-gate LDAP_CALL
ldap_init_searchprefs(char * file,struct ldap_searchobj ** solistp)650Sstevel@tonic-gate ldap_init_searchprefs( char *file, struct ldap_searchobj **solistp )
660Sstevel@tonic-gate {
670Sstevel@tonic-gate     FILE	*fp;
680Sstevel@tonic-gate     char	*buf;
690Sstevel@tonic-gate     long	rlen, len;
700Sstevel@tonic-gate     int		rc, eof;
710Sstevel@tonic-gate 
72*1914Scasper     if (( fp = fopen( file, "rF" )) == NULL ) {
730Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_FILE );
740Sstevel@tonic-gate     }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate     if ( fseek( fp, 0L, SEEK_END ) != 0 ) {	/* move to end to get len */
770Sstevel@tonic-gate 	fclose( fp );
780Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_FILE );
790Sstevel@tonic-gate     }
800Sstevel@tonic-gate 
810Sstevel@tonic-gate     len = ftell( fp );
820Sstevel@tonic-gate 
830Sstevel@tonic-gate     if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {	/* back to start of file */
840Sstevel@tonic-gate 	fclose( fp );
850Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_FILE );
860Sstevel@tonic-gate     }
870Sstevel@tonic-gate 
880Sstevel@tonic-gate     if (( buf = NSLDAPI_MALLOC( (size_t)len )) == NULL ) {
890Sstevel@tonic-gate 	fclose( fp );
900Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_MEM );
910Sstevel@tonic-gate     }
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     rlen = fread( buf, 1, (size_t)len, fp );
940Sstevel@tonic-gate     eof = feof( fp );
950Sstevel@tonic-gate     fclose( fp );
960Sstevel@tonic-gate 
970Sstevel@tonic-gate     if ( rlen != len && !eof ) {	/* error:  didn't get the whole file */
980Sstevel@tonic-gate 	NSLDAPI_FREE( buf );
990Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_FILE );
1000Sstevel@tonic-gate     }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate     rc = ldap_init_searchprefs_buf( buf, rlen, solistp );
1030Sstevel@tonic-gate     NSLDAPI_FREE( buf );
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate     return( rc );
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate int
1100Sstevel@tonic-gate LDAP_CALL
ldap_init_searchprefs_buf(char * buf,long buflen,struct ldap_searchobj ** solistp)1110Sstevel@tonic-gate ldap_init_searchprefs_buf( char *buf, long buflen,
1120Sstevel@tonic-gate 	struct ldap_searchobj **solistp )
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate     int				rc = 0, version;
1150Sstevel@tonic-gate     char			**toks;
1160Sstevel@tonic-gate     struct ldap_searchobj	*prevso, *so;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate     *solistp = prevso = NULLSEARCHOBJ;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate     if ( ldap_next_line_tokens( &buf, &buflen, &toks ) != 2 ||
1210Sstevel@tonic-gate 	    strcasecmp( toks[ 0 ], "version" ) != 0 ) {
1220Sstevel@tonic-gate 	ldap_free_strarray( toks );
1230Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
1240Sstevel@tonic-gate     }
1250Sstevel@tonic-gate     version = atoi( toks[ 1 ] );
1260Sstevel@tonic-gate     ldap_free_strarray( toks );
1270Sstevel@tonic-gate     if ( version != LDAP_SEARCHPREF_VERSION &&
1280Sstevel@tonic-gate 	    version != LDAP_SEARCHPREF_VERSION_ZERO ) {
1290Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_VERSION );
1300Sstevel@tonic-gate     }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate     while ( buflen > 0 && ( rc = read_next_searchobj( &buf, &buflen, &so,
1330Sstevel@tonic-gate 	    version )) == 0 && so != NULLSEARCHOBJ ) {
1340Sstevel@tonic-gate 	if ( prevso == NULLSEARCHOBJ ) {
1350Sstevel@tonic-gate 	    *solistp = so;
1360Sstevel@tonic-gate 	} else {
1370Sstevel@tonic-gate 	    prevso->so_next = so;
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 	prevso = so;
1400Sstevel@tonic-gate     }
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate     if ( rc != 0 ) {
1430Sstevel@tonic-gate 	ldap_free_searchprefs( *solistp );
1440Sstevel@tonic-gate     }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate     return( rc );
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate void
1520Sstevel@tonic-gate LDAP_CALL
ldap_free_searchprefs(struct ldap_searchobj * solist)1530Sstevel@tonic-gate ldap_free_searchprefs( struct ldap_searchobj *solist )
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate     struct ldap_searchobj	*so, *nextso;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate     if ( solist != NULL ) {
1580Sstevel@tonic-gate 	for ( so = solist; so != NULL; so = nextso ) {
1590Sstevel@tonic-gate 	    nextso = so->so_next;
1600Sstevel@tonic-gate 	    free_searchobj( so );
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate     }
1630Sstevel@tonic-gate     /* XXX XXX need to do some work here */
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate static void
free_searchobj(struct ldap_searchobj * so)1680Sstevel@tonic-gate free_searchobj( struct ldap_searchobj *so )
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate     if ( so != NULL ) {
1710Sstevel@tonic-gate 	if ( so->so_objtypeprompt != NULL ) {
1720Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_objtypeprompt );
1730Sstevel@tonic-gate 	}
1740Sstevel@tonic-gate 	if ( so->so_prompt != NULL ) {
1750Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_prompt );
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate 	if ( so->so_filterprefix != NULL ) {
1780Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_filterprefix );
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 	if ( so->so_filtertag != NULL ) {
1810Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_filtertag );
1820Sstevel@tonic-gate 	}
1830Sstevel@tonic-gate 	if ( so->so_defaultselectattr != NULL ) {
1840Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_defaultselectattr );
1850Sstevel@tonic-gate 	}
1860Sstevel@tonic-gate 	if ( so->so_defaultselecttext != NULL ) {
1870Sstevel@tonic-gate 	    NSLDAPI_FREE(  so->so_defaultselecttext );
1880Sstevel@tonic-gate 	}
1890Sstevel@tonic-gate 	if ( so->so_salist != NULL ) {
1900Sstevel@tonic-gate 	    struct ldap_searchattr *sa, *nextsa;
1910Sstevel@tonic-gate 	    for ( sa = so->so_salist; sa != NULL; sa = nextsa ) {
1920Sstevel@tonic-gate 		nextsa = sa->sa_next;
1930Sstevel@tonic-gate 		if ( sa->sa_attrlabel != NULL ) {
1940Sstevel@tonic-gate 		    NSLDAPI_FREE( sa->sa_attrlabel );
1950Sstevel@tonic-gate 		}
1960Sstevel@tonic-gate 		if ( sa->sa_attr != NULL ) {
1970Sstevel@tonic-gate 		    NSLDAPI_FREE( sa->sa_attr );
1980Sstevel@tonic-gate 		}
1990Sstevel@tonic-gate 		if ( sa->sa_selectattr != NULL ) {
2000Sstevel@tonic-gate 		    NSLDAPI_FREE( sa->sa_selectattr );
2010Sstevel@tonic-gate 		}
2020Sstevel@tonic-gate 		if ( sa->sa_selecttext != NULL ) {
2030Sstevel@tonic-gate 		    NSLDAPI_FREE( sa->sa_selecttext );
2040Sstevel@tonic-gate 		}
2050Sstevel@tonic-gate 		NSLDAPI_FREE( sa );
2060Sstevel@tonic-gate 	    }
2070Sstevel@tonic-gate 	}
2080Sstevel@tonic-gate 	if ( so->so_smlist != NULL ) {
2090Sstevel@tonic-gate 	    struct ldap_searchmatch *sm, *nextsm;
2100Sstevel@tonic-gate 	    for ( sm = so->so_smlist; sm != NULL; sm = nextsm ) {
2110Sstevel@tonic-gate 		nextsm = sm->sm_next;
2120Sstevel@tonic-gate 		if ( sm->sm_matchprompt != NULL ) {
2130Sstevel@tonic-gate 		    NSLDAPI_FREE( sm->sm_matchprompt );
2140Sstevel@tonic-gate 		}
2150Sstevel@tonic-gate 		if ( sm->sm_filter != NULL ) {
2160Sstevel@tonic-gate 		    NSLDAPI_FREE( sm->sm_filter );
2170Sstevel@tonic-gate 		}
2180Sstevel@tonic-gate 		NSLDAPI_FREE( sm );
2190Sstevel@tonic-gate 	    }
2200Sstevel@tonic-gate 	}
2210Sstevel@tonic-gate 	NSLDAPI_FREE( so );
2220Sstevel@tonic-gate     }
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate struct ldap_searchobj *
2280Sstevel@tonic-gate LDAP_CALL
ldap_first_searchobj(struct ldap_searchobj * solist)2290Sstevel@tonic-gate ldap_first_searchobj( struct ldap_searchobj *solist )
2300Sstevel@tonic-gate {
2310Sstevel@tonic-gate     return( solist );
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate struct ldap_searchobj *
2360Sstevel@tonic-gate LDAP_CALL
ldap_next_searchobj(struct ldap_searchobj * solist,struct ldap_searchobj * so)2370Sstevel@tonic-gate ldap_next_searchobj( struct ldap_searchobj *solist, struct ldap_searchobj *so )
2380Sstevel@tonic-gate {
2390Sstevel@tonic-gate     return( so == NULLSEARCHOBJ ? so : so->so_next );
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate static int
read_next_searchobj(char ** bufp,long * blenp,struct ldap_searchobj ** sop,int soversion)2450Sstevel@tonic-gate read_next_searchobj( char **bufp, long *blenp, struct ldap_searchobj **sop,
2460Sstevel@tonic-gate 	int soversion )
2470Sstevel@tonic-gate {
2480Sstevel@tonic-gate     int				i, j, tokcnt;
2490Sstevel@tonic-gate     char			**toks;
2500Sstevel@tonic-gate     struct ldap_searchobj	*so;
2510Sstevel@tonic-gate     struct ldap_searchattr	**sa;
2520Sstevel@tonic-gate     struct ldap_searchmatch	**sm;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate     *sop = NULL;
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate     /*
2570Sstevel@tonic-gate      * Object type prompt comes first
2580Sstevel@tonic-gate      */
2590Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
2600Sstevel@tonic-gate 	ldap_free_strarray( toks );
2610Sstevel@tonic-gate 	return( tokcnt == 0 ? 0 : LDAP_SEARCHPREF_ERR_SYNTAX );
2620Sstevel@tonic-gate     }
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate     if (( so = (struct ldap_searchobj *)NSLDAPI_CALLOC( 1,
2650Sstevel@tonic-gate 	    sizeof( struct ldap_searchobj ))) == NULL ) {
2660Sstevel@tonic-gate 	ldap_free_strarray( toks );
2670Sstevel@tonic-gate 	return(  LDAP_SEARCHPREF_ERR_MEM );
2680Sstevel@tonic-gate     }
2690Sstevel@tonic-gate     so->so_objtypeprompt = toks[ 0 ];
2700Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate     /*
2730Sstevel@tonic-gate      * if this is post-version zero, options come next
2740Sstevel@tonic-gate      */
2750Sstevel@tonic-gate     if ( soversion > LDAP_SEARCHPREF_VERSION_ZERO ) {
2760Sstevel@tonic-gate 	if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) < 1 ) {
2770Sstevel@tonic-gate 	    ldap_free_strarray( toks );
2780Sstevel@tonic-gate 	    ldap_free_searchprefs( so );
2790Sstevel@tonic-gate 	    return( LDAP_SEARCHPREF_ERR_SYNTAX );
2800Sstevel@tonic-gate 	}
2810Sstevel@tonic-gate 	for ( i = 0; toks[ i ] != NULL; ++i ) {
2820Sstevel@tonic-gate 	    for ( j = 0; sobjoptions[ j ] != NULL; ++j ) {
2830Sstevel@tonic-gate 		if ( strcasecmp( toks[ i ], sobjoptions[ j ] ) == 0 ) {
2840Sstevel@tonic-gate 		    so->so_options |= sobjoptvals[ j ];
2850Sstevel@tonic-gate 		}
2860Sstevel@tonic-gate 	    }
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 	ldap_free_strarray( toks );
2890Sstevel@tonic-gate     }
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate     /*
2920Sstevel@tonic-gate      * "Fewer choices" prompt is next
2930Sstevel@tonic-gate      */
2940Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
2950Sstevel@tonic-gate 	ldap_free_strarray( toks );
2960Sstevel@tonic-gate 	ldap_free_searchprefs( so );
2970Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
2980Sstevel@tonic-gate     }
2990Sstevel@tonic-gate     so->so_prompt = toks[ 0 ];
3000Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate     /*
3030Sstevel@tonic-gate      * Filter prefix for "More Choices" searching is next
3040Sstevel@tonic-gate      */
3050Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
3060Sstevel@tonic-gate 	ldap_free_strarray( toks );
3070Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3080Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3090Sstevel@tonic-gate     }
3100Sstevel@tonic-gate     so->so_filterprefix = toks[ 0 ];
3110Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate     /*
3140Sstevel@tonic-gate      * "Fewer Choices" filter tag comes next
3150Sstevel@tonic-gate      */
3160Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
3170Sstevel@tonic-gate 	ldap_free_strarray( toks );
3180Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3190Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3200Sstevel@tonic-gate     }
3210Sstevel@tonic-gate     so->so_filtertag = toks[ 0 ];
3220Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate     /*
3250Sstevel@tonic-gate      * Selection (disambiguation) attribute comes next
3260Sstevel@tonic-gate      */
3270Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
3280Sstevel@tonic-gate 	ldap_free_strarray( toks );
3290Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3300Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3310Sstevel@tonic-gate     }
3320Sstevel@tonic-gate     so->so_defaultselectattr = toks[ 0 ];
3330Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate     /*
3360Sstevel@tonic-gate      * Label for selection (disambiguation) attribute
3370Sstevel@tonic-gate      */
3380Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
3390Sstevel@tonic-gate 	ldap_free_strarray( toks );
3400Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3410Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3420Sstevel@tonic-gate     }
3430Sstevel@tonic-gate     so->so_defaultselecttext = toks[ 0 ];
3440Sstevel@tonic-gate     NSLDAPI_FREE( (char *)toks );
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate     /*
3470Sstevel@tonic-gate      * Search scope is next
3480Sstevel@tonic-gate      */
3490Sstevel@tonic-gate     if (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
3500Sstevel@tonic-gate 	ldap_free_strarray( toks );
3510Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3520Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3530Sstevel@tonic-gate     }
3540Sstevel@tonic-gate     if ( !strcasecmp(toks[ 0 ], "subtree" )) {
3550Sstevel@tonic-gate 	so->so_defaultscope = LDAP_SCOPE_SUBTREE;
3560Sstevel@tonic-gate     } else if ( !strcasecmp(toks[ 0 ], "onelevel" )) {
3570Sstevel@tonic-gate 	so->so_defaultscope = LDAP_SCOPE_ONELEVEL;
3580Sstevel@tonic-gate     } else if ( !strcasecmp(toks[ 0 ], "base" )) {
3590Sstevel@tonic-gate 	so->so_defaultscope = LDAP_SCOPE_BASE;
3600Sstevel@tonic-gate     } else {
3610Sstevel@tonic-gate 	ldap_free_searchprefs( so );
3620Sstevel@tonic-gate 	return( LDAP_SEARCHPREF_ERR_SYNTAX );
3630Sstevel@tonic-gate     }
3640Sstevel@tonic-gate     ldap_free_strarray( toks );
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate     /*
3680Sstevel@tonic-gate      * "More Choices" search option list comes next
3690Sstevel@tonic-gate      */
3700Sstevel@tonic-gate     sa = &( so->so_salist );
3710Sstevel@tonic-gate     while (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
3720Sstevel@tonic-gate 	if ( tokcnt < 5 ) {
3730Sstevel@tonic-gate 	    ldap_free_strarray( toks );
3740Sstevel@tonic-gate 	    ldap_free_searchprefs( so );
3750Sstevel@tonic-gate 	    return( LDAP_SEARCHPREF_ERR_SYNTAX );
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate 	if (( *sa = ( struct ldap_searchattr * )NSLDAPI_CALLOC( 1,
3780Sstevel@tonic-gate 		sizeof( struct ldap_searchattr ))) == NULL ) {
3790Sstevel@tonic-gate 	    ldap_free_strarray( toks );
3800Sstevel@tonic-gate 	    ldap_free_searchprefs( so );
3810Sstevel@tonic-gate 	    return(  LDAP_SEARCHPREF_ERR_MEM );
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 	( *sa )->sa_attrlabel = toks[ 0 ];
3840Sstevel@tonic-gate 	( *sa )->sa_attr = toks[ 1 ];
3850Sstevel@tonic-gate 	( *sa )->sa_selectattr = toks[ 3 ];
3860Sstevel@tonic-gate 	( *sa )->sa_selecttext = toks[ 4 ];
3870Sstevel@tonic-gate 	/* Deal with bitmap */
3880Sstevel@tonic-gate 	( *sa )->sa_matchtypebitmap = 0;
3890Sstevel@tonic-gate 	for ( i = strlen( toks[ 2 ] ) - 1, j = 0; i >= 0; i--, j++ ) {
3900Sstevel@tonic-gate 	    if ( toks[ 2 ][ i ] == '1' ) {
3910Sstevel@tonic-gate 		( *sa )->sa_matchtypebitmap |= (1 << j);
3920Sstevel@tonic-gate 	    }
3930Sstevel@tonic-gate 	}
3940Sstevel@tonic-gate 	NSLDAPI_FREE( toks[ 2 ] );
3950Sstevel@tonic-gate 	NSLDAPI_FREE( ( char * ) toks );
3960Sstevel@tonic-gate 	sa = &(( *sa )->sa_next);
3970Sstevel@tonic-gate     }
3980Sstevel@tonic-gate     *sa = NULL;
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate     /*
4010Sstevel@tonic-gate      * Match types are last
4020Sstevel@tonic-gate      */
4030Sstevel@tonic-gate     sm = &( so->so_smlist );
4040Sstevel@tonic-gate     while (( tokcnt = ldap_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
4050Sstevel@tonic-gate 	if ( tokcnt < 2 ) {
4060Sstevel@tonic-gate 	    ldap_free_strarray( toks );
4070Sstevel@tonic-gate 	    ldap_free_searchprefs( so );
4080Sstevel@tonic-gate 	    return( LDAP_SEARCHPREF_ERR_SYNTAX );
4090Sstevel@tonic-gate 	}
4100Sstevel@tonic-gate 	if (( *sm = ( struct ldap_searchmatch * )NSLDAPI_CALLOC( 1,
4110Sstevel@tonic-gate 		sizeof( struct ldap_searchmatch ))) == NULL ) {
4120Sstevel@tonic-gate 	    ldap_free_strarray( toks );
4130Sstevel@tonic-gate 	    ldap_free_searchprefs( so );
4140Sstevel@tonic-gate 	    return(  LDAP_SEARCHPREF_ERR_MEM );
4150Sstevel@tonic-gate 	}
4160Sstevel@tonic-gate 	( *sm )->sm_matchprompt = toks[ 0 ];
4170Sstevel@tonic-gate 	( *sm )->sm_filter = toks[ 1 ];
4180Sstevel@tonic-gate 	NSLDAPI_FREE( ( char * ) toks );
4190Sstevel@tonic-gate 	sm = &(( *sm )->sm_next );
4200Sstevel@tonic-gate     }
4210Sstevel@tonic-gate     *sm = NULL;
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate     *sop = so;
4240Sstevel@tonic-gate     return( 0 );
4250Sstevel@tonic-gate }
426