1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/* This file is part of the Project Athena Zephyr Notification System.
* It contains code for the "znol" command.
*
* Created by: Robert French
*
* $Source$
* $Author$
*
* Copyright (c) 1987 by the Massachusetts Institute of Technology.
* For copying and distribution information, see the file
* "mit-copyright.h".
*/
#include <zephyr/zephyr.h>
#include <pwd.h>
#include <string.h>
#ifndef lint
static char rcsid_znol_c[] = "$Id$";
#endif
#define SUBSATONCE 7
#define ON 1
#define OFF 0
#ifdef POSIX
#include <stdlib.h>
#else
extern char *getenv(), *malloc();
#endif
extern uid_t getuid();
main(argc,argv)
int argc;
register char *argv[];
{
register char *cp;
ZSubscription_t subs[SUBSATONCE];
ZLocations_t locations;
FILE *fp;
struct passwd *pwd;
char anyonename[BUFSIZ],name[BUFSIZ],cleanname[BUFSIZ],*envptr;
int onoff = ON,quiet = 0,justlist = 0,useronly = 0, filenamed = 0;
int retval,arg,ind,one,numlocs,i;
short wgport;
if ((retval = ZInitialize()) != ZERR_NONE) {
com_err(argv[0],retval,"initializing");
exit (1);
}
for (arg=1;arg<argc;arg++) {
if (!strcmp(argv[arg],"on")) {
onoff = ON;
continue;
}
if (!strcmp(argv[arg],"off")) {
onoff = OFF;
continue;
}
if (argv[arg][0] == '-') {
char opt = argv[arg][1];
if (opt == 0 || argv[arg][2] != 0)
goto usage;
switch (argv[arg][1]) {
case 'q':
quiet = 1;
break;
case 'l':
justlist = 1;
break;
case 'f':
if (arg == argc-1) {
fprintf(stderr,"No file name specified\n");
goto usage;
}
(void) strcpy(anyonename,argv[++arg]);
filenamed = 1;
break;
case 'u':
if (arg == argc-1) {
fprintf(stderr,"No username specified\n");
goto usage;
}
(void) strcpy(cleanname,argv[++arg]);
useronly = 1;
break;
default:
goto usage;
}
continue;
}
usage:
fprintf(stderr,"Usage: %s [on|off] [-q | -l] [-f file | -u username]\n", argv[0]);
exit (1);
}
if (quiet && justlist) {
fprintf(stderr,"-q and -l cannot both be used\n");
goto usage;
}
if (useronly && filenamed) {
fprintf(stderr,"-u and -f cannot both be used\n");
goto usage;
}
if (!justlist)
if ((wgport = ZGetWGPort()) == -1) {
com_err(argv[0],errno,"while getting WindowGram port");
exit(1);
}
if (!useronly) {
/* If no filename specified, get the default */
if (!filenamed) {
envptr = getenv("HOME");
if (envptr)
(void) strcpy(anyonename,envptr);
else {
if (!(pwd = getpwuid((int) getuid()))) {
fprintf(stderr,"You are not listed in the password file.\n");
exit (1);
}
(void) strcpy(anyonename,pwd->pw_dir);
}
(void) strcat(anyonename,"/.anyone");
}
/* if the filename is "-", read stdin */
if (strcmp(anyonename,"-") == 0) {
fp = stdin;
} else if (!(fp = fopen(anyonename,"r"))) {
fprintf(stderr,"Can't open %s for input\n",anyonename);
exit (1);
}
}
ind = 0;
for (;;) {
if (!useronly) {
if (!fgets(cleanname,sizeof cleanname,fp))
break;
if (cleanname[0] == '#' || cleanname[0] == '\0' ||
cleanname[0] == '\n')
continue; /* ignore comment and empty lines */
/* Get rid of old-style nol entries, just in case */
cp = cleanname + strlen(cleanname) - 1;
*cp = '\0';
while(*--cp == ' ')
*cp = '\0';
if (*cleanname == '@' || !*cleanname)
continue;
} else if (ind)
break; /* only do the one name */
subs[ind].zsub_class = LOGIN_CLASS;
(void) strcpy(name,cleanname);
if (!index(name,'@')) {
cp = name + strlen(name);
*cp++ = '@';
(void) strcpy(cp,ZGetRealm());
}
if ((subs[ind].zsub_classinst = malloc((unsigned)(strlen(name)+1))) == NULL) {
fprintf (stderr, "znol: out of memory");
exit (1);
}
(void) strcpy(subs[ind].zsub_classinst, name);
subs[ind++].zsub_recipient = "";
if (!quiet && onoff == ON) {
if ((retval = ZLocateUser(name,&numlocs,ZAUTH))
!= ZERR_NONE) {
com_err(argv[0],retval,"locating user");
exit(1);
}
one = 1;
if (numlocs) {
for (i=0;i<numlocs;i++) {
if ((retval =
ZGetLocations(&locations,&one))
!= ZERR_NONE) {
com_err(argv[0],retval,
"getting location");
continue;
}
if (one != 1) {
printf("%s: internal failure while getting location\n",argv[0]);
exit(1);
}
printf("%s: %s\t%s\t%s\n",cleanname,
locations.host,
locations.tty,
locations.time);
}
}
}
if (ind == SUBSATONCE) {
if (!justlist)
if ((retval = (onoff==ON)?
ZSubscribeTo(subs,ind,(u_short)wgport):
ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
ZERR_NONE) {
com_err(argv[0],retval,(onoff==ON)?
"subscribing":
"unsubscribing");
exit(1);
}
for (ind=0;ind<SUBSATONCE;ind++)
free(subs[ind].zsub_classinst);
ind = 0;
}
}
if (ind && !justlist)
if ((retval = (onoff==ON)?
ZSubscribeTo(subs,ind,(u_short)wgport):
ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
ZERR_NONE) {
com_err(argv[0],retval,(onoff==ON)?
"subscribing":
"unsubscribing");
exit(1);
}
if (!useronly)
(void) fclose(fp); /* file is open read-only,
ignore errs */
exit(0);
}
|