xref: /csrg-svn/usr.bin/uucp/libuu/versys.c (revision 25148)
113698Ssam #ifndef lint
2*25148Sbloom static char sccsid[] = "@(#)versys.c	5.5 (Berkeley) 10/09/85";
313698Ssam #endif
413698Ssam 
513698Ssam #include "uucp.h"
618629Sralph #include <stdio.h>
718629Sralph #include <ctype.h>
813698Ssam 
923693Sbloom /*LINTLIBRARY*/
1013698Ssam 
11*25148Sbloom char PhoneNumber[MAXPH];
12*25148Sbloom 
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 
3523693Sbloom 	if (strncmp(name, Myname, MAXBASENAME) == 0)
3617847Sralph 		return SUCCESS;
3713698Ssam 
3813698Ssam 	fp = fopen(SYSFILE, "r");
3917847Sralph 	ASSERT(fp != NULL, CANTOPEN, SYSFILE, 0);
40*25148Sbloom 	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*25148Sbloom 			strncpy(PhoneNumber, targs[F_PHONE], MAXPH);
4817847Sralph 			return SUCCESS;
4913698Ssam 		}
5013698Ssam 	}
5113698Ssam 	fclose(fp);
5217847Sralph 	return FAIL;
5313698Ssam }
5418629Sralph 
5518629Sralph /*
5618629Sralph  *	Works (sort of) like rhost(3) on 4.1[abc] Bsd systems.
5718629Sralph  *
5818629Sralph  *	Looks for the host in the L.aliases file and returns the
5918629Sralph  *	"standard" name by modifying the pointer. The returned
6018629Sralph  *	value is saved with malloc(3) so it isn't zapped by
6118629Sralph  *	subsequent calls.
6218629Sralph  *
6318629Sralph  *	Returns:
6418629Sralph  *		FAIL		No L.aliases file
6518629Sralph  *		SUCCESS		Anything else
6618629Sralph  */
6718629Sralph 
68*25148Sbloom uualias(hostptr)
6918629Sralph char  **hostptr;			  /* we change it */
7018629Sralph {
71*25148Sbloom 	FILE *Aliases;			  /* list of aliases */
7218629Sralph 	char buf[BUFSIZ];
7318629Sralph 	int atend;
7418629Sralph 	char *p, *q;
7518629Sralph 	char *koshername;		 /* "official" name */
7618629Sralph 
7718629Sralph 	if ((Aliases = fopen(ALIASFILE, "r")) == NULL) {
7818629Sralph 		DEBUG(11, "No %s file\n", ALIASFILE);
7918629Sralph 		return FAIL;			  /* no alias file */
8018629Sralph 	}
8118629Sralph 
8218629Sralph 	DEBUG (11, "Alias expansion for %s\n", *hostptr);
83*25148Sbloom 	while (cfgets(buf, sizeof (buf), Aliases)) {
8418629Sralph 		p = &buf[0];
8518629Sralph 		atend = 0;
8618629Sralph 		DEBUG(11, "Alias line: %s\n", buf);
8718629Sralph 
8818629Sralph 		while (!atend) {
8918629Sralph 			while (isspace(*p) && *p != '\n')
9018629Sralph 				p++;			  /* skip white space */
9118629Sralph 			q = p;
9218629Sralph 			while (!isspace(*q) && *q != '\n')
9318629Sralph 				q++;			  /* find end */
9418629Sralph 			if (*q == '\n')
9518629Sralph 				atend++;		  /* last entry */
9618629Sralph 			*q = '\0';
9718629Sralph 			DEBUG(11, "Compare against: %s\n", p);
9818629Sralph 			if (strcmp(*hostptr, p) == 0)/* match? */ {
9923693Sbloom 				koshername = malloc((unsigned)strlen(buf) + 1);
10018629Sralph 				strcpy(koshername, buf); /* save it */
10118629Sralph 				fclose(Aliases);
10218629Sralph 				DEBUG(4, "Alias: %s to ", *hostptr);
10318629Sralph 				DEBUG(4, "%s\n", koshername);
10418629Sralph 				*hostptr = koshername;	  /* correct one */
10518629Sralph 				return SUCCESS;		  /* all is well */
10618629Sralph 			}
10718629Sralph 			p = q + 1;			  /* try next entry */
10818629Sralph 		}
10918629Sralph 
11018629Sralph 	}
11118629Sralph 	fclose(Aliases);
11218629Sralph 	DEBUG(11, "Alias doesn't match %s, remains unchanged\n", *hostptr);
11318629Sralph 	return SUCCESS;				  /* unchanged host */
11418629Sralph }
115