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 /*
22a87701e9SGary Mills  * Copyright 2015 Gary Mills
23b9175c69SKenjiro Tsuji  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <ctype.h>
317c478bd9Sstevel@tonic-gate #include <fcntl.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <locale.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <lber.h>
377c478bd9Sstevel@tonic-gate #include <ldap.h>
387c478bd9Sstevel@tonic-gate #include <deflt.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include "ldap_map.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include "ldap_parse.h"
437c478bd9Sstevel@tonic-gate #include "ldap_glob.h"
447c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info	proxyInfo		=
477c478bd9Sstevel@tonic-gate 	{NULL, (auth_method_t)NO_VALUE_SET, (tls_method_t)NO_VALUE_SET, NULL,
487c478bd9Sstevel@tonic-gate 		NULL, NULL, NULL, NULL, (follow_referral_t)NO_VALUE_SET};
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;
56*9c508120SToomas Soome 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 
87a87701e9SGary Mills /* Forward declarations */
88a87701e9SGary Mills int yp_parse_ldap_config_file(const char *, __nis_ldap_proxy_info *,
89a87701e9SGary Mills     __nis_config_t *, __nis_table_mapping_t **, __nis_config_info_t *,
90*9c508120SToomas Soome     __nisdb_table_mapping_t *, __yp_domain_context_t *);
91a87701e9SGary Mills 
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* helper functions */
947c478bd9Sstevel@tonic-gate static config_key get_attrib_num_cmdline(const char *s,
957c478bd9Sstevel@tonic-gate     const char **begin_s, const char **end_s);
967c478bd9Sstevel@tonic-gate static config_key get_file_attr_val(int fd, char **attr_val);
977c478bd9Sstevel@tonic-gate static void get_attribute_list(
987c478bd9Sstevel@tonic-gate 	const __nis_ldap_proxy_info *proxy_info,
997c478bd9Sstevel@tonic-gate 	const __nis_config_t *nis_config,
1007c478bd9Sstevel@tonic-gate 	const __nis_config_info_t *config_info,
1017c478bd9Sstevel@tonic-gate 	const __nisdb_table_mapping_t *table_info,
1027c478bd9Sstevel@tonic-gate 	char **ldap_config_attributes);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_migration
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP. The values are first
1087c478bd9Sstevel@tonic-gate  *	obtained from the command line, secondly from the preference
1097c478bd9Sstevel@tonic-gate  *	file, and finally from an LDAP profile (if so configured in
1107c478bd9Sstevel@tonic-gate  *	the command line or preference file). Any unset values will
1117c478bd9Sstevel@tonic-gate  *	be set to their default values.
1127c478bd9Sstevel@tonic-gate  *
1137c478bd9Sstevel@tonic-gate  *	If no command line options, no settings in the /etc/default
1147c478bd9Sstevel@tonic-gate  *  configuration file, and no mapping file, then no mapping
1157c478bd9Sstevel@tonic-gate  *  should be used.
1167c478bd9Sstevel@tonic-gate  *
1177c478bd9Sstevel@tonic-gate  * RETURN VALUE:
1187c478bd9Sstevel@tonic-gate  *			0	Success
1197c478bd9Sstevel@tonic-gate  *			-1	Config file stat/open or parse error
1207c478bd9Sstevel@tonic-gate  *			1	No mapping should be used.
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * INPUT:		command line parameters, configuration file
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate int
parse_ldap_migration(const char * const * cmdline_options,const char * config_file)1267c478bd9Sstevel@tonic-gate parse_ldap_migration(
1277c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options,
1287c478bd9Sstevel@tonic-gate 	const char		*config_file)
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	int			rc	= 0;
1317c478bd9Sstevel@tonic-gate 	__nis_config_info_t	config_info
1327c478bd9Sstevel@tonic-gate 				= {NULL, NULL, (auth_method_t)NO_VALUE_SET,
1337c478bd9Sstevel@tonic-gate 					(tls_method_t)NO_VALUE_SET, NULL,
1347c478bd9Sstevel@tonic-gate 					NULL, NULL};
1357c478bd9Sstevel@tonic-gate 	struct stat		buf;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	p_error = no_parse_error;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	if (verbose)
1407c478bd9Sstevel@tonic-gate 		report_info("Getting LDAP configuration", NULL);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	initialize_parse_structs(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	if (yp2ldap)
1457c478bd9Sstevel@tonic-gate 		initialize_yp_parse_structs(&ypDomains);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	if (cmdline_options != NULL) {
1487c478bd9Sstevel@tonic-gate 		got_config_data = TRUE;
1497c478bd9Sstevel@tonic-gate 		/* NIS to LDAP does not read command line attributes */
1507c478bd9Sstevel@tonic-gate 		if (!yp2ldap)
1517c478bd9Sstevel@tonic-gate 			rc = parse_ldap_cmd_line(cmdline_options, &proxyInfo,
152b9175c69SKenjiro Tsuji 			    &ldapConfig, &ldapTableMapping, &config_info,
153b9175c69SKenjiro Tsuji 			    &ldapDBTableMapping);
1547c478bd9Sstevel@tonic-gate 		else
1557c478bd9Sstevel@tonic-gate 			rc = 0;
1567c478bd9Sstevel@tonic-gate 	}
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	if (rc == 0) {
1597c478bd9Sstevel@tonic-gate 		if (yp2ldap)
1607c478bd9Sstevel@tonic-gate 			rc = yp_parse_ldap_default_conf(&proxyInfo, &ldapConfig,
161b9175c69SKenjiro Tsuji 			    &config_info, &ldapDBTableMapping);
1627c478bd9Sstevel@tonic-gate 		else
1637c478bd9Sstevel@tonic-gate 			rc = parse_ldap_default_conf(&proxyInfo, &ldapConfig,
164b9175c69SKenjiro Tsuji 			    &config_info, &ldapDBTableMapping);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (config_file == NULL) {
1687c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
1697c478bd9Sstevel@tonic-gate 			if (stat(YP_DEFAULT_MAPPING_FILE, &buf) == 0)
1707c478bd9Sstevel@tonic-gate 				config_file = YP_DEFAULT_MAPPING_FILE;
1717c478bd9Sstevel@tonic-gate 		} else {
1727c478bd9Sstevel@tonic-gate 			if (stat(DEFAULT_MAPPING_FILE, &buf) == 0)
1737c478bd9Sstevel@tonic-gate 				config_file = DEFAULT_MAPPING_FILE;
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (rc == 0 && config_file != NULL) {
1787c478bd9Sstevel@tonic-gate 		got_config_data = TRUE;
1797c478bd9Sstevel@tonic-gate 		warn_file = config_file;
1807c478bd9Sstevel@tonic-gate 		cmdline_config = cmdline_options;
1817c478bd9Sstevel@tonic-gate 		if (yp2ldap)
1827c478bd9Sstevel@tonic-gate 			rc = yp_parse_ldap_config_file(config_file, &proxyInfo,
183b9175c69SKenjiro Tsuji 			    &ldapConfig, &ldapTableMapping, &config_info,
184b9175c69SKenjiro Tsuji 			    &ldapDBTableMapping, &ypDomains);
1857c478bd9Sstevel@tonic-gate 		else
1867c478bd9Sstevel@tonic-gate 			rc = parse_ldap_config_file(config_file, &proxyInfo,
187b9175c69SKenjiro Tsuji 			    &ldapConfig, &ldapTableMapping, &config_info,
188b9175c69SKenjiro Tsuji 			    &ldapDBTableMapping);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 		warn_file = NULL;
1917c478bd9Sstevel@tonic-gate 		cmdline_config = NULL;
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 	if (rc == 0 && (config_info.config_dn != NULL) &&
194b9175c69SKenjiro Tsuji 	    (config_info.config_dn[0] != '\0')) {
1957c478bd9Sstevel@tonic-gate 		rc = parse_ldap_config_dn_attrs(&proxyInfo,
196b9175c69SKenjiro Tsuji 		    &ldapConfig, &ldapTableMapping, &config_info,
197b9175c69SKenjiro Tsuji 		    &ldapDBTableMapping);
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	free_config_info(&config_info);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	if (rc == 0 && got_config_data == FALSE)
2037c478bd9Sstevel@tonic-gate 		rc = 1;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	set_default_values(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	if (yp2ldap == 1 && rc == 0) {
2087c478bd9Sstevel@tonic-gate 		rc = second_parser_pass(&ldapTableMapping);
2097c478bd9Sstevel@tonic-gate 		if (rc == 0)
2107c478bd9Sstevel@tonic-gate 			rc = final_parser_pass(&ldapTableMapping, &ypDomains);
2117c478bd9Sstevel@tonic-gate 		if (rc == -2)
2127c478bd9Sstevel@tonic-gate 			return (-1);
2137c478bd9Sstevel@tonic-gate 	}
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	if (rc == 0)
2167c478bd9Sstevel@tonic-gate 		rc = finish_parse(&proxyInfo, &ldapTableMapping);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	if (rc == 0)
2197c478bd9Sstevel@tonic-gate 		rc = linked2hash(ldapTableMapping);
2207c478bd9Sstevel@tonic-gate 
2214a190493Ssdussud 	if ((rc == 0) && yptol_mode)
2224a190493Ssdussud 		rc = map_id_list_init();
2234a190493Ssdussud 
2247c478bd9Sstevel@tonic-gate 	if (rc != 0) {
2257c478bd9Sstevel@tonic-gate 		free_parse_structs();
2267c478bd9Sstevel@tonic-gate 	} else if (verbose)
2277c478bd9Sstevel@tonic-gate 		report_info("LDAP configuration complete", NULL);
2287c478bd9Sstevel@tonic-gate 	return (rc);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_cmd_line
2337c478bd9Sstevel@tonic-gate  *
2347c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
2357c478bd9Sstevel@tonic-gate  *
2367c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  * INPUT:		command line values
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@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)2427c478bd9Sstevel@tonic-gate parse_ldap_cmd_line(
2437c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options,
2447c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
2457c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
2467c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
2477c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
2487c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
2497c478bd9Sstevel@tonic-gate {
2507c478bd9Sstevel@tonic-gate 	int		rc = 0;
2517c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
2527c478bd9Sstevel@tonic-gate 	const char	*begin_s;
2537c478bd9Sstevel@tonic-gate 	const char	*end_s;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (verbose)
2567c478bd9Sstevel@tonic-gate 		report_info("Command line values: ", NULL);
2577c478bd9Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
2587c478bd9Sstevel@tonic-gate 		if (verbose)
2597c478bd9Sstevel@tonic-gate 			report_info("\t", *cmdline_options);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
2627c478bd9Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
2637c478bd9Sstevel@tonic-gate 		if (attrib_num == key_bad) {
2647c478bd9Sstevel@tonic-gate 			command_line_source = "command line";
2657c478bd9Sstevel@tonic-gate 			report_error(*cmdline_options, NULL);
2667c478bd9Sstevel@tonic-gate 			command_line_source = NULL;
2677c478bd9Sstevel@tonic-gate 			rc = -1;
2687c478bd9Sstevel@tonic-gate 			break;
2697c478bd9Sstevel@tonic-gate 		} else if (IS_CONFIG_KEYWORD(attrib_num)) {
2707c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
2717c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, config_info);
2727c478bd9Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
2737c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
2747c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, proxy_info);
2757c478bd9Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
2767c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
2777c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, nis_config,
2787c478bd9Sstevel@tonic-gate 			    table_info);
2797c478bd9Sstevel@tonic-gate 		} else {
2807c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
2817c478bd9Sstevel@tonic-gate 			    begin_s, end_s - begin_s, table_mapping);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		if (rc < 0) {
2857c478bd9Sstevel@tonic-gate 			command_line_source = "command line";
2867c478bd9Sstevel@tonic-gate 			report_error(begin_s, _key_val);
2877c478bd9Sstevel@tonic-gate 			command_line_source = NULL;
2887c478bd9Sstevel@tonic-gate 			break;
2897c478bd9Sstevel@tonic-gate 		}
2907c478bd9Sstevel@tonic-gate 		cmdline_options++;
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 	return (rc);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@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)2967c478bd9Sstevel@tonic-gate parse_ldap_default_conf(
2977c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
2987c478bd9Sstevel@tonic-gate 	__nis_config_t *nis_config,
2997c478bd9Sstevel@tonic-gate 	__nis_config_info_t *config_info,
3007c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 	int		rc = 0;
3037c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
3047c478bd9Sstevel@tonic-gate 	char		attr_buf[128];
3057c478bd9Sstevel@tonic-gate 	char		*attr;
306b9175c69SKenjiro Tsuji 	char		*attr_val;
3077c478bd9Sstevel@tonic-gate 	int		defflags;
3087c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
3097c478bd9Sstevel@tonic-gate 	int		i;
3107c478bd9Sstevel@tonic-gate 	int		len;
3117c478bd9Sstevel@tonic-gate 	int		attr_len;
312b9175c69SKenjiro Tsuji 	void		*defp;
3137c478bd9Sstevel@tonic-gate 
314b9175c69SKenjiro Tsuji 	if ((defp = defopen_r(ETCCONFFILE)) != NULL) {
315b9175c69SKenjiro Tsuji 		file_source = ETCCONFFILE;
316b9175c69SKenjiro Tsuji 		if (verbose)
317b9175c69SKenjiro Tsuji 			report_info("default configuration values: ", NULL);
318b9175c69SKenjiro Tsuji 		/* Set defread_r() to be case insensitive */
319b9175c69SKenjiro Tsuji 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
320b9175c69SKenjiro Tsuji 		TURNOFF(defflags, DC_CASE);
321b9175c69SKenjiro Tsuji 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
322b9175c69SKenjiro Tsuji 
323b9175c69SKenjiro Tsuji 		get_attribute_list(proxy_info, nis_config, config_info,
324b9175c69SKenjiro Tsuji 		    table_info, ldap_config_attributes);
325b9175c69SKenjiro Tsuji 		i = 0;
326b9175c69SKenjiro Tsuji 		while ((attr = ldap_config_attributes[i++]) != NULL) {
327b9175c69SKenjiro Tsuji 			(void) strlcpy(attr_buf, attr, sizeof (attr_buf));
328b9175c69SKenjiro Tsuji 			/*
329b9175c69SKenjiro Tsuji 			 * if nisplusUpdateBatching, make sure
330b9175c69SKenjiro Tsuji 			 * we don't match nisplusUpdateBatchingTimeout
331b9175c69SKenjiro Tsuji 			 */
332b9175c69SKenjiro Tsuji 			if (strcmp(attr, UPDATE_BATCHING) == 0) {
333b9175c69SKenjiro Tsuji 				attr_len = strlen(attr);
334b9175c69SKenjiro Tsuji 				attr_buf[attr_len] = '=';
335b9175c69SKenjiro Tsuji 				attr_buf[attr_len + 1] = '\0';
336b9175c69SKenjiro Tsuji 				attr_val = defread_r(attr_buf, defp);
337b9175c69SKenjiro Tsuji 
338b9175c69SKenjiro Tsuji 				if (attr_val == 0) {
339b9175c69SKenjiro Tsuji 					attr_buf[attr_len] = ' ';
340b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3417c478bd9Sstevel@tonic-gate 				}
342b9175c69SKenjiro Tsuji 				if (attr_val == 0) {
343b9175c69SKenjiro Tsuji 					attr_buf[attr_len] = '\t';
344b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3457c478bd9Sstevel@tonic-gate 				}
346b9175c69SKenjiro Tsuji 				if (attr_val == 0) {
347b9175c69SKenjiro Tsuji 					attr_buf[attr_len] = '\n';
348b9175c69SKenjiro Tsuji 					attr_val = defread_r(attr_buf, defp);
3497c478bd9Sstevel@tonic-gate 				}
350b9175c69SKenjiro Tsuji 			} else {
351b9175c69SKenjiro Tsuji 				attr_val = defread_r(attr_buf, defp);
352b9175c69SKenjiro Tsuji 			}
353b9175c69SKenjiro Tsuji 			if (attr_val == NULL)
354b9175c69SKenjiro Tsuji 				continue;
355b9175c69SKenjiro Tsuji 
356b9175c69SKenjiro Tsuji 			got_config_data = TRUE;
357b9175c69SKenjiro Tsuji 			attrib_num = get_attrib_num(attr, strlen(attr));
358b9175c69SKenjiro Tsuji 			if (attrib_num == key_bad) {
359b9175c69SKenjiro Tsuji 				report_error(attr, NULL);
360b9175c69SKenjiro Tsuji 				rc = -1;
361b9175c69SKenjiro Tsuji 				break;
362b9175c69SKenjiro Tsuji 			}
363b9175c69SKenjiro Tsuji 
364b9175c69SKenjiro Tsuji 			/*
365b9175c69SKenjiro Tsuji 			 * Allow either entries of the form
366b9175c69SKenjiro Tsuji 			 *	attr val
367b9175c69SKenjiro Tsuji 			 *	   or
368b9175c69SKenjiro Tsuji 			 *	attr = val
369b9175c69SKenjiro Tsuji 			 */
370b9175c69SKenjiro Tsuji 			while (is_whitespace(*attr_val))
371b9175c69SKenjiro Tsuji 				attr_val++;
372b9175c69SKenjiro Tsuji 			if (*attr_val == '=')
373b9175c69SKenjiro Tsuji 				attr_val++;
374b9175c69SKenjiro Tsuji 			while (is_whitespace(*attr_val))
375b9175c69SKenjiro Tsuji 				attr_val++;
376b9175c69SKenjiro Tsuji 			len = strlen(attr_val);
377b9175c69SKenjiro Tsuji 			while (len > 0 && is_whitespace(attr_val[len - 1]))
378b9175c69SKenjiro Tsuji 				len--;
379b9175c69SKenjiro Tsuji 
380b9175c69SKenjiro Tsuji 			if (verbose) {
381b9175c69SKenjiro Tsuji 				report_info("\t", attr);
382b9175c69SKenjiro Tsuji 				report_info("\t\t", attr_val);
383b9175c69SKenjiro Tsuji 			}
384b9175c69SKenjiro Tsuji 			if (IS_BIND_INFO(attrib_num)) {
385b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num,
386b9175c69SKenjiro Tsuji 				    attr_val, len, proxy_info);
387b9175c69SKenjiro Tsuji 			} else if (IS_OPER_INFO(attrib_num)) {
388b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
389b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config,
390b9175c69SKenjiro Tsuji 				    table_info);
391b9175c69SKenjiro Tsuji 			}
392b9175c69SKenjiro Tsuji 			if (p_error != no_parse_error) {
393b9175c69SKenjiro Tsuji 				report_error(attr_val, attr);
394b9175c69SKenjiro Tsuji 				rc = -1;
395b9175c69SKenjiro Tsuji 				break;
3967c478bd9Sstevel@tonic-gate 			}
3977c478bd9Sstevel@tonic-gate 		}
398b9175c69SKenjiro Tsuji 		file_source = NULL;
399b9175c69SKenjiro Tsuji 		/* Close the /etc/default file */
400b9175c69SKenjiro Tsuji 		defclose_r(defp);
401b9175c69SKenjiro Tsuji 	}
402b9175c69SKenjiro Tsuji 	return (rc);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@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)4067c478bd9Sstevel@tonic-gate yp_parse_ldap_default_conf(
4077c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
4087c478bd9Sstevel@tonic-gate 	__nis_config_t	*nis_config,
4097c478bd9Sstevel@tonic-gate 	__nis_config_info_t *config_info,
4107c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t *table_info)
4117c478bd9Sstevel@tonic-gate {
4127c478bd9Sstevel@tonic-gate 	int rc = 0;
4137c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
4147c478bd9Sstevel@tonic-gate 	char		attr_buf[128];
4157c478bd9Sstevel@tonic-gate 	char		*attr;
416b9175c69SKenjiro Tsuji 	char		*attr_val;
4177c478bd9Sstevel@tonic-gate 	int		defflags;
4187c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
419*9c508120SToomas Soome 	int		i, len;
420b9175c69SKenjiro Tsuji 	void		*defp;
4217c478bd9Sstevel@tonic-gate 
422b9175c69SKenjiro Tsuji 	if ((defp = defopen_r(YP_ETCCONFFILE)) != NULL) {
4237c478bd9Sstevel@tonic-gate 		file_source = YP_ETCCONFFILE;
4247c478bd9Sstevel@tonic-gate 		if (verbose)
4257c478bd9Sstevel@tonic-gate 			report_info("default configuration values: ", NULL);
426b9175c69SKenjiro Tsuji 		/* Set defread_r() to be case insensitive */
427b9175c69SKenjiro Tsuji 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
428b9175c69SKenjiro Tsuji 		TURNOFF(defflags, DC_CASE);
429b9175c69SKenjiro Tsuji 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
430b9175c69SKenjiro Tsuji 
431b9175c69SKenjiro Tsuji 		get_attribute_list(proxy_info, nis_config, config_info,
432b9175c69SKenjiro Tsuji 		    table_info, ldap_config_attributes);
433b9175c69SKenjiro Tsuji 		i = 0;
434b9175c69SKenjiro Tsuji 		while ((attr = ldap_config_attributes[i++]) != NULL) {
435b9175c69SKenjiro Tsuji 			if ((strlcpy(attr_buf, attr, sizeof (attr_buf))) >=
436b9175c69SKenjiro Tsuji 			    sizeof (attr_buf)) {
437b9175c69SKenjiro Tsuji 				report_error(
438b9175c69SKenjiro Tsuji 				    "Static buffer attr_buf overflow", NULL);
439b9175c69SKenjiro Tsuji 				defclose_r(defp);
440b9175c69SKenjiro Tsuji 				return (-1);
441b9175c69SKenjiro Tsuji 			}
4427c478bd9Sstevel@tonic-gate 
443b9175c69SKenjiro Tsuji 			if ((attr_val = defread_r(attr_buf, defp)) == NULL)
444b9175c69SKenjiro Tsuji 				continue;
4457c478bd9Sstevel@tonic-gate 
446b9175c69SKenjiro Tsuji 			got_config_data = TRUE;
447b9175c69SKenjiro Tsuji 			attrib_num = get_attrib_num(attr, strlen(attr));
448b9175c69SKenjiro Tsuji 			if (attrib_num == key_bad) {
449b9175c69SKenjiro Tsuji 				report_error(attr, NULL);
450b9175c69SKenjiro Tsuji 				rc = -1;
451b9175c69SKenjiro Tsuji 				break;
452b9175c69SKenjiro Tsuji 			}
4537c478bd9Sstevel@tonic-gate 
454b9175c69SKenjiro Tsuji 			/*
455b9175c69SKenjiro Tsuji 			 * Allow either entries of the form
456b9175c69SKenjiro Tsuji 			 * attr val
457b9175c69SKenjiro Tsuji 			 * or
458b9175c69SKenjiro Tsuji 			 * attr = val
459b9175c69SKenjiro Tsuji 			 */
460b9175c69SKenjiro Tsuji 			while (is_whitespace(*attr_val))
461b9175c69SKenjiro Tsuji 				attr_val++;
462b9175c69SKenjiro Tsuji 			if (*attr_val == '=')
463b9175c69SKenjiro Tsuji 				attr_val++;
464b9175c69SKenjiro Tsuji 			while (is_whitespace(*attr_val))
465b9175c69SKenjiro Tsuji 				attr_val++;
466b9175c69SKenjiro Tsuji 			len = strlen(attr_val);
467b9175c69SKenjiro Tsuji 			while (len > 0 && is_whitespace(attr_val[len - 1]))
468b9175c69SKenjiro Tsuji 				len--;
469b9175c69SKenjiro Tsuji 
470b9175c69SKenjiro Tsuji 			if (verbose) {
471b9175c69SKenjiro Tsuji 				report_info("\t", attr);
472b9175c69SKenjiro Tsuji 				report_info("\t\t", attr_val);
473b9175c69SKenjiro Tsuji 			}
474b9175c69SKenjiro Tsuji 			if (IS_YP_BIND_INFO(attrib_num)) {
475b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num,
476b9175c69SKenjiro Tsuji 				    attr_val, len, proxy_info);
477b9175c69SKenjiro Tsuji 			} else if (IS_YP_OPER_INFO(attrib_num)) {
478b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
479b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config,
480b9175c69SKenjiro Tsuji 				    table_info);
481b9175c69SKenjiro Tsuji 			}
482b9175c69SKenjiro Tsuji 			if (p_error != no_parse_error) {
483b9175c69SKenjiro Tsuji 				report_error(attr_val, attr);
484b9175c69SKenjiro Tsuji 				rc = -1;
485b9175c69SKenjiro Tsuji 				break;
4867c478bd9Sstevel@tonic-gate 			}
4877c478bd9Sstevel@tonic-gate 		}
488b9175c69SKenjiro Tsuji 		file_source = NULL;
489b9175c69SKenjiro Tsuji 		/* Close the /etc/default file */
490b9175c69SKenjiro Tsuji 		defclose_r(defp);
491b9175c69SKenjiro Tsuji 	}
492b9175c69SKenjiro Tsuji 	return (rc);
4937c478bd9Sstevel@tonic-gate }
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate /*
4967c478bd9Sstevel@tonic-gate  * FUNCTION:	get_attrib_num_cmdline
4977c478bd9Sstevel@tonic-gate  *
4987c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
4997c478bd9Sstevel@tonic-gate  *	The form of the command line request is
5007c478bd9Sstevel@tonic-gate  *		-x attribute=value
5017c478bd9Sstevel@tonic-gate  *
5027c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
5037c478bd9Sstevel@tonic-gate  *
5047c478bd9Sstevel@tonic-gate  * INPUT:		command line values
5057c478bd9Sstevel@tonic-gate  */
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate static config_key
get_attrib_num_cmdline(const char * s,const char ** begin_s,const char ** end_s)508*9c508120SToomas Soome get_attrib_num_cmdline(const char *s, const char **begin_s, const char **end_s)
5097c478bd9Sstevel@tonic-gate {
5107c478bd9Sstevel@tonic-gate 	const char	*s_end		= s + strlen(s);
5117c478bd9Sstevel@tonic-gate 	const char	*equal_s;
5127c478bd9Sstevel@tonic-gate 	const char	*s1;
5137c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	while (s < s_end && is_whitespace(*s))
5167c478bd9Sstevel@tonic-gate 		s++;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	for (equal_s = s; equal_s < s_end; equal_s++)
5197c478bd9Sstevel@tonic-gate 		if (*equal_s == EQUAL_CHAR)
5207c478bd9Sstevel@tonic-gate 			break;
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	if (equal_s == s_end) {
5237c478bd9Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5247c478bd9Sstevel@tonic-gate 		return (key_bad);
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	for (s1 = equal_s; s1 > s && is_whitespace(s1[-1]); s1--)
5287c478bd9Sstevel@tonic-gate 		;
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	if (s1 == s) {
5317c478bd9Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5327c478bd9Sstevel@tonic-gate 		return (key_bad);
5337c478bd9Sstevel@tonic-gate 	}
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	attrib_num = get_attrib_num(s, s1 - s);
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	if (attrib_num != key_bad) {
5387c478bd9Sstevel@tonic-gate 		s1 = equal_s + 1;
5397c478bd9Sstevel@tonic-gate 		while (s1 < s_end && is_whitespace(*s1))
5407c478bd9Sstevel@tonic-gate 			s1++;
5417c478bd9Sstevel@tonic-gate 		*begin_s = s1;
5427c478bd9Sstevel@tonic-gate 		while (s_end > s1 && is_whitespace(s_end[-1]))
5437c478bd9Sstevel@tonic-gate 			s_end--;
5447c478bd9Sstevel@tonic-gate 		*end_s = s_end;
5457c478bd9Sstevel@tonic-gate 	}
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 	return (attrib_num);
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate /*
5517c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_file
5527c478bd9Sstevel@tonic-gate  *
5537c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from a configuration
5547c478bd9Sstevel@tonic-gate  *	file. If no file is specified, /var/nis/NIS+LDAPmapping
5557c478bd9Sstevel@tonic-gate  *	is used
5567c478bd9Sstevel@tonic-gate  *
5577c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
5587c478bd9Sstevel@tonic-gate  *
5597c478bd9Sstevel@tonic-gate  * INPUT:		configuration file name
5607c478bd9Sstevel@tonic-gate  */
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@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)563*9c508120SToomas Soome parse_ldap_config_file(const char *config_file,
564*9c508120SToomas Soome     __nis_ldap_proxy_info *proxy_info, __nis_config_t *nis_config,
565*9c508120SToomas Soome     __nis_table_mapping_t **table_mapping, __nis_config_info_t *config_info,
566*9c508120SToomas Soome     __nisdb_table_mapping_t *table_info)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate 	int		rc = 0;
5697c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
5707c478bd9Sstevel@tonic-gate 	int		fd;
5717c478bd9Sstevel@tonic-gate 	char		*attr_val;
5727c478bd9Sstevel@tonic-gate 	int		len;
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
5757c478bd9Sstevel@tonic-gate 		p_error = parse_open_file_error;
5767c478bd9Sstevel@tonic-gate 		report_error(config_file, NULL);
5777c478bd9Sstevel@tonic-gate 		return (-1);
5787c478bd9Sstevel@tonic-gate 	}
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	start_line_num = 1;
5817c478bd9Sstevel@tonic-gate 	cur_line_num = 1;
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	if (verbose)
5847c478bd9Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	file_source = config_file;
5877c478bd9Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
5887c478bd9Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
5897c478bd9Sstevel@tonic-gate 		if (IS_CONFIG_KEYWORD(attrib_num)) {
5907c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
5917c478bd9Sstevel@tonic-gate 			    attr_val, len, config_info);
5927c478bd9Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
5937c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
5947c478bd9Sstevel@tonic-gate 			    attr_val, len, proxy_info);
5957c478bd9Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
5967c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
5977c478bd9Sstevel@tonic-gate 			    attr_val, len, nis_config, table_info);
5987c478bd9Sstevel@tonic-gate 		} else {
5997c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
600b9175c69SKenjiro Tsuji 			    attr_val, len, table_mapping);
6017c478bd9Sstevel@tonic-gate 		}
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 		if (rc < 0) {
6047c478bd9Sstevel@tonic-gate 			report_error(attr_val == NULL ?
605b9175c69SKenjiro Tsuji 			    "<no attribute>" : attr_val, _key_val);
6067c478bd9Sstevel@tonic-gate 			if (attr_val)
6077c478bd9Sstevel@tonic-gate 				free(attr_val);
6087c478bd9Sstevel@tonic-gate 			break;
6097c478bd9Sstevel@tonic-gate 		}
6107c478bd9Sstevel@tonic-gate 		if (attr_val)
6117c478bd9Sstevel@tonic-gate 			free(attr_val);
6127c478bd9Sstevel@tonic-gate 	}
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 	(void) close(fd);
6157c478bd9Sstevel@tonic-gate 	if (attrib_num == key_bad) {
6167c478bd9Sstevel@tonic-gate 		report_error(_key_val, NULL);
6177c478bd9Sstevel@tonic-gate 		rc = -1;
6187c478bd9Sstevel@tonic-gate 	}
6197c478bd9Sstevel@tonic-gate 	start_line_num = 0;
6207c478bd9Sstevel@tonic-gate 	file_source = NULL;
6217c478bd9Sstevel@tonic-gate 	return (rc);
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate /*
6257c478bd9Sstevel@tonic-gate  * FUNCTION:	yp_parse_ldap_config_file
6267c478bd9Sstevel@tonic-gate  *
6277c478bd9Sstevel@tonic-gate  * Parses the information for LDAP from a configuration
6287c478bd9Sstevel@tonic-gate  * file. If no file is specified, /var/yp/NISLDAPmapping
6297c478bd9Sstevel@tonic-gate  * is used
6307c478bd9Sstevel@tonic-gate  *
6317c478bd9Sstevel@tonic-gate  * RETURN VALUE:    0 on success, -1 on failure
6327c478bd9Sstevel@tonic-gate  *
6337c478bd9Sstevel@tonic-gate  * INPUT:       configuration file name
6347c478bd9Sstevel@tonic-gate  */
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@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)6377c478bd9Sstevel@tonic-gate yp_parse_ldap_config_file(
6387c478bd9Sstevel@tonic-gate 	const char	*config_file,
6397c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
6407c478bd9Sstevel@tonic-gate 	__nis_config_t			*nis_config,
6417c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
6427c478bd9Sstevel@tonic-gate 	__nis_config_info_t		*config_info,
6437c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info,
6447c478bd9Sstevel@tonic-gate 	__yp_domain_context_t	*ypDomains)
6457c478bd9Sstevel@tonic-gate {
6467c478bd9Sstevel@tonic-gate 	int	rc = 0;
6477c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
6487c478bd9Sstevel@tonic-gate 	int	fd;
6497c478bd9Sstevel@tonic-gate 	char	*attr_val = NULL;
6507c478bd9Sstevel@tonic-gate 	int		len;
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
6537c478bd9Sstevel@tonic-gate 		p_error = parse_open_file_error;
6547c478bd9Sstevel@tonic-gate 		report_error(config_file, NULL);
6557c478bd9Sstevel@tonic-gate 		return (-1);
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	start_line_num = 1;
6597c478bd9Sstevel@tonic-gate 	cur_line_num = 1;
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	if (verbose)
6627c478bd9Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	file_source = config_file;
6657c478bd9Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
6667c478bd9Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
6677c478bd9Sstevel@tonic-gate 		if (IS_YP_CONFIG_KEYWORD(attrib_num)) {
6687c478bd9Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
669b9175c69SKenjiro Tsuji 			    attr_val, len, config_info);
6707c478bd9Sstevel@tonic-gate 		} else if (IS_YP_BIND_INFO(attrib_num)) {
6717c478bd9Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
672b9175c69SKenjiro Tsuji 			    attr_val, len, proxy_info);
6737c478bd9Sstevel@tonic-gate 		} else if (IS_YP_OPER_INFO(attrib_num)) {
6747c478bd9Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
675b9175c69SKenjiro Tsuji 			    attr_val, len, nis_config, table_info);
6767c478bd9Sstevel@tonic-gate 		} else if (IS_YP_DOMAIN_INFO(attrib_num)) {
6777c478bd9Sstevel@tonic-gate 			rc = add_ypdomains_attribute(attrib_num,
678b9175c69SKenjiro Tsuji 			    attr_val, len, ypDomains);
6797c478bd9Sstevel@tonic-gate 		} else if (IS_YP_MAP_ATTR(attrib_num)) {
6807c478bd9Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
681b9175c69SKenjiro Tsuji 			    attr_val, len, table_mapping);
6827c478bd9Sstevel@tonic-gate 		} else {
6837c478bd9Sstevel@tonic-gate 			rc = -1;
6847c478bd9Sstevel@tonic-gate 			p_error = parse_unsupported_format;
6857c478bd9Sstevel@tonic-gate 		}
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 		if (rc < 0) {
6887c478bd9Sstevel@tonic-gate 			report_error(attr_val == NULL ?
689b9175c69SKenjiro Tsuji 			    "<no attribute>" : attr_val, _key_val);
6907c478bd9Sstevel@tonic-gate 			if (attr_val)
6917c478bd9Sstevel@tonic-gate 				free(attr_val);
6927c478bd9Sstevel@tonic-gate 			break;
6937c478bd9Sstevel@tonic-gate 		}
6947c478bd9Sstevel@tonic-gate 		if (attr_val) {
6957c478bd9Sstevel@tonic-gate 			free(attr_val);
6967c478bd9Sstevel@tonic-gate 			attr_val = NULL;
6977c478bd9Sstevel@tonic-gate 		}
6987c478bd9Sstevel@tonic-gate 	}
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	(void) close(fd);
7017c478bd9Sstevel@tonic-gate 	if (attrib_num == key_bad) {
7027c478bd9Sstevel@tonic-gate 		report_error(_key_val, NULL);
7037c478bd9Sstevel@tonic-gate 		rc = -1;
7047c478bd9Sstevel@tonic-gate 	}
7057c478bd9Sstevel@tonic-gate 	start_line_num = 0;
7067c478bd9Sstevel@tonic-gate 	file_source = NULL;
7077c478bd9Sstevel@tonic-gate 	return (rc);
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate /*
7117c478bd9Sstevel@tonic-gate  * FUNCTION:	get_file_attr_val
7127c478bd9Sstevel@tonic-gate  *
7137c478bd9Sstevel@tonic-gate  *	Gets the next attribute from the configuration file.
7147c478bd9Sstevel@tonic-gate  *
7157c478bd9Sstevel@tonic-gate  * RETURN VALUE:	The config key if more attributes
7167c478bd9Sstevel@tonic-gate  *			no_more_keys if eof
7177c478bd9Sstevel@tonic-gate  *			key_bad if error
7187c478bd9Sstevel@tonic-gate  */
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate static config_key
get_file_attr_val(int fd,char ** attr_val)7217c478bd9Sstevel@tonic-gate get_file_attr_val(int fd, char **attr_val)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate 	char		buf[BUFSIZE];
7247c478bd9Sstevel@tonic-gate 	char		*start_tag;
7257c478bd9Sstevel@tonic-gate 	char		*start_val;
7267c478bd9Sstevel@tonic-gate 	char		*end_val;
7277c478bd9Sstevel@tonic-gate 	char		*cut_here;
7287c478bd9Sstevel@tonic-gate 	char		*s;
7297c478bd9Sstevel@tonic-gate 	char		*a;
7307c478bd9Sstevel@tonic-gate 	char		*attribute_value;
7317c478bd9Sstevel@tonic-gate 	int		ret;
7327c478bd9Sstevel@tonic-gate 	config_key	attrib_num = no_more_keys;
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	*attr_val = NULL;
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	if ((ret = read_line(fd, buf, sizeof (buf))) > 0) {
7377c478bd9Sstevel@tonic-gate 		for (s = buf; is_whitespace(*s); s++)
7387c478bd9Sstevel@tonic-gate 			;
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 		start_tag = s;
7417c478bd9Sstevel@tonic-gate 		while (*s != '\0' && !is_whitespace(*s))
7427c478bd9Sstevel@tonic-gate 			s++;
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		if (verbose)
7457c478bd9Sstevel@tonic-gate 			report_info("\t", start_tag);
7467c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num(start_tag, s - start_tag);
7477c478bd9Sstevel@tonic-gate 		if (attrib_num == key_bad)
7487c478bd9Sstevel@tonic-gate 			return (key_bad);
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 		while (is_whitespace(*s))
7517c478bd9Sstevel@tonic-gate 			s++;
7527c478bd9Sstevel@tonic-gate 		if (*s == '\0')
7537c478bd9Sstevel@tonic-gate 			return (attrib_num);
7547c478bd9Sstevel@tonic-gate 		start_val = s;
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 		/* note that read_line will not return a line ending with \ */
7577c478bd9Sstevel@tonic-gate 		for (; *s != '\0'; s++) {
7587c478bd9Sstevel@tonic-gate 			if (*s == ESCAPE_CHAR)
7597c478bd9Sstevel@tonic-gate 				s++;
7607c478bd9Sstevel@tonic-gate 		}
7617c478bd9Sstevel@tonic-gate 		while (s > start_val && is_whitespace(s[-1]))
7627c478bd9Sstevel@tonic-gate 			s--;
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 		attribute_value =
765b9175c69SKenjiro Tsuji 		    calloc(1, (size_t)(s - start_val) + 1);
7667c478bd9Sstevel@tonic-gate 		if (attribute_value == NULL) {
7677c478bd9Sstevel@tonic-gate 			p_error = parse_no_mem_error;
7687c478bd9Sstevel@tonic-gate 			return (key_bad);
7697c478bd9Sstevel@tonic-gate 		}
7707c478bd9Sstevel@tonic-gate 		attr_val[0] = attribute_value;
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 		a = *attr_val;
7737c478bd9Sstevel@tonic-gate 		end_val = s;
7747c478bd9Sstevel@tonic-gate 		cut_here = 0;
7757c478bd9Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++) {
7767c478bd9Sstevel@tonic-gate 			if (*s == POUND_SIGN) {
7777c478bd9Sstevel@tonic-gate 					cut_here = s;
7787c478bd9Sstevel@tonic-gate 					while (s < end_val) {
7797c478bd9Sstevel@tonic-gate 						if (*s == DOUBLE_QUOTE_CHAR ||
780b9175c69SKenjiro Tsuji 						    *s == SINGLE_QUOTE_CHAR) {
7817c478bd9Sstevel@tonic-gate 							cut_here = 0;
7827c478bd9Sstevel@tonic-gate 							break;
7837c478bd9Sstevel@tonic-gate 						}
7847c478bd9Sstevel@tonic-gate 						s++;
7857c478bd9Sstevel@tonic-gate 					}
7867c478bd9Sstevel@tonic-gate 			}
7877c478bd9Sstevel@tonic-gate 		}
7887c478bd9Sstevel@tonic-gate 		if (cut_here != 0)
7897c478bd9Sstevel@tonic-gate 			end_val = cut_here;
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++)
7927c478bd9Sstevel@tonic-gate 			*a++ = *s;
7937c478bd9Sstevel@tonic-gate 		*a++ = '\0';
7947c478bd9Sstevel@tonic-gate 	}
7957c478bd9Sstevel@tonic-gate 	if (ret == -1)
7967c478bd9Sstevel@tonic-gate 		return (key_bad);
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	return (attrib_num);
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate static LDAP *
connect_to_ldap_config_server(char * sever_name,int server_port,__nis_config_info_t * config_info)8027c478bd9Sstevel@tonic-gate connect_to_ldap_config_server(
8037c478bd9Sstevel@tonic-gate 	char			*sever_name,
8047c478bd9Sstevel@tonic-gate 	int			server_port,
8057c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info)
8067c478bd9Sstevel@tonic-gate {
8077c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
8087c478bd9Sstevel@tonic-gate 	int		ldapVersion	= LDAP_VERSION3;
8097c478bd9Sstevel@tonic-gate 	int		derefOption	= LDAP_DEREF_ALWAYS;
8107c478bd9Sstevel@tonic-gate 	int		timelimit	= LDAP_NO_LIMIT;
8117c478bd9Sstevel@tonic-gate 	int		sizelimit	= LDAP_NO_LIMIT;
8127c478bd9Sstevel@tonic-gate 	int		errnum;
8137c478bd9Sstevel@tonic-gate 	bool_t		retrying	= FALSE;
8147c478bd9Sstevel@tonic-gate 	int		sleep_seconds	= 1;
8157c478bd9Sstevel@tonic-gate 	struct berval	cred;
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	if (config_info->tls_method == no_tls) {
8187c478bd9Sstevel@tonic-gate 		ld = ldap_init(sever_name, server_port);
8197c478bd9Sstevel@tonic-gate 		if (ld == NULL) {
8207c478bd9Sstevel@tonic-gate 			p_error = parse_ldap_init_error;
8217c478bd9Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8227c478bd9Sstevel@tonic-gate 			return (NULL);
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 	} else {
8257c478bd9Sstevel@tonic-gate 		if ((errnum = ldapssl_client_init(
826b9175c69SKenjiro Tsuji 		    config_info->tls_cert_db, NULL)) < 0) {
8277c478bd9Sstevel@tonic-gate 			p_error = parse_ldapssl_client_init_error;
8287c478bd9Sstevel@tonic-gate 			report_error(ldapssl_err2string(errnum), NULL);
8297c478bd9Sstevel@tonic-gate 			return (NULL);
8307c478bd9Sstevel@tonic-gate 		}
8317c478bd9Sstevel@tonic-gate 		ld = ldapssl_init(sever_name, server_port, 1);
8327c478bd9Sstevel@tonic-gate 		if (ld == NULL) {
8337c478bd9Sstevel@tonic-gate 			p_error = parse_ldapssl_init_error;
8347c478bd9Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8357c478bd9Sstevel@tonic-gate 			return (NULL);
8367c478bd9Sstevel@tonic-gate 		}
8377c478bd9Sstevel@tonic-gate 	}
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,
840b9175c69SKenjiro Tsuji 	    &ldapVersion);
8417c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_DEREF, &derefOption);
8427c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
8437c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_TIMELIMIT, &timelimit);
8447c478bd9Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	/*
8477c478bd9Sstevel@tonic-gate 	 * Attempt to bind to the LDAP server.
8487c478bd9Sstevel@tonic-gate 	 * We will loop until success or until an error other
8497c478bd9Sstevel@tonic-gate 	 * than LDAP_CONNECT_ERROR or LDAP_SERVER_DOWN
8507c478bd9Sstevel@tonic-gate 	 */
8517c478bd9Sstevel@tonic-gate 	if (verbose)
8527c478bd9Sstevel@tonic-gate 		report_info("Connecting to ", sever_name);
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	for (;;) {
8557c478bd9Sstevel@tonic-gate 		if (config_info->auth_method == simple) {
8567c478bd9Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, config_info->proxy_dn,
857b9175c69SKenjiro Tsuji 			    config_info->proxy_passwd);
8587c478bd9Sstevel@tonic-gate 		} else if (config_info->auth_method == cram_md5) {
8597c478bd9Sstevel@tonic-gate 			cred.bv_len = strlen(config_info->proxy_passwd);
8607c478bd9Sstevel@tonic-gate 			cred.bv_val = config_info->proxy_passwd;
8617c478bd9Sstevel@tonic-gate 			errnum = ldap_sasl_cram_md5_bind_s(ld,
862b9175c69SKenjiro Tsuji 			    config_info->proxy_dn, &cred, NULL, NULL);
8637c478bd9Sstevel@tonic-gate 		} else if (config_info->auth_method == digest_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_x_sasl_digest_md5_bind_s(ld,
867b9175c69SKenjiro Tsuji 			    config_info->proxy_dn, &cred, NULL, NULL);
8687c478bd9Sstevel@tonic-gate 		} else {
8697c478bd9Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, NULL, NULL);
8707c478bd9Sstevel@tonic-gate 		}
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 		if (errnum == LDAP_SUCCESS)
8737c478bd9Sstevel@tonic-gate 			break;
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 		if (errnum == LDAP_CONNECT_ERROR ||
876b9175c69SKenjiro Tsuji 		    errnum == LDAP_SERVER_DOWN) {
8777c478bd9Sstevel@tonic-gate 			if (!retrying) {
8787c478bd9Sstevel@tonic-gate 				if (verbose)
879b9175c69SKenjiro Tsuji 					report_info(
8807c478bd9Sstevel@tonic-gate 					"LDAP server unavailable. Retrying...",
881b9175c69SKenjiro Tsuji 					    NULL);
8827c478bd9Sstevel@tonic-gate 				retrying = TRUE;
8837c478bd9Sstevel@tonic-gate 			}
8847c478bd9Sstevel@tonic-gate 			(void) sleep(sleep_seconds);
8857c478bd9Sstevel@tonic-gate 			sleep_seconds *= 2;
8867c478bd9Sstevel@tonic-gate 			if (sleep_seconds > MAX_LDAP_CONFIG_RETRY_TIME)
8877c478bd9Sstevel@tonic-gate 				sleep_seconds = MAX_LDAP_CONFIG_RETRY_TIME;
8887c478bd9Sstevel@tonic-gate 			p_error = no_parse_error;
8897c478bd9Sstevel@tonic-gate 			continue;
8907c478bd9Sstevel@tonic-gate 		}
8917c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_bind_error;
8927c478bd9Sstevel@tonic-gate 		report_error2(config_info->proxy_dn, ldap_err2string(errnum));
8937c478bd9Sstevel@tonic-gate 		(void) ldap_unbind(ld);
8947c478bd9Sstevel@tonic-gate 		return (NULL);
8957c478bd9Sstevel@tonic-gate 	}
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	if (verbose)
8987c478bd9Sstevel@tonic-gate 		report_info("Reading values from ", config_info->config_dn);
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 	return (ld);
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_config_result
9057c478bd9Sstevel@tonic-gate  *
9067c478bd9Sstevel@tonic-gate  *	Extracts the LDAPMessage containing the nis+/LDAP
9077c478bd9Sstevel@tonic-gate  *	configuration
9087c478bd9Sstevel@tonic-gate  *
9097c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
9107c478bd9Sstevel@tonic-gate  *
9117c478bd9Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
9127c478bd9Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
9137c478bd9Sstevel@tonic-gate  */
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@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)9167c478bd9Sstevel@tonic-gate process_ldap_config_result(
9177c478bd9Sstevel@tonic-gate 	LDAP			*ld,
9187c478bd9Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
9197c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
9207c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
9217c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
9227c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
9237c478bd9Sstevel@tonic-gate {
9247c478bd9Sstevel@tonic-gate 	LDAPMessage	*e;
9257c478bd9Sstevel@tonic-gate 	int		errnum;
9267c478bd9Sstevel@tonic-gate 	char		*attr;
9277c478bd9Sstevel@tonic-gate 	BerElement	*ber		= NULL;
9287c478bd9Sstevel@tonic-gate 	config_key	attrib_num;
9297c478bd9Sstevel@tonic-gate 	char		**vals;
9307c478bd9Sstevel@tonic-gate 	int		n;
9317c478bd9Sstevel@tonic-gate 	int		i;
9327c478bd9Sstevel@tonic-gate 	char		*attr_val;
9337c478bd9Sstevel@tonic-gate 	int		len;
9347c478bd9Sstevel@tonic-gate 	int		rc = 0;
9357c478bd9Sstevel@tonic-gate 	bool_t		error_reported	= FALSE;
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	e = ldap_first_entry(ld, resultMsg);
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate 	if (e != NULL) {
940b9175c69SKenjiro Tsuji 		for (attr = ldap_first_attribute(ld, e, &ber); attr != NULL;
941b9175c69SKenjiro Tsuji 		    attr = ldap_next_attribute(ld, e, ber)) {
942b9175c69SKenjiro Tsuji 			if (verbose)
943b9175c69SKenjiro Tsuji 				report_info("\t", attr);
944b9175c69SKenjiro Tsuji 			attrib_num = get_attrib_num(attr, strlen(attr));
945b9175c69SKenjiro Tsuji 			if (attrib_num == key_bad) {
9467c478bd9Sstevel@tonic-gate 				report_error(attr, NULL);
9477c478bd9Sstevel@tonic-gate 				break;
948b9175c69SKenjiro Tsuji 			}
949b9175c69SKenjiro Tsuji 			if ((vals = ldap_get_values(ld, e, attr)) != NULL) {
950b9175c69SKenjiro Tsuji 				n = ldap_count_values(vals);
951b9175c69SKenjiro Tsuji 				/* parse the attribute values */
952b9175c69SKenjiro Tsuji 				for (i = 0; i < n; i++) {
953b9175c69SKenjiro Tsuji 					attr_val = vals[i];
954b9175c69SKenjiro Tsuji 					while (is_whitespace(*attr_val))
955b9175c69SKenjiro Tsuji 						attr_val++;
956b9175c69SKenjiro Tsuji 					if (verbose)
957b9175c69SKenjiro Tsuji 						report_info("\t\t", attr_val);
958b9175c69SKenjiro Tsuji 					len = strlen(attr_val);
959b9175c69SKenjiro Tsuji 					while (len > 0 &&
960b9175c69SKenjiro Tsuji 					    is_whitespace(attr_val[len - 1]))
961b9175c69SKenjiro Tsuji 						len--;
962b9175c69SKenjiro Tsuji 		if (yp2ldap) {
963b9175c69SKenjiro Tsuji 			if (IS_YP_BIND_INFO(attrib_num)) {
964b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num, attr_val,
965b9175c69SKenjiro Tsuji 				    len, proxy_info);
966b9175c69SKenjiro Tsuji 			} else if (IS_YP_OPER_INFO(attrib_num)) {
967b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
968b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config, table_info);
969b9175c69SKenjiro Tsuji 			} else if (IS_YP_MAP_ATTR(attrib_num)) {
970b9175c69SKenjiro Tsuji 				rc = add_mapping_attribute(attrib_num, attr_val,
971b9175c69SKenjiro Tsuji 				    len, table_mapping);
972b9175c69SKenjiro Tsuji 			} else {
973b9175c69SKenjiro Tsuji 				p_error = parse_unsupported_format;
974b9175c69SKenjiro Tsuji 			}
975b9175c69SKenjiro Tsuji 		} else {
976b9175c69SKenjiro Tsuji 			if (IS_BIND_INFO(attrib_num)) {
977b9175c69SKenjiro Tsuji 				rc = add_bind_attribute(attrib_num, attr_val,
978b9175c69SKenjiro Tsuji 				    len, proxy_info);
979b9175c69SKenjiro Tsuji 			} else if (IS_OPER_INFO(attrib_num)) {
980b9175c69SKenjiro Tsuji 				rc = add_operation_attribute(attrib_num,
981b9175c69SKenjiro Tsuji 				    attr_val, len, nis_config, table_info);
982b9175c69SKenjiro Tsuji 			} else {
983b9175c69SKenjiro Tsuji 				rc = add_mapping_attribute(attrib_num, attr_val,
984b9175c69SKenjiro Tsuji 				    len, table_mapping);
985b9175c69SKenjiro Tsuji 			}
986b9175c69SKenjiro Tsuji 		}
987b9175c69SKenjiro Tsuji 					if (p_error != no_parse_error) {
988b9175c69SKenjiro Tsuji 						report_error(attr_val, attr);
989b9175c69SKenjiro Tsuji 						error_reported = TRUE;
990b9175c69SKenjiro Tsuji 						break;
9917c478bd9Sstevel@tonic-gate 					}
9927c478bd9Sstevel@tonic-gate 				}
993b9175c69SKenjiro Tsuji 				ldap_value_free(vals);
994b9175c69SKenjiro Tsuji 			} else {
995b9175c69SKenjiro Tsuji 				(void) ldap_get_option(ld,
996b9175c69SKenjiro Tsuji 				    LDAP_OPT_ERROR_NUMBER, &errnum);
997b9175c69SKenjiro Tsuji 				if (errnum != LDAP_SUCCESS)
998b9175c69SKenjiro Tsuji 					p_error = parse_ldap_get_values_error;
9997c478bd9Sstevel@tonic-gate 			}
1000b9175c69SKenjiro Tsuji 			ldap_memfree(attr);
1001b9175c69SKenjiro Tsuji 			if (p_error != no_parse_error)
1002b9175c69SKenjiro Tsuji 				break;
10037c478bd9Sstevel@tonic-gate 		}
1004b9175c69SKenjiro Tsuji 	} else {
10057c478bd9Sstevel@tonic-gate 		errnum = ldap_result2error(ld, resultMsg, FALSE);
10067c478bd9Sstevel@tonic-gate 		if (errnum != LDAP_SUCCESS)
10077c478bd9Sstevel@tonic-gate 			p_error = parse_ldap_search_error;
10087c478bd9Sstevel@tonic-gate 	}
10097c478bd9Sstevel@tonic-gate 	if (ber != NULL)
10107c478bd9Sstevel@tonic-gate 		ber_free(ber, 0);
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate 	if (!error_reported && p_error != no_parse_error) {
10137c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10147c478bd9Sstevel@tonic-gate 	}
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 	if (p_error != no_parse_error)
10177c478bd9Sstevel@tonic-gate 		rc = -1;
10187c478bd9Sstevel@tonic-gate 	return (rc);
10197c478bd9Sstevel@tonic-gate }
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate /*
10227c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral
10237c478bd9Sstevel@tonic-gate  *
10247c478bd9Sstevel@tonic-gate  *	Retrieves the configuration for a referral url
10257c478bd9Sstevel@tonic-gate  *
10267c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure, 1 on skip
10277c478bd9Sstevel@tonic-gate  *
10287c478bd9Sstevel@tonic-gate  * INPUT:		url		the ldap url
10297c478bd9Sstevel@tonic-gate  *			__nis_ldap_proxy_info
10307c478bd9Sstevel@tonic-gate  */
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@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)10337c478bd9Sstevel@tonic-gate process_ldap_referral(
10347c478bd9Sstevel@tonic-gate 	char			*url,
10357c478bd9Sstevel@tonic-gate 	char			**attrs,
10367c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
10377c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
10387c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
10397c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
10407c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
10417c478bd9Sstevel@tonic-gate {
10427c478bd9Sstevel@tonic-gate 	LDAPURLDesc	*ludpp		= NULL;
10437c478bd9Sstevel@tonic-gate 	int		rc;
10447c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
10457c478bd9Sstevel@tonic-gate 	int		errnum;
10467c478bd9Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	if ((rc = ldap_url_parse(url, &ludpp)) != LDAP_SUCCESS)
10497c478bd9Sstevel@tonic-gate 		return (1);
10507c478bd9Sstevel@tonic-gate 
10517c478bd9Sstevel@tonic-gate #ifdef LDAP_URL_OPT_SECURE
10527c478bd9Sstevel@tonic-gate 	if (ludpp->lud_options & LDAP_URL_OPT_SECURE) {
10537c478bd9Sstevel@tonic-gate 		if (config_info->tls_method != ssl_tls) {
10547c478bd9Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10557c478bd9Sstevel@tonic-gate 			return (1);
10567c478bd9Sstevel@tonic-gate 		}
10577c478bd9Sstevel@tonic-gate 	} else {
10587c478bd9Sstevel@tonic-gate 		if (config_info->tls_method != no_tls) {
10597c478bd9Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10607c478bd9Sstevel@tonic-gate 			return (1);
10617c478bd9Sstevel@tonic-gate 		}
10627c478bd9Sstevel@tonic-gate 	}
10637c478bd9Sstevel@tonic-gate #endif
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(ludpp->lud_host,
1066b9175c69SKenjiro Tsuji 	    ludpp->lud_port, config_info)) == NULL) {
10677c478bd9Sstevel@tonic-gate 		ldap_free_urldesc(ludpp);
10687c478bd9Sstevel@tonic-gate 		return (-1);
10697c478bd9Sstevel@tonic-gate 	}
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
1072b9175c69SKenjiro Tsuji 	    "objectclass=nisplusLDAPconfig", attrs, 0, &resultMsg);
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	if (errnum != LDAP_SUCCESS) {
10777c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
10787c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10797c478bd9Sstevel@tonic-gate 		rc = -1;
10807c478bd9Sstevel@tonic-gate 	} else {
10817c478bd9Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
1082b9175c69SKenjiro Tsuji 		    nis_config, table_mapping, table_info);
10837c478bd9Sstevel@tonic-gate 	}
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	ldap_source = NULL;
10867c478bd9Sstevel@tonic-gate 	(void) ldap_unbind(ld);
10877c478bd9Sstevel@tonic-gate 	if (resultMsg != NULL)
10887c478bd9Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 	return (rc);
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate /*
10947c478bd9Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral_msg
10957c478bd9Sstevel@tonic-gate  *
10967c478bd9Sstevel@tonic-gate  *	Retrieves the configuration from referred servers
10977c478bd9Sstevel@tonic-gate  *
10987c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
10997c478bd9Sstevel@tonic-gate  *
11007c478bd9Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
11017c478bd9Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
11027c478bd9Sstevel@tonic-gate  *			__nis_ldap_proxy_info
11037c478bd9Sstevel@tonic-gate  */
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@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)11067c478bd9Sstevel@tonic-gate process_ldap_referral_msg(
11077c478bd9Sstevel@tonic-gate 	LDAP			*ld,
11087c478bd9Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
11097c478bd9Sstevel@tonic-gate 	char			**attrs,
11107c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11117c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11127c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11137c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11147c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11157c478bd9Sstevel@tonic-gate {
11167c478bd9Sstevel@tonic-gate 	int	errCode;
11177c478bd9Sstevel@tonic-gate 	char	**referralsp	= NULL;
11187c478bd9Sstevel@tonic-gate 	int	i;
11197c478bd9Sstevel@tonic-gate 	int	rc;
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	rc = ldap_parse_result(ld, resultMsg, &errCode, NULL, NULL, &referralsp,
1122b9175c69SKenjiro Tsuji 	    NULL, 0);
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 	if (rc != LDAP_SUCCESS || errCode != LDAP_REFERRAL) {
11257c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_get_values_error;
11267c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errCode), 0);
11277c478bd9Sstevel@tonic-gate 		rc = -1;
11287c478bd9Sstevel@tonic-gate 	} else {
11297c478bd9Sstevel@tonic-gate 		for (i = 0; referralsp[i] != NULL; i++) {
11307c478bd9Sstevel@tonic-gate 			rc = process_ldap_referral(referralsp[i], attrs,
1131b9175c69SKenjiro Tsuji 			    proxy_info, nis_config, table_mapping,
1132b9175c69SKenjiro Tsuji 			    config_info, table_info);
11337c478bd9Sstevel@tonic-gate 			if (rc <= 0)
11347c478bd9Sstevel@tonic-gate 				break;
11357c478bd9Sstevel@tonic-gate 			else
11367c478bd9Sstevel@tonic-gate 				report_info("Cannot use referral \n",
1137b9175c69SKenjiro Tsuji 				    referralsp[i]);
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 		}
11407c478bd9Sstevel@tonic-gate 		if (rc > 0) {
11417c478bd9Sstevel@tonic-gate 			p_error = parse_no_available_referrals_error;
11427c478bd9Sstevel@tonic-gate 			report_error(0, 0);
11437c478bd9Sstevel@tonic-gate 		}
11447c478bd9Sstevel@tonic-gate 	}
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate 	if (referralsp)
11477c478bd9Sstevel@tonic-gate 		ldap_value_free(referralsp);
11487c478bd9Sstevel@tonic-gate 
11497c478bd9Sstevel@tonic-gate 	return (rc);
11507c478bd9Sstevel@tonic-gate }
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate /*
11537c478bd9Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_dn_attrs
11547c478bd9Sstevel@tonic-gate  *
11557c478bd9Sstevel@tonic-gate  *	Parses the information for LDAP from the LDAP profile
11567c478bd9Sstevel@tonic-gate  *	- the profile object name, the LDAP server, and the
11577c478bd9Sstevel@tonic-gate  *	authentication method must be specified.
11587c478bd9Sstevel@tonic-gate  *
11597c478bd9Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
11607c478bd9Sstevel@tonic-gate  *
11617c478bd9Sstevel@tonic-gate  * INPUT:		__nis_ldap_proxy_info
11627c478bd9Sstevel@tonic-gate  */
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@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)11657c478bd9Sstevel@tonic-gate parse_ldap_config_dn_attrs(
11667c478bd9Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11677c478bd9Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11687c478bd9Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11697c478bd9Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11707c478bd9Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11717c478bd9Sstevel@tonic-gate {
11727c478bd9Sstevel@tonic-gate 	int		rc		= 0;
11737c478bd9Sstevel@tonic-gate 	LDAP		*ld		= NULL;
11747c478bd9Sstevel@tonic-gate 	int		errnum;
11757c478bd9Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
11767c478bd9Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 	/* Determine if properly configured for LDAP lookup */
11797c478bd9Sstevel@tonic-gate 	if (config_info->auth_method == simple &&
11807c478bd9Sstevel@tonic-gate 	    config_info->proxy_dn == NULL)
11817c478bd9Sstevel@tonic-gate 		p_error = parse_no_proxy_dn_error;
11827c478bd9Sstevel@tonic-gate 	else if (config_info->auth_method ==
11837c478bd9Sstevel@tonic-gate 	    (auth_method_t)NO_VALUE_SET)
11847c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_auth_error;
11857c478bd9Sstevel@tonic-gate 	else if ((config_info->default_servers == NULL) ||
1186b9175c69SKenjiro Tsuji 	    (config_info->default_servers[0] == '\0'))
11877c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_server_addr;
11887c478bd9Sstevel@tonic-gate 	if (p_error != no_parse_error) {
11897c478bd9Sstevel@tonic-gate 		report_error(NULL, NULL);
11907c478bd9Sstevel@tonic-gate 		return (-1);
11917c478bd9Sstevel@tonic-gate 	}
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	if (config_info->tls_method == (tls_method_t)NO_VALUE_SET)
11947c478bd9Sstevel@tonic-gate 		config_info->tls_method = no_tls;
11957c478bd9Sstevel@tonic-gate 	else if (config_info->tls_method == ssl_tls &&
1196b9175c69SKenjiro Tsuji 	    (config_info->tls_cert_db == NULL ||
1197b9175c69SKenjiro Tsuji 	    *config_info->tls_cert_db == '\0')) {
11987c478bd9Sstevel@tonic-gate 		p_error = parse_no_config_cert_db;
11997c478bd9Sstevel@tonic-gate 		report_error(NULL, NULL);
12007c478bd9Sstevel@tonic-gate 		return (-1);
12017c478bd9Sstevel@tonic-gate 	}
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate 	if (verbose)
12047c478bd9Sstevel@tonic-gate 		report_info(
1205b9175c69SKenjiro Tsuji 		    "Getting configuration from LDAP server(s): ",
1206b9175c69SKenjiro Tsuji 		    config_info->default_servers);
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12097c478bd9Sstevel@tonic-gate 	get_attribute_list(proxy_info, nis_config, NULL, table_info,
1210b9175c69SKenjiro Tsuji 	    ldap_config_attributes);
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(config_info->default_servers, 0,
1213b9175c69SKenjiro Tsuji 	    config_info)) == NULL)
12147c478bd9Sstevel@tonic-gate 		return (-1);
12157c478bd9Sstevel@tonic-gate 
12167c478bd9Sstevel@tonic-gate 	/* Get the attribute values */
12177c478bd9Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
1218b9175c69SKenjiro Tsuji 	    "objectclass=nisplusLDAPconfig",
1219b9175c69SKenjiro Tsuji 	    ldap_config_attributes, 0, &resultMsg);
12207c478bd9Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	if (errnum == LDAP_REFERRAL) {
12237c478bd9Sstevel@tonic-gate 		rc = process_ldap_referral_msg(ld, resultMsg,
1224b9175c69SKenjiro Tsuji 		    ldap_config_attributes, proxy_info, nis_config,
1225b9175c69SKenjiro Tsuji 		    table_mapping, config_info, table_info);
12267c478bd9Sstevel@tonic-gate 	} else if (errnum != LDAP_SUCCESS) {
12277c478bd9Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
12287c478bd9Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
12297c478bd9Sstevel@tonic-gate 		rc = -1;
12307c478bd9Sstevel@tonic-gate 	} else {
12317c478bd9Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
1232b9175c69SKenjiro Tsuji 		    nis_config, table_mapping, table_info);
12337c478bd9Sstevel@tonic-gate 	}
12347c478bd9Sstevel@tonic-gate 
12357c478bd9Sstevel@tonic-gate 	ldap_source = NULL;
12367c478bd9Sstevel@tonic-gate 	(void) ldap_unbind(ld);
12377c478bd9Sstevel@tonic-gate 	if (resultMsg != NULL)
12387c478bd9Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate 	return (rc);
12417c478bd9Sstevel@tonic-gate }
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate bool_t
is_cmd_line_option(config_key a_num)12447c478bd9Sstevel@tonic-gate is_cmd_line_option(config_key a_num)
12457c478bd9Sstevel@tonic-gate {
12467c478bd9Sstevel@tonic-gate 	const char *const	*cmdline_options = cmdline_config;
12477c478bd9Sstevel@tonic-gate 	config_key		attrib_num;
12487c478bd9Sstevel@tonic-gate 	const char		*begin_s;
12497c478bd9Sstevel@tonic-gate 	const char		*end_s;
12507c478bd9Sstevel@tonic-gate 
12517c478bd9Sstevel@tonic-gate 	if (cmdline_options == NULL)
12527c478bd9Sstevel@tonic-gate 		return (FALSE);
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
12557c478bd9Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
12567c478bd9Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
12577c478bd9Sstevel@tonic-gate 		if (attrib_num == a_num)
12587c478bd9Sstevel@tonic-gate 			break;
12597c478bd9Sstevel@tonic-gate 		cmdline_options++;
12607c478bd9Sstevel@tonic-gate 	}
12617c478bd9Sstevel@tonic-gate 	return (*cmdline_options != NULL);
12627c478bd9Sstevel@tonic-gate }
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate /*
12657c478bd9Sstevel@tonic-gate  * FUNCTION:	get_attribute_list
12667c478bd9Sstevel@tonic-gate  *
12677c478bd9Sstevel@tonic-gate  *	Get a list of attributes from the LDAP server that have not yet
12687c478bd9Sstevel@tonic-gate  *	been gotten. If config_info is NULL, the associated parameters
12697c478bd9Sstevel@tonic-gate  *	are not needed.
12707c478bd9Sstevel@tonic-gate  *
12717c478bd9Sstevel@tonic-gate  * RETURN VALUE:	none
12727c478bd9Sstevel@tonic-gate  *
12737c478bd9Sstevel@tonic-gate  * INPUT:		Returns a list of parameters in attributes
12747c478bd9Sstevel@tonic-gate  *			which is assumed to be of sufficient size.
12757c478bd9Sstevel@tonic-gate  */
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@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)12787c478bd9Sstevel@tonic-gate get_attribute_list(
12797c478bd9Sstevel@tonic-gate 	const __nis_ldap_proxy_info	*proxy_info,
12807c478bd9Sstevel@tonic-gate 	const __nis_config_t		*nis_config,
12817c478bd9Sstevel@tonic-gate 	const __nis_config_info_t	*config_info,
12827c478bd9Sstevel@tonic-gate 	const __nisdb_table_mapping_t	*table_info,
12837c478bd9Sstevel@tonic-gate 	char				**attributes)
12847c478bd9Sstevel@tonic-gate {
12857c478bd9Sstevel@tonic-gate 	int		n_attrs;
12867c478bd9Sstevel@tonic-gate 
12877c478bd9Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12887c478bd9Sstevel@tonic-gate 	n_attrs = 0;
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 	if (config_info != NULL) {
12917c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
12927c478bd9Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
12937c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_DN;
12947c478bd9Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
12957c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_SERVER_LIST;
12967c478bd9Sstevel@tonic-gate 			if (config_info->auth_method ==
1297b9175c69SKenjiro Tsuji 			    (auth_method_t)NO_VALUE_SET)
12987c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_AUTH_METHOD;
12997c478bd9Sstevel@tonic-gate 			if (config_info->tls_method ==
1300b9175c69SKenjiro Tsuji 			    (tls_method_t)NO_VALUE_SET)
13017c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_OPTION;
13027c478bd9Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13037c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_USER;
13047c478bd9Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13057c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_PASSWD;
13067c478bd9Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13077c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_CERT_DB;
13087c478bd9Sstevel@tonic-gate 		} else {
13097c478bd9Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
13107c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_DN;
13117c478bd9Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
13127c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_SERVER_LIST;
13137c478bd9Sstevel@tonic-gate 			if (config_info->auth_method ==
1314b9175c69SKenjiro Tsuji 			    (auth_method_t)NO_VALUE_SET)
13157c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_AUTH_METHOD;
13167c478bd9Sstevel@tonic-gate 			if (config_info->tls_method ==
1317b9175c69SKenjiro Tsuji 			    (tls_method_t)NO_VALUE_SET)
13187c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_OPTION;
13197c478bd9Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13207c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_USER;
13217c478bd9Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13227c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_PASSWD;
13237c478bd9Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13247c478bd9Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_CERT_DB;
13257c478bd9Sstevel@tonic-gate 		}
13267c478bd9Sstevel@tonic-gate 	} else {
13277c478bd9Sstevel@tonic-gate 		if (yp2ldap) {
13287c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DOMAIN_CONTEXT;
13297c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YPPASSWDD_DOMAINS;
13307c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DB_ID_MAP;
13317c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_COMMENT_CHAR;
13327c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MAP_FLAGS;
13337c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ENTRY_TTL;
13347c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_NAME_FIELDS;
13357c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SPLIT_FIELD;
13367c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_REPEATED_FIELD_SEPARATORS;
13377c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_OBJECT_DN;
13387c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = NIS_TO_LDAP_MAP;
13397c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NIS_MAP;
13407c478bd9Sstevel@tonic-gate 		} else {
13417c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = DB_ID_MAP;
13427c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = ENTRY_TTL;
13437c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_OBJECT_DN;
13447c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = NISPLUS_TO_LDAP_MAP;
13457c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NISPLUS_MAP;
13467c478bd9Sstevel@tonic-gate 		}
13477c478bd9Sstevel@tonic-gate 	}
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	if (yp2ldap) {
13507c478bd9Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
13517c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
13527c478bd9Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
13537c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
13547c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
13557c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_OPTION;
13567c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
13577c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_CERT_DB;
13587c478bd9Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
13597c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
13607c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
13617c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_USER;
13627c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
13637c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_PASSWD;
13647c478bd9Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
13657c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_BASE_DOMAIN;
13667c478bd9Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
1367b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
13687c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_BIND_TIMEOUT;
13697c478bd9Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
1370b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
13717c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIMEOUT;
13727c478bd9Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
1373b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
13747c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MODIFY_TIMEOUT;
13757c478bd9Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
13767c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ADD_TIMEOUT;
13777c478bd9Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
1378b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
13797c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DELETE_TIMEOUT;
13807c478bd9Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
13817c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIME_LIMIT;
13827c478bd9Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
13837c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_SIZE_LIMIT;
13847c478bd9Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
1385b9175c69SKenjiro Tsuji 		    (follow_referral_t)NO_VALUE_SET)
13867c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_FOLLOW_REFERRAL;
13877c478bd9Sstevel@tonic-gate 
13887c478bd9Sstevel@tonic-gate 		if (table_info->retrieveError ==
1389b9175c69SKenjiro Tsuji 		    (__nis_retrieve_error_t)NO_VALUE_SET)
13907c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETRIEVE_ERROR_ACTION;
13917c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
13927c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_ATTEMPTS;
13937c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
1394b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
13957c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_TIMEOUT;
13967c478bd9Sstevel@tonic-gate 		if (table_info->storeError ==
1397b9175c69SKenjiro Tsuji 		    (__nis_store_error_t)NO_VALUE_SET)
13987c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ACTION;
13997c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14007c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ATTEMPTS;
14017c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
1402b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14037c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_TIMEOUT;
14047c478bd9Sstevel@tonic-gate 		if (table_info->refreshError ==
1405b9175c69SKenjiro Tsuji 		    (__nis_refresh_error_t)NO_VALUE_SET)
14067c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14077c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14087c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14097c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
1410b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14117c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14127c478bd9Sstevel@tonic-gate 		if (table_info->matchFetch ==
1413b9175c69SKenjiro Tsuji 		    (__nis_match_fetch_t)NO_VALUE_SET)
14147c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MATCH_FETCH;
14157c478bd9Sstevel@tonic-gate 	} else {
14167c478bd9Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
14177c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
14187c478bd9Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
14197c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
14207c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
14217c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_OPTION;
14227c478bd9Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
14237c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_CERT_DB;
14247c478bd9Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
14257c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
14267c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
14277c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_USER;
14287c478bd9Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
14297c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_PASSWD;
14307c478bd9Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
14317c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_BASE_DOMAIN;
14327c478bd9Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
1433b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14347c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = BIND_TIMEOUT;
14357c478bd9Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
1436b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14377c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIMEOUT;
14387c478bd9Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
1439b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14407c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = MODIFY_TIMEOUT;
14417c478bd9Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
14427c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = ADD_TIMEOUT;
14437c478bd9Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
1444b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14457c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = DELETE_TIMEOUT;
14467c478bd9Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
14477c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIME_LIMIT;
14487c478bd9Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
14497c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_SIZE_LIMIT;
14507c478bd9Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
1451b9175c69SKenjiro Tsuji 		    (follow_referral_t)NO_VALUE_SET)
14527c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = FOLLOW_REFERRAL;
14537c478bd9Sstevel@tonic-gate 
14547c478bd9Sstevel@tonic-gate 		if (table_info->retrieveError ==
1455b9175c69SKenjiro Tsuji 		    (__nis_retrieve_error_t)NO_VALUE_SET)
14567c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETRIEVE_ERROR_ACTION;
14577c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
14587c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_ATTEMPTS;
14597c478bd9Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
1460b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14617c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_TIMEOUT;
14627c478bd9Sstevel@tonic-gate 		if (table_info->storeError ==
1463b9175c69SKenjiro Tsuji 		    (__nis_store_error_t)NO_VALUE_SET)
14647c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ACTION;
14657c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14667c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ATTEMPTS;
14677c478bd9Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
1468b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14697c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_TIMEOUT;
14707c478bd9Sstevel@tonic-gate 		if (table_info->refreshError ==
1471b9175c69SKenjiro Tsuji 		    (__nis_refresh_error_t)NO_VALUE_SET)
14727c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14737c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14747c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14757c478bd9Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
1476b9175c69SKenjiro Tsuji 		    (time_t)NO_VALUE_SET)
14777c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14787c478bd9Sstevel@tonic-gate 		if (table_info->matchFetch ==
1479b9175c69SKenjiro Tsuji 		    (__nis_match_fetch_t)NO_VALUE_SET)
14807c478bd9Sstevel@tonic-gate 			attributes[n_attrs++] = MATCH_FETCH;
14817c478bd9Sstevel@tonic-gate 	}
14827c478bd9Sstevel@tonic-gate 
14837c478bd9Sstevel@tonic-gate 	switch (nis_config->initialUpdate) {
1484b9175c69SKenjiro Tsuji 	case (__nis_initial_update_t)NO_VALUE_SET:
1485b9175c69SKenjiro Tsuji 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
1486b9175c69SKenjiro Tsuji 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
1487b9175c69SKenjiro Tsuji 		break;
1488b9175c69SKenjiro Tsuji 	case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION:
1489b9175c69SKenjiro Tsuji 	case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION:
1490b9175c69SKenjiro Tsuji 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
1491b9175c69SKenjiro Tsuji 		break;
1492b9175c69SKenjiro Tsuji 	case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE:
1493b9175c69SKenjiro Tsuji 	case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE:
1494b9175c69SKenjiro Tsuji 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
1495b9175c69SKenjiro Tsuji 		break;
14967c478bd9Sstevel@tonic-gate 	}
14977c478bd9Sstevel@tonic-gate 
14987c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationError ==
14997c478bd9Sstevel@tonic-gate 	    (__nis_thread_creation_error_t)NO_VALUE_SET)
15007c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ACTION;
15017c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.attempts == NO_VALUE_SET)
15027c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ATTEMPTS;
15037c478bd9Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.timeout ==
1504b9175c69SKenjiro Tsuji 	    (time_t)NO_VALUE_SET)
15057c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_TIMEOUT;
15067c478bd9Sstevel@tonic-gate 	if (nis_config->dumpError == (__nis_dump_error_t)NO_VALUE_SET)
15077c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ACTION;
15087c478bd9Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.attempts == NO_VALUE_SET)
15097c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ATTEMPTS;
15107c478bd9Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET)
15117c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_TIMEOUT;
15127c478bd9Sstevel@tonic-gate 	if (nis_config->resyncService == (__nis_resync_service_t)NO_VALUE_SET)
15137c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = RESYNC;
15147c478bd9Sstevel@tonic-gate 	if (nis_config->updateBatching ==
1515b9175c69SKenjiro Tsuji 	    (__nis_update_batching_t)NO_VALUE_SET)
15167c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING;
15177c478bd9Sstevel@tonic-gate 	if (nis_config->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET)
15187c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING_TIMEOUT;
15197c478bd9Sstevel@tonic-gate 	if (nis_config->numberOfServiceThreads == (int)NO_VALUE_SET)
15207c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = NUMBER_THEADS;
15217c478bd9Sstevel@tonic-gate 	if (nis_config->emulate_yp == (int)NO_VALUE_SET)
15227c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = YP_EMULATION;
15237c478bd9Sstevel@tonic-gate 
15247c478bd9Sstevel@tonic-gate 	/* maxRPCRecordSize is not configurable through LDAP profiles */
15257c478bd9Sstevel@tonic-gate 	if (nis_config->maxRPCRecordSize == (int)NO_VALUE_SET)
15267c478bd9Sstevel@tonic-gate 		attributes[n_attrs++] = MAX_RPC_RECSIZE;
15277c478bd9Sstevel@tonic-gate 
15287c478bd9Sstevel@tonic-gate 	attributes[n_attrs++] = NULL;
15297c478bd9Sstevel@tonic-gate }
15307c478bd9Sstevel@tonic-gate 
15317c478bd9Sstevel@tonic-gate /*
15327c478bd9Sstevel@tonic-gate  *	Notes on adding new attributes
15337c478bd9Sstevel@tonic-gate  *	1. Determine where the attribute value will be saved
15347c478bd9Sstevel@tonic-gate  *	    Currently, the following structures are defined:
15357c478bd9Sstevel@tonic-gate  *		__nis_config_info_t	config_info
15367c478bd9Sstevel@tonic-gate  *		__nis_ldap_proxy_info	proxyInfo
15377c478bd9Sstevel@tonic-gate  *		__nis_config_t		ldapConfig
15387c478bd9Sstevel@tonic-gate  *		__nisdb_table_mapping_t	ldapDBTableMapping
15397c478bd9Sstevel@tonic-gate  *		__nis_table_mapping_t	ldapTableMapping
15407c478bd9Sstevel@tonic-gate  *	    or add a new structure or variable - this will require
15417c478bd9Sstevel@tonic-gate  *	    more code.
15427c478bd9Sstevel@tonic-gate  *	2. Initialize the value to a known unconfigured value.
15437c478bd9Sstevel@tonic-gate  *	    This can be done in initialize_parse_structs or
15447c478bd9Sstevel@tonic-gate  *	    parse_ldap_migration.
15457c478bd9Sstevel@tonic-gate  *	3. In the header file nis_parse_ldap_conf.h, add the name
15467c478bd9Sstevel@tonic-gate  *	    of the attribute. (Currently, the attribute name is assumed
15477c478bd9Sstevel@tonic-gate  *	    to be the same for the command line, the preference file,
15487c478bd9Sstevel@tonic-gate  *	    and LDAP.) The names are grouped logically. Add a corresponding
15497c478bd9Sstevel@tonic-gate  *	    config_key to the enum. Note that position in this file is
15507c478bd9Sstevel@tonic-gate  *	    essential because the macros such as IS_BIND_INFO depend on
15517c478bd9Sstevel@tonic-gate  *	    the sequence. The corresponding macro (IS_CONFIG_KEYWORD,
15527c478bd9Sstevel@tonic-gate  *	    IS_BIND_INFO, or IS_OPER_INFO) may need to be adjusted. These
15537c478bd9Sstevel@tonic-gate  *	    are used to partition the attributes into smaller chunks.
15547c478bd9Sstevel@tonic-gate  *	4. Add the correspond entry to the keyword_lookup array in
15557c478bd9Sstevel@tonic-gate  *	    nis_parse_ldap_attr.c, which is used to determine the config_key
15567c478bd9Sstevel@tonic-gate  *	    from the corresponding key word.
15577c478bd9Sstevel@tonic-gate  *	5. Add the attribute to the list of attributes to retrieve from
15587c478bd9Sstevel@tonic-gate  *	    the LDAP server if no value has been set in the function
15597c478bd9Sstevel@tonic-gate  *	    parse_ldap_config_dn_attrs. (This assumes that the attribute
15607c478bd9Sstevel@tonic-gate  *	    is not used to get the configuration from the LDAP server.)
15617c478bd9Sstevel@tonic-gate  *	6. Add logic to parse the individual attribute in
15627c478bd9Sstevel@tonic-gate  *	    add_config_attribute, add_bind_attribute,
15637c478bd9Sstevel@tonic-gate  *	    add_operation_attribute, or add_mapping_attribute depending
15647c478bd9Sstevel@tonic-gate  *	    which group of attributes the added attribute belongs to.
15657c478bd9Sstevel@tonic-gate  *	7. In set_default_values, if the attribute value has not been set, set
15667c478bd9Sstevel@tonic-gate  *	    the default value. If any additional fixup is needed depending
15677c478bd9Sstevel@tonic-gate  *	    on other configuration values, it should be done here.
15687c478bd9Sstevel@tonic-gate  *	8. If an attribute name is a subset of another, parse_ldap_default_conf
15697c478bd9Sstevel@tonic-gate  *          should be modified.
15707c478bd9Sstevel@tonic-gate  */
1571