xref: /onnv-gate/usr/src/lib/libnisdb/nis_parse_ldap_conf.c (revision 11838:32bb5d254240)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52189Ssdussud  * Common Development and Distribution License (the "License").
62189Ssdussud  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*8563SKenjiro.Tsuji@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <stdio.h>
270Sstevel@tonic-gate #include <string.h>
280Sstevel@tonic-gate #include <stdlib.h>
290Sstevel@tonic-gate #include <ctype.h>
300Sstevel@tonic-gate #include <fcntl.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate #include <locale.h>
340Sstevel@tonic-gate #include <sys/stat.h>
350Sstevel@tonic-gate #include <lber.h>
360Sstevel@tonic-gate #include <ldap.h>
370Sstevel@tonic-gate #include <deflt.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include "ldap_map.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include "ldap_parse.h"
420Sstevel@tonic-gate #include "ldap_glob.h"
430Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
440Sstevel@tonic-gate 
450Sstevel@tonic-gate __nis_ldap_proxy_info	proxyInfo		=
460Sstevel@tonic-gate 	{NULL, (auth_method_t)NO_VALUE_SET, (tls_method_t)NO_VALUE_SET, NULL,
470Sstevel@tonic-gate 		NULL, NULL, NULL, NULL, (follow_referral_t)NO_VALUE_SET};
480Sstevel@tonic-gate __nis_config_t		ldapConfig;
490Sstevel@tonic-gate __nisdb_table_mapping_t ldapDBTableMapping;
500Sstevel@tonic-gate __nis_table_mapping_t	*ldapTableMapping	= NULL;
510Sstevel@tonic-gate __yp_domain_context_t	ypDomains;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate parse_error		p_error			= no_parse_error;
540Sstevel@tonic-gate int			cur_line_num		= 0;
550Sstevel@tonic-gate int			start_line_num		= 0;
560Sstevel@tonic-gate int			seq_num 		= 0;
570Sstevel@tonic-gate const char		*warn_file		= NULL;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate char			_key_val[38];
600Sstevel@tonic-gate const char		*command_line_source	= NULL;
610Sstevel@tonic-gate const char		*file_source		= NULL;
620Sstevel@tonic-gate const char		*ldap_source		= NULL;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate static
650Sstevel@tonic-gate const char *const	*cmdline_config		= NULL;
660Sstevel@tonic-gate static bool_t		got_config_data		= FALSE;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* high level parsing functions functions */
690Sstevel@tonic-gate static int parse_ldap_cmd_line(const char *const *cmdline_options,
700Sstevel@tonic-gate     __nis_ldap_proxy_info *proxy_info, __nis_config_t *nis_config,
710Sstevel@tonic-gate     __nis_table_mapping_t **table_mapping, __nis_config_info_t *config_info,
720Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
730Sstevel@tonic-gate static int parse_ldap_default_conf(__nis_ldap_proxy_info *proxy_info,
740Sstevel@tonic-gate     __nis_config_t *nis_config, __nis_config_info_t *config_info,
750Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
760Sstevel@tonic-gate static int parse_ldap_config_file(const char *config_file,
770Sstevel@tonic-gate     __nis_ldap_proxy_info *proxy_info, __nis_config_t *nis_config,
780Sstevel@tonic-gate     __nis_table_mapping_t **table_mapping, __nis_config_info_t *config_info,
790Sstevel@tonic-gate     __nisdb_table_mapping_t *table_info);
800Sstevel@tonic-gate static int parse_ldap_config_dn_attrs(__nis_ldap_proxy_info *proxy_info,
810Sstevel@tonic-gate     __nis_config_t *nis_config, __nis_table_mapping_t **table_mapping,
820Sstevel@tonic-gate     __nis_config_info_t *config_info, __nisdb_table_mapping_t *table_info);
830Sstevel@tonic-gate static int yp_parse_ldap_default_conf(__nis_ldap_proxy_info *proxy_info,
840Sstevel@tonic-gate 	__nis_config_t *nis_config, __nis_config_info_t *config_info,
850Sstevel@tonic-gate 	__nisdb_table_mapping_t *table_info);
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /* helper functions */
890Sstevel@tonic-gate static config_key get_attrib_num_cmdline(const char *s,
900Sstevel@tonic-gate     const char **begin_s, const char **end_s);
910Sstevel@tonic-gate static config_key get_file_attr_val(int fd, char **attr_val);
920Sstevel@tonic-gate static void get_attribute_list(
930Sstevel@tonic-gate 	const __nis_ldap_proxy_info *proxy_info,
940Sstevel@tonic-gate 	const __nis_config_t *nis_config,
950Sstevel@tonic-gate 	const __nis_config_info_t *config_info,
960Sstevel@tonic-gate 	const __nisdb_table_mapping_t *table_info,
970Sstevel@tonic-gate 	char **ldap_config_attributes);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * FUNCTION:	parse_ldap_migration
1010Sstevel@tonic-gate  *
1020Sstevel@tonic-gate  *	Parses the information for LDAP. The values are first
1030Sstevel@tonic-gate  *	obtained from the command line, secondly from the preference
1040Sstevel@tonic-gate  *	file, and finally from an LDAP profile (if so configured in
1050Sstevel@tonic-gate  *	the command line or preference file). Any unset values will
1060Sstevel@tonic-gate  *	be set to their default values.
1070Sstevel@tonic-gate  *
1080Sstevel@tonic-gate  *	If no command line options, no settings in the /etc/default
1090Sstevel@tonic-gate  *  configuration file, and no mapping file, then no mapping
1100Sstevel@tonic-gate  *  should be used.
1110Sstevel@tonic-gate  *
1120Sstevel@tonic-gate  * RETURN VALUE:
1130Sstevel@tonic-gate  *			0	Success
1140Sstevel@tonic-gate  *			-1	Config file stat/open or parse error
1150Sstevel@tonic-gate  *			1	No mapping should be used.
1160Sstevel@tonic-gate  *
1170Sstevel@tonic-gate  * INPUT:		command line parameters, configuration file
1180Sstevel@tonic-gate  */
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate int
parse_ldap_migration(const char * const * cmdline_options,const char * config_file)1210Sstevel@tonic-gate parse_ldap_migration(
1220Sstevel@tonic-gate 	const char *const	*cmdline_options,
1230Sstevel@tonic-gate 	const char		*config_file)
1240Sstevel@tonic-gate {
1250Sstevel@tonic-gate 	int			rc	= 0;
1260Sstevel@tonic-gate 	__nis_config_info_t	config_info
1270Sstevel@tonic-gate 				= {NULL, NULL, (auth_method_t)NO_VALUE_SET,
1280Sstevel@tonic-gate 					(tls_method_t)NO_VALUE_SET, NULL,
1290Sstevel@tonic-gate 					NULL, NULL};
1300Sstevel@tonic-gate 	struct stat		buf;
1310Sstevel@tonic-gate 	int i = 0;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	p_error = no_parse_error;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	if (verbose)
1360Sstevel@tonic-gate 		report_info("Getting LDAP configuration", NULL);
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	initialize_parse_structs(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	if (yp2ldap)
1410Sstevel@tonic-gate 		initialize_yp_parse_structs(&ypDomains);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	if (cmdline_options != NULL) {
1440Sstevel@tonic-gate 		got_config_data = TRUE;
1450Sstevel@tonic-gate 		/* NIS to LDAP does not read command line attributes */
1460Sstevel@tonic-gate 		if (!yp2ldap)
1470Sstevel@tonic-gate 			rc = parse_ldap_cmd_line(cmdline_options, &proxyInfo,
148*8563SKenjiro.Tsuji@Sun.COM 			    &ldapConfig, &ldapTableMapping, &config_info,
149*8563SKenjiro.Tsuji@Sun.COM 			    &ldapDBTableMapping);
1500Sstevel@tonic-gate 		else
1510Sstevel@tonic-gate 			rc = 0;
1520Sstevel@tonic-gate 	}
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	if (rc == 0) {
1550Sstevel@tonic-gate 		if (yp2ldap)
1560Sstevel@tonic-gate 			rc = yp_parse_ldap_default_conf(&proxyInfo, &ldapConfig,
157*8563SKenjiro.Tsuji@Sun.COM 			    &config_info, &ldapDBTableMapping);
1580Sstevel@tonic-gate 		else
1590Sstevel@tonic-gate 			rc = parse_ldap_default_conf(&proxyInfo, &ldapConfig,
160*8563SKenjiro.Tsuji@Sun.COM 			    &config_info, &ldapDBTableMapping);
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	if (config_file == NULL) {
1640Sstevel@tonic-gate 		if (yp2ldap) {
1650Sstevel@tonic-gate 			if (stat(YP_DEFAULT_MAPPING_FILE, &buf) == 0)
1660Sstevel@tonic-gate 				config_file = YP_DEFAULT_MAPPING_FILE;
1670Sstevel@tonic-gate 		} else {
1680Sstevel@tonic-gate 			if (stat(DEFAULT_MAPPING_FILE, &buf) == 0)
1690Sstevel@tonic-gate 				config_file = DEFAULT_MAPPING_FILE;
1700Sstevel@tonic-gate 		}
1710Sstevel@tonic-gate 	}
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 	if (rc == 0 && config_file != NULL) {
1740Sstevel@tonic-gate 		got_config_data = TRUE;
1750Sstevel@tonic-gate 		warn_file = config_file;
1760Sstevel@tonic-gate 		cmdline_config = cmdline_options;
1770Sstevel@tonic-gate 		if (yp2ldap)
1780Sstevel@tonic-gate 			rc = yp_parse_ldap_config_file(config_file, &proxyInfo,
179*8563SKenjiro.Tsuji@Sun.COM 			    &ldapConfig, &ldapTableMapping, &config_info,
180*8563SKenjiro.Tsuji@Sun.COM 			    &ldapDBTableMapping, &ypDomains);
1810Sstevel@tonic-gate 		else
1820Sstevel@tonic-gate 			rc = parse_ldap_config_file(config_file, &proxyInfo,
183*8563SKenjiro.Tsuji@Sun.COM 			    &ldapConfig, &ldapTableMapping, &config_info,
184*8563SKenjiro.Tsuji@Sun.COM 			    &ldapDBTableMapping);
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 		warn_file = NULL;
1870Sstevel@tonic-gate 		cmdline_config = NULL;
1880Sstevel@tonic-gate 	}
1890Sstevel@tonic-gate 	if (rc == 0 && (config_info.config_dn != NULL) &&
190*8563SKenjiro.Tsuji@Sun.COM 	    (config_info.config_dn[0] != '\0')) {
1910Sstevel@tonic-gate 		rc = parse_ldap_config_dn_attrs(&proxyInfo,
192*8563SKenjiro.Tsuji@Sun.COM 		    &ldapConfig, &ldapTableMapping, &config_info,
193*8563SKenjiro.Tsuji@Sun.COM 		    &ldapDBTableMapping);
1940Sstevel@tonic-gate 	}
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	free_config_info(&config_info);
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate 	if (rc == 0 && got_config_data == FALSE)
1990Sstevel@tonic-gate 		rc = 1;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	set_default_values(&proxyInfo, &ldapConfig, &ldapDBTableMapping);
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	if (yp2ldap == 1 && rc == 0) {
2040Sstevel@tonic-gate 		rc = second_parser_pass(&ldapTableMapping);
2050Sstevel@tonic-gate 		if (rc == 0)
2060Sstevel@tonic-gate 			rc = final_parser_pass(&ldapTableMapping, &ypDomains);
2070Sstevel@tonic-gate 		if (rc == -2)
2080Sstevel@tonic-gate 			return (-1);
2090Sstevel@tonic-gate 	}
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	if (rc == 0)
2120Sstevel@tonic-gate 		rc = finish_parse(&proxyInfo, &ldapTableMapping);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	if (rc == 0)
2150Sstevel@tonic-gate 		rc = linked2hash(ldapTableMapping);
2160Sstevel@tonic-gate 
2172189Ssdussud 	if ((rc == 0) && yptol_mode)
2182189Ssdussud 		rc = map_id_list_init();
2192189Ssdussud 
2200Sstevel@tonic-gate 	if (rc != 0) {
2210Sstevel@tonic-gate 		free_parse_structs();
2220Sstevel@tonic-gate 	} else if (verbose)
2230Sstevel@tonic-gate 		report_info("LDAP configuration complete", NULL);
2240Sstevel@tonic-gate 	return (rc);
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate /*
2280Sstevel@tonic-gate  * FUNCTION:	parse_ldap_cmd_line
2290Sstevel@tonic-gate  *
2300Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
2310Sstevel@tonic-gate  *
2320Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
2330Sstevel@tonic-gate  *
2340Sstevel@tonic-gate  * INPUT:		command line values
2350Sstevel@tonic-gate  */
2360Sstevel@tonic-gate 
2370Sstevel@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)2380Sstevel@tonic-gate parse_ldap_cmd_line(
2390Sstevel@tonic-gate 	const char *const	*cmdline_options,
2400Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
2410Sstevel@tonic-gate 	__nis_config_t		*nis_config,
2420Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
2430Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
2440Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
2450Sstevel@tonic-gate {
2460Sstevel@tonic-gate 	int		rc = 0;
2470Sstevel@tonic-gate 	config_key	attrib_num;
2480Sstevel@tonic-gate 	const char	*begin_s;
2490Sstevel@tonic-gate 	const char	*end_s;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	if (verbose)
2520Sstevel@tonic-gate 		report_info("Command line values: ", NULL);
2530Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
2540Sstevel@tonic-gate 		if (verbose)
2550Sstevel@tonic-gate 			report_info("\t", *cmdline_options);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
2580Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
2590Sstevel@tonic-gate 		if (attrib_num == key_bad) {
2600Sstevel@tonic-gate 			command_line_source = "command line";
2610Sstevel@tonic-gate 			report_error(*cmdline_options, NULL);
2620Sstevel@tonic-gate 			command_line_source = NULL;
2630Sstevel@tonic-gate 			rc = -1;
2640Sstevel@tonic-gate 			break;
2650Sstevel@tonic-gate 		} else if (IS_CONFIG_KEYWORD(attrib_num)) {
2660Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
2670Sstevel@tonic-gate 			    begin_s, end_s - begin_s, config_info);
2680Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
2690Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
2700Sstevel@tonic-gate 			    begin_s, end_s - begin_s, proxy_info);
2710Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
2720Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
2730Sstevel@tonic-gate 			    begin_s, end_s - begin_s, nis_config,
2740Sstevel@tonic-gate 			    table_info);
2750Sstevel@tonic-gate 		} else {
2760Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
2770Sstevel@tonic-gate 			    begin_s, end_s - begin_s, table_mapping);
2780Sstevel@tonic-gate 		}
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 		if (rc < 0) {
2810Sstevel@tonic-gate 			command_line_source = "command line";
2820Sstevel@tonic-gate 			report_error(begin_s, _key_val);
2830Sstevel@tonic-gate 			command_line_source = NULL;
2840Sstevel@tonic-gate 			break;
2850Sstevel@tonic-gate 		}
2860Sstevel@tonic-gate 		cmdline_options++;
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 	return (rc);
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate 
2910Sstevel@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)2920Sstevel@tonic-gate parse_ldap_default_conf(
2930Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
2940Sstevel@tonic-gate 	__nis_config_t *nis_config,
2950Sstevel@tonic-gate 	__nis_config_info_t *config_info,
2960Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate 	int		rc = 0;
2990Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
3000Sstevel@tonic-gate 	char		attr_buf[128];
3010Sstevel@tonic-gate 	char		*attr;
302*8563SKenjiro.Tsuji@Sun.COM 	char		*attr_val;
3030Sstevel@tonic-gate 	int		defflags;
3040Sstevel@tonic-gate 	config_key	attrib_num;
3050Sstevel@tonic-gate 	int		i;
3060Sstevel@tonic-gate 	int		len;
3070Sstevel@tonic-gate 	int		attr_len;
308*8563SKenjiro.Tsuji@Sun.COM 	void		*defp;
3090Sstevel@tonic-gate 
310*8563SKenjiro.Tsuji@Sun.COM 	if ((defp = defopen_r(ETCCONFFILE)) != NULL) {
311*8563SKenjiro.Tsuji@Sun.COM 		file_source = ETCCONFFILE;
312*8563SKenjiro.Tsuji@Sun.COM 		if (verbose)
313*8563SKenjiro.Tsuji@Sun.COM 			report_info("default configuration values: ", NULL);
314*8563SKenjiro.Tsuji@Sun.COM 		/* Set defread_r() to be case insensitive */
315*8563SKenjiro.Tsuji@Sun.COM 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
316*8563SKenjiro.Tsuji@Sun.COM 		TURNOFF(defflags, DC_CASE);
317*8563SKenjiro.Tsuji@Sun.COM 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
3180Sstevel@tonic-gate 
319*8563SKenjiro.Tsuji@Sun.COM 		get_attribute_list(proxy_info, nis_config, config_info,
320*8563SKenjiro.Tsuji@Sun.COM 		    table_info, ldap_config_attributes);
321*8563SKenjiro.Tsuji@Sun.COM 		i = 0;
322*8563SKenjiro.Tsuji@Sun.COM 		while ((attr = ldap_config_attributes[i++]) != NULL) {
323*8563SKenjiro.Tsuji@Sun.COM 			(void) strlcpy(attr_buf, attr, sizeof (attr_buf));
324*8563SKenjiro.Tsuji@Sun.COM 			/*
325*8563SKenjiro.Tsuji@Sun.COM 			 * if nisplusUpdateBatching, make sure
326*8563SKenjiro.Tsuji@Sun.COM 			 * we don't match nisplusUpdateBatchingTimeout
327*8563SKenjiro.Tsuji@Sun.COM 			 */
328*8563SKenjiro.Tsuji@Sun.COM 			if (strcmp(attr, UPDATE_BATCHING) == 0) {
329*8563SKenjiro.Tsuji@Sun.COM 				attr_len = strlen(attr);
330*8563SKenjiro.Tsuji@Sun.COM 				attr_buf[attr_len] = '=';
331*8563SKenjiro.Tsuji@Sun.COM 				attr_buf[attr_len + 1] = '\0';
332*8563SKenjiro.Tsuji@Sun.COM 				attr_val = defread_r(attr_buf, defp);
3330Sstevel@tonic-gate 
334*8563SKenjiro.Tsuji@Sun.COM 				if (attr_val == 0) {
335*8563SKenjiro.Tsuji@Sun.COM 					attr_buf[attr_len] = ' ';
336*8563SKenjiro.Tsuji@Sun.COM 					attr_val = defread_r(attr_buf, defp);
337*8563SKenjiro.Tsuji@Sun.COM 				}
338*8563SKenjiro.Tsuji@Sun.COM 				if (attr_val == 0) {
339*8563SKenjiro.Tsuji@Sun.COM 					attr_buf[attr_len] = '\t';
340*8563SKenjiro.Tsuji@Sun.COM 					attr_val = defread_r(attr_buf, defp);
3410Sstevel@tonic-gate 				}
342*8563SKenjiro.Tsuji@Sun.COM 				if (attr_val == 0) {
343*8563SKenjiro.Tsuji@Sun.COM 					attr_buf[attr_len] = '\n';
344*8563SKenjiro.Tsuji@Sun.COM 					attr_val = defread_r(attr_buf, defp);
345*8563SKenjiro.Tsuji@Sun.COM 				}
346*8563SKenjiro.Tsuji@Sun.COM 			} else {
347*8563SKenjiro.Tsuji@Sun.COM 				attr_val = defread_r(attr_buf, defp);
348*8563SKenjiro.Tsuji@Sun.COM 			}
349*8563SKenjiro.Tsuji@Sun.COM 			if (attr_val == NULL)
350*8563SKenjiro.Tsuji@Sun.COM 				continue;
3510Sstevel@tonic-gate 
352*8563SKenjiro.Tsuji@Sun.COM 			got_config_data = TRUE;
353*8563SKenjiro.Tsuji@Sun.COM 			attrib_num = get_attrib_num(attr, strlen(attr));
354*8563SKenjiro.Tsuji@Sun.COM 			if (attrib_num == key_bad) {
355*8563SKenjiro.Tsuji@Sun.COM 				report_error(attr, NULL);
356*8563SKenjiro.Tsuji@Sun.COM 				rc = -1;
357*8563SKenjiro.Tsuji@Sun.COM 				break;
358*8563SKenjiro.Tsuji@Sun.COM 			}
359*8563SKenjiro.Tsuji@Sun.COM 
360*8563SKenjiro.Tsuji@Sun.COM 			/*
361*8563SKenjiro.Tsuji@Sun.COM 			 * Allow either entries of the form
362*8563SKenjiro.Tsuji@Sun.COM 			 *	attr val
363*8563SKenjiro.Tsuji@Sun.COM 			 *	   or
364*8563SKenjiro.Tsuji@Sun.COM 			 *	attr = val
365*8563SKenjiro.Tsuji@Sun.COM 			 */
366*8563SKenjiro.Tsuji@Sun.COM 			while (is_whitespace(*attr_val))
367*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
368*8563SKenjiro.Tsuji@Sun.COM 			if (*attr_val == '=')
369*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
370*8563SKenjiro.Tsuji@Sun.COM 			while (is_whitespace(*attr_val))
371*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
372*8563SKenjiro.Tsuji@Sun.COM 			len = strlen(attr_val);
373*8563SKenjiro.Tsuji@Sun.COM 			while (len > 0 && is_whitespace(attr_val[len - 1]))
374*8563SKenjiro.Tsuji@Sun.COM 				len--;
3750Sstevel@tonic-gate 
376*8563SKenjiro.Tsuji@Sun.COM 			if (verbose) {
377*8563SKenjiro.Tsuji@Sun.COM 				report_info("\t", attr);
378*8563SKenjiro.Tsuji@Sun.COM 				report_info("\t\t", attr_val);
379*8563SKenjiro.Tsuji@Sun.COM 			}
380*8563SKenjiro.Tsuji@Sun.COM 			if (IS_BIND_INFO(attrib_num)) {
381*8563SKenjiro.Tsuji@Sun.COM 				rc = add_bind_attribute(attrib_num,
382*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, proxy_info);
383*8563SKenjiro.Tsuji@Sun.COM 			} else if (IS_OPER_INFO(attrib_num)) {
384*8563SKenjiro.Tsuji@Sun.COM 				rc = add_operation_attribute(attrib_num,
385*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, nis_config,
386*8563SKenjiro.Tsuji@Sun.COM 				    table_info);
3870Sstevel@tonic-gate 			}
388*8563SKenjiro.Tsuji@Sun.COM 			if (p_error != no_parse_error) {
389*8563SKenjiro.Tsuji@Sun.COM 				report_error(attr_val, attr);
390*8563SKenjiro.Tsuji@Sun.COM 				rc = -1;
391*8563SKenjiro.Tsuji@Sun.COM 				break;
392*8563SKenjiro.Tsuji@Sun.COM 			}
3930Sstevel@tonic-gate 		}
394*8563SKenjiro.Tsuji@Sun.COM 		file_source = NULL;
395*8563SKenjiro.Tsuji@Sun.COM 		/* Close the /etc/default file */
396*8563SKenjiro.Tsuji@Sun.COM 		defclose_r(defp);
397*8563SKenjiro.Tsuji@Sun.COM 	}
398*8563SKenjiro.Tsuji@Sun.COM 	return (rc);
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate 
4010Sstevel@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)4020Sstevel@tonic-gate yp_parse_ldap_default_conf(
4030Sstevel@tonic-gate 	__nis_ldap_proxy_info *proxy_info,
4040Sstevel@tonic-gate 	__nis_config_t	*nis_config,
4050Sstevel@tonic-gate 	__nis_config_info_t *config_info,
4060Sstevel@tonic-gate 	__nisdb_table_mapping_t *table_info)
4070Sstevel@tonic-gate {
4080Sstevel@tonic-gate 	int rc = 0;
4090Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
4100Sstevel@tonic-gate 	char		attr_buf[128];
4110Sstevel@tonic-gate 	char		*attr;
412*8563SKenjiro.Tsuji@Sun.COM 	char		*attr_val;
4130Sstevel@tonic-gate 	int		defflags;
4140Sstevel@tonic-gate 	config_key	attrib_num;
4150Sstevel@tonic-gate 	int 	i, len, attr_len;
416*8563SKenjiro.Tsuji@Sun.COM 	void		*defp;
4170Sstevel@tonic-gate 
418*8563SKenjiro.Tsuji@Sun.COM 	if ((defp = defopen_r(YP_ETCCONFFILE)) != NULL) {
4190Sstevel@tonic-gate 		file_source = YP_ETCCONFFILE;
4200Sstevel@tonic-gate 		if (verbose)
4210Sstevel@tonic-gate 			report_info("default configuration values: ", NULL);
422*8563SKenjiro.Tsuji@Sun.COM 		/* Set defread_r() to be case insensitive */
423*8563SKenjiro.Tsuji@Sun.COM 		defflags = defcntl_r(DC_GETFLAGS, 0, defp);
424*8563SKenjiro.Tsuji@Sun.COM 		TURNOFF(defflags, DC_CASE);
425*8563SKenjiro.Tsuji@Sun.COM 		(void) defcntl_r(DC_SETFLAGS, defflags, defp);
4260Sstevel@tonic-gate 
427*8563SKenjiro.Tsuji@Sun.COM 		get_attribute_list(proxy_info, nis_config, config_info,
428*8563SKenjiro.Tsuji@Sun.COM 		    table_info, ldap_config_attributes);
429*8563SKenjiro.Tsuji@Sun.COM 		i = 0;
430*8563SKenjiro.Tsuji@Sun.COM 		while ((attr = ldap_config_attributes[i++]) != NULL) {
431*8563SKenjiro.Tsuji@Sun.COM 			if ((strlcpy(attr_buf, attr, sizeof (attr_buf))) >=
432*8563SKenjiro.Tsuji@Sun.COM 			    sizeof (attr_buf)) {
433*8563SKenjiro.Tsuji@Sun.COM 				report_error(
434*8563SKenjiro.Tsuji@Sun.COM 				    "Static buffer attr_buf overflow", NULL);
435*8563SKenjiro.Tsuji@Sun.COM 				defclose_r(defp);
436*8563SKenjiro.Tsuji@Sun.COM 				return (-1);
437*8563SKenjiro.Tsuji@Sun.COM 			}
4380Sstevel@tonic-gate 
439*8563SKenjiro.Tsuji@Sun.COM 			if ((attr_val = defread_r(attr_buf, defp)) == NULL)
440*8563SKenjiro.Tsuji@Sun.COM 				continue;
4410Sstevel@tonic-gate 
442*8563SKenjiro.Tsuji@Sun.COM 			got_config_data = TRUE;
443*8563SKenjiro.Tsuji@Sun.COM 			attrib_num = get_attrib_num(attr, strlen(attr));
444*8563SKenjiro.Tsuji@Sun.COM 			if (attrib_num == key_bad) {
445*8563SKenjiro.Tsuji@Sun.COM 				report_error(attr, NULL);
446*8563SKenjiro.Tsuji@Sun.COM 				rc = -1;
447*8563SKenjiro.Tsuji@Sun.COM 				break;
448*8563SKenjiro.Tsuji@Sun.COM 			}
4490Sstevel@tonic-gate 
450*8563SKenjiro.Tsuji@Sun.COM 			/*
451*8563SKenjiro.Tsuji@Sun.COM 			 * Allow either entries of the form
452*8563SKenjiro.Tsuji@Sun.COM 			 * attr val
453*8563SKenjiro.Tsuji@Sun.COM 			 * or
454*8563SKenjiro.Tsuji@Sun.COM 			 * attr = val
455*8563SKenjiro.Tsuji@Sun.COM 			 */
456*8563SKenjiro.Tsuji@Sun.COM 			while (is_whitespace(*attr_val))
457*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
458*8563SKenjiro.Tsuji@Sun.COM 			if (*attr_val == '=')
459*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
460*8563SKenjiro.Tsuji@Sun.COM 			while (is_whitespace(*attr_val))
461*8563SKenjiro.Tsuji@Sun.COM 				attr_val++;
462*8563SKenjiro.Tsuji@Sun.COM 			len = strlen(attr_val);
463*8563SKenjiro.Tsuji@Sun.COM 			while (len > 0 && is_whitespace(attr_val[len - 1]))
464*8563SKenjiro.Tsuji@Sun.COM 				len--;
4650Sstevel@tonic-gate 
466*8563SKenjiro.Tsuji@Sun.COM 			if (verbose) {
467*8563SKenjiro.Tsuji@Sun.COM 				report_info("\t", attr);
468*8563SKenjiro.Tsuji@Sun.COM 				report_info("\t\t", attr_val);
469*8563SKenjiro.Tsuji@Sun.COM 			}
470*8563SKenjiro.Tsuji@Sun.COM 			if (IS_YP_BIND_INFO(attrib_num)) {
471*8563SKenjiro.Tsuji@Sun.COM 				rc = add_bind_attribute(attrib_num,
472*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, proxy_info);
473*8563SKenjiro.Tsuji@Sun.COM 			} else if (IS_YP_OPER_INFO(attrib_num)) {
474*8563SKenjiro.Tsuji@Sun.COM 				rc = add_operation_attribute(attrib_num,
475*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, nis_config,
476*8563SKenjiro.Tsuji@Sun.COM 				    table_info);
4770Sstevel@tonic-gate 			}
478*8563SKenjiro.Tsuji@Sun.COM 			if (p_error != no_parse_error) {
479*8563SKenjiro.Tsuji@Sun.COM 				report_error(attr_val, attr);
480*8563SKenjiro.Tsuji@Sun.COM 				rc = -1;
481*8563SKenjiro.Tsuji@Sun.COM 				break;
482*8563SKenjiro.Tsuji@Sun.COM 			}
4830Sstevel@tonic-gate 		}
484*8563SKenjiro.Tsuji@Sun.COM 		file_source = NULL;
485*8563SKenjiro.Tsuji@Sun.COM 		/* Close the /etc/default file */
486*8563SKenjiro.Tsuji@Sun.COM 		defclose_r(defp);
487*8563SKenjiro.Tsuji@Sun.COM 	}
488*8563SKenjiro.Tsuji@Sun.COM 	return (rc);
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate /*
4920Sstevel@tonic-gate  * FUNCTION:	get_attrib_num_cmdline
4930Sstevel@tonic-gate  *
4940Sstevel@tonic-gate  *	Parses the information for LDAP from the command line
4950Sstevel@tonic-gate  *	The form of the command line request is
4960Sstevel@tonic-gate  *		-x attribute=value
4970Sstevel@tonic-gate  *
4980Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
4990Sstevel@tonic-gate  *
5000Sstevel@tonic-gate  * INPUT:		command line values
5010Sstevel@tonic-gate  */
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate static config_key
get_attrib_num_cmdline(const char * s,const char ** begin_s,const char ** end_s)5040Sstevel@tonic-gate get_attrib_num_cmdline(
5050Sstevel@tonic-gate 	const char	*s,
5060Sstevel@tonic-gate 	const char 	**begin_s,
5070Sstevel@tonic-gate 	const char 	**end_s)
5080Sstevel@tonic-gate {
5090Sstevel@tonic-gate 	const char	*s_end		= s + strlen(s);
5100Sstevel@tonic-gate 	const char	*equal_s;
5110Sstevel@tonic-gate 	const char	*s1;
5120Sstevel@tonic-gate 	config_key	attrib_num;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	while (s < s_end && is_whitespace(*s))
5150Sstevel@tonic-gate 		s++;
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 	for (equal_s = s; equal_s < s_end; equal_s++)
5180Sstevel@tonic-gate 		if (*equal_s == EQUAL_CHAR)
5190Sstevel@tonic-gate 			break;
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate 	if (equal_s == s_end) {
5220Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5230Sstevel@tonic-gate 		return (key_bad);
5240Sstevel@tonic-gate 	}
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate 	for (s1 = equal_s; s1 > s && is_whitespace(s1[-1]); s1--)
5270Sstevel@tonic-gate 		;
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate 	if (s1 == s) {
5300Sstevel@tonic-gate 		p_error = parse_bad_command_line_attribute_format;
5310Sstevel@tonic-gate 		return (key_bad);
5320Sstevel@tonic-gate 	}
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 	attrib_num = get_attrib_num(s, s1 - s);
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 	if (attrib_num != key_bad) {
5370Sstevel@tonic-gate 		s1 = equal_s + 1;
5380Sstevel@tonic-gate 		while (s1 < s_end && is_whitespace(*s1))
5390Sstevel@tonic-gate 			s1++;
5400Sstevel@tonic-gate 		*begin_s = s1;
5410Sstevel@tonic-gate 		while (s_end > s1 && is_whitespace(s_end[-1]))
5420Sstevel@tonic-gate 			s_end--;
5430Sstevel@tonic-gate 		*end_s = s_end;
5440Sstevel@tonic-gate 	}
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 	return (attrib_num);
5470Sstevel@tonic-gate }
5480Sstevel@tonic-gate 
5490Sstevel@tonic-gate /*
5500Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_file
5510Sstevel@tonic-gate  *
5520Sstevel@tonic-gate  *	Parses the information for LDAP from a configuration
5530Sstevel@tonic-gate  *	file. If no file is specified, /var/nis/NIS+LDAPmapping
5540Sstevel@tonic-gate  *	is used
5550Sstevel@tonic-gate  *
5560Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
5570Sstevel@tonic-gate  *
5580Sstevel@tonic-gate  * INPUT:		configuration file name
5590Sstevel@tonic-gate  */
5600Sstevel@tonic-gate 
5610Sstevel@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)5620Sstevel@tonic-gate parse_ldap_config_file(
5630Sstevel@tonic-gate 	const char 		*config_file,
5640Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
5650Sstevel@tonic-gate 	__nis_config_t		*nis_config,
5660Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
5670Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
5680Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
5690Sstevel@tonic-gate {
5700Sstevel@tonic-gate 	int		rc = 0;
5710Sstevel@tonic-gate 	config_key	attrib_num;
5720Sstevel@tonic-gate 	int		fd;
5730Sstevel@tonic-gate 	char		*attr_val;
5740Sstevel@tonic-gate 	int		len;
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
5770Sstevel@tonic-gate 		p_error = parse_open_file_error;
5780Sstevel@tonic-gate 		report_error(config_file, NULL);
5790Sstevel@tonic-gate 		return (-1);
5800Sstevel@tonic-gate 	}
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate 	start_line_num = 1;
5830Sstevel@tonic-gate 	cur_line_num = 1;
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate 	if (verbose)
5860Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate 	file_source = config_file;
5890Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
5900Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
5910Sstevel@tonic-gate 		if (IS_CONFIG_KEYWORD(attrib_num)) {
5920Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
5930Sstevel@tonic-gate 			    attr_val, len, config_info);
5940Sstevel@tonic-gate 		} else if (IS_BIND_INFO(attrib_num)) {
5950Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
5960Sstevel@tonic-gate 			    attr_val, len, proxy_info);
5970Sstevel@tonic-gate 		} else if (IS_OPER_INFO(attrib_num)) {
5980Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
5990Sstevel@tonic-gate 			    attr_val, len, nis_config, table_info);
6000Sstevel@tonic-gate 		} else {
6010Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
602*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, table_mapping);
6030Sstevel@tonic-gate 		}
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate 		if (rc < 0) {
6060Sstevel@tonic-gate 			report_error(attr_val == NULL ?
607*8563SKenjiro.Tsuji@Sun.COM 			    "<no attribute>" : attr_val, _key_val);
6080Sstevel@tonic-gate 			if (attr_val)
6090Sstevel@tonic-gate 				free(attr_val);
6100Sstevel@tonic-gate 			break;
6110Sstevel@tonic-gate 		}
6120Sstevel@tonic-gate 		if (attr_val)
6130Sstevel@tonic-gate 			free(attr_val);
6140Sstevel@tonic-gate 	}
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 	(void) close(fd);
6170Sstevel@tonic-gate 	if (attrib_num == key_bad) {
6180Sstevel@tonic-gate 		report_error(_key_val, NULL);
6190Sstevel@tonic-gate 		rc = -1;
6200Sstevel@tonic-gate 	}
6210Sstevel@tonic-gate 	start_line_num = 0;
6220Sstevel@tonic-gate 	file_source = NULL;
6230Sstevel@tonic-gate 	return (rc);
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate /*
6270Sstevel@tonic-gate  * FUNCTION:	yp_parse_ldap_config_file
6280Sstevel@tonic-gate  *
6290Sstevel@tonic-gate  * Parses the information for LDAP from a configuration
6300Sstevel@tonic-gate  * file. If no file is specified, /var/yp/NISLDAPmapping
6310Sstevel@tonic-gate  * is used
6320Sstevel@tonic-gate  *
6330Sstevel@tonic-gate  * RETURN VALUE:    0 on success, -1 on failure
6340Sstevel@tonic-gate  *
6350Sstevel@tonic-gate  * INPUT:       configuration file name
6360Sstevel@tonic-gate  */
6370Sstevel@tonic-gate 
6380Sstevel@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)6390Sstevel@tonic-gate yp_parse_ldap_config_file(
6400Sstevel@tonic-gate 	const char	*config_file,
6410Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
6420Sstevel@tonic-gate 	__nis_config_t			*nis_config,
6430Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
6440Sstevel@tonic-gate 	__nis_config_info_t		*config_info,
6450Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info,
6460Sstevel@tonic-gate 	__yp_domain_context_t	*ypDomains)
6470Sstevel@tonic-gate {
6480Sstevel@tonic-gate 	int	rc = 0;
6490Sstevel@tonic-gate 	int	numDomains = 0;
6500Sstevel@tonic-gate 	config_key	attrib_num;
6510Sstevel@tonic-gate 	int	fd;
6520Sstevel@tonic-gate 	char	*attr_val = NULL;
6530Sstevel@tonic-gate 	int		len;
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	if ((fd = open(config_file, O_RDONLY)) == -1) {
6560Sstevel@tonic-gate 		p_error = parse_open_file_error;
6570Sstevel@tonic-gate 		report_error(config_file, NULL);
6580Sstevel@tonic-gate 		return (-1);
6590Sstevel@tonic-gate 	}
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate 	start_line_num = 1;
6620Sstevel@tonic-gate 	cur_line_num = 1;
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate 	if (verbose)
6650Sstevel@tonic-gate 		report_info("Reading configuration from ", config_file);
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate 	file_source = config_file;
6680Sstevel@tonic-gate 	while ((attrib_num = get_file_attr_val(fd, &attr_val)) > 0) {
6690Sstevel@tonic-gate 		len = attr_val == NULL ? 0 : strlen(attr_val);
6700Sstevel@tonic-gate 		if (IS_YP_CONFIG_KEYWORD(attrib_num)) {
6710Sstevel@tonic-gate 			rc = add_config_attribute(attrib_num,
672*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, config_info);
6730Sstevel@tonic-gate 		} else if (IS_YP_BIND_INFO(attrib_num)) {
6740Sstevel@tonic-gate 			rc = add_bind_attribute(attrib_num,
675*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, proxy_info);
6760Sstevel@tonic-gate 		} else if (IS_YP_OPER_INFO(attrib_num)) {
6770Sstevel@tonic-gate 			rc = add_operation_attribute(attrib_num,
678*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, nis_config, table_info);
6790Sstevel@tonic-gate 		} else if (IS_YP_DOMAIN_INFO(attrib_num)) {
6800Sstevel@tonic-gate 			rc = add_ypdomains_attribute(attrib_num,
681*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, ypDomains);
6820Sstevel@tonic-gate 		} else if (IS_YP_MAP_ATTR(attrib_num)) {
6830Sstevel@tonic-gate 			rc = add_mapping_attribute(attrib_num,
684*8563SKenjiro.Tsuji@Sun.COM 			    attr_val, len, table_mapping);
6850Sstevel@tonic-gate 		} else {
6860Sstevel@tonic-gate 			rc = -1;
6870Sstevel@tonic-gate 			p_error = parse_unsupported_format;
6880Sstevel@tonic-gate 		}
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate 		if (rc < 0) {
6910Sstevel@tonic-gate 			report_error(attr_val == NULL ?
692*8563SKenjiro.Tsuji@Sun.COM 			    "<no attribute>" : attr_val, _key_val);
6930Sstevel@tonic-gate 			if (attr_val)
6940Sstevel@tonic-gate 				free(attr_val);
6950Sstevel@tonic-gate 			break;
6960Sstevel@tonic-gate 		}
6970Sstevel@tonic-gate 		if (attr_val) {
6980Sstevel@tonic-gate 			free(attr_val);
6990Sstevel@tonic-gate 			attr_val = NULL;
7000Sstevel@tonic-gate 		}
7010Sstevel@tonic-gate 	}
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 	(void) close(fd);
7040Sstevel@tonic-gate 	if (attrib_num == key_bad) {
7050Sstevel@tonic-gate 		report_error(_key_val, NULL);
7060Sstevel@tonic-gate 		rc = -1;
7070Sstevel@tonic-gate 	}
7080Sstevel@tonic-gate 	start_line_num = 0;
7090Sstevel@tonic-gate 	file_source = NULL;
7100Sstevel@tonic-gate 	return (rc);
7110Sstevel@tonic-gate }
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate /*
7140Sstevel@tonic-gate  * FUNCTION:	get_file_attr_val
7150Sstevel@tonic-gate  *
7160Sstevel@tonic-gate  *	Gets the next attribute from the configuration file.
7170Sstevel@tonic-gate  *
7180Sstevel@tonic-gate  * RETURN VALUE:	The config key if more attributes
7190Sstevel@tonic-gate  *			no_more_keys if eof
7200Sstevel@tonic-gate  *			key_bad if error
7210Sstevel@tonic-gate  */
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate static config_key
get_file_attr_val(int fd,char ** attr_val)7240Sstevel@tonic-gate get_file_attr_val(int fd, char **attr_val)
7250Sstevel@tonic-gate {
7260Sstevel@tonic-gate 	char		buf[BUFSIZE];
7270Sstevel@tonic-gate 	char		*start_tag;
7280Sstevel@tonic-gate 	char		*start_val;
7290Sstevel@tonic-gate 	char		*end_val;
7300Sstevel@tonic-gate 	char		*cut_here;
7310Sstevel@tonic-gate 	char		*s;
7320Sstevel@tonic-gate 	char		*a;
7330Sstevel@tonic-gate 	char		*attribute_value;
7340Sstevel@tonic-gate 	int		ret;
7350Sstevel@tonic-gate 	config_key	attrib_num = no_more_keys;
7360Sstevel@tonic-gate 	int		found_quote = 0;
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 	*attr_val = NULL;
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 	if ((ret = read_line(fd, buf, sizeof (buf))) > 0) {
7410Sstevel@tonic-gate 		for (s = buf; is_whitespace(*s); s++)
7420Sstevel@tonic-gate 			;
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate 		start_tag = s;
7450Sstevel@tonic-gate 		while (*s != '\0' && !is_whitespace(*s))
7460Sstevel@tonic-gate 			s++;
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate 		if (verbose)
7490Sstevel@tonic-gate 			report_info("\t", start_tag);
7500Sstevel@tonic-gate 		attrib_num = get_attrib_num(start_tag, s - start_tag);
7510Sstevel@tonic-gate 		if (attrib_num == key_bad)
7520Sstevel@tonic-gate 			return (key_bad);
7530Sstevel@tonic-gate 
7540Sstevel@tonic-gate 		while (is_whitespace(*s))
7550Sstevel@tonic-gate 			s++;
7560Sstevel@tonic-gate 		if (*s == '\0')
7570Sstevel@tonic-gate 			return (attrib_num);
7580Sstevel@tonic-gate 		start_val = s;
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 		/* note that read_line will not return a line ending with \ */
7610Sstevel@tonic-gate 		for (; *s != '\0'; s++) {
7620Sstevel@tonic-gate 			if (*s == ESCAPE_CHAR)
7630Sstevel@tonic-gate 				s++;
7640Sstevel@tonic-gate 		}
7650Sstevel@tonic-gate 		while (s > start_val && is_whitespace(s[-1]))
7660Sstevel@tonic-gate 			s--;
7670Sstevel@tonic-gate 
7680Sstevel@tonic-gate 		attribute_value =
769*8563SKenjiro.Tsuji@Sun.COM 		    calloc(1, (size_t)(s - start_val) + 1);
7700Sstevel@tonic-gate 		if (attribute_value == NULL) {
7710Sstevel@tonic-gate 			p_error = parse_no_mem_error;
7720Sstevel@tonic-gate 			return (key_bad);
7730Sstevel@tonic-gate 		}
7740Sstevel@tonic-gate 		attr_val[0] = attribute_value;
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 		a = *attr_val;
7770Sstevel@tonic-gate 		end_val = s;
7780Sstevel@tonic-gate 		cut_here = 0;
7790Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++) {
7800Sstevel@tonic-gate 			if (*s == POUND_SIGN) {
7810Sstevel@tonic-gate 					cut_here = s;
7820Sstevel@tonic-gate 					while (s < end_val) {
7830Sstevel@tonic-gate 						if (*s == DOUBLE_QUOTE_CHAR ||
784*8563SKenjiro.Tsuji@Sun.COM 						    *s == SINGLE_QUOTE_CHAR) {
7850Sstevel@tonic-gate 							cut_here = 0;
7860Sstevel@tonic-gate 							break;
7870Sstevel@tonic-gate 						}
7880Sstevel@tonic-gate 						s++;
7890Sstevel@tonic-gate 					}
7900Sstevel@tonic-gate 			}
7910Sstevel@tonic-gate 		}
7920Sstevel@tonic-gate 		if (cut_here != 0)
7930Sstevel@tonic-gate 			end_val = cut_here;
7940Sstevel@tonic-gate 
7950Sstevel@tonic-gate 		for (s = start_val; s < end_val; s++)
7960Sstevel@tonic-gate 			*a++ = *s;
7970Sstevel@tonic-gate 		*a++ = '\0';
7980Sstevel@tonic-gate 	}
7990Sstevel@tonic-gate 	if (ret == -1)
8000Sstevel@tonic-gate 		return (key_bad);
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate 	return (attrib_num);
8030Sstevel@tonic-gate }
8040Sstevel@tonic-gate 
8050Sstevel@tonic-gate static LDAP *
connect_to_ldap_config_server(char * sever_name,int server_port,__nis_config_info_t * config_info)8060Sstevel@tonic-gate connect_to_ldap_config_server(
8070Sstevel@tonic-gate 	char			*sever_name,
8080Sstevel@tonic-gate 	int			server_port,
8090Sstevel@tonic-gate 	__nis_config_info_t	*config_info)
8100Sstevel@tonic-gate {
8110Sstevel@tonic-gate 	int		rc		= 0;
8120Sstevel@tonic-gate 	LDAP		*ld		= NULL;
8130Sstevel@tonic-gate 	int		ldapVersion	= LDAP_VERSION3;
8140Sstevel@tonic-gate 	int		derefOption	= LDAP_DEREF_ALWAYS;
8150Sstevel@tonic-gate 	int		timelimit	= LDAP_NO_LIMIT;
8160Sstevel@tonic-gate 	int		sizelimit	= LDAP_NO_LIMIT;
8170Sstevel@tonic-gate 	int		errnum;
8180Sstevel@tonic-gate 	bool_t		retrying	= FALSE;
8190Sstevel@tonic-gate 	int		sleep_seconds	= 1;
8200Sstevel@tonic-gate 	struct berval	cred;
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 	if (config_info->tls_method == no_tls) {
8230Sstevel@tonic-gate 		ld = ldap_init(sever_name, server_port);
8240Sstevel@tonic-gate 		if (ld == NULL) {
8250Sstevel@tonic-gate 			p_error = parse_ldap_init_error;
8260Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8270Sstevel@tonic-gate 			return (NULL);
8280Sstevel@tonic-gate 		}
8290Sstevel@tonic-gate 	} else {
8300Sstevel@tonic-gate 		if ((errnum = ldapssl_client_init(
831*8563SKenjiro.Tsuji@Sun.COM 		    config_info->tls_cert_db, NULL)) < 0) {
8320Sstevel@tonic-gate 			p_error = parse_ldapssl_client_init_error;
8330Sstevel@tonic-gate 			report_error(ldapssl_err2string(errnum), NULL);
8340Sstevel@tonic-gate 			return (NULL);
8350Sstevel@tonic-gate 		}
8360Sstevel@tonic-gate 		ld = ldapssl_init(sever_name, server_port, 1);
8370Sstevel@tonic-gate 		if (ld == NULL) {
8380Sstevel@tonic-gate 			p_error = parse_ldapssl_init_error;
8390Sstevel@tonic-gate 			report_error(strerror(errno), NULL);
8400Sstevel@tonic-gate 			return (NULL);
8410Sstevel@tonic-gate 		}
8420Sstevel@tonic-gate 	}
8430Sstevel@tonic-gate 
8440Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,
845*8563SKenjiro.Tsuji@Sun.COM 	    &ldapVersion);
8460Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_DEREF, &derefOption);
8470Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
8480Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_TIMELIMIT, &timelimit);
8490Sstevel@tonic-gate 	(void) ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 	/*
8520Sstevel@tonic-gate 	 * Attempt to bind to the LDAP server.
8530Sstevel@tonic-gate 	 * We will loop until success or until an error other
8540Sstevel@tonic-gate 	 * than LDAP_CONNECT_ERROR or LDAP_SERVER_DOWN
8550Sstevel@tonic-gate 	 */
8560Sstevel@tonic-gate 	if (verbose)
8570Sstevel@tonic-gate 		report_info("Connecting to ", sever_name);
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate 	for (;;) {
8600Sstevel@tonic-gate 		if (config_info->auth_method == simple) {
8610Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, config_info->proxy_dn,
862*8563SKenjiro.Tsuji@Sun.COM 			    config_info->proxy_passwd);
8630Sstevel@tonic-gate 		} else if (config_info->auth_method == cram_md5) {
8640Sstevel@tonic-gate 			cred.bv_len = strlen(config_info->proxy_passwd);
8650Sstevel@tonic-gate 			cred.bv_val = config_info->proxy_passwd;
8660Sstevel@tonic-gate 			errnum = ldap_sasl_cram_md5_bind_s(ld,
867*8563SKenjiro.Tsuji@Sun.COM 			    config_info->proxy_dn, &cred, NULL, NULL);
8680Sstevel@tonic-gate 		} else if (config_info->auth_method == digest_md5) {
8690Sstevel@tonic-gate 			cred.bv_len = strlen(config_info->proxy_passwd);
8700Sstevel@tonic-gate 			cred.bv_val = config_info->proxy_passwd;
8710Sstevel@tonic-gate 			errnum = ldap_x_sasl_digest_md5_bind_s(ld,
872*8563SKenjiro.Tsuji@Sun.COM 			    config_info->proxy_dn, &cred, NULL, NULL);
8730Sstevel@tonic-gate 		} else {
8740Sstevel@tonic-gate 			errnum = ldap_simple_bind_s(ld, NULL, NULL);
8750Sstevel@tonic-gate 		}
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate 		if (errnum == LDAP_SUCCESS)
8780Sstevel@tonic-gate 			break;
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate 		if (errnum == LDAP_CONNECT_ERROR ||
881*8563SKenjiro.Tsuji@Sun.COM 		    errnum == LDAP_SERVER_DOWN) {
8820Sstevel@tonic-gate 			if (!retrying) {
8830Sstevel@tonic-gate 				if (verbose)
884*8563SKenjiro.Tsuji@Sun.COM 					report_info(
8850Sstevel@tonic-gate 					"LDAP server unavailable. Retrying...",
886*8563SKenjiro.Tsuji@Sun.COM 					    NULL);
8870Sstevel@tonic-gate 				retrying = TRUE;
8880Sstevel@tonic-gate 			}
8890Sstevel@tonic-gate 			(void) sleep(sleep_seconds);
8900Sstevel@tonic-gate 			sleep_seconds *= 2;
8910Sstevel@tonic-gate 			if (sleep_seconds > MAX_LDAP_CONFIG_RETRY_TIME)
8920Sstevel@tonic-gate 				sleep_seconds = MAX_LDAP_CONFIG_RETRY_TIME;
8930Sstevel@tonic-gate 			p_error = no_parse_error;
8940Sstevel@tonic-gate 			continue;
8950Sstevel@tonic-gate 		}
8960Sstevel@tonic-gate 		p_error = parse_ldap_bind_error;
8970Sstevel@tonic-gate 		report_error2(config_info->proxy_dn, ldap_err2string(errnum));
8980Sstevel@tonic-gate 		(void) ldap_unbind(ld);
8990Sstevel@tonic-gate 		return (NULL);
9000Sstevel@tonic-gate 	}
9010Sstevel@tonic-gate 
9020Sstevel@tonic-gate 	if (verbose)
9030Sstevel@tonic-gate 		report_info("Reading values from ", config_info->config_dn);
9040Sstevel@tonic-gate 
9050Sstevel@tonic-gate 	return (ld);
9060Sstevel@tonic-gate }
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate /*
9090Sstevel@tonic-gate  * FUNCTION:	process_ldap_config_result
9100Sstevel@tonic-gate  *
9110Sstevel@tonic-gate  *	Extracts the LDAPMessage containing the nis+/LDAP
9120Sstevel@tonic-gate  *	configuration
9130Sstevel@tonic-gate  *
9140Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
9150Sstevel@tonic-gate  *
9160Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
9170Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
9180Sstevel@tonic-gate  */
9190Sstevel@tonic-gate 
9200Sstevel@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)9210Sstevel@tonic-gate process_ldap_config_result(
9220Sstevel@tonic-gate 	LDAP			*ld,
9230Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
9240Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
9250Sstevel@tonic-gate 	__nis_config_t		*nis_config,
9260Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
9270Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
9280Sstevel@tonic-gate {
9290Sstevel@tonic-gate 	LDAPMessage	*e;
9300Sstevel@tonic-gate 	int		errnum;
9310Sstevel@tonic-gate 	char		*attr;
9320Sstevel@tonic-gate 	BerElement	*ber		= NULL;
9330Sstevel@tonic-gate 	config_key	attrib_num;
9340Sstevel@tonic-gate 	char		**vals;
9350Sstevel@tonic-gate 	int		n;
9360Sstevel@tonic-gate 	int		i;
9370Sstevel@tonic-gate 	char		*attr_val;
9380Sstevel@tonic-gate 	int		len;
9390Sstevel@tonic-gate 	int		rc = 0;
9400Sstevel@tonic-gate 	bool_t		error_reported	= FALSE;
9410Sstevel@tonic-gate 
9420Sstevel@tonic-gate 	e = ldap_first_entry(ld, resultMsg);
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate 	if (e != NULL) {
945*8563SKenjiro.Tsuji@Sun.COM 		for (attr = ldap_first_attribute(ld, e, &ber); attr != NULL;
946*8563SKenjiro.Tsuji@Sun.COM 		    attr = ldap_next_attribute(ld, e, ber)) {
947*8563SKenjiro.Tsuji@Sun.COM 			if (verbose)
948*8563SKenjiro.Tsuji@Sun.COM 				report_info("\t", attr);
949*8563SKenjiro.Tsuji@Sun.COM 			attrib_num = get_attrib_num(attr, strlen(attr));
950*8563SKenjiro.Tsuji@Sun.COM 			if (attrib_num == key_bad) {
9510Sstevel@tonic-gate 				report_error(attr, NULL);
9520Sstevel@tonic-gate 				break;
953*8563SKenjiro.Tsuji@Sun.COM 			}
954*8563SKenjiro.Tsuji@Sun.COM 			if ((vals = ldap_get_values(ld, e, attr)) != NULL) {
955*8563SKenjiro.Tsuji@Sun.COM 				n = ldap_count_values(vals);
956*8563SKenjiro.Tsuji@Sun.COM 				/* parse the attribute values */
957*8563SKenjiro.Tsuji@Sun.COM 				for (i = 0; i < n; i++) {
958*8563SKenjiro.Tsuji@Sun.COM 					attr_val = vals[i];
959*8563SKenjiro.Tsuji@Sun.COM 					while (is_whitespace(*attr_val))
960*8563SKenjiro.Tsuji@Sun.COM 						attr_val++;
961*8563SKenjiro.Tsuji@Sun.COM 					if (verbose)
962*8563SKenjiro.Tsuji@Sun.COM 						report_info("\t\t", attr_val);
963*8563SKenjiro.Tsuji@Sun.COM 					len = strlen(attr_val);
964*8563SKenjiro.Tsuji@Sun.COM 					while (len > 0 &&
965*8563SKenjiro.Tsuji@Sun.COM 					    is_whitespace(attr_val[len - 1]))
966*8563SKenjiro.Tsuji@Sun.COM 						len--;
967*8563SKenjiro.Tsuji@Sun.COM 		if (yp2ldap) {
968*8563SKenjiro.Tsuji@Sun.COM 			if (IS_YP_BIND_INFO(attrib_num)) {
969*8563SKenjiro.Tsuji@Sun.COM 				rc = add_bind_attribute(attrib_num, attr_val,
970*8563SKenjiro.Tsuji@Sun.COM 				    len, proxy_info);
971*8563SKenjiro.Tsuji@Sun.COM 			} else if (IS_YP_OPER_INFO(attrib_num)) {
972*8563SKenjiro.Tsuji@Sun.COM 				rc = add_operation_attribute(attrib_num,
973*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, nis_config, table_info);
974*8563SKenjiro.Tsuji@Sun.COM 			} else if (IS_YP_MAP_ATTR(attrib_num)) {
975*8563SKenjiro.Tsuji@Sun.COM 				rc = add_mapping_attribute(attrib_num, attr_val,
976*8563SKenjiro.Tsuji@Sun.COM 				    len, table_mapping);
977*8563SKenjiro.Tsuji@Sun.COM 			} else {
978*8563SKenjiro.Tsuji@Sun.COM 				p_error = parse_unsupported_format;
979*8563SKenjiro.Tsuji@Sun.COM 			}
980*8563SKenjiro.Tsuji@Sun.COM 		} else {
981*8563SKenjiro.Tsuji@Sun.COM 			if (IS_BIND_INFO(attrib_num)) {
982*8563SKenjiro.Tsuji@Sun.COM 				rc = add_bind_attribute(attrib_num, attr_val,
983*8563SKenjiro.Tsuji@Sun.COM 				    len, proxy_info);
984*8563SKenjiro.Tsuji@Sun.COM 			} else if (IS_OPER_INFO(attrib_num)) {
985*8563SKenjiro.Tsuji@Sun.COM 				rc = add_operation_attribute(attrib_num,
986*8563SKenjiro.Tsuji@Sun.COM 				    attr_val, len, nis_config, table_info);
987*8563SKenjiro.Tsuji@Sun.COM 			} else {
988*8563SKenjiro.Tsuji@Sun.COM 				rc = add_mapping_attribute(attrib_num, attr_val,
989*8563SKenjiro.Tsuji@Sun.COM 				    len, table_mapping);
990*8563SKenjiro.Tsuji@Sun.COM 			}
991*8563SKenjiro.Tsuji@Sun.COM 		}
992*8563SKenjiro.Tsuji@Sun.COM 					if (p_error != no_parse_error) {
993*8563SKenjiro.Tsuji@Sun.COM 						report_error(attr_val, attr);
994*8563SKenjiro.Tsuji@Sun.COM 						error_reported = TRUE;
995*8563SKenjiro.Tsuji@Sun.COM 						break;
9960Sstevel@tonic-gate 					}
9970Sstevel@tonic-gate 				}
998*8563SKenjiro.Tsuji@Sun.COM 				ldap_value_free(vals);
999*8563SKenjiro.Tsuji@Sun.COM 			} else {
1000*8563SKenjiro.Tsuji@Sun.COM 				(void) ldap_get_option(ld,
1001*8563SKenjiro.Tsuji@Sun.COM 				    LDAP_OPT_ERROR_NUMBER, &errnum);
1002*8563SKenjiro.Tsuji@Sun.COM 				if (errnum != LDAP_SUCCESS)
1003*8563SKenjiro.Tsuji@Sun.COM 					p_error = parse_ldap_get_values_error;
10040Sstevel@tonic-gate 			}
1005*8563SKenjiro.Tsuji@Sun.COM 			ldap_memfree(attr);
1006*8563SKenjiro.Tsuji@Sun.COM 			if (p_error != no_parse_error)
1007*8563SKenjiro.Tsuji@Sun.COM 				break;
10080Sstevel@tonic-gate 		}
1009*8563SKenjiro.Tsuji@Sun.COM 	} else {
10100Sstevel@tonic-gate 		errnum = ldap_result2error(ld, resultMsg, FALSE);
10110Sstevel@tonic-gate 		if (errnum != LDAP_SUCCESS)
10120Sstevel@tonic-gate 			p_error = parse_ldap_search_error;
10130Sstevel@tonic-gate 	}
10140Sstevel@tonic-gate 	if (ber != NULL)
10150Sstevel@tonic-gate 		ber_free(ber, 0);
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate 	if (!error_reported && p_error != no_parse_error) {
10180Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10190Sstevel@tonic-gate 	}
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate 	if (p_error != no_parse_error)
10220Sstevel@tonic-gate 		rc = -1;
10230Sstevel@tonic-gate 	return (rc);
10240Sstevel@tonic-gate }
10250Sstevel@tonic-gate 
10260Sstevel@tonic-gate /*
10270Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral
10280Sstevel@tonic-gate  *
10290Sstevel@tonic-gate  *	Retrieves the configuration for a referral url
10300Sstevel@tonic-gate  *
10310Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure, 1 on skip
10320Sstevel@tonic-gate  *
10330Sstevel@tonic-gate  * INPUT:		url		the ldap url
10340Sstevel@tonic-gate  *			__nis_ldap_proxy_info
10350Sstevel@tonic-gate  */
10360Sstevel@tonic-gate 
10370Sstevel@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)10380Sstevel@tonic-gate process_ldap_referral(
10390Sstevel@tonic-gate 	char			*url,
10400Sstevel@tonic-gate 	char			**attrs,
10410Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
10420Sstevel@tonic-gate 	__nis_config_t		*nis_config,
10430Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
10440Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
10450Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
10460Sstevel@tonic-gate {
10470Sstevel@tonic-gate 	LDAPURLDesc	*ludpp		= NULL;
10480Sstevel@tonic-gate 	int		rc;
10490Sstevel@tonic-gate 	LDAP		*ld		= NULL;
10500Sstevel@tonic-gate 	int		errnum;
10510Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
10520Sstevel@tonic-gate 
10530Sstevel@tonic-gate 	if ((rc = ldap_url_parse(url, &ludpp)) != LDAP_SUCCESS)
10540Sstevel@tonic-gate 		return (1);
10550Sstevel@tonic-gate 
10560Sstevel@tonic-gate #ifdef LDAP_URL_OPT_SECURE
10570Sstevel@tonic-gate 	if (ludpp->lud_options & LDAP_URL_OPT_SECURE) {
10580Sstevel@tonic-gate 		if (config_info->tls_method != ssl_tls) {
10590Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10600Sstevel@tonic-gate 			return (1);
10610Sstevel@tonic-gate 		}
10620Sstevel@tonic-gate 	} else {
10630Sstevel@tonic-gate 		if (config_info->tls_method != no_tls) {
10640Sstevel@tonic-gate 			ldap_free_urldesc(ludpp);
10650Sstevel@tonic-gate 			return (1);
10660Sstevel@tonic-gate 		}
10670Sstevel@tonic-gate 	}
10680Sstevel@tonic-gate #endif
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(ludpp->lud_host,
1071*8563SKenjiro.Tsuji@Sun.COM 	    ludpp->lud_port, config_info)) == NULL) {
10720Sstevel@tonic-gate 		ldap_free_urldesc(ludpp);
10730Sstevel@tonic-gate 		return (-1);
10740Sstevel@tonic-gate 	}
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
1077*8563SKenjiro.Tsuji@Sun.COM 	    "objectclass=nisplusLDAPconfig", attrs, 0, &resultMsg);
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
10800Sstevel@tonic-gate 
10810Sstevel@tonic-gate 	if (errnum != LDAP_SUCCESS) {
10820Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
10830Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
10840Sstevel@tonic-gate 		rc = -1;
10850Sstevel@tonic-gate 	} else {
10860Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
1087*8563SKenjiro.Tsuji@Sun.COM 		    nis_config, table_mapping, table_info);
10880Sstevel@tonic-gate 	}
10890Sstevel@tonic-gate 
10900Sstevel@tonic-gate 	ldap_source = NULL;
10910Sstevel@tonic-gate 	(void) ldap_unbind(ld);
10920Sstevel@tonic-gate 	if (resultMsg != NULL)
10930Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
10940Sstevel@tonic-gate 
10950Sstevel@tonic-gate 	return (rc);
10960Sstevel@tonic-gate }
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate /*
10990Sstevel@tonic-gate  * FUNCTION:	process_ldap_referral_msg
11000Sstevel@tonic-gate  *
11010Sstevel@tonic-gate  *	Retrieves the configuration from referred servers
11020Sstevel@tonic-gate  *
11030Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
11040Sstevel@tonic-gate  *
11050Sstevel@tonic-gate  * INPUT:		LDAP		the LDAP connection
11060Sstevel@tonic-gate  *			LDAPMessage	the LDAP message
11070Sstevel@tonic-gate  *			__nis_ldap_proxy_info
11080Sstevel@tonic-gate  */
11090Sstevel@tonic-gate 
11100Sstevel@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)11110Sstevel@tonic-gate process_ldap_referral_msg(
11120Sstevel@tonic-gate 	LDAP			*ld,
11130Sstevel@tonic-gate 	LDAPMessage		*resultMsg,
11140Sstevel@tonic-gate 	char			**attrs,
11150Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11160Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11170Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11180Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11190Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11200Sstevel@tonic-gate {
11210Sstevel@tonic-gate 	int	errCode;
11220Sstevel@tonic-gate 	char	**referralsp	= NULL;
11230Sstevel@tonic-gate 	int	i;
11240Sstevel@tonic-gate 	int	rc;
11250Sstevel@tonic-gate 
11260Sstevel@tonic-gate 	rc = ldap_parse_result(ld, resultMsg, &errCode, NULL, NULL, &referralsp,
1127*8563SKenjiro.Tsuji@Sun.COM 	    NULL, 0);
11280Sstevel@tonic-gate 
11290Sstevel@tonic-gate 	if (rc != LDAP_SUCCESS || errCode != LDAP_REFERRAL) {
11300Sstevel@tonic-gate 		p_error = parse_ldap_get_values_error;
11310Sstevel@tonic-gate 		report_error(ldap_err2string(errCode), 0);
11320Sstevel@tonic-gate 		rc = -1;
11330Sstevel@tonic-gate 	} else {
11340Sstevel@tonic-gate 		for (i = 0; referralsp[i] != NULL; i++) {
11350Sstevel@tonic-gate 			rc = process_ldap_referral(referralsp[i], attrs,
1136*8563SKenjiro.Tsuji@Sun.COM 			    proxy_info, nis_config, table_mapping,
1137*8563SKenjiro.Tsuji@Sun.COM 			    config_info, table_info);
11380Sstevel@tonic-gate 			if (rc <= 0)
11390Sstevel@tonic-gate 				break;
11400Sstevel@tonic-gate 			else
11410Sstevel@tonic-gate 				report_info("Cannot use referral \n",
1142*8563SKenjiro.Tsuji@Sun.COM 				    referralsp[i]);
11430Sstevel@tonic-gate 
11440Sstevel@tonic-gate 		}
11450Sstevel@tonic-gate 		if (rc > 0) {
11460Sstevel@tonic-gate 			p_error = parse_no_available_referrals_error;
11470Sstevel@tonic-gate 			report_error(0, 0);
11480Sstevel@tonic-gate 		}
11490Sstevel@tonic-gate 	}
11500Sstevel@tonic-gate 
11510Sstevel@tonic-gate 	if (referralsp)
11520Sstevel@tonic-gate 		ldap_value_free(referralsp);
11530Sstevel@tonic-gate 
11540Sstevel@tonic-gate 	return (rc);
11550Sstevel@tonic-gate }
11560Sstevel@tonic-gate 
11570Sstevel@tonic-gate /*
11580Sstevel@tonic-gate  * FUNCTION:	parse_ldap_config_dn_attrs
11590Sstevel@tonic-gate  *
11600Sstevel@tonic-gate  *	Parses the information for LDAP from the LDAP profile
11610Sstevel@tonic-gate  *	- the profile object name, the LDAP server, and the
11620Sstevel@tonic-gate  *	authentication method must be specified.
11630Sstevel@tonic-gate  *
11640Sstevel@tonic-gate  * RETURN VALUE:	0 on success, -1 on failure
11650Sstevel@tonic-gate  *
11660Sstevel@tonic-gate  * INPUT:		__nis_ldap_proxy_info
11670Sstevel@tonic-gate  */
11680Sstevel@tonic-gate 
11690Sstevel@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)11700Sstevel@tonic-gate parse_ldap_config_dn_attrs(
11710Sstevel@tonic-gate 	__nis_ldap_proxy_info	*proxy_info,
11720Sstevel@tonic-gate 	__nis_config_t		*nis_config,
11730Sstevel@tonic-gate 	__nis_table_mapping_t	**table_mapping,
11740Sstevel@tonic-gate 	__nis_config_info_t	*config_info,
11750Sstevel@tonic-gate 	__nisdb_table_mapping_t	*table_info)
11760Sstevel@tonic-gate {
11770Sstevel@tonic-gate 	int		rc		= 0;
11780Sstevel@tonic-gate 	LDAP		*ld		= NULL;
11790Sstevel@tonic-gate 	int		errnum;
11800Sstevel@tonic-gate 	char		*ldap_config_attributes[n_config_keys];
11810Sstevel@tonic-gate 	LDAPMessage	*resultMsg	= NULL;
11820Sstevel@tonic-gate 
11830Sstevel@tonic-gate 	/* Determine if properly configured for LDAP lookup */
11840Sstevel@tonic-gate 	if (config_info->auth_method == simple &&
11850Sstevel@tonic-gate 	    config_info->proxy_dn == NULL)
11860Sstevel@tonic-gate 		p_error = parse_no_proxy_dn_error;
11870Sstevel@tonic-gate 	else if (config_info->auth_method ==
11880Sstevel@tonic-gate 	    (auth_method_t)NO_VALUE_SET)
11890Sstevel@tonic-gate 		p_error = parse_no_config_auth_error;
11900Sstevel@tonic-gate 	else if ((config_info->default_servers == NULL) ||
1191*8563SKenjiro.Tsuji@Sun.COM 	    (config_info->default_servers[0] == '\0'))
11920Sstevel@tonic-gate 		p_error = parse_no_config_server_addr;
11930Sstevel@tonic-gate 	if (p_error != no_parse_error) {
11940Sstevel@tonic-gate 		report_error(NULL, NULL);
11950Sstevel@tonic-gate 		return (-1);
11960Sstevel@tonic-gate 	}
11970Sstevel@tonic-gate 
11980Sstevel@tonic-gate 	if (config_info->tls_method == (tls_method_t)NO_VALUE_SET)
11990Sstevel@tonic-gate 		config_info->tls_method = no_tls;
12000Sstevel@tonic-gate 	else if (config_info->tls_method == ssl_tls &&
1201*8563SKenjiro.Tsuji@Sun.COM 	    (config_info->tls_cert_db == NULL ||
1202*8563SKenjiro.Tsuji@Sun.COM 	    *config_info->tls_cert_db == '\0')) {
12030Sstevel@tonic-gate 		p_error = parse_no_config_cert_db;
12040Sstevel@tonic-gate 		report_error(NULL, NULL);
12050Sstevel@tonic-gate 		return (-1);
12060Sstevel@tonic-gate 	}
12070Sstevel@tonic-gate 
12080Sstevel@tonic-gate 	if (verbose)
12090Sstevel@tonic-gate 		report_info(
1210*8563SKenjiro.Tsuji@Sun.COM 		    "Getting configuration from LDAP server(s): ",
1211*8563SKenjiro.Tsuji@Sun.COM 		    config_info->default_servers);
12120Sstevel@tonic-gate 
12130Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12140Sstevel@tonic-gate 	get_attribute_list(proxy_info, nis_config, NULL, table_info,
1215*8563SKenjiro.Tsuji@Sun.COM 	    ldap_config_attributes);
12160Sstevel@tonic-gate 
12170Sstevel@tonic-gate 	if ((ld = connect_to_ldap_config_server(config_info->default_servers, 0,
1218*8563SKenjiro.Tsuji@Sun.COM 	    config_info)) == NULL)
12190Sstevel@tonic-gate 		return (-1);
12200Sstevel@tonic-gate 
12210Sstevel@tonic-gate 	/* Get the attribute values */
12220Sstevel@tonic-gate 	errnum = ldap_search_s(ld, config_info->config_dn, LDAP_SCOPE_BASE,
1223*8563SKenjiro.Tsuji@Sun.COM 	    "objectclass=nisplusLDAPconfig",
1224*8563SKenjiro.Tsuji@Sun.COM 	    ldap_config_attributes, 0, &resultMsg);
12250Sstevel@tonic-gate 	ldap_source = config_info->config_dn;
12260Sstevel@tonic-gate 
12270Sstevel@tonic-gate 	if (errnum == LDAP_REFERRAL) {
12280Sstevel@tonic-gate 		rc = process_ldap_referral_msg(ld, resultMsg,
1229*8563SKenjiro.Tsuji@Sun.COM 		    ldap_config_attributes, proxy_info, nis_config,
1230*8563SKenjiro.Tsuji@Sun.COM 		    table_mapping, config_info, table_info);
12310Sstevel@tonic-gate 	} else if (errnum != LDAP_SUCCESS) {
12320Sstevel@tonic-gate 		p_error = parse_ldap_search_error;
12330Sstevel@tonic-gate 		report_error(ldap_err2string(errnum), 0);
12340Sstevel@tonic-gate 		rc = -1;
12350Sstevel@tonic-gate 	} else {
12360Sstevel@tonic-gate 		rc = process_ldap_config_result(ld, resultMsg, proxy_info,
1237*8563SKenjiro.Tsuji@Sun.COM 		    nis_config, table_mapping, table_info);
12380Sstevel@tonic-gate 	}
12390Sstevel@tonic-gate 
12400Sstevel@tonic-gate 	ldap_source = NULL;
12410Sstevel@tonic-gate 	(void) ldap_unbind(ld);
12420Sstevel@tonic-gate 	if (resultMsg != NULL)
12430Sstevel@tonic-gate 		(void) ldap_msgfree(resultMsg);
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate 	return (rc);
12460Sstevel@tonic-gate }
12470Sstevel@tonic-gate 
12480Sstevel@tonic-gate bool_t
is_cmd_line_option(config_key a_num)12490Sstevel@tonic-gate is_cmd_line_option(config_key a_num)
12500Sstevel@tonic-gate {
12510Sstevel@tonic-gate 	const char *const	*cmdline_options = cmdline_config;
12520Sstevel@tonic-gate 	config_key		attrib_num;
12530Sstevel@tonic-gate 	const char		*begin_s;
12540Sstevel@tonic-gate 	const char		*end_s;
12550Sstevel@tonic-gate 
12560Sstevel@tonic-gate 	if (cmdline_options == NULL)
12570Sstevel@tonic-gate 		return (FALSE);
12580Sstevel@tonic-gate 
12590Sstevel@tonic-gate 	while (*cmdline_options != NULL) {
12600Sstevel@tonic-gate 		attrib_num = get_attrib_num_cmdline(
12610Sstevel@tonic-gate 		    *cmdline_options, &begin_s, &end_s);
12620Sstevel@tonic-gate 		if (attrib_num == a_num)
12630Sstevel@tonic-gate 			break;
12640Sstevel@tonic-gate 		cmdline_options++;
12650Sstevel@tonic-gate 	}
12660Sstevel@tonic-gate 	return (*cmdline_options != NULL);
12670Sstevel@tonic-gate }
12680Sstevel@tonic-gate 
12690Sstevel@tonic-gate /*
12700Sstevel@tonic-gate  * FUNCTION:	get_attribute_list
12710Sstevel@tonic-gate  *
12720Sstevel@tonic-gate  *	Get a list of attributes from the LDAP server that have not yet
12730Sstevel@tonic-gate  *	been gotten. If config_info is NULL, the associated parameters
12740Sstevel@tonic-gate  *	are not needed.
12750Sstevel@tonic-gate  *
12760Sstevel@tonic-gate  * RETURN VALUE:	none
12770Sstevel@tonic-gate  *
12780Sstevel@tonic-gate  * INPUT:		Returns a list of parameters in attributes
12790Sstevel@tonic-gate  *			which is assumed to be of sufficient size.
12800Sstevel@tonic-gate  */
12810Sstevel@tonic-gate 
12820Sstevel@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)12830Sstevel@tonic-gate get_attribute_list(
12840Sstevel@tonic-gate 	const __nis_ldap_proxy_info	*proxy_info,
12850Sstevel@tonic-gate 	const __nis_config_t		*nis_config,
12860Sstevel@tonic-gate 	const __nis_config_info_t	*config_info,
12870Sstevel@tonic-gate 	const __nisdb_table_mapping_t	*table_info,
12880Sstevel@tonic-gate 	char				**attributes)
12890Sstevel@tonic-gate {
12900Sstevel@tonic-gate 	int		n_attrs;
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 	/* Determine which attributes should be retrieved */
12930Sstevel@tonic-gate 	n_attrs = 0;
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 	if (config_info != NULL) {
12960Sstevel@tonic-gate 		if (yp2ldap) {
12970Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
12980Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_DN;
12990Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
13000Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_SERVER_LIST;
13010Sstevel@tonic-gate 			if (config_info->auth_method ==
1302*8563SKenjiro.Tsuji@Sun.COM 			    (auth_method_t)NO_VALUE_SET)
13030Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_AUTH_METHOD;
13040Sstevel@tonic-gate 			if (config_info->tls_method ==
1305*8563SKenjiro.Tsuji@Sun.COM 			    (tls_method_t)NO_VALUE_SET)
13060Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_OPTION;
13070Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13080Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_USER;
13090Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13100Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_PROXY_PASSWD;
13110Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13120Sstevel@tonic-gate 				attributes[n_attrs++] = YP_CONFIG_TLS_CERT_DB;
13130Sstevel@tonic-gate 		} else {
13140Sstevel@tonic-gate 			if (config_info->config_dn == NULL)
13150Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_DN;
13160Sstevel@tonic-gate 			if (config_info->default_servers == NULL)
13170Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_SERVER_LIST;
13180Sstevel@tonic-gate 			if (config_info->auth_method ==
1319*8563SKenjiro.Tsuji@Sun.COM 			    (auth_method_t)NO_VALUE_SET)
13200Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_AUTH_METHOD;
13210Sstevel@tonic-gate 			if (config_info->tls_method ==
1322*8563SKenjiro.Tsuji@Sun.COM 			    (tls_method_t)NO_VALUE_SET)
13230Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_OPTION;
13240Sstevel@tonic-gate 			if (config_info->proxy_dn == NULL)
13250Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_USER;
13260Sstevel@tonic-gate 			if (config_info->proxy_passwd == NULL)
13270Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_PROXY_PASSWD;
13280Sstevel@tonic-gate 			if (config_info->tls_cert_db == NULL)
13290Sstevel@tonic-gate 				attributes[n_attrs++] = CONFIG_TLS_CERT_DB;
13300Sstevel@tonic-gate 		}
13310Sstevel@tonic-gate 	} else {
13320Sstevel@tonic-gate 		if (yp2ldap) {
13330Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DOMAIN_CONTEXT;
13340Sstevel@tonic-gate 			attributes[n_attrs++] = YPPASSWDD_DOMAINS;
13350Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DB_ID_MAP;
13360Sstevel@tonic-gate 			attributes[n_attrs++] = YP_COMMENT_CHAR;
13370Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MAP_FLAGS;
13380Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ENTRY_TTL;
13390Sstevel@tonic-gate 			attributes[n_attrs++] = YP_NAME_FIELDS;
13400Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SPLIT_FIELD;
13410Sstevel@tonic-gate 			attributes[n_attrs++] = YP_REPEATED_FIELD_SEPARATORS;
13420Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_OBJECT_DN;
13430Sstevel@tonic-gate 			attributes[n_attrs++] = NIS_TO_LDAP_MAP;
13440Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NIS_MAP;
13450Sstevel@tonic-gate 		} else {
13460Sstevel@tonic-gate 			attributes[n_attrs++] = DB_ID_MAP;
13470Sstevel@tonic-gate 			attributes[n_attrs++] = ENTRY_TTL;
13480Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_OBJECT_DN;
13490Sstevel@tonic-gate 			attributes[n_attrs++] = NISPLUS_TO_LDAP_MAP;
13500Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_TO_NISPLUS_MAP;
13510Sstevel@tonic-gate 		}
13520Sstevel@tonic-gate 	}
13530Sstevel@tonic-gate 
13540Sstevel@tonic-gate 	if (yp2ldap) {
13550Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
13560Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
13570Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
13580Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
13590Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
13600Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_OPTION;
13610Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
13620Sstevel@tonic-gate 			attributes[n_attrs++] = YP_TLS_CERT_DB;
13630Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
13640Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
13650Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
13660Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_USER;
13670Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
13680Sstevel@tonic-gate 			attributes[n_attrs++] = YP_PROXY_PASSWD;
13690Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
13700Sstevel@tonic-gate 			attributes[n_attrs++] = YP_LDAP_BASE_DOMAIN;
13710Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
1372*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
13730Sstevel@tonic-gate 			attributes[n_attrs++] = YP_BIND_TIMEOUT;
13740Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
1375*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
13760Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIMEOUT;
13770Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
1378*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
13790Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MODIFY_TIMEOUT;
13800Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
13810Sstevel@tonic-gate 			attributes[n_attrs++] = YP_ADD_TIMEOUT;
13820Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
1383*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
13840Sstevel@tonic-gate 			attributes[n_attrs++] = YP_DELETE_TIMEOUT;
13850Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
13860Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_TIME_LIMIT;
13870Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
13880Sstevel@tonic-gate 			attributes[n_attrs++] = YP_SEARCH_SIZE_LIMIT;
13890Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
1390*8563SKenjiro.Tsuji@Sun.COM 		    (follow_referral_t)NO_VALUE_SET)
13910Sstevel@tonic-gate 			attributes[n_attrs++] = YP_FOLLOW_REFERRAL;
13920Sstevel@tonic-gate 
13930Sstevel@tonic-gate 		if (table_info->retrieveError ==
1394*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_retrieve_error_t)NO_VALUE_SET)
13950Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETRIEVE_ERROR_ACTION;
13960Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
13970Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_ATTEMPTS;
13980Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
1399*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14000Sstevel@tonic-gate 			attributes[n_attrs++] = YP_RETREIVE_ERROR_TIMEOUT;
14010Sstevel@tonic-gate 		if (table_info->storeError ==
1402*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_store_error_t)NO_VALUE_SET)
14030Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ACTION;
14040Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14050Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_ATTEMPTS;
14060Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
1407*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14080Sstevel@tonic-gate 			attributes[n_attrs++] = YP_STORE_ERROR_TIMEOUT;
14090Sstevel@tonic-gate 		if (table_info->refreshError ==
1410*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_refresh_error_t)NO_VALUE_SET)
14110Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14120Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14130Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14140Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
1415*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14160Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14170Sstevel@tonic-gate 		if (table_info->matchFetch ==
1418*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_match_fetch_t)NO_VALUE_SET)
14190Sstevel@tonic-gate 			attributes[n_attrs++] = YP_MATCH_FETCH;
14200Sstevel@tonic-gate 	} else {
14210Sstevel@tonic-gate 		if (proxy_info->default_servers == NULL)
14220Sstevel@tonic-gate 			attributes[n_attrs++] = PREFERRED_SERVERS;
14230Sstevel@tonic-gate 		if (proxy_info->auth_method == (auth_method_t)NO_VALUE_SET)
14240Sstevel@tonic-gate 			attributes[n_attrs++] = AUTH_METHOD;
14250Sstevel@tonic-gate 		if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
14260Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_OPTION;
14270Sstevel@tonic-gate 		if (proxy_info->tls_cert_db == NULL)
14280Sstevel@tonic-gate 			attributes[n_attrs++] = TLS_CERT_DB;
14290Sstevel@tonic-gate 		if (proxy_info->default_search_base == NULL)
14300Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_BASE;
14310Sstevel@tonic-gate 		if (proxy_info->proxy_dn == NULL)
14320Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_USER;
14330Sstevel@tonic-gate 		if (proxy_info->proxy_passwd == NULL)
14340Sstevel@tonic-gate 			attributes[n_attrs++] = PROXY_PASSWD;
14350Sstevel@tonic-gate 		if (proxy_info->default_nis_domain == NULL)
14360Sstevel@tonic-gate 			attributes[n_attrs++] = LDAP_BASE_DOMAIN;
14370Sstevel@tonic-gate 		if (proxy_info->bind_timeout.tv_sec ==
1438*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14390Sstevel@tonic-gate 			attributes[n_attrs++] = BIND_TIMEOUT;
14400Sstevel@tonic-gate 		if (proxy_info->search_timeout.tv_sec ==
1441*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14420Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIMEOUT;
14430Sstevel@tonic-gate 		if (proxy_info->modify_timeout.tv_sec ==
1444*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14450Sstevel@tonic-gate 			attributes[n_attrs++] = MODIFY_TIMEOUT;
14460Sstevel@tonic-gate 		if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
14470Sstevel@tonic-gate 			attributes[n_attrs++] = ADD_TIMEOUT;
14480Sstevel@tonic-gate 		if (proxy_info->delete_timeout.tv_sec ==
1449*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14500Sstevel@tonic-gate 			attributes[n_attrs++] = DELETE_TIMEOUT;
14510Sstevel@tonic-gate 		if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
14520Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_TIME_LIMIT;
14530Sstevel@tonic-gate 		if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
14540Sstevel@tonic-gate 			attributes[n_attrs++] = SEARCH_SIZE_LIMIT;
14550Sstevel@tonic-gate 		if (proxy_info->follow_referral ==
1456*8563SKenjiro.Tsuji@Sun.COM 		    (follow_referral_t)NO_VALUE_SET)
14570Sstevel@tonic-gate 			attributes[n_attrs++] = FOLLOW_REFERRAL;
14580Sstevel@tonic-gate 
14590Sstevel@tonic-gate 		if (table_info->retrieveError ==
1460*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_retrieve_error_t)NO_VALUE_SET)
14610Sstevel@tonic-gate 			attributes[n_attrs++] = RETRIEVE_ERROR_ACTION;
14620Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
14630Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_ATTEMPTS;
14640Sstevel@tonic-gate 		if (table_info->retrieveErrorRetry.timeout ==
1465*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14660Sstevel@tonic-gate 			attributes[n_attrs++] = RETREIVE_ERROR_TIMEOUT;
14670Sstevel@tonic-gate 		if (table_info->storeError ==
1468*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_store_error_t)NO_VALUE_SET)
14690Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ACTION;
14700Sstevel@tonic-gate 		if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
14710Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_ATTEMPTS;
14720Sstevel@tonic-gate 		if (table_info->storeErrorRetry.timeout ==
1473*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14740Sstevel@tonic-gate 			attributes[n_attrs++] = STORE_ERROR_TIMEOUT;
14750Sstevel@tonic-gate 		if (table_info->refreshError ==
1476*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_refresh_error_t)NO_VALUE_SET)
14770Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ACTION;
14780Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
14790Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_ATTEMPTS;
14800Sstevel@tonic-gate 		if (table_info->refreshErrorRetry.timeout ==
1481*8563SKenjiro.Tsuji@Sun.COM 		    (time_t)NO_VALUE_SET)
14820Sstevel@tonic-gate 			attributes[n_attrs++] = REFRESH_ERROR_TIMEOUT;
14830Sstevel@tonic-gate 		if (table_info->matchFetch ==
1484*8563SKenjiro.Tsuji@Sun.COM 		    (__nis_match_fetch_t)NO_VALUE_SET)
14850Sstevel@tonic-gate 			attributes[n_attrs++] = MATCH_FETCH;
14860Sstevel@tonic-gate 	}
14870Sstevel@tonic-gate 
14880Sstevel@tonic-gate 	switch (nis_config->initialUpdate) {
1489*8563SKenjiro.Tsuji@Sun.COM 	case (__nis_initial_update_t)NO_VALUE_SET:
1490*8563SKenjiro.Tsuji@Sun.COM 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
1491*8563SKenjiro.Tsuji@Sun.COM 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
1492*8563SKenjiro.Tsuji@Sun.COM 		break;
1493*8563SKenjiro.Tsuji@Sun.COM 	case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION:
1494*8563SKenjiro.Tsuji@Sun.COM 	case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION:
1495*8563SKenjiro.Tsuji@Sun.COM 		attributes[n_attrs++] = INITIAL_UPDATE_ACTION;
1496*8563SKenjiro.Tsuji@Sun.COM 		break;
1497*8563SKenjiro.Tsuji@Sun.COM 	case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE:
1498*8563SKenjiro.Tsuji@Sun.COM 	case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE:
1499*8563SKenjiro.Tsuji@Sun.COM 		attributes[n_attrs++] = INITIAL_UPDATE_ONLY;
1500*8563SKenjiro.Tsuji@Sun.COM 		break;
15010Sstevel@tonic-gate 	}
15020Sstevel@tonic-gate 
15030Sstevel@tonic-gate 	if (nis_config->threadCreationError ==
15040Sstevel@tonic-gate 	    (__nis_thread_creation_error_t)NO_VALUE_SET)
15050Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ACTION;
15060Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.attempts == NO_VALUE_SET)
15070Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_ATTEMPTS;
15080Sstevel@tonic-gate 	if (nis_config->threadCreationErrorTimeout.timeout ==
1509*8563SKenjiro.Tsuji@Sun.COM 	    (time_t)NO_VALUE_SET)
15100Sstevel@tonic-gate 		attributes[n_attrs++] = THREAD_CREATE_ERROR_TIMEOUT;
15110Sstevel@tonic-gate 	if (nis_config->dumpError == (__nis_dump_error_t)NO_VALUE_SET)
15120Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ACTION;
15130Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.attempts == NO_VALUE_SET)
15140Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_ATTEMPTS;
15150Sstevel@tonic-gate 	if (nis_config->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET)
15160Sstevel@tonic-gate 		attributes[n_attrs++] = DUMP_ERROR_TIMEOUT;
15170Sstevel@tonic-gate 	if (nis_config->resyncService == (__nis_resync_service_t)NO_VALUE_SET)
15180Sstevel@tonic-gate 		attributes[n_attrs++] = RESYNC;
15190Sstevel@tonic-gate 	if (nis_config->updateBatching ==
1520*8563SKenjiro.Tsuji@Sun.COM 	    (__nis_update_batching_t)NO_VALUE_SET)
15210Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING;
15220Sstevel@tonic-gate 	if (nis_config->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET)
15230Sstevel@tonic-gate 		attributes[n_attrs++] = UPDATE_BATCHING_TIMEOUT;
15240Sstevel@tonic-gate 	if (nis_config->numberOfServiceThreads == (int)NO_VALUE_SET)
15250Sstevel@tonic-gate 		attributes[n_attrs++] = NUMBER_THEADS;
15260Sstevel@tonic-gate 	if (nis_config->emulate_yp == (int)NO_VALUE_SET)
15270Sstevel@tonic-gate 		attributes[n_attrs++] = YP_EMULATION;
15280Sstevel@tonic-gate 
15290Sstevel@tonic-gate 	/* maxRPCRecordSize is not configurable through LDAP profiles */
15300Sstevel@tonic-gate 	if (nis_config->maxRPCRecordSize == (int)NO_VALUE_SET)
15310Sstevel@tonic-gate 		attributes[n_attrs++] = MAX_RPC_RECSIZE;
15320Sstevel@tonic-gate 
15330Sstevel@tonic-gate 	attributes[n_attrs++] = NULL;
15340Sstevel@tonic-gate }
15350Sstevel@tonic-gate 
15360Sstevel@tonic-gate /*
15370Sstevel@tonic-gate  *	Notes on adding new attributes
15380Sstevel@tonic-gate  *	1. Determine where the attribute value will be saved
15390Sstevel@tonic-gate  *	    Currently, the following structures are defined:
15400Sstevel@tonic-gate  *		__nis_config_info_t	config_info
15410Sstevel@tonic-gate  *		__nis_ldap_proxy_info	proxyInfo
15420Sstevel@tonic-gate  *		__nis_config_t		ldapConfig
15430Sstevel@tonic-gate  *		__nisdb_table_mapping_t	ldapDBTableMapping
15440Sstevel@tonic-gate  *		__nis_table_mapping_t	ldapTableMapping
15450Sstevel@tonic-gate  *	    or add a new structure or variable - this will require
15460Sstevel@tonic-gate  *	    more code.
15470Sstevel@tonic-gate  *	2. Initialize the value to a known unconfigured value.
15480Sstevel@tonic-gate  *	    This can be done in initialize_parse_structs or
15490Sstevel@tonic-gate  *	    parse_ldap_migration.
15500Sstevel@tonic-gate  *	3. In the header file nis_parse_ldap_conf.h, add the name
15510Sstevel@tonic-gate  *	    of the attribute. (Currently, the attribute name is assumed
15520Sstevel@tonic-gate  *	    to be the same for the command line, the preference file,
15530Sstevel@tonic-gate  *	    and LDAP.) The names are grouped logically. Add a corresponding
15540Sstevel@tonic-gate  *	    config_key to the enum. Note that position in this file is
15550Sstevel@tonic-gate  *	    essential because the macros such as IS_BIND_INFO depend on
15560Sstevel@tonic-gate  *	    the sequence. The corresponding macro (IS_CONFIG_KEYWORD,
15570Sstevel@tonic-gate  *	    IS_BIND_INFO, or IS_OPER_INFO) may need to be adjusted. These
15580Sstevel@tonic-gate  *	    are used to partition the attributes into smaller chunks.
15590Sstevel@tonic-gate  *	4. Add the correspond entry to the keyword_lookup array in
15600Sstevel@tonic-gate  *	    nis_parse_ldap_attr.c, which is used to determine the config_key
15610Sstevel@tonic-gate  *	    from the corresponding key word.
15620Sstevel@tonic-gate  *	5. Add the attribute to the list of attributes to retrieve from
15630Sstevel@tonic-gate  *	    the LDAP server if no value has been set in the function
15640Sstevel@tonic-gate  *	    parse_ldap_config_dn_attrs. (This assumes that the attribute
15650Sstevel@tonic-gate  *	    is not used to get the configuration from the LDAP server.)
15660Sstevel@tonic-gate  *	6. Add logic to parse the individual attribute in
15670Sstevel@tonic-gate  *	    add_config_attribute, add_bind_attribute,
15680Sstevel@tonic-gate  *	    add_operation_attribute, or add_mapping_attribute depending
15690Sstevel@tonic-gate  *	    which group of attributes the added attribute belongs to.
15700Sstevel@tonic-gate  *	7. In set_default_values, if the attribute value has not been set, set
15710Sstevel@tonic-gate  *	    the default value. If any additional fixup is needed depending
15720Sstevel@tonic-gate  *	    on other configuration values, it should be done here.
15730Sstevel@tonic-gate  *	8. If an attribute name is a subset of another, parse_ldap_default_conf
15740Sstevel@tonic-gate  *          should be modified.
15750Sstevel@tonic-gate  */
1576