xref: /titanic_44/usr/src/lib/libnisdb/nis_parse_ldap_conf.c (revision ead1f93ee620d7580f7e53350fe5a884fc4f158a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
54a190493Ssdussud  * Common Development and Distribution License (the "License").
64a190493Ssdussud  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*b9175c69SKenjiro Tsuji  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <string.h>
287c478bd9Sstevel@tonic-gate #include <stdlib.h>
297c478bd9Sstevel@tonic-gate #include <ctype.h>
307c478bd9Sstevel@tonic-gate #include <fcntl.h>
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <errno.h>
337c478bd9Sstevel@tonic-gate #include <locale.h>
347c478bd9Sstevel@tonic-gate #include <sys/stat.h>
357c478bd9Sstevel@tonic-gate #include <lber.h>
367c478bd9Sstevel@tonic-gate #include <ldap.h>
377c478bd9Sstevel@tonic-gate #include <deflt.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include "ldap_map.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include "ldap_parse.h"
427c478bd9Sstevel@tonic-gate #include "ldap_glob.h"
437c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info	proxyInfo		=
467c478bd9Sstevel@tonic-gate 	{NULL, (auth_method_t)NO_VALUE_SET, (tls_method_t)NO_VALUE_SET, NULL,
477c478bd9Sstevel@tonic-gate 		NULL, NULL, NULL, NULL, (follow_referral_t)NO_VALUE_SET};
487c478bd9Sstevel@tonic-gate __nis_config_t		ldapConfig;
497c478bd9Sstevel@tonic-gate __nisdb_table_mapping_t ldapDBTableMapping;
507c478bd9Sstevel@tonic-gate __nis_table_mapping_t	*ldapTableMapping	= NULL;
517c478bd9Sstevel@tonic-gate __yp_domain_context_t	ypDomains;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate parse_error		p_error			= no_parse_error;
547c478bd9Sstevel@tonic-gate int			cur_line_num		= 0;
557c478bd9Sstevel@tonic-gate int			start_line_num		= 0;
567c478bd9Sstevel@tonic-gate int			seq_num 		= 0;
577c478bd9Sstevel@tonic-gate const char		*warn_file		= NULL;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate char			_key_val[38];
607c478bd9Sstevel@tonic-gate const char		*command_line_source	= NULL;
617c478bd9Sstevel@tonic-gate const char		*file_source		= NULL;
627c478bd9Sstevel@tonic-gate const char		*ldap_source		= NULL;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate static
657c478bd9Sstevel@tonic-gate const char *const	*cmdline_config		= NULL;
667c478bd9Sstevel@tonic-gate static bool_t		got_config_data		= FALSE;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* high level parsing functions functions */
697c478bd9Sstevel@tonic-gate static int parse_ldap_cmd_line(const char *const *cmdline_options,
707c478bd9Sstevel@tonic-gate     __nis_ldap_proxy_info *proxy_info, __nis_config_t *nis_config,
717c478bd9Sstevel@tonic-gate     __nis_table_mapping_t **table_mapping, __nis_config_info_t *config_info,
727c478bd9Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
737c478bd9Sstevel@tonic-gate static int parse_ldap_default_conf(__nis_ldap_proxy_info *proxy_info,
747c478bd9Sstevel@tonic-gate     __nis_config_t *nis_config, __nis_config_info_t *config_info,
757c478bd9Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
767c478bd9Sstevel@tonic-gate static int parse_ldap_config_file(const char *config_file,
777c478bd9Sstevel@tonic-gate     __nis_ldap_proxy_info *proxy_info, __nis_config_t *nis_config,
787c478bd9Sstevel@tonic-gate     __nis_table_mapping_t **table_mapping, __nis_config_info_t *config_info,
797c478bd9Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
807c478bd9Sstevel@tonic-gate static int parse_ldap_config_dn_attrs(__nis_ldap_proxy_info *proxy_info,
817c478bd9Sstevel@tonic-gate     __nis_config_t *nis_config, __nis_table_mapping_t **table_mapping,
827c478bd9Sstevel@tonic-gate     __nis_config_info_t *config_info, __nisdb_table_mapping_t *table_info);
837c478bd9Sstevel@tonic-gate static int yp_parse_ldap_default_conf(__nis_ldap_proxy_info *proxy_info,
847c478bd9Sstevel@tonic-gate 	__nis_config_t *nis_config, __nis_config_info_t *config_info,
857c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t *table_info);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* helper functions */
897c478bd9Sstevel@tonic-gate static config_key get_attrib_num_cmdline(const char *s,
907c478bd9Sstevel@tonic-gate     const char **begin_s, const char **end_s);
917c478bd9Sstevel@tonic-gate static config_key get_file_attr_val(int fd, char **attr_val);
927c478bd9Sstevel@tonic-gate static void get_attribute_list(
937c478bd9Sstevel@tonic-gate 	const __nis_ldap_proxy_info *proxy_info,
947c478bd9Sstevel@tonic-gate 	const __nis_config_t *nis_config,
957c478bd9Sstevel@tonic-gate 	const __nis_config_info_t *config_info,
967c478bd9Sstevel@tonic-gate 	const __nisdb_table_mapping_t *table_info,
977c478bd9Sstevel@tonic-gate 	char **ldap_config_attributes);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_migration
1017c478bd9Sstevel@tonic-gate  *
1027c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP. The values are first
1037c478bd9Sstevel@tonic-gate  *	obtained from the command line, secondly from the preference
1047c478bd9Sstevel@tonic-gate  *	file, and finally from an LDAP profile (if so configured in
1057c478bd9Sstevel@tonic-gate  *	the command line or preference file). Any unset values will
1067c478bd9Sstevel@tonic-gate  *	be set to their default values.
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  *	If no command line options, no settings in the /etc/default
1097c478bd9Sstevel@tonic-gate  *  configuration file, and no mapping file, then no mapping
1107c478bd9Sstevel@tonic-gate  *  should be used.
1117c478bd9Sstevel@tonic-gate  *
1127c478bd9Sstevel@tonic-gate  * RETURN VALUE:
1137c478bd9Sstevel@tonic-gate  *			0	Success
1147c478bd9Sstevel@tonic-gate  *			-1	Config file stat/open or parse error
1157c478bd9Sstevel@tonic-gate  *			1	No mapping should be used.
1167c478bd9Sstevel@tonic-gate  *
1177c478bd9Sstevel@tonic-gate  * INPUT:		command line parameters, configuration file
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate int
parse_ldap_migration(const char * const * cmdline_options,const char * config_file)1217c478bd9Sstevel@tonic-gate parse_ldap_migration(
1227c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options,
1237c478bd9Sstevel@tonic-gate 	const char		*config_file)
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate 	int			rc	= 0;
1267c478bd9Sstevel@tonic-gate 	__nis_config_info_t	config_info
1277c478bd9Sstevel@tonic-gate 				= {NULL, NULL, (auth_method_t)NO_VALUE_SET,
1287c478bd9Sstevel@tonic-gate 					(tls_method_t)NO_VALUE_SET, NULL,
1297c478bd9Sstevel@tonic-gate 					NULL, NULL};
1307c478bd9Sstevel@tonic-gate 	struct stat		buf;
1317c478bd9Sstevel@tonic-gate 	int i = 0;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	p_error = no_parse_error;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	if (verbose)
1367c478bd9Sstevel@tonic-gate 		report_info("Getting LDAP configuration", NULL);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	initialize_parse_structs(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if (yp2ldap)
1417c478bd9Sstevel@tonic-gate 		initialize_yp_parse_structs(&ypDomains);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	if (cmdline_options != NULL) {
1447c478bd9Sstevel@tonic-gate 		got_config_data = TRUE;
1457c478bd9Sstevel@tonic-gate 		/* NIS to LDAP does not read command line attributes */
1467c478bd9Sstevel@tonic-gate 		if (!yp2ldap)
1477c478bd9Sstevel@tonic-gate 			rc = parse_ldap_cmd_line(cmdline_options, &proxyInfo,
1487c478bd9Sstevel@tonic-gate 			    &ldapConfig, &ldapTableMapping, &config_info,
1497c478bd9Sstevel@tonic-gate 			    &ldapDBTableMapping);
1507c478bd9Sstevel@tonic-gate 		else
1517c478bd9Sstevel@tonic-gate 			rc = 0;
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (rc == 0) {
1557c478bd9Sstevel@tonic-gate 		if (yp2ldap)
1567c478bd9Sstevel@tonic-gate 			rc = yp_parse_ldap_default_conf(&proxyInfo, &ldapConfig,
1577c478bd9Sstevel@tonic-gate 			    &config_info, &ldapDBTableMapping);
1587c478bd9Sstevel@tonic-gate 		else
1597c478bd9Sstevel@tonic-gate 			rc = parse_ldap_default_conf(&proxyInfo, &ldapConfig,
1607c478bd9Sstevel@tonic-gate 			    &config_info, &ldapDBTableMapping);
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (config_file == NULL) {
1647c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
1657c478bd9Sstevel@tonic-gate 			if (stat(YP_DEFAULT_MAPPING_FILE, &buf) == 0)
1667c478bd9Sstevel@tonic-gate 				config_file = YP_DEFAULT_MAPPING_FILE;
1677c478bd9Sstevel@tonic-gate 		} else {
1687c478bd9Sstevel@tonic-gate 			if (stat(DEFAULT_MAPPING_FILE, &buf) == 0)
1697c478bd9Sstevel@tonic-gate 				config_file = DEFAULT_MAPPING_FILE;
1707c478bd9Sstevel@tonic-gate 		}
1717c478bd9Sstevel@tonic-gate 	}
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	if (rc == 0 && config_file != NULL) {
1747c478bd9Sstevel@tonic-gate 		got_config_data = TRUE;
1757c478bd9Sstevel@tonic-gate 		warn_file = config_file;
1767c478bd9Sstevel@tonic-gate 		cmdline_config = cmdline_options;
1777c478bd9Sstevel@tonic-gate 		if (yp2ldap)
1787c478bd9Sstevel@tonic-gate 			rc = yp_parse_ldap_config_file(config_file, &proxyInfo,
1797c478bd9Sstevel@tonic-gate 			    &ldapConfig, &ldapTableMapping, &config_info,
1807c478bd9Sstevel@tonic-gate 			    &ldapDBTableMapping, &ypDomains);
1817c478bd9Sstevel@tonic-gate 		else
1827c478bd9Sstevel@tonic-gate 			rc = parse_ldap_config_file(config_file, &proxyInfo,
1837c478bd9Sstevel@tonic-gate 			    &ldapConfig, &ldapTableMapping, &config_info,
1847c478bd9Sstevel@tonic-gate 			    &ldapDBTableMapping);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 		warn_file = NULL;
1877c478bd9Sstevel@tonic-gate 		cmdline_config = NULL;
1887c478bd9Sstevel@tonic-gate 	}
1897c478bd9Sstevel@tonic-gate 	if (rc == 0 && (config_info.config_dn != NULL) &&
1907c478bd9Sstevel@tonic-gate 	    (config_info.config_dn[0] != '\0')) {
1917c478bd9Sstevel@tonic-gate 		rc = parse_ldap_config_dn_attrs(&proxyInfo,
1927c478bd9Sstevel@tonic-gate 		    &ldapConfig, &ldapTableMapping, &config_info,
1937c478bd9Sstevel@tonic-gate 		    &ldapDBTableMapping);
1947c478bd9Sstevel@tonic-gate 	}
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	free_config_info(&config_info);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (rc == 0 && got_config_data == FALSE)
1997c478bd9Sstevel@tonic-gate 		rc = 1;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	set_default_values(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (yp2ldap == 1 && rc == 0) {
2047c478bd9Sstevel@tonic-gate 		rc = second_parser_pass(&ldapTableMapping);
2057c478bd9Sstevel@tonic-gate 		if (rc == 0)
2067c478bd9Sstevel@tonic-gate 			rc = final_parser_pass(&ldapTableMapping, &ypDomains);
2077c478bd9Sstevel@tonic-gate 		if (rc == -2)
2087c478bd9Sstevel@tonic-gate 			return (-1);
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	if (rc == 0)
2127c478bd9Sstevel@tonic-gate 		rc = finish_parse(&proxyInfo, &ldapTableMapping);
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	if (rc == 0)
2157c478bd9Sstevel@tonic-gate 		rc = linked2hash(ldapTableMapping);
2167c478bd9Sstevel@tonic-gate 
2174a190493Ssdussud 	if ((rc == 0) && yptol_mode)
2184a190493Ssdussud 		rc = map_id_list_init();
2194a190493Ssdussud 
2207c478bd9Sstevel@tonic-gate 	if (rc != 0) {
2217c478bd9Sstevel@tonic-gate 		free_parse_structs();
2227c478bd9Sstevel@tonic-gate 	} else if (verbose)
2237c478bd9Sstevel@tonic-gate 		report_info("LDAP configuration complete", NULL);
2247c478bd9Sstevel@tonic-gate 	return (rc);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_cmd_line
2297c478bd9Sstevel@tonic-gate  *
2307c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
2317c478bd9Sstevel@tonic-gate  *
2327c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
2337c478bd9Sstevel@tonic-gate  *
2347c478bd9Sstevel@tonic-gate  * INPUT:		command line values
2357c478bd9Sstevel@tonic-gate  */
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate static int
parse_ldap_cmd_line(const char * const * cmdline_options,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)2387c478bd9Sstevel@tonic-gate parse_ldap_cmd_line(
2397c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options,
2407c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
2417c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
2427c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
2437c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
2447c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate 	int		rc = 0;
2477c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
2487c478bd9Sstevel@tonic-gate 	const char	*begin_s;
2497c478bd9Sstevel@tonic-gate 	const char	*end_s;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if (verbose)
2527c478bd9Sstevel@tonic-gate 		report_info("Command line values: ", NULL);
2537c478bd9Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
2547c478bd9Sstevel@tonic-gate 		if (verbose)
2557c478bd9Sstevel@tonic-gate 			report_info("\t", *cmdline_options);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
2587c478bd9Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
2597c478bd9Sstevel@tonic-gate 		if (attrib_num == key_bad) {
2607c478bd9Sstevel@tonic-gate 			command_line_source = "command line";
2617c478bd9Sstevel@tonic-gate 			report_error(*cmdline_options, NULL);
2627c478bd9Sstevel@tonic-gate 			command_line_source = NULL;
2637c478bd9Sstevel@tonic-gate 			rc = -1;
2647c478bd9Sstevel@tonic-gate 			break;
2657c478bd9Sstevel@tonic-gate 		} else if (IS_CONFIG_KEYWORD(attrib_num)) {
2667c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
2677c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, config_info);
2687c478bd9Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
2697c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
2707c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, proxy_info);
2717c478bd9Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
2727c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
2737c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, nis_config,
2747c478bd9Sstevel@tonic-gate 			    table_info);
2757c478bd9Sstevel@tonic-gate 		} else {
2767c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
2777c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, table_mapping);
2787c478bd9Sstevel@tonic-gate 		}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 		if (rc < 0) {
2817c478bd9Sstevel@tonic-gate 			command_line_source = "command line";
2827c478bd9Sstevel@tonic-gate 			report_error(begin_s, _key_val);
2837c478bd9Sstevel@tonic-gate 			command_line_source = NULL;
2847c478bd9Sstevel@tonic-gate 			break;
2857c478bd9Sstevel@tonic-gate 		}
2867c478bd9Sstevel@tonic-gate 		cmdline_options++;
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	return (rc);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate static int
parse_ldap_default_conf(__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)2927c478bd9Sstevel@tonic-gate parse_ldap_default_conf(
2937c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
2947c478bd9Sstevel@tonic-gate 	__nis_config_t *nis_config,
2957c478bd9Sstevel@tonic-gate 	__nis_config_info_t *config_info,
2967c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	int		rc = 0;
2997c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
3007c478bd9Sstevel@tonic-gate 	char		attr_buf[128];
3017c478bd9Sstevel@tonic-gate 	char		*attr;
302*b9175c69SKenjiro Tsuji 	char		*attr_val;
3037c478bd9Sstevel@tonic-gate 	int		defflags;
3047c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
3057c478bd9Sstevel@tonic-gate 	int		i;
3067c478bd9Sstevel@tonic-gate 	int		len;
3077c478bd9Sstevel@tonic-gate 	int		attr_len;
308*b9175c69SKenjiro Tsuji 	void		*defp;
3097c478bd9Sstevel@tonic-gate 
310*b9175c69SKenjiro Tsuji 	if ((defp = defopen_r(ETCCONFFILE)) != NULL) {
3117c478bd9Sstevel@tonic-gate 		file_source = ETCCONFFILE;
3127c478bd9Sstevel@tonic-gate 		if (verbose)
313*b9175c69SKenjiro Tsuji 			report_info("default configuration values: ", NULL);
314*b9175c69SKenjiro Tsuji 		/* Set defread_r() to be case insensitive */
315*b9175c69SKenjiro Tsuji 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
3167c478bd9Sstevel@tonic-gate 		TURNOFF(defflags, DC_CASE);
317*b9175c69SKenjiro Tsuji 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 		get_attribute_list(proxy_info, nis_config, config_info,
3207c478bd9Sstevel@tonic-gate 		    table_info, ldap_config_attributes);
3217c478bd9Sstevel@tonic-gate 		i = 0;
3227c478bd9Sstevel@tonic-gate 		while ((attr = ldap_config_attributes[i++]) != NULL) {
323*b9175c69SKenjiro Tsuji 			(void) strlcpy(attr_buf, attr, sizeof (attr_buf));
3247c478bd9Sstevel@tonic-gate 			/*
3257c478bd9Sstevel@tonic-gate 			 * if nisplusUpdateBatching, make sure
3267c478bd9Sstevel@tonic-gate 			 * we don't match nisplusUpdateBatchingTimeout
3277c478bd9Sstevel@tonic-gate 			 */
3287c478bd9Sstevel@tonic-gate 			if (strcmp(attr, UPDATE_BATCHING) == 0) {
3297c478bd9Sstevel@tonic-gate 				attr_len = strlen(attr);
3307c478bd9Sstevel@tonic-gate 				attr_buf[attr_len] = '=';
3317c478bd9Sstevel@tonic-gate 				attr_buf[attr_len + 1] = '\0';
332*b9175c69SKenjiro Tsuji 				attr_val = defread_r(attr_buf, defp);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 				if (attr_val == 0) {
3357c478bd9Sstevel@tonic-gate 					attr_buf[attr_len] = ' ';
336*b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3377c478bd9Sstevel@tonic-gate 				}
3387c478bd9Sstevel@tonic-gate 				if (attr_val == 0) {
3397c478bd9Sstevel@tonic-gate 					attr_buf[attr_len] = '\t';
340*b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3417c478bd9Sstevel@tonic-gate 				}
3427c478bd9Sstevel@tonic-gate 				if (attr_val == 0) {
3437c478bd9Sstevel@tonic-gate 					attr_buf[attr_len] = '\n';
344*b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3457c478bd9Sstevel@tonic-gate 				}
3467c478bd9Sstevel@tonic-gate 			} else {
347*b9175c69SKenjiro Tsuji 				attr_val = defread_r(attr_buf, defp);
3487c478bd9Sstevel@tonic-gate 			}
349*b9175c69SKenjiro Tsuji 			if (attr_val == NULL)
3507c478bd9Sstevel@tonic-gate 				continue;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 			got_config_data = TRUE;
3537c478bd9Sstevel@tonic-gate 			attrib_num = get_attrib_num(attr, strlen(attr));
3547c478bd9Sstevel@tonic-gate 			if (attrib_num == key_bad) {
3557c478bd9Sstevel@tonic-gate 				report_error(attr, NULL);
3567c478bd9Sstevel@tonic-gate 				rc = -1;
3577c478bd9Sstevel@tonic-gate 				break;
3587c478bd9Sstevel@tonic-gate 			}
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 			/*
3617c478bd9Sstevel@tonic-gate 			 * Allow either entries of the form
3627c478bd9Sstevel@tonic-gate 			 *	attr val
3637c478bd9Sstevel@tonic-gate 			 *	   or
3647c478bd9Sstevel@tonic-gate 			 *	attr = val
3657c478bd9Sstevel@tonic-gate 			 */
3667c478bd9Sstevel@tonic-gate 			while (is_whitespace(*attr_val))
3677c478bd9Sstevel@tonic-gate 				attr_val++;
3687c478bd9Sstevel@tonic-gate 			if (*attr_val == '=')
3697c478bd9Sstevel@tonic-gate 				attr_val++;
3707c478bd9Sstevel@tonic-gate 			while (is_whitespace(*attr_val))
3717c478bd9Sstevel@tonic-gate 				attr_val++;
3727c478bd9Sstevel@tonic-gate 			len = strlen(attr_val);
373*b9175c69SKenjiro Tsuji 			while (len > 0 && is_whitespace(attr_val[len - 1]))
3747c478bd9Sstevel@tonic-gate 				len--;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 			if (verbose) {
3777c478bd9Sstevel@tonic-gate 				report_info("\t", attr);
3787c478bd9Sstevel@tonic-gate 				report_info("\t\t", attr_val);
3797c478bd9Sstevel@tonic-gate 			}
3807c478bd9Sstevel@tonic-gate 			if (IS_BIND_INFO(attrib_num)) {
3817c478bd9Sstevel@tonic-gate 				rc = add_bind_attribute(attrib_num,
3827c478bd9Sstevel@tonic-gate 				    attr_val, len, proxy_info);
3837c478bd9Sstevel@tonic-gate 			} else if (IS_OPER_INFO(attrib_num)) {
3847c478bd9Sstevel@tonic-gate 				rc = add_operation_attribute(attrib_num,
3857c478bd9Sstevel@tonic-gate 				    attr_val, len, nis_config,
3867c478bd9Sstevel@tonic-gate 				    table_info);
3877c478bd9Sstevel@tonic-gate 			}
3887c478bd9Sstevel@tonic-gate 			if (p_error != no_parse_error) {
3897c478bd9Sstevel@tonic-gate 				report_error(attr_val, attr);
3907c478bd9Sstevel@tonic-gate 				rc = -1;
3917c478bd9Sstevel@tonic-gate 				break;
3927c478bd9Sstevel@tonic-gate 			}
3937c478bd9Sstevel@tonic-gate 		}
3947c478bd9Sstevel@tonic-gate 		file_source = NULL;
3957c478bd9Sstevel@tonic-gate 		/* Close the /etc/default file */
396*b9175c69SKenjiro Tsuji 		defclose_r(defp);
3977c478bd9Sstevel@tonic-gate 	}
3987c478bd9Sstevel@tonic-gate 	return (rc);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate static int
yp_parse_ldap_default_conf(__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)4027c478bd9Sstevel@tonic-gate yp_parse_ldap_default_conf(
4037c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
4047c478bd9Sstevel@tonic-gate 	__nis_config_t	*nis_config,
4057c478bd9Sstevel@tonic-gate 	__nis_config_info_t *config_info,
4067c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t *table_info)
4077c478bd9Sstevel@tonic-gate {
4087c478bd9Sstevel@tonic-gate 	int rc = 0;
4097c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
4107c478bd9Sstevel@tonic-gate 	char		attr_buf[128];
4117c478bd9Sstevel@tonic-gate 	char		*attr;
412*b9175c69SKenjiro Tsuji 	char		*attr_val;
4137c478bd9Sstevel@tonic-gate 	int		defflags;
4147c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
4157c478bd9Sstevel@tonic-gate 	int 	i, len, attr_len;
416*b9175c69SKenjiro Tsuji 	void		*defp;
4177c478bd9Sstevel@tonic-gate 
418*b9175c69SKenjiro Tsuji 	if ((defp = defopen_r(YP_ETCCONFFILE)) != NULL) {
4197c478bd9Sstevel@tonic-gate 		file_source = YP_ETCCONFFILE;
4207c478bd9Sstevel@tonic-gate 		if (verbose)
4217c478bd9Sstevel@tonic-gate 			report_info("default configuration values: ", NULL);
422*b9175c69SKenjiro Tsuji 		/* Set defread_r() to be case insensitive */
423*b9175c69SKenjiro Tsuji 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
4247c478bd9Sstevel@tonic-gate 		TURNOFF(defflags, DC_CASE);
425*b9175c69SKenjiro Tsuji 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 		get_attribute_list(proxy_info, nis_config, config_info,
4287c478bd9Sstevel@tonic-gate 		    table_info, ldap_config_attributes);
4297c478bd9Sstevel@tonic-gate 		i = 0;
4307c478bd9Sstevel@tonic-gate 		while ((attr = ldap_config_attributes[i++]) != NULL) {
431*b9175c69SKenjiro Tsuji 			if ((strlcpy(attr_buf, attr, sizeof (attr_buf))) >=
4327c478bd9Sstevel@tonic-gate 			    sizeof (attr_buf)) {
4337c478bd9Sstevel@tonic-gate 				report_error(
4347c478bd9Sstevel@tonic-gate 				    "Static buffer attr_buf overflow", NULL);
435*b9175c69SKenjiro Tsuji 				defclose_r(defp);
4367c478bd9Sstevel@tonic-gate 				return (-1);
4377c478bd9Sstevel@tonic-gate 			}
4387c478bd9Sstevel@tonic-gate 
439*b9175c69SKenjiro Tsuji 			if ((attr_val = defread_r(attr_buf, defp)) == NULL)
4407c478bd9Sstevel@tonic-gate 				continue;
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 			got_config_data = TRUE;
4437c478bd9Sstevel@tonic-gate 			attrib_num = get_attrib_num(attr, strlen(attr));
4447c478bd9Sstevel@tonic-gate 			if (attrib_num == key_bad) {
4457c478bd9Sstevel@tonic-gate 				report_error(attr, NULL);
4467c478bd9Sstevel@tonic-gate 				rc = -1;
4477c478bd9Sstevel@tonic-gate 				break;
4487c478bd9Sstevel@tonic-gate 			}
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 			/*
4517c478bd9Sstevel@tonic-gate 			 * Allow either entries of the form
4527c478bd9Sstevel@tonic-gate 			 * attr val
4537c478bd9Sstevel@tonic-gate 			 * or
4547c478bd9Sstevel@tonic-gate 			 * attr = val
4557c478bd9Sstevel@tonic-gate 			 */
4567c478bd9Sstevel@tonic-gate 			while (is_whitespace(*attr_val))
4577c478bd9Sstevel@tonic-gate 				attr_val++;
4587c478bd9Sstevel@tonic-gate 			if (*attr_val == '=')
4597c478bd9Sstevel@tonic-gate 				attr_val++;
4607c478bd9Sstevel@tonic-gate 			while (is_whitespace(*attr_val))
4617c478bd9Sstevel@tonic-gate 				attr_val++;
4627c478bd9Sstevel@tonic-gate 			len = strlen(attr_val);
463*b9175c69SKenjiro Tsuji 			while (len > 0 && is_whitespace(attr_val[len - 1]))
4647c478bd9Sstevel@tonic-gate 				len--;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 			if (verbose) {
4677c478bd9Sstevel@tonic-gate 				report_info("\t", attr);
4687c478bd9Sstevel@tonic-gate 				report_info("\t\t", attr_val);
4697c478bd9Sstevel@tonic-gate 			}
4707c478bd9Sstevel@tonic-gate 			if (IS_YP_BIND_INFO(attrib_num)) {
4717c478bd9Sstevel@tonic-gate 				rc = add_bind_attribute(attrib_num,
4727c478bd9Sstevel@tonic-gate 				    attr_val, len, proxy_info);
4737c478bd9Sstevel@tonic-gate 			} else if (IS_YP_OPER_INFO(attrib_num)) {
4747c478bd9Sstevel@tonic-gate 				rc = add_operation_attribute(attrib_num,
4757c478bd9Sstevel@tonic-gate 				    attr_val, len, nis_config,
4767c478bd9Sstevel@tonic-gate 				    table_info);
4777c478bd9Sstevel@tonic-gate 			}
4787c478bd9Sstevel@tonic-gate 			if (p_error != no_parse_error) {
4797c478bd9Sstevel@tonic-gate 				report_error(attr_val, attr);
4807c478bd9Sstevel@tonic-gate 				rc = -1;
4817c478bd9Sstevel@tonic-gate 				break;
4827c478bd9Sstevel@tonic-gate 			}
4837c478bd9Sstevel@tonic-gate 		}
4847c478bd9Sstevel@tonic-gate 		file_source = NULL;
4857c478bd9Sstevel@tonic-gate 		/* Close the /etc/default file */
486*b9175c69SKenjiro Tsuji 		defclose_r(defp);
4877c478bd9Sstevel@tonic-gate 	}
4887c478bd9Sstevel@tonic-gate 	return (rc);
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate  * FUNCTION:	get_attrib_num_cmdline
4937c478bd9Sstevel@tonic-gate  *
4947c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
4957c478bd9Sstevel@tonic-gate  *	The form of the command line request is
4967c478bd9Sstevel@tonic-gate  *		-x attribute=value
4977c478bd9Sstevel@tonic-gate  *
4987c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
4997c478bd9Sstevel@tonic-gate  *
5007c478bd9Sstevel@tonic-gate  * INPUT:		command line values
5017c478bd9Sstevel@tonic-gate  */
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate static config_key
get_attrib_num_cmdline(const char * s,const char ** begin_s,const char ** end_s)5047c478bd9Sstevel@tonic-gate get_attrib_num_cmdline(
5057c478bd9Sstevel@tonic-gate 	const char	*s,
5067c478bd9Sstevel@tonic-gate 	const char 	**begin_s,
5077c478bd9Sstevel@tonic-gate 	const char 	**end_s)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate 	const char	*s_end		= s + strlen(s);
5107c478bd9Sstevel@tonic-gate 	const char	*equal_s;
5117c478bd9Sstevel@tonic-gate 	const char	*s1;
5127c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	while (s < s_end && is_whitespace(*s))
5157c478bd9Sstevel@tonic-gate 		s++;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	for (equal_s = s; equal_s < s_end; equal_s++)
5187c478bd9Sstevel@tonic-gate 		if (*equal_s == EQUAL_CHAR)
5197c478bd9Sstevel@tonic-gate 			break;
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	if (equal_s == s_end) {
5227c478bd9Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5237c478bd9Sstevel@tonic-gate 		return (key_bad);
5247c478bd9Sstevel@tonic-gate 	}
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	for (s1 = equal_s; s1 > s && is_whitespace(s1[-1]); s1--)
5277c478bd9Sstevel@tonic-gate 		;
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	if (s1 == s) {
5307c478bd9Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5317c478bd9Sstevel@tonic-gate 		return (key_bad);
5327c478bd9Sstevel@tonic-gate 	}
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	attrib_num = get_attrib_num(s, s1 - s);
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	if (attrib_num != key_bad) {
5377c478bd9Sstevel@tonic-gate 		s1 = equal_s + 1;
5387c478bd9Sstevel@tonic-gate 		while (s1 < s_end && is_whitespace(*s1))
5397c478bd9Sstevel@tonic-gate 			s1++;
5407c478bd9Sstevel@tonic-gate 		*begin_s = s1;
5417c478bd9Sstevel@tonic-gate 		while (s_end > s1 && is_whitespace(s_end[-1]))
5427c478bd9Sstevel@tonic-gate 			s_end--;
5437c478bd9Sstevel@tonic-gate 		*end_s = s_end;
5447c478bd9Sstevel@tonic-gate 	}
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	return (attrib_num);
5477c478bd9Sstevel@tonic-gate }
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate /*
5507c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_file
5517c478bd9Sstevel@tonic-gate  *
5527c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from a configuration
5537c478bd9Sstevel@tonic-gate  *	file. If no file is specified, /var/nis/NIS+LDAPmapping
5547c478bd9Sstevel@tonic-gate  *	is used
5557c478bd9Sstevel@tonic-gate  *
5567c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
5577c478bd9Sstevel@tonic-gate  *
5587c478bd9Sstevel@tonic-gate  * INPUT:		configuration file name
5597c478bd9Sstevel@tonic-gate  */
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate static int
parse_ldap_config_file(const char * config_file,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)5627c478bd9Sstevel@tonic-gate parse_ldap_config_file(
5637c478bd9Sstevel@tonic-gate 	const char 		*config_file,
5647c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
5657c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
5667c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
5677c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
5687c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
5697c478bd9Sstevel@tonic-gate {
5707c478bd9Sstevel@tonic-gate 	int		rc = 0;
5717c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
5727c478bd9Sstevel@tonic-gate 	int		fd;
5737c478bd9Sstevel@tonic-gate 	char		*attr_val;
5747c478bd9Sstevel@tonic-gate 	int		len;
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
5777c478bd9Sstevel@tonic-gate 		p_error = parse_open_file_error;
5787c478bd9Sstevel@tonic-gate 		report_error(config_file, NULL);
5797c478bd9Sstevel@tonic-gate 		return (-1);
5807c478bd9Sstevel@tonic-gate 	}
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	start_line_num = 1;
5837c478bd9Sstevel@tonic-gate 	cur_line_num = 1;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	if (verbose)
5867c478bd9Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 	file_source = config_file;
5897c478bd9Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
5907c478bd9Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
5917c478bd9Sstevel@tonic-gate 		if (IS_CONFIG_KEYWORD(attrib_num)) {
5927c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
5937c478bd9Sstevel@tonic-gate 			    attr_val, len, config_info);
5947c478bd9Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
5957c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
5967c478bd9Sstevel@tonic-gate 			    attr_val, len, proxy_info);
5977c478bd9Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
5987c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
5997c478bd9Sstevel@tonic-gate 			    attr_val, len, nis_config, table_info);
6007c478bd9Sstevel@tonic-gate 		} else {
6017c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
6027c478bd9Sstevel@tonic-gate 			    attr_val, len, table_mapping);
6037c478bd9Sstevel@tonic-gate 		}
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 		if (rc < 0) {
6067c478bd9Sstevel@tonic-gate 			report_error(attr_val == NULL ?
6077c478bd9Sstevel@tonic-gate 			    "<no attribute>" : attr_val, _key_val);
6087c478bd9Sstevel@tonic-gate 			if (attr_val)
6097c478bd9Sstevel@tonic-gate 				free(attr_val);
6107c478bd9Sstevel@tonic-gate 			break;
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 		if (attr_val)
6137c478bd9Sstevel@tonic-gate 			free(attr_val);
6147c478bd9Sstevel@tonic-gate 	}
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	(void) close(fd);
6177c478bd9Sstevel@tonic-gate 	if (attrib_num == key_bad) {
6187c478bd9Sstevel@tonic-gate 		report_error(_key_val, NULL);
6197c478bd9Sstevel@tonic-gate 		rc = -1;
6207c478bd9Sstevel@tonic-gate 	}
6217c478bd9Sstevel@tonic-gate 	start_line_num = 0;
6227c478bd9Sstevel@tonic-gate 	file_source = NULL;
6237c478bd9Sstevel@tonic-gate 	return (rc);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate /*
6277c478bd9Sstevel@tonic-gate  * FUNCTION:	yp_parse_ldap_config_file
6287c478bd9Sstevel@tonic-gate  *
6297c478bd9Sstevel@tonic-gate  * Parses the information for LDAP from a configuration
6307c478bd9Sstevel@tonic-gate  * file. If no file is specified, /var/yp/NISLDAPmapping
6317c478bd9Sstevel@tonic-gate  * is used
6327c478bd9Sstevel@tonic-gate  *
6337c478bd9Sstevel@tonic-gate  * RETURN VALUE:    0 on success, -1 on failure
6347c478bd9Sstevel@tonic-gate  *
6357c478bd9Sstevel@tonic-gate  * INPUT:       configuration file name
6367c478bd9Sstevel@tonic-gate  */
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate int
yp_parse_ldap_config_file(const char * config_file,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info,__yp_domain_context_t * ypDomains)6397c478bd9Sstevel@tonic-gate yp_parse_ldap_config_file(
6407c478bd9Sstevel@tonic-gate 	const char	*config_file,
6417c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
6427c478bd9Sstevel@tonic-gate 	__nis_config_t			*nis_config,
6437c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
6447c478bd9Sstevel@tonic-gate 	__nis_config_info_t		*config_info,
6457c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info,
6467c478bd9Sstevel@tonic-gate 	__yp_domain_context_t	*ypDomains)
6477c478bd9Sstevel@tonic-gate {
6487c478bd9Sstevel@tonic-gate 	int	rc = 0;
6497c478bd9Sstevel@tonic-gate 	int	numDomains = 0;
6507c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
6517c478bd9Sstevel@tonic-gate 	int	fd;
6527c478bd9Sstevel@tonic-gate 	char	*attr_val = NULL;
6537c478bd9Sstevel@tonic-gate 	int		len;
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
6567c478bd9Sstevel@tonic-gate 		p_error = parse_open_file_error;
6577c478bd9Sstevel@tonic-gate 		report_error(config_file, NULL);
6587c478bd9Sstevel@tonic-gate 		return (-1);
6597c478bd9Sstevel@tonic-gate 	}
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	start_line_num = 1;
6627c478bd9Sstevel@tonic-gate 	cur_line_num = 1;
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	if (verbose)
6657c478bd9Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	file_source = config_file;
6687c478bd9Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
6697c478bd9Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
6707c478bd9Sstevel@tonic-gate 		if (IS_YP_CONFIG_KEYWORD(attrib_num)) {
6717c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
6727c478bd9Sstevel@tonic-gate 			    attr_val, len, config_info);
6737c478bd9Sstevel@tonic-gate 		} else if (IS_YP_BIND_INFO(attrib_num)) {
6747c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
6757c478bd9Sstevel@tonic-gate 			    attr_val, len, proxy_info);
6767c478bd9Sstevel@tonic-gate 		} else if (IS_YP_OPER_INFO(attrib_num)) {
6777c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
6787c478bd9Sstevel@tonic-gate 			    attr_val, len, nis_config, table_info);
6797c478bd9Sstevel@tonic-gate 		} else if (IS_YP_DOMAIN_INFO(attrib_num)) {
6807c478bd9Sstevel@tonic-gate 			rc = add_ypdomains_attribute(attrib_num,
6817c478bd9Sstevel@tonic-gate 			    attr_val, len, ypDomains);
6827c478bd9Sstevel@tonic-gate 		} else if (IS_YP_MAP_ATTR(attrib_num)) {
6837c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
6847c478bd9Sstevel@tonic-gate 			    attr_val, len, table_mapping);
6857c478bd9Sstevel@tonic-gate 		} else {
6867c478bd9Sstevel@tonic-gate 			rc = -1;
6877c478bd9Sstevel@tonic-gate 			p_error = parse_unsupported_format;
6887c478bd9Sstevel@tonic-gate 		}
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 		if (rc < 0) {
6917c478bd9Sstevel@tonic-gate 			report_error(attr_val == NULL ?
6927c478bd9Sstevel@tonic-gate 			    "<no attribute>" : attr_val, _key_val);
6937c478bd9Sstevel@tonic-gate 			if (attr_val)
6947c478bd9Sstevel@tonic-gate 				free(attr_val);
6957c478bd9Sstevel@tonic-gate 			break;
6967c478bd9Sstevel@tonic-gate 		}
6977c478bd9Sstevel@tonic-gate 		if (attr_val) {
6987c478bd9Sstevel@tonic-gate 			free(attr_val);
6997c478bd9Sstevel@tonic-gate 			attr_val = NULL;
7007c478bd9Sstevel@tonic-gate 		}
7017c478bd9Sstevel@tonic-gate 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	(void) close(fd);
7047c478bd9Sstevel@tonic-gate 	if (attrib_num == key_bad) {
7057c478bd9Sstevel@tonic-gate 		report_error(_key_val, NULL);
7067c478bd9Sstevel@tonic-gate 		rc = -1;
7077c478bd9Sstevel@tonic-gate 	}
7087c478bd9Sstevel@tonic-gate 	start_line_num = 0;
7097c478bd9Sstevel@tonic-gate 	file_source = NULL;
7107c478bd9Sstevel@tonic-gate 	return (rc);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate /*
7147c478bd9Sstevel@tonic-gate  * FUNCTION:	get_file_attr_val
7157c478bd9Sstevel@tonic-gate  *
7167c478bd9Sstevel@tonic-gate  *	Gets the next attribute from the configuration file.
7177c478bd9Sstevel@tonic-gate  *
7187c478bd9Sstevel@tonic-gate  * RETURN VALUE:	The config key if more attributes
7197c478bd9Sstevel@tonic-gate  *			no_more_keys if eof
7207c478bd9Sstevel@tonic-gate  *			key_bad if error
7217c478bd9Sstevel@tonic-gate  */
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate static config_key
get_file_attr_val(int fd,char ** attr_val)7247c478bd9Sstevel@tonic-gate get_file_attr_val(int fd, char **attr_val)
7257c478bd9Sstevel@tonic-gate {
7267c478bd9Sstevel@tonic-gate 	char		buf[BUFSIZE];
7277c478bd9Sstevel@tonic-gate 	char		*start_tag;
7287c478bd9Sstevel@tonic-gate 	char		*start_val;
7297c478bd9Sstevel@tonic-gate 	char		*end_val;
7307c478bd9Sstevel@tonic-gate 	char		*cut_here;
7317c478bd9Sstevel@tonic-gate 	char		*s;
7327c478bd9Sstevel@tonic-gate 	char		*a;
7337c478bd9Sstevel@tonic-gate 	char		*attribute_value;
7347c478bd9Sstevel@tonic-gate 	int		ret;
7357c478bd9Sstevel@tonic-gate 	config_key	attrib_num = no_more_keys;
7367c478bd9Sstevel@tonic-gate 	int		found_quote = 0;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	*attr_val = NULL;
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	if ((ret = read_line(fd, buf, sizeof (buf))) > 0) {
7417c478bd9Sstevel@tonic-gate 		for (s = buf; is_whitespace(*s); s++)
7427c478bd9Sstevel@tonic-gate 			;
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		start_tag = s;
7457c478bd9Sstevel@tonic-gate 		while (*s != '\0' && !is_whitespace(*s))
7467c478bd9Sstevel@tonic-gate 			s++;
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 		if (verbose)
7497c478bd9Sstevel@tonic-gate 			report_info("\t", start_tag);
7507c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num(start_tag, s - start_tag);
7517c478bd9Sstevel@tonic-gate 		if (attrib_num == key_bad)
7527c478bd9Sstevel@tonic-gate 			return (key_bad);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		while (is_whitespace(*s))
7557c478bd9Sstevel@tonic-gate 			s++;
7567c478bd9Sstevel@tonic-gate 		if (*s == '\0')
7577c478bd9Sstevel@tonic-gate 			return (attrib_num);
7587c478bd9Sstevel@tonic-gate 		start_val = s;
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 		/* note that read_line will not return a line ending with \ */
7617c478bd9Sstevel@tonic-gate 		for (; *s != '\0'; s++) {
7627c478bd9Sstevel@tonic-gate 			if (*s == ESCAPE_CHAR)
7637c478bd9Sstevel@tonic-gate 				s++;
7647c478bd9Sstevel@tonic-gate 		}
7657c478bd9Sstevel@tonic-gate 		while (s > start_val && is_whitespace(s[-1]))
7667c478bd9Sstevel@tonic-gate 			s--;
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 		attribute_value =
769*b9175c69SKenjiro Tsuji 		    calloc(1, (size_t)(s - start_val) + 1);
7707c478bd9Sstevel@tonic-gate 		if (attribute_value == NULL) {
7717c478bd9Sstevel@tonic-gate 			p_error = parse_no_mem_error;
7727c478bd9Sstevel@tonic-gate 			return (key_bad);
7737c478bd9Sstevel@tonic-gate 		}
7747c478bd9Sstevel@tonic-gate 		attr_val[0] = attribute_value;
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 		a = *attr_val;
7777c478bd9Sstevel@tonic-gate 		end_val = s;
7787c478bd9Sstevel@tonic-gate 		cut_here = 0;
7797c478bd9Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++) {
7807c478bd9Sstevel@tonic-gate 			if (*s == POUND_SIGN) {
7817c478bd9Sstevel@tonic-gate 					cut_here = s;
7827c478bd9Sstevel@tonic-gate 					while (s < end_val) {
7837c478bd9Sstevel@tonic-gate 						if (*s == DOUBLE_QUOTE_CHAR ||
7847c478bd9Sstevel@tonic-gate 						    *s == SINGLE_QUOTE_CHAR) {
7857c478bd9Sstevel@tonic-gate 							cut_here = 0;
7867c478bd9Sstevel@tonic-gate 							break;
7877c478bd9Sstevel@tonic-gate 						}
7887c478bd9Sstevel@tonic-gate 						s++;
7897c478bd9Sstevel@tonic-gate 					}
7907c478bd9Sstevel@tonic-gate 			}
7917c478bd9Sstevel@tonic-gate 		}
7927c478bd9Sstevel@tonic-gate 		if (cut_here != 0)
7937c478bd9Sstevel@tonic-gate 			end_val = cut_here;
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++)
7967c478bd9Sstevel@tonic-gate 			*a++ = *s;
7977c478bd9Sstevel@tonic-gate 		*a++ = '\0';
7987c478bd9Sstevel@tonic-gate 	}
7997c478bd9Sstevel@tonic-gate 	if (ret == -1)
8007c478bd9Sstevel@tonic-gate 		return (key_bad);
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate 	return (attrib_num);
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate static LDAP *
connect_to_ldap_config_server(char * sever_name,int server_port,__nis_config_info_t * config_info)8067c478bd9Sstevel@tonic-gate connect_to_ldap_config_server(
8077c478bd9Sstevel@tonic-gate 	char			*sever_name,
8087c478bd9Sstevel@tonic-gate 	int			server_port,
8097c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info)
8107c478bd9Sstevel@tonic-gate {
8117c478bd9Sstevel@tonic-gate 	int		rc		= 0;
8127c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
8137c478bd9Sstevel@tonic-gate 	int		ldapVersion	= LDAP_VERSION3;
8147c478bd9Sstevel@tonic-gate 	int		derefOption	= LDAP_DEREF_ALWAYS;
8157c478bd9Sstevel@tonic-gate 	int		timelimit	= LDAP_NO_LIMIT;
8167c478bd9Sstevel@tonic-gate 	int		sizelimit	= LDAP_NO_LIMIT;
8177c478bd9Sstevel@tonic-gate 	int		errnum;
8187c478bd9Sstevel@tonic-gate 	bool_t		retrying	= FALSE;
8197c478bd9Sstevel@tonic-gate 	int		sleep_seconds	= 1;
8207c478bd9Sstevel@tonic-gate 	struct berval	cred;
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate 	if (config_info->tls_method == no_tls) {
8237c478bd9Sstevel@tonic-gate 		ld = ldap_init(sever_name, server_port);
8247c478bd9Sstevel@tonic-gate 		if (ld == NULL) {
8257c478bd9Sstevel@tonic-gate 			p_error = parse_ldap_init_error;
8267c478bd9Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8277c478bd9Sstevel@tonic-gate 			return (NULL);
8287c478bd9Sstevel@tonic-gate 		}
8297c478bd9Sstevel@tonic-gate 	} else {
8307c478bd9Sstevel@tonic-gate 		if ((errnum = ldapssl_client_init(
8317c478bd9Sstevel@tonic-gate 		    config_info->tls_cert_db, NULL)) < 0) {
8327c478bd9Sstevel@tonic-gate 			p_error = parse_ldapssl_client_init_error;
8337c478bd9Sstevel@tonic-gate 			report_error(ldapssl_err2string(errnum), NULL);
8347c478bd9Sstevel@tonic-gate 			return (NULL);
8357c478bd9Sstevel@tonic-gate 		}
8367c478bd9Sstevel@tonic-gate 		ld = ldapssl_init(sever_name, server_port, 1);
8377c478bd9Sstevel@tonic-gate 		if (ld == NULL) {
8387c478bd9Sstevel@tonic-gate 			p_error = parse_ldapssl_init_error;
8397c478bd9Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8407c478bd9Sstevel@tonic-gate 			return (NULL);
8417c478bd9Sstevel@tonic-gate 		}
8427c478bd9Sstevel@tonic-gate 	}
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,
8457c478bd9Sstevel@tonic-gate 	    &ldapVersion);
8467c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_DEREF, &derefOption);
8477c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
8487c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_TIMELIMIT, &timelimit);
8497c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 	/*
8527c478bd9Sstevel@tonic-gate 	 * Attempt to bind to the LDAP server.
8537c478bd9Sstevel@tonic-gate 	 * We will loop until success or until an error other
8547c478bd9Sstevel@tonic-gate 	 * than LDAP_CONNECT_ERROR or LDAP_SERVER_DOWN
8557c478bd9Sstevel@tonic-gate 	 */
8567c478bd9Sstevel@tonic-gate 	if (verbose)
8577c478bd9Sstevel@tonic-gate 		report_info("Connecting to ", sever_name);
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	for (;;) {
8607c478bd9Sstevel@tonic-gate 		if (config_info->auth_method == simple) {
8617c478bd9Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, config_info->proxy_dn,
8627c478bd9Sstevel@tonic-gate 			    config_info->proxy_passwd);
8637c478bd9Sstevel@tonic-gate 		} else if (config_info->auth_method == cram_md5) {
8647c478bd9Sstevel@tonic-gate 			cred.bv_len = strlen(config_info->proxy_passwd);
8657c478bd9Sstevel@tonic-gate 			cred.bv_val = config_info->proxy_passwd;
8667c478bd9Sstevel@tonic-gate 			errnum = ldap_sasl_cram_md5_bind_s(ld,
8677c478bd9Sstevel@tonic-gate 			    config_info->proxy_dn, &cred, NULL, NULL);
8687c478bd9Sstevel@tonic-gate 		} else if (config_info->auth_method == digest_md5) {
8697c478bd9Sstevel@tonic-gate 			cred.bv_len = strlen(config_info->proxy_passwd);
8707c478bd9Sstevel@tonic-gate 			cred.bv_val = config_info->proxy_passwd;
8717c478bd9Sstevel@tonic-gate 			errnum = ldap_x_sasl_digest_md5_bind_s(ld,
8727c478bd9Sstevel@tonic-gate 			    config_info->proxy_dn, &cred, NULL, NULL);
8737c478bd9Sstevel@tonic-gate 		} else {
8747c478bd9Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, NULL, NULL);
8757c478bd9Sstevel@tonic-gate 		}
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 		if (errnum == LDAP_SUCCESS)
8787c478bd9Sstevel@tonic-gate 			break;
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 		if (errnum == LDAP_CONNECT_ERROR ||
8817c478bd9Sstevel@tonic-gate 		    errnum == LDAP_SERVER_DOWN) {
8827c478bd9Sstevel@tonic-gate 			if (!retrying) {
8837c478bd9Sstevel@tonic-gate 				if (verbose)
8847c478bd9Sstevel@tonic-gate 					report_info(
8857c478bd9Sstevel@tonic-gate 					"LDAP server unavailable. Retrying...",
8867c478bd9Sstevel@tonic-gate 					    NULL);
8877c478bd9Sstevel@tonic-gate 				retrying = TRUE;
8887c478bd9Sstevel@tonic-gate 			}
8897c478bd9Sstevel@tonic-gate 			(void) sleep(sleep_seconds);
8907c478bd9Sstevel@tonic-gate 			sleep_seconds *= 2;
8917c478bd9Sstevel@tonic-gate 			if (sleep_seconds > MAX_LDAP_CONFIG_RETRY_TIME)
8927c478bd9Sstevel@tonic-gate 				sleep_seconds = MAX_LDAP_CONFIG_RETRY_TIME;
8937c478bd9Sstevel@tonic-gate 			p_error = no_parse_error;
8947c478bd9Sstevel@tonic-gate 			continue;
8957c478bd9Sstevel@tonic-gate 		}
8967c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_bind_error;
8977c478bd9Sstevel@tonic-gate 		report_error2(config_info->proxy_dn, ldap_err2string(errnum));
8987c478bd9Sstevel@tonic-gate 		(void) ldap_unbind(ld);
8997c478bd9Sstevel@tonic-gate 		return (NULL);
9007c478bd9Sstevel@tonic-gate 	}
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	if (verbose)
9037c478bd9Sstevel@tonic-gate 		report_info("Reading values from ", config_info->config_dn);
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	return (ld);
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate /*
9097c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_config_result
9107c478bd9Sstevel@tonic-gate  *
9117c478bd9Sstevel@tonic-gate  *	Extracts the LDAPMessage containing the nis+/LDAP
9127c478bd9Sstevel@tonic-gate  *	configuration
9137c478bd9Sstevel@tonic-gate  *
9147c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
9157c478bd9Sstevel@tonic-gate  *
9167c478bd9Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
9177c478bd9Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
9187c478bd9Sstevel@tonic-gate  */
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate static int
process_ldap_config_result(LDAP * ld,LDAPMessage * resultMsg,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nisdb_table_mapping_t * table_info)9217c478bd9Sstevel@tonic-gate process_ldap_config_result(
9227c478bd9Sstevel@tonic-gate 	LDAP			*ld,
9237c478bd9Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
9247c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
9257c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
9267c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
9277c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
9287c478bd9Sstevel@tonic-gate {
9297c478bd9Sstevel@tonic-gate 	LDAPMessage	*e;
9307c478bd9Sstevel@tonic-gate 	int		errnum;
9317c478bd9Sstevel@tonic-gate 	char		*attr;
9327c478bd9Sstevel@tonic-gate 	BerElement	*ber		= NULL;
9337c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
9347c478bd9Sstevel@tonic-gate 	char		**vals;
9357c478bd9Sstevel@tonic-gate 	int		n;
9367c478bd9Sstevel@tonic-gate 	int		i;
9377c478bd9Sstevel@tonic-gate 	char		*attr_val;
9387c478bd9Sstevel@tonic-gate 	int		len;
9397c478bd9Sstevel@tonic-gate 	int		rc = 0;
9407c478bd9Sstevel@tonic-gate 	bool_t		error_reported	= FALSE;
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	e = ldap_first_entry(ld, resultMsg);
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	if (e != NULL) {
945*b9175c69SKenjiro Tsuji 		for (attr = ldap_first_attribute(ld, e, &ber); attr != NULL;
9467c478bd9Sstevel@tonic-gate 		    attr = ldap_next_attribute(ld, e, ber)) {
9477c478bd9Sstevel@tonic-gate 			if (verbose)
9487c478bd9Sstevel@tonic-gate 				report_info("\t", attr);
9497c478bd9Sstevel@tonic-gate 			attrib_num = get_attrib_num(attr, strlen(attr));
9507c478bd9Sstevel@tonic-gate 			if (attrib_num == key_bad) {
9517c478bd9Sstevel@tonic-gate 				report_error(attr, NULL);
9527c478bd9Sstevel@tonic-gate 				break;
9537c478bd9Sstevel@tonic-gate 			}
9547c478bd9Sstevel@tonic-gate 			if ((vals = ldap_get_values(ld, e, attr)) != NULL) {
9557c478bd9Sstevel@tonic-gate 				n = ldap_count_values(vals);
9567c478bd9Sstevel@tonic-gate 				/* parse the attribute values */
9577c478bd9Sstevel@tonic-gate 				for (i = 0; i < n; i++) {
9587c478bd9Sstevel@tonic-gate 					attr_val = vals[i];
9597c478bd9Sstevel@tonic-gate 					while (is_whitespace(*attr_val))
9607c478bd9Sstevel@tonic-gate 						attr_val++;
9617c478bd9Sstevel@tonic-gate 					if (verbose)
9627c478bd9Sstevel@tonic-gate 						report_info("\t\t", attr_val);
9637c478bd9Sstevel@tonic-gate 					len = strlen(attr_val);
9647c478bd9Sstevel@tonic-gate 					while (len > 0 &&
9657c478bd9Sstevel@tonic-gate 					    is_whitespace(attr_val[len - 1]))
9667c478bd9Sstevel@tonic-gate 						len--;
9677c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
9687c478bd9Sstevel@tonic-gate 			if (IS_YP_BIND_INFO(attrib_num)) {
969*b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num, attr_val,
9707c478bd9Sstevel@tonic-gate 				    len, proxy_info);
971*b9175c69SKenjiro Tsuji 			} else if (IS_YP_OPER_INFO(attrib_num)) {
972*b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
973*b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config, table_info);
974*b9175c69SKenjiro Tsuji 			} else if (IS_YP_MAP_ATTR(attrib_num)) {
975*b9175c69SKenjiro Tsuji 				rc = add_mapping_attribute(attrib_num, attr_val,
976*b9175c69SKenjiro Tsuji 				    len, table_mapping);
9777c478bd9Sstevel@tonic-gate 			} else {
978*b9175c69SKenjiro Tsuji 				p_error = parse_unsupported_format;
9797c478bd9Sstevel@tonic-gate 			}
9807c478bd9Sstevel@tonic-gate 		} else {
9817c478bd9Sstevel@tonic-gate 			if (IS_BIND_INFO(attrib_num)) {
982*b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num, attr_val,
983*b9175c69SKenjiro Tsuji 				    len, proxy_info);
9847c478bd9Sstevel@tonic-gate 			} else if (IS_OPER_INFO(attrib_num)) {
985*b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
986*b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config, table_info);
9877c478bd9Sstevel@tonic-gate 			} else {
988*b9175c69SKenjiro Tsuji 				rc = add_mapping_attribute(attrib_num, attr_val,
989*b9175c69SKenjiro Tsuji 				    len, table_mapping);
9907c478bd9Sstevel@tonic-gate 			}
9917c478bd9Sstevel@tonic-gate 		}
9927c478bd9Sstevel@tonic-gate 					if (p_error != no_parse_error) {
9937c478bd9Sstevel@tonic-gate 						report_error(attr_val, attr);
9947c478bd9Sstevel@tonic-gate 						error_reported = TRUE;
9957c478bd9Sstevel@tonic-gate 						break;
9967c478bd9Sstevel@tonic-gate 					}
9977c478bd9Sstevel@tonic-gate 				}
9987c478bd9Sstevel@tonic-gate 				ldap_value_free(vals);
9997c478bd9Sstevel@tonic-gate 			} else {
1000*b9175c69SKenjiro Tsuji 				(void) ldap_get_option(ld,
1001*b9175c69SKenjiro Tsuji 				    LDAP_OPT_ERROR_NUMBER, &errnum);
10027c478bd9Sstevel@tonic-gate 				if (errnum != LDAP_SUCCESS)
10037c478bd9Sstevel@tonic-gate 					p_error = parse_ldap_get_values_error;
10047c478bd9Sstevel@tonic-gate 			}
10057c478bd9Sstevel@tonic-gate 			ldap_memfree(attr);
10067c478bd9Sstevel@tonic-gate 			if (p_error != no_parse_error)
10077c478bd9Sstevel@tonic-gate 				break;
10087c478bd9Sstevel@tonic-gate 		}
10097c478bd9Sstevel@tonic-gate 	} else {
10107c478bd9Sstevel@tonic-gate 		errnum = ldap_result2error(ld, resultMsg, FALSE);
10117c478bd9Sstevel@tonic-gate 		if (errnum != LDAP_SUCCESS)
10127c478bd9Sstevel@tonic-gate 			p_error = parse_ldap_search_error;
10137c478bd9Sstevel@tonic-gate 	}
10147c478bd9Sstevel@tonic-gate 	if (ber != NULL)
10157c478bd9Sstevel@tonic-gate 		ber_free(ber, 0);
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate 	if (!error_reported && p_error != no_parse_error) {
10187c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10197c478bd9Sstevel@tonic-gate 	}
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate 	if (p_error != no_parse_error)
10227c478bd9Sstevel@tonic-gate 		rc = -1;
10237c478bd9Sstevel@tonic-gate 	return (rc);
10247c478bd9Sstevel@tonic-gate }
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate /*
10277c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral
10287c478bd9Sstevel@tonic-gate  *
10297c478bd9Sstevel@tonic-gate  *	Retrieves the configuration for a referral url
10307c478bd9Sstevel@tonic-gate  *
10317c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure, 1 on skip
10327c478bd9Sstevel@tonic-gate  *
10337c478bd9Sstevel@tonic-gate  * INPUT:		url		the ldap url
10347c478bd9Sstevel@tonic-gate  *			__nis_ldap_proxy_info
10357c478bd9Sstevel@tonic-gate  */
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate static int
process_ldap_referral(char * url,char ** attrs,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)10387c478bd9Sstevel@tonic-gate process_ldap_referral(
10397c478bd9Sstevel@tonic-gate 	char			*url,
10407c478bd9Sstevel@tonic-gate 	char			**attrs,
10417c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
10427c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
10437c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
10447c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
10457c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
10467c478bd9Sstevel@tonic-gate {
10477c478bd9Sstevel@tonic-gate 	LDAPURLDesc	*ludpp		= NULL;
10487c478bd9Sstevel@tonic-gate 	int		rc;
10497c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
10507c478bd9Sstevel@tonic-gate 	int		errnum;
10517c478bd9Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate 	if ((rc = ldap_url_parse(url, &ludpp)) != LDAP_SUCCESS)
10547c478bd9Sstevel@tonic-gate 		return (1);
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate #ifdef LDAP_URL_OPT_SECURE
10577c478bd9Sstevel@tonic-gate 	if (ludpp->lud_options & LDAP_URL_OPT_SECURE) {
10587c478bd9Sstevel@tonic-gate 		if (config_info->tls_method != ssl_tls) {
10597c478bd9Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10607c478bd9Sstevel@tonic-gate 			return (1);
10617c478bd9Sstevel@tonic-gate 		}
10627c478bd9Sstevel@tonic-gate 	} else {
10637c478bd9Sstevel@tonic-gate 		if (config_info->tls_method != no_tls) {
10647c478bd9Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10657c478bd9Sstevel@tonic-gate 			return (1);
10667c478bd9Sstevel@tonic-gate 		}
10677c478bd9Sstevel@tonic-gate 	}
10687c478bd9Sstevel@tonic-gate #endif
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(ludpp->lud_host,
10717c478bd9Sstevel@tonic-gate 	    ludpp->lud_port, config_info)) == NULL) {
10727c478bd9Sstevel@tonic-gate 		ldap_free_urldesc(ludpp);
10737c478bd9Sstevel@tonic-gate 		return (-1);
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
10777c478bd9Sstevel@tonic-gate 	    "objectclass=nisplusLDAPconfig", attrs, 0, &resultMsg);
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 	if (errnum != LDAP_SUCCESS) {
10827c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
10837c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10847c478bd9Sstevel@tonic-gate 		rc = -1;
10857c478bd9Sstevel@tonic-gate 	} else {
10867c478bd9Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
10877c478bd9Sstevel@tonic-gate 		    nis_config, table_mapping, table_info);
10887c478bd9Sstevel@tonic-gate 	}
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 	ldap_source = NULL;
10917c478bd9Sstevel@tonic-gate 	(void) ldap_unbind(ld);
10927c478bd9Sstevel@tonic-gate 	if (resultMsg != NULL)
10937c478bd9Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate 	return (rc);
10967c478bd9Sstevel@tonic-gate }
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate /*
10997c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral_msg
11007c478bd9Sstevel@tonic-gate  *
11017c478bd9Sstevel@tonic-gate  *	Retrieves the configuration from referred servers
11027c478bd9Sstevel@tonic-gate  *
11037c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
11047c478bd9Sstevel@tonic-gate  *
11057c478bd9Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
11067c478bd9Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
11077c478bd9Sstevel@tonic-gate  *			__nis_ldap_proxy_info
11087c478bd9Sstevel@tonic-gate  */
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate static int
process_ldap_referral_msg(LDAP * ld,LDAPMessage * resultMsg,char ** attrs,__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)11117c478bd9Sstevel@tonic-gate process_ldap_referral_msg(
11127c478bd9Sstevel@tonic-gate 	LDAP			*ld,
11137c478bd9Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
11147c478bd9Sstevel@tonic-gate 	char			**attrs,
11157c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11167c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11177c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11187c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11197c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11207c478bd9Sstevel@tonic-gate {
11217c478bd9Sstevel@tonic-gate 	int	errCode;
11227c478bd9Sstevel@tonic-gate 	char	**referralsp	= NULL;
11237c478bd9Sstevel@tonic-gate 	int	i;
11247c478bd9Sstevel@tonic-gate 	int	rc;
11257c478bd9Sstevel@tonic-gate 
11267c478bd9Sstevel@tonic-gate 	rc = ldap_parse_result(ld, resultMsg, &errCode, NULL, NULL, &referralsp,
11277c478bd9Sstevel@tonic-gate 	    NULL, 0);
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate 	if (rc != LDAP_SUCCESS || errCode != LDAP_REFERRAL) {
11307c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_get_values_error;
11317c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errCode), 0);
11327c478bd9Sstevel@tonic-gate 		rc = -1;
11337c478bd9Sstevel@tonic-gate 	} else {
11347c478bd9Sstevel@tonic-gate 		for (i = 0; referralsp[i] != NULL; i++) {
11357c478bd9Sstevel@tonic-gate 			rc = process_ldap_referral(referralsp[i], attrs,
11367c478bd9Sstevel@tonic-gate 			    proxy_info, nis_config, table_mapping,
11377c478bd9Sstevel@tonic-gate 			    config_info, table_info);
11387c478bd9Sstevel@tonic-gate 			if (rc <= 0)
11397c478bd9Sstevel@tonic-gate 				break;
11407c478bd9Sstevel@tonic-gate 			else
11417c478bd9Sstevel@tonic-gate 				report_info("Cannot use referral \n",
11427c478bd9Sstevel@tonic-gate 				    referralsp[i]);
11437c478bd9Sstevel@tonic-gate 
11447c478bd9Sstevel@tonic-gate 		}
11457c478bd9Sstevel@tonic-gate 		if (rc > 0) {
11467c478bd9Sstevel@tonic-gate 			p_error = parse_no_available_referrals_error;
11477c478bd9Sstevel@tonic-gate 			report_error(0, 0);
11487c478bd9Sstevel@tonic-gate 		}
11497c478bd9Sstevel@tonic-gate 	}
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate 	if (referralsp)
11527c478bd9Sstevel@tonic-gate 		ldap_value_free(referralsp);
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 	return (rc);
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate /*
11587c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_dn_attrs
11597c478bd9Sstevel@tonic-gate  *
11607c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the LDAP profile
11617c478bd9Sstevel@tonic-gate  *	- the profile object name, the LDAP server, and the
11627c478bd9Sstevel@tonic-gate  *	authentication method must be specified.
11637c478bd9Sstevel@tonic-gate  *
11647c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
11657c478bd9Sstevel@tonic-gate  *
11667c478bd9Sstevel@tonic-gate  * INPUT:		__nis_ldap_proxy_info
11677c478bd9Sstevel@tonic-gate  */
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate static int
parse_ldap_config_dn_attrs(__nis_ldap_proxy_info * proxy_info,__nis_config_t * nis_config,__nis_table_mapping_t ** table_mapping,__nis_config_info_t * config_info,__nisdb_table_mapping_t * table_info)11707c478bd9Sstevel@tonic-gate parse_ldap_config_dn_attrs(
11717c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11727c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11737c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11747c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11757c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11767c478bd9Sstevel@tonic-gate {
11777c478bd9Sstevel@tonic-gate 	int		rc		= 0;
11787c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
11797c478bd9Sstevel@tonic-gate 	int		errnum;
11807c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
11817c478bd9Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 	/* Determine if properly configured for LDAP lookup */
11847c478bd9Sstevel@tonic-gate 	if (config_info->auth_method == simple &&
11857c478bd9Sstevel@tonic-gate 	    config_info->proxy_dn == NULL)
11867c478bd9Sstevel@tonic-gate 		p_error = parse_no_proxy_dn_error;
11877c478bd9Sstevel@tonic-gate 	else if (config_info->auth_method ==
11887c478bd9Sstevel@tonic-gate 	    (auth_method_t)NO_VALUE_SET)
11897c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_auth_error;
11907c478bd9Sstevel@tonic-gate 	else if ((config_info->default_servers == NULL) ||
11917c478bd9Sstevel@tonic-gate 	    (config_info->default_servers[0] == '\0'))
11927c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_server_addr;
11937c478bd9Sstevel@tonic-gate 	if (p_error != no_parse_error) {
11947c478bd9Sstevel@tonic-gate 		report_error(NULL, NULL);
11957c478bd9Sstevel@tonic-gate 		return (-1);
11967c478bd9Sstevel@tonic-gate 	}
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate 	if (config_info->tls_method == (tls_method_t)NO_VALUE_SET)
11997c478bd9Sstevel@tonic-gate 		config_info->tls_method = no_tls;
12007c478bd9Sstevel@tonic-gate 	else if (config_info->tls_method == ssl_tls &&
12017c478bd9Sstevel@tonic-gate 	    (config_info->tls_cert_db == NULL ||
12027c478bd9Sstevel@tonic-gate 	    *config_info->tls_cert_db == '\0')) {
12037c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_cert_db;
12047c478bd9Sstevel@tonic-gate 		report_error(NULL, NULL);
12057c478bd9Sstevel@tonic-gate 		return (-1);
12067c478bd9Sstevel@tonic-gate 	}
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate 	if (verbose)
12097c478bd9Sstevel@tonic-gate 		report_info(
12107c478bd9Sstevel@tonic-gate 		    "Getting configuration from LDAP server(s): ",
12117c478bd9Sstevel@tonic-gate 		    config_info->default_servers);
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12147c478bd9Sstevel@tonic-gate 	get_attribute_list(proxy_info, nis_config, NULL, table_info,
12157c478bd9Sstevel@tonic-gate 	    ldap_config_attributes);
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(config_info->default_servers, 0,
12187c478bd9Sstevel@tonic-gate 	    config_info)) == NULL)
12197c478bd9Sstevel@tonic-gate 		return (-1);
12207c478bd9Sstevel@tonic-gate 
12217c478bd9Sstevel@tonic-gate 	/* Get the attribute values */
12227c478bd9Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
12237c478bd9Sstevel@tonic-gate 	    "objectclass=nisplusLDAPconfig",
12247c478bd9Sstevel@tonic-gate 	    ldap_config_attributes, 0, &resultMsg);
12257c478bd9Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	if (errnum == LDAP_REFERRAL) {
12287c478bd9Sstevel@tonic-gate 		rc = process_ldap_referral_msg(ld, resultMsg,
12297c478bd9Sstevel@tonic-gate 		    ldap_config_attributes, proxy_info, nis_config,
12307c478bd9Sstevel@tonic-gate 		    table_mapping, config_info, table_info);
12317c478bd9Sstevel@tonic-gate 	} else if (errnum != LDAP_SUCCESS) {
12327c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
12337c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
12347c478bd9Sstevel@tonic-gate 		rc = -1;
12357c478bd9Sstevel@tonic-gate 	} else {
12367c478bd9Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
12377c478bd9Sstevel@tonic-gate 		    nis_config, table_mapping, table_info);
12387c478bd9Sstevel@tonic-gate 	}
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate 	ldap_source = NULL;
12417c478bd9Sstevel@tonic-gate 	(void) ldap_unbind(ld);
12427c478bd9Sstevel@tonic-gate 	if (resultMsg != NULL)
12437c478bd9Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
12447c478bd9Sstevel@tonic-gate 
12457c478bd9Sstevel@tonic-gate 	return (rc);
12467c478bd9Sstevel@tonic-gate }
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate bool_t
is_cmd_line_option(config_key a_num)12497c478bd9Sstevel@tonic-gate is_cmd_line_option(config_key a_num)
12507c478bd9Sstevel@tonic-gate {
12517c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options = cmdline_config;
12527c478bd9Sstevel@tonic-gate 	config_key		attrib_num;
12537c478bd9Sstevel@tonic-gate 	const char		*begin_s;
12547c478bd9Sstevel@tonic-gate 	const char		*end_s;
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate 	if (cmdline_options == NULL)
12577c478bd9Sstevel@tonic-gate 		return (FALSE);
12587c478bd9Sstevel@tonic-gate 
12597c478bd9Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
12607c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
12617c478bd9Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
12627c478bd9Sstevel@tonic-gate 		if (attrib_num == a_num)
12637c478bd9Sstevel@tonic-gate 			break;
12647c478bd9Sstevel@tonic-gate 		cmdline_options++;
12657c478bd9Sstevel@tonic-gate 	}
12667c478bd9Sstevel@tonic-gate 	return (*cmdline_options != NULL);
12677c478bd9Sstevel@tonic-gate }
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate /*
12707c478bd9Sstevel@tonic-gate  * FUNCTION:	get_attribute_list
12717c478bd9Sstevel@tonic-gate  *
12727c478bd9Sstevel@tonic-gate  *	Get a list of attributes from the LDAP server that have not yet
12737c478bd9Sstevel@tonic-gate  *	been gotten. If config_info is NULL, the associated parameters
12747c478bd9Sstevel@tonic-gate  *	are not needed.
12757c478bd9Sstevel@tonic-gate  *
12767c478bd9Sstevel@tonic-gate  * RETURN VALUE:	none
12777c478bd9Sstevel@tonic-gate  *
12787c478bd9Sstevel@tonic-gate  * INPUT:		Returns a list of parameters in attributes
12797c478bd9Sstevel@tonic-gate  *			which is assumed to be of sufficient size.
12807c478bd9Sstevel@tonic-gate  */
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate static void
get_attribute_list(const __nis_ldap_proxy_info * proxy_info,const __nis_config_t * nis_config,const __nis_config_info_t * config_info,const __nisdb_table_mapping_t * table_info,char ** attributes)12837c478bd9Sstevel@tonic-gate get_attribute_list(
12847c478bd9Sstevel@tonic-gate 	const __nis_ldap_proxy_info	*proxy_info,
12857c478bd9Sstevel@tonic-gate 	const __nis_config_t		*nis_config,
12867c478bd9Sstevel@tonic-gate 	const __nis_config_info_t	*config_info,
12877c478bd9Sstevel@tonic-gate 	const __nisdb_table_mapping_t	*table_info,
12887c478bd9Sstevel@tonic-gate 	char				**attributes)
12897c478bd9Sstevel@tonic-gate {
12907c478bd9Sstevel@tonic-gate 	int		n_attrs;
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12937c478bd9Sstevel@tonic-gate 	n_attrs = 0;
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 	if (config_info != NULL) {
12967c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
12977c478bd9Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
12987c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_DN;
12997c478bd9Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
13007c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_SERVER_LIST;
13017c478bd9Sstevel@tonic-gate 			if (config_info->auth_method ==
13027c478bd9Sstevel@tonic-gate 			    (auth_method_t)NO_VALUE_SET)
13037c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_AUTH_METHOD;
13047c478bd9Sstevel@tonic-gate 			if (config_info->tls_method ==
13057c478bd9Sstevel@tonic-gate 			    (tls_method_t)NO_VALUE_SET)
13067c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_OPTION;
13077c478bd9Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13087c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_USER;
13097c478bd9Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13107c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_PASSWD;
13117c478bd9Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13127c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_CERT_DB;
13137c478bd9Sstevel@tonic-gate 		} else {
13147c478bd9Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
13157c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_DN;
13167c478bd9Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
13177c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_SERVER_LIST;
13187c478bd9Sstevel@tonic-gate 			if (config_info->auth_method ==
13197c478bd9Sstevel@tonic-gate 			    (auth_method_t)NO_VALUE_SET)
13207c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_AUTH_METHOD;
13217c478bd9Sstevel@tonic-gate 			if (config_info->tls_method ==
13227c478bd9Sstevel@tonic-gate 			    (tls_method_t)NO_VALUE_SET)
13237c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_OPTION;
13247c478bd9Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13257c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_USER;
13267c478bd9Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13277c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_PASSWD;
13287c478bd9Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13297c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_CERT_DB;
13307c478bd9Sstevel@tonic-gate 		}
13317c478bd9Sstevel@tonic-gate 	} else {
13327c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
13337c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DOMAIN_CONTEXT;
13347c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YPPASSWDD_DOMAINS;
13357c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DB_ID_MAP;
13367c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_COMMENT_CHAR;
13377c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MAP_FLAGS;
13387c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ENTRY_TTL;
13397c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_NAME_FIELDS;
13407c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SPLIT_FIELD;
13417c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_REPEATED_FIELD_SEPARATORS;
13427c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_OBJECT_DN;
13437c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = NIS_TO_LDAP_MAP;
13447c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NIS_MAP;
13457c478bd9Sstevel@tonic-gate 		} else {
13467c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = DB_ID_MAP;
13477c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = ENTRY_TTL;
13487c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_OBJECT_DN;
13497c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = NISPLUS_TO_LDAP_MAP;
13507c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NISPLUS_MAP;
13517c478bd9Sstevel@tonic-gate 		}
13527c478bd9Sstevel@tonic-gate 	}
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate 	if (yp2ldap) {
13557c478bd9Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
13567c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
13577c478bd9Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
13587c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
13597c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
13607c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_OPTION;
13617c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
13627c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_CERT_DB;
13637c478bd9Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
13647c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
13657c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
13667c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_USER;
13677c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
13687c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_PASSWD;
13697c478bd9Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
13707c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_BASE_DOMAIN;
13717c478bd9Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
13727c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
13737c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_BIND_TIMEOUT;
13747c478bd9Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
13757c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
13767c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIMEOUT;
13777c478bd9Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
13787c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
13797c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MODIFY_TIMEOUT;
13807c478bd9Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
13817c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ADD_TIMEOUT;
13827c478bd9Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
13837c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
13847c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DELETE_TIMEOUT;
13857c478bd9Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
13867c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIME_LIMIT;
13877c478bd9Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
13887c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_SIZE_LIMIT;
13897c478bd9Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
13907c478bd9Sstevel@tonic-gate 		    (follow_referral_t)NO_VALUE_SET)
13917c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_FOLLOW_REFERRAL;
13927c478bd9Sstevel@tonic-gate 
13937c478bd9Sstevel@tonic-gate 		if (table_info->retrieveError ==
13947c478bd9Sstevel@tonic-gate 		    (__nis_retrieve_error_t)NO_VALUE_SET)
13957c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETRIEVE_ERROR_ACTION;
13967c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
13977c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_ATTEMPTS;
13987c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
13997c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14007c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_TIMEOUT;
14017c478bd9Sstevel@tonic-gate 		if (table_info->storeError ==
14027c478bd9Sstevel@tonic-gate 		    (__nis_store_error_t)NO_VALUE_SET)
14037c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ACTION;
14047c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14057c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ATTEMPTS;
14067c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
14077c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14087c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_TIMEOUT;
14097c478bd9Sstevel@tonic-gate 		if (table_info->refreshError ==
14107c478bd9Sstevel@tonic-gate 		    (__nis_refresh_error_t)NO_VALUE_SET)
14117c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14127c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14137c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14147c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
14157c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14167c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14177c478bd9Sstevel@tonic-gate 		if (table_info->matchFetch ==
14187c478bd9Sstevel@tonic-gate 		    (__nis_match_fetch_t)NO_VALUE_SET)
14197c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MATCH_FETCH;
14207c478bd9Sstevel@tonic-gate 	} else {
14217c478bd9Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
14227c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
14237c478bd9Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
14247c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
14257c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
14267c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_OPTION;
14277c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
14287c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_CERT_DB;
14297c478bd9Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
14307c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
14317c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
14327c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_USER;
14337c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
14347c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_PASSWD;
14357c478bd9Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
14367c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_BASE_DOMAIN;
14377c478bd9Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
14387c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14397c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = BIND_TIMEOUT;
14407c478bd9Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
14417c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14427c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIMEOUT;
14437c478bd9Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
14447c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14457c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = MODIFY_TIMEOUT;
14467c478bd9Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
14477c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = ADD_TIMEOUT;
14487c478bd9Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
14497c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14507c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = DELETE_TIMEOUT;
14517c478bd9Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
14527c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIME_LIMIT;
14537c478bd9Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
14547c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_SIZE_LIMIT;
14557c478bd9Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
14567c478bd9Sstevel@tonic-gate 		    (follow_referral_t)NO_VALUE_SET)
14577c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = FOLLOW_REFERRAL;
14587c478bd9Sstevel@tonic-gate 
14597c478bd9Sstevel@tonic-gate 		if (table_info->retrieveError ==
14607c478bd9Sstevel@tonic-gate 		    (__nis_retrieve_error_t)NO_VALUE_SET)
14617c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETRIEVE_ERROR_ACTION;
14627c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
14637c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_ATTEMPTS;
14647c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
14657c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14667c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_TIMEOUT;
14677c478bd9Sstevel@tonic-gate 		if (table_info->storeError ==
14687c478bd9Sstevel@tonic-gate 		    (__nis_store_error_t)NO_VALUE_SET)
14697c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ACTION;
14707c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14717c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ATTEMPTS;
14727c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
14737c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14747c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_TIMEOUT;
14757c478bd9Sstevel@tonic-gate 		if (table_info->refreshError ==
14767c478bd9Sstevel@tonic-gate 		    (__nis_refresh_error_t)NO_VALUE_SET)
14777c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14787c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14797c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14807c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
14817c478bd9Sstevel@tonic-gate 		    (time_t)NO_VALUE_SET)
14827c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14837c478bd9Sstevel@tonic-gate 		if (table_info->matchFetch ==
14847c478bd9Sstevel@tonic-gate 		    (__nis_match_fetch_t)NO_VALUE_SET)
14857c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = MATCH_FETCH;
14867c478bd9Sstevel@tonic-gate 	}
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 	switch (nis_config->initialUpdate) {
14897c478bd9Sstevel@tonic-gate 	case (__nis_initial_update_t)NO_VALUE_SET:
14907c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
14917c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
14927c478bd9Sstevel@tonic-gate 		break;
14937c478bd9Sstevel@tonic-gate 	case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION:
14947c478bd9Sstevel@tonic-gate 	case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION:
14957c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
14967c478bd9Sstevel@tonic-gate 		break;
14977c478bd9Sstevel@tonic-gate 	case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE:
14987c478bd9Sstevel@tonic-gate 	case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE:
14997c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
15007c478bd9Sstevel@tonic-gate 		break;
15017c478bd9Sstevel@tonic-gate 	}
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationError ==
15047c478bd9Sstevel@tonic-gate 	    (__nis_thread_creation_error_t)NO_VALUE_SET)
15057c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ACTION;
15067c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.attempts == NO_VALUE_SET)
15077c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ATTEMPTS;
15087c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.timeout ==
15097c478bd9Sstevel@tonic-gate 	    (time_t)NO_VALUE_SET)
15107c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_TIMEOUT;
15117c478bd9Sstevel@tonic-gate 	if (nis_config->dumpError == (__nis_dump_error_t)NO_VALUE_SET)
15127c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ACTION;
15137c478bd9Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.attempts == NO_VALUE_SET)
15147c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ATTEMPTS;
15157c478bd9Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET)
15167c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_TIMEOUT;
15177c478bd9Sstevel@tonic-gate 	if (nis_config->resyncService == (__nis_resync_service_t)NO_VALUE_SET)
15187c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = RESYNC;
15197c478bd9Sstevel@tonic-gate 	if (nis_config->updateBatching ==
15207c478bd9Sstevel@tonic-gate 	    (__nis_update_batching_t)NO_VALUE_SET)
15217c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING;
15227c478bd9Sstevel@tonic-gate 	if (nis_config->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET)
15237c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING_TIMEOUT;
15247c478bd9Sstevel@tonic-gate 	if (nis_config->numberOfServiceThreads == (int)NO_VALUE_SET)
15257c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = NUMBER_THEADS;
15267c478bd9Sstevel@tonic-gate 	if (nis_config->emulate_yp == (int)NO_VALUE_SET)
15277c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = YP_EMULATION;
15287c478bd9Sstevel@tonic-gate 
15297c478bd9Sstevel@tonic-gate 	/* maxRPCRecordSize is not configurable through LDAP profiles */
15307c478bd9Sstevel@tonic-gate 	if (nis_config->maxRPCRecordSize == (int)NO_VALUE_SET)
15317c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = MAX_RPC_RECSIZE;
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate 	attributes[n_attrs++] = NULL;
15347c478bd9Sstevel@tonic-gate }
15357c478bd9Sstevel@tonic-gate 
15367c478bd9Sstevel@tonic-gate /*
15377c478bd9Sstevel@tonic-gate  *	Notes on adding new attributes
15387c478bd9Sstevel@tonic-gate  *	1. Determine where the attribute value will be saved
15397c478bd9Sstevel@tonic-gate  *	    Currently, the following structures are defined:
15407c478bd9Sstevel@tonic-gate  *		__nis_config_info_t	config_info
15417c478bd9Sstevel@tonic-gate  *		__nis_ldap_proxy_info	proxyInfo
15427c478bd9Sstevel@tonic-gate  *		__nis_config_t		ldapConfig
15437c478bd9Sstevel@tonic-gate  *		__nisdb_table_mapping_t	ldapDBTableMapping
15447c478bd9Sstevel@tonic-gate  *		__nis_table_mapping_t	ldapTableMapping
15457c478bd9Sstevel@tonic-gate  *	    or add a new structure or variable - this will require
15467c478bd9Sstevel@tonic-gate  *	    more code.
15477c478bd9Sstevel@tonic-gate  *	2. Initialize the value to a known unconfigured value.
15487c478bd9Sstevel@tonic-gate  *	    This can be done in initialize_parse_structs or
15497c478bd9Sstevel@tonic-gate  *	    parse_ldap_migration.
15507c478bd9Sstevel@tonic-gate  *	3. In the header file nis_parse_ldap_conf.h, add the name
15517c478bd9Sstevel@tonic-gate  *	    of the attribute. (Currently, the attribute name is assumed
15527c478bd9Sstevel@tonic-gate  *	    to be the same for the command line, the preference file,
15537c478bd9Sstevel@tonic-gate  *	    and LDAP.) The names are grouped logically. Add a corresponding
15547c478bd9Sstevel@tonic-gate  *	    config_key to the enum. Note that position in this file is
15557c478bd9Sstevel@tonic-gate  *	    essential because the macros such as IS_BIND_INFO depend on
15567c478bd9Sstevel@tonic-gate  *	    the sequence. The corresponding macro (IS_CONFIG_KEYWORD,
15577c478bd9Sstevel@tonic-gate  *	    IS_BIND_INFO, or IS_OPER_INFO) may need to be adjusted. These
15587c478bd9Sstevel@tonic-gate  *	    are used to partition the attributes into smaller chunks.
15597c478bd9Sstevel@tonic-gate  *	4. Add the correspond entry to the keyword_lookup array in
15607c478bd9Sstevel@tonic-gate  *	    nis_parse_ldap_attr.c, which is used to determine the config_key
15617c478bd9Sstevel@tonic-gate  *	    from the corresponding key word.
15627c478bd9Sstevel@tonic-gate  *	5. Add the attribute to the list of attributes to retrieve from
15637c478bd9Sstevel@tonic-gate  *	    the LDAP server if no value has been set in the function
15647c478bd9Sstevel@tonic-gate  *	    parse_ldap_config_dn_attrs. (This assumes that the attribute
15657c478bd9Sstevel@tonic-gate  *	    is not used to get the configuration from the LDAP server.)
15667c478bd9Sstevel@tonic-gate  *	6. Add logic to parse the individual attribute in
15677c478bd9Sstevel@tonic-gate  *	    add_config_attribute, add_bind_attribute,
15687c478bd9Sstevel@tonic-gate  *	    add_operation_attribute, or add_mapping_attribute depending
15697c478bd9Sstevel@tonic-gate  *	    which group of attributes the added attribute belongs to.
15707c478bd9Sstevel@tonic-gate  *	7. In set_default_values, if the attribute value has not been set, set
15717c478bd9Sstevel@tonic-gate  *	    the default value. If any additional fixup is needed depending
15727c478bd9Sstevel@tonic-gate  *	    on other configuration values, it should be done here.
15737c478bd9Sstevel@tonic-gate  *	8. If an attribute name is a subset of another, parse_ldap_default_conf
15747c478bd9Sstevel@tonic-gate  *          should be modified.
15757c478bd9Sstevel@tonic-gate  */
1576