Commit | Line | Data |
---|---|---|
b8493e0e | 1 | #ifndef lint |
95f51977 | 2 | static char sccsid[] = "@(#)versys.c 5.5 (Berkeley) 10/9/85"; |
b8493e0e SL |
3 | #endif |
4 | ||
5 | #include "uucp.h" | |
1a85e9d2 RC |
6 | #include <stdio.h> |
7 | #include <ctype.h> | |
b8493e0e | 8 | |
901550ff | 9 | /*LINTLIBRARY*/ |
b8493e0e | 10 | |
ba8a7d50 JB |
11 | char PhoneNumber[MAXPH]; |
12 | ||
1a85e9d2 RC |
13 | /* |
14 | * verify system names n1 and n2 | |
15 | * return codes: SUCCESS | FAIL | |
b8493e0e | 16 | * |
1a85e9d2 RC |
17 | * NOTE: |
18 | * the old calling sequence was versys(name) but is | |
19 | * now versys(&name) so that we can perform aliasing!!!! | |
20 | * See accompanying changes in uucp.c and uux.c | |
21 | * -- Ray Essick, April 27, 1984 | |
b8493e0e | 22 | */ |
1a85e9d2 RC |
23 | versys(nameptr) |
24 | register char **nameptr; | |
b8493e0e SL |
25 | { |
26 | register FILE *fp; | |
1a85e9d2 RC |
27 | char line[BUFSIZ]; |
28 | char *name; | |
29 | ||
30 | DEBUG (11, "Before Alias: %s\n", *nameptr); | |
901550ff | 31 | uualias (nameptr); /* alias expansion */ |
1a85e9d2 RC |
32 | DEBUG (11, "After Alias: %s\n", *nameptr); |
33 | name = *nameptr; /* dereference */ | |
b8493e0e | 34 | |
901550ff | 35 | if (strncmp(name, Myname, MAXBASENAME) == 0) |
46b15d8a | 36 | return SUCCESS; |
b8493e0e SL |
37 | |
38 | fp = fopen(SYSFILE, "r"); | |
46b15d8a | 39 | ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0); |
ba8a7d50 | 40 | PhoneNumber[0] = '\0'; |
b8493e0e SL |
41 | while (cfgets(line, sizeof(line), fp) != NULL) { |
42 | char *targs[100]; | |
43 | ||
46b15d8a | 44 | getargs(line, targs, 100); |
901550ff | 45 | if (strncmp(name, targs[0], MAXBASENAME) == SAME) { |
b8493e0e | 46 | fclose(fp); |
ba8a7d50 | 47 | strncpy(PhoneNumber, targs[F_PHONE], MAXPH); |
46b15d8a | 48 | return SUCCESS; |
b8493e0e SL |
49 | } |
50 | } | |
51 | fclose(fp); | |
46b15d8a | 52 | return FAIL; |
b8493e0e | 53 | } |
1a85e9d2 RC |
54 | |
55 | /* | |
56 | * Works (sort of) like rhost(3) on 4.1[abc] Bsd systems. | |
57 | * | |
58 | * Looks for the host in the L.aliases file and returns the | |
59 | * "standard" name by modifying the pointer. The returned | |
60 | * value is saved with malloc(3) so it isn't zapped by | |
61 | * subsequent calls. | |
62 | * | |
63 | * Returns: | |
64 | * FAIL No L.aliases file | |
65 | * SUCCESS Anything else | |
66 | */ | |
67 | ||
ba8a7d50 | 68 | uualias(hostptr) |
1a85e9d2 RC |
69 | char **hostptr; /* we change it */ |
70 | { | |
ba8a7d50 | 71 | FILE *Aliases; /* list of aliases */ |
1a85e9d2 RC |
72 | char buf[BUFSIZ]; |
73 | int atend; | |
74 | char *p, *q; | |
75 | char *koshername; /* "official" name */ | |
76 | ||
77 | if ((Aliases = fopen(ALIASFILE, "r")) == NULL) { | |
78 | DEBUG(11, "No %s file\n", ALIASFILE); | |
79 | return FAIL; /* no alias file */ | |
80 | } | |
81 | ||
82 | DEBUG (11, "Alias expansion for %s\n", *hostptr); | |
ba8a7d50 | 83 | while (cfgets(buf, sizeof (buf), Aliases)) { |
1a85e9d2 RC |
84 | p = &buf[0]; |
85 | atend = 0; | |
86 | DEBUG(11, "Alias line: %s\n", buf); | |
87 | ||
88 | while (!atend) { | |
89 | while (isspace(*p) && *p != '\n') | |
90 | p++; /* skip white space */ | |
91 | q = p; | |
92 | while (!isspace(*q) && *q != '\n') | |
93 | q++; /* find end */ | |
94 | if (*q == '\n') | |
95 | atend++; /* last entry */ | |
96 | *q = '\0'; | |
97 | DEBUG(11, "Compare against: %s\n", p); | |
98 | if (strcmp(*hostptr, p) == 0)/* match? */ { | |
901550ff | 99 | koshername = malloc((unsigned)strlen(buf) + 1); |
1a85e9d2 RC |
100 | strcpy(koshername, buf); /* save it */ |
101 | fclose(Aliases); | |
102 | DEBUG(4, "Alias: %s to ", *hostptr); | |
103 | DEBUG(4, "%s\n", koshername); | |
104 | *hostptr = koshername; /* correct one */ | |
105 | return SUCCESS; /* all is well */ | |
106 | } | |
107 | p = q + 1; /* try next entry */ | |
108 | } | |
109 | ||
110 | } | |
111 | fclose(Aliases); | |
112 | DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr); | |
113 | return SUCCESS; /* unchanged host */ | |
114 | } |