113698Ssam #ifndef lint 2*23693Sbloom static char sccsid[] = "@(#)versys.c 5.4 (Berkeley) 06/23/85"; 313698Ssam #endif 413698Ssam 513698Ssam #include "uucp.h" 618629Sralph #include <stdio.h> 718629Sralph #include <ctype.h> 813698Ssam 9*23693Sbloom /*LINTLIBRARY*/ 1013698Ssam 1118629Sralph /* 1218629Sralph * verify system names n1 and n2 1318629Sralph * return codes: SUCCESS | FAIL 1413698Ssam * 1518629Sralph * NOTE: 1618629Sralph * the old calling sequence was versys(name) but is 1718629Sralph * now versys(&name) so that we can perform aliasing!!!! 1818629Sralph * See accompanying changes in uucp.c and uux.c 1918629Sralph * -- Ray Essick, April 27, 1984 2013698Ssam */ 2118629Sralph versys(nameptr) 2218629Sralph register char **nameptr; 2313698Ssam { 2413698Ssam register FILE *fp; 2518629Sralph char line[BUFSIZ]; 2618629Sralph char *name; 2713698Ssam 2818629Sralph DEBUG (11, "Before Alias: %s\n", *nameptr); 29*23693Sbloom uualias (nameptr); /* alias expansion */ 3018629Sralph DEBUG (11, "After Alias: %s\n", *nameptr); 3118629Sralph name = *nameptr; /* dereference */ 3218629Sralph 33*23693Sbloom if (strncmp(name, Myname, MAXBASENAME) == 0) 3417847Sralph return SUCCESS; 3513698Ssam 3613698Ssam fp = fopen(SYSFILE, "r"); 3717847Sralph ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0); 3813698Ssam while (cfgets(line, sizeof(line), fp) != NULL) { 3913698Ssam char *targs[100]; 4013698Ssam 4117847Sralph getargs(line, targs, 100); 42*23693Sbloom if (strncmp(name, targs[0], MAXBASENAME) == SAME) { 4313698Ssam fclose(fp); 4417847Sralph return SUCCESS; 4513698Ssam } 4613698Ssam } 4713698Ssam fclose(fp); 4817847Sralph return FAIL; 4913698Ssam } 5018629Sralph 5118629Sralph /* 5218629Sralph * Works (sort of) like rhost(3) on 4.1[abc] Bsd systems. 5318629Sralph * 5418629Sralph * Looks for the host in the L.aliases file and returns the 5518629Sralph * "standard" name by modifying the pointer. The returned 5618629Sralph * value is saved with malloc(3) so it isn't zapped by 5718629Sralph * subsequent calls. 5818629Sralph * 5918629Sralph * Returns: 6018629Sralph * FAIL No L.aliases file 6118629Sralph * SUCCESS Anything else 6218629Sralph */ 6318629Sralph 64*23693Sbloom uualias (hostptr) 6518629Sralph char **hostptr; /* we change it */ 6618629Sralph { 6718629Sralph FILE * Aliases; /* list of aliases */ 6818629Sralph char buf[BUFSIZ]; 6918629Sralph int atend; 7018629Sralph char *p, *q; 7118629Sralph char *koshername; /* "official" name */ 7218629Sralph 7318629Sralph if ((Aliases = fopen(ALIASFILE, "r")) == NULL) { 7418629Sralph DEBUG(11, "No %s file\n", ALIASFILE); 7518629Sralph return FAIL; /* no alias file */ 7618629Sralph } 7718629Sralph 7818629Sralph DEBUG (11, "Alias expansion for %s\n", *hostptr); 7918629Sralph while (fgets(buf, sizeof (buf), Aliases)) { 8018629Sralph if (buf[0] == '#') /* comment line */ 8118629Sralph continue; 8218629Sralph p = &buf[0]; 8318629Sralph atend = 0; 8418629Sralph DEBUG(11, "Alias line: %s\n", buf); 8518629Sralph 8618629Sralph while (!atend) { 8718629Sralph while (isspace(*p) && *p != '\n') 8818629Sralph p++; /* skip white space */ 8918629Sralph q = p; 9018629Sralph while (!isspace(*q) && *q != '\n') 9118629Sralph q++; /* find end */ 9218629Sralph if (*q == '\n') 9318629Sralph atend++; /* last entry */ 9418629Sralph *q = '\0'; 9518629Sralph DEBUG(11, "Compare against: %s\n", p); 9618629Sralph if (strcmp(*hostptr, p) == 0)/* match? */ { 97*23693Sbloom koshername = malloc((unsigned)strlen(buf) + 1); 9818629Sralph strcpy(koshername, buf); /* save it */ 9918629Sralph fclose(Aliases); 10018629Sralph DEBUG(4, "Alias: %s to ", *hostptr); 10118629Sralph DEBUG(4, "%s\n", koshername); 10218629Sralph *hostptr = koshername; /* correct one */ 10318629Sralph return SUCCESS; /* all is well */ 10418629Sralph } 10518629Sralph p = q + 1; /* try next entry */ 10618629Sralph } 10718629Sralph 10818629Sralph } 10918629Sralph fclose(Aliases); 11018629Sralph DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr); 11118629Sralph return SUCCESS; /* unchanged host */ 11218629Sralph } 113