summaryrefslogtreecommitdiff
path: root/h/zephyr/zephyr.h
blob: 50c6b43002743aafea6a72422f403b00d6e8c358 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* This file is part of the Project Athena Zephyr Notification System.
 * It contains global definitions
 *
 *	Created by:	Robert French
 *
 *	$Source$
 *	$Author$
 *	$Id$
 *
 *	Copyright (c) 1987,1988,1991 by the Massachusetts Institute of
 *	Technology. For copying and distribution information, see the
 *	file "mit-copyright.h".
 */

#ifndef __ZEPHYR_H__
#define __ZEPHYR_H__

#include <zephyr/zephyr_conf.h>
#include <zephyr/zephyr_err.h>

#include <errno.h>
#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

#ifndef va_start /* guaranteed to be a macro */
#if defined(__STDC__) && !defined(ibm032) &&!defined(SABER)
#include <stdarg.h>
#else
#include <varargs.h>
#define Z_varargs
#endif
#endif

#ifdef Z_HaveKerberos
#include <krb.h>
#endif

#ifndef IPPROTO_MAX	/* Make sure not already included */
#include <netinet/in.h>
#endif

#if defined(__STDC__)
#define Zproto(X) X
#define Zconst const
#else
#define Zproto(X) ()
#define Zconst /* const */
#endif

#define ZVERSIONHDR	"ZEPH"
#define ZVERSIONMAJOR	0
#define ZVERSIONMINOR	2

    /* Types */

    /* Maximum size packet we can send */
#define Z_MAXPKTLEN		1024

    /* Packet */
    typedef char ZPacket_t[Z_MAXPKTLEN];

    /* Maximum size for a notice header */
#define Z_MAXHEADERLEN		800

    /* Maximum number of unknown fields in ZNotice_t */
#define Z_MAXOTHERFIELDS	10

    /* Authentication levels returned by ZCheckAuthentication */
#define ZAUTH_FAILED    	(-1)
#define ZAUTH_YES       	1
#define ZAUTH_NO        	0
#define ZAUTH_CKSUM_FAILED	(-2) /* Used only by server. */
#define ZAUTH_UNSET		(-3) /* Internal to client library. */

    /* Packet type */
    typedef enum { UNSAFE, UNACKED, ACKED, HMACK, HMCTL, SERVACK, SERVNAK,
		       CLIENTACK, STAT } ZNotice_Kind_t;
    extern Zconst char *ZNoticeKinds[9];

    /* Unique ID format */
    typedef struct _ZUnique_Id_t {
	struct	in_addr zuid_addr;
	struct	timeval	tv;
    } ZUnique_Id_t;

    /* Checksum */
    typedef u_long ZChecksum_t;

#define ZNUMFIELDS	17

    /* Notice definition */
    typedef struct _ZNotice_t {
	char		*z_packet;
	char		*z_version;
	ZNotice_Kind_t	z_kind;
	ZUnique_Id_t	z_uid;
#define z_sender_addr	z_uid.zuid_addr
	struct		timeval z_time;
	u_short		z_port;
	int		z_auth;
	int		z_checked_auth;
	int		z_authent_len;
	char		*z_ascii_authent;
	char		*z_class;
	char		*z_class_inst;
	char		*z_opcode;
	char		*z_sender;
	char		*z_recipient;
	char		*z_default_format;
	char		*z_multinotice;
	ZUnique_Id_t	z_multiuid;
	ZChecksum_t	z_checksum;
	int		z_num_other_fields;
	char		*z_other_fields[Z_MAXOTHERFIELDS];
	caddr_t		z_message;
	int		z_message_len;
    } ZNotice_t;

    /* Subscription structure */
    typedef struct _ZSubscriptions_t {
	char	*zsub_recipient;
	/* The following field used to be named "class", but that
	   conflicts with C++ */
	char	*zsub_class;
	char	*zsub_classinst;
    } ZSubscription_t;

    /* Function return code */
    typedef int Code_t;

    /* Locations structure */
    typedef struct _ZLocations_t {
	char	*host;
	char	*time;
	char	*tty;
    } ZLocations_t;

    typedef struct _ZAsyncLocateData_t {
      char		*user;
      ZUnique_Id_t	uid;
      char		*version;
    } ZAsyncLocateData_t;

    /* Predicate for async locate */
    extern int ZCompareALDPred Zproto((ZNotice_t *, char *));

    /* Socket file descriptor */
    extern int __Zephyr_fd;

    /* Port number */
    extern int __Zephyr_port;

    /* Destination (hostmanager, usually) addr */
    extern struct sockaddr_in __HM_addr;

    /* for ZQLength */
    extern int __Q_CompleteLength;

    /* UNIX error codes */
    extern int errno;

    /* for ZSetDebug */
