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
35 #pragma ident "%Z%%M% %I% %E% SMI"
40 #include <sys/types.h>
41 #include <sys/statvfs.h>
45 extern void sysvconfig();
48 extern int yp_getalias();
51 * Given a domain name, return its system v alias.
52 * If there is no alias name in the alias file,
53 * create one. Rule of creation is to take the 1st
54 * NAME_MAX-4 characters and concatenate the last 4 characters.
55 * If the alias in the file is too long, trim off the end.
59 mkdomain_alias(name
, result
)
63 char tmpbuf
[MAXNAMLEN
] = {NULL
};
65 retval
= yp_getalias(name
, result
, NAME_MAX
);
67 if ((int)strlen(name
) > NAME_MAX
) {
68 strncpy(result
, name
, NAME_MAX
-4);
69 strncpy(&result
[NAME_MAX
-4],
70 &name
[strlen(name
)-4], 4);
71 result
[NAME_MAX
] = '\0';
74 } else if ((retval
) && (int)strlen(result
) > NAME_MAX
) {
75 strncpy(tmpbuf
, result
, NAME_MAX
);
76 strcpy(result
, tmpbuf
);
81 * Given a map name, return its system v alias .
82 * If there is no alias name in the alias file,
83 * create one. Rule of creation is to take the 1st
84 * MAXALIASLEN-4 characters and concatenate the last 4 characters.
85 * If the alias in the file is too long, trim off the end.
88 mkmap_alias(name
, result
)
92 char tmpbuf
[MAXNAMLEN
] = {NULL
};
94 retval
= yp_getalias(name
, result
, MAXALIASLEN
);
97 if ((int)strlen(name
) > MAXALIASLEN
) {
98 (void) strncpy(result
, name
, MAXALIASLEN
-4);
99 (void) strncpy(&result
[MAXALIASLEN
-4],
100 &name
[strlen(name
)-4], 4);
101 result
[MAXALIASLEN
] = '\0';
103 (void) strcpy(result
, name
);
104 } else if ((retval
) && (int)strlen(result
) > MAXALIASLEN
) {
105 (void) strncpy(tmpbuf
, result
, MAXALIASLEN
);
106 (void) strcpy(result
, tmpbuf
);
113 * executed only for the command ypalias
114 * and not when ypbind or ypserv make use
118 static char usage
[] =
120 ypalias -d domainname\n\
127 char result
[MAXNAMLEN
] = {NULL
};
134 if (strcmp(argv
[1], "-d") == 0)
135 if (argc
== 3) mkdomain_alias(argv
[2], (char *)&result
);
138 mkmap_alias(argv
[1], (char *)&result
);
141 (void) printf("%s", result
);
144 (void) fprintf(stderr
, usage
);