From 6d052aeba968f16100de9e59add743abcfb06094 Mon Sep 17 00:00:00 2001 From: "Robert S. French" Date: Sun, 5 Jul 1987 22:09:03 +0000 Subject: safety --- lib/ZLocations.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'lib/ZLocations.c') 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 #include +#include +#include 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(¬ice,bptr,2,ZAUTH)) != ZERR_NONE) + return (retval); + + if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,(int *)0, + ZCompareUIDPred,(char *)¬ice.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); +} -- cgit v1.2.3