xref: /titanic_44/usr/src/lib/libnisdb/yptol/shim_ancil.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #ifndef	lint
38 static	char sccsid[] = "%Z%%M% %I%     %E% SMI";
39 #endif
40 
41 #include <dirent.h>
42 #include <strings.h>
43 #include "ypsym.h"
44 #include "ypdefs.h"
45 USE_YPDBPATH
46 USE_DBM
47 #include "shim.h"
48 
49 /*
50  * This constructs a file name from a passed domain name, a passed map name,
51  * and a globally known YP data base path prefix.
52  *
53  * Has to be in shim because it needs the N2L prefix
54  *
55  * RETURNS :	TRUE = A name was successfully created
56  *		FALSE = A name could not be created
57  */
58 
59 bool_t
60 ypmkfilename(domain, map, path)
61 	char *domain;
62 	char *map;
63 	char *path;
64 {
65 	int length;
66 
67 	/* Do not allow any path as a domain name. */
68 	if (strchr(domain, '/') != NULL)
69 		return (FALSE);
70 
71 	length = strlen(domain) + strlen(map) + ypdbpath_sz + 3;
72 	if (yptol_mode)
73 		length += strlen(NTOL_PREFIX) + 1;
74 
75 	if ((MAXNAMLEN + 1) < length) {
76 		fprintf(stderr, "ypserv:  Map name string too long.\n");
77 		return (FALSE);
78 	}
79 
80 	strcpy(path, ypdbpath);
81 	strcat(path, "/");
82 	strcat(path, domain);
83 	strcat(path, "/");
84 
85 	/* If in N2L mode add N2L prefix */
86 	if (yptol_mode)
87 		strcat(path, NTOL_PREFIX);
88 	strcat(path, map);
89 
90 	return (TRUE);
91 }
92