#ifdef Z_DEBUG
    extern void (*__Z_debug_print) Zproto((const char *fmt, va_list args,
					   void *closure));
    extern void *__Z_debug_print_closure;
#endif

#ifdef Z_HaveKerberos
    /* Kerberos error table base */
    extern int krb_err_base;

    /* for ZGetRealm */
    extern char __Zephyr_realm[];

    /* Session key for last parsed packet - server only */
    extern C_Block __Zephyr_session;
#else
    /* for ZGetRealm -- you can change this, if you care... */
#define __Zephyr_realm ("local-realm")
#endif

    /* ZCompareUIDPred definition */
    extern int ZCompareUIDPred Zproto((ZNotice_t *, ZUnique_Id_t *)),
	       ZCompareMultiUIDPred Zproto((ZNotice_t *, ZUnique_Id_t *));

    /* Defines for ZFormatNotice, et al. */
    typedef Code_t (*Z_AuthProc) Zproto((ZNotice_t*, char *, int, int *));
    extern Code_t ZMakeAuthentication Zproto((ZNotice_t*, char *,int, int*));

    /* Random declarations */
    extern char *ZGetSender Zproto((void)), *ZGetVariable Zproto((char *));
    extern int ZGetWGPort Zproto((void));
    extern Code_t ZSetDestAddr Zproto ((struct sockaddr_in *));
    extern Code_t ZFormatNoticeList Zproto((ZNotice_t*, char**, int,
					    char **, int*, Z_AuthProc));
    extern Code_t ZParseNotice Zproto((char*, int, ZNotice_t *));
    extern Code_t ZReadAscii Zproto((char*, int, unsigned char*, int));
    extern Code_t ZSendPacket Zproto((char*, int, int));
    extern Code_t ZSendList Zproto((ZNotice_t*, char *[], int, Z_AuthProc));
    extern Code_t ZFormatNotice Zproto((ZNotice_t*, char**, int*, Z_AuthProc));
    extern Code_t ZFormatSmallNotice Zproto ((ZNotice_t*, ZPacket_t, int*,
					      Z_AuthProc));
    extern Code_t ZLocateUser Zproto((char *, int *, Z_AuthProc));
    extern Code_t ZRequestLocations Zproto((char *, ZAsyncLocateData_t *, ZNotice_Kind_t, Z_AuthProc));
    extern Code_t ZInitialize Zproto ((void));
    extern Code_t ZSetServerState Zproto((int));
    extern Code_t ZSetFD Zproto ((int));
    extern Code_t ZFormatSmallRawNotice Zproto ((ZNotice_t*, ZPacket_t, int*));
    extern int ZCompareUID Zproto ((ZUnique_Id_t*, ZUnique_Id_t*));
    extern Code_t ZSrvSendRawList Zproto ((ZNotice_t*, char*[], int,
					   Code_t (*)(ZNotice_t *, char *,
						      int, int)));
    extern Code_t ZMakeAscii Zproto ((char*, int, unsigned char*, int));
    extern Code_t ZReceivePacket Zproto ((ZPacket_t, int*,
					  struct sockaddr_in*));
    extern Code_t ZCheckAuthentication Zproto ((ZNotice_t*,
						struct sockaddr_in*));
#ifdef Z_HaveKerberos
    extern Code_t ZFormatAuthenticNotice Zproto ((ZNotice_t*, char*, int,
						  int*, C_Block));
#endif
    extern Code_t ZFormatRawNotice Zproto ((ZNotice_t *, char**, int *));
#ifdef Z_DEBUG
#ifndef Z_varargs
    extern void Z_debug Zproto ((const char *, ...));
#else
    extern void Z_debug ();
#endif
#endif

    /* Compatibility */
#define	ZNewLocateUser ZLocateUser

#ifdef Z_HaveKerberos
    /* ZGetSession() macro */
#define ZGetSession() (__Zephyr_session)
#endif

    /* ZGetFD() macro */
    extern int ZGetFD ();
#define ZGetFD() __Zephyr_fd

    /* ZQLength macro */
    extern int ZQLength ();
#define ZQLength() __Q_CompleteLength

    /* ZGetDestAddr() macro */
    extern struct sockaddr_in ZGetDestAddr ();
#define ZGetDestAddr() __HM_addr

    /* ZGetRealm() macro */
    extern Zconst char * ZGetRealm ();
#define ZGetRealm() __Zephyr_realm

    /* ZSetDebug() macro */
#ifdef Z_DEBUG
    extern void ZSetDebug Zproto ((void (*)(const char *, va_list, void *),
				   void *));
#define ZSetDebug(proc,closure)    (__Z_debug_print=(proc), \
				    __Z_debug_print_closure=(closure), \
				    (void) 0)
#else
#define	ZSetDebug(proc,closure)
#endif

    /* Maximum queue length */
#define Z_MAXQLEN 		30

    /* Successful function return */
#define ZERR_NONE		0

    /* Hostmanager wait time (in secs) */
