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
|
/* This file is part of the Project Athena Zephyr Notification System.
* It contains source for the ZSetLocation, ZUnsetLocation, ZHideLocation,
* and ZUnhideLocation 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$ */
#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()
{
char bfr[BUFSIZ];
int quiet;
struct passwd *pw;
quiet = 0;
/* XXX a uid_t is a u_short (now), but getpwuid wants an int. AARGH! */
if (pw = getpwuid((int) getuid())) {
(void) sprintf(bfr,"%s/.hideme",pw->pw_dir);
quiet = !access(bfr,F_OK);
}
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);
}
|