xref: /onnv-gate/usr/src/lib/libnisdb/yptol/map_conv.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * DESCRIPTION: Contains functions relating to movement of entire maps.
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <unistd.h>
34*0Sstevel@tonic-gate #include <syslog.h>
35*0Sstevel@tonic-gate #include <ndbm.h>
36*0Sstevel@tonic-gate #include <string.h>
37*0Sstevel@tonic-gate #include "ypsym.h"
38*0Sstevel@tonic-gate #include "ypdefs.h"
39*0Sstevel@tonic-gate #include "shim.h"
40*0Sstevel@tonic-gate #include "yptol.h"
41*0Sstevel@tonic-gate #include "../ldap_util.h"
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * Switch on parts of ypdefs.h
45*0Sstevel@tonic-gate  */
46*0Sstevel@tonic-gate USE_YPDBPATH
47*0Sstevel@tonic-gate USE_DBM
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  * Decs
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate void add_separator(char *);
53*0Sstevel@tonic-gate suc_code dump_domain_to_dit(char *, bool_t);
54*0Sstevel@tonic-gate suc_code dump_map_to_dit(char *, char *, bool_t);
55*0Sstevel@tonic-gate suc_code dump_maps_to_dit(bool_t);
56*0Sstevel@tonic-gate suc_code dump_dit_to_map();
57*0Sstevel@tonic-gate suc_code dump_dit_to_maps();
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * FUNCTION :	dump_maps_to_dit()
61*0Sstevel@tonic-gate  *
62*0Sstevel@tonic-gate  * DESCRIPTION:	Dump all the OLD STYLE NIS maps into the DIT.
63*0Sstevel@tonic-gate  *
64*0Sstevel@tonic-gate  *		Since the DIT is not yet set up details about which maps and
65*0Sstevel@tonic-gate  *		domains exist are gathered from the N2L config file and the
66*0Sstevel@tonic-gate  *		existing map files.
67*0Sstevel@tonic-gate  *
68*0Sstevel@tonic-gate  * GIVEN :	Flag indicating if containers and domains should be set up.
69*0Sstevel@tonic-gate  *
70*0Sstevel@tonic-gate  * RETURNS :	Success code
71*0Sstevel@tonic-gate  */
72*0Sstevel@tonic-gate suc_code
dump_maps_to_dit(bool_t init_containers)73*0Sstevel@tonic-gate dump_maps_to_dit(bool_t init_containers)
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate 	char **dom_list;
76*0Sstevel@tonic-gate 	int num_doms, i;
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate 	num_doms = get_mapping_domain_list(&dom_list);
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	/* Dump all domains in list */
81*0Sstevel@tonic-gate 	for (i = 0; i < num_doms; i++) {
82*0Sstevel@tonic-gate 		if (FAILURE == dump_domain_to_dit(dom_list[i], init_containers))
83*0Sstevel@tonic-gate 			return (FAILURE);
84*0Sstevel@tonic-gate 	}
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	return (SUCCESS);
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * FUNCTION :	dump_domain_to_dit()
91*0Sstevel@tonic-gate  *
92*0Sstevel@tonic-gate  * DESCRIPTION:	Dumps all maps in one domain into the DIT
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  * GIVEN :	Name of the domain
95*0Sstevel@tonic-gate  *		Flag indicating if containers and domains should be set up.
96*0Sstevel@tonic-gate  *
97*0Sstevel@tonic-gate  * RETURNS :	SUCCESS = domain completely dumped
98*0Sstevel@tonic-gate  *		FAILURE = domain not completely dumped
99*0Sstevel@tonic-gate  *
100*0Sstevel@tonic-gate  */
101*0Sstevel@tonic-gate suc_code
dump_domain_to_dit(char * dom_name,bool_t init_containers)102*0Sstevel@tonic-gate dump_domain_to_dit(char *dom_name, bool_t init_containers)
103*0Sstevel@tonic-gate {
104*0Sstevel@tonic-gate 	char **map_list;
105*0Sstevel@tonic-gate 	int	i;
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	/* Set up nis domain object */
108*0Sstevel@tonic-gate 	if (SUCCESS != make_nis_domain(dom_name, init_containers)) {
109*0Sstevel@tonic-gate 		if (init_containers)
110*0Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
111*0Sstevel@tonic-gate 			"Could not make nisDomain object for %s", dom_name);
112*0Sstevel@tonic-gate 		else
113*0Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
114*0Sstevel@tonic-gate 			"Problem detected with nisDomain object for %s",
115*0Sstevel@tonic-gate 								dom_name);
116*0Sstevel@tonic-gate 		return (FAILURE);
117*0Sstevel@tonic-gate 	}
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 	/* Get list of maps from mapping file */
120*0Sstevel@tonic-gate 	map_list = get_mapping_map_list(dom_name);
121*0Sstevel@tonic-gate 	if (NULL == map_list) {
122*0Sstevel@tonic-gate 		logmsg(MSG_NOTIMECHECK, LOG_ERR,
123*0Sstevel@tonic-gate 			"Could not get map list for %s", dom_name);
124*0Sstevel@tonic-gate 		return (FAILURE);
125*0Sstevel@tonic-gate 	}
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate 	for (i = 0; NULL != map_list[i]; i++) {
128*0Sstevel@tonic-gate 		dump_map_to_dit(map_list[i], dom_name, init_containers);
129*0Sstevel@tonic-gate 	}
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	free_map_list(map_list);
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate 	return (SUCCESS);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /*
137*0Sstevel@tonic-gate  * FUNCTION :	dump_map_to_dit()
138*0Sstevel@tonic-gate  *
139*0Sstevel@tonic-gate  * DESCRIPTION:	Dump a OLD STYLE NIS map into the DIT.
140*0Sstevel@tonic-gate  *
141*0Sstevel@tonic-gate  * GIVEN :	Name of map (not fully qualified)
142*0Sstevel@tonic-gate  *		Name of domain
143*0Sstevel@tonic-gate  *		Flag indicating if containers should be set up.
144*0Sstevel@tonic-gate  *
145*0Sstevel@tonic-gate  * RETURNS :	SUCCESS = Map copy completed
146*0Sstevel@tonic-gate  *		FAILURE = Map copy not completed
147*0Sstevel@tonic-gate  */
148*0Sstevel@tonic-gate suc_code
dump_map_to_dit(char * map_name,char * domain,bool_t init_containers)149*0Sstevel@tonic-gate dump_map_to_dit(char *map_name, char *domain, bool_t init_containers)
150*0Sstevel@tonic-gate {
151*0Sstevel@tonic-gate 	char *myself = "dump_map_to_dit";
152*0Sstevel@tonic-gate 	DBM *dbm;
153*0Sstevel@tonic-gate 	datum key;
154*0Sstevel@tonic-gate 	datum value;
155*0Sstevel@tonic-gate 	char *map_path;		/* Qualified map name */
156*0Sstevel@tonic-gate 	int entry_count;
157*0Sstevel@tonic-gate 	int next_print;
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 	printf("Copying map \"%s\", domain \"%s\", to LDAP.\n",
160*0Sstevel@tonic-gate 							map_name, domain);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 	/* Create the NIS container */
163*0Sstevel@tonic-gate 	if (SUCCESS != make_nis_container(map_name, domain, init_containers)) {
164*0Sstevel@tonic-gate 		if (init_containers)
165*0Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
166*0Sstevel@tonic-gate 				"Could not make container for %s %s",
167*0Sstevel@tonic-gate 				map_name, domain);
168*0Sstevel@tonic-gate 		else
169*0Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_ERR,
170*0Sstevel@tonic-gate 				"Problem detected with container for %s %s",
171*0Sstevel@tonic-gate 				map_name, domain);
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate 		return (FAILURE);
174*0Sstevel@tonic-gate 	}
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	/* Make up fully qualified map name */
177*0Sstevel@tonic-gate 	map_path = (char *)am(myself, strlen(domain) + strlen(map_name) +
178*0Sstevel@tonic-gate 						ypdbpath_sz + 3);
179*0Sstevel@tonic-gate 	if (NULL == map_path) {
180*0Sstevel@tonic-gate 		logmsg(MSG_NOMEM, LOG_ERR,
181*0Sstevel@tonic-gate 			"Could not alloc memory for %s %s", map_name, domain);
182*0Sstevel@tonic-gate 		return (FAILURE);
183*0Sstevel@tonic-gate 	}
184*0Sstevel@tonic-gate 	strcpy(map_path, ypdbpath);
185*0Sstevel@tonic-gate 	add_separator(map_path);
186*0Sstevel@tonic-gate 	strcat(map_path, domain);
187*0Sstevel@tonic-gate 	add_separator(map_path);
188*0Sstevel@tonic-gate 	strcat(map_path, map_name);
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 	/* Open the DBM file. Use real dbm call */
191*0Sstevel@tonic-gate 	dbm = dbm_open(map_path, O_RDONLY, 0644);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate 	/* Finished with full name */
194*0Sstevel@tonic-gate 	sfree(map_path);
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 	if (NULL == dbm) {
197*0Sstevel@tonic-gate 		/*
198*0Sstevel@tonic-gate 		 * This map probably didn't exist. No problem, user may be
199*0Sstevel@tonic-gate 		 * going to populate container using LDAP.
200*0Sstevel@tonic-gate 		 */
201*0Sstevel@tonic-gate 		return (SUCCESS);
202*0Sstevel@tonic-gate 	}
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 	/*
205*0Sstevel@tonic-gate 	 * N2L has no lock for old style maps. No problem ypserv -i is the
206*0Sstevel@tonic-gate 	 * only thing that accesses them.
207*0Sstevel@tonic-gate 	 */
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	/* For all entries in file */
210*0Sstevel@tonic-gate 	for (key = dbm_firstkey(dbm), next_print = PRINT_FREQ, entry_count = 1;
211*0Sstevel@tonic-gate 		NULL != key.dptr; key = dbm_nextkey(dbm), entry_count ++) {
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate 		/* Don't write zero length keys */
214*0Sstevel@tonic-gate 		if (0 == key.dsize) {
215*0Sstevel@tonic-gate 			logmsg(MSG_NOTIMECHECK, LOG_INFO,
216*0Sstevel@tonic-gate 			"Zero length key ignored in %s %s", map_name, domain);
217*0Sstevel@tonic-gate 			continue;
218*0Sstevel@tonic-gate 		}
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 		/* Don't write 'special' nis entries */
221*0Sstevel@tonic-gate 		if (is_special_key(&key))
222*0Sstevel@tonic-gate 			continue;
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate 		/* Get entry */
225*0Sstevel@tonic-gate 		value = dbm_fetch(dbm, key);
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate 		/* Copy entry to DIT */
228*0Sstevel@tonic-gate 		if (SUCCESS != write_to_dit(map_name, domain, key, value,
229*0Sstevel@tonic-gate 								TRUE, TRUE))
230*0Sstevel@tonic-gate 			/* Syslog will have already been done */
231*0Sstevel@tonic-gate 			break;
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate 		/* If necessary print a progress report */
234*0Sstevel@tonic-gate 		if (entry_count >= next_print) {
235*0Sstevel@tonic-gate 			printf("%d entries processed.\n", entry_count);
236*0Sstevel@tonic-gate 			next_print *= 2;
237*0Sstevel@tonic-gate 		}
238*0Sstevel@tonic-gate 	}
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	dbm_close(dbm);
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	return (SUCCESS);
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate /*
246*0Sstevel@tonic-gate  * FUNCTION :	dump_dit_to_maps()
247*0Sstevel@tonic-gate  *
248*0Sstevel@tonic-gate  * DESCRIPTION:	Dumps the contents of the DIT into the NEW STYLE NIS maps. If
249*0Sstevel@tonic-gate  *		the maps, or their TTL files do not exist creates them.
250*0Sstevel@tonic-gate  *
251*0Sstevel@tonic-gate  *		Since we are now treating the DIT as authoritative details of
252*0Sstevel@tonic-gate  *		which domains and maps exist are gathered from the DIT.
253*0Sstevel@tonic-gate  *
254*0Sstevel@tonic-gate  * GIVEN :	Nothing
255*0Sstevel@tonic-gate  *
256*0Sstevel@tonic-gate  * RETURNS :	Success code
257*0Sstevel@tonic-gate  */
258*0Sstevel@tonic-gate suc_code
dump_dit_to_maps()259*0Sstevel@tonic-gate dump_dit_to_maps()
260*0Sstevel@tonic-gate {
261*0Sstevel@tonic-gate 	char **dom_list;
262*0Sstevel@tonic-gate 	int dom_count;
263*0Sstevel@tonic-gate 	char *dom_path;
264*0Sstevel@tonic-gate 	char **map_list;
265*0Sstevel@tonic-gate 	int i, j;
266*0Sstevel@tonic-gate 	char *myself = "dump_dit_to_maps";
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 	/* For all domain objects in DIT */
269*0Sstevel@tonic-gate 	dom_count = get_mapping_domain_list(&dom_list);
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate 	if (0 == dom_count) {
272*0Sstevel@tonic-gate 		/* No problem, maybe no domains */
273*0Sstevel@tonic-gate 		return (SUCCESS);
274*0Sstevel@tonic-gate 	}
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate 	/* Dump all domains in list */
277*0Sstevel@tonic-gate 	for (i = 0; i < dom_count; i++) {
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 		/* If necessary create domain directory */
280*0Sstevel@tonic-gate 		dom_path = (char *)am(myself, ypdbpath_sz +
281*0Sstevel@tonic-gate 						strlen(dom_list[i]) + 2);
282*0Sstevel@tonic-gate 		if (NULL == dom_path) {
283*0Sstevel@tonic-gate 			return (FAILURE);
284*0Sstevel@tonic-gate 		}
285*0Sstevel@tonic-gate 
286*0Sstevel@tonic-gate 		strcpy(dom_path, ypdbpath);
287*0Sstevel@tonic-gate 		strcat(dom_path, "/");
288*0Sstevel@tonic-gate 		strcat(dom_path, dom_list[i]);
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 		if (0 != mkdir(dom_path, 0644)) {
291*0Sstevel@tonic-gate 			/* If dir exists fine. Just use it */
292*0Sstevel@tonic-gate 			if (EEXIST != errno) {
293*0Sstevel@tonic-gate 				logmsg(MSG_NOTIMECHECK, LOG_ERR,
294*0Sstevel@tonic-gate 				"Could not make create domain directory %s",
295*0Sstevel@tonic-gate 								dom_path);
296*0Sstevel@tonic-gate 				sfree(dom_path);
297*0Sstevel@tonic-gate 			}
298*0Sstevel@tonic-gate 		}
299*0Sstevel@tonic-gate 
300*0Sstevel@tonic-gate 		sfree(dom_path);
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate 		/* Get list of maps for this domain */
303*0Sstevel@tonic-gate 		map_list = get_mapping_map_list(dom_list[i]);
304*0Sstevel@tonic-gate 		if (NULL == map_list) {
305*0Sstevel@tonic-gate 			/* No problem. Just no maps in this domain */
306*0Sstevel@tonic-gate 			continue;
307*0Sstevel@tonic-gate 		}
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 		/* For all maps in domain */
310*0Sstevel@tonic-gate 		for (j = 0; map_list[j] != NULL; j++) {
311*0Sstevel@tonic-gate 			/* A normal map update will initialize it. */
312*0Sstevel@tonic-gate 			if (FAILURE == dump_dit_to_map(map_list[j],
313*0Sstevel@tonic-gate 							dom_list[i])) {
314*0Sstevel@tonic-gate 				free_map_list(map_list);
315*0Sstevel@tonic-gate 				return (FAILURE);
316*0Sstevel@tonic-gate 			}
317*0Sstevel@tonic-gate 
318*0Sstevel@tonic-gate 			/* If we have a netgroup also generate netgroup.byxxx */
319*0Sstevel@tonic-gate 			if (0 == strcmp(map_list[j], NETGROUP_MAP)) {
320*0Sstevel@tonic-gate 				if (FAILURE == dump_dit_to_map(NETGROUP_BYHOST,
321*0Sstevel@tonic-gate 								dom_list[i])) {
322*0Sstevel@tonic-gate 					free_map_list(map_list);
323*0Sstevel@tonic-gate 					return (FAILURE);
324*0Sstevel@tonic-gate 				}
325*0Sstevel@tonic-gate 				if (FAILURE == dump_dit_to_map(NETGROUP_BYUSER,
326*0Sstevel@tonic-gate 								dom_list[i])) {
327*0Sstevel@tonic-gate 					free_map_list(map_list);
328*0Sstevel@tonic-gate 					return (FAILURE);
329*0Sstevel@tonic-gate 				}
330*0Sstevel@tonic-gate 			}
331*0Sstevel@tonic-gate 		}
332*0Sstevel@tonic-gate 		free_map_list(map_list);
333*0Sstevel@tonic-gate 	}
334*0Sstevel@tonic-gate 	return (SUCCESS);
335*0Sstevel@tonic-gate }
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate /*
338*0Sstevel@tonic-gate  * FUNCTION :	dump_dit_to_map()
339*0Sstevel@tonic-gate  *
340*0Sstevel@tonic-gate  * DESCRIPTION:	Dumps the contents of the DIT into one NEW STYLE NIS map. If
341*0Sstevel@tonic-gate  *		the map, or its TTL file does not exist creates them.
342*0Sstevel@tonic-gate  *
343*0Sstevel@tonic-gate  *		This is the same operation as is carried out when updating a
344*0Sstevel@tonic-gate  *		map that has timed out. As a result we can call the normal
345*0Sstevel@tonic-gate  *		update function.
346*0Sstevel@tonic-gate  *
347*0Sstevel@tonic-gate  *
348*0Sstevel@tonic-gate  * GIVEN :	Map name (unqualified)
349*0Sstevel@tonic-gate  *		Domain name.
350*0Sstevel@tonic-gate  *
351*0Sstevel@tonic-gate  * RETURNS :	SUCCESS = Map copy complete
352*0Sstevel@tonic-gate  *		FAILURE = Problems
353*0Sstevel@tonic-gate  */
354*0Sstevel@tonic-gate suc_code
dump_dit_to_map(char * map_name,char * domain)355*0Sstevel@tonic-gate dump_dit_to_map(char *map_name, char *domain)
356*0Sstevel@tonic-gate {
357*0Sstevel@tonic-gate 	char *myself = "dump_dit_to_map";
358*0Sstevel@tonic-gate 	map_ctrl map;
359*0Sstevel@tonic-gate 	char 	*map_path;
360*0Sstevel@tonic-gate 
361*0Sstevel@tonic-gate 	printf("Copying LDAP data to map \"%s\", domain \"%s\".\n",
362*0Sstevel@tonic-gate 							map_name, domain);
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 	/*
365*0Sstevel@tonic-gate 	 * To call update_map_from_dit() we need an initialized map_ctrl.
366*0Sstevel@tonic-gate 	 * The easiest way to get this is to generate a full path to the new
367*0Sstevel@tonic-gate 	 * map and then call map_ctrl_init().
368*0Sstevel@tonic-gate 	 */
369*0Sstevel@tonic-gate 	map_path = (char *)am(myself, ypdbpath_sz + strlen(map_name) +
370*0Sstevel@tonic-gate 				strlen(domain) + strlen(NTOL_PREFIX) + 3);
371*0Sstevel@tonic-gate 	if (NULL == map_path)
372*0Sstevel@tonic-gate 		return (FAILURE);
373*0Sstevel@tonic-gate 
374*0Sstevel@tonic-gate 	strcpy(map_path, ypdbpath);
375*0Sstevel@tonic-gate 	add_separator(map_path);
376*0Sstevel@tonic-gate 	strcat(map_path, domain);
377*0Sstevel@tonic-gate 	add_separator(map_path);
378*0Sstevel@tonic-gate 	strcat(map_path, NTOL_PREFIX);
379*0Sstevel@tonic-gate 	strcat(map_path, map_name);
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 	if (FAILURE == map_ctrl_init(&map, map_path)) {
382*0Sstevel@tonic-gate 		sfree(map_path);
383*0Sstevel@tonic-gate 		return (FAILURE);
384*0Sstevel@tonic-gate 	}
385*0Sstevel@tonic-gate 
386*0Sstevel@tonic-gate 	sfree(map_path);
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate 	/*
389*0Sstevel@tonic-gate 	 * This is called before anything else is running so don't need to
390*0Sstevel@tonic-gate 	 * do normal update lock.
391*0Sstevel@tonic-gate 	 */
392*0Sstevel@tonic-gate 	return (update_map_from_dit(&map, TRUE));
393*0Sstevel@tonic-gate }
394*0Sstevel@tonic-gate 
395*0Sstevel@tonic-gate /*
396*0Sstevel@tonic-gate  * FUNCTION :	add_seperator()
397*0Sstevel@tonic-gate  *
398*0Sstevel@tonic-gate  * DESCRIPTION:	Adds a file separator to a string (which must already be big
399*0Sstevel@tonic-gate  *		enough.)
400*0Sstevel@tonic-gate  *
401*0Sstevel@tonic-gate  * GIVEN :	Pointer to the string
402*0Sstevel@tonic-gate  *
403*0Sstevel@tonic-gate  * RETURNS :	Nothing
404*0Sstevel@tonic-gate  */
405*0Sstevel@tonic-gate void
add_separator(char * str)406*0Sstevel@tonic-gate add_separator(char *str)
407*0Sstevel@tonic-gate {
408*0Sstevel@tonic-gate 	char *p;
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate 	p = str + strlen(str);
411*0Sstevel@tonic-gate 	*p = SEP_CHAR;
412*0Sstevel@tonic-gate 	*(p+1) = '\0';
413*0Sstevel@tonic-gate }
414