1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains global definitions
4 * Created by: Robert French
6 * $Id: zephyr.h 2362 2009-03-28 21:05:19Z kcr@ATHENA.MIT.EDU $
8 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of
9 * Technology. For copying and distribution information, see the
10 * file "mit-copyright.h".
16 #include <sys/types.h>
18 #include <sys/socket.h>
20 #include <zephyr/zephyr_err.h>
22 #ifndef IPPROTO_MAX /* Make sure not already included */
23 #include <netinet/in.h>
29 #define HM_SVCNAME "zephyr-hm"
30 #define HM_SRV_SVCNAME "zephyr-hm-srv"
31 #define SERVER_SVCNAME "zephyr-clt"
32 #define SERVER_SERVICE "zephyr"
33 #define SERVER_INSTANCE "zephyr"
34 #define SERVER_KRB5_SERVICE "zephyr"
36 #define ZVERSIONHDR "ZEPH"
37 #define ZVERSIONMAJOR 0
38 #define ZVERSIONMINOR 2
40 #define Z_MAXPKTLEN 1024
41 #define Z_MAXHEADERLEN 800
42 #define Z_MAXOTHERFIELDS 10 /* Max unknown fields in ZNotice_t */
43 #define Z_NUMFIELDS 19
45 /* Authentication levels returned by ZCheckAuthentication */
46 #define ZAUTH_FAILED (-1)
50 #define ZNOTICE_SOCKADDR 1
51 #define ZNOTICE_CHARSET 1
53 #define ZCHARSET_UNKNOWN 0
54 /* The following are from http://www.iana.org/assignments/character-sets */
55 #define ZCHARSET_ISO_8859_1 4
56 #define ZCHARSET_UTF_8 106
58 typedef char ZPacket_t[Z_MAXPKTLEN];
62 UNSAFE, UNACKED, ACKED, HMACK, HMCTL, SERVACK, SERVNAK, CLIENTACK, STAT
64 extern const char *ZNoticeKinds[9];
71 /* Unique ID format */
72 typedef struct _ZUnique_Id_t {
73 struct in_addr zuid_addr;
78 typedef unsigned int ZChecksum_t;
80 /* Notice definition */
81 typedef struct _ZNotice_t {
84 ZNotice_Kind_t z_kind;
88 struct sockaddr_in ip4;
89 struct sockaddr_in6 ip6;
91 /* heavily deprecated: */
92 #define z_sender_addr z_sender_sockaddr.ip4.sin_addr
93 /* probably a bad idea?: */
94 struct _ZTimeval z_time;
95 unsigned short z_port;
96 unsigned short z_charset;
100 char *z_ascii_authent;
106 char *z_default_format;
108 ZUnique_Id_t z_multiuid;
109 ZChecksum_t z_checksum;
110 char *z_ascii_checksum;
111 int z_num_other_fields;
112 char *z_other_fields[Z_MAXOTHERFIELDS];
115 int z_num_hdr_fields;
119 /* Subscription structure */
120 typedef struct _ZSubscriptions_t {
121 char *zsub_recipient;
123 char *zsub_classinst;
126 /* Function return code */
129 /* Locations structure */
130 typedef struct _ZLocations_t {
136 typedef struct _ZAsyncLocateData_t {
140 } ZAsyncLocateData_t;
144 void (*__Z_debug_print)(const char *fmt, va_list args, void *closure);
145 void *__Z_debug_print_closure;
148 int ZCompareUIDPred(ZNotice_t *, void *);
149 int ZCompareMultiUIDPred(ZNotice_t *, void *);
151 /* Defines for ZFormatNotice, et al. */
152 typedef Code_t (*Z_AuthProc)(ZNotice_t*, char *, int, int *);
153 Code_t ZMakeAuthentication(ZNotice_t*, char *,int, int*);
154 Code_t ZMakeZcodeAuthentication(ZNotice_t*, char *,int, int*);
155 Code_t ZMakeZcodeRealmAuthentication(ZNotice_t*, char *,int, int*, char*);
157 char *ZGetSender(void);
158 char *ZGetVariable(char *);
159 Code_t ZSetVariable(char *var, char *value);
160 Code_t ZUnsetVariable(char *var);
161 int ZGetWGPort(void);
162 Code_t ZSetDestAddr(struct sockaddr_in *);
163 Code_t ZFormatNoticeList(ZNotice_t*, char**, int,
164 char **, int*, Z_AuthProc);
165 Code_t ZParseNotice(char*, int, ZNotice_t *);
166 Code_t ZReadAscii(char*, int, unsigned char*, int);
167 Code_t ZReadAscii32(char *, int, unsigned long *);
168 Code_t ZReadAscii16(char *, int, unsigned short *);
169 Code_t ZReadZcode(unsigned char*, unsigned char*, int, int *);
170 Code_t ZSendPacket(char*, int, int);
171 Code_t ZSendList(ZNotice_t*, char *[], int, Z_AuthProc);
172 Code_t ZSrvSendList(ZNotice_t*, char*[], int, Z_AuthProc,
173 Code_t (*)(ZNotice_t *, char *, int, int));
174 Code_t ZSendNotice(ZNotice_t *, Z_AuthProc);
175 Code_t ZSrvSendNotice(ZNotice_t*, Z_AuthProc,
176 Code_t (*)(ZNotice_t *, char *, int, int));
177 Code_t ZFormatNotice(ZNotice_t*, char**, int*, Z_AuthProc);
178 Code_t ZFormatSmallNotice(ZNotice_t*, ZPacket_t, int*, Z_AuthProc);
179 Code_t ZFormatRawNoticeList(ZNotice_t *, char *[], int, char **, int *);
180 Code_t ZFormatSmallRawNotice(ZNotice_t *, ZPacket_t, int *);
181 Code_t ZNewFormatSmallRawNotice(ZNotice_t *, ZPacket_t, int *);
182 Code_t ZLocateUser(char *, int *, Z_AuthProc);
183 Code_t ZRequestLocations(char *, ZAsyncLocateData_t *,
184 ZNotice_Kind_t, Z_AuthProc);
185 Code_t ZhmStat(struct in_addr *, ZNotice_t *);
186 Code_t ZInitialize(void);
187 Code_t ZSetServerState(int);
189 Code_t ZFormatSmallRawNotice(ZNotice_t*, ZPacket_t, int*);
190 int ZCompareUID(ZUnique_Id_t*, ZUnique_Id_t*);
191 Code_t ZSrvSendRawList(ZNotice_t*, char*[], int,
192 Code_t (*)(ZNotice_t *, char *, int, int));
193 Code_t ZMakeAscii(char*, int, unsigned char*, int);
194 Code_t ZMakeAscii32(char *, int, unsigned long);
195 Code_t ZMakeAscii16(char *, int, unsigned int);
196 Code_t ZMakeZcode(char*, int, unsigned char*, int);
197 Code_t ZMakeZcode32(char *, int, unsigned long);
198 Code_t ZReceivePacket(ZPacket_t, int*, struct sockaddr_in*);
199 Code_t ZCheckAuthentication(ZNotice_t*, struct sockaddr_in*);
200 Code_t ZCheckZcodeAuthentication(ZNotice_t*, struct sockaddr_in*);
201 Code_t ZCheckZcodeRealmAuthentication(ZNotice_t*, struct sockaddr_in*, char *realm);
202 Code_t ZInitLocationInfo(char *hostname, char *tty);
203 Code_t ZSetLocation(char *exposure);
204 Code_t ZUnsetLocation(void);
205 Code_t ZFlushMyLocations(void);
206 char *ZParseExposureLevel(char *text);
207 Code_t ZFormatRawNotice(ZNotice_t *, char**, int *);
208 Code_t ZRetrieveSubscriptions(unsigned short, int*);
209 Code_t ZRetrieveDefaultSubscriptions(int *);
210 Code_t ZGetSubscriptions(ZSubscription_t *, int *);
211 Code_t ZOpenPort(unsigned short *port);
212 Code_t ZClosePort(void);
213 Code_t ZFlushLocations(void);
214 Code_t ZFlushSubscriptions(void);
215 Code_t ZFreeNotice(ZNotice_t *notice);
216 Code_t ZGetLocations(ZLocations_t *, int *);
217 Code_t ZParseLocations(register ZNotice_t *notice,
218 register ZAsyncLocateData_t *zald, int *nlocs,
220 int ZCompareALDPred(ZNotice_t *notice, void *zald);
221 void ZFreeALD(register ZAsyncLocateData_t *zald);
222 Code_t ZCheckIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
223 register int (*predicate)(ZNotice_t *,void *),
225 Code_t ZPeekPacket(char **buffer, int *ret_len,
226 struct sockaddr_in *from);
227 Code_t ZPeekNotice(ZNotice_t *notice, struct sockaddr_in *from);
228 Code_t ZIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
229 int (*predicate)(ZNotice_t *, void *), void *args);
230 Code_t ZSubscribeTo(ZSubscription_t *sublist, int nitems,
232 Code_t ZSubscribeToSansDefaults(ZSubscription_t *sublist, int nitems,
234 Code_t ZUnsubscribeTo(ZSubscription_t *sublist, int nitems,
236 Code_t ZCancelSubscriptions(unsigned int port);
238 Code_t ZReceiveNotice(ZNotice_t *notice, struct sockaddr_in *from);
239 unsigned short ZGetCharset(char *charset);
240 const char *ZCharsetToString(unsigned short charset);
242 void Z_debug(const char *, ...);
244 char *ZExpandRealm(char *realm);
247 #define ZNewLocateUser ZLocateUser
249 /* Not macros to retrieve Zephyr library values. */
250 const char *ZGetRealm(void);
253 struct sockaddr_in ZGetDestAddr (void);
257 void ZSetDebug (void (*)(const char *, va_list, void *), void *);
258 #define ZSetDebug(proc,closure) (__Z_debug_print=(proc), \
259 __Z_debug_print_closure=(closure), \
262 #define ZSetDebug(proc,closure)
265 /* Maximum queue length */
268 /* Successful function return */
271 /* Hostmanager wait time (in secs) */
272 #define HM_TIMEOUT 10
274 /* Server wait time (in secs) */
275 #define SRV_TIMEOUT 30
277 #define ZAUTH (ZMakeAuthentication)
278 #define ZCAUTH (ZMakeZcodeAuthentication)
279 #define ZNOAUTH ((Z_AuthProc)0)
282 #define ZSRVACK_SENT "SENT" /* SERVACK codes */
283 #define ZSRVACK_NOTSENT "LOST"
284 #define ZSRVACK_FAIL "FAIL"
286 /* Server internal class */
287 #define ZEPHYR_ADMIN_CLASS "ZEPHYR_ADMIN" /* Class */
289 /* Control codes sent to a server */
290 #define ZEPHYR_CTL_CLASS "ZEPHYR_CTL" /* Class */
292 #define ZEPHYR_CTL_REALM "REALM" /* Inst: From realm */
293 #define REALM_ADD_SUBSCRIBE "ADD_SUBSCRIBE" /* Opcode: Add subs */
294 #define REALM_REQ_SUBSCRIBE "REQ_SUBSCRIBE" /* Opcode: Request subs */
295 #define REALM_SUBSCRIBE "RLM_SUBSCRIBE" /* Opcode: Subscribe realm */
296 #define REALM_UNSUBSCRIBE "RLM_UNSUBSCRIBE" /* Opcode: Unsub realm */
298 #define ZEPHYR_CTL_CLIENT "CLIENT" /* Inst: From client */
299 #define CLIENT_SUBSCRIBE "SUBSCRIBE" /* Opcode: Subscribe */
300 #define CLIENT_SUBSCRIBE_NODEFS "SUBSCRIBE_NODEFS" /* Opcode: Subscribe */
301 #define CLIENT_UNSUBSCRIBE "UNSUBSCRIBE" /* Opcode: Unsubsubscribe */
302 #define CLIENT_CANCELSUB "CLEARSUB" /* Opcode: Clear all subs */
303 #define CLIENT_GIMMESUBS "GIMME" /* Opcode: Give me subs */
304 #define CLIENT_GIMMEDEFS "GIMMEDEFS" /* Opcode: Give me default
307 #define ZEPHYR_CTL_HM "HM" /* Inst: From HM */
308 #define HM_BOOT "BOOT" /* Opcode: Boot msg */
309 #define HM_FLUSH "FLUSH" /* Opcode: Flush me */
310 #define HM_DETACH "DETACH" /* Opcode: Detach me */
311 #define HM_ATTACH "ATTACH" /* Opcode: Attach me */
313 /* Control codes send to a HostManager */
314 #define HM_CTL_CLASS "HM_CTL" /* Class */
316 #define HM_CTL_SERVER "SERVER" /* Inst: From server */
317 #define SERVER_SHUTDOWN "SHUTDOWN" /* Opcode: Server shutdown */
318 #define SERVER_PING "PING" /* Opcode: PING */
320 #define HM_CTL_CLIENT "CLIENT" /* Inst: From client */
321 #define CLIENT_FLUSH "FLUSH" /* Opcode: Send flush to srv */
322 #define CLIENT_NEW_SERVER "NEWSERV" /* Opcode: Find new server */
325 #define HM_STAT_CLASS "HM_STAT" /* Class */
327 #define HM_STAT_CLIENT "HMST_CLIENT" /* Inst: From client */
328 #define HM_GIMMESTATS "GIMMESTATS" /* Opcode: get stats */
330 /* Login class messages */
331 #define LOGIN_CLASS "LOGIN" /* Class */
333 /* Class Instance is principal of user who is logging in or logging out */
335 #define EXPOSE_NONE "NONE" /* Opcode: Not visible */
336 #define EXPOSE_OPSTAFF "OPSTAFF" /* Opcode: Opstaff visible */
337 #define EXPOSE_REALMVIS "REALM-VISIBLE" /* Opcode: Realm visible */
338 #define EXPOSE_REALMANN "REALM-ANNOUNCED"/* Opcode: Realm announced */
339 #define EXPOSE_NETVIS "NET-VISIBLE" /* Opcode: Net visible */
340 #define EXPOSE_NETANN "NET-ANNOUNCED" /* Opcode: Net announced */
341 #define LOGIN_USER_LOGIN "USER_LOGIN" /* Opcode: user login
343 #define LOGIN_USER_LOGOUT "USER_LOGOUT" /* Opcode: User logout */
344 #define LOGIN_USER_FLUSH "USER_FLUSH" /* Opcode: flush all locs */
346 /* Locate class messages */
347 #define LOCATE_CLASS "USER_LOCATE" /* Class */
349 #define LOCATE_HIDE "USER_HIDE" /* Opcode: Hide me */
350 #define LOCATE_UNHIDE "USER_UNHIDE" /* Opcode: Unhide me */
352 /* Class Instance is principal of user to locate */
353 #define LOCATE_LOCATE "LOCATE" /* Opcode: Locate user */
355 /* WG_CTL class messages */
356 #define WG_CTL_CLASS "WG_CTL" /* Class */
358 #define WG_CTL_USER "USER" /* Inst: User request */
359 #define USER_REREAD "REREAD" /* Opcode: Reread desc file */
360 #define USER_SHUTDOWN "SHUTDOWN" /* Opcode: Go catatonic */
361 #define USER_STARTUP "STARTUP" /* Opcode: Come out of it */
362 #define USER_EXIT "EXIT" /* Opcode: Exit the client */
364 #endif /* __ZEPHYR_H__ */