dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / ypcmd / yp_getalias.c
bloba383e83117ca68fc7c3291202eaafb67d13f13a6
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
22 * Copyright 1996 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
32 * California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <stdio.h>
38 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/statvfs.h>
41 #include "ypsym.h"
42 /* this is 14 less the space for temps pids and .pag more or less */
44 #ifdef DEBUG
45 #define YPDBDIR "/var/ypnew"
46 #define ALIASLIST "/var/ypnew/aliases"
47 #else
48 #define YPDBDIR "/var/yp"
49 #define ALIASLIST "/var/yp/aliases"
50 #endif
51 #define issep(c) (c == ' ' || c == '\t')
53 #ifdef SYSVCONFIG
54 #define isvar_sysv() (wasitsysv)
56 static int wasitsysv = TRUE;
57 static int first_time = TRUE;
58 static listofnames *list = NULL;
59 #endif
61 void sysv_exit();
62 extern listofnames *names();
63 extern void exit();
64 extern void free_listofnames();
67 * Setup alias file, check /var/yp filesystem type
68 * Note: The *never* checks for aliases under Solaris, so there is no need
69 * for this function. As of 1.1 beta 4, I will ifdef it out (cause
70 * you never know...). Should go away completely soon.
73 #ifdef SYSVCONFIG
74 void
75 sysvconfig(void)
77 struct statvfs statbuf;
79 sigset(SIGCHLD, SIG_IGN);
81 * if neccesary free previous list, then read in aliaslist
84 if (!first_time)
85 free_listofnames(list);
86 else
87 first_time = FALSE;
89 list = names(ALIASLIST);
92 * Check if YP database directory is in a system v filesystem
95 if (statvfs(YPDBDIR, &statbuf) != 0) {
96 fprintf(stderr, "Cannot stat %s\n", YPDBDIR);
97 exit(-1);
98 } else {
99 /* if (strcmp(statbuf.f_basetype,"s5")) (doesn't work in k13) */
100 if (statbuf.f_namemax == 14)
101 wasitsysv = TRUE;
102 else
103 wasitsysv = FALSE;
105 sigset(SIGCHLD, (void (*)())sysvconfig);
107 #endif
110 * Match key to alias
113 yp_getalias(key, key_alias, maxlen)
114 char *key;
115 char *key_alias;
116 int maxlen;
118 listofnames *entry;
119 char *longname;
120 char *alias;
121 char name[256];
123 #ifndef SYSVCONFIG
124 strcpy(key_alias, key);
125 return (0);
126 #else
127 /* sysvconfig must be run before this routine */
128 if (key == NULL || first_time)
129 return (-1);
131 if (!isvar_sysv()) {
132 strcpy(key_alias, key);
133 return (0);
136 for (entry = list, strcpy(name, entry->name); entry;
137 entry = entry->nextname, strcpy(name, entry->name)) {
139 longname = strtok(name, " \t");
140 alias = strtok(NULL, " \t\n");
141 if (longname == NULL || alias == NULL) {
142 continue;
144 if (strcmp(longname, key) == 0) {
145 if ((int)strlen(alias) > (maxlen)) {
146 strncpy(key_alias, alias, (maxlen));
147 key_alias[maxlen] = '\0';
148 } else {
149 strcpy(key_alias, alias);
151 return (0);
154 /* alias not found */
155 return (-1);
156 #endif
160 * Match alias to key
163 yp_getkey(key_alias, key, maxlen)
164 char *key_alias;
165 char *key;
166 int maxlen;
168 listofnames *entry;
169 char *longname;
170 char *alias;
171 char name[256];
173 #ifndef SYSVCONFIG
174 strcpy(key, key_alias);
175 return (0);
176 #else
177 if (key_alias == NULL || first_time) {
178 return (-1);
181 if (!isvar_sysv()) {
182 strcpy(key, key_alias);
183 return (0);
186 for (entry = list, strcpy(name, entry->name);
187 entry; entry = entry->nextname, strcpy(name, entry->name)) {
189 longname = strtok(name, " \t");
190 alias = strtok(NULL, " \t\n");
191 if (alias == NULL || longname == NULL) {
192 continue;
194 if ((strcmp(alias, key_alias) == 0) ||
195 (strncmp(alias, key_alias, maxlen) == 0)) {
196 strcpy(key, longname);
197 return (0);
200 /* key not found */
201 return (-1);
202 #endif