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 */
34 #if defined(HAVE_KRB5) || defined(HAVE_KRB4)
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,
44 extern C_Block __Zephyr_session;
45 #define ZGetSession() (__Zephyr_session)
47 void ZSetSessionDES(C_Block *key);
49 Code_t ZFormatAuthenticNotice(ZNotice_t*, char*, int, int*, C_Block);
52 /* For krb_rd_req prototype and definition. */
54 #define KRB_INT32 ZEPHYR_INT32
57 /* These macros are for insertion into and deletion from a singly-linked list
58 * with back pointers to the previous element's next pointer. In order to
59 * make these macros act like expressions, they use the comma operator for
60 * sequenced evaluations of assignment, and "a && b" for "evaluate assignment
61 * b if expression a is true". */
62 #define LIST_INSERT(head, elem) \
63 ((elem)->next = *(head), \
64 (*head) && ((*(head))->prev_p = &(elem)->next), \
65 (*head) = (elem), (elem)->prev_p = (head))
66 #define LIST_DELETE(elem) \
67 (*(elem)->prev_p = (elem)->next, \
68 (elem)->next && ((elem)->next->prev_p = (elem)->prev_p))
70 /* Current time as cached by main(); use instead of time(). */
71 #define NOW t_local.tv_sec
75 /* Kerberos shouldn't stick us with array types... */
82 typedef struct _Destination Destination;
83 typedef struct _Destlist Destlist;
84 typedef struct _ZRealm ZRealm;
85 typedef struct _ZRealmname ZRealmname;
86 typedef enum _ZRealm_state ZRealm_state;
87 typedef struct _Client Client;
88 typedef struct _Triplet Triplet;
89 typedef enum _Server_state Server_state;
90 typedef struct _Unacked Unacked;
91 typedef struct _Pending Pending;
92 typedef struct _Server Server;
93 typedef enum _Sent_type Sent_type;
94 typedef struct _Statistic Statistic;
104 struct _Destlist *next, **prev_p;
108 REALM_UP, /* ZRealm is up */
109 REALM_TARDY, /* ZRealm due for a hello XXX */
110 REALM_DEAD, /* ZRealm is considered dead */
111 REALM_STARTING /* ZRealm is between dead and up */
117 struct sockaddr_in *addrs;
118 int idx; /* which server we are connected to */
119 Destlist *subs; /* what their clients sub to */
120 Destlist *remsubs; /* our subs on their end */
135 struct sockaddr_in addr; /* ipaddr/port of client */
136 Destlist *subs ; /* subscriptions */
138 krb5_keyblock *session_keyblock;
141 C_Block session_key; /* session key for this client */
142 #endif /* HAVE_KRB4 */
144 String *principal; /* krb principal of user */
145 int last_send; /* Counter for last sent packet. */
146 time_t last_ack; /* Time of last received ack */
148 struct _Client *next, **prev_p;
156 struct _Triplet *next, **prev_p;
160 SERV_UP, /* Server is up */
161 SERV_TARDY, /* Server due for a hello */
162 SERV_DEAD, /* Server is considered dead */
163 SERV_STARTING /* Server is between dead and up */
167 Timer *timer; /* timer for retransmit */
168 Client *client; /* responsible client, or NULL */
169 short rexmits; /* number of retransmits */
170 short packsz; /* size of packet */
171 char *packet; /* ptr to packet */
172 ZUnique_Id_t uid; /* uid of packet */
173 struct sockaddr_in ack_addr;
174 union { /* address to send to */
175 struct sockaddr_in addr; /* client address */
176 int srv_idx; /* index of server */
178 int rlm_idx; /* index of realm */
179 int rlm_srv_idx; /* index of server in realm */
182 struct _Unacked *next, **prev_p;
186 char *packet; /* the notice (in pkt form) */
187 short len; /* len of pkt */
188 unsigned int auth; /* whether it is authentic */
189 struct sockaddr_in who; /* the addr of the sender */
190 struct _Pending *next;
194 Server_state state; /* server's state */
195 struct sockaddr_in addr; /* server's address */
196 long timeout; /* Length of timeout in sec */
197 Timer *timer; /* timer for this server */
198 Pending *queue; /* queue of packets to send
199 to this server when done dumping */
200 Pending *queue_last; /* last packet on queue */
201 short num_hello_sent; /* number of hello's sent */
202 unsigned int dumping; /* 1 if dumping, so we should queue */
203 char addr_str[16]; /* text version of address */
207 NOT_SENT, /* message was not xmitted */
208 SENT, /* message was xmitted */
209 AUTH_FAILED, /* authentication failed */
210 NOT_FOUND /* user not found for uloc */
213 /* statistics gathering */
219 /* Function declarations */
221 /* found in bdump.c */
222 void bdump_get(ZNotice_t *notice, int auth, struct sockaddr_in *who,
224 void bdump_send(void);
225 void bdump_offer(struct sockaddr_in *who);
226 Code_t bdump_send_list_tcp(ZNotice_Kind_t kind, struct sockaddr_in *addr,
227 char *class_name, char *inst, char *opcode,
228 char *sender, char *recip, char **lyst,
232 /* found in class.c */
233 extern String *class_control, *class_admin, *class_hm;
234 extern String *class_ulogin, *class_ulocate;
235 int ZDest_eq(Destination *d1, Destination *d2);
236 Code_t triplet_register(Client *client, Destination *dest, ZRealm *realm);
237 Code_t triplet_deregister(Client *client, Destination *dest,
239 Code_t class_restrict(char *class, Acl *acl);
240 Code_t class_setup_restricted(char *class, Acl *acl);
241 Client **triplet_lookup(Destination *dest);
242 Acl *class_get_acl(String *class);
243 int dest_eq(Destination *d1, Destination *d2);
244 int order_dest_strings(Destination *d1, Destination *d2);
245 void triplet_dump_subs(FILE *fp);
247 /* found in client.c */
248 Code_t client_register(ZNotice_t *notice, struct in_addr *host,
249 Client **client_p, int wantdefaults);
250 void client_deregister(Client *client, int flush);
251 void client_flush_host(struct in_addr *host);
252 void client_dump_clients(FILE *fp);
253 Client *client_find(struct in_addr *host, unsigned int port);
254 Code_t client_send_clients(void);
256 /* found in common.c */
257 char *strsave(const char *str);
258 unsigned long hash (const char *);
259 void dump_quote(char *p, FILE *fp);
261 /* found in dispatch.c */
262 void handle_packet(void);
263 void clt_ack(ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent);
264 void nack_release(Client *client);
265 void sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who,
268 void xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth,
270 Code_t hostm_dispatch(ZNotice_t *notice, int auth,
271 struct sockaddr_in *who, Server *server);
272 Code_t control_dispatch(ZNotice_t *notice, int auth,
273 struct sockaddr_in *who, Server *server);
274 Code_t xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack);
275 void hostm_shutdown(void);
277 /* found in kstuff.c */
279 int GetKerberosData (int, struct in_addr, AUTH_DAT *, char *, char *);
280 Code_t SendKerberosData (int, KTEXT, char *, char *);
281 void sweep_ticket_hash_table(void *);
284 /* found in kopt.c */
287 Sched *check_key_sched_cache(des_cblock key);
288 void add_to_key_sched_cache(des_cblock key, Sched *sched);
289 /*int krb_set_key(void *key, int cvt);*/
290 /* int krb_rd_req(KTEXT authent, char *service, char *instance,
291 unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn); */
292 int krb_find_ticket(KTEXT authent, KTEXT ticket);
293 int krb_get_lrealm(char *r, int n);
297 /* found in server.c */
298 void server_timo(void *which);
299 void server_dump_servers(FILE *fp);
300 void server_init(void);
301 void server_shutdown(void);
302 void server_forward(ZNotice_t *notice, int auth,
303 struct sockaddr_in *who);
304 void server_kill_clt(Client *client);
305 void server_pending_free(Pending *pending);
306 void server_self_queue(ZNotice_t *, int, struct sockaddr_in *);
307 void server_send_queue(Server *);
308 void server_reset(void);
309 Server *server_which_server(struct sockaddr_in *who);
310 Pending *server_dequeue(Server *server);
311 Code_t server_dispatch(ZNotice_t *notice, int auth,
312 struct sockaddr_in *who);
313 Code_t server_adispatch(ZNotice_t *notice, int auth,
314 struct sockaddr_in *who, Server *server);
316 /* found in subscr.c */
317 Code_t subscr_foreign_user(ZNotice_t *, struct sockaddr_in *, Server *, ZRealm *);
318 Code_t subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice);
319 Code_t subscr_subscribe(Client *who, ZNotice_t *notice, Server *server);
320 Code_t subscr_send_subs(Client *client);
321 void subscr_cancel_client(Client *client);
322 void subscr_sendlist(ZNotice_t *notice, int auth,
323 struct sockaddr_in *who);
324 void subscr_dump_subs(FILE *fp, Destlist *subs);
325 void subscr_reset(void);
326 Code_t subscr_def_subs(Client *who);
328 /* found in uloc.c */
329 void uloc_hflush(struct in_addr *addr);
330 void uloc_flush_client(struct sockaddr_in *sin);
331 void uloc_dump_locs(FILE *fp);
332 Code_t ulogin_dispatch(ZNotice_t *notice, int auth,
333 struct sockaddr_in *who, Server *server);
334 Code_t ulocate_dispatch(ZNotice_t *notice, int auth,
335 struct sockaddr_in *who, Server *server);
336 Code_t uloc_send_locations(void);
338 /* found in realm.c */
339 int realm_sender_in_realm(char *realm, char *sender);
340 int realm_bound_for_realm(char *realm, char *recip);
341 ZRealm *realm_which_realm(struct sockaddr_in *who);
342 ZRealm *realm_get_realm_by_name(char *name);
343 ZRealm *realm_get_realm_by_pid(int);
344 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, ZRealm *, int);
345 char *realm_expand_realm(char *);
346 void realm_init(void);
347 Code_t ZCheckZRealmAuthentication(ZNotice_t *, struct sockaddr_in *,
349 Code_t realm_control_dispatch(ZNotice_t *, int, struct sockaddr_in *,
351 void realm_shutdown(void);
352 void realm_deathgram(Server *);
354 /* found in version.c */
355 char *get_version(void);
357 /* global identifiers */
359 /* found in main.c */
360 int packets_waiting(void);
361 extern struct sockaddr_in srv_addr; /* server socket address */
362 extern unsigned short hm_port; /* host manager receiver port */
363 extern unsigned short hm_srv_port; /* host manager server sending port */
364 extern int srv_socket; /* dgram sockets for clients
366 extern int bdump_socket; /* brain dump socket
367 (closed most of the time) */
369 extern fd_set interesting; /* the file descrips we are listening
371 extern int nfds; /* number to look at in select() */
373 extern char myname[]; /* domain name of this host */
374 extern char list_file[];
376 extern char keytab_file[];
377 extern krb5_ccache Z_krb5_ccache;
380 extern char srvtab_file[];
381 extern char my_realm[];
383 extern char acl_dir[];
384 extern char subs_file[];
385 extern const char version[];
386 extern u_long npackets; /* num of packets processed */
387 extern time_t uptime; /* time we started */
388 extern struct in_addr my_addr;
389 extern struct timeval t_local; /* current time */
391 /* found in bdump.c */
392 extern int bdumping; /* are we processing a bdump packet? */
393 extern int bdump_concurrent; /* set while processing a packet
394 * concurrently during a braindump. */
396 /* found in dispatch.c */
397 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
398 extern int rexmit_times[];
400 /* found in server.c */
401 extern Server *otherservers; /* array of servers */
402 extern int me_server_idx; /* me (in the array of servers) */
403 extern int nservers; /* number of other servers*/
405 /* found in subscr.c */
406 extern String *empty;
407 extern String *wildcard_instance;
409 extern ZRealm *otherrealms;
412 extern struct in_addr my_addr; /* my inet address */
414 #define class_is_control(classname) (classname == class_control)
415 #define class_is_admin(classname) (classname == class_admin)
416 #define class_is_hm(classname) (classname == class_hm)
417 #define class_is_ulogin(classname) (classname == class_ulogin)
418 #define class_is_ulocate(classname) (classname == class_ulocate)
420 #define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
421 #define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
422 #define ADMIN_SHUTDOWN "GOODBYE" /* Opcode: I am shutting down */
423 #define ADMIN_BDUMP "DUMP_AVAIL" /* Opcode: I will give you a dump */
424 #define ADMIN_DONE "DUMP_DONE" /* Opcode: brain dump for this server
426 #define ADMIN_NEWCLT "NEXT_CLIENT" /* Opcode: this is a new client */
427 #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */
428 #define ADMIN_STATUS "STATUS" /* Opcode: please send status */
430 #define ADMIN_NEWREALM "NEXT_REALM" /* Opcode: this is a new realm */
431 #define REALM_REQ_LOCATE "REQ_LOCATE" /* Opcode: request a location */
432 #define REALM_ANS_LOCATE "ANS_LOCATE" /* Opcode: answer to location */
433 #define REALM_BOOT "SENDSUBS" /* Opcode: first server in realm */
435 /* me_server_idx is the index into otherservers of this server descriptor. */
436 /* the 'limbo' server is always the first server */
438 #define me_server (&otherservers[me_server_idx])
439 #define limbo_server_idx() (0)
440 #define limbo_server (&otherservers[limbo_server_idx()])
442 #define msgs_queued() (ZQLength() || otherservers[me_server_idx].queue)
444 #define ack(a,b) clt_ack(a,b,SENT)
445 #define nack(a,b) clt_ack(a,b,NOT_SENT)
447 #define min(a,b) ((a) < (b) ? (a) : (b))
448 #define max(a,b) ((a) > (b) ? (a) : (b))
450 #define START_CRITICAL_CODE
451 #define END_CRITICAL_CODE
453 /* the instance that matches all instances */
454 #define WILDCARD_INSTANCE "*"
456 /* debugging macros */
458 #define zdbug(s1) if (zdebug) syslog s1;
463 #endif /* !__ZSERVER_H__ */