xref: /csrg-svn/contrib/usr.x25/lib/verify.c (revision 45195)
1*45195Ssklower /*
2*45195Ssklower  * x25_can_callin(person)
3*45195Ssklower  * x25_can_callout(person)
4*45195Ssklower  *	Boolean functions for determining if `person'
5*45195Ssklower  * 	can charge an incoming (login) or outgoing X.25
6*45195Ssklower  *	call locally, using the file /etc/x25users.  Each line
7*45195Ssklower  *	of x25users is of the form
8*45195Ssklower  *		user [in|out]
9*45195Ssklower  *	If "in" or "out" is given, the user may place incoming
10*45195Ssklower  *	or outgoing calls only.  Otherwise, the user may place both.
11*45195Ssklower  *	Lines starting with # are comments.
12*45195Ssklower  */
13*45195Ssklower 
14*45195Ssklower #include <stdio.h>
15*45195Ssklower 
16*45195Ssklower #define CALL_OUT	(1<<0)	/* can charge outgoing calls locally */
17*45195Ssklower #define CALL_IN		(1<<1)	/* can charge incoming calls locally */
18*45195Ssklower static char Users[] = "/etc/x25users";
19*45195Ssklower 
x25_can_callout(who)20*45195Ssklower x25_can_callout(who)
21*45195Ssklower 	char *who;
22*45195Ssklower {
23*45195Ssklower 	return (lookup(who) & CALL_OUT) != 0;
24*45195Ssklower }
25*45195Ssklower 
x25_can_callin(who)26*45195Ssklower x25_can_callin(who)
27*45195Ssklower 	char *who;
28*45195Ssklower {
29*45195Ssklower 	return (lookup(who) & CALL_IN) != 0;
30*45195Ssklower }
31*45195Ssklower 
32*45195Ssklower 	static int
lookup(who)33*45195Ssklower lookup(who)
34*45195Ssklower 	char *who;
35*45195Ssklower {
36*45195Ssklower 	FILE *f;
37*45195Ssklower 	int r;
38*45195Ssklower 
39*45195Ssklower 	if ((f = fopen(Users, "r")) == NULL)
40*45195Ssklower 		return 0;
41*45195Ssklower 	r = dolookup(f, who);
42*45195Ssklower 	fclose(f);
43*45195Ssklower 	return r;
44*45195Ssklower }
45*45195Ssklower 
46*45195Ssklower 	static int
dolookup(f,who)47*45195Ssklower dolookup(f, who)
48*45195Ssklower 	FILE *f;
49*45195Ssklower 	char *who;
50*45195Ssklower {
51*45195Ssklower 	char buf[256], name[50], arg[50];
52*45195Ssklower 	int n;
53*45195Ssklower 
54*45195Ssklower 	while (fgets(buf, sizeof buf, f) != NULL) {
55*45195Ssklower 		if (buf[0] == '#')
56*45195Ssklower 			continue;
57*45195Ssklower 		n = sscanf(buf, "%s%s", name, arg);
58*45195Ssklower 		if (n < 1)
59*45195Ssklower 			continue;
60*45195Ssklower 		if (strcmp(name, who) != 0)
61*45195Ssklower 			continue;
62*45195Ssklower 		if (n == 1)
63*45195Ssklower 			return CALL_IN|CALL_OUT;
64*45195Ssklower 		if (strcmp(arg, "in") == 0)
65*45195Ssklower 			return CALL_IN;
66*45195Ssklower 		if (strcmp(arg, "out") == 0)
67*45195Ssklower 			return CALL_OUT;
68*45195Ssklower 	}
69*45195Ssklower 	return 0;
70*45195Ssklower }
71