1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains code for the "znol" command.
4 * Created by: Robert French
8 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
14 #include <zephyr/zephyr.h>
19 static const char rcsid_znol_c[] = "$Id$";
31 ZSubscription_t subs[SUBSATONCE];
32 ZLocations_t locations;
35 char anyonename[BUFSIZ],name[BUFSIZ],cleanname[BUFSIZ],*envptr;
37 int onoff = ON,quiet = 0,justlist = 0,useronly = 0, filenamed = 0;
38 int retval,arg,ind,one,numlocs,i;
41 if ((retval = ZInitialize()) != ZERR_NONE) {
42 com_err(argv[0],retval,"initializing");
46 for (arg=1;arg<argc;arg++) {
47 if (!strcmp(argv[arg],"on")) {
51 if (!strcmp(argv[arg],"off")) {
55 if (argv[arg][0] == '-') {
56 char opt = argv[arg][1];
57 if (opt == 0 || argv[arg][2] != 0)
59 switch (argv[arg][1]) {
68 fprintf(stderr,"No file name specified\n");
71 (void) strcpy(anyonename,argv[++arg]);
76 fprintf(stderr,"No username specified\n");
79 (void) strcpy(cleanname,argv[++arg]);
88 fprintf(stderr,"Usage: %s [on|off] [-q | -l] [-f file | -u username]\n", argv[0]);
92 if (quiet && justlist) {
93 fprintf(stderr,"-q and -l cannot both be used\n");
96 if (useronly && filenamed) {
97 fprintf(stderr,"-u and -f cannot both be used\n");
101 if ((wgport = ZGetWGPort()) == -1) {
102 com_err(argv[0],errno,"while getting WindowGram port");
107 /* If no filename specified, get the default */
109 envptr = getenv("HOME");
111 (void) strcpy(anyonename,envptr);
113 if (!(pwd = getpwuid((int) getuid()))) {
114 fprintf(stderr,"You are not listed in the password file.\n");
117 (void) strcpy(anyonename,pwd->pw_dir);
119 (void) strcat(anyonename,"/.anyone");
122 /* if the filename is "-", read stdin */
123 if (strcmp(anyonename,"-") == 0) {
125 } else if (!(fp = fopen(anyonename,"r"))) {
126 fprintf(stderr,"Can't open %s for input\n",anyonename);
135 if (!fgets(cleanname,sizeof cleanname,fp))
137 if (cleanname[0] == '#' || cleanname[0] == '\0' ||
138 cleanname[0] == '\n')
139 continue; /* ignore comment and empty lines */
140 comment_ptr = strchr(cleanname, '#');
142 *comment_ptr = '\0'; /* Ignore from # onwards */
143 /* Get rid of old-style nol entries, just in case */
144 cp = cleanname + strlen(cleanname) - 1;
148 if (*cleanname == '@' || !*cleanname)
151 break; /* only do the one name */
153 subs[ind].zsub_class = LOGIN_CLASS;
154 (void) strcpy(name,cleanname);
155 if (!strchr(name,'@')) {
156 cp = name + strlen(name);
158 (void) strcpy(cp,ZGetRealm());
160 if ((subs[ind].zsub_classinst = malloc((unsigned)(strlen(name)+1))) == NULL) {
161 fprintf (stderr, "znol: out of memory");
164 (void) strcpy(subs[ind].zsub_classinst, name);
165 subs[ind++].zsub_recipient = "";
167 if (!quiet && onoff == ON) {
168 if ((retval = ZLocateUser(name,&numlocs,ZAUTH))
170 com_err(argv[0],retval,"locating user");
175 for (i=0;i<numlocs;i++) {
177 ZGetLocations(&locations,&one))
179 com_err(argv[0],retval,
184 printf("%s: internal failure while getting location\n",argv[0]);
187 printf("%s: %s\t%s\t%s\n",cleanname,
195 if (ind == SUBSATONCE) {
197 if ((retval = (onoff==ON)?
198 ZSubscribeToSansDefaults(subs,ind,
200 ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
202 com_err(argv[0],retval,(onoff==ON)?
207 for (ind=0;ind<SUBSATONCE;ind++)
208 free(subs[ind].zsub_classinst);
213 if (ind && !justlist)
214 if ((retval = (onoff==ON)?
215 ZSubscribeToSansDefaults(subs,ind,(u_short)wgport):
216 ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
218 com_err(argv[0],retval,(onoff==ON)?
225 (void) fclose(fp); /* file is open read-only,