1*48652Sbostic /*- 2*48652Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48652Sbostic * All rights reserved. 4*48652Sbostic * 5*48652Sbostic * %sccs.include.proprietary.c% 6*48652Sbostic */ 7*48652Sbostic 813698Ssam #ifndef lint 9*48652Sbostic static char sccsid[] = "@(#)versys.c 5.8 (Berkeley) 04/24/91"; 10*48652Sbostic #endif /* not lint */ 1113698Ssam 1213698Ssam #include "uucp.h" 1318629Sralph #include <stdio.h> 1418629Sralph #include <ctype.h> 1513698Ssam 1623693Sbloom /*LINTLIBRARY*/ 1713698Ssam 1825148Sbloom char PhoneNumber[MAXPH]; 1925148Sbloom 2018629Sralph /* 2118629Sralph * verify system names n1 and n2 2218629Sralph * return codes: SUCCESS | FAIL 2313698Ssam * 2418629Sralph * NOTE: 2518629Sralph * the old calling sequence was versys(name) but is 2618629Sralph * now versys(&name) so that we can perform aliasing!!!! 2718629Sralph * See accompanying changes in uucp.c and uux.c 2818629Sralph * -- Ray Essick, April 27, 1984 2913698Ssam */ 3018629Sralph versys(nameptr) 3118629Sralph register char **nameptr; 3213698Ssam { 3313698Ssam register FILE *fp; 3418629Sralph char line[BUFSIZ]; 3518629Sralph char *name; 3613698Ssam 3718629Sralph DEBUG (11, "Before Alias: %s\n", *nameptr); 3823693Sbloom uualias (nameptr); /* alias expansion */ 3918629Sralph DEBUG (11, "After Alias: %s\n", *nameptr); 4018629Sralph name = *nameptr; /* dereference */ 4118629Sralph 4233580Srick if (name[0] == '\0' || strncmp(name, Myname, MAXBASENAME) == 0) 4317847Sralph return SUCCESS; 4413698Ssam 4513698Ssam fp = fopen(SYSFILE, "r"); 4633967Srick if (fp == NULL) { 4733967Srick syslog(LOG_ERR, "fopen(%s) failed: %m", SYSFILE); 4833967Srick cleanup(FAIL); 4933967Srick } 5025148Sbloom PhoneNumber[0] = '\0'; 5113698Ssam while (cfgets(line, sizeof(line), fp) != NULL) { 5213698Ssam char *targs[100]; 5313698Ssam 5417847Sralph getargs(line, targs, 100); 5523693Sbloom if (strncmp(name, targs[0], MAXBASENAME) == SAME) { 5613698Ssam fclose(fp); 5733580Srick if (targs[F_PHONE]) 5833580Srick strncpy(PhoneNumber, targs[F_PHONE], MAXPH); 5917847Sralph return SUCCESS; 6013698Ssam } 6113698Ssam } 6213698Ssam fclose(fp); 6317847Sralph return FAIL; 6413698Ssam } 6518629Sralph 6618629Sralph /* 6718629Sralph * Works (sort of) like rhost(3) on 4.1[abc] Bsd systems. 6818629Sralph * 6918629Sralph * Looks for the host in the L.aliases file and returns the 7018629Sralph * "standard" name by modifying the pointer. The returned 7118629Sralph * value is saved with malloc(3) so it isn't zapped by 7218629Sralph * subsequent calls. 7318629Sralph * 7418629Sralph * Returns: 7518629Sralph * FAIL No L.aliases file 7618629Sralph * SUCCESS Anything else 7718629Sralph */ 7818629Sralph 7925148Sbloom uualias(hostptr) 8018629Sralph char **hostptr; /* we change it */ 8118629Sralph { 8225148Sbloom FILE *Aliases; /* list of aliases */ 8318629Sralph char buf[BUFSIZ]; 8418629Sralph int atend; 8518629Sralph char *p, *q; 8618629Sralph char *koshername; /* "official" name */ 8718629Sralph 8818629Sralph if ((Aliases = fopen(ALIASFILE, "r")) == NULL) { 8918629Sralph DEBUG(11, "No %s file\n", ALIASFILE); 9018629Sralph return FAIL; /* no alias file */ 9118629Sralph } 9218629Sralph 9318629Sralph DEBUG (11, "Alias expansion for %s\n", *hostptr); 9425148Sbloom while (cfgets(buf, sizeof (buf), Aliases)) { 9518629Sralph p = &buf[0]; 9618629Sralph atend = 0; 9718629Sralph DEBUG(11, "Alias line: %s\n", buf); 9818629Sralph 9918629Sralph while (!atend) { 10018629Sralph while (isspace(*p) && *p != '\n') 10118629Sralph p++; /* skip white space */ 10218629Sralph q = p; 10318629Sralph while (!isspace(*q) && *q != '\n') 10418629Sralph q++; /* find end */ 10518629Sralph if (*q == '\n') 10618629Sralph atend++; /* last entry */ 10718629Sralph *q = '\0'; 10818629Sralph DEBUG(11, "Compare against: %s\n", p); 10918629Sralph if (strcmp(*hostptr, p) == 0)/* match? */ { 11023693Sbloom koshername = malloc((unsigned)strlen(buf) + 1); 11118629Sralph strcpy(koshername, buf); /* save it */ 11218629Sralph fclose(Aliases); 11318629Sralph DEBUG(4, "Alias: %s to ", *hostptr); 11418629Sralph DEBUG(4, "%s\n", koshername); 11518629Sralph *hostptr = koshername; /* correct one */ 11618629Sralph return SUCCESS; /* all is well */ 11718629Sralph } 11818629Sralph p = q + 1; /* try next entry */ 11918629Sralph } 12018629Sralph 12118629Sralph } 12218629Sralph fclose(Aliases); 12318629Sralph DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr); 12418629Sralph return SUCCESS; /* unchanged host */ 12518629Sralph } 126