1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZSetLocation, ZUnsetLocation, and
3 * ZFlushMyLocations functions.
5 * Created by: Robert French
7 * $Id: ZLocations.c 2422 2009-04-14 12:57:11Z kcr@ATHENA.MIT.EDU $
9 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
15 static const char rcsid_ZLocations_c[] =
16 "$Id: ZLocations.c 2422 2009-04-14 12:57:11Z kcr@ATHENA.MIT.EDU $";
23 static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN];
24 static int location_info_set = 0;
27 ZInitLocationInfo(char *hostname,
34 strcpy(host, hostname);
36 if (gethostname(host, MAXHOSTNAMELEN) < 0)
38 hent = gethostbyname(host);
40 (void) strncpy(host, hent->h_name, sizeof(host));
41 host[sizeof(host) - 1] = '\0';
49 p = strchr(ttyp + 1, '/');
50 strcpy(mytty, (p) ? p + 1 : ttyp);
52 strcpy(mytty, "unknown");
55 location_info_set = 1;
60 ZSetLocation(char *exposure)
62 return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH,
63 "$sender logged in to $1 on $3 at $2"));
69 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH,
70 "$sender logged out of $1 on $3 at $2"));
74 ZFlushMyLocations(void)
76 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
80 ZParseExposureLevel(char *text)
82 if (!strcasecmp(text, EXPOSE_NONE))
84 else if (!strcasecmp(text, EXPOSE_OPSTAFF))
85 return (EXPOSE_OPSTAFF);
86 else if (!strcasecmp(text, EXPOSE_REALMVIS))
87 return (EXPOSE_REALMVIS);
88 else if (!strcasecmp(text, EXPOSE_REALMANN))
89 return (EXPOSE_REALMANN);
90 else if (!strcasecmp(text, EXPOSE_NETVIS))
91 return (EXPOSE_NETVIS);
92 else if (!strcasecmp(text, EXPOSE_NETANN))
93 return (EXPOSE_NETANN);
98 /* lifted from lib/ZSendPkt.c wait_for_hmack, but waits for SERVACK instead */
100 wait_for_srvack(ZNotice_t *notice, void *uid)
102 return (notice->z_kind == SERVACK && ZCompareUID(¬ice->z_uid, (ZUnique_Id_t *)uid));
106 Z_SendLocation(char *class,
113 ZNotice_t notice, retnotice;
115 short wg_port = ZGetWGPort();
117 if (!location_info_set)
118 ZInitLocationInfo(NULL, NULL);
120 memset((char *)¬ice, 0, sizeof(notice));
121 notice.z_kind = ACKED;
122 notice.z_port = (u_short) ((wg_port == -1) ? 0 : wg_port);
123 notice.z_class = class;
124 notice.z_class_inst = ZGetSender();
125 notice.z_opcode = opcode;
127 notice.z_recipient = "";
128 notice.z_num_other_fields = 0;
129 notice.z_default_format = format;
132 ourtime = time((time_t *)0);
133 bptr[1] = ctime(&ourtime);
134 bptr[1][strlen(bptr[1])-1] = '\0';
137 if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE)
140 retval = Z_WaitForNotice (&retnotice, wait_for_srvack, ¬ice.z_uid,
142 if (retval != ZERR_NONE)
145 if (retnotice.z_kind == SERVNAK) {
146 if (!retnotice.z_message_len) {
147 ZFreeNotice(&retnotice);
148 return (ZERR_SERVNAK);
150 if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
151 ZFreeNotice(&retnotice);
152 return (ZERR_AUTHFAIL);
154 if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) {
155 ZFreeNotice(&retnotice);
156 return (ZERR_LOGINFAIL);
158 ZFreeNotice(&retnotice);
159 return (ZERR_SERVNAK);
162 if (retnotice.z_kind != SERVACK) {
163 ZFreeNotice(&retnotice);
164 return (ZERR_INTERNAL);
167 if (!retnotice.z_message_len) {
168 ZFreeNotice(&retnotice);
169 return (ZERR_INTERNAL);
172 if (strcmp(retnotice.z_message, ZSRVACK_SENT) &&
173 strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
174 ZFreeNotice(&retnotice);
175 return (ZERR_INTERNAL);
178 ZFreeNotice(&retnotice);