summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-08-06 18:53:11 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-08-06 18:53:11 +0000
commitbacf033d5947c8aadcdfe98e57a5f56366d4855c (patch)
treefcc1de5b613645a5c3e8100a96e1aa64d88fcd2c /clients
parent3f91b7ff976ed513f2b221e8dd918cafcacc31f5 (diff)
Initial revision
Diffstat (limited to 'clients')
-rw-r--r--clients/znol/znol.c187
-rw-r--r--clients/zpopnotify/zpopnotify.c91
2 files changed, 278 insertions, 0 deletions
diff --git a/clients/znol/znol.c b/clients/znol/znol.c
new file mode 100644
index 0000000..df0bff1
--- /dev/null
+++ b/clients/znol/znol.c
@@ -0,0 +1,187 @@
+/* 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/mit-copyright.h>
+
+#include <zephyr/zephyr.h>
+
+#include <pwd.h>
+
+#ifndef lint
+static char rcsid_znol_c[] = "$Header$";
+#endif lint
+
+#define SUBSATONCE 7
+#define ON 1
+#define OFF 0
+
+main(argc,argv)
+ int argc;
+ char *argv[];
+{
+ 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;
+ int retval,arg,ind,wgport,one,numlocs,i;
+
+ if ((retval = ZInitialize()) != ZERR_NONE) {
+ com_err(argv[0],retval,"initializing");
+ exit (1);
+ }
+
+ envptr = (char *)getenv("WGFILE");
+ if (!envptr) {
+ sprintf(name,"/tmp/wg.%d",getuid());
+ envptr = name;
+ }
+ if (!(fp = fopen(envptr,"r"))) {
+ fprintf(stderr,"Can't find WindowGram subscription port\n");
+ exit (1);
+ }
+ fscanf(fp,"%d",&wgport);
+ fclose(fp);
+
+ envptr = (char *)getenv("HOME");
+ if (envptr)
+ strcpy(anyonename,envptr);
+ else {
+ if (!(pwd = getpwuid(getuid()))) {
+ fprintf(stderr,"Who are you?\n");
+ exit (1);
+ }
+
+ strcpy(anyonename,pwd->pw_dir);
+ }
+ strcat(anyonename,"/.anyone");
+
+ for (arg=1;arg<argc;arg++) {
+ if (!strcmp(argv[arg],"on")) {
+ onoff = ON;
+ continue;
+ }
+ if (!strcmp(argv[arg],"off")) {
+ onoff = OFF;
+ continue;
+ }
+ if (!strcmp(argv[arg],"-q")) {
+ quiet = 1;
+ continue;
+ }
+ if (!strcmp(argv[arg],"-l")) {
+ justlist = 1;
+ continue;
+ }
+ if (!strcmp(argv[arg],"-f")) {
+ if (arg == argc-1) {
+ fprintf(stderr,"No file name specified\n");
+ exit (1);
+ }
+ strcpy(anyonename,argv[++arg]);
+ continue;
+ }
+ printf("Usage: %s [on|off] [-f file]\n",argv[0]);
+ exit (1);
+ }
+
+ if (quiet && justlist) {
+ fprintf(stderr,"-q and -l cannot both be used\n");
+ exit (1);
+ }
+
+ if (!(fp = fopen(anyonename,"r"))) {
+ fprintf(stderr,"Can't open %s for input\n",anyonename);
+ exit (1);
+ }
+
+ ind = 0;
+
+ for (;;) {
+ if (!fgets(cleanname,sizeof cleanname,fp))
+ break;
+ /* Get rid of old-style nol entries, just in case */
+ cleanname[strlen(cleanname)-1] = '\0';
+ while (cleanname[strlen(cleanname)-1] == ' ')
+ cleanname[strlen(cleanname)-1] = '\0';
+ if (*cleanname == '@' || !*cleanname)
+ continue;
+ subs[ind].class = LOGIN_CLASS;
+ strcpy(name,cleanname);
+ if (!index(name,'@')) {
+ strcat(name,"@");
+ strcat(name,ZGetRealm());
+ }
+ subs[ind].classinst = (char *)malloc(strlen(name)+1);
+ strcpy(subs[ind].classinst,name);
+ subs[ind++].recipient = "";
+
+ if (!quiet && onoff == ON) {
+ if ((retval = ZLocateUser(name,&numlocs))
+ != 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].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);
+ }
+
+ fclose(fp);
+}
diff --git a/clients/zpopnotify/zpopnotify.c b/clients/zpopnotify/zpopnotify.c
new file mode 100644
index 0000000..aed159a
--- /dev/null
+++ b/clients/zpopnotify/zpopnotify.c
@@ -0,0 +1,91 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains code for the "zpopnotify" 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/mit-copyright.h>
+
+#include <zephyr/zephyr.h>
+#include <netdb.h>
+
+#ifndef lint
+static char rcsid_zpopnotify_c[] = "$Header$";
+#endif lint
+
+#define MAIL_CLASS "MAIL"
+#define MAIL_INSTANCE "POP"
+
+main(argc,argv)
+ int argc;
+ char *argv[];
+{
+ char *rindex();
+
+ ZNotice_t notice;
+ struct hostent *hent;
+ int retval;
+ char *whoami,*ptr,bfr[BUFSIZ],myhost[BUFSIZ],mysender[BUFSIZ];
+ char *lines[2];
+
+ whoami = argv[0];
+
+ if ((retval = ZInitialize()) != ZERR_NONE) {
+ com_err(whoami,retval,"while initializing");
+ exit(1);
+ }
+
+ if (argc != 2) {
+ usage(whoami);
+ exit(1);
+ }
+
+ ptr = (char *)rindex(argv[1],'/');
+ if (ptr)
+ ptr++;
+ else
+ ptr = argv[1];
+
+ if (gethostname(myhost,BUFSIZ) == -1) {
+ com_err(whoami,errno,"Can't get hostname");
+ exit(1);
+ }
+
+ if (!(hent = gethostbyname(myhost))) {
+ com_err(whoami,errno,"Can't get canonical hostname");
+ exit(1);
+ }
+
+ strcpy(myhost,hent->h_name);
+ lines[0] = myhost;
+ lines[1] = "You have new mail.";
+
+ strcpy(mysender,"pop@");
+ strcat(mysender,ZGetRealm());
+
+ notice.z_kind = UNSAFE;
+ notice.z_class = MAIL_CLASS;
+ notice.z_class_inst = MAIL_INSTANCE;
+ notice.z_opcode = "";
+ notice.z_sender = mysender;
+ notice.z_recipient = ptr;
+ notice.z_default_format = "";
+
+ if ((retval = ZSendList(&notice,lines,2,ZNOAUTH)) != ZERR_NONE) {
+ com_err(whoami,retval,"while sending notice");
+ exit(1);
+ }
+}
+
+usage(whoami)
+ char *whoami;
+{
+ printf("Usage: %s username\n",whoami);
+}