17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
23a87701eGary Mills * Copyright 2015 Gary Mills
247c478bdstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
257c478bdstevel@tonic-gate * Use is subject to license terms.
267c478bdstevel@tonic-gate */
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#include <stdio.h>
297c478bdstevel@tonic-gate#include <string.h>
307c478bdstevel@tonic-gate#include <stdlib.h>
317c478bdstevel@tonic-gate#include <ctype.h>
327c478bdstevel@tonic-gate#include <fcntl.h>
337c478bdstevel@tonic-gate#include <unistd.h>
347c478bdstevel@tonic-gate#include <errno.h>
357c478bdstevel@tonic-gate#include <locale.h>
367c478bdstevel@tonic-gate#include <lber.h>
377c478bdstevel@tonic-gate#include <ldap.h>
387c478bdstevel@tonic-gate#include <syslog.h>
397c478bdstevel@tonic-gate#include <dlfcn.h>	/* for dynamic loading only */
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate#include "ldap_parse.h"
427c478bdstevel@tonic-gate#include "nis_parse_ldap_conf.h"
437c478bdstevel@tonic-gate#include "nis_parse_ldap_err.h"
447c478bdstevel@tonic-gate#include "ldap_util.h"
457c478bdstevel@tonic-gate#include "ldap_util.h"
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gatevoid append_dot(char **str);
487c478bdstevel@tonic-gatevoid	append_comma(char **str);
497c478bdstevel@tonic-gatebool_t make_full_dn(char **dn, const char *base);
507c478bdstevel@tonic-gatebool_t make_fqdn(__nis_object_dn_t *dn, const char *base);
517c478bdstevel@tonic-gatechar *get_default_ldap_base(const char *domain);
527c478bdstevel@tonic-gatebool_t add_domain(char **objName, const char *domain);
537c478bdstevel@tonic-gatebool_t add_column(__nis_table_mapping_t *t, const char *col_name);
547c478bdstevel@tonic-gate__nis_mapping_rule_t **dup_mapping_rules(
557c478bdstevel@tonic-gate	__nis_mapping_rule_t **rules, int n_rules);
567c478bdstevel@tonic-gate__nis_mapping_rule_t *dup_mapping_rule(
577c478bdstevel@tonic-gate	__nis_mapping_rule_t *in);
587c478bdstevel@tonic-gatevoid *s_malloc(size_t size);
597c478bdstevel@tonic-gate__nis_mapping_format_t *dup_format_mapping(
607c478bdstevel@tonic-gate	__nis_mapping_format_t *in);
617c478bdstevel@tonic-gatebool_t dup_mapping_element(__nis_mapping_element_t *in,
627c478bdstevel@tonic-gate	__nis_mapping_element_t *out);
63a87701eGary Millsbool_t is_string_ok(char *, int);
647c478bdstevel@tonic-gate
657c478bdstevel@tonic-gateextern FILE *cons;
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate/*
687c478bdstevel@tonic-gate * FUNCTION:	free_parse_structs
697c478bdstevel@tonic-gate *
707c478bdstevel@tonic-gate *	Release the resources in parse results
717c478bdstevel@tonic-gate *
727c478bdstevel@tonic-gate */
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gatevoid
757c478bdstevel@tonic-gatefree_parse_structs()
767c478bdstevel@tonic-gate{
777c478bdstevel@tonic-gate	__nis_table_mapping_t	*t;
787c478bdstevel@tonic-gate	__nis_table_mapping_t	*t1;
797c478bdstevel@tonic-gate
807c478bdstevel@tonic-gate	free_proxy_info(&proxyInfo);
817c478bdstevel@tonic-gate	for (t = ldapTableMapping; t != NULL; t = t1) {
827c478bdstevel@tonic-gate		t1 = t->next;
837c478bdstevel@tonic-gate		free_table_mapping(t);
847c478bdstevel@tonic-gate	}
857c478bdstevel@tonic-gate	ldapTableMapping = NULL;
867c478bdstevel@tonic-gate}
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gate/*
897c478bdstevel@tonic-gate * FUNCTION:	initialize_parse_structs
907c478bdstevel@tonic-gate *
917c478bdstevel@tonic-gate *	Initialize fields to unset values
927c478bdstevel@tonic-gate *
937c478bdstevel@tonic-gate * INPUT:		__nis_ldap_proxy_info, __nis_config_t
947c478bdstevel@tonic-gate * 			and __nisdb_table_mapping_t structures
957c478bdstevel@tonic-gate */
967c478bdstevel@tonic-gate
977c478bdstevel@tonic-gatevoid
987c478bdstevel@tonic-gateinitialize_parse_structs(
997c478bdstevel@tonic-gate	__nis_ldap_proxy_info	*proxy_info,
1007c478bdstevel@tonic-gate	__nis_config_t		*config_info,
1017c478bdstevel@tonic-gate	__nisdb_table_mapping_t	*table_info)
1027c478bdstevel@tonic-gate{
1037c478bdstevel@tonic-gate	proxy_info->default_servers = NULL;
1047c478bdstevel@tonic-gate	proxy_info->auth_method = (auth_method_t)NO_VALUE_SET;
1057c478bdstevel@tonic-gate	proxy_info->tls_method = (tls_method_t)NO_VALUE_SET;
1067c478bdstevel@tonic-gate	proxy_info->tls_cert_db = NULL;
1077c478bdstevel@tonic-gate	proxy_info->default_search_base = NULL;
1087c478bdstevel@tonic-gate	proxy_info->proxy_dn = NULL;
1097c478bdstevel@tonic-gate	proxy_info->proxy_passwd = NULL;
1107c478bdstevel@tonic-gate	proxy_info->default_nis_domain = NULL;
1117c478bdstevel@tonic-gate	proxy_info->bind_timeout.tv_sec = (time_t)NO_VALUE_SET;
1127c478bdstevel@tonic-gate	proxy_info->bind_timeout.tv_usec = 0;
1137c478bdstevel@tonic-gate	proxy_info->search_timeout.tv_sec = (time_t)NO_VALUE_SET;
1147c478bdstevel@tonic-gate	proxy_info->search_timeout.tv_usec = 0;
1157c478bdstevel@tonic-gate	proxy_info->modify_timeout.tv_sec = (time_t)NO_VALUE_SET;
1167c478bdstevel@tonic-gate	proxy_info->modify_timeout.tv_usec = 0;
1177c478bdstevel@tonic-gate	proxy_info->add_timeout.tv_sec = (time_t)NO_VALUE_SET;
1187c478bdstevel@tonic-gate	proxy_info->add_timeout.tv_usec = 0;
1197c478bdstevel@tonic-gate	proxy_info->delete_timeout.tv_sec = (time_t)NO_VALUE_SET;
1207c478bdstevel@tonic-gate	proxy_info->delete_timeout.tv_usec = 0;
1217c478bdstevel@tonic-gate	proxy_info->search_time_limit = (int)NO_VALUE_SET;
1227c478bdstevel@tonic-gate	proxy_info->search_size_limit = (int)NO_VALUE_SET;
1237c478bdstevel@tonic-gate	proxy_info->follow_referral = (follow_referral_t)NO_VALUE_SET;
1247c478bdstevel@tonic-gate
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gate	config_info->initialUpdate = (__nis_initial_update_t)NO_VALUE_SET;
1277c478bdstevel@tonic-gate	config_info->threadCreationError =
1287c478bdstevel@tonic-gate		(__nis_thread_creation_error_t)NO_VALUE_SET;
1297c478bdstevel@tonic-gate	config_info->threadCreationErrorTimeout.attempts = NO_VALUE_SET;
1307c478bdstevel@tonic-gate	config_info->threadCreationErrorTimeout.timeout = (time_t)NO_VALUE_SET;
1317c478bdstevel@tonic-gate	config_info->dumpError = (__nis_dump_error_t)NO_VALUE_SET;
1327c478bdstevel@tonic-gate	config_info->dumpErrorTimeout.attempts = NO_VALUE_SET;
1337c478bdstevel@tonic-gate	config_info->dumpErrorTimeout.timeout = (time_t)NO_VALUE_SET;
1347c478bdstevel@tonic-gate	config_info->resyncService = (__nis_resync_service_t)NO_VALUE_SET;
1357c478bdstevel@tonic-gate	config_info->updateBatching = (__nis_update_batching_t)NO_VALUE_SET;
1367c478bdstevel@tonic-gate	config_info->updateBatchingTimeout.timeout = (time_t)NO_VALUE_SET;
1377c478bdstevel@tonic-gate	config_info->numberOfServiceThreads = (int)NO_VALUE_SET;
1387c478bdstevel@tonic-gate	config_info->emulate_yp = (int)NO_VALUE_SET;
1397c478bdstevel@tonic-gate	config_info->maxRPCRecordSize = (int)NO_VALUE_SET;
1407c478bdstevel@tonic-gate
1417c478bdstevel@tonic-gate	table_info->retrieveError = (__nis_retrieve_error_t)NO_VALUE_SET;
1427c478bdstevel@tonic-gate	table_info->retrieveErrorRetry.attempts = NO_VALUE_SET;
1437c478bdstevel@tonic-gate	table_info->retrieveErrorRetry.timeout = (time_t)NO_VALUE_SET;
1447c478bdstevel@tonic-gate	table_info->storeError = (__nis_store_error_t)NO_VALUE_SET;
1457c478bdstevel@tonic-gate	table_info->storeErrorRetry.attempts = NO_VALUE_SET;
1467c478bdstevel@tonic-gate	table_info->storeErrorRetry.timeout = (time_t)NO_VALUE_SET;
1477c478bdstevel@tonic-gate	table_info->refreshError = (__nis_refresh_error_t)NO_VALUE_SET;
1487c478bdstevel@tonic-gate	table_info->refreshErrorRetry.attempts = NO_VALUE_SET;
1497c478bdstevel@tonic-gate	table_info->refreshErrorRetry.timeout = (time_t)NO_VALUE_SET;
1507c478bdstevel@tonic-gate	table_info->matchFetch = (__nis_match_fetch_t)NO_VALUE_SET;
1517c478bdstevel@tonic-gate}
1527c478bdstevel@tonic-gate
1537c478bdstevel@tonic-gate/*
1547c478bdstevel@tonic-gate * FUNCTION:	free_mapping_rule
1557c478bdstevel@tonic-gate *
1567c478bdstevel@tonic-gate *	Frees __nis_mapping_rule_t
1577c478bdstevel@tonic-gate *
1587c478bdstevel@tonic-gate * INPUT:		__nis_mapping_rule_t
1597c478bdstevel@tonic-gate */
1607c478bdstevel@tonic-gate
1617c478bdstevel@tonic-gatevoid
1627c478bdstevel@tonic-gatefree_mapping_rule(__nis_mapping_rule_t	*rule)
1637c478bdstevel@tonic-gate{
1647c478bdstevel@tonic-gate	int			i;
1657c478bdstevel@tonic-gate	__nis_mapping_rlhs_t	*r;
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gate	if (rule != NULL) {
1687c478bdstevel@tonic-gate		r = &rule->lhs;
1697c478bdstevel@tonic-gate		for (i = 0; i < r->numElements; i++)
1707c478bdstevel@tonic-gate			free_mapping_element(&r->element[i]);
1717c478bdstevel@tonic-gate		if (r->element != NULL)
1727c478bdstevel@tonic-gate			free(r->element);
1737c478bdstevel@tonic-gate
1747c478bdstevel@tonic-gate		r = &rule->rhs;
1757c478bdstevel@tonic-gate		for (i = 0; i < r->numElements; i++)
1767c478bdstevel@tonic-gate			free_mapping_element(&r->element[i]);
1777c478bdstevel@tonic-gate		if (r->element != NULL)
1787c478bdstevel@tonic-gate			free(r->element);
1797c478bdstevel@tonic-gate
1807c478bdstevel@tonic-gate		free(rule);
1817c478bdstevel@tonic-gate	}
1827c478bdstevel@tonic-gate}
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gate/*
1857c478bdstevel@tonic-gate * FUNCTION:	free_mapping_element
1867c478bdstevel@tonic-gate *
1877c478bdstevel@tonic-gate *	Frees __nis_mapping_element_t
1887c478bdstevel@tonic-gate *
1897c478bdstevel@tonic-gate * INPUT:		__nis_mapping_element_t
1907c478bdstevel@tonic-gate */
1917c478bdstevel@tonic-gate
1927c478bdstevel@tonic-gatevoid
1937c478bdstevel@tonic-gatefree_mapping_element(__nis_mapping_element_t *e)
1947c478bdstevel@tonic-gate{
1957c478bdstevel@tonic-gate	int	i;
1967c478bdstevel@tonic-gate
1977c478bdstevel@tonic-gate	if (e == NULL)
1987c478bdstevel@tonic-gate		return;
1997c478bdstevel@tonic-gate
2007c478bdstevel@tonic-gate	switch (e->type) {
2017c478bdstevel@tonic-gate	    case me_item:
2027c478bdstevel@tonic-gate		free_mapping_item(&e->element.item);
2037c478bdstevel@tonic-gate		break;
2047c478bdstevel@tonic-gate	    case me_print:
2057c478bdstevel@tonic-gate		if (e->element.print.fmt != NULL)
2067c478bdstevel@tonic-gate			free_mapping_format(e->element.print.fmt);
2077c478bdstevel@tonic-gate		e->element.print.fmt = NULL;
2087c478bdstevel@tonic-gate		for (i = 0; i < e->element.print.numSubElements; i++)
2097c478bdstevel@tonic-gate			free_mapping_sub_element(
2107c478bdstevel@tonic-gate				&e->element.print.subElement[i]);
2117c478bdstevel@tonic-gate		e->element.print.numSubElements = 0;
2127c478bdstevel@tonic-gate		if (e->element.print.subElement != NULL)
2137c478bdstevel@tonic-gate			free(e->element.print.subElement);
2147c478bdstevel@tonic-gate		e->element.print.subElement = NULL;
2157c478bdstevel@tonic-gate		break;
2167c478bdstevel@tonic-gate	    case me_split:
2177c478bdstevel@tonic-gate		free_mapping_item(&e->element.split.item);
2187c478bdstevel@tonic-gate		break;
2197c478bdstevel@tonic-gate	    case me_match:
2207c478bdstevel@tonic-gate		if (e->element.match.fmt != NULL)
2217c478bdstevel@tonic-gate			free_mapping_format(e->element.match.fmt);
2227c478bdstevel@tonic-gate		e->element.match.fmt = NULL;
2237c478bdstevel@tonic-gate		for (i = 0; i < e->element.match.numItems; i++)
2247c478bdstevel@tonic-gate			free_mapping_item(&e->element.match.item[i]);
2257c478bdstevel@tonic-gate		e->element.match.numItems = 0;
2267c478bdstevel@tonic-gate		if (e->element.match.item != NULL)
2277c478bdstevel@tonic-gate		    free(e->element.match.item);
2287c478bdstevel@tonic-gate		e->element.match.item = NULL;
2297c478bdstevel@tonic-gate		break;
2307c478bdstevel@tonic-gate	    case me_extract:
2317c478bdstevel@tonic-gate		if (e->element.extract.fmt != NULL)
2327c478bdstevel@tonic-gate			free_mapping_format(e->element.extract.fmt);
2337c478bdstevel@tonic-gate		e->element.extract.fmt = NULL;
2347c478bdstevel@tonic-gate		free_mapping_item(&e->element.extract.item);
2357c478bdstevel@tonic-gate		break;
2367c478bdstevel@tonic-gate	}
2377c478bdstevel@tonic-gate	e = NULL;
2387c478bdstevel@tonic-gate}
2397c478bdstevel@tonic-gate
2407c478bdstevel@tonic-gate/*
2417c478bdstevel@tonic-gate * FUNCTION:	free_table_mapping
2427c478bdstevel@tonic-gate *
2437c478bdstevel@tonic-gate *	Frees __nis_table_mapping_t
2447c478bdstevel@tonic-gate *
2457c478bdstevel@tonic-gate * INPUT:		__nis_table_mapping_t
2467c478bdstevel@tonic-gate */
2477c478bdstevel@tonic-gate
2487c478bdstevel@tonic-gate/*
2497c478bdstevel@tonic-gate * free_table_mapping does not remove the table mapping from
2507c478bdstevel@tonic-gate * its hashed list
2517c478bdstevel@tonic-gate */
2527c478bdstevel@tonic-gate
2537c478bdstevel@tonic-gatevoid
2547c478bdstevel@tonic-gatefree_table_mapping(__nis_table_mapping_t *mapping)
2557c478bdstevel@tonic-gate{
2567c478bdstevel@tonic-gate	int	i;
2577c478bdstevel@tonic-gate
2587c478bdstevel@tonic-gate	if (mapping == NULL)
2597c478bdstevel@tonic-gate		return;
2607c478bdstevel@tonic-gate
2617c478bdstevel@tonic-gate	if (mapping->dbId != NULL)
2627c478bdstevel@tonic-gate		free(mapping->dbId);
2637c478bdstevel@tonic-gate	mapping->dbId = NULL;
2647c478bdstevel@tonic-gate
2657c478bdstevel@tonic-gate	if (mapping->objName != NULL)
2667c478bdstevel@tonic-gate		free(mapping->objName);
2677c478bdstevel@tonic-gate	mapping->objName = NULL;
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate	for (i = 0; i < mapping->index.numIndexes; i++) {
2707c478bdstevel@tonic-gate		free(mapping->index.name[i]);
2717c478bdstevel@tonic-gate		free_mapping_format(mapping->index.value[i]);
2727c478bdstevel@tonic-gate	}
2737c478bdstevel@tonic-gate
2747c478bdstevel@tonic-gate	if (mapping->index.name != NULL)
2757c478bdstevel@tonic-gate		free(mapping->index.name);
2767c478bdstevel@tonic-gate	mapping->index.name = NULL;
2777c478bdstevel@tonic-gate
2787c478bdstevel@tonic-gate	if (mapping->index.value != NULL)
2797c478bdstevel@tonic-gate		free(mapping->index.value);
2807c478bdstevel@tonic-gate	mapping->index.value = NULL;
2817c478bdstevel@tonic-gate
2827c478bdstevel@tonic-gate	mapping->index.numIndexes = 0;
2837c478bdstevel@tonic-gate
2847c478bdstevel@tonic-gate	if (mapping->column != NULL) {
2857c478bdstevel@tonic-gate		for (i = 0; i < mapping->numColumns; i++) {
2867c478bdstevel@tonic-gate			free(mapping->column[i]);
2877c478bdstevel@tonic-gate		}
2887c478bdstevel@tonic-gate		mapping->numColumns = 0;
2897c478bdstevel@tonic-gate		free(mapping->column);
2907c478bdstevel@tonic-gate		mapping->column = NULL;
2917c478bdstevel@tonic-gate	}
2927c478bdstevel@tonic-gate
293a345176Toomas Soome	if (mapping->commentChar != 0)
294a345176Toomas Soome		mapping->commentChar = 0;
2957c478bdstevel@tonic-gate
2967c478bdstevel@tonic-gate	if (mapping->objectDN != NULL)
2977c478bdstevel@tonic-gate		free_object_dn(mapping->objectDN);
2987c478bdstevel@tonic-gate	mapping->objectDN = NULL;
2997c478bdstevel@tonic-gate
3007c478bdstevel@tonic-gate	if (mapping->separatorStr != NULL)
3017c478bdstevel@tonic-gate		mapping->separatorStr = NULL;
3027c478bdstevel@tonic-gate
3037c478bdstevel@tonic-gate	for (i = 0; i < mapping->numRulesFromLDAP; i++) {
3047c478bdstevel@tonic-gate		if (mapping->ruleFromLDAP[i]) /* See Comment below */
3057c478bdstevel@tonic-gate			free_mapping_rule(mapping->ruleFromLDAP[i]);
3067c478bdstevel@tonic-gate	}
3077c478bdstevel@tonic-gate	mapping->numRulesFromLDAP = 0;
3087c478bdstevel@tonic-gate
3097c478bdstevel@tonic-gate	if (mapping->ruleFromLDAP != NULL)
3107c478bdstevel@tonic-gate		free(mapping->ruleFromLDAP);
3117c478bdstevel@tonic-gate	mapping->ruleFromLDAP = NULL;
3127c478bdstevel@tonic-gate
3137c478bdstevel@tonic-gate	for (i = 0; i < mapping->numRulesToLDAP; i++) {
3147c478bdstevel@tonic-gate		if (mapping->ruleToLDAP[i])
3157c478bdstevel@tonic-gate		/*
3167c478bdstevel@tonic-gate		 * Normally mapping->ruleToLDAP[i] should
3177c478bdstevel@tonic-gate		 * always be non-null if
3187c478bdstevel@tonic-gate		 * mapping->numRulesToLDAP is > 0.
3197c478bdstevel@tonic-gate		 * However it is possible to have data
3207c478bdstevel@tonic-gate		 * corruption where numRulesToLDAP gets
3217c478bdstevel@tonic-gate		 * some integer value even though no real
3227c478bdstevel@tonic-gate		 * data is present in mapping->ruleToLDAP.
3237c478bdstevel@tonic-gate		 */
3247c478bdstevel@tonic-gate			free_mapping_rule(mapping->ruleToLDAP[i]);
3257c478bdstevel@tonic-gate	}
3267c478bdstevel@tonic-gate	mapping->numRulesToLDAP = 0;
3277c478bdstevel@tonic-gate
3287c478bdstevel@tonic-gate	if (mapping->ruleToLDAP != NULL)
3297c478bdstevel@tonic-gate		free(mapping->ruleToLDAP);
3307c478bdstevel@tonic-gate	mapping->ruleToLDAP = NULL;
3317c478bdstevel@tonic-gate
3327c478bdstevel@tonic-gate	if (mapping->e != NULL) {
3337c478bdstevel@tonic-gate		/* Similar logic as in above comment applies. */
3347c478bdstevel@tonic-gate		for (i = 0; i <= mapping->numSplits; i++) {
3357c478bdstevel@tonic-gate			free_mapping_element(&mapping->e[i]);
3367c478bdstevel@tonic-gate		}
3377c478bdstevel@tonic-gate		free(mapping->e);
3387c478bdstevel@tonic-gate	}
3397c478bdstevel@tonic-gate	mapping->e = NULL;
3407c478bdstevel@tonic-gate
3417c478bdstevel@tonic-gate	mapping->numSplits = 0;
3427c478bdstevel@tonic-gate
3437c478bdstevel@tonic-gate	free(mapping);
3447c478bdstevel@tonic-gate}
3457c478bdstevel@tonic-gate
3467c478bdstevel@tonic-gate/*
3477c478bdstevel@tonic-gate * FUNCTION:	free_config_info
3487c478bdstevel@tonic-gate *
3497c478bdstevel@tonic-gate *	Frees __nis_config_info_t
3507c478bdstevel@tonic-gate *
3517c478bdstevel@tonic-gate * INPUT:		__nis_config_info_t
3527c478bdstevel@tonic-gate */
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gatevoid
3557c478bdstevel@tonic-gatefree_config_info(__nis_config_info_t *config_info)
3567c478bdstevel@tonic-gate{
3577c478bdstevel@tonic-gate	if (config_info->config_dn != NULL)
3587c478bdstevel@tonic-gate		free(config_info->config_dn);
3597c478bdstevel@tonic-gate	config_info->config_dn = NULL;
3607c478bdstevel@tonic-gate
3617c478bdstevel@tonic-gate	if (config_info->default_servers != NULL)
3627c478bdstevel@tonic-gate		free(config_info->default_servers);
3637c478bdstevel@tonic-gate	config_info->default_servers = NULL;
3647c478bdstevel@tonic-gate
3657c478bdstevel@tonic-gate	if (config_info->proxy_dn != NULL)
3667c478bdstevel@tonic-gate		free(config_info->proxy_dn);
3677c478bdstevel@tonic-gate	config_info->proxy_dn = NULL;
3687c478bdstevel@tonic-gate
3697c478bdstevel@tonic-gate	if (config_info->proxy_passwd != NULL)
3707c478bdstevel@tonic-gate		free(config_info->proxy_passwd);
3717c478bdstevel@tonic-gate	config_info->proxy_passwd = NULL;
3727c478bdstevel@tonic-gate
3737c478bdstevel@tonic-gate	if (config_info->tls_cert_db != NULL)
3747c478bdstevel@tonic-gate		free(config_info->tls_cert_db);
3757c478bdstevel@tonic-gate	config_info->tls_cert_db = NULL;
3767c478bdstevel@tonic-gate}
3777c478bdstevel@tonic-gate
3787c478bdstevel@tonic-gate/*
3797c478bdstevel@tonic-gate * FUNCTION:	free_proxy_info
3807c478bdstevel@tonic-gate *
3817c478bdstevel@tonic-gate *	Frees __nis_ldap_proxy_info
3827c478bdstevel@tonic-gate *
3837c478bdstevel@tonic-gate * INPUT:		__nis_ldap_proxy_info
3847c478bdstevel@tonic-gate */
3857c478bdstevel@tonic-gate
3867c478bdstevel@tonic-gatevoid
3877c478bdstevel@tonic-gatefree_proxy_info(__nis_ldap_proxy_info *proxy_info)
3887c478bdstevel@tonic-gate{
3897c478bdstevel@tonic-gate	if (proxy_info->tls_cert_db != NULL)
3907c478bdstevel@tonic-gate		free(proxy_info->tls_cert_db);
3917c478bdstevel@tonic-gate	proxy_info->tls_cert_db = NULL;
3927c478bdstevel@tonic-gate
3937c478bdstevel@tonic-gate	if (proxy_info->default_servers != NULL)
3947c478bdstevel@tonic-gate		free(proxy_info->default_servers);
3957c478bdstevel@tonic-gate	proxy_info->default_servers = NULL;
3967c478bdstevel@tonic-gate
3977c478bdstevel@tonic-gate	if (proxy_info->default_search_base != NULL)
3987c478bdstevel@tonic-gate		free(proxy_info->default_search_base);
3997c478bdstevel@tonic-gate	proxy_info->default_search_base = NULL;
4007c478bdstevel@tonic-gate
4017c478bdstevel@tonic-gate	if (proxy_info->proxy_dn != NULL)
4027c478bdstevel@tonic-gate		free(proxy_info->proxy_dn);
4037c478bdstevel@tonic-gate	proxy_info->proxy_dn = NULL;
4047c478bdstevel@tonic-gate
4057c478bdstevel@tonic-gate	if (proxy_info->proxy_passwd != NULL)
4067c478bdstevel@tonic-gate		free(proxy_info->proxy_passwd);
4077c478bdstevel@tonic-gate	proxy_info->proxy_passwd = NULL;
4087c478bdstevel@tonic-gate
4097c478bdstevel@tonic-gate	if (proxy_info->default_nis_domain != NULL)
4107c478bdstevel@tonic-gate		free(proxy_info->default_nis_domain);
4117c478bdstevel@tonic-gate	proxy_info->default_nis_domain = NULL;
4127c478bdstevel@tonic-gate}
4137c478bdstevel@tonic-gate
4147c478bdstevel@tonic-gate/*
4157c478bdstevel@tonic-gate * FUNCTION:	free_object_dn
4167c478bdstevel@tonic-gate *
4177c478bdstevel@tonic-gate *	Frees __nis_object_dn_t
4187c478bdstevel@tonic-gate *
4197c478bdstevel@tonic-gate * INPUT:		__nis_object_dn_t
4207c478bdstevel@tonic-gate */
4217c478bdstevel@tonic-gate
4227c478bdstevel@tonic-gatevoid
4237c478bdstevel@tonic-gatefree_object_dn(__nis_object_dn_t *obj_dn)
4247c478bdstevel@tonic-gate{
4257c478bdstevel@tonic-gate	__nis_object_dn_t	*t;
4267c478bdstevel@tonic-gate	int			i;
4277c478bdstevel@tonic-gate
4287c478bdstevel@tonic-gate	while (obj_dn != NULL) {
4297c478bdstevel@tonic-gate		if (obj_dn->read.base != NULL)
4307c478bdstevel@tonic-gate			free(obj_dn->read.base);
4317c478bdstevel@tonic-gate		obj_dn->read.base = NULL;
4327c478bdstevel@tonic-gate		if (obj_dn->read.attrs != NULL)
4337c478bdstevel@tonic-gate			free(obj_dn->read.attrs);
4347c478bdstevel@tonic-gate		obj_dn->read.attrs = NULL;
4357c478bdstevel@tonic-gate		if (obj_dn->write.base != NULL)
4367c478bdstevel@tonic-gate			free(obj_dn->write.base);
4377c478bdstevel@tonic-gate		obj_dn->write.base = NULL;
4387c478bdstevel@tonic-gate		if (obj_dn->write.attrs != NULL)
4397c478bdstevel@tonic-gate			free(obj_dn->write.attrs);
4407c478bdstevel@tonic-gate		obj_dn->write.attrs = NULL;
4417c478bdstevel@tonic-gate		if (obj_dn->dbIdName != NULL)
4427c478bdstevel@tonic-gate			free(obj_dn->dbIdName);
4437c478bdstevel@tonic-gate		obj_dn->dbIdName = NULL;
4447c478bdstevel@tonic-gate		for (i = 0; i < obj_dn->numDbIds; i++)
4457c478bdstevel@tonic-gate			free_mapping_rule(obj_dn->dbId[i]);
4467c478bdstevel@tonic-gate		obj_dn->numDbIds = 0;
4477c478bdstevel@tonic-gate
4487c478bdstevel@tonic-gate		if (obj_dn->dbId != NULL)
4497c478bdstevel@tonic-gate			free(obj_dn->dbId);
4507c478bdstevel@tonic-gate		obj_dn->dbId = NULL;
4517c478bdstevel@tonic-gate
4527c478bdstevel@tonic-gate		t = obj_dn;
4537c478bdstevel@tonic-gate		obj_dn = obj_dn->next;
4547c478bdstevel@tonic-gate		free(t);
4557c478bdstevel@tonic-gate	}
4567c478bdstevel@tonic-gate}
4577c478bdstevel@tonic-gate
4587c478bdstevel@tonic-gate/*
4597c478bdstevel@tonic-gate * FUNCTION:	free_index
4607c478bdstevel@tonic-gate *
4617c478bdstevel@tonic-gate *	Frees __nis_index_t
4627c478bdstevel@tonic-gate *
4637c478bdstevel@tonic-gate * INPUT:		__nis_index_t
4647c478bdstevel@tonic-gate */
4657c478bdstevel@tonic-gate
4667c478bdstevel@tonic-gatevoid
4677c478bdstevel@tonic-gatefree_index(__nis_index_t *index)
4687c478bdstevel@tonic-gate{
4697c478bdstevel@tonic-gate	int	i;
4707c478bdstevel@tonic-gate	for (i = 0; i < index->numIndexes; i++) {
4717c478bdstevel@tonic-gate		free(index->name[i]);
4727c478bdstevel@tonic-gate		free_mapping_format(index->value[i]);
4737c478bdstevel@tonic-gate	}
4747c478bdstevel@tonic-gate	index->numIndexes = 0;
4757c478bdstevel@tonic-gate	if (index->name != NULL)
4767c478bdstevel@tonic-gate		free(index->name);
4777c478bdstevel@tonic-gate	index->name = NULL;
4787c478bdstevel@tonic-gate	if (index->value != NULL)
4797c478bdstevel@tonic-gate		free(index->value);
4807c478bdstevel@tonic-gate	index->value = NULL;
4817c478bdstevel@tonic-gate}
4827c478bdstevel@tonic-gate
4837c478bdstevel@tonic-gate/*
4847c478bdstevel@tonic-gate * FUNCTION:	free_mapping_item
4857c478bdstevel@tonic-gate *
4867c478bdstevel@tonic-gate *	Frees __nis_mapping_item_t
4877c478bdstevel@tonic-gate *
4887c478bdstevel@tonic-gate * INPUT:		__nis_mapping_item_t
4897c478bdstevel@tonic-gate */
4907c478bdstevel@tonic-gate
4917c478bdstevel@tonic-gatevoid
4927c478bdstevel@tonic-gatefree_mapping_item(__nis_mapping_item_t	*item)
4937c478bdstevel@tonic-gate{
4947c478bdstevel@tonic-gate	if (item == NULL)
4957c478bdstevel@tonic-gate		return;
4967c478bdstevel@tonic-gate
4977c478bdstevel@tonic-gate	if (item->name != NULL)
4987c478bdstevel@tonic-gate		free(item->name);
4997c478bdstevel@tonic-gate	item->name = NULL;
5007c478bdstevel@tonic-gate	if (item->type == mit_nisplus) {
5017c478bdstevel@tonic-gate		free_index(&item->searchSpec.obj.index);
5027c478bdstevel@tonic-gate		if (item->searchSpec.obj.name != NULL)
5037c478bdstevel@tonic-gate			free(item->searchSpec.obj.name);
5047c478bdstevel@tonic-gate		item->searchSpec.obj.name = NULL;
5057c478bdstevel@tonic-gate	} else if (item->type == mit_ldap) {
5067c478bdstevel@tonic-gate		if (item->searchSpec.triple.base != NULL)
5077c478bdstevel@tonic-gate			free(item->searchSpec.triple.base);
5087c478bdstevel@tonic-gate		item->searchSpec.triple.base = NULL;
5097c478bdstevel@tonic-gate		if (item->searchSpec.triple.attrs != NULL)
5107c478bdstevel@tonic-gate			free(item->searchSpec.triple.attrs);
5117c478bdstevel@tonic-gate		item->searchSpec.triple.attrs = NULL;
5127c478bdstevel@tonic-gate		if (item->searchSpec.triple.element != NULL) {
5137c478bdstevel@tonic-gate			free_mapping_element(
5147c478bdstevel@tonic-gate				item->searchSpec.triple.element);
5157c478bdstevel@tonic-gate			free(item->searchSpec.triple.element);
5167c478bdstevel@tonic-gate		}
5177c478bdstevel@tonic-gate		item->searchSpec.triple.element = NULL;
5187c478bdstevel@tonic-gate	}
5197c478bdstevel@tonic-gate	if (item->exItem != NULL) {
5207c478bdstevel@tonic-gate		free_mapping_item(item->exItem);
5217c478bdstevel@tonic-gate		free(item->exItem);
5227c478bdstevel@tonic-gate		item->exItem = 0;
5237c478bdstevel@tonic-gate	}
5247c478bdstevel@tonic-gate}
5257c478bdstevel@tonic-gate
5267c478bdstevel@tonic-gate/*
5277c478bdstevel@tonic-gate * FUNCTION:	free_mapping_format
5287c478bdstevel@tonic-gate *
5297c478bdstevel@tonic-gate *	Frees __nis_mapping_format_t
5307c478bdstevel@tonic-gate *
5317c478bdstevel@tonic-gate * INPUT:		__nis_mapping_format_t
5327c478bdstevel@tonic-gate */
5337c478bdstevel@tonic-gate
5347c478bdstevel@tonic-gatevoid
5357c478bdstevel@tonic-gatefree_mapping_format(__nis_mapping_format_t *fmt)
5367c478bdstevel@tonic-gate{
5377c478bdstevel@tonic-gate	__nis_mapping_format_t *f = fmt;
5387c478bdstevel@tonic-gate
5397c478bdstevel@tonic-gate	while (fmt->type != mmt_end) {
5407c478bdstevel@tonic-gate		switch (fmt->type) {
5417c478bdstevel@tonic-gate		    case mmt_item:
5427c478bdstevel@tonic-gate			break;
5437c478bdstevel@tonic-gate		    case mmt_string:
5447c478bdstevel@tonic-gate			if (fmt->match.string != NULL)
5457c478bdstevel@tonic-gate				free(fmt->match.string);
5467c478bdstevel@tonic-gate			fmt->match.string = NULL;
5477c478bdstevel@tonic-gate			break;
5487c478bdstevel@tonic-gate		    case mmt_single:
5497c478bdstevel@tonic-gate			if (fmt->match.single.lo != NULL)
5507c478bdstevel@tonic-gate				free(fmt->match.single.lo);
5517c478bdstevel@tonic-gate			fmt->match.single.lo = NULL;
5527c478bdstevel@tonic-gate			if (fmt->match.single.hi != NULL)
5537c478bdstevel@tonic-gate				free(fmt->match.single.hi);
5547c478bdstevel@tonic-gate			fmt->match.single.hi = NULL;
5557c478bdstevel@tonic-gate			break;
5567c478bdstevel@tonic-gate		    case mmt_limit:
5577c478bdstevel@tonic-gate			break;
5587c478bdstevel@tonic-gate		    case mmt_any:
5597c478bdstevel@tonic-gate			break;
5607c478bdstevel@tonic-gate		    case mmt_berstring:
5617c478bdstevel@tonic-gate		    case mmt_berstring_null:
5627c478bdstevel@tonic-gate			if (fmt->match.berString != NULL)
5637c478bdstevel@tonic-gate				free(fmt->match.berString);
5647c478bdstevel@tonic-gate			fmt->match.berString = NULL;
5657c478bdstevel@tonic-gate			break;
5667c478bdstevel@tonic-gate		    case mmt_begin:
5677c478bdstevel@tonic-gate			break;
5687c478bdstevel@tonic-gate		    case mmt_end:
5697c478bdstevel@tonic-gate			break;
5707c478bdstevel@tonic-gate		}
5717c478bdstevel@tonic-gate		fmt++;
5727c478bdstevel@tonic-gate	}
5737c478bdstevel@tonic-gate	free(f);
5747c478bdstevel@tonic-gate}
5757c478bdstevel@tonic-gate
5767c478bdstevel@tonic-gate/*
5777c478bdstevel@tonic-gate * FUNCTION:	free_mapping_sub_element
5787c478bdstevel@tonic-gate *
5797c478bdstevel@tonic-gate *	Frees __nis_mapping_sub_element_t
5807c478bdstevel@tonic-gate *
5817c478bdstevel@tonic-gate * INPUT:		__nis_mapping_sub_element_t
5827c478bdstevel@tonic-gate */
5837c478bdstevel@tonic-gate
5847c478bdstevel@tonic-gatevoid
5857c478bdstevel@tonic-gatefree_mapping_sub_element(__nis_mapping_sub_element_t *sub)
5867c478bdstevel@tonic-gate{
5877c478bdstevel@tonic-gate	int	i;
5887c478bdstevel@tonic-gate
5897c478bdstevel@tonic-gate	switch (sub->type) {
5907c478bdstevel@tonic-gate	    case me_item:
5917c478bdstevel@tonic-gate		free_mapping_item(&sub->element.item);
5927c478bdstevel@tonic-gate		break;
5937c478bdstevel@tonic-gate	    case me_print:
5947c478bdstevel@tonic-gate		if (sub->element.print.fmt != NULL)
5957c478bdstevel@tonic-gate			free_mapping_format(sub->element.print.fmt);
5967c478bdstevel@tonic-gate		sub->element.print.fmt = NULL;
5977c478bdstevel@tonic-gate		for (i = 0; i < sub->element.print.numItems; i++)
5987c478bdstevel@tonic-gate			free_mapping_item(&sub->element.print.item[i]);
5997c478bdstevel@tonic-gate		sub->element.print.numItems = 0;
6007c478bdstevel@tonic-gate		if (sub->element.print.item != NULL)
6017c478bdstevel@tonic-gate			free(sub->element.print.item);
6027c478bdstevel@tonic-gate		sub->element.print.item = NULL;
6037c478bdstevel@tonic-gate		break;
6047c478bdstevel@tonic-gate	    case me_split:
6057c478bdstevel@tonic-gate		free_mapping_item(&sub->element.split.item);
6067c478bdstevel@tonic-gate		break;
6077c478bdstevel@tonic-gate	    case me_extract:
6087c478bdstevel@tonic-gate		if (sub->element.extract.fmt != NULL)
6097c478bdstevel@tonic-gate			free_mapping_format(sub->element.extract.fmt);
6107c478bdstevel@tonic-gate		sub->element.extract.fmt = NULL;
6117c478bdstevel@tonic-gate		free_mapping_item(&sub->element.extract.item);
6127c478bdstevel@tonic-gate		break;
6137c478bdstevel@tonic-gate	}
6147c478bdstevel@tonic-gate}
6157c478bdstevel@tonic-gate
6167c478bdstevel@tonic-gate/*
6177c478bdstevel@tonic-gate * FUNCTION:	read_line
6187c478bdstevel@tonic-gate *
6197c478bdstevel@tonic-gate *	Gets next line in buffer - using '\' at end of line
6207c478bdstevel@tonic-gate *  to indicate continuation. Lines beginning with # are
6217c478bdstevel@tonic-gate *	ignored. start_line_num and start_line_num are
6227c478bdstevel@tonic-gate *	maintained to track the line number currently being
6237c478bdstevel@tonic-gate *	parsed.
6247c478bdstevel@tonic-gate *
6257c478bdstevel@tonic-gate * RETURN VALUE:	The number of characters read. 0 for
6267c478bdstevel@tonic-gate *                      eof, -1 for error
6277c478bdstevel@tonic-gate *
6287c478bdstevel@tonic-gate * INPUT:		file descriptor, buffer, and buffer size
6297c478bdstevel@tonic-gate */
6307c478bdstevel@tonic-gate
6317c478bdstevel@tonic-gateint
6327c478bdstevel@tonic-gateread_line(int fd, char *buffer, int buflen)
6337c478bdstevel@tonic-gate{
6347c478bdstevel@tonic-gate	int		linelen;
6357c478bdstevel@tonic-gate	int		rc;
6367c478bdstevel@tonic-gate	char		c;
6377c478bdstevel@tonic-gate	bool_t		skip_line	= FALSE;
6387c478bdstevel@tonic-gate	bool_t		begin_line	= TRUE;
6397c478bdstevel@tonic-gate	static bool_t	prev_cr		= FALSE;
6407c478bdstevel@tonic-gate
6417c478bdstevel@tonic-gate	start_line_num = cur_line_num;
6427c478bdstevel@tonic-gate	(void) memset(buffer, 0, buflen);
6437c478bdstevel@tonic-gate	for (; p_error == no_parse_error; ) {
6447c478bdstevel@tonic-gate		linelen = 0;
6457c478bdstevel@tonic-gate		while (linelen < buflen) {
6467c478bdstevel@tonic-gate			rc = read(fd, &c, 1);
6477c478bdstevel@tonic-gate			if (1 == rc) {
6487c478bdstevel@tonic-gate				if (c == '\n' || c == '\r') {
6497c478bdstevel@tonic-gate					if (c == '\n') {
6507c478bdstevel@tonic-gate						if (prev_cr) {
6517c478bdstevel@tonic-gate							prev_cr = FALSE;
6527c478bdstevel@tonic-gate							continue;
6537c478bdstevel@tonic-gate						} else {
6547c478bdstevel@tonic-gate							if (linelen == 0)
6557c478bdstevel@tonic-gate							    start_line_num =
6567c478bdstevel@tonic-gate								cur_line_num;
6577c478bdstevel@tonic-gate							else {
6587c478bdstevel@tonic-gate								if (
6597c478bdstevel@tonic-gate								is_string_ok(
6607c478bdstevel@tonic-gate								buffer,
6617c478bdstevel@tonic-gate								linelen)) {
6627c478bdstevel@tonic-gate								(void) memset(
6637c478bdstevel@tonic-gate								buffer, 0,
6647c478bdstevel@tonic-gate								linelen);
6657c478bdstevel@tonic-gate								linelen = 0;
6667c478bdstevel@tonic-gate								cur_line_num++;
6677c478bdstevel@tonic-gate								begin_line =
6687c478bdstevel@tonic-gate									TRUE;
6697c478bdstevel@tonic-gate								continue;
6707c478bdstevel@tonic-gate								}
6717c478bdstevel@tonic-gate							}
6727c478bdstevel@tonic-gate							cur_line_num++;
6737c478bdstevel@tonic-gate						}
6747c478bdstevel@tonic-gate						prev_cr = FALSE;
6757c478bdstevel@tonic-gate					} else {
6767c478bdstevel@tonic-gate						prev_cr = TRUE;
6777c478bdstevel@tonic-gate						if (linelen == 0)
6787c478bdstevel@tonic-gate						    start_line_num =
6797c478bdstevel@tonic-gate							cur_line_num;
6807c478bdstevel@tonic-gate						cur_line_num++;
6817c478bdstevel@tonic-gate					}
6827c478bdstevel@tonic-gate					if (skip_line) {
6837c478bdstevel@tonic-gate						skip_line = FALSE;
6847c478bdstevel@tonic-gate						if (linelen == 0)
6857c478bdstevel@tonic-gate						    start_line_num =
6867c478bdstevel@tonic-gate							cur_line_num;
6877c478bdstevel@tonic-gate					} else if (linelen > 0 &&
6887c478bdstevel@tonic-gate					    buffer[linelen - 1]
6897c478bdstevel@tonic-gate					    == ESCAPE_CHAR) {
6907c478bdstevel@tonic-gate						--linelen;
6917c478bdstevel@tonic-gate					} else if (linelen > 0) {
6927c478bdstevel@tonic-gate						buffer[linelen] = '\0';
6937c478bdstevel@tonic-gate						return (linelen);
6947c478bdstevel@tonic-gate					}
6957c478bdstevel@tonic-gate					begin_line = TRUE;
6967c478bdstevel@tonic-gate				} else {
6977c478bdstevel@tonic-gate					if (begin_line)
6987c478bdstevel@tonic-gate						skip_line = c == POUND_SIGN;
6997c478bdstevel@tonic-gate					begin_line = FALSE;
7007c478bdstevel@tonic-gate					if (!skip_line)
7017c478bdstevel@tonic-gate						buffer[linelen++] = c;
7027c478bdstevel@tonic-gate				}
7037c478bdstevel@tonic-gate			} else {
7047c478bdstevel@tonic-gate				if (linelen > 0 &&
7057c478bdstevel@tonic-gate				    buffer[linelen - 1] == ESCAPE_CHAR) {
7067c478bdstevel@tonic-gate					/* continuation on last line */
7077c478bdstevel@tonic-gate					p_error = parse_bad_continuation_error;
7087c478bdstevel@tonic-gate					return (-1);
7097c478bdstevel@tonic-gate				} else {
7107c478bdstevel@tonic-gate					buffer[linelen] = '\0';
7117c478bdstevel@tonic-gate					return (linelen);
7127c478bdstevel@tonic-gate				}
7137c478bdstevel@tonic-gate			}
7147c478bdstevel@tonic-gate		}
7157c478bdstevel@tonic-gate		p_error = parse_line_too_long;
7167c478bdstevel@tonic-gate	}
7177c478bdstevel@tonic-gate	return (-1);
7187c478bdstevel@tonic-gate}
7197c478bdstevel@tonic-gate
7207c478bdstevel@tonic-gate/*
7217c478bdstevel@tonic-gate * FUNCTION:	finish_parse
7227c478bdstevel@tonic-gate *
7237c478bdstevel@tonic-gate *	Adds any elements not configured, fully qualifies
7247c478bdstevel@tonic-gate *      names
7257c478bdstevel@tonic-gate *
7267c478bdstevel@tonic-gate * RETURN VALUE:	0 on success, -1 on failure
7277c478bdstevel@tonic-gate */
7287c478bdstevel@tonic-gate
7297c478bdstevel@tonic-gateint
7307c478bdstevel@tonic-gatefinish_parse(
7317c478bdstevel@tonic-gate	__nis_ldap_proxy_info	*proxy_info,
7327c478bdstevel@tonic-gate	__nis_table_mapping_t	**table_mapping)
7337c478bdstevel@tonic-gate{
7347c478bdstevel@tonic-gate	__nis_table_mapping_t	*t;
7357c478bdstevel@tonic-gate	__nis_table_mapping_t	*t1;
7367c478bdstevel@tonic-gate	__nis_table_mapping_t	*t2;
7377c478bdstevel@tonic-gate	__nis_table_mapping_t	*t_del		= NULL;
7387c478bdstevel@tonic-gate	int			i;
7397c478bdstevel@tonic-gate	int			j;
7407c478bdstevel@tonic-gate	int			k;
7417c478bdstevel@tonic-gate	__nis_object_dn_t	*objectDN;
7427c478bdstevel@tonic-gate	__nis_mapping_rlhs_t	*lhs;
7437c478bdstevel@tonic-gate	__nis_mapping_element_t	*e;
7447c478bdstevel@tonic-gate	char			*s;
7457c478bdstevel@tonic-gate	int			errnum;
7467c478bdstevel@tonic-gate
7477c478bdstevel@tonic-gate	/* set to default those values yet set */
7487c478bdstevel@tonic-gate	if (proxy_info->auth_method ==
7497c478bdstevel@tonic-gate	    (auth_method_t)NO_VALUE_SET) {
7507c478bdstevel@tonic-gate		p_error = parse_no_proxy_auth_error;
7517c478bdstevel@tonic-gate		report_error(NULL, NULL);
7527c478bdstevel@tonic-gate		return (-1);
7537c478bdstevel@tonic-gate	}
7547c478bdstevel@tonic-gate
7557c478bdstevel@tonic-gate	if (proxy_info->default_servers == NULL) {
7567c478bdstevel@tonic-gate		p_error = parse_no_ldap_server_error;
7577c478bdstevel@tonic-gate		report_error(NULL, NULL);
7587c478bdstevel@tonic-gate		return (-1);
7597c478bdstevel@tonic-gate	}
7607c478bdstevel@tonic-gate
7617c478bdstevel@tonic-gate	if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
7627c478bdstevel@tonic-gate		proxy_info->tls_method = no_tls;
7637c478bdstevel@tonic-gate	else if (proxy_info->tls_method == ssl_tls &&
7647c478bdstevel@tonic-gate			(proxy_info->tls_cert_db == NULL ||
7657c478bdstevel@tonic-gate			*proxy_info->tls_cert_db == '\0')) {
7667c478bdstevel@tonic-gate		p_error = parse_no_cert_db;
7677c478bdstevel@tonic-gate		report_error(NULL, NULL);
7687c478bdstevel@tonic-gate		return (-1);
7697c478bdstevel@tonic-gate	}
7707c478bdstevel@tonic-gate
7717c478bdstevel@tonic-gate	if (proxy_info->default_nis_domain == NULL)
7727c478bdstevel@tonic-gate		proxy_info->default_nis_domain =
7737c478bdstevel@tonic-gate			s_strdup(__nis_rpc_domain());
7747c478bdstevel@tonic-gate	else if (*proxy_info->default_nis_domain == '\0') {
7757c478bdstevel@tonic-gate		free(proxy_info->default_nis_domain);
7767c478bdstevel@tonic-gate		proxy_info->default_nis_domain =
7777c478bdstevel@tonic-gate			s_strdup(__nis_rpc_domain());
7787c478bdstevel@tonic-gate	}
7797c478bdstevel@tonic-gate	if (proxy_info->default_nis_domain != NULL)
7807c478bdstevel@tonic-gate		append_dot(&proxy_info->default_nis_domain);
7817c478bdstevel@tonic-gate
7827c478bdstevel@tonic-gate	if (proxy_info->tls_method == ssl_tls) {
7837c478bdstevel@tonic-gate		if ((errnum = ldapssl_client_init(
7847c478bdstevel@tonic-gate				proxy_info->tls_cert_db, NULL)) < 0) {
7857c478bdstevel@tonic-gate			p_error = parse_ldapssl_client_init_error;
7867c478bdstevel@tonic-gate			report_error(ldapssl_err2string(errnum), NULL);
7877c478bdstevel@tonic-gate			return (-1);
7887c478bdstevel@tonic-gate		}
7897c478bdstevel@tonic-gate	}
7907c478bdstevel@tonic-gate
7917c478bdstevel@tonic-gate	if (proxy_info->default_search_base == NULL)
7927c478bdstevel@tonic-gate	    proxy_info->default_search_base =
7937c478bdstevel@tonic-gate		get_default_ldap_base(proxy_info->default_nis_domain);
7947c478bdstevel@tonic-gate
7957c478bdstevel@tonic-gate	/* convert a relative dn to a fullly qualified dn */
7967c478bdstevel@tonic-gate	(void) make_full_dn(&proxy_info->proxy_dn,
7977c478bdstevel@tonic-gate		proxy_info->default_search_base);
7987c478bdstevel@tonic-gate
7997c478bdstevel@tonic-gate	if (p_error != no_parse_error) {
8007c478bdstevel@tonic-gate		report_error(NULL, NULL);
8017c478bdstevel@tonic-gate		return (-1);
8027c478bdstevel@tonic-gate	}
8037c478bdstevel@tonic-gate
8047c478bdstevel@tonic-gate	/*
8057c478bdstevel@tonic-gate	 * Create a list of potential delete mappings
8067c478bdstevel@tonic-gate	 * those have NULL objectDNs, but badly also rules
8077c478bdstevel@tonic-gate	 * that are missing object dn's will be included.
8087c478bdstevel@tonic-gate	 * We will use the ttl field to determine if the
8097c478bdstevel@tonic-gate	 * delete rule is actually used
8107c478bdstevel@tonic-gate	 */
8117c478bdstevel@tonic-gate	t2 = NULL;
8127c478bdstevel@tonic-gate	for (t = *table_mapping; t != NULL; t = t1) {
8137c478bdstevel@tonic-gate		t1 = t->next;
8147c478bdstevel@tonic-gate		if (t->objectDN == NULL) {
8157c478bdstevel@tonic-gate			if (t2 == NULL)
8167c478bdstevel@tonic-gate				*table_mapping = t1;
8177c478bdstevel@tonic-gate			else
8187c478bdstevel@tonic-gate				t2->next = t1;
8197c478bdstevel@tonic-gate			t->next = t_del;
8207c478bdstevel@tonic-gate			t_del = t;
8217c478bdstevel@tonic-gate			t->ttl = 0;
8227c478bdstevel@tonic-gate		} else
8237c478bdstevel@tonic-gate			t2 = t;
8247c478bdstevel@tonic-gate	}
8257c478bdstevel@tonic-gate
8267c478bdstevel@tonic-gate	for (t = *table_mapping; t != NULL; t = t->next) {
8277c478bdstevel@tonic-gate	    objectDN = t->objectDN;
8287c478bdstevel@tonic-gate	    while (objectDN != NULL) {
8297c478bdstevel@tonic-gate		if (objectDN->dbIdName != NULL) {
8307c478bdstevel@tonic-gate			s = objectDN->dbIdName;
8317c478bdstevel@tonic-gate			t1 = find_table_mapping(s, strlen(s), t_del);
8327c478bdstevel@tonic-gate			if (t1 == NULL) {
8337c478bdstevel@tonic-gate				p_error = parse_no_db_del_mapping_rule;
8347c478bdstevel@tonic-gate				report_error2(objectDN->dbIdName, t->dbId);
8357c478bdstevel@tonic-gate				return (-1);
8367c478bdstevel@tonic-gate			} else if (t1->objName != NULL ||
8377c478bdstevel@tonic-gate			    t1->numRulesToLDAP == 0 ||
8387c478bdstevel@tonic-gate			    t1->numRulesFromLDAP != 0) {
8397c478bdstevel@tonic-gate				p_error = parse_invalid_db_del_mapping_rule;
8407c478bdstevel@tonic-gate				report_error(t1->dbId, NULL);
8417c478bdstevel@tonic-gate				return (-1);
8427c478bdstevel@tonic-gate			}
8437c478bdstevel@tonic-gate			objectDN->dbId =
8447c478bdstevel@tonic-gate				dup_mapping_rules(t1->ruleToLDAP,
8457c478bdstevel@tonic-gate					t1->numRulesToLDAP);
8467c478bdstevel@tonic-gate			if (objectDN->dbId == NULL) {
8477c478bdstevel@tonic-gate				break;
8487c478bdstevel@tonic-gate			}
8497c478bdstevel@tonic-gate			objectDN->numDbIds = t1->numRulesToLDAP;
8507c478bdstevel@tonic-gate			t1->ttl++;
8517c478bdstevel@tonic-gate		}
8527c478bdstevel@tonic-gate		objectDN = objectDN->next;
8537c478bdstevel@tonic-gate	    }
8547c478bdstevel@tonic-gate	}
8557c478bdstevel@tonic-gate
8567c478bdstevel@tonic-gate	for (t = t_del; t != NULL; t = t1) {
8577c478bdstevel@tonic-gate		t1 = t->next;
8587c478bdstevel@tonic-gate		if (t->ttl == 0) {
8597c478bdstevel@tonic-gate			p_error = parse_no_object_dn;
8607c478bdstevel@tonic-gate			report_error(t->dbId, NULL);
8617c478bdstevel@tonic-gate		}
8627c478bdstevel@tonic-gate		free_table_mapping(t);
8637c478bdstevel@tonic-gate	}
8647c478bdstevel@tonic-gate
8657c478bdstevel@tonic-gate	if (p_error != no_parse_error)
8667c478bdstevel@tonic-gate		return (-1);
8677c478bdstevel@tonic-gate
8687c478bdstevel@tonic-gate	/* set to default those table mapping values yet set */
8697c478bdstevel@tonic-gate	for (t = *table_mapping; t != NULL; t = t->next) {
8707c478bdstevel@tonic-gate		if (t->objName == 0) {
8717c478bdstevel@tonic-gate			p_error = parse_no_object_dn;
8727c478bdstevel@tonic-gate			report_error(t->dbId, NULL);
8737c478bdstevel@tonic-gate			return (-1);
8747c478bdstevel@tonic-gate		}
8757c478bdstevel@tonic-gate		if (!yp2ldap) {
8767c478bdstevel@tonic-gate			if (!add_domain(&t->objName,
8777c478bdstevel@tonic-gate					proxy_info->default_nis_domain)) {
8787c478bdstevel@tonic-gate				report_error(NULL, NULL);
8797c478bdstevel@tonic-gate				return (-1);
8807c478bdstevel@tonic-gate			}
8817c478bdstevel@tonic-gate		}
8827c478bdstevel@tonic-gate		if (t->initTtlHi == (time_t)NO_VALUE_SET)
8837c478bdstevel@tonic-gate			t->initTtlHi = DEFAULT_TTL_HIGH;
8847c478bdstevel@tonic-gate		if (t->initTtlLo == (time_t)NO_VALUE_SET)
8857c478bdstevel@tonic-gate			t->initTtlLo = DEFAULT_TTL_LOW;
8867c478bdstevel@tonic-gate		if (t->ttl == (time_t)NO_VALUE_SET)
8877c478bdstevel@tonic-gate			t->ttl = DEFAULT_TTL;
8887c478bdstevel@tonic-gate		objectDN = t->objectDN;
8897c478bdstevel@tonic-gate
8907c478bdstevel@tonic-gate		/* fixup relative dn's */
8917c478bdstevel@tonic-gate		while (objectDN != NULL) {
8927c478bdstevel@tonic-gate			if (!yp2ldap) {
8937c478bdstevel@tonic-gate				if (!make_full_dn(&objectDN->read.base,
8947c478bdstevel@tonic-gate					proxy_info->default_search_base))
8957c478bdstevel@tonic-gate						break;
8967c478bdstevel@tonic-gate			}
8977c478bdstevel@tonic-gate			if (objectDN->write.scope != LDAP_SCOPE_UNKNOWN) {
8987c478bdstevel@tonic-gate				if (objectDN->write.base != NULL &&
8997c478bdstevel@tonic-gate					!make_full_dn(&objectDN->write.base,
9007c478bdstevel@tonic-gate					proxy_info->default_search_base))
9017c478bdstevel@tonic-gate						break;
9027c478bdstevel@tonic-gate				if (objectDN->write.base == NULL) {
9037c478bdstevel@tonic-gate				    objectDN->write.base =
9047c478bdstevel@tonic-gate					s_strdup(objectDN->read.base);
9057c478bdstevel@tonic-gate				    if (objectDN->write.base == NULL)
9067c478bdstevel@tonic-gate					break;
9077c478bdstevel@tonic-gate				}
9087c478bdstevel@tonic-gate			}
9097c478bdstevel@tonic-gate			objectDN = objectDN->next;
9107c478bdstevel@tonic-gate		}
9117c478bdstevel@tonic-gate
9127c478bdstevel@tonic-gate		if (p_error != no_parse_error) {
9137c478bdstevel@tonic-gate			report_error(NULL, NULL);
9147c478bdstevel@tonic-gate			return (-1);
9157c478bdstevel@tonic-gate		}
9167c478bdstevel@tonic-gate
9177c478bdstevel@tonic-gate		/* Check for ruleToLDAP with no rhs */
9187c478bdstevel@tonic-gate		for (i = 0; i < t->numRulesToLDAP; i++) {
9197c478bdstevel@tonic-gate		    if (t->ruleToLDAP[i]->rhs.numElements == 0) {
9207c478bdstevel@tonic-gate			p_error = parse_unexpected_data_end_rule;
9217c478bdstevel@tonic-gate			report_error(t->dbId, NULL);
9227c478bdstevel@tonic-gate			return (-1);
9237c478bdstevel@tonic-gate		    }
9247c478bdstevel@tonic-gate		}
9257c478bdstevel@tonic-gate
9267c478bdstevel@tonic-gate		/* populate cols field */
9277c478bdstevel@tonic-gate		if (!yp2ldap) {
9287c478bdstevel@tonic-gate			for (i = 0; i < t->numRulesFromLDAP; i++) {
9297c478bdstevel@tonic-gate				lhs = &t->ruleFromLDAP[i]->lhs;
9307c478bdstevel@tonic-gate				for (j = 0; j < lhs->numElements; j++) {
9317c478bdstevel@tonic-gate					e = &lhs->element[j];
9327c478bdstevel@tonic-gate					switch (e->type) {
9337c478bdstevel@tonic-gate						case me_item:
9347c478bdstevel@tonic-gate						if (!add_column(t,
9357c478bdstevel@tonic-gate						e->element.item.name)) {
9367c478bdstevel@tonic-gate							report_error(
9377c478bdstevel@tonic-gate							NULL, NULL);
9387c478bdstevel@tonic-gate							return (-1);
9397c478bdstevel@tonic-gate						}
9407c478bdstevel@tonic-gate						break;
9417c478bdstevel@tonic-gate						case me_match:
9427c478bdstevel@tonic-gate						for (k = 0;
9437c478bdstevel@tonic-gate						k < e->element.match.numItems;
9447c478bdstevel@tonic-gate						k++)
9457c478bdstevel@tonic-gate							if (!add_column(t,
9467c478bdstevel@tonic-gate					e->element.match.item[k].name)) {
9477c478bdstevel@tonic-gate								report_error(
9487c478bdstevel@tonic-gate								NULL, NULL);
9497c478bdstevel@tonic-gate								return (-1);
9507c478bdstevel@tonic-gate							}
9517c478bdstevel@tonic-gate						break;
9527c478bdstevel@tonic-gate					}
9537c478bdstevel@tonic-gate				}
9547c478bdstevel@tonic-gate			}
9557c478bdstevel@tonic-gate		}
9567c478bdstevel@tonic-gate	}
9577c478bdstevel@tonic-gate	return (0);
9587c478bdstevel@tonic-gate}
9597c478bdstevel@tonic-gate
9607c478bdstevel@tonic-gate/*
9617c478bdstevel@tonic-gate * FUNCTION:	set_default_values
9627c478bdstevel@tonic-gate *
9637c478bdstevel@tonic-gate *	Sets unconfigured values to their default value
9647c478bdstevel@tonic-gate */
9657c478bdstevel@tonic-gate
9667c478bdstevel@tonic-gatevoid
9677c478bdstevel@tonic-gateset_default_values(__nis_ldap_proxy_info *proxy_info,
9687c478bdstevel@tonic-gate    __nis_config_t *config_info, __nisdb_table_mapping_t *table_info)
9697c478bdstevel@tonic-gate{
9707c478bdstevel@tonic-gate	if (proxy_info->bind_timeout.tv_sec == (time_t)NO_VALUE_SET)
9717c478bdstevel@tonic-gate		proxy_info->bind_timeout.tv_sec = DEFAULT_BIND_TIMEOUT;
9727c478bdstevel@tonic-gate	if (proxy_info->search_timeout.tv_sec == (time_t)NO_VALUE_SET)
9737c478bdstevel@tonic-gate		proxy_info->search_timeout.tv_sec =
9747c478bdstevel@tonic-gate			(yp2ldap)?DEFAULT_YP_SEARCH_TIMEOUT:
9757c478bdstevel@tonic-gate				DEFAULT_SEARCH_TIMEOUT;
9767c478bdstevel@tonic-gate	if (proxy_info->modify_timeout.tv_sec == (time_t)NO_VALUE_SET)
9777c478bdstevel@tonic-gate		proxy_info->modify_timeout.tv_sec = DEFAULT_MODIFY_TIMEOUT;
9787c478bdstevel@tonic-gate	if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
9797c478bdstevel@tonic-gate		proxy_info->add_timeout.tv_sec = DEFAULT_ADD_TIMEOUT;
9807c478bdstevel@tonic-gate	if (proxy_info->delete_timeout.tv_sec == (time_t)NO_VALUE_SET)
9817c478bdstevel@tonic-gate		proxy_info->delete_timeout.tv_sec = DEFAULT_DELETE_TIMEOUT;
9827c478bdstevel@tonic-gate
9837c478bdstevel@tonic-gate	if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
9847c478bdstevel@tonic-gate		proxy_info->search_time_limit = DEFAULT_SEARCH_TIME_LIMIT;
9857c478bdstevel@tonic-gate	if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
9867c478bdstevel@tonic-gate		proxy_info->search_size_limit = DEFAULT_SEARCH_SIZE_LIMIT;
9877c478bdstevel@tonic-gate
9887c478bdstevel@tonic-gate	if (proxy_info->follow_referral == (follow_referral_t)NO_VALUE_SET)
9897c478bdstevel@tonic-gate		proxy_info->follow_referral = no_follow;
9907c478bdstevel@tonic-gate
9917c478bdstevel@tonic-gate	switch (config_info->initialUpdate) {
9927c478bdstevel@tonic-gate		case (__nis_initial_update_t)NO_VALUE_SET:
9937c478bdstevel@tonic-gate		case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION:
9947c478bdstevel@tonic-gate		case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION:
9957c478bdstevel@tonic-gate			config_info->initialUpdate = ini_none;
9967c478bdstevel@tonic-gate			break;
9977c478bdstevel@tonic-gate		case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE:
9987c478bdstevel@tonic-gate			config_info->initialUpdate = from_ldap;
9997c478bdstevel@tonic-gate			break;
10007c478bdstevel@tonic-gate		case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE:
10017c478bdstevel@tonic-gate			config_info->initialUpdate = to_ldap;
10027c478bdstevel@tonic-gate			break;
10037c478bdstevel@tonic-gate	}
10047c478bdstevel@tonic-gate	if (config_info->threadCreationError ==
10057c478bdstevel@tonic-gate	    (__nis_thread_creation_error_t)NO_VALUE_SET)
10067c478bdstevel@tonic-gate		config_info->threadCreationError = pass_error;
10077c478bdstevel@tonic-gate	if (config_info->threadCreationErrorTimeout.attempts == NO_VALUE_SET)
10087c478bdstevel@tonic-gate		config_info->threadCreationErrorTimeout.attempts =
10097c478bdstevel@tonic-gate			DEFAULT_THREAD_ERROR_ATTEMPTS;
10107c478bdstevel@tonic-gate	if (config_info->threadCreationErrorTimeout.timeout ==
10117c478bdstevel@tonic-gate			(time_t)NO_VALUE_SET)
10127c478bdstevel@tonic-gate		config_info->threadCreationErrorTimeout.timeout =
10137c478bdstevel@tonic-gate			DEFAULT_THREAD_ERROR_TIME_OUT;
10147c478bdstevel@tonic-gate	if (config_info->dumpError ==
10157c478bdstevel@tonic-gate	    (__nis_dump_error_t)NO_VALUE_SET)
10167c478bdstevel@tonic-gate		config_info->dumpError = de_retry;
10177c478bdstevel@tonic-gate	if (config_info->dumpErrorTimeout.attempts == NO_VALUE_SET)
10187c478bdstevel@tonic-gate		config_info->dumpErrorTimeout.attempts =
10197c478bdstevel@tonic-gate			DEFAULT_DUMP_ERROR_ATTEMPTS;
10207c478bdstevel@tonic-gate	if (config_info->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET)
10217c478bdstevel@tonic-gate		config_info->dumpErrorTimeout.timeout =
10227c478bdstevel@tonic-gate			DEFAULT_DUMP_ERROR_TIME_OUT;
10237c478bdstevel@tonic-gate	if (config_info->resyncService ==
10247c478bdstevel@tonic-gate	    (__nis_resync_service_t)NO_VALUE_SET)
10257c478bdstevel@tonic-gate		config_info->resyncService = from_copy;
10267c478bdstevel@tonic-gate	if (config_info->updateBatching ==
10277c478bdstevel@tonic-gate	    (__nis_update_batching_t)NO_VALUE_SET)
10287c478bdstevel@tonic-gate		config_info->updateBatching = accumulate;
10297c478bdstevel@tonic-gate	if (config_info->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET)
10307c478bdstevel@tonic-gate		config_info->updateBatchingTimeout.timeout =
10317c478bdstevel@tonic-gate			DEFAULT_BATCHING_TIME_OUT;
10327c478bdstevel@tonic-gate	if (config_info->numberOfServiceThreads == (int)NO_VALUE_SET)
10337c478bdstevel@tonic-gate		config_info->numberOfServiceThreads =
10347c478bdstevel@tonic-gate			DEFAULT_NUMBER_OF_THREADS;
10357c478bdstevel@tonic-gate	if (config_info->emulate_yp == (int)NO_VALUE_SET)
10367c478bdstevel@tonic-gate		config_info->emulate_yp =
10377c478bdstevel@tonic-gate			DEFAULT_YP_EMULATION;
10387c478bdstevel@tonic-gate	if (config_info->maxRPCRecordSize == (int)NO_VALUE_SET)
10397c478bdstevel@tonic-gate		config_info->maxRPCRecordSize = RPC_MAXDATASIZE;
10407c478bdstevel@tonic-gate
10417c478bdstevel@tonic-gate	if (table_info->retrieveError ==
10427c478bdstevel@tonic-gate	    (__nis_retrieve_error_t)NO_VALUE_SET)
10437c478bdstevel@tonic-gate		table_info->retrieveError = use_cached;
10447c478bdstevel@tonic-gate	if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
10457c478bdstevel@tonic-gate		table_info->retrieveErrorRetry.attempts =
10467c478bdstevel@tonic-gate			DEFAULT_RETRIEVE_ERROR_ATTEMPTS;
10477c478bdstevel@tonic-gate	if (table_info->retrieveErrorRetry.timeout == (time_t)NO_VALUE_SET)
10487c478bdstevel@tonic-gate		table_info->retrieveErrorRetry.timeout =
10497c478bdstevel@tonic-gate			DEFAULT_RETRIEVE_ERROR_TIME_OUT;
10507c478bdstevel@tonic-gate	if (table_info->storeError ==
10517c478bdstevel@tonic-gate	    (__nis_store_error_t)NO_VALUE_SET)
10527c478bdstevel@tonic-gate		table_info->storeError = sto_retry;
10537c478bdstevel@tonic-gate	if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
10547c478bdstevel@tonic-gate		table_info->storeErrorRetry.attempts =
10557c478bdstevel@tonic-gate			DEFAULT_STORE_ERROR_ATTEMPTS;
10567c478bdstevel@tonic-gate	if (table_info->storeErrorRetry.timeout == (time_t)NO_VALUE_SET)
10577c478bdstevel@tonic-gate		table_info->storeErrorRetry.timeout =
10587c478bdstevel@tonic-gate			DEFAULT_STORE_ERROR_TIME_OUT;
10597c478bdstevel@tonic-gate	if (table_info->refreshError ==
10607c478bdstevel@tonic-gate	    (__nis_refresh_error_t)NO_VALUE_SET)
10617c478bdstevel@tonic-gate		table_info->refreshError = continue_using;
10627c478bdstevel@tonic-gate	if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
10637c478bdstevel@tonic-gate		table_info->refreshErrorRetry.attempts =
10647c478bdstevel@tonic-gate			DEFAULT_REFRESH_ERROR_ATTEMPTS;
10657c478bdstevel@tonic-gate	if (table_info->refreshErrorRetry.timeout == (time_t)NO_VALUE_SET)
10667c478bdstevel@tonic-gate		table_info->refreshErrorRetry.timeout =
10677c478bdstevel@tonic-gate			DEFAULT_REFRESH_ERROR_TIME_OUT;
10687c478bdstevel@tonic-gate	if (table_info->matchFetch ==
10697c478bdstevel@tonic-gate	    (__nis_match_fetch_t)NO_VALUE_SET)
10707c478bdstevel@tonic-gate		table_info->matchFetch = no_match_only;
10717c478bdstevel@tonic-gate}
10727c478bdstevel@tonic-gate
10737c478bdstevel@tonic-gate__nis_table_mapping_t *
10747c478bdstevel@tonic-gatefind_table_mapping(const char *s, int len, __nis_table_mapping_t *table_mapping)
10757c478bdstevel@tonic-gate{
10767c478bdstevel@tonic-gate	__nis_table_mapping_t *t;
10777c478bdstevel@tonic-gate
10787c478bdstevel@tonic-gate	for (t = table_mapping; t != NULL; t = t->next)
10797c478bdstevel@tonic-gate		if (strlen(t->dbId) == len &&
10807c478bdstevel@tonic-gate		    strncasecmp(t->dbId, s, len) == 0)
10817c478bdstevel@tonic-gate			break;
10827c478bdstevel@tonic-gate	return (t);
10837c478bdstevel@tonic-gate}
10847c478bdstevel@tonic-gate
10857c478bdstevel@tonic-gatevoid
10867c478bdstevel@tonic-gateappend_dot(char **str)
10877c478bdstevel@tonic-gate{
10887c478bdstevel@tonic-gate	char	*s	= *str;
10897c478bdstevel@tonic-gate	int	len	= strlen(s);
10907c478bdstevel@tonic-gate
10917c478bdstevel@tonic-gate	if (len == 0 || s[len - 1] != PERIOD_CHAR) {
10927c478bdstevel@tonic-gate		s = s_realloc(s, len + 2);
10937c478bdstevel@tonic-gate		if (s != NULL) {
10947c478bdstevel@tonic-gate			s[len] = PERIOD_CHAR;
10957c478bdstevel@tonic-gate			s[len+1] = '\0';
10967c478bdstevel@tonic-gate			*str = s;
10977c478bdstevel@tonic-gate		}
10987c478bdstevel@tonic-gate	}
10997c478bdstevel@tonic-gate}
11007c478bdstevel@tonic-gate
11017c478bdstevel@tonic-gatevoid
11027c478bdstevel@tonic-gateappend_comma(char **str)
11037c478bdstevel@tonic-gate{
11047c478bdstevel@tonic-gate
11057c478bdstevel@tonic-gate	char    *s  = *str;
11067c478bdstevel@tonic-gate	int len = strlen(s);
11077c478bdstevel@tonic-gate
11087c478bdstevel@tonic-gate	if (len == 0 || s[len - 1] != COMMA_CHAR) {
11097c478bdstevel@tonic-gate		s = s_realloc(s, len + 2);
11107c478bdstevel@tonic-gate		if (s != NULL) {
11117c478bdstevel@tonic-gate			s[len] = COMMA_CHAR;
11127c478bdstevel@tonic-gate			s[len+1] = '\0';
11137c478bdstevel@tonic-gate			*str = s;
11147c478bdstevel@tonic-gate		}
11157c478bdstevel@tonic-gate	}
11167c478bdstevel@tonic-gate}
11177c478bdstevel@tonic-gate
11187c478bdstevel@tonic-gate/*
11197c478bdstevel@tonic-gate * FUNCTION:	make_full_dn
11207c478bdstevel@tonic-gate *
11217c478bdstevel@tonic-gate *	Appends the base dn if a relative ldap dn
11227c478bdstevel@tonic-gate *	(invoked only for LDAP write cycle)
11237c478bdstevel@tonic-gate *
11247c478bdstevel@tonic-gate * RETURN VALUE:	FALSE if error
11257c478bdstevel@tonic-gate *			TRUE if __nis_index_t returned
11267c478bdstevel@tonic-gate *
11277c478bdstevel@tonic-gate * INPUT:		the relative dn and ldap base
11287c478bdstevel@tonic-gate */
11297c478bdstevel@tonic-gate
11307c478bdstevel@tonic-gatebool_t
11317c478bdstevel@tonic-gatemake_full_dn(char **dn, const char *base)
11327c478bdstevel@tonic-gate{
11337c478bdstevel@tonic-gate	int len;
11347c478bdstevel@tonic-gate	int len1;
11357c478bdstevel@tonic-gate
11367c478bdstevel@tonic-gate	if (*dn == NULL) {
11377c478bdstevel@tonic-gate		*dn = s_strdup(base);
11387c478bdstevel@tonic-gate	} else {
11397c478bdstevel@tonic-gate		len = strlen(*dn);
11407c478bdstevel@tonic-gate		if (len > 0 && (*dn)[len-1] == COMMA_CHAR) {
11417c478bdstevel@tonic-gate			len1 = strlen(base) + 1;
11427c478bdstevel@tonic-gate			*dn = s_realloc(*dn, len + len1);
11437c478bdstevel@tonic-gate			if (*dn != NULL)
11447c478bdstevel@tonic-gate				(void) strcpy(*dn + len, base);
11457c478bdstevel@tonic-gate		}
11467c478bdstevel@tonic-gate	}
11477c478bdstevel@tonic-gate	return (*dn != NULL);
11487c478bdstevel@tonic-gate}
11497c478bdstevel@tonic-gate
11507c478bdstevel@tonic-gate/*
11517c478bdstevel@tonic-gate * FUNCTION:	make_fqdn
11527c478bdstevel@tonic-gate *
11537c478bdstevel@tonic-gate *	Appends the base dn if a relative ldap dn
11547c478bdstevel@tonic-gate *	(invoked only for LDAP read cycle)
11557c478bdstevel@tonic-gate *
11567c478bdstevel@tonic-gate * RETURN VALUE:	FALSE if error
11577c478bdstevel@tonic-gate *			TRUE if success
11587c478bdstevel@tonic-gate *
11597c478bdstevel@tonic-gate * INPUT:		the relative dn and ldap base
11607c478bdstevel@tonic-gate */
11617c478bdstevel@tonic-gatebool_t
11627c478bdstevel@tonic-gatemake_fqdn(__nis_object_dn_t *dn, const char *base)
11637c478bdstevel@tonic-gate{
11647c478bdstevel@tonic-gate	int len;
11657c478bdstevel@tonic-gate	int len1;
11667c478bdstevel@tonic-gate
11677c478bdstevel@tonic-gate	if (dn == NULL) {
11687c478bdstevel@tonic-gate		return (FALSE);
11697c478bdstevel@tonic-gate	} else {
11707c478bdstevel@tonic-gate		while (dn != NULL && dn->read.base != NULL) {
11717c478bdstevel@tonic-gate			len = strlen(dn->read.base);
11727c478bdstevel@tonic-gate			if (len > 0 && (dn->read.base)[len-1] == COMMA_CHAR) {
11737c478bdstevel@tonic-gate				len1 = strlen(base) + 1;
11747c478bdstevel@tonic-gate				dn->read.base =
11757c478bdstevel@tonic-gate					s_realloc(dn->read.base, len + len1);
11767c478bdstevel@tonic-gate				if (dn->read.base != NULL)
11777c478bdstevel@tonic-gate					(void) strlcpy(dn->read.base + len,
11787c478bdstevel@tonic-gate							base, len1);
11797c478bdstevel@tonic-gate				else
11807c478bdstevel@tonic-gate					return (FALSE);
11817c478bdstevel@tonic-gate			}
11827c478bdstevel@tonic-gate			dn = dn->next;
11837c478bdstevel@tonic-gate		}
11847c478bdstevel@tonic-gate	}
11857c478bdstevel@tonic-gate	return (TRUE);
11867c478bdstevel@tonic-gate}
11877c478bdstevel@tonic-gate
11887c478bdstevel@tonic-gate/*
11897c478bdstevel@tonic-gate * FUNCTION:	get_default_ldap_base
11907c478bdstevel@tonic-gate *
11917c478bdstevel@tonic-gate *	Gets the default LDAP search base from the
11927c478bdstevel@tonic-gate *	nis+ default domain
11937c478bdstevel@tonic-gate *
11947c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
11957c478bdstevel@tonic-gate *			the default base
11967c478bdstevel@tonic-gate *
11977c478bdstevel@tonic-gate * INPUT:		the nis domain
11987c478bdstevel@tonic-gate */
11997c478bdstevel@tonic-gate
12007c478bdstevel@tonic-gatechar *
12017c478bdstevel@tonic-gateget_default_ldap_base(const char *domain)
12027c478bdstevel@tonic-gate{
12037c478bdstevel@tonic-gate
12047c478bdstevel@tonic-gate	int		len	= strlen(domain);
12057c478bdstevel@tonic-gate	int		i;
12067c478bdstevel@tonic-gate	int		count	= len + 4;
12077c478bdstevel@tonic-gate	char		*base;
12087c478bdstevel@tonic-gate
12097c478bdstevel@tonic-gate	for (i = 0; i < len - 1; i++)
12107c478bdstevel@tonic-gate		if (domain[i] == PERIOD_CHAR)
12117c478bdstevel@tonic-gate			count += 4;
12127c478bdstevel@tonic-gate	if ((base = malloc(count)) == NULL) {
12137c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
12147c478bdstevel@tonic-gate	} else {
12157c478bdstevel@tonic-gate		(void) strcpy(base, "dc=");
12167c478bdstevel@tonic-gate		count = 3;
12177c478bdstevel@tonic-gate		for (i = 0; i < len - 1; i++) {
12187c478bdstevel@tonic-gate			if (domain[i] == PERIOD_CHAR) {
12197c478bdstevel@tonic-gate				(void) strcpy(base + count, ",dc=");
12207c478bdstevel@tonic-gate				count += 4;
12217c478bdstevel@tonic-gate			} else {
12227c478bdstevel@tonic-gate				base[count++] = domain[i];
12237c478bdstevel@tonic-gate			}
12247c478bdstevel@tonic-gate		}
12257c478bdstevel@tonic-gate		base[count] = '\0';
12267c478bdstevel@tonic-gate	}
12277c478bdstevel@tonic-gate	return (base);
12287c478bdstevel@tonic-gate}
12297c478bdstevel@tonic-gate
12307c478bdstevel@tonic-gate/*
12317c478bdstevel@tonic-gate * FUNCTION:	add_domain
12327c478bdstevel@tonic-gate *
12337c478bdstevel@tonic-gate *	Appends the base domain if a relative object name
12347c478bdstevel@tonic-gate *
12357c478bdstevel@tonic-gate * RETURN VALUE:	FALSE if error
12367c478bdstevel@tonic-gate *			TRUE if OK
12377c478bdstevel@tonic-gate *
12387c478bdstevel@tonic-gate * INPUT:		the relative object name and base domain
12397c478bdstevel@tonic-gate *			name
12407c478bdstevel@tonic-gate */
12417c478bdstevel@tonic-gate
12427c478bdstevel@tonic-gatebool_t
12437c478bdstevel@tonic-gateadd_domain(char **objName, const char *domain)
12447c478bdstevel@tonic-gate{
12457c478bdstevel@tonic-gate	int	len;
12467c478bdstevel@tonic-gate	int	len1;
12477c478bdstevel@tonic-gate	bool_t	trailing_dot;
12487c478bdstevel@tonic-gate	char	*obj_name;
12497c478bdstevel@tonic-gate
12507c478bdstevel@tonic-gate	if (domain == NULL || *objName == NULL) {
12517c478bdstevel@tonic-gate		p_error = parse_internal_error;
12527c478bdstevel@tonic-gate		return (FALSE);
12537c478bdstevel@tonic-gate	}
12547c478bdstevel@tonic-gate	len1 = strlen(domain);
12557c478bdstevel@tonic-gate	trailing_dot = (len1 > 0 && domain[len1 - 1] == PERIOD_CHAR) ?
12567c478bdstevel@tonic-gate		0 : 1;
12577c478bdstevel@tonic-gate	len = strlen(*objName);
12587c478bdstevel@tonic-gate	if (len == 0 || (*objName)[len - 1] != PERIOD_CHAR) {
12597c478bdstevel@tonic-gate		obj_name = s_realloc(*objName,
12607c478bdstevel@tonic-gate			len + len1 + 2 + trailing_dot);
12617c478bdstevel@tonic-gate		if (obj_name != NULL) {
12627c478bdstevel@tonic-gate			obj_name[len++] = PERIOD_CHAR;
12637c478bdstevel@tonic-gate			(void) strcpy(obj_name + len, domain);
12647c478bdstevel@tonic-gate			if (trailing_dot != 0) {
12657c478bdstevel@tonic-gate				obj_name[len + len1] = PERIOD_CHAR;
12667c478bdstevel@tonic-gate				obj_name[len + len1 + 1] = '\0';
12677c478bdstevel@tonic-gate			}
12687c478bdstevel@tonic-gate			*objName = obj_name;
12697c478bdstevel@tonic-gate		}
12707c478bdstevel@tonic-gate	}
12717c478bdstevel@tonic-gate
12727c478bdstevel@tonic-gate	return (*objName != NULL);
12737c478bdstevel@tonic-gate}
12747c478bdstevel@tonic-gate
12757c478bdstevel@tonic-gatebool_t
12767c478bdstevel@tonic-gatedup_index(__nis_index_t *in, __nis_index_t *out)
12777c478bdstevel@tonic-gate{
12787c478bdstevel@tonic-gate	int i;
12797c478bdstevel@tonic-gate	int j;
12807c478bdstevel@tonic-gate
12817c478bdstevel@tonic-gate	out->name = (char **)s_calloc(in->numIndexes, sizeof (char *));
12827c478bdstevel@tonic-gate	if (out->name == NULL)
12837c478bdstevel@tonic-gate		return (FALSE);
12847c478bdstevel@tonic-gate	out->value = (__nis_mapping_format_t **)
12857c478bdstevel@tonic-gate		s_calloc(in->numIndexes, sizeof (__nis_mapping_format_t *));
12867c478bdstevel@tonic-gate	if (out->value == NULL) {
12877c478bdstevel@tonic-gate		free(out->name);
12887c478bdstevel@tonic-gate		out->name = NULL;
12897c478bdstevel@tonic-gate		return (FALSE);
12907c478bdstevel@tonic-gate	}
12917c478bdstevel@tonic-gate
12927c478bdstevel@tonic-gate	for (i = 0; i < in->numIndexes; i++) {
12937c478bdstevel@tonic-gate		out->name[i] = s_strdup(in->name[i]);
12947c478bdstevel@tonic-gate		if (out->name[i] == NULL)
12957c478bdstevel@tonic-gate			break;
12967c478bdstevel@tonic-gate		out->value[i] = dup_format_mapping(in->value[i]);
12977c478bdstevel@tonic-gate		if (out->value[i] == NULL)
12987c478bdstevel@tonic-gate			break;
12997c478bdstevel@tonic-gate	}
13007c478bdstevel@tonic-gate	if (i < in->numIndexes) {
13017c478bdstevel@tonic-gate		for (j = 0; j <= i; j++) {
13027c478bdstevel@tonic-gate			if (out->name[j] != NULL)
13037c478bdstevel@tonic-gate				free(out->name[j]);
13047c478bdstevel@tonic-gate			if (out->value[j] != NULL)
13057c478bdstevel@tonic-gate				free_mapping_format(out->value[j]);
13067c478bdstevel@tonic-gate		}
13077c478bdstevel@tonic-gate		free(out->name);
13087c478bdstevel@tonic-gate		out->name = NULL;
13097c478bdstevel@tonic-gate		free(out->value);
13107c478bdstevel@tonic-gate		out->value = NULL;
13117c478bdstevel@tonic-gate	} else {
13127c478bdstevel@tonic-gate		out->numIndexes = in->numIndexes;
13137c478bdstevel@tonic-gate	}
13147c478bdstevel@tonic-gate	return (i == in->numIndexes);
13157c478bdstevel@tonic-gate}
13167c478bdstevel@tonic-gate
13177c478bdstevel@tonic-gatebool_t
13187c478bdstevel@tonic-gatedup_mapping_item(__nis_mapping_item_t *in, __nis_mapping_item_t *out)
13197c478bdstevel@tonic-gate{
13207c478bdstevel@tonic-gate	bool_t	ret;
13217c478bdstevel@tonic-gate
13227c478bdstevel@tonic-gate	if (in->type == mit_nisplus) {
13237c478bdstevel@tonic-gate		ret = dup_index(&in->searchSpec.obj.index,
13247c478bdstevel@tonic-gate			&out->searchSpec.obj.index);
13257c478bdstevel@tonic-gate		if (!ret)
13267c478bdstevel@tonic-gate			return (ret);
13277c478bdstevel@tonic-gate		if (in->searchSpec.obj.name != NULL) {
13287c478bdstevel@tonic-gate		    out->searchSpec.obj.name =
13297c478bdstevel@tonic-gate			s_strdup(in->searchSpec.obj.name);
13307c478bdstevel@tonic-gate			if (out->searchSpec.obj.name == NULL)
13317c478bdstevel@tonic-gate				return (FALSE);
13327c478bdstevel@tonic-gate		} else
13337c478bdstevel@tonic-gate			out->searchSpec.obj.name = NULL;
13347c478bdstevel@tonic-gate	} else if (in->type == mit_ldap) {
13357c478bdstevel@tonic-gate		if (in->searchSpec.triple.base != NULL) {
13367c478bdstevel@tonic-gate		    out->searchSpec.triple.base =
13377c478bdstevel@tonic-gate			s_strdup(in->searchSpec.triple.base);
13387c478bdstevel@tonic-gate			if (out->searchSpec.triple.base == NULL)
13397c478bdstevel@tonic-gate				return (FALSE);
13407c478bdstevel@tonic-gate		} else
13417c478bdstevel@tonic-gate			out->searchSpec.triple.base = NULL;
13427c478bdstevel@tonic-gate		out->searchSpec.triple.scope =
13437c478bdstevel@tonic-gate			in->searchSpec.triple.scope;
13447c478bdstevel@tonic-gate		if (in->searchSpec.triple.attrs != NULL) {
13457c478bdstevel@tonic-gate		    out->searchSpec.triple.attrs =
13467c478bdstevel@tonic-gate			s_strdup(in->searchSpec.triple.attrs);
13477c478bdstevel@tonic-gate			if (out->searchSpec.triple.attrs == NULL)
13487c478bdstevel@tonic-gate				return (FALSE);
13497c478bdstevel@tonic-gate		} else
13507c478bdstevel@tonic-gate			out->searchSpec.triple.attrs = NULL;
13517c478bdstevel@tonic-gate		if (in->searchSpec.triple.element != NULL) {
13527c478bdstevel@tonic-gate			out->searchSpec.triple.element =
13537c478bdstevel@tonic-gate				(__nis_mapping_element_t *)
13547c478bdstevel@tonic-gate				s_calloc(1, sizeof (__nis_mapping_element_t));
13557c478bdstevel@tonic-gate			if (out->searchSpec.triple.element != NULL)
13567c478bdstevel@tonic-gate				dup_mapping_element(
13577c478bdstevel@tonic-gate					in->searchSpec.triple.element,
13587c478bdstevel@tonic-gate					out->searchSpec.triple.element);
13597c478bdstevel@tonic-gate			if (out->searchSpec.triple.element == NULL)
13607c478bdstevel@tonic-gate				return (FALSE);
13617c478bdstevel@tonic-gate		} else
13627c478bdstevel@tonic-gate			out->searchSpec.triple.element = NULL;
13637c478bdstevel@tonic-gate	}
13647c478bdstevel@tonic-gate
13657c478bdstevel@tonic-gate	if (in->name != NULL) {
13667c478bdstevel@tonic-gate		out->name = s_strdup(in->name);
13677c478bdstevel@tonic-gate		if (out->name == NULL)
13687c478bdstevel@tonic-gate			return (FALSE);
13697c478bdstevel@tonic-gate	} else
13707c478bdstevel@tonic-gate		out->name = NULL;
13717c478bdstevel@tonic-gate	out->type = in->type;
13727c478bdstevel@tonic-gate	out->repeat = in->repeat;
13737c478bdstevel@tonic-gate	if (in->exItem) {
13747c478bdstevel@tonic-gate		out->exItem = (__nis_mapping_item_t *)s_malloc
13757c478bdstevel@tonic-gate			(sizeof (__nis_mapping_item_t));
13767c478bdstevel@tonic-gate		if (out->exItem == NULL)
13777c478bdstevel@tonic-gate			return (FALSE);
13787c478bdstevel@tonic-gate		else {
13797c478bdstevel@tonic-gate			(void) memset
13807c478bdstevel@tonic-gate				(out->exItem, 0, sizeof (out->exItem[0]));
13817c478bdstevel@tonic-gate			if (!dup_mapping_item
13827c478bdstevel@tonic-gate				(in->exItem, out->exItem))
13837c478bdstevel@tonic-gate				p_error = parse_internal_error;
13847c478bdstevel@tonic-gate		}
13857c478bdstevel@tonic-gate	} else
13867c478bdstevel@tonic-gate		out->exItem = NULL;
13877c478bdstevel@tonic-gate
13887c478bdstevel@tonic-gate	return (p_error == no_parse_error);
13897c478bdstevel@tonic-gate}
13907c478bdstevel@tonic-gate
13917c478bdstevel@tonic-gate__nis_mapping_format_t *
13927c478bdstevel@tonic-gatedup_format_mapping(__nis_mapping_format_t *in)
13937c478bdstevel@tonic-gate{
13947c478bdstevel@tonic-gate	int			i;
13957c478bdstevel@tonic-gate	__nis_mapping_format_t	*out;
13967c478bdstevel@tonic-gate	bool_t			got_end;
13977c478bdstevel@tonic-gate
13987c478bdstevel@tonic-gate	i = 0;
13997c478bdstevel@tonic-gate	while (in[i].type != mmt_end)
14007c478bdstevel@tonic-gate		i++;
14017c478bdstevel@tonic-gate	out = (__nis_mapping_format_t *)s_calloc(
14027c478bdstevel@tonic-gate		i + 1, sizeof (__nis_mapping_format_t));
14037c478bdstevel@tonic-gate	if (out != NULL) {
14047c478bdstevel@tonic-gate		got_end = FALSE;
14057c478bdstevel@tonic-gate		for (i = 0; !got_end; i++) {
14067c478bdstevel@tonic-gate		    switch (in[i].type) {
14077c478bdstevel@tonic-gate			case mmt_item:
14087c478bdstevel@tonic-gate				break;
14097c478bdstevel@tonic-gate			case mmt_string:
14107c478bdstevel@tonic-gate				out[i].match.string =
14117c478bdstevel@tonic-gate					s_strdup(in[i].match.string);
14127c478bdstevel@tonic-gate				break;
14137c478bdstevel@tonic-gate			case mmt_single:
14147c478bdstevel@tonic-gate				out[i].match.single.numRange =
14157c478bdstevel@tonic-gate					in[i].match.single.numRange;
14167c478bdstevel@tonic-gate				out[i].match.single.lo =
14177c478bdstevel@tonic-gate					s_malloc(in[i].match.single.numRange);
14187c478bdstevel@tonic-gate				if (out[i].match.single.lo == NULL)
14197c478bdstevel@tonic-gate					break;
14207c478bdstevel@tonic-gate				out[i].match.single.hi =
14217c478bdstevel@tonic-gate					s_malloc(in[i].match.single.numRange);
14227c478bdstevel@tonic-gate				if (out[i].match.single.hi == NULL)
14237c478bdstevel@tonic-gate					break;
14247c478bdstevel@tonic-gate				memcpy(out[i].match.single.lo,
14257c478bdstevel@tonic-gate					in[i].match.single.lo,
14267c478bdstevel@tonic-gate					in[i].match.single.numRange);
14277c478bdstevel@tonic-gate				memcpy(out[i].match.single.hi,
14287c478bdstevel@tonic-gate					in[i].match.single.hi,
14297c478bdstevel@tonic-gate					in[i].match.single.numRange);
14307c478bdstevel@tonic-gate				break;
14317c478bdstevel@tonic-gate			case mmt_limit:
14327c478bdstevel@tonic-gate				out[i].match.limit = in[i].match.limit;
14337c478bdstevel@tonic-gate				break;
14347c478bdstevel@tonic-gate			case mmt_any:
14357c478bdstevel@tonic-gate				break;
14367c478bdstevel@tonic-gate			case mmt_berstring:
14377c478bdstevel@tonic-gate				out[i].match.berString =
14387c478bdstevel@tonic-gate					s_strdup(in[i].match.berString);
14397c478bdstevel@tonic-gate				break;
14407c478bdstevel@tonic-gate			case mmt_begin:
14417c478bdstevel@tonic-gate				break;
14427c478bdstevel@tonic-gate			case mmt_end:
14437c478bdstevel@tonic-gate				got_end = TRUE;
14447c478bdstevel@tonic-gate				break;
14457c478bdstevel@tonic-gate			default:
14467c478bdstevel@tonic-gate				p_error = parse_internal_error;
14477c478bdstevel@tonic-gate		    }
14487c478bdstevel@tonic-gate		    if (p_error != no_parse_error)
14497c478bdstevel@tonic-gate			break;
14507c478bdstevel@tonic-gate		    out[i].type = in[i].type;
14517c478bdstevel@tonic-gate		}
14527c478bdstevel@tonic-gate		if (p_error != no_parse_error) {
14537c478bdstevel@tonic-gate			free_mapping_format(out);
14547c478bdstevel@tonic-gate			out = NULL;
14557c478bdstevel@tonic-gate		}
14567c478bdstevel@tonic-gate	}
14577c478bdstevel@tonic-gate
14587c478bdstevel@tonic-gate	return (out);
14597c478bdstevel@tonic-gate}
14607c478bdstevel@tonic-gate
14617c478bdstevel@tonic-gatebool_t
14627c478bdstevel@tonic-gatedup_mapping_sub_element(
14637c478bdstevel@tonic-gate	__nis_mapping_sub_element_t	*in,
14647c478bdstevel@tonic-gate	__nis_mapping_sub_element_t	*out)
14657c478bdstevel@tonic-gate{
14667c478bdstevel@tonic-gate	bool_t	ret = FALSE;
14677c478bdstevel@tonic-gate	int	i;
14687c478bdstevel@tonic-gate
14697c478bdstevel@tonic-gate	switch (in->type) {
14707c478bdstevel@tonic-gate		case me_item:
14717c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.item,
14727c478bdstevel@tonic-gate				&out->element.item);
14737c478bdstevel@tonic-gate			break;
14747c478bdstevel@tonic-gate		case me_print:
14757c478bdstevel@tonic-gate			out->element.print.fmt =
14767c478bdstevel@tonic-gate				dup_format_mapping(in->element.print.fmt);
14777c478bdstevel@tonic-gate			if (out->element.print.fmt == NULL)
14787c478bdstevel@tonic-gate				break;
14797c478bdstevel@tonic-gate			out->element.print.numItems =
14807c478bdstevel@tonic-gate				in->element.print.numItems;
14817c478bdstevel@tonic-gate			out->element.print.item = (__nis_mapping_item_t *)
14827c478bdstevel@tonic-gate				s_calloc(in->element.print.numItems,
14837c478bdstevel@tonic-gate					sizeof (__nis_mapping_item_t));
14847c478bdstevel@tonic-gate			if (out->element.print.item == NULL)
14857c478bdstevel@tonic-gate				break;
14867c478bdstevel@tonic-gate			for (i = 0; i < in->element.print.numItems; i++)
14877c478bdstevel@tonic-gate				if (!dup_mapping_item(
14887c478bdstevel@tonic-gate					&in->element.print.item[i],
14897c478bdstevel@tonic-gate					&out->element.print.item[i]))
14907c478bdstevel@tonic-gate						break;
14917c478bdstevel@tonic-gate			if (i < in->element.print.numItems)
14927c478bdstevel@tonic-gate				break;
14937c478bdstevel@tonic-gate			ret = TRUE;
14947c478bdstevel@tonic-gate			out->element.print.doElide = in->element.print.doElide;
14957c478bdstevel@tonic-gate			out->element.print.elide = in->element.print.elide;
14967c478bdstevel@tonic-gate			break;
14977c478bdstevel@tonic-gate		case me_split:
14987c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.split.item,
14997c478bdstevel@tonic-gate				&out->element.split.item);
15007c478bdstevel@tonic-gate			out->element.split.delim = in->element.split.delim;
15017c478bdstevel@tonic-gate			break;
15027c478bdstevel@tonic-gate		case me_extract:
15037c478bdstevel@tonic-gate			out->element.extract.fmt =
15047c478bdstevel@tonic-gate				dup_format_mapping(in->element.extract.fmt);
15057c478bdstevel@tonic-gate			if (out->element.extract.fmt == NULL)
15067c478bdstevel@tonic-gate				break;
15077c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.extract.item,
15087c478bdstevel@tonic-gate				&out->element.extract.item);
15097c478bdstevel@tonic-gate			break;
15107c478bdstevel@tonic-gate		default:
15117c478bdstevel@tonic-gate			p_error = parse_internal_error;
15127c478bdstevel@tonic-gate	}
15137c478bdstevel@tonic-gate	out->type = in->type;
15147c478bdstevel@tonic-gate
15157c478bdstevel@tonic-gate	return (ret);
15167c478bdstevel@tonic-gate}
15177c478bdstevel@tonic-gate
15187c478bdstevel@tonic-gatebool_t
15197c478bdstevel@tonic-gatedup_mapping_element(
15207c478bdstevel@tonic-gate	__nis_mapping_element_t *in,
15217c478bdstevel@tonic-gate	__nis_mapping_element_t *out)
15227c478bdstevel@tonic-gate{
15237c478bdstevel@tonic-gate	bool_t	ret = FALSE;
15247c478bdstevel@tonic-gate	int	i;
15257c478bdstevel@tonic-gate
15267c478bdstevel@tonic-gate	if (in == NULL)
15277c478bdstevel@tonic-gate		return (ret);
15287c478bdstevel@tonic-gate
15297c478bdstevel@tonic-gate	switch (in->type) {
15307c478bdstevel@tonic-gate		case me_item:
15317c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.item,
15327c478bdstevel@tonic-gate				&out->element.item);
15337c478bdstevel@tonic-gate			break;
15347c478bdstevel@tonic-gate		case me_print:
15357c478bdstevel@tonic-gate			out->element.print.fmt =
15367c478bdstevel@tonic-gate				dup_format_mapping(in->element.print.fmt);
15377c478bdstevel@tonic-gate			if (out->element.print.fmt == NULL)
15387c478bdstevel@tonic-gate				break;
15397c478bdstevel@tonic-gate			out->element.print.numSubElements =
15407c478bdstevel@tonic-gate				in->element.print.numSubElements;
15417c478bdstevel@tonic-gate			out->element.print.subElement =
15427c478bdstevel@tonic-gate				(__nis_mapping_sub_element_t *)
15437c478bdstevel@tonic-gate				s_calloc(in->element.print.numSubElements,
15447c478bdstevel@tonic-gate					sizeof (__nis_mapping_sub_element_t));
15457c478bdstevel@tonic-gate			if (out->element.print.subElement == NULL)
15467c478bdstevel@tonic-gate				break;
15477c478bdstevel@tonic-gate			for (i = 0; i < in->element.print.numSubElements; i++)
15487c478bdstevel@tonic-gate				if (!dup_mapping_sub_element(
15497c478bdstevel@tonic-gate					&in->element.print.subElement[i],
15507c478bdstevel@tonic-gate					&out->element.print.subElement[i]))
15517c478bdstevel@tonic-gate						break;
15527c478bdstevel@tonic-gate			if (i < in->element.print.numSubElements)
15537c478bdstevel@tonic-gate				break;
15547c478bdstevel@tonic-gate			ret = TRUE;
15557c478bdstevel@tonic-gate			out->element.print.doElide = in->element.print.doElide;
15567c478bdstevel@tonic-gate			out->element.print.elide = in->element.print.elide;
15577c478bdstevel@tonic-gate			break;
15587c478bdstevel@tonic-gate		case me_split:
15597c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.split.item,
15607c478bdstevel@tonic-gate				&out->element.split.item);
15617c478bdstevel@tonic-gate			out->element.split.delim = in->element.split.delim;
15627c478bdstevel@tonic-gate			break;
15637c478bdstevel@tonic-gate		case me_match:
15647c478bdstevel@tonic-gate			out->element.match.fmt =
15657c478bdstevel@tonic-gate				dup_format_mapping(in->element.match.fmt);
15667c478bdstevel@tonic-gate			if (out->element.match.fmt == NULL)
15677c478bdstevel@tonic-gate				break;
15687c478bdstevel@tonic-gate			out->element.match.numItems =
15697c478bdstevel@tonic-gate				in->element.match.numItems;
15707c478bdstevel@tonic-gate			out->element.match.item = (__nis_mapping_item_t *)
15717c478bdstevel@tonic-gate				s_calloc(in->element.match.numItems,
15727c478bdstevel@tonic-gate					sizeof (__nis_mapping_item_t));
15737c478bdstevel@tonic-gate			if (out->element.match.item == NULL)
15747c478bdstevel@tonic-gate				break;
15757c478bdstevel@tonic-gate			for (i = 0; i < in->element.match.numItems; i++)
15767c478bdstevel@tonic-gate				if (!dup_mapping_item(
15777c478bdstevel@tonic-gate					&in->element.match.item[i],
15787c478bdstevel@tonic-gate					&out->element.match.item[i]))
15797c478bdstevel@tonic-gate						break;
15807c478bdstevel@tonic-gate			if (i < in->element.match.numItems)
15817c478bdstevel@tonic-gate				break;
15827c478bdstevel@tonic-gate			ret = TRUE;
15837c478bdstevel@tonic-gate			break;
15847c478bdstevel@tonic-gate		case me_extract:
15857c478bdstevel@tonic-gate			out->element.extract.fmt =
15867c478bdstevel@tonic-gate				dup_format_mapping(in->element.extract.fmt);
15877c478bdstevel@tonic-gate			if (out->element.extract.fmt == NULL)
15887c478bdstevel@tonic-gate				break;
15897c478bdstevel@tonic-gate			ret = dup_mapping_item(&in->element.extract.item,
15907c478bdstevel@tonic-gate				&out->element.extract.item);
15917c478bdstevel@tonic-gate			break;
15927c478bdstevel@tonic-gate		default:
15937c478bdstevel@tonic-gate			p_error = parse_internal_error;
15947c478bdstevel@tonic-gate	}
15957c478bdstevel@tonic-gate	out->type = in->type;
15967c478bdstevel@tonic-gate
15977c478bdstevel@tonic-gate	return (ret);
15987c478bdstevel@tonic-gate}
15997c478bdstevel@tonic-gate
16007c478bdstevel@tonic-gate__nis_mapping_rule_t *
16017c478bdstevel@tonic-gatedup_mapping_rule(__nis_mapping_rule_t *in)
16027c478bdstevel@tonic-gate{
16037c478bdstevel@tonic-gate	int			i;
16047c478bdstevel@tonic-gate	__nis_mapping_rlhs_t	*r_in;
16057c478bdstevel@tonic-gate	__nis_mapping_rlhs_t	*r_out;
16067c478bdstevel@tonic-gate	__nis_mapping_rule_t	*out;
16077c478bdstevel@tonic-gate
16087c478bdstevel@tonic-gate	out = (__nis_mapping_rule_t *)
16097c478bdstevel@tonic-gate		s_calloc(1, sizeof (__nis_mapping_rule_t));
16107c478bdstevel@tonic-gate	if (out != NULL) {
16117c478bdstevel@tonic-gate		r_in = &in->lhs;
16127c478bdstevel@tonic-gate		r_out = &out->lhs;
16137c478bdstevel@tonic-gate		r_out->numElements = r_in->numElements;
16147c478bdstevel@tonic-gate		r_out->element = (__nis_mapping_element_t *)s_calloc
16157c478bdstevel@tonic-gate			(r_in->numElements, sizeof (__nis_mapping_element_t));
16167c478bdstevel@tonic-gate		if (r_out->element == NULL) {
16177c478bdstevel@tonic-gate			free_mapping_rule(out);
16187c478bdstevel@tonic-gate			return (NULL);
16197c478bdstevel@tonic-gate		}
16207c478bdstevel@tonic-gate		for (i = 0; i < r_in->numElements; i++) {
16217c478bdstevel@tonic-gate		    if (!dup_mapping_element(&r_in->element[i],
16227c478bdstevel@tonic-gate			&r_out->element[i]))
16237c478bdstevel@tonic-gate				break;
16247c478bdstevel@tonic-gate		}
16257c478bdstevel@tonic-gate		if (i < r_in->numElements) {
16267c478bdstevel@tonic-gate			free_mapping_rule(out);
16277c478bdstevel@tonic-gate			return (NULL);
16287c478bdstevel@tonic-gate		}
16297c478bdstevel@tonic-gate
16307c478bdstevel@tonic-gate		r_in = &in->rhs;
16317c478bdstevel@tonic-gate		r_out = &out->rhs;
16327c478bdstevel@tonic-gate		r_out->numElements = r_in->numElements;
16337c478bdstevel@tonic-gate		r_out->element = (__nis_mapping_element_t *)s_calloc
16347c478bdstevel@tonic-gate			(r_in->numElements, sizeof (__nis_mapping_element_t));
16357c478bdstevel@tonic-gate		if (r_out->element == NULL) {
16367c478bdstevel@tonic-gate			free_mapping_rule(out);
16377c478bdstevel@tonic-gate			return (NULL);
16387c478bdstevel@tonic-gate		}
16397c478bdstevel@tonic-gate		for (i = 0; i < r_in->numElements; i++) {
16407c478bdstevel@tonic-gate		    if (!dup_mapping_element(&r_in->element[i],
16417c478bdstevel@tonic-gate			&r_out->element[i]))
16427c478bdstevel@tonic-gate				break;
16437c478bdstevel@tonic-gate		}
16447c478bdstevel@tonic-gate		if (i < r_in->numElements) {
16457c478bdstevel@tonic-gate			free_mapping_rule(out);
16467c478bdstevel@tonic-gate			return (NULL);
16477c478bdstevel@tonic-gate		}
16487c478bdstevel@tonic-gate	}
16497c478bdstevel@tonic-gate	return (out);
16507c478bdstevel@tonic-gate}
16517c478bdstevel@tonic-gate
16527c478bdstevel@tonic-gate__nis_mapping_rule_t **
16537c478bdstevel@tonic-gatedup_mapping_rules(__nis_mapping_rule_t **rules, int n_rules)
16547c478bdstevel@tonic-gate{
16557c478bdstevel@tonic-gate	int			i, j;
16567c478bdstevel@tonic-gate	__nis_mapping_rule_t	**r;
16577c478bdstevel@tonic-gate
16587c478bdstevel@tonic-gate	r = (__nis_mapping_rule_t **)s_calloc(n_rules,
16597c478bdstevel@tonic-gate		sizeof (__nis_mapping_rule_t *));
16607c478bdstevel@tonic-gate	if (r != NULL) {
16617c478bdstevel@tonic-gate		for (i = 0; i < n_rules; i++) {
16627c478bdstevel@tonic-gate			r[i] = dup_mapping_rule(rules[i]);
16637c478bdstevel@tonic-gate			if (r[i] == NULL) {
16647c478bdstevel@tonic-gate				for (j = 0; j < i; j++)
16657c478bdstevel@tonic-gate					free_mapping_rule(r[j]);
16667c478bdstevel@tonic-gate				free(r);
16677c478bdstevel@tonic-gate				r = NULL;
16687c478bdstevel@tonic-gate				break;
16697c478bdstevel@tonic-gate			}
16707c478bdstevel@tonic-gate		}
16717c478bdstevel@tonic-gate	}
16727c478bdstevel@tonic-gate	return (r);
16737c478bdstevel@tonic-gate}
16747c478bdstevel@tonic-gate
16757c478bdstevel@tonic-gate/*
16767c478bdstevel@tonic-gate * FUNCTION:	add_column
16777c478bdstevel@tonic-gate *
16787c478bdstevel@tonic-gate *	Adds a column name to the column list in __nis_table_mapping_t
16797c478bdstevel@tonic-gate *
16807c478bdstevel@tonic-gate * RETURN VALUE:	FALSE if error
16817c478bdstevel@tonic-gate *			TRUE if __nis_index_t returned
16827c478bdstevel@tonic-gate *
16837c478bdstevel@tonic-gate * INPUT:		the __nis_table_mapping_t and column name
16847c478bdstevel@tonic-gate */
16857c478bdstevel@tonic-gate
16867c478bdstevel@tonic-gatebool_t
16877c478bdstevel@tonic-gateadd_column(__nis_table_mapping_t *t, const char *col_name)
16887c478bdstevel@tonic-gate{
16897c478bdstevel@tonic-gate	int i;
16907c478bdstevel@tonic-gate	char **cols = NULL;
16917c478bdstevel@tonic-gate
16927c478bdstevel@tonic-gate	if (!yp2ldap) {
16937c478bdstevel@tonic-gate		for (i = 0; i < t->numColumns; i++) {
16947c478bdstevel@tonic-gate			if (strcasecmp(col_name, t->column[i]) == 0)
16957c478bdstevel@tonic-gate				return (TRUE);
16967c478bdstevel@tonic-gate		}
16977c478bdstevel@tonic-gate	}
16987c478bdstevel@tonic-gate	cols = (char **)s_realloc(t->column, (t->numColumns + 1) *
16997c478bdstevel@tonic-gate		sizeof (char *));
17007c478bdstevel@tonic-gate	if (cols == NULL)
17017c478bdstevel@tonic-gate		return (FALSE);
17027c478bdstevel@tonic-gate	t->column = cols;
17037c478bdstevel@tonic-gate	cols[t->numColumns] = s_strdup(col_name);
17047c478bdstevel@tonic-gate	if (cols[t->numColumns] == NULL)
17057c478bdstevel@tonic-gate		return (FALSE);
17067c478bdstevel@tonic-gate	t->numColumns++;
17077c478bdstevel@tonic-gate	return (TRUE);
17087c478bdstevel@tonic-gate}
17097c478bdstevel@tonic-gate
17107c478bdstevel@tonic-gate/*
17117c478bdstevel@tonic-gate * FUNCTION:	add_element
17127c478bdstevel@tonic-gate *
17137c478bdstevel@tonic-gate *	Adds a __nis_mapping_element_t to __nis_mapping_rlhs_t
17147c478bdstevel@tonic-gate *
17157c478bdstevel@tonic-gate * RETURN VALUE:	FALSE if error
17167c478bdstevel@tonic-gate *			TRUE if __nis_index_t returned
17177c478bdstevel@tonic-gate *
17187c478bdstevel@tonic-gate * INPUT:		the __nis_mapping_element_t and
17197c478bdstevel@tonic-gate *			__nis_mapping_rlhs_t
17207c478bdstevel@tonic-gate */
17217c478bdstevel@tonic-gate
17227c478bdstevel@tonic-gatebool_t
17237c478bdstevel@tonic-gateadd_element(
17247c478bdstevel@tonic-gate	__nis_mapping_element_t	*e,
17257c478bdstevel@tonic-gate	__nis_mapping_rlhs_t	*m)
17267c478bdstevel@tonic-gate{
17277c478bdstevel@tonic-gate	__nis_mapping_element_t *e1;
17287c478bdstevel@tonic-gate	int			i;
17297c478bdstevel@tonic-gate	int			n	= m->numElements;
17307c478bdstevel@tonic-gate
17317c478bdstevel@tonic-gate	e1 = (__nis_mapping_element_t *)s_realloc(m->element,
17327c478bdstevel@tonic-gate		(n + 1) * sizeof (__nis_mapping_element_t));
17337c478bdstevel@tonic-gate	if (e1 == NULL) {
17347c478bdstevel@tonic-gate		e1 = m->element;
17357c478bdstevel@tonic-gate		for (i = 0; i < n; i++)
17367c478bdstevel@tonic-gate			free_mapping_element(e1++);
17377c478bdstevel@tonic-gate		if (m->element != NULL)
17387c478bdstevel@tonic-gate			free(m->element);
17397c478bdstevel@tonic-gate		m->element = NULL;
17407c478bdstevel@tonic-gate		m->numElements = 0;
17417c478bdstevel@tonic-gate	} else {
17427c478bdstevel@tonic-gate		e1[m->numElements++] = *e;
17437c478bdstevel@tonic-gate		free(e);
17447c478bdstevel@tonic-gate		m->element = (__nis_mapping_element_t *)e1;
17457c478bdstevel@tonic-gate	}
17467c478bdstevel@tonic-gate	return (e1 != NULL);
17477c478bdstevel@tonic-gate}
17487c478bdstevel@tonic-gate
17497c478bdstevel@tonic-gate/*
17507c478bdstevel@tonic-gate * FUNCTION:	get_next_object_dn_token
17517c478bdstevel@tonic-gate *
17527c478bdstevel@tonic-gate *	Get the next token in parsing object_dn
17537c478bdstevel@tonic-gate *
17547c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
17557c478bdstevel@tonic-gate *			position of beginning next token after
17567c478bdstevel@tonic-gate *			token
17577c478bdstevel@tonic-gate *
17587c478bdstevel@tonic-gate * INPUT:		the attribute value
17597c478bdstevel@tonic-gate */
17607c478bdstevel@tonic-gate
17617c478bdstevel@tonic-gateconst char *
17627c478bdstevel@tonic-gateget_next_object_dn_token(
17637c478bdstevel@tonic-gate	const char	**begin_ret,
17647c478bdstevel@tonic-gate	const char	**end_ret,
17657c478bdstevel@tonic-gate	object_dn_token	*token)
17667c478bdstevel@tonic-gate{
17677c478bdstevel@tonic-gate	object_dn_token	t		= dn_no_token;
17687c478bdstevel@tonic-gate	const char	*s		= *begin_ret;
17697c478bdstevel@tonic-gate	const char	*begin;
17707c478bdstevel@tonic-gate	const char	*end		= *end_ret;
17717c478bdstevel@tonic-gate	const char	*s1;
17727c478bdstevel@tonic-gate	bool_t		in_quotes;
17737c478bdstevel@tonic-gate
17747c478bdstevel@tonic-gate	while (s < end && is_whitespace(*s))
17757c478bdstevel@tonic-gate		s++;
17767c478bdstevel@tonic-gate	if (s >= end) {
17777c478bdstevel@tonic-gate		/* EMPTY */
17787c478bdstevel@tonic-gate	} else if (*s == SEMI_COLON_CHAR) {
17797c478bdstevel@tonic-gate		t = dn_semi_token;
17807c478bdstevel@tonic-gate		s++;
17817c478bdstevel@tonic-gate	} else if (*s == QUESTION_MARK) {
17827c478bdstevel@tonic-gate		t = dn_ques_token;
17837c478bdstevel@tonic-gate		s++;
17847c478bdstevel@tonic-gate	} else if (*s == COLON_CHAR) {
17857c478bdstevel@tonic-gate		t = dn_colon_token;
17867c478bdstevel@tonic-gate		s++;
17877c478bdstevel@tonic-gate	} else if (*s == OPEN_PAREN_CHAR) {
17887c478bdstevel@tonic-gate		begin = s;
17897c478bdstevel@tonic-gate		s = get_ldap_filter(&begin, &end);
17907c478bdstevel@tonic-gate		if (s != NULL) {
17917c478bdstevel@tonic-gate			t = dn_text_token;
17927c478bdstevel@tonic-gate			*begin_ret = begin;
17937c478bdstevel@tonic-gate			*end_ret = end;
17947c478bdstevel@tonic-gate		}
17957c478bdstevel@tonic-gate	} else {
17967c478bdstevel@tonic-gate		begin = s;
17977c478bdstevel@tonic-gate		in_quotes = FALSE;
17987c478bdstevel@tonic-gate		while (s < end) {
17997c478bdstevel@tonic-gate			if (*s == ESCAPE_CHAR) {
18007c478bdstevel@tonic-gate			    if (s + 2 > end) {
18017c478bdstevel@tonic-gate				p_error = parse_unmatched_escape;
18027c478bdstevel@tonic-gate				s = NULL;
18037c478bdstevel@tonic-gate				break;
18047c478bdstevel@tonic-gate			    }
18057c478bdstevel@tonic-gate			    s++;
18067c478bdstevel@tonic-gate			} else if (*s == DOUBLE_QUOTE_CHAR) {
18077c478bdstevel@tonic-gate				in_quotes = ! in_quotes;
18087c478bdstevel@tonic-gate			} else if (in_quotes)
18097c478bdstevel@tonic-gate				;
18107c478bdstevel@tonic-gate			else if (*s == SEMI_COLON_CHAR ||
18117c478bdstevel@tonic-gate				*s == QUESTION_MARK ||
18127c478bdstevel@tonic-gate				*s == COLON_CHAR)
18137c478bdstevel@tonic-gate					break;
18147c478bdstevel@tonic-gate			s++;
18157c478bdstevel@tonic-gate		}
18167c478bdstevel@tonic-gate		if (s != NULL) {
18177c478bdstevel@tonic-gate			s1 = s - 1;
18187c478bdstevel@tonic-gate			while (is_whitespace(*s1))
18197c478bdstevel@tonic-gate				s1--;
18207c478bdstevel@tonic-gate			s1++;
18217c478bdstevel@tonic-gate			if (same_string("base", begin, s1 - begin))
18227c478bdstevel@tonic-gate				t = dn_base_token;
18237c478bdstevel@tonic-gate			else if (same_string("one", begin, s1 - begin))
18247c478bdstevel@tonic-gate				t = dn_one_token;
18257c478bdstevel@tonic-gate			else if (same_string("sub", begin, s1 - begin))
18267c478bdstevel@tonic-gate				t = dn_sub_token;
18277c478bdstevel@tonic-gate			else
18287c478bdstevel@tonic-gate				t = dn_text_token;
18297c478bdstevel@tonic-gate			*begin_ret = begin;
18307c478bdstevel@tonic-gate			*end_ret = s1;
18317c478bdstevel@tonic-gate		}
18327c478bdstevel@tonic-gate	}
18337c478bdstevel@tonic-gate	*token = t;
18347c478bdstevel@tonic-gate	return (s);
18357c478bdstevel@tonic-gate}
18367c478bdstevel@tonic-gate
18377c478bdstevel@tonic-gate/*
18387c478bdstevel@tonic-gate * FUNCTION:	get_next_token
18397c478bdstevel@tonic-gate *
18407c478bdstevel@tonic-gate *	Get the next token in parsing mapping attribute
18417c478bdstevel@tonic-gate *
18427c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
18437c478bdstevel@tonic-gate *			position of beginning next token after
18447c478bdstevel@tonic-gate *			token
18457c478bdstevel@tonic-gate *
18467c478bdstevel@tonic-gate * INPUT:		the attribute value
18477c478bdstevel@tonic-gate */
18487c478bdstevel@tonic-gate
18497c478bdstevel@tonic-gateconst char *
18507c478bdstevel@tonic-gateget_next_token(const char **begin_token, const char **end_token, token_type *t)
18517c478bdstevel@tonic-gate{
18527c478bdstevel@tonic-gate	const char	*s		= *begin_token;
18537c478bdstevel@tonic-gate	const char	*end_s		= *end_token;
18547c478bdstevel@tonic-gate	const char	*s_begin;
18557c478bdstevel@tonic-gate
18567c478bdstevel@tonic-gate	while (s < end_s && is_whitespace(*s))
18577c478bdstevel@tonic-gate		s++;
18587c478bdstevel@tonic-gate	if (s == end_s) {
18597c478bdstevel@tonic-gate		*t = no_token;
18607c478bdstevel@tonic-gate		return (s);
18617c478bdstevel@tonic-gate	}
18627c478bdstevel@tonic-gate
18637c478bdstevel@tonic-gate	s_begin = s;
18647c478bdstevel@tonic-gate
18657c478bdstevel@tonic-gate	if (*s == OPEN_PAREN_CHAR) {
18667c478bdstevel@tonic-gate		*begin_token = s;
18677c478bdstevel@tonic-gate		s++;
18687c478bdstevel@tonic-gate		*end_token = s;
18697c478bdstevel@tonic-gate		while (s < end_s && is_whitespace(*s))
18707c478bdstevel@tonic-gate			s++;
18717c478bdstevel@tonic-gate		*t = open_paren_token;
18727c478bdstevel@tonic-gate	} else if (*s == DOUBLE_QUOTE_CHAR) {
18737c478bdstevel@tonic-gate		s++;
18747c478bdstevel@tonic-gate		while (s < end_s) {
18757c478bdstevel@tonic-gate			if (*s == ESCAPE_CHAR)
18767c478bdstevel@tonic-gate				s += 2;
18777c478bdstevel@tonic-gate			else if (*s == DOUBLE_QUOTE_CHAR)
18787c478bdstevel@tonic-gate				break;
18797c478bdstevel@tonic-gate			else
18807c478bdstevel@tonic-gate				s++;
18817c478bdstevel@tonic-gate		}
18827c478bdstevel@tonic-gate		if (s >= end_s) {
18837c478bdstevel@tonic-gate			p_error = parse_unmatched_escape;
18847c478bdstevel@tonic-gate			return (NULL);
18857c478bdstevel@tonic-gate		}
18867c478bdstevel@tonic-gate
18877c478bdstevel@tonic-gate		*t = quoted_string_token;
18887c478bdstevel@tonic-gate		*begin_token = s_begin + 1;
18897c478bdstevel@tonic-gate		*end_token = s++;
18907c478bdstevel@tonic-gate	} else if (*s == EQUAL_CHAR || *s == COMMA_CHAR ||
18917c478bdstevel@tonic-gate	    *s == CLOSE_PAREN_CHAR || *s == COLON_CHAR) {
18927c478bdstevel@tonic-gate		if (*s == EQUAL_CHAR)
18937c478bdstevel@tonic-gate			*t = equal_token;
18947c478bdstevel@tonic-gate		else if (*s == COMMA_CHAR)
18957c478bdstevel@tonic-gate			*t = comma_token;
18967c478bdstevel@tonic-gate		else if (*s == CLOSE_PAREN_CHAR)
18977c478bdstevel@tonic-gate			*t = close_paren_token;
18987c478bdstevel@tonic-gate		else
18997c478bdstevel@tonic-gate			*t = colon_token;
19007c478bdstevel@tonic-gate		*begin_token = s;
19017c478bdstevel@tonic-gate		*end_token = ++s;
19027c478bdstevel@tonic-gate	} else {
19037c478bdstevel@tonic-gate		s_begin = s;
19047c478bdstevel@tonic-gate		while (s < end_s && !is_whitespace(*s)) {
19057c478bdstevel@tonic-gate			if (*s == ESCAPE_CHAR)
19067c478bdstevel@tonic-gate				s += 2;
19077c478bdstevel@tonic-gate			else if (*s == EQUAL_CHAR || *s == CLOSE_PAREN_CHAR ||
19087c478bdstevel@tonic-gate			    *s == OPEN_PAREN_CHAR || *s == COMMA_CHAR ||
19097c478bdstevel@tonic-gate			    *s == COLON_CHAR || *s == OPEN_BRACKET ||
19107c478bdstevel@tonic-gate			    *s == CLOSE_BRACKET)
19117c478bdstevel@tonic-gate				break;
19127c478bdstevel@tonic-gate			else
19137c478bdstevel@tonic-gate				s++;
19147c478bdstevel@tonic-gate		}
19157c478bdstevel@tonic-gate		if (s > end_s) {
19167c478bdstevel@tonic-gate			p_error = parse_unmatched_escape;
19177c478bdstevel@tonic-gate			return (NULL);
19187c478bdstevel@tonic-gate		}
19197c478bdstevel@tonic-gate		*t = string_token;
19207c478bdstevel@tonic-gate		*end_token = s;
19217c478bdstevel@tonic-gate		*begin_token = s_begin;
19227c478bdstevel@tonic-gate	}
19237c478bdstevel@tonic-gate	if (s) {
19247c478bdstevel@tonic-gate		while (s < end_s && is_whitespace(*s))
19257c478bdstevel@tonic-gate			s++;
19267c478bdstevel@tonic-gate	}
19277c478bdstevel@tonic-gate	return (s);
19287c478bdstevel@tonic-gate}
19297c478bdstevel@tonic-gate
19307c478bdstevel@tonic-gate/*
19317c478bdstevel@tonic-gate * FUNCTION:	skip_token
19327c478bdstevel@tonic-gate *
19337c478bdstevel@tonic-gate *	Skip over the specified token - An error is set if
19347c478bdstevel@tonic-gate *	next token does not match expected token
19357c478bdstevel@tonic-gate *
19367c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
19377c478bdstevel@tonic-gate *			position of beginning next token after
19387c478bdstevel@tonic-gate *			token
19397c478bdstevel@tonic-gate *
19407c478bdstevel@tonic-gate * INPUT:		the attribute value
19417c478bdstevel@tonic-gate */
19427c478bdstevel@tonic-gate
19437c478bdstevel@tonic-gateconst char *
19447c478bdstevel@tonic-gateskip_token(const char *s, const char *end_s, token_type t)
19457c478bdstevel@tonic-gate{
19467c478bdstevel@tonic-gate	bool_t	match;
19477c478bdstevel@tonic-gate	char	c	= 0;
19487c478bdstevel@tonic-gate
19497c478bdstevel@tonic-gate	if (s == NULL)
19507c478bdstevel@tonic-gate		return (s);
19517c478bdstevel@tonic-gate	while (s < end_s && is_whitespace(*s))
19527c478bdstevel@tonic-gate		s++;
19537c478bdstevel@tonic-gate	c = (s == end_s) ? 0 : *s;
19547c478bdstevel@tonic-gate	switch (t) {
19557c478bdstevel@tonic-gate		case equal_token:
19567c478bdstevel@tonic-gate			match = c == EQUAL_CHAR;
19577c478bdstevel@tonic-gate			if (!match)
19587c478bdstevel@tonic-gate				p_error = parse_equal_expected_error;
19597c478bdstevel@tonic-gate			break;
19607c478bdstevel@tonic-gate		case comma_token:
19617c478bdstevel@tonic-gate			match = c == COMMA_CHAR;
19627c478bdstevel@tonic-gate			if (!match)
19637c478bdstevel@tonic-gate				p_error = parse_comma_expected_error;
19647c478bdstevel@tonic-gate			break;
19657c478bdstevel@tonic-gate		case close_paren_token:
19667c478bdstevel@tonic-gate			match = c == CLOSE_PAREN_CHAR;
19677c478bdstevel@tonic-gate			if (!match)
19687c478bdstevel@tonic-gate				p_error = parse_close_paren_expected_error;
19697c478bdstevel@tonic-gate			break;
19707c478bdstevel@tonic-gate		default:
19717c478bdstevel@tonic-gate			match = FALSE;
19727c478bdstevel@tonic-gate			break;
19737c478bdstevel@tonic-gate	}
19747c478bdstevel@tonic-gate	if (match) {
19757c478bdstevel@tonic-gate		s++;
19767c478bdstevel@tonic-gate		while (s < end_s && is_whitespace(*s))
19777c478bdstevel@tonic-gate			s++;
19787c478bdstevel@tonic-gate	} else {
19797c478bdstevel@tonic-gate		s = NULL;
19807c478bdstevel@tonic-gate	}
19817c478bdstevel@tonic-gate	return (s);
19827c478bdstevel@tonic-gate}
19837c478bdstevel@tonic-gate
19847c478bdstevel@tonic-gate/*
19857c478bdstevel@tonic-gate * FUNCTION:	get_next_extract_format_item
19867c478bdstevel@tonic-gate *
19877c478bdstevel@tonic-gate *	Get the next format token from the string. Note that
19887c478bdstevel@tonic-gate *	get_next_extract_format_item may change the input string.
19897c478bdstevel@tonic-gate *
19907c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
19917c478bdstevel@tonic-gate *			position of beginning next token after
19927c478bdstevel@tonic-gate *			token
19937c478bdstevel@tonic-gate *
19947c478bdstevel@tonic-gate * INPUT:		the format string
19957c478bdstevel@tonic-gate */
19967c478bdstevel@tonic-gate
19977c478bdstevel@tonic-gateconst char *
19987c478bdstevel@tonic-gateget_next_extract_format_item(
19997c478bdstevel@tonic-gate	const char		*begin_fmt,
20007c478bdstevel@tonic-gate	const char		*end_fmt,
20017c478bdstevel@tonic-gate	__nis_mapping_format_t	*fmt)
20027c478bdstevel@tonic-gate{
20037c478bdstevel@tonic-gate	const char	*s		= begin_fmt;
20047c478bdstevel@tonic-gate	const char	*s_end		= end_fmt;
20057c478bdstevel@tonic-gate	bool_t		escape;
20067c478bdstevel@tonic-gate	bool_t		in_range;
20077c478bdstevel@tonic-gate	bool_t		got_char;
20087c478bdstevel@tonic-gate	bool_t		done;
20097c478bdstevel@tonic-gate	int		numRange;
20107c478bdstevel@tonic-gate	char		*lo		= NULL;
20117c478bdstevel@tonic-gate	char		*hi		= NULL;
20127c478bdstevel@tonic-gate	bool_t		skip_ber;
20137c478bdstevel@tonic-gate
20147c478bdstevel@tonic-gate	for (; p_error == no_parse_error; ) {
20157c478bdstevel@tonic-gate		if (s >= s_end)
20167c478bdstevel@tonic-gate			break;
20177c478bdstevel@tonic-gate
20187c478bdstevel@tonic-gate		if (*s == PERCENT_SIGN) {
20197c478bdstevel@tonic-gate			s++;
20207c478bdstevel@tonic-gate			/*
20217c478bdstevel@tonic-gate			 * If the format is %s, it is interpreted
20227c478bdstevel@tonic-gate			 * as a string.
20237c478bdstevel@tonic-gate			 */
20247c478bdstevel@tonic-gate			if (s >= s_end) {
20257c478bdstevel@tonic-gate				p_error = parse_unsupported_format;
20267c478bdstevel@tonic-gate				break;
20277c478bdstevel@tonic-gate			}
20287c478bdstevel@tonic-gate			skip_ber = FALSE;
20297c478bdstevel@tonic-gate			switch (*s) {
20307c478bdstevel@tonic-gate				case 's':
20317c478bdstevel@tonic-gate					fmt->type = mmt_item;
20327c478bdstevel@tonic-gate					break;
20337c478bdstevel@tonic-gate				case 'n':	/* null */
20347c478bdstevel@tonic-gate				case 'x':	/* skip the next element */
20357c478bdstevel@tonic-gate					skip_ber = TRUE;
20367c478bdstevel@tonic-gate					/* FALLTHRU */
20377c478bdstevel@tonic-gate				case 'b':	/* boolean */
20387c478bdstevel@tonic-gate				case 'e':	/* enumerated */
20397c478bdstevel@tonic-gate				case 'i':	/* int */
20407c478bdstevel@tonic-gate				case 'o':	/* octet string */
20417c478bdstevel@tonic-gate				case 'B':	/* bit string */
20427c478bdstevel@tonic-gate					fmt->match.berString = s_strndup(s, 1);
20437c478bdstevel@tonic-gate					fmt->type = skip_ber ?
20447c478bdstevel@tonic-gate						mmt_berstring_null :
20457c478bdstevel@tonic-gate						mmt_berstring;
20467c478bdstevel@tonic-gate					break;
20477c478bdstevel@tonic-gate				case 'a':	/* octet string */
20487c478bdstevel@tonic-gate					if (yp2ldap) {
20497c478bdstevel@tonic-gate						fmt->match.berString =
20507c478bdstevel@tonic-gate							s_strndup(s, 1);
20517c478bdstevel@tonic-gate						fmt->type = skip_ber ?
20527c478bdstevel@tonic-gate							mmt_berstring_null :
20537c478bdstevel@tonic-gate							mmt_berstring;
20547c478bdstevel@tonic-gate						break;
205547b593aToomas Soome					}
205647b593aToomas Soome					/* FALLTHROUGH */
20577c478bdstevel@tonic-gate				case '{':	/* begin sequence */
20587c478bdstevel@tonic-gate				case '[':	/* begin set */
20597c478bdstevel@tonic-gate				case '}':	/* end sequence */
20607c478bdstevel@tonic-gate				case ']':	/* end set */
20617c478bdstevel@tonic-gate				case 'l':	/* length of next item */
20627c478bdstevel@tonic-gate				case 'O':	/* octet string */
20637c478bdstevel@tonic-gate				case 't':	/* tag of next item */
20647c478bdstevel@tonic-gate				case 'T':	/* skip tag of next item */
20657c478bdstevel@tonic-gate				case 'v':	/* seq of strings */
20667c478bdstevel@tonic-gate				case 'V':	/* seq of strings + lengths */
20677c478bdstevel@tonic-gate				default:
20687c478bdstevel@tonic-gate					p_error = parse_bad_ber_format;
20697c478bdstevel@tonic-gate					break;
20707c478bdstevel@tonic-gate			}
20717c478bdstevel@tonic-gate			s++;
20727c478bdstevel@tonic-gate		} else if (*s == ASTERIX_CHAR) {
20737c478bdstevel@tonic-gate			fmt->type = mmt_any;
20747c478bdstevel@tonic-gate			s++;
20757c478bdstevel@tonic-gate			while (s < s_end && *s == ASTERIX_CHAR)
20767c478bdstevel@tonic-gate				s++;
20777c478bdstevel@tonic-gate
20787c478bdstevel@tonic-gate		} else if (*s == OPEN_BRACKET) {
20797c478bdstevel@tonic-gate			escape = FALSE;
20807c478bdstevel@tonic-gate			in_range = FALSE;
20817c478bdstevel@tonic-gate			got_char = FALSE;
20827c478bdstevel@tonic-gate			numRange = 0;
20837c478bdstevel@tonic-gate			done = FALSE;
20847c478bdstevel@tonic-gate			s++;
20857c478bdstevel@tonic-gate			for (; s < s_end; s++) {
20867c478bdstevel@tonic-gate				if (escape) {
20877c478bdstevel@tonic-gate					escape = FALSE;
20887c478bdstevel@tonic-gate				} else if (*s == DASH_CHAR) {
20897c478bdstevel@tonic-gate					if (in_range || !got_char) {
20907c478bdstevel@tonic-gate						p_error = parse_unexpected_dash;
20917c478bdstevel@tonic-gate						break;
20927c478bdstevel@tonic-gate					}
20937c478bdstevel@tonic-gate					in_range = TRUE;
20947c478bdstevel@tonic-gate					got_char = FALSE;
20957c478bdstevel@tonic-gate					continue;
20967c478bdstevel@tonic-gate				} else if (*s == CLOSE_BRACKET) {
20977c478bdstevel@tonic-gate					if (in_range) {
20987c478bdstevel@tonic-gate						p_error = parse_unexpected_dash;
20997c478bdstevel@tonic-gate					}
21007c478bdstevel@tonic-gate					done = TRUE;
21017c478bdstevel@tonic-gate					break;
21027c478bdstevel@tonic-gate				} else if (*s == ESCAPE_CHAR) {
21037c478bdstevel@tonic-gate					escape = TRUE;
21047c478bdstevel@tonic-gate					continue;
21057c478bdstevel@tonic-gate				}
21067c478bdstevel@tonic-gate				if (in_range) {
21077c478bdstevel@tonic-gate					hi[numRange - 1] = *s;
21087c478bdstevel@tonic-gate					in_range = FALSE;
21097c478bdstevel@tonic-gate				} else {
21107c478bdstevel@tonic-gate					lo = s_realloc(lo, numRange + 1);
21117c478bdstevel@tonic-gate					hi = s_realloc(hi, numRange + 1);
21127c478bdstevel@tonic-gate					if (lo == NULL || hi == NULL)
21137c478bdstevel@tonic-gate						break;
21147c478bdstevel@tonic-gate					lo[numRange] = *s;
21157c478bdstevel@tonic-gate					hi[numRange] = *s;
21167c478bdstevel@tonic-gate					numRange++;
21177c478bdstevel@tonic-gate					got_char = TRUE;
21187c478bdstevel@tonic-gate				}
21197c478bdstevel@tonic-gate			}
21207c478bdstevel@tonic-gate			if (p_error != no_parse_error) {
21217c478bdstevel@tonic-gate				break;
21227c478bdstevel@tonic-gate			} else if (!done) {
21237c478bdstevel@tonic-gate				p_error = parse_mismatched_brackets;
21247c478bdstevel@tonic-gate				break;
21257c478bdstevel@tonic-gate			}
21267c478bdstevel@tonic-gate			s++;
21277c478bdstevel@tonic-gate			fmt->type = mmt_single;
21287c478bdstevel@tonic-gate			fmt->match.single.numRange = numRange;
21297c478bdstevel@tonic-gate			fmt->match.single.lo = (unsigned char *)lo;
21307c478bdstevel@tonic-gate			fmt->match.single.hi = (unsigned char *)hi;
21317c478bdstevel@tonic-gate		} else {
21327c478bdstevel@tonic-gate			/* go to next key symbol - copy escaped key symbols */
21337c478bdstevel@tonic-gate			escape = FALSE;
21347c478bdstevel@tonic-gate			done = FALSE;
21357c478bdstevel@tonic-gate			while (s < s_end) {
21367c478bdstevel@tonic-gate				if (escape)
21377c478bdstevel@tonic-gate					escape = FALSE;
21387c478bdstevel@tonic-gate				else {
21397c478bdstevel@tonic-gate				    switch (*s) {
21407c478bdstevel@tonic-gate					case OPEN_BRACKET:
21417c478bdstevel@tonic-gate					case ASTERIX_CHAR:
21427c478bdstevel@tonic-gate					case PERCENT_SIGN:
21437c478bdstevel@tonic-gate						done = TRUE;
21447c478bdstevel@tonic-gate						break;
21457c478bdstevel@tonic-gate					case ESCAPE_CHAR:
21467c478bdstevel@tonic-gate						escape = !escape;
21477c478bdstevel@tonic-gate						break;
21487c478bdstevel@tonic-gate					default:
21497c478bdstevel@tonic-gate						break;
21507c478bdstevel@tonic-gate				    }
21517c478bdstevel@tonic-gate				}
21527c478bdstevel@tonic-gate				if (done)
21537c478bdstevel@tonic-gate					break;
21547c478bdstevel@tonic-gate				s++;
21557c478bdstevel@tonic-gate			}
21567c478bdstevel@tonic-gate			if (escape) {
21577c478bdstevel@tonic-gate				p_error = parse_unmatched_escape;
21587c478bdstevel@tonic-gate				break;
21597c478bdstevel@tonic-gate			}
21607c478bdstevel@tonic-gate			fmt->type = mmt_string;
21617c478bdstevel@tonic-gate			fmt->match.string =
21627c478bdstevel@tonic-gate				s_strndup_esc(begin_fmt, s - begin_fmt);
21637c478bdstevel@tonic-gate			if (fmt->match.string == NULL)
21647c478bdstevel@tonic-gate				break;
21657c478bdstevel@tonic-gate		}
21667c478bdstevel@tonic-gate
21677c478bdstevel@tonic-gate		if (p_error == no_parse_error)
21687c478bdstevel@tonic-gate			return (s);
21697c478bdstevel@tonic-gate	}
21707c478bdstevel@tonic-gate	if (lo != NULL)
21717c478bdstevel@tonic-gate		free(lo);
21727c478bdstevel@tonic-gate	if (hi != NULL)
21737c478bdstevel@tonic-gate		free(hi);
21747c478bdstevel@tonic-gate	return (NULL);
21757c478bdstevel@tonic-gate}
21767c478bdstevel@tonic-gate
21777c478bdstevel@tonic-gate/*
21787c478bdstevel@tonic-gate * FUNCTION:	get_next_print_format_item
21797c478bdstevel@tonic-gate *
21807c478bdstevel@tonic-gate *	Get the next format token from the string
21817c478bdstevel@tonic-gate *
21827c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
21837c478bdstevel@tonic-gate *			position of beginning next token after
21847c478bdstevel@tonic-gate *			token
21857c478bdstevel@tonic-gate *
21867c478bdstevel@tonic-gate * INPUT:		the format string
21877c478bdstevel@tonic-gate */
21887c478bdstevel@tonic-gate
21897c478bdstevel@tonic-gateconst char *
21907c478bdstevel@tonic-gateget_next_print_format_item(
21917c478bdstevel@tonic-gate	const char		*begin_fmt,
21927c478bdstevel@tonic-gate	const char		*end_fmt,
21937c478bdstevel@tonic-gate	__nis_mapping_format_t	*fmt)
21947c478bdstevel@tonic-gate{
21957c478bdstevel@tonic-gate	const char		*s	= begin_fmt;
21967c478bdstevel@tonic-gate	const char		*s_end	= end_fmt;
21977c478bdstevel@tonic-gate	bool_t			skip_ber;
21987c478bdstevel@tonic-gate
21997c478bdstevel@tonic-gate	for (; p_error == no_parse_error; ) {
22007c478bdstevel@tonic-gate		if (s >= s_end) {
22017c478bdstevel@tonic-gate			p_error = parse_internal_error;
22027c478bdstevel@tonic-gate			break;
22037c478bdstevel@tonic-gate		}
22047c478bdstevel@tonic-gate
22057c478bdstevel@tonic-gate		if (*s == PERCENT_SIGN) {
22067c478bdstevel@tonic-gate			s++;
22077c478bdstevel@tonic-gate			if (s >= s_end) {
22087c478bdstevel@tonic-gate				p_error = parse_unsupported_format;
22097c478bdstevel@tonic-gate				break;
22107c478bdstevel@tonic-gate			}
22117c478bdstevel@tonic-gate			skip_ber = FALSE;
22127c478bdstevel@tonic-gate			/*
22137c478bdstevel@tonic-gate			 * If the format is %s, it is interpretted
22147c478bdstevel@tonic-gate			 * as a string.
22157c478bdstevel@tonic-gate			 */
22167c478bdstevel@tonic-gate			switch (*s) {
22177c478bdstevel@tonic-gate				case 's':
22187c478bdstevel@tonic-gate					fmt->type = mmt_item;
22197c478bdstevel@tonic-gate					break;
22207c478bdstevel@tonic-gate				case 'n':	/* null */
22217c478bdstevel@tonic-gate				case 'x':	/* skip the next element */
22227c478bdstevel@tonic-gate					skip_ber = TRUE;
22237c478bdstevel@tonic-gate					/* FALLTHRU */
22247c478bdstevel@tonic-gate				case 'b':	/* boolean */
22257c478bdstevel@tonic-gate				case 'e':	/* enumerated */
22267c478bdstevel@tonic-gate				case 'i':	/* int */
22277c478bdstevel@tonic-gate				case 'o':	/* octet string */
22287c478bdstevel@tonic-gate				case 'B':	/* bit string */
22297c478bdstevel@tonic-gate					fmt->match.berString = s_strndup(s, 1);
22307c478bdstevel@tonic-gate					fmt->type = skip_ber ?
22317c478bdstevel@tonic-gate						mmt_berstring_null :
22327c478bdstevel@tonic-gate						mmt_berstring;
22337c478bdstevel@tonic-gate					break;
22347c478bdstevel@tonic-gate				case '{':	/* begin sequence */
22357c478bdstevel@tonic-gate				case '[':	/* begin set */
22367c478bdstevel@tonic-gate				case '}':	/* end sequence */
22377c478bdstevel@tonic-gate				case ']':	/* end set */
22387c478bdstevel@tonic-gate				case 'a':	/* octet string */
22397c478bdstevel@tonic-gate				case 'l':	/* length of next item */
22407c478bdstevel@tonic-gate				case 'O':	/* octet string */
22417c478bdstevel@tonic-gate				case 't':	/* tag of next item */
22427c478bdstevel@tonic-gate				case 'T':	/* skip tag of next item */
22437c478bdstevel@tonic-gate				case 'v':	/* seq of strings */
22447c478bdstevel@tonic-gate				case 'V':	/* seq of strings + lengths */
22457c478bdstevel@tonic-gate				default:
22467c478bdstevel@tonic-gate					p_error = parse_bad_ber_format;
22477c478bdstevel@tonic-gate					break;
22487c478bdstevel@tonic-gate			}
22497c478bdstevel@tonic-gate			s++;
22507c478bdstevel@tonic-gate		} else {
22517c478bdstevel@tonic-gate			while (s < s_end) {
22527c478bdstevel@tonic-gate				if (*s == PERCENT_SIGN)
22537c478bdstevel@tonic-gate					break;
22547c478bdstevel@tonic-gate				else if (*s == ESCAPE_CHAR)
22557c478bdstevel@tonic-gate					s++;
22567c478bdstevel@tonic-gate				s++;
22577c478bdstevel@tonic-gate			}
22587c478bdstevel@tonic-gate			if (s > s_end) {
22597c478bdstevel@tonic-gate				p_error = parse_unmatched_escape;
22607c478bdstevel@tonic-gate				break;
22617c478bdstevel@tonic-gate			}
22627c478bdstevel@tonic-gate			fmt->match.string =
22637c478bdstevel@tonic-gate				s_strndup_esc(begin_fmt, s - begin_fmt);
22647c478bdstevel@tonic-gate			if (fmt->match.string == NULL)
22657c478bdstevel@tonic-gate				break;
22667c478bdstevel@tonic-gate			fmt->type = mmt_string;
22677c478bdstevel@tonic-gate		}
22687c478bdstevel@tonic-gate		if (p_error == no_parse_error)
22697c478bdstevel@tonic-gate			return (s);
22707c478bdstevel@tonic-gate	}
22717c478bdstevel@tonic-gate	return (NULL);
22727c478bdstevel@tonic-gate}
22737c478bdstevel@tonic-gate
22747c478bdstevel@tonic-gate/*
22757c478bdstevel@tonic-gate * FUNCTION:	get_ldap_filter
22767c478bdstevel@tonic-gate *
22777c478bdstevel@tonic-gate *	Gets an LDAP filter - see RFC 2254. Note that this does not
22787c478bdstevel@tonic-gate *	determine if the ldap filter is valid. This only determines
22797c478bdstevel@tonic-gate *	that the parentheses are balanced.
22807c478bdstevel@tonic-gate *
22817c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
22827c478bdstevel@tonic-gate *			position of beginning next token after
22837c478bdstevel@tonic-gate *			filter
22847c478bdstevel@tonic-gate *
22857c478bdstevel@tonic-gate * INPUT:		the begin and end of string
22867c478bdstevel@tonic-gate *
22877c478bdstevel@tonic-gate * OUTPUT:		the begin and end of LDAP filter
22887c478bdstevel@tonic-gate *
22897c478bdstevel@tonic-gate */
22907c478bdstevel@tonic-gate
22917c478bdstevel@tonic-gateconst char *
22927c478bdstevel@tonic-gateget_ldap_filter(const char **begin, const char **end)
22937c478bdstevel@tonic-gate{
22947c478bdstevel@tonic-gate	const char	*s		= *begin;
22957c478bdstevel@tonic-gate	const char	*s_begin;
22967c478bdstevel@tonic-gate	const char	*s_end		= *end;
22977c478bdstevel@tonic-gate	int		nParen;
22987c478bdstevel@tonic-gate
22997c478bdstevel@tonic-gate	for (; p_error == no_parse_error; ) {
23007c478bdstevel@tonic-gate		while (s < s_end && is_whitespace(*s))
23017c478bdstevel@tonic-gate			s++;
23027c478bdstevel@tonic-gate		if (s == s_end) {
23037c478bdstevel@tonic-gate			s = NULL;
23047c478bdstevel@tonic-gate			break;
23057c478bdstevel@tonic-gate		}
23067c478bdstevel@tonic-gate
23077c478bdstevel@tonic-gate		s_begin = s;
23087c478bdstevel@tonic-gate		if (*s == OPEN_PAREN_CHAR) {
23097c478bdstevel@tonic-gate			nParen = 1;
23107c478bdstevel@tonic-gate			s++;
23117c478bdstevel@tonic-gate			while (s < s_end && nParen > 0) {
23127c478bdstevel@tonic-gate				if (*s == ESCAPE_CHAR)
23137c478bdstevel@tonic-gate					s++;
23147c478bdstevel@tonic-gate				else if (*s == OPEN_PAREN_CHAR)
23157c478bdstevel@tonic-gate					nParen++;
23167c478bdstevel@tonic-gate				else if (*s == CLOSE_PAREN_CHAR)
23177c478bdstevel@tonic-gate					nParen--;
23187c478bdstevel@tonic-gate				s++;
23197c478bdstevel@tonic-gate			}
23207c478bdstevel@tonic-gate			if (nParen == 0) {
23217c478bdstevel@tonic-gate				*begin = s_begin;
23227c478bdstevel@tonic-gate				*end = s;
23237c478bdstevel@tonic-gate				while (s < s_end && is_whitespace(*s))
23247c478bdstevel@tonic-gate					s++;
23257c478bdstevel@tonic-gate			} else
23267c478bdstevel@tonic-gate				s = NULL;
23277c478bdstevel@tonic-gate		} else
23287c478bdstevel@tonic-gate			s = NULL;
23297c478bdstevel@tonic-gate		if (p_error == no_parse_error)
23307c478bdstevel@tonic-gate			break;
23317c478bdstevel@tonic-gate	}
23327c478bdstevel@tonic-gate	if (s == NULL)
23337c478bdstevel@tonic-gate		p_error = parse_invalid_ldap_search_filter;
23347c478bdstevel@tonic-gate
23357c478bdstevel@tonic-gate	return (s);
23367c478bdstevel@tonic-gate}
23377c478bdstevel@tonic-gate
23387c478bdstevel@tonic-gate/*
23397c478bdstevel@tonic-gate * FUNCTION:	get_ava_list
23407c478bdstevel@tonic-gate *
23417c478bdstevel@tonic-gate *	Gets an attribute value assertion list
23427c478bdstevel@tonic-gate *
23437c478bdstevel@tonic-gate * RETURN VALUE:	NULL if error
23447c478bdstevel@tonic-gate *			position of beginning next token after
23457c478bdstevel@tonic-gate *			after attribute assertion
23467c478bdstevel@tonic-gate *
23477c478bdstevel@tonic-gate * INPUT:		the begin and end of string
23487c478bdstevel@tonic-gate *			Indicator if ava list is part of a nisplus
23497c478bdstevel@tonic-gate *			item
23507c478bdstevel@tonic-gate *
23517c478bdstevel@tonic-gate * OUTPUT:		the begin and end of LDAP filter
23527c478bdstevel@tonic-gate *
23537c478bdstevel@tonic-gate */
23547c478bdstevel@tonic-gate
23557c478bdstevel@tonic-gateconst char *
23567c478bdstevel@tonic-gateget_ava_list(const char **begin, const char **end, bool_t end_nisplus)
23577c478bdstevel@tonic-gate{
23587c478bdstevel@tonic-gate	const char	*s		= *begin;
23597c478bdstevel@tonic-gate	const char	*s_begin;
23607c478bdstevel@tonic-gate	const char	*s_end		= *end;
23617c478bdstevel@tonic-gate	bool_t		in_quote;
23627c478bdstevel@tonic-gate	bool_t		got_equal;
23637c478bdstevel@tonic-gate	bool_t		got_data;
23647c478bdstevel@tonic-gate
23657c478bdstevel@tonic-gate	for (; p_error == no_parse_error; ) {
23667c478bdstevel@tonic-gate		while (s < s_end && is_whitespace(*s))
23677c478bdstevel@tonic-gate			s++;
23687c478bdstevel@tonic-gate		if (s == s_end) {
23697c478bdstevel@tonic-gate			s = NULL;
23707c478bdstevel@tonic-gate			break;
23717c478bdstevel@tonic-gate		}
23727c478bdstevel@tonic-gate
23737c478bdstevel@tonic-gate		in_quote = FALSE;
23747c478bdstevel@tonic-gate		got_equal = FALSE;
23757c478bdstevel@tonic-gate		got_data = FALSE;
23767c478bdstevel@tonic-gate		s_begin = s;
23777c478bdstevel@tonic-gate		while (s < s_end) {
23787c478bdstevel@tonic-gate			if (*s == ESCAPE_CHAR) {
23797c478bdstevel@tonic-gate			    s++;
23807c478bdstevel@tonic-gate			    got_data = TRUE;
23817c478bdstevel@tonic-gate			} else if (*s == DOUBLE_QUOTE_CHAR) {
23827c478bdstevel@tonic-gate			    in_quote = !in_quote;
23837c478bdstevel@tonic-gate			    got_data = TRUE;
23847c478bdstevel@tonic-gate			} else if (in_quote)
23857c478bdstevel@tonic-gate				;
23867c478bdstevel@tonic-gate			else if (*s == EQUAL_CHAR) {
23877c478bdstevel@tonic-gate			    if (end_nisplus && got_data && got_equal)
23887c478bdstevel@tonic-gate				break;
23897c478bdstevel@tonic-gate			    if (!got_data || got_equal) {
23907c478bdstevel@tonic-gate				got_equal = FALSE;
23917c478bdstevel@tonic-gate				break;
23927c478bdstevel@tonic-gate			    }
23937c478bdstevel@tonic-gate			    got_equal = TRUE;
23947c478bdstevel@tonic-gate			    got_data = FALSE;
23957c478bdstevel@tonic-gate			} else if (*s == COMMA_CHAR) {
23967c478bdstevel@tonic-gate			    if (!got_data || !got_equal)
23977c478bdstevel@tonic-gate				break;
23987c478bdstevel@tonic-gate			    got_data = FALSE;
23997c478bdstevel@tonic-gate			    got_equal = FALSE;
24007c478bdstevel@tonic-gate			} else if (is_whitespace(*s))
24017c478bdstevel@tonic-gate				;
24027c478bdstevel@tonic-gate			else
24037c478bdstevel@tonic-gate				got_data = TRUE;
24047c478bdstevel@tonic-gate			s++;
24057c478bdstevel@tonic-gate		}
24067c478bdstevel@tonic-gate		if (!got_data || !got_equal || in_quote)
24077c478bdstevel@tonic-gate			s = NULL;
24087c478bdstevel@tonic-gate		else {
24097c478bdstevel@tonic-gate			*begin = s_begin;
24107c478bdstevel@tonic-gate			*end = s;
24117c478bdstevel@tonic-gate			while (s < s_end && is_whitespace(*s))
24127c478bdstevel@tonic-gate				s++;
24137c478bdstevel@tonic-gate		}
24147c478bdstevel@tonic-gate		if (p_error == no_parse_error)
24157c478bdstevel@tonic-gate			break;
24167c478bdstevel@tonic-gate	}
24177c478bdstevel@tonic-gate	if (s == NULL)
24187c478bdstevel@tonic-gate		p_error = parse_invalid_ldap_search_filter;
24197c478bdstevel@tonic-gate
24207c478bdstevel@tonic-gate	return (s);
24217c478bdstevel@tonic-gate}
24227c478bdstevel@tonic-gate
24237c478bdstevel@tonic-gate/* Utility functions */
24247c478bdstevel@tonic-gatebool_t
24257c478bdstevel@tonic-gatevalidate_dn(const char *s, int len)
24267c478bdstevel@tonic-gate{
24277c478bdstevel@tonic-gate	const char *end = s + len;
24287c478bdstevel@tonic-gate	bool_t	valid;
24297c478bdstevel@tonic-gate
24307c478bdstevel@tonic-gate	valid = skip_get_dn(s, end) == end;
24317c478bdstevel@tonic-gate
24327c478bdstevel@tonic-gate	if (!valid)
24337c478bdstevel@tonic-gate		p_error = parse_bad_dn;
24347c478bdstevel@tonic-gate	return (valid);
24357c478bdstevel@tonic-gate}
24367c478bdstevel@tonic-gate
24377c478bdstevel@tonic-gatebool_t
24387c478bdstevel@tonic-gatevalidate_ldap_filter(const char *s, const char *end)
24397c478bdstevel@tonic-gate{
24407c478bdstevel@tonic-gate	const char	*s_begin;
24417c478bdstevel@tonic-gate	const char	*s_end;
24427c478bdstevel@tonic-gate
24437c478bdstevel@tonic-gate	s_begin = s;
24447c478bdstevel@tonic-gate	s_end = end;
24457c478bdstevel@tonic-gate
24467c478bdstevel@tonic-gate	if (*s == OPEN_PAREN_CHAR) {
24477c478bdstevel@tonic-gate		s = get_ldap_filter(&s_begin, &s_end);
24487c478bdstevel@tonic-gate	} else {
24497c478bdstevel@tonic-gate		/* Assume an attribute value list */
24507c478bdstevel@tonic-gate		s = get_ava_list(&s_begin, &s_end, FALSE);
24517c478bdstevel@tonic-gate	}
24527c478bdstevel@tonic-gate	if (s == NULL || s_end != end)
24537c478bdstevel@tonic-gate		p_error = parse_invalid_ldap_search_filter;
24547c478bdstevel@tonic-gate
24557c478bdstevel@tonic-gate	return (p_error == no_parse_error);
24567c478bdstevel@tonic-gate}
24577c478bdstevel@tonic-gate
24587c478bdstevel@tonic-gatechar *
24597c478bdstevel@tonic-gates_strndup(const char *s, int n)
24607c478bdstevel@tonic-gate{
24617c478bdstevel@tonic-gate	char *d = (char *)malloc(n + 1);
24627c478bdstevel@tonic-gate
24637c478bdstevel@tonic-gate	if (d != NULL) {
24647c478bdstevel@tonic-gate		(void) memcpy(d, s, n);
24657c478bdstevel@tonic-gate		d[n] = '\0';
24667c478bdstevel@tonic-gate	} else {
24677c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
24687c478bdstevel@tonic-gate	}
24697c478bdstevel@tonic-gate
24707c478bdstevel@tonic-gate	return (d);
24717c478bdstevel@tonic-gate}
24727c478bdstevel@tonic-gate
24737c478bdstevel@tonic-gatechar *
24747c478bdstevel@tonic-gates_strndup_esc(const char *s, int n)
24757c478bdstevel@tonic-gate{
24767c478bdstevel@tonic-gate	char	*d	= (char *)malloc(n + 1);
24777c478bdstevel@tonic-gate	int	i;
24787c478bdstevel@tonic-gate	int	j;
24797c478bdstevel@tonic-gate
24807c478bdstevel@tonic-gate	if (d != NULL) {
24817c478bdstevel@tonic-gate		for (i = 0, j = 0; i < n; i++) {
24827c478bdstevel@tonic-gate			if (s[i] == ESCAPE_CHAR)
24837c478bdstevel@tonic-gate				i++;
24847c478bdstevel@tonic-gate			d[j++] = s[i];
24857c478bdstevel@tonic-gate		}
24867c478bdstevel@tonic-gate		d[j] = '\0';
24877c478bdstevel@tonic-gate	} else {
24887c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
24897c478bdstevel@tonic-gate	}
24907c478bdstevel@tonic-gate
24917c478bdstevel@tonic-gate	return (d);
24927c478bdstevel@tonic-gate}
24937c478bdstevel@tonic-gate
24947c478bdstevel@tonic-gatevoid *
24957c478bdstevel@tonic-gates_calloc(size_t n, size_t size)
24967c478bdstevel@tonic-gate{
24977c478bdstevel@tonic-gate	void *d = (char *)calloc(n, size);
24987c478bdstevel@tonic-gate
24997c478bdstevel@tonic-gate	if (d == NULL) {
25007c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
25017c478bdstevel@tonic-gate	}
25027c478bdstevel@tonic-gate
25037c478bdstevel@tonic-gate	return (d);
25047c478bdstevel@tonic-gate}
25057c478bdstevel@tonic-gate
25067c478bdstevel@tonic-gatevoid *
25077c478bdstevel@tonic-gates_malloc(size_t size)
25087c478bdstevel@tonic-gate{
25097c478bdstevel@tonic-gate	void *d = malloc(size);
25107c478bdstevel@tonic-gate	if (d == NULL)
25117c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
25127c478bdstevel@tonic-gate	return (d);
25137c478bdstevel@tonic-gate}
25147c478bdstevel@tonic-gate
25157c478bdstevel@tonic-gatevoid *
25167c478bdstevel@tonic-gates_realloc(void *s, size_t size)
25177c478bdstevel@tonic-gate{
25187c478bdstevel@tonic-gate	s = realloc(s, size);
25197c478bdstevel@tonic-gate	if (s == NULL)
25207c478bdstevel@tonic-gate		p_error = parse_no_mem_error;
25217c478bdstevel@tonic-gate	return (s);
25227c478bdstevel@tonic-gate}
25237c478bdstevel@tonic-gate
25247c478bdstevel@tonic-gatechar *
25257c478bdstevel@tonic-gates_strdup(const char *s)
25267c478bdstevel@tonic-gate{
25277c478bdstevel@tonic-gate	return (s != NULL ? s_strndup(s, strlen(s)) : NULL);
25287c478bdstevel@tonic-gate}
25297c478bdstevel@tonic-gate
25307c478bdstevel@tonic-gatebool_t
25317c478bdstevel@tonic-gateis_whitespace(int c)
25327c478bdstevel@tonic-gate{
25337c478bdstevel@tonic-gate	return (c == ' ' || c == '\t');
25347c478bdstevel@tonic-gate}
25357c478bdstevel@tonic-gate
25367c478bdstevel@tonic-gatebool_t
25377c478bdstevel@tonic-gateis_string_ok(char *buffer, int buflen)
25387c478bdstevel@tonic-gate{
25397c478bdstevel@tonic-gate	int i;
25407c478bdstevel@tonic-gate
25417c478bdstevel@tonic-gate	if (buffer == NULL)
25427c478bdstevel@tonic-gate		return (FALSE);
25437c478bdstevel@tonic-gate
25447c478bdstevel@tonic-gate	for (i = 0; i < buflen; i++) {
25457c478bdstevel@tonic-gate		if (!is_whitespace(buffer[i])) {
25467c478bdstevel@tonic-gate			if (buffer[i] == POUND_SIGN)
25477c478bdstevel@tonic-gate				return (TRUE);
25487c478bdstevel@tonic-gate			else
25497c478bdstevel@tonic-gate				return (FALSE);
25507c478bdstevel@tonic-gate		}
25517c478bdstevel@tonic-gate	}
25527c478bdstevel@tonic-gate	return (TRUE);
25537c478bdstevel@tonic-gate}
25547c478bdstevel@tonic-gate
25557c478bdstevel@tonic-gate/*
25567c478bdstevel@tonic-gate * Returns true if the first string is contained at the beginning of the
25577c478bdstevel@tonic-gate * second string. Otherwise returns false.
25587c478bdstevel@tonic-gate */
25597c478bdstevel@tonic-gate
25607c478bdstevel@tonic-gatebool_t
25617c478bdstevel@tonic-gatecontains_string(const char *s1, const char *s2)
25627c478bdstevel@tonic-gate{
25637c478bdstevel@tonic-gate	return (strncasecmp(s1, s2, strlen(s1)) == 0);
25647c478bdstevel@tonic-gate}
25657c478bdstevel@tonic-gate
25667c478bdstevel@tonic-gate/*
25677c478bdstevel@tonic-gate * Returns the next character position in the second string, if the first
25687c478bdstevel@tonic-gate * string is contained at the beginning of the second string. Otherwise
25697c478bdstevel@tonic-gate * returns NULL.
25707c478bdstevel@tonic-gate */
25717c478bdstevel@tonic-gate
25727c478bdstevel@tonic-gateconst char *
25737c478bdstevel@tonic-gateskip_string(const char *s1, const char *s2, int len)
25747c478bdstevel@tonic-gate{
25757c478bdstevel@tonic-gate	int len1 = strlen(s1);
25767c478bdstevel@tonic-gate
25777c478bdstevel@tonic-gate	if (len >= len1 && strncasecmp(s1, s2, strlen(s1)) == 0)
25787c478bdstevel@tonic-gate		return (s2 + len1);
25797c478bdstevel@tonic-gate	else
25807c478bdstevel@tonic-gate		return (NULL);
25817c478bdstevel@tonic-gate}
25827c478bdstevel@tonic-gate
25837c478bdstevel@tonic-gate/*
25847c478bdstevel@tonic-gate * The second string is not necessarily null terminated.
25857c478bdstevel@tonic-gate * same_string returns true if the second string matches the first.
25867c478bdstevel@tonic-gate * Otherwise returns false.
25877c478bdstevel@tonic-gate */
25887c478bdstevel@tonic-gate
25897c478bdstevel@tonic-gatebool_t
25907c478bdstevel@tonic-gatesame_string(const char *s1, const char *s2, int len)
25917c478bdstevel@tonic-gate{
25927c478bdstevel@tonic-gate	int len1 = strlen(s1);
25937c478bdstevel@tonic-gate
25947c478bdstevel@tonic-gate	return (len1 == len && strncasecmp(s1, s2, len1) == 0);
25957c478bdstevel@tonic-gate}
25967c478bdstevel@tonic-gate
25977c478bdstevel@tonic-gatevoid
25987c478bdstevel@tonic-gatereport_error(const char	*str, const char *attr)
25997c478bdstevel@tonic-gate{
26007c478bdstevel@tonic-gate	char	fmt_buf[1024];
26017c478bdstevel@tonic-gate	int	pos		= 0;
26027c478bdstevel@tonic-gate
26037c478bdstevel@tonic-gate	if (command_line_source != NULL) {
26047c478bdstevel@tonic-gate		snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing %s: ",
26057c478bdstevel@tonic-gate			command_line_source);
26067c478bdstevel@tonic-gate		pos = strlen(fmt_buf);
26077c478bdstevel@tonic-gate	} else if (file_source != NULL) {
26087c478bdstevel@tonic-gate		snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing file '%s': ",
26097c478bdstevel@tonic-gate			file_source);
26107c478bdstevel@tonic-gate		pos = strlen(fmt_buf);
26117c478bdstevel@tonic-gate	} else if (ldap_source != NULL) {
26127c478bdstevel@tonic-gate		snprintf(