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