#define HM_TIMEOUT		10

    /* Server wait time (in secs) */
#define	SRV_TIMEOUT		30

#define ZAUTH (ZMakeAuthentication)
#define ZNOAUTH ((Z_AuthProc)0)

    /* Packet strings */

#define ZSRVACK_SENT		"SENT"	/* SERVACK codes */
#define ZSRVACK_NOTSENT		"LOST"
#define ZSRVACK_FAIL		"FAIL"

    /* Server internal class */
#define ZEPHYR_ADMIN_CLASS	"ZEPHYR_ADMIN"	/* Class */

    /* Control codes sent to a server */
#define ZEPHYR_CTL_CLASS	"ZEPHYR_CTL"	/* Class */

#define ZEPHYR_CTL_CLIENT	"CLIENT"	/* Inst: From client */
#define CLIENT_SUBSCRIBE	"SUBSCRIBE"	/* Opcode: Subscribe */
#define CLIENT_SUBSCRIBE_NODEFS	"SUBSCRIBE_NODEFS"	/* Opcode: Subscribe */
#define CLIENT_UNSUBSCRIBE	"UNSUBSCRIBE"	/* Opcode: Unsubsubscribe */
#define CLIENT_CANCELSUB	"CLEARSUB"	/* Opcode: Clear all subs */
#define CLIENT_GIMMESUBS	"GIMME"		/* Opcode: Give me subs */
#define	CLIENT_GIMMEDEFS	"GIMMEDEFS"	/* Opcode: Give me default
						 * subscriptions */

#define ZEPHYR_CTL_HM		"HM"		/* Inst: From HM */
#define HM_BOOT			"BOOT"		/* Opcode: Boot msg */
#define HM_FLUSH		"FLUSH"		/* Opcode: Flush me */
#define HM_DETACH		"DETACH"	/* Opcode: Detach me */
#define HM_ATTACH		"ATTACH"	/* Opcode: Attach me */

    /* Control codes send to a HostManager */
#define	HM_CTL_CLASS		"HM_CTL"	/* Class */

#define HM_CTL_SERVER		"SERVER"	/* Inst: From server */
#define SERVER_SHUTDOWN		"SHUTDOWN"	/* Opcode: Server shutdown */
#define SERVER_PING		"PING"		/* Opcode: PING */

#define HM_CTL_CLIENT           "CLIENT"        /* Inst: From client */
#define CLIENT_FLUSH            "FLUSH"         /* Opcode: Send flush to srv */
#define CLIENT_NEW_SERVER       "NEWSERV"       /* Opcode: Find new server */

    /* HM Statistics */
#define HM_STAT_CLASS		"HM_STAT"	/* Class */

#define HM_STAT_CLIENT		"HMST_CLIENT"	/* Inst: From client */
#define HM_GIMMESTATS		"GIMMESTATS"	/* Opcode: get stats */

    /* Login class messages */
#define LOGIN_CLASS		"LOGIN"		/* Class */

    /* Class Instance is principal of user who is logging in or logging out */

#define EXPOSE_NONE		"NONE"		/* Opcode: Not visible */
#define EXPOSE_OPSTAFF		"OPSTAFF"	/* Opcode: Opstaff visible */
#define EXPOSE_REALMVIS		"REALM-VISIBLE"	/* Opcode: Realm visible */
#define EXPOSE_REALMANN		"REALM-ANNOUNCED"/* Opcode: Realm announced */
#define EXPOSE_NETVIS		"NET-VISIBLE"	/* Opcode: Net visible */
#define EXPOSE_NETANN		"NET-ANNOUNCED"	/* Opcode: Net announced */
#define	LOGIN_USER_LOGIN	"USER_LOGIN"	/* Opcode: user login
						   (from server) */
#define LOGIN_USER_LOGOUT	"USER_LOGOUT"	/* Opcode: User logout */
#define	LOGIN_USER_FLUSH	"USER_FLUSH"	/* Opcode: flush all locs */

    /* Locate class messages */
#define LOCATE_CLASS		"USER_LOCATE"	/* Class */

#define LOCATE_HIDE		"USER_HIDE"	/* Opcode: Hide me */
#define LOCATE_UNHIDE		"USER_UNHIDE"	/* Opcode: Unhide me */

    /* Class Instance is principal of user to locate */

#define LOCATE_LOCATE		"LOCATE"	/* Opcode: Locate user */

    /* WG_CTL class messages */
#define WG_CTL_CLASS		"WG_CTL"	/* Class */

#define WG_CTL_USER		"USER"		/* Inst: User request */
#define USER_REREAD		"REREAD"	/* Opcode: Reread desc file */
#define USER_SHUTDOWN		"SHUTDOWN"	/* Opcode: Go catatonic */
#define USER_STARTUP		"STARTUP"	/* Opcode: Come out of it */

#endif