xref: /titanic_50/usr/src/lib/libnisdb/yptol/map_conv.c (revision a87701e9837f8a9ee9e4c4d3186295c0e29f743f)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*a87701e9SGary Mills  * Copyright 2015 Gary Mills
247c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * DESCRIPTION: Contains functions relating to movement of entire maps.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <syslog.h>
347c478bd9Sstevel@tonic-gate #include <ndbm.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include "ypsym.h"
377c478bd9Sstevel@tonic-gate #include "ypdefs.h"
387c478bd9Sstevel@tonic-gate #include "shim.h"
397c478bd9Sstevel@tonic-gate #include "yptol.h"
407c478bd9Sstevel@tonic-gate #include "../ldap_util.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Switch on parts of ypdefs.h
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate USE_YPDBPATH
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Decs
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate void add_separator(char *);
517c478bd9Sstevel@tonic-gate suc_code dump_domain_to_dit(char *, bool_t);
527c478bd9Sstevel@tonic-gate suc_code dump_map_to_dit(char *, char *, bool_t);
537c478bd9Sstevel@tonic-gate suc_code dump_maps_to_dit(bool_t);
547c478bd9Sstevel@tonic-gate suc_code dump_dit_to_map();
557c478bd9Sstevel@tonic-gate suc_code dump_dit_to_maps();
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * FUNCTION :	dump_maps_to_dit()
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Dump all the OLD STYLE NIS maps into the DIT.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  *		Since the DIT is not yet set up details about which maps and
637c478bd9Sstevel@tonic-gate  *		domains exist are gathered from the N2L config file and the
647c478bd9Sstevel@tonic-gate  *		existing map files.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * GIVEN :	Flag indicating if containers and domains should be set up.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * RETURNS :	Success code
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate suc_code
dump_maps_to_dit(bool_t init_containers)717c478bd9Sstevel@tonic-gate dump_maps_to_dit(bool_t init_containers)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	char **dom_list;
747c478bd9Sstevel@tonic-gate 	int num_doms, i;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	num_doms = get_mapping_domain_list(&dom_list);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* Dump all domains in list */
797c478bd9Sstevel@tonic-gate 	for (i = 0; i < num_doms; i++) {
807c478bd9Sstevel@tonic-gate 		if (FAILURE == dump_domain_to_dit(dom_list[i], init_containers))
817c478bd9Sstevel@tonic-gate 			return (FAILURE);
827c478bd9Sstevel@tonic-gate 	}
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	return (SUCCESS);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * FUNCTION :	dump_domain_to_dit()
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Dumps all maps in one domain into the DIT
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * GIVEN :	Name of the domain
937c478bd9Sstevel@tonic-gate  *		Flag indicating if containers and domains should be set up.
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  * RETURNS :	SUCCESS = domain completely dumped
967c478bd9Sstevel@tonic-gate  *		FAILURE = domain not completely dumped
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate suc_code
dump_domain_to_dit(char * dom_name,bool_t init_containers)1007c478bd9Sstevel@tonic-gate dump_domain_to_dit(char *dom_name, bool_t init_containers)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	char **map_list;
1037c478bd9Sstevel@tonic-gate 	int	i;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	/* Set up nis domain object */
1067c478bd9Sstevel@tonic-gate 	if (SUCCESS != make_nis_domain(dom_name, init_containers)) {
1077c478bd9Sstevel@tonic-gate 		if (init_containers)
1087c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
1097c478bd9Sstevel@tonic-gate 			"Could not make nisDomain object for %s", dom_name);
1107c478bd9Sstevel@tonic-gate 		else
1117c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
1127c478bd9Sstevel@tonic-gate 			"Problem detected with nisDomain object for %s",
1137c478bd9Sstevel@tonic-gate 								dom_name);
1147c478bd9Sstevel@tonic-gate 		return (FAILURE);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/* Get list of maps from mapping file */
1187c478bd9Sstevel@tonic-gate 	map_list = get_mapping_map_list(dom_name);
1197c478bd9Sstevel@tonic-gate 	if (NULL == map_list) {
1207c478bd9Sstevel@tonic-gate 		logmsg(MSG_NOTIMECHECK, LOG_ERR,
1217c478bd9Sstevel@tonic-gate 			"Could not get map list for %s", dom_name);
1227c478bd9Sstevel@tonic-gate 		return (FAILURE);
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	for (i = 0; NULL != map_list[i]; i++) {
1267c478bd9Sstevel@tonic-gate 		dump_map_to_dit(map_list[i], dom_name, init_containers);
1277c478bd9Sstevel@tonic-gate 	}
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	free_map_list(map_list);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	return (SUCCESS);
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * FUNCTION :	dump_map_to_dit()
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Dump a OLD STYLE NIS map into the DIT.
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  * GIVEN :	Name of map (not fully qualified)
1407c478bd9Sstevel@tonic-gate  *		Name of domain
1417c478bd9Sstevel@tonic-gate  *		Flag indicating if containers should be set up.
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * RETURNS :	SUCCESS = Map copy completed
1447c478bd9Sstevel@tonic-gate  *		FAILURE = Map copy not completed
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate suc_code
dump_map_to_dit(char * map_name,char * domain,bool_t init_containers)1477c478bd9Sstevel@tonic-gate dump_map_to_dit(char *map_name, char *domain, bool_t init_containers)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate 	char *myself = "dump_map_to_dit";
1507c478bd9Sstevel@tonic-gate 	DBM *dbm;
1517c478bd9Sstevel@tonic-gate 	datum key;
1527c478bd9Sstevel@tonic-gate 	datum value;
1537c478bd9Sstevel@tonic-gate 	char *map_path;		/* Qualified map name */
1547c478bd9Sstevel@tonic-gate 	int entry_count;
1557c478bd9Sstevel@tonic-gate 	int next_print;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	printf("Copying map \"%s\", domain \"%s\", to LDAP.\n",
1587c478bd9Sstevel@tonic-gate 							map_name, domain);
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	/* Create the NIS container */
1617c478bd9Sstevel@tonic-gate 	if (SUCCESS != make_nis_container(map_name, domain, init_containers)) {
1627c478bd9Sstevel@tonic-gate 		if (init_containers)
1637c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
1647c478bd9Sstevel@tonic-gate 				"Could not make container for %s %s",
1657c478bd9Sstevel@tonic-gate 				map_name, domain);
1667c478bd9Sstevel@tonic-gate 		else
1677c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
1687c478bd9Sstevel@tonic-gate 				"Problem detected with container for %s %s",
1697c478bd9Sstevel@tonic-gate 				map_name, domain);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 		return (FAILURE);
1727c478bd9Sstevel@tonic-gate 	}
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	/* Make up fully qualified map name */
1757c478bd9Sstevel@tonic-gate 	map_path = (char *)am(myself, strlen(domain) + strlen(map_name) +
1767c478bd9Sstevel@tonic-gate 						ypdbpath_sz + 3);
1777c478bd9Sstevel@tonic-gate 	if (NULL == map_path) {
1787c478bd9Sstevel@tonic-gate 		logmsg(MSG_NOMEM, LOG_ERR,
1797c478bd9Sstevel@tonic-gate 			"Could not alloc memory for %s %s", map_name, domain);
1807c478bd9Sstevel@tonic-gate 		return (FAILURE);
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 	strcpy(map_path, ypdbpath);
1837c478bd9Sstevel@tonic-gate 	add_separator(map_path);
1847c478bd9Sstevel@tonic-gate 	strcat(map_path, domain);
1857c478bd9Sstevel@tonic-gate 	add_separator(map_path);
1867c478bd9Sstevel@tonic-gate 	strcat(map_path, map_name);
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	/* Open the DBM file. Use real dbm call */
1897c478bd9Sstevel@tonic-gate 	dbm = dbm_open(map_path, O_RDONLY, 0644);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/* Finished with full name */
1927c478bd9Sstevel@tonic-gate 	sfree(map_path);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	if (NULL == dbm) {
1957c478bd9Sstevel@tonic-gate 		/*
1967c478bd9Sstevel@tonic-gate 		 * This map probably didn't exist. No problem, user may be
1977c478bd9Sstevel@tonic-gate 		 * going to populate container using LDAP.
1987c478bd9Sstevel@tonic-gate 		 */
1997c478bd9Sstevel@tonic-gate 		return (SUCCESS);
2007c478bd9Sstevel@tonic-gate 	}
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * N2L has no lock for old style maps. No problem ypserv -i is the
2047c478bd9Sstevel@tonic-gate 	 * only thing that accesses them.
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	/* For all entries in file */
2087c478bd9Sstevel@tonic-gate 	for (key = dbm_firstkey(dbm), next_print = PRINT_FREQ, entry_count = 1;
2097c478bd9Sstevel@tonic-gate 		NULL != key.dptr; key = dbm_nextkey(dbm), entry_count ++) {
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 		/* Don't write zero length keys */
2127c478bd9Sstevel@tonic-gate 		if (0 == key.dsize) {
2137c478bd9Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_INFO,
2147c478bd9Sstevel@tonic-gate 			"Zero length key ignored in %s %s", map_name, domain);
2157c478bd9Sstevel@tonic-gate 			continue;
2167c478bd9Sstevel@tonic-gate 		}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 		/* Don't write 'special' nis entries */
2197c478bd9Sstevel@tonic-gate 		if (is_special_key(&key))
2207c478bd9Sstevel@tonic-gate 			continue;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 		/* Get entry */
2237c478bd9Sstevel@tonic-gate 		value = dbm_fetch(dbm, key);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 		/* Copy entry to DIT */
2267c478bd9Sstevel@tonic-gate 		if (SUCCESS != write_to_dit(map_name, domain, key, value,
2277c478bd9Sstevel@tonic-gate 								TRUE, TRUE))
2287c478bd9Sstevel@tonic-gate 			/* Syslog will have already been done */
2297c478bd9Sstevel@tonic-gate 			break;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 		/* If necessary print a progress report */
2327c478bd9Sstevel@tonic-gate 		if (entry_count >= next_print) {
2337c478bd9Sstevel@tonic-gate 			printf("%d entries processed.\n", entry_count);
2347c478bd9Sstevel@tonic-gate 			next_print *= 2;
2357c478bd9Sstevel@tonic-gate 		}
2367c478bd9Sstevel@tonic-gate 	}
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	dbm_close(dbm);
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	return (SUCCESS);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * FUNCTION :	dump_dit_to_maps()
2457c478bd9Sstevel@tonic-gate  *
2467c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Dumps the contents of the DIT into the NEW STYLE NIS maps. If
2477c478bd9Sstevel@tonic-gate  *		the maps, or their TTL files do not exist creates them.
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  *		Since we are now treating the DIT as authoritative details of
2507c478bd9Sstevel@tonic-gate  *		which domains and maps exist are gathered from the DIT.
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  * GIVEN :	Nothing
2537c478bd9Sstevel@tonic-gate  *
2547c478bd9Sstevel@tonic-gate  * RETURNS :	Success code
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate suc_code
dump_dit_to_maps()2577c478bd9Sstevel@tonic-gate dump_dit_to_maps()
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate 	char **dom_list;
2607c478bd9Sstevel@tonic-gate 	int dom_count;
2617c478bd9Sstevel@tonic-gate 	char *dom_path;
2627c478bd9Sstevel@tonic-gate 	char **map_list;
2637c478bd9Sstevel@tonic-gate 	int i, j;
2647c478bd9Sstevel@tonic-gate 	char *myself = "dump_dit_to_maps";
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	/* For all domain objects in DIT */
2677c478bd9Sstevel@tonic-gate 	dom_count = get_mapping_domain_list(&dom_list);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	if (0 == dom_count) {
2707c478bd9Sstevel@tonic-gate 		/* No problem, maybe no domains */
2717c478bd9Sstevel@tonic-gate 		return (SUCCESS);
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	/* Dump all domains in list */
2757c478bd9Sstevel@tonic-gate 	for (i = 0; i < dom_count; i++) {
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		/* If necessary create domain directory */
2787c478bd9Sstevel@tonic-gate 		dom_path = (char *)am(myself, ypdbpath_sz +
2797c478bd9Sstevel@tonic-gate 						strlen(dom_list[i]) + 2);
2807c478bd9Sstevel@tonic-gate 		if (NULL == dom_path) {
2817c478bd9Sstevel@tonic-gate 			return (FAILURE);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		strcpy(dom_path, ypdbpath);
2857c478bd9Sstevel@tonic-gate 		strcat(dom_path, "/");
2867c478bd9Sstevel@tonic-gate 		strcat(dom_path, dom_list[i]);
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		if (0 != mkdir(dom_path, 0644)) {
2897c478bd9Sstevel@tonic-gate 			/* If dir exists fine. Just use it */
2907c478bd9Sstevel@tonic-gate 			if (EEXIST != errno) {
2917c478bd9Sstevel@tonic-gate 				logmsg(MSG_NOTIMECHECK, LOG_ERR,
2927c478bd9Sstevel@tonic-gate 				"Could not make create domain directory %s",
2937c478bd9Sstevel@tonic-gate 								dom_path);
2947c478bd9Sstevel@tonic-gate 				sfree(dom_path);
2957c478bd9Sstevel@tonic-gate 			}
2967c478bd9Sstevel@tonic-gate 		}
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 		sfree(dom_path);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		/* Get list of maps for this domain */
3017c478bd9Sstevel@tonic-gate 		map_list = get_mapping_map_list(dom_list[i]);
3027c478bd9Sstevel@tonic-gate 		if (NULL == map_list) {
3037c478bd9Sstevel@tonic-gate 			/* No problem. Just no maps in this domain */
3047c478bd9Sstevel@tonic-gate 			continue;
3057c478bd9Sstevel@tonic-gate 		}
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 		/* For all maps in domain */
3087c478bd9Sstevel@tonic-gate 		for (j = 0; map_list[j] != NULL; j++) {
3097c478bd9Sstevel@tonic-gate 			/* A normal map update will initialize it. */
3107c478bd9Sstevel@tonic-gate 			if (FAILURE == dump_dit_to_map(map_list[j],
3117c478bd9Sstevel@tonic-gate 							dom_list[i])) {
3127c478bd9Sstevel@tonic-gate 				free_map_list(map_list);
3137c478bd9Sstevel@tonic-gate 				return (FAILURE);
3147c478bd9Sstevel@tonic-gate 			}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 			/* If we have a netgroup also generate netgroup.byxxx */
3177c478bd9Sstevel@tonic-gate 			if (0 == strcmp(map_list[j], NETGROUP_MAP)) {
3187c478bd9Sstevel@tonic-gate 				if (FAILURE == dump_dit_to_map(NETGROUP_BYHOST,
3197c478bd9Sstevel@tonic-gate 								dom_list[i])) {
3207c478bd9Sstevel@tonic-gate 					free_map_list(map_list);
3217c478bd9Sstevel@tonic-gate 					return (FAILURE);
3227c478bd9Sstevel@tonic-gate 				}
3237c478bd9Sstevel@tonic-gate 				if (FAILURE == dump_dit_to_map(NETGROUP_BYUSER,
3247c478bd9Sstevel@tonic-gate 								dom_list[i])) {
3257c478bd9Sstevel@tonic-gate 					free_map_list(map_list);
3267c478bd9Sstevel@tonic-gate 					return (FAILURE);
3277c478bd9Sstevel@tonic-gate 				}
3287c478bd9Sstevel@tonic-gate 			}
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 		free_map_list(map_list);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	return (SUCCESS);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  * FUNCTION :	dump_dit_to_map()
3377c478bd9Sstevel@tonic-gate  *
3387c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Dumps the contents of the DIT into one NEW STYLE NIS map. If
3397c478bd9Sstevel@tonic-gate  *		the map, or its TTL file does not exist creates them.
3407c478bd9Sstevel@tonic-gate  *
3417c478bd9Sstevel@tonic-gate  *		This is the same operation as is carried out when updating a
3427c478bd9Sstevel@tonic-gate  *		map that has timed out. As a result we can call the normal
3437c478bd9Sstevel@tonic-gate  *		update function.
3447c478bd9Sstevel@tonic-gate  *
3457c478bd9Sstevel@tonic-gate  *
3467c478bd9Sstevel@tonic-gate  * GIVEN :	Map name (unqualified)
3477c478bd9Sstevel@tonic-gate  *		Domain name.
3487c478bd9Sstevel@tonic-gate  *
3497c478bd9Sstevel@tonic-gate  * RETURNS :	SUCCESS = Map copy complete
3507c478bd9Sstevel@tonic-gate  *		FAILURE = Problems
3517c478bd9Sstevel@tonic-gate  */
3527c478bd9Sstevel@tonic-gate suc_code
dump_dit_to_map(char * map_name,char * domain)3537c478bd9Sstevel@tonic-gate dump_dit_to_map(char *map_name, char *domain)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate 	char *myself = "dump_dit_to_map";
3567c478bd9Sstevel@tonic-gate 	map_ctrl map;
3577c478bd9Sstevel@tonic-gate 	char 	*map_path;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	printf("Copying LDAP data to map \"%s\", domain \"%s\".\n",
3607c478bd9Sstevel@tonic-gate 							map_name, domain);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	/*
3637c478bd9Sstevel@tonic-gate 	 * To call update_map_from_dit() we need an initialized map_ctrl.
3647c478bd9Sstevel@tonic-gate 	 * The easiest way to get this is to generate a full path to the new
3657c478bd9Sstevel@tonic-gate 	 * map and then call map_ctrl_init().
3667c478bd9Sstevel@tonic-gate 	 */
3677c478bd9Sstevel@tonic-gate 	map_path = (char *)am(myself, ypdbpath_sz + strlen(map_name) +
3687c478bd9Sstevel@tonic-gate 				strlen(domain) + strlen(NTOL_PREFIX) + 3);
3697c478bd9Sstevel@tonic-gate 	if (NULL == map_path)
3707c478bd9Sstevel@tonic-gate 		return (FAILURE);
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	strcpy(map_path, ypdbpath);
3737c478bd9Sstevel@tonic-gate 	add_separator(map_path);
3747c478bd9Sstevel@tonic-gate 	strcat(map_path, domain);
3757c478bd9Sstevel@tonic-gate 	add_separator(map_path);
3767c478bd9Sstevel@tonic-gate 	strcat(map_path, NTOL_PREFIX);
3777c478bd9Sstevel@tonic-gate 	strcat(map_path, map_name);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	if (FAILURE == map_ctrl_init(&map, map_path)) {
3807c478bd9Sstevel@tonic-gate 		sfree(map_path);
3817c478bd9Sstevel@tonic-gate 		return (FAILURE);
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	sfree(map_path);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	/*
3877c478bd9Sstevel@tonic-gate 	 * This is called before anything else is running so don't need to
3887c478bd9Sstevel@tonic-gate 	 * do normal update lock.
3897c478bd9Sstevel@tonic-gate 	 */
3907c478bd9Sstevel@tonic-gate 	return (update_map_from_dit(&map, TRUE));
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /*
3947c478bd9Sstevel@tonic-gate  * FUNCTION :	add_seperator()
3957c478bd9Sstevel@tonic-gate  *
3967c478bd9Sstevel@tonic-gate  * DESCRIPTION:	Adds a file separator to a string (which must already be big
3977c478bd9Sstevel@tonic-gate  *		enough.)
3987c478bd9Sstevel@tonic-gate  *
3997c478bd9Sstevel@tonic-gate  * GIVEN :	Pointer to the string
4007c478bd9Sstevel@tonic-gate  *
4017c478bd9Sstevel@tonic-gate  * RETURNS :	Nothing
4027c478bd9Sstevel@tonic-gate  */
4037c478bd9Sstevel@tonic-gate void
add_separator(char * str)4047c478bd9Sstevel@tonic-gate add_separator(char *str)
4057c478bd9Sstevel@tonic-gate {
4067c478bd9Sstevel@tonic-gate 	char *p;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	p = str + strlen(str);
4097c478bd9Sstevel@tonic-gate 	*p = SEP_CHAR;
4107c478bd9Sstevel@tonic-gate 	*(p+1) = '\0';
4117c478bd9Sstevel@tonic-gate }
412