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 (c) 1986-1992 by Sun Microsystems Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #include <stdio.h>
27*0Sstevel@tonic-gate #include <rpc/rpc.h>
28*0Sstevel@tonic-gate #include <rpcsvc/yp_prot.h>
29*0Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
30*0Sstevel@tonic-gate #include <string.h>
31*0Sstevel@tonic-gate #include <unistd.h>
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #define MAXMAPS 500
34*0Sstevel@tonic-gate /* number of nickname file entries arbitrarily limited */
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate static char NICKFILE[] = "/var/yp/nicknames";
37*0Sstevel@tonic-gate static char *transtable[MAXMAPS];
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate * This will read nicknames from file /var/yp/nicknames
41*0Sstevel@tonic-gate * and print it out or save it for future use.
42*0Sstevel@tonic-gate */
43*0Sstevel@tonic-gate void
maketable(dump)44*0Sstevel@tonic-gate maketable(dump)
45*0Sstevel@tonic-gate int dump;
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate FILE *nickp;
48*0Sstevel@tonic-gate int i = 0;
49*0Sstevel@tonic-gate char nickbuf[2*YPMAXMAP+3], nickname[YPMAXMAP+1], mapname[YPMAXMAP+1];
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate if ((nickp = fopen(NICKFILE, "r")) == NULL) {
52*0Sstevel@tonic-gate (void) fprintf(stderr, "nickname file %s does not exist\n",
53*0Sstevel@tonic-gate NICKFILE);
54*0Sstevel@tonic-gate exit(1);
55*0Sstevel@tonic-gate }
56*0Sstevel@tonic-gate while (fgets(nickbuf, YPMAXMAP, nickp) != NULL) {
57*0Sstevel@tonic-gate if (strchr(nickbuf, '\n') == NULL) {
58*0Sstevel@tonic-gate (void) fprintf(stderr,
59*0Sstevel@tonic-gate "garbled nickname file %s\n", NICKFILE);
60*0Sstevel@tonic-gate exit(1);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate (void) memset(nickname, 0, YPMAXMAP+1);
63*0Sstevel@tonic-gate (void) memset(mapname, 0, YPMAXMAP+1);
64*0Sstevel@tonic-gate if (sscanf(nickbuf, "%s %s\n", nickname, mapname) != 2) {
65*0Sstevel@tonic-gate (void) fprintf(stderr,
66*0Sstevel@tonic-gate "garbled nickname file %s\n", NICKFILE);
67*0Sstevel@tonic-gate exit(1);
68*0Sstevel@tonic-gate }
69*0Sstevel@tonic-gate if (!dump) {
70*0Sstevel@tonic-gate transtable[i] = strdup(nickname);
71*0Sstevel@tonic-gate transtable[i+1] = strdup(mapname);
72*0Sstevel@tonic-gate i += 2;
73*0Sstevel@tonic-gate transtable[i] = NULL;
74*0Sstevel@tonic-gate } else {
75*0Sstevel@tonic-gate printf("Use \"%s\"\tfor map \"%s\"\n",
76*0Sstevel@tonic-gate nickname, mapname);
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate }
79*0Sstevel@tonic-gate fclose(nickp);
80*0Sstevel@tonic-gate }
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate /*
83*0Sstevel@tonic-gate * This will get the mapname for a given nickname from the file.
84*0Sstevel@tonic-gate */
85*0Sstevel@tonic-gate int
getmapname(nick,map)86*0Sstevel@tonic-gate getmapname(nick, map)
87*0Sstevel@tonic-gate char *nick, *map;
88*0Sstevel@tonic-gate {
89*0Sstevel@tonic-gate FILE *nickp;
90*0Sstevel@tonic-gate char nickbuf[2*YPMAXMAP+3], nickname[YPMAXMAP+1];
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate if ((nickp = fopen(NICKFILE, "r")) == NULL)
93*0Sstevel@tonic-gate return (0);
94*0Sstevel@tonic-gate while (fgets(nickbuf, YPMAXMAP, nickp) != NULL) {
95*0Sstevel@tonic-gate if (strchr(nickbuf, '\n') == NULL) {
96*0Sstevel@tonic-gate fclose(nickp);
97*0Sstevel@tonic-gate return (0);
98*0Sstevel@tonic-gate }
99*0Sstevel@tonic-gate (void) memset(nickname, 0, YPMAXMAP+1);
100*0Sstevel@tonic-gate (void) memset(map, 0, YPMAXMAP+1);
101*0Sstevel@tonic-gate if (sscanf(nickbuf, "%s %s\n", nickname, map) != 2) {
102*0Sstevel@tonic-gate fclose(nickp);
103*0Sstevel@tonic-gate return (0);
104*0Sstevel@tonic-gate }
105*0Sstevel@tonic-gate if (strcmp(nick, nickname) == 0) {
106*0Sstevel@tonic-gate fclose(nickp);
107*0Sstevel@tonic-gate return (1);
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate fclose(nickp);
111*0Sstevel@tonic-gate return (0);
112*0Sstevel@tonic-gate }
113