113698Ssam #ifndef lint 2*33580Srick static char sccsid[] = "@(#)versys.c 5.6 (Berkeley) 02/24/88"; 313698Ssam #endif 413698Ssam 513698Ssam #include "uucp.h" 618629Sralph #include <stdio.h> 718629Sralph #include <ctype.h> 813698Ssam 923693Sbloom /*LINTLIBRARY*/ 1013698Ssam 1125148Sbloom char PhoneNumber[MAXPH]; 1225148Sbloom 1318629Sralph /* 1418629Sralph * verify system names n1 and n2 1518629Sralph * return codes: SUCCESS | FAIL 1613698Ssam * 1718629Sralph * NOTE: 1818629Sralph * the old calling sequence was versys(name) but is 1918629Sralph * now versys(&name) so that we can perform aliasing!!!! 2018629Sralph * See accompanying changes in uucp.c and uux.c 2118629Sralph * -- Ray Essick, April 27, 1984 2213698Ssam */ 2318629Sralph versys(nameptr) 2418629Sralph register char **nameptr; 2513698Ssam { 2613698Ssam register FILE *fp; 2718629Sralph char line[BUFSIZ]; 2818629Sralph char *name; 2913698Ssam 3018629Sralph DEBUG (11, "Before Alias: %s\n", *nameptr); 3123693Sbloom uualias (nameptr); /* alias expansion */ 3218629Sralph DEBUG (11, "After Alias: %s\n", *nameptr); 3318629Sralph name = *nameptr; /* dereference */ 3418629Sralph 35*33580Srick if (name[0] == '\0' || strncmp(name, Myname, MAXBASENAME) == 0) 3617847Sralph return SUCCESS; 3713698Ssam 3813698Ssam fp = fopen(SYSFILE, "r"); 3917847Sralph ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0); 4025148Sbloom PhoneNumber[0] = '\0'; 4113698Ssam while (cfgets(line, sizeof(line), fp) != NULL) { 4213698Ssam char *targs[100]; 4313698Ssam 4417847Sralph getargs(line, targs, 100); 4523693Sbloom if (strncmp(name, targs[0], MAXBASENAME) == SAME) { 4613698Ssam fclose(fp); 47*33580Srick if (targs[F_PHONE]) 48*33580Srick strncpy(PhoneNumber, targs[F_PHONE], MAXPH); 4917847Sralph return SUCCESS; 5013698Ssam } 5113698Ssam } 5213698Ssam fclose(fp); 5317847Sralph return FAIL; 5413698Ssam } 5518629Sralph 5618629Sralph /* 5718629Sralph * Works (sort of) like rhost(3) on 4.1[abc] Bsd systems. 5818629Sralph * 5918629Sralph * Looks for the host in the L.aliases file and returns the 6018629Sralph * "standard" name by modifying the pointer. The returned 6118629Sralph * value is saved with malloc(3) so it isn't zapped by 6218629Sralph * subsequent calls. 6318629Sralph * 6418629Sralph * Returns: 6518629Sralph * FAIL No L.aliases file 6618629Sralph * SUCCESS Anything else 6718629Sralph */ 6818629Sralph 6925148Sbloom uualias(hostptr) 7018629Sralph char **hostptr; /* we change it */ 7118629Sralph { 7225148Sbloom FILE *Aliases; /* list of aliases */ 7318629Sralph char buf[BUFSIZ]; 7418629Sralph int atend; 7518629Sralph char *p, *q; 7618629Sralph char *koshername; /* "official" name */ 7718629Sralph 7818629Sralph if ((Aliases = fopen(ALIASFILE, "r")) == NULL) { 7918629Sralph DEBUG(11, "No %s file\n", ALIASFILE); 8018629Sralph return FAIL; /* no alias file */ 8118629Sralph } 8218629Sralph 8318629Sralph DEBUG (11, "Alias expansion for %s\n", *hostptr); 8425148Sbloom while (cfgets(buf, sizeof (buf), Aliases)) { 8518629Sralph p = &buf[0]; 8618629Sralph atend = 0; 8718629Sralph DEBUG(11, "Alias line: %s\n", buf); 8818629Sralph 8918629Sralph while (!atend) { 9018629Sralph while (isspace(*p) && *p != '\n') 9118629Sralph p++; /* skip white space */ 9218629Sralph q = p; 9318629Sralph while (!isspace(*q) && *q != '\n') 9418629Sralph q++; /* find end */ 9518629Sralph if (*q == '\n') 9618629Sralph atend++; /* last entry */ 9718629Sralph *q = '\0'; 9818629Sralph DEBUG(11, "Compare against: %s\n", p); 9918629Sralph if (strcmp(*hostptr, p) == 0)/* match? */ { 10023693Sbloom koshername = malloc((unsigned)strlen(buf) + 1); 10118629Sralph strcpy(koshername, buf); /* save it */ 10218629Sralph fclose(Aliases); 10318629Sralph DEBUG(4, "Alias: %s to ", *hostptr); 10418629Sralph DEBUG(4, "%s\n", koshername); 10518629Sralph *hostptr = koshername; /* correct one */ 10618629Sralph return SUCCESS; /* all is well */ 10718629Sralph } 10818629Sralph p = q + 1; /* try next entry */ 10918629Sralph } 11018629Sralph 11118629Sralph } 11218629Sralph fclose(Aliases); 11318629Sralph DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr); 11418629Sralph return SUCCESS; /* unchanged host */ 11518629Sralph } 116