3 /* This file is part of the Project Athena Zephyr Notification System.
4 * It contains declarations for use in the server.
6 * Created by: John T. Kohl
8 * $Source: /afs/dev.mit.edu/source/repository/athena/lib/zephyr/server/zserver.h,v $
10 * $Zephyr: /mit/zephyr/src/server/RCS/zserver.h,v 1.34 91/03/08 12:53:24 raeburn Exp $
12 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
13 * For copying and distribution information, see the file
17 #include <zephyr/mit-copyright.h>
23 #include <arpa/inet.h>
28 #include "zsrv_conf.h" /* configuration params */
35 /* Kerberos-specific library interfaces used only by the server. */
37 extern krb5_keyblock *__Zephyr_keyblock;
38 #define ZGetSession() (__Zephyr_keyblock)
39 void ZSetSession(krb5_keyblock *keyblock);
40 Code_t ZFormatAuthenticNoticeV5(ZNotice_t*, char*, int, int*, krb5_keyblock *);
41 krb5_error_code Z_krb5_init_keyblock(krb5_context, krb5_enctype, size_t,
46 void ZSetSessionDES(C_Block *key);
48 Code_t ZFormatAuthenticNotice(ZNotice_t*, char*, int, int*, C_Block);
51 extern C_Block __Zephyr_session;
52 #define ZGetSession() (__Zephyr_session)
56 /* For krb_rd_req prototype and definition. */
58 #define KRB_INT32 ZEPHYR_INT32
61 /* Current time as cached by main(); use instead of time(). */
62 #define NOW t_local.tv_sec
65 /* Kerberos shouldn't stick us with array types... */
71 typedef struct _Destination Destination;
72 typedef struct _Destlist Destlist;
73 typedef struct _ZRealm ZRealm;
74 typedef struct _ZRealmname ZRealmname;
75 typedef enum _ZRealm_state ZRealm_state;
76 typedef struct _Client Client;
77 typedef struct _Triplet Triplet;
78 typedef enum _Server_state Server_state;
79 typedef struct _Unacked Unacked;
80 typedef struct _Pending Pending;
81 typedef struct _Server Server;
82 typedef enum _Sent_type Sent_type;
83 typedef struct _Statistic Statistic;
93 struct _Destlist *next, **prev_p;
97 REALM_UP, /* ZRealm is up */
98 REALM_TARDY, /* ZRealm due for a hello XXX */
99 REALM_DEAD, /* ZRealm is considered dead */
100 REALM_STARTING /* ZRealm is between dead and up */
106 struct sockaddr_in *addrs;
107 int idx; /* which server we are connected to */
108 Destlist *subs; /* what their clients sub to */
109 Destlist *remsubs; /* our subs on their end */
124 struct sockaddr_in addr; /* ipaddr/port of client */
125 Destlist *subs ; /* subscriptions */
127 krb5_keyblock *session_keyblock;
130 C_Block session_key; /* session key for this client */
131 #endif /* HAVE_KRB4 */
133 String *principal; /* krb principal of user */
134 int last_send; /* Counter for last sent packet. */
135 time_t last_ack; /* Time of last received ack */
137 struct _Client *next, **prev_p;
145 struct _Triplet *next, **prev_p;
149 SERV_UP, /* Server is up */
150 SERV_TARDY, /* Server due for a hello */
151 SERV_DEAD, /* Server is considered dead */
152 SERV_STARTING /* Server is between dead and up */
156 Timer *timer; /* timer for retransmit */
157 Client *client; /* responsible client, or NULL */
158 short rexmits; /* number of retransmits */
159 short packsz; /* size of packet */
160 char *packet; /* ptr to packet */
161 ZUnique_Id_t uid; /* uid of packet */
162 struct sockaddr_in ack_addr;
163 union { /* address to send to */
164 struct sockaddr_in addr; /* client address */
165 int srv_idx; /* index of server */
167 int rlm_idx; /* index of realm */
168 int rlm_srv_idx; /* index of server in realm */
171 struct _Unacked *next, **prev_p;
175 char *packet; /* the notice (in pkt form) */
176 short len; /* len of pkt */
177 unsigned int auth; /* whether it is authentic */
178 struct sockaddr_in who; /* the addr of the sender */
179 struct _Pending *next;
183 Server_state state; /* server's state */
184 struct sockaddr_in addr; /* server's address */
185 long timeout; /* Length of timeout in sec */
186 Timer *timer; /* timer for this server */
187 Pending *queue; /* queue of packets to send
188 to this server when done dumping */
189 Pending *queue_last; /* last packet on queue */
190 short num_hello_sent; /* number of hello's sent */
191 unsigned int dumping; /* 1 if dumping, so we should queue */
192 char addr_str[16]; /* text version of address */
196 NOT_SENT, /* message was not xmitted */
197 SENT, /* message was xmitted */
198 AUTH_FAILED, /* authentication failed */
199 NOT_FOUND /* user not found for uloc */
202 /* statistics gathering */
208 /* Function declarations */
210 /* These macros instantiate inline functions that do the work of the formder
211 LIST_INSERT and LIST_DELETE functions, which unfortunately triggered gcc's
212 pedanticism. The comment before the *former* macros was: */
213 /* These macros are for insertion into and deletion from a singly-linked list
214 * with back pointers to the previous element's next pointer. In order to
215 * make these macros act like expressions, they use the comma operator for
216 * sequenced evaluations of assignment, and "a && b" for "evaluate assignment
217 * b if expression a is true". */
219 #define MAKE_LIST_INSERT(type) inline static void type##_insert(type **head, type *elem) \
221 (elem)->next = *(head); \
222 if(*head) (*(head))->prev_p = &(elem)->next; \
224 (elem)->prev_p = (head); \
227 #define MAKE_LIST_DELETE(type) inline static void type##_delete(type *elem) \
229 *(elem)->prev_p = (elem)->next; \
230 if((elem)->next) (elem)->next->prev_p = (elem)->prev_p; \
233 MAKE_LIST_INSERT(Destlist);
234 MAKE_LIST_DELETE(Destlist);
235 MAKE_LIST_INSERT(Client);
236 MAKE_LIST_DELETE(Client);
237 MAKE_LIST_INSERT(Triplet);
238 MAKE_LIST_DELETE(Triplet);
239 MAKE_LIST_INSERT(Unacked);
240 MAKE_LIST_DELETE(Unacked);
242 /* found in bdump.c */
243 void bdump_get(ZNotice_t *notice, int auth, struct sockaddr_in *who,
245 void bdump_send(void);
246 void bdump_offer(struct sockaddr_in *who);
247 Code_t bdump_send_list_tcp(ZNotice_Kind_t kind, struct sockaddr_in *addr,
248 char *class_name, char *inst, char *opcode,
249 char *sender, char *recip, char **lyst,
253 /* found in class.c */
254 extern String *class_control, *class_admin, *class_hm;
255 extern String *class_ulogin, *class_ulocate;
256 int ZDest_eq(Destination *d1, Destination *d2);
257 Code_t triplet_register(Client *client, Destination *dest, ZRealm *realm);
258 Code_t triplet_deregister(Client *client, Destination *dest,
260 Code_t class_restrict(char *class, Acl *acl);
261 Code_t class_setup_restricted(char *class, Acl *acl);
262 Client **triplet_lookup(Destination *dest);
263 Acl *class_get_acl(String *class);
264 int dest_eq(Destination *d1, Destination *d2);
265 int order_dest_strings(Destination *d1, Destination *d2);
266 void triplet_dump_subs(FILE *fp);
268 /* found in client.c */
269 Code_t client_register(ZNotice_t *notice, struct in_addr *host,
270 Client **client_p, int wantdefaults);
271 void client_deregister(Client *client, int flush);
272 void client_flush_host(struct in_addr *host);
273 void client_dump_clients(FILE *fp);
274 Client *client_find(struct in_addr *host, unsigned int port);
275 Code_t client_send_clients(void);
277 /* found in common.c */
278 char *strsave(const char *str);
279 unsigned long hash (const char *);
280 void dump_quote(char *p, FILE *fp);
282 /* found in dispatch.c */
283 void handle_packet(void);
284 void clt_ack(ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent);
285 void nack_release(Client *client);
286 void sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who,
289 void xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth,
291 Code_t hostm_dispatch(ZNotice_t *notice, int auth,
292 struct sockaddr_in *who, Server *server);
293 Code_t control_dispatch(ZNotice_t *notice, int auth,
294 struct sockaddr_in *who, Server *server);
295 Code_t xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack);
296 void hostm_shutdown(void);
298 /* found in kstuff.c */
299 #if defined(HAVE_KRB4) || defined(HAVE_KRB5)
300 Code_t ReadKerberosData(int, int *, char **, int *);
301 void sweep_ticket_hash_table(void *);
302 Code_t ZCheckRealmAuthentication(ZNotice_t *, struct sockaddr_in *, char *);
305 int GetKerberosData (int, struct in_addr, AUTH_DAT *, char *, char *);
306 Code_t SendKerberosData (int, KTEXT, char *, char *);
309 Code_t SendKrb5Data(int, krb5_data *);
310 Code_t GetKrb5Data(int, krb5_data *);
313 /* found in server.c */
314 void server_timo(void *which);
315 void server_dump_servers(FILE *fp);
316 void server_init(void);
317 void server_shutdown(void);
318 void server_forward(ZNotice_t *notice, int auth,
319 struct sockaddr_in *who);
320 void server_kill_clt(Client *client);
321 void server_pending_free(Pending *pending);
322 void server_self_queue(ZNotice_t *, int, struct sockaddr_in *);
323 void server_send_queue(Server *);
324 void server_reset(void);
325 Server *server_which_server(struct sockaddr_in *who);
326 Pending *server_dequeue(Server *server);
327 Code_t server_dispatch(ZNotice_t *notice, int auth,
328 struct sockaddr_in *who);
329 Code_t server_adispatch(ZNotice_t *notice, int auth,
330 struct sockaddr_in *who, Server *server);
332 /* found in subscr.c */
333 Code_t subscr_foreign_user(ZNotice_t *, struct sockaddr_in *, Server *, ZRealm *);
334 Code_t subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice);
335 Code_t subscr_subscribe(Client *who, ZNotice_t *notice, Server *server);
336 Code_t subscr_send_subs(Client *client);
337 void subscr_cancel_client(Client *client);
338 void subscr_sendlist(ZNotice_t *notice, int auth,
339 struct sockaddr_in *who);
340 void subscr_dump_subs(FILE *fp, Destlist *subs);
341 void subscr_reset(void);
342 Code_t subscr_def_subs(Client *who);
343 Code_t subscr_realm(ZRealm *, ZNotice_t *);
344 Code_t subscr_send_realm_subs(ZRealm *);
345 Code_t subscr_realm_cancel(struct sockaddr_in *, ZNotice_t *, ZRealm *);
347 /* found in uloc.c */
348 void uloc_hflush(struct in_addr *addr);
349 void uloc_flush_client(struct sockaddr_in *sin);
350 void uloc_dump_locs(FILE *fp);
351 Code_t ulogin_dispatch(ZNotice_t *notice, int auth,
352 struct sockaddr_in *who, Server *server);
353 Code_t ulocate_dispatch(ZNotice_t *notice, int auth,
354 struct sockaddr_in *who, Server *server);
355 Code_t uloc_send_locations(void);
356 void ulogin_relay_locate(ZNotice_t *, struct sockaddr_in *);
357 void ulogin_realm_locate(ZNotice_t *, struct sockaddr_in *, ZRealm *);
359 /* found in realm.c */
360 int realm_sender_in_realm(const char *realm, char *sender);
361 int realm_bound_for_realm(const char *realm, char *recip);
362 ZRealm *realm_which_realm(struct sockaddr_in *who);
363 ZRealm *realm_get_realm_by_name(char *name);
364 ZRealm *realm_get_realm_by_pid(int);
365 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, ZRealm *, int);
366 const char *realm_expand_realm(char *);
367 void realm_init(void);
368 Code_t ZCheckZRealmAuthentication(ZNotice_t *, struct sockaddr_in *,
370 Code_t realm_control_dispatch(ZNotice_t *, int, struct sockaddr_in *,
372 void realm_shutdown(void);
373 void realm_deathgram(Server *);
374 Code_t realm_send_realms(void);
375 Code_t realm_dispatch(ZNotice_t *, int, struct sockaddr_in *, Server *);
376 void realm_wakeup(void);
377 void kill_realm_pids(void);
378 void realm_dump_realms(FILE *);
380 /* found in version.c */
381 char *get_version(void);
383 /* found in access.c */
384 int access_check(char *, Acl *, Access);
386 /* global identifiers */
388 /* found in main.c */
389 int packets_waiting(void);
390 extern struct sockaddr_in srv_addr; /* server socket address */
391 extern unsigned short hm_port; /* host manager receiver port */
392 extern unsigned short hm_srv_port; /* host manager server sending port */
393 extern int srv_socket; /* dgram sockets for clients
395 extern int bdump_socket; /* brain dump socket
396 (closed most of the time) */
398 extern fd_set interesting; /* the file descrips we are listening
400 extern int nfds; /* number to look at in select() */
402 extern char myname[]; /* domain name of this host */
403 extern char list_file[];
405 extern char keytab_file[];
406 extern krb5_ccache Z_krb5_ccache;
409 extern char srvtab_file[];
410 extern char my_realm[];
412 extern char acl_dir[];
413 extern char subs_file[];
414 extern const char version[];
415 extern u_long npackets; /* num of packets processed */
416 extern time_t uptime; /* time we started */
417 extern struct in_addr my_addr;
418 extern struct timeval t_local; /* current time */
420 /* found in bdump.c */
421 extern int bdumping; /* are we processing a bdump packet? */
422 extern int bdump_concurrent; /* set while processing a packet
423 * concurrently during a braindump. */
425 /* found in dispatch.c */
426 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
427 extern int rexmit_times[];
429 /* found in server.c */
430 extern Server *otherservers; /* array of servers */
431 extern int me_server_idx; /* me (in the array of servers) */
432 extern int nservers; /* number of other servers*/
434 /* found in subscr.c */
435 extern String *empty;
436 extern String *wildcard_instance;
438 extern ZRealm *otherrealms;
441 extern struct in_addr my_addr; /* my inet address */
443 #define class_is_control(classname) (classname == class_control)
444 #define class_is_admin(classname) (classname == class_admin)
445 #define class_is_hm(classname) (classname == class_hm)
446 #define class_is_ulogin(classname) (classname == class_ulogin)
447 #define class_is_ulocate(classname) (classname == class_ulocate)
449 #define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
450 #define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
451 #define ADMIN_SHUTDOWN "GOODBYE" /* Opcode: I am shutting down */
452 #define ADMIN_BDUMP "DUMP_AVAIL" /* Opcode: I will give you a dump */
453 #define ADMIN_DONE "DUMP_DONE" /* Opcode: brain dump for this server
455 #define ADMIN_NEWCLT "NEXT_CLIENT" /* Opcode: this is a new client */
456 #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */
457 #define ADMIN_STATUS "STATUS" /* Opcode: please send status */
459 #define ADMIN_NEWREALM "NEXT_REALM" /* Opcode: this is a new realm */
460 #define REALM_REQ_LOCATE "REQ_LOCATE" /* Opcode: request a location */
461 #define REALM_ANS_LOCATE "ANS_LOCATE" /* Opcode: answer to location */
462 #define REALM_BOOT "SENDSUBS" /* Opcode: first server in realm */
464 /* me_server_idx is the index into otherservers of this server descriptor. */
465 /* the 'limbo' server is always the first server */
467 #define me_server (&otherservers[me_server_idx])
468 #define limbo_server_idx() (0)
469 #define limbo_server (&otherservers[limbo_server_idx()])
471 #define msgs_queued() (ZQLength() || otherservers[me_server_idx].queue)
473 #define ack(a,b) clt_ack(a,b,SENT)
474 #define nack(a,b) clt_ack(a,b,NOT_SENT)
476 #define min(a,b) ((a) < (b) ? (a) : (b))
477 #define max(a,b) ((a) > (b) ? (a) : (b))
479 #define START_CRITICAL_CODE
480 #define END_CRITICAL_CODE
482 /* the instance that matches all instances */
483 #define WILDCARD_INSTANCE "*"
485 /* debugging macros */
487 #define zdbug(s1) if (zdebug) syslog s1;
492 #endif /* !__ZSERVER_H__ */