1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* This file is part of the Project Athena Zephyr Notification System.
* It contains source for the ZSetLocation, ZUnsetLocation, and
* ZFlushMyLocations functions.
*
* 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".
*/
/* $Header$ */
#ifndef lint
static char rcsid_ZLocations_c[] = "$Header$";
#endif lint
#include <zephyr/mit-copyright.h>
#include <zephyr/zephyr_internal.h>
#include <pwd.h>
#include <sys/file.h>
#include <sys/param.h>
#include <netdb.h>
uid_t getuid();
Code_t ZSetLocation(exposure)
char *exposure;
{
return (Z_SendLocation(LOGIN_CLASS,exposure,ZAUTH,
"$sender logged in to $1 on $3 at $2"));
}
Code_t ZUnsetLocation()
{
return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_LOGOUT,ZNOAUTH,
"$sender logged out of $1 on $3 at $2"));
}
Code_t ZFlushMyLocations()
{
return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_FLUSH,ZAUTH,""));
}
Z_SendLocation(class,opcode,auth,format)
char *class;
char *opcode;
int (*auth)();
char *format;
{
char *ttyname(),*ctime();
int retval;
long ourtime;
ZNotice_t notice,retnotice;
ZPacket_t buffer;
char *bptr[3],host[MAXHOSTNAMELEN],mytty[100];
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 = "";
notice.z_default_format = format;
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';
(void) strcpy(mytty,ttyname(0));
bptr[2] = rindex(mytty,'/');
if (bptr[2])
bptr[2]++;
else
bptr[2] = mytty;
if ((retval = ZSendList(¬ice,bptr,3,auth)) != ZERR_NONE)
return (retval);
if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,
(struct sockaddr_in *)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);
}
|