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
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.
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]
22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * under license from the Regents of the University of
38 #include <sys/types.h>
39 #include <sys/statvfs.h>
43 extern void sysvconfig();
46 extern int yp_getalias();
49 * Given a domain name, return its system v alias.
50 * If there is no alias name in the alias file,
51 * create one. Rule of creation is to take the 1st
52 * NAME_MAX-4 characters and concatenate the last 4 characters.
53 * If the alias in the file is too long, trim off the end.
57 mkdomain_alias(name
, result
)
61 char tmpbuf
[MAXNAMLEN
] = {0};
63 retval
= yp_getalias(name
, result
, NAME_MAX
);
65 if ((int)strlen(name
) > NAME_MAX
) {
66 strncpy(result
, name
, NAME_MAX
-4);
67 strncpy(&result
[NAME_MAX
-4],
68 &name
[strlen(name
)-4], 4);
69 result
[NAME_MAX
] = '\0';
72 } else if ((retval
) && (int)strlen(result
) > NAME_MAX
) {
73 strncpy(tmpbuf
, result
, NAME_MAX
);
74 strcpy(result
, tmpbuf
);
79 * Given a map name, return its system v alias .
80 * If there is no alias name in the alias file,
81 * create one. Rule of creation is to take the 1st
82 * MAXALIASLEN-4 characters and concatenate the last 4 characters.
83 * If the alias in the file is too long, trim off the end.
86 mkmap_alias(name
, result
)
90 char tmpbuf
[MAXNAMLEN
] = {0};
92 retval
= yp_getalias(name
, result
, MAXALIASLEN
);
95 if ((int)strlen(name
) > MAXALIASLEN
) {
96 (void) strncpy(result
, name
, MAXALIASLEN
-4);
97 (void) strncpy(&result
[MAXALIASLEN
-4],
98 &name
[strlen(name
)-4], 4);
99 result
[MAXALIASLEN
] = '\0';
101 (void) strcpy(result
, name
);
102 } else if ((retval
) && (int)strlen(result
) > MAXALIASLEN
) {
103 (void) strncpy(tmpbuf
, result
, MAXALIASLEN
);
104 (void) strcpy(result
, tmpbuf
);
111 * executed only for the command ypalias
112 * and not when ypbind or ypserv make use
116 static char usage
[] =
118 ypalias -d domainname\n\
125 char result
[MAXNAMLEN
] = {0};
132 if (strcmp(argv
[1], "-d") == 0)
133 if (argc
== 3) mkdomain_alias(argv
[2], (char *)&result
);
136 mkmap_alias(argv
[1], (char *)&result
);
139 (void) printf("%s", result
);
142 (void) fprintf(stderr
, usage
);