summaryrefslogtreecommitdiff
path: root/lib/ZLocations.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-07-05 22:09:03 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-07-05 22:09:03 +0000
commit6d052aeba968f16100de9e59add743abcfb06094 (patch)
tree368c868683b79102cca00e89abbe29987573e639 /lib/ZLocations.c
parent63e063c0681783c90e604aa788dc4e9e52f0719b (diff)
safety
Diffstat (limited to 'lib/ZLocations.c')
-rw-r--r--lib/ZLocations.c87
1 files changed, 86 insertions, 1 deletions
diff --git a/lib/ZLocations.c b/lib/ZLocations.c
index 76c80e5..e831eaf 100644
--- a/lib/ZLocations.c
+++ b/lib/ZLocations.c
@@ -1,5 +1,6 @@
/* This file is part of the Project Athena Zephyr Notification System.
- * It contains source for the ZSetLocation function.
+ * It contains source for the ZSetLocation, ZUnsetLocation, ZHideLocation,
+ * and ZUnhideLocation functions.
*
* Created by: Robert French
*
@@ -18,6 +19,8 @@
#include <pwd.h>
#include <sys/file.h>
+#include <sys/param.h>
+#include <netdb.h>
uid_t getuid();
@@ -37,3 +40,85 @@ Code_t ZSetLocation()
return (Z_SendLocation(LOGIN_CLASS,quiet?LOGIN_QUIET_LOGIN:
LOGIN_USER_LOGIN));
}
+
+Code_t ZUnsetLocation()
+{
+ return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_LOGOUT));
+}
+
+Code_t ZHideLocation()
+{
+ return (Z_SendLocation(LOCATE_CLASS,LOCATE_HIDE));
+}
+
+Code_t ZUnhideLocation()
+{
+ return (Z_SendLocation(LOCATE_CLASS,LOCATE_UNHIDE));
+}
+
+Z_SendLocation(class,opcode)
+ char *class;
+ char *opcode;
+{
+ char *ttyname(),*ctime();
+
+ int retval;
+ long ourtime;
+ ZNotice_t notice,retnotice;
+ ZPacket_t buffer;
+ char *bptr[2],host[MAXHOSTNAMELEN];
+ struct hostent *hent;
+
+ notice.z_kind = ACKED;
+ notice.z_port = 0;
+ notice.z_class = class;
+ notice.z_class_inst = ZGetSender();
+ notice.z_opcode = opcode;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+
+ if (gethostname(host,MAXHOSTNAMELEN) < 0)
+ return (errno);
+
+ hent = gethostbyname(host);
+ if (!hent)
+ bptr[0] = "unknown";
+ else {
+ (void) strcpy(host,hent->h_name);
+ bptr[0] = host;
+ }
+
+ ourtime = time((long *)0);
+ bptr[1] = ctime(&ourtime);
+ bptr[1][strlen(bptr[1])-1] = '\0';
+
+ if ((retval = ZSendList(&notice,bptr,2,ZAUTH)) != ZERR_NONE)
+ return (retval);
+
+ if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,(int *)0,
+ ZCompareUIDPred,(char *)&notice.z_uid)) !=
+ ZERR_NONE)
+ return (retval);
+
+ if (retnotice.z_kind == SERVNAK) {
+ if (!retnotice.z_message_len)
+ return (ZERR_SERVNAK);
+ if (!strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
+ return (ZERR_AUTHFAIL);
+ if (!strcmp(retnotice.z_message,ZSRVACK_FAIL))
+ return (ZERR_LOGINFAIL);
+ return (ZERR_SERVNAK);
+ }
+
+ if (retnotice.z_kind != SERVACK)
+ return (ZERR_INTERNAL);
+
+ if (!retnotice.z_message_len)
+ return (ZERR_INTERNAL);
+
+ if (strcmp(retnotice.z_message,ZSRVACK_SENT) &&
+ strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
+ return (ZERR_INTERNAL);
+
+ return (ZERR_NONE);
+}