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
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>
20 #include <arpa/inet.h>
25 #include "zsrv_conf.h" /* configuration params */
32 /* Kerberos-specific library interfaces used only by the server. */
33 extern C_Block __Zephyr_session;
34 #define ZGetSession() (__Zephyr_session)
35 Code_t ZFormatAuthenticNotice __P((ZNotice_t*, char*, int, int*, C_Block));
38 /* For krb_rd_req prototype and definition. */
40 #define KRB_INT32 ZEPHYR_INT32
43 /* These macros are for insertion into and deletion from a singly-linked list
44 * with back pointers to the previous element's next pointer. In order to
45 * make these macros act like expressions, they use the comma operator for
46 * sequenced evaluations of assignment, and "a && b" for "evaluate assignment
47 * b if expression a is true". */
48 #define LIST_INSERT(head, elem) \
49 ((elem)->next = *(head), \
50 (*head) && ((*(head))->prev_p = &(elem)->next), \
51 (*head) = (elem), (elem)->prev_p = (head))
52 #define LIST_DELETE(elem) \
53 (*(elem)->prev_p = (elem)->next, \
54 (elem)->next && ((elem)->next->prev_p = (elem)->prev_p))
56 /* Current time as cached by main(); use instead of time(). */
57 #define NOW t_local.tv_sec
61 /* Kerberos shouldn't stick us with array types... */
68 typedef struct _Destination Destination;
69 typedef struct _Destlist Destlist;
70 typedef struct _Realm Realm;
71 typedef struct _Realmname Realmname;
72 typedef enum _Realm_state Realm_state;
73 typedef struct _Client Client;
74 typedef struct _Triplet Triplet;
75 typedef enum _Server_state Server_state;
76 typedef struct _Unacked Unacked;
77 typedef struct _Pending Pending;
78 typedef struct _Server Server;
79 typedef enum _Sent_type Sent_type;
80 typedef struct _Statistic Statistic;
90 struct _Destlist *next, **prev_p;
93 typedef struct _galaxy_info {
94 Z_GalaxyConfig galaxy_config;
98 REALM_UP, /* Realm is up */
99 REALM_TARDY, /* Realm due for a hello XXX */
100 REALM_DEAD, /* Realm is considered dead */
101 REALM_STARTING /* Realm is between dead and up */
107 struct sockaddr_in *addrs;
108 int idx; /* which server we are connected to */
109 Destlist *subs; /* what their clients sub to */
110 Destlist *remsubs; /* our subs on their end */
125 struct sockaddr_in addr; /* ipaddr/port of client */
126 Destlist *subs ; /* subscriptions */
128 C_Block session_key; /* session key for this client */
129 #endif /* HAVE_KRB4 */
130 String *principal; /* krb principal of user */
131 int last_send; /* Counter for last sent packet. */
132 time_t last_ack; /* Time of last received ack */
134 struct _Client *next, **prev_p;
142 struct _Triplet *next, **prev_p;
146 SERV_UP, /* Server is up */
147 SERV_TARDY, /* Server due for a hello */
148 SERV_DEAD, /* Server is considered dead */
149 SERV_STARTING /* Server is between dead and up */
153 Timer *timer; /* timer for retransmit */
154 Client *client; /* responsible client, or NULL */
155 short rexmits; /* number of retransmits */
156 short packsz; /* size of packet */
157 char *packet; /* ptr to packet */
158 ZUnique_Id_t uid; /* uid of packet */
159 struct sockaddr_in ack_addr;
160 union { /* address to send to */
161 struct sockaddr_in addr; /* client address */
162 int srv_idx; /* index of server */
164 int rlm_idx; /* index of realm */
165 int rlm_srv_idx; /* index of server in realm */
168 struct _Unacked *next, **prev_p;
172 char *packet; /* the notice (in pkt form) */
173 short len; /* len of pkt */
174 unsigned int auth; /* whether it is authentic */
175 struct sockaddr_in who; /* the addr of the sender */
176 struct _Pending *next;
180 Server_state state; /* server's state */
181 struct sockaddr_in addr; /* server's address */
182 long timeout; /* Length of timeout in sec */
183 Timer *timer; /* timer for this server */
184 Pending *queue; /* queue of packets to send
185 to this server when done dumping */
186 Pending *queue_last; /* last packet on queue */
187 short num_hello_sent; /* number of hello's sent */
188 unsigned int dumping; /* 1 if dumping, so we should queue */
189 char addr_str[16]; /* text version of address */
193 NOT_SENT, /* message was not xmitted */
194 SENT, /* message was xmitted */
195 AUTH_FAILED, /* authentication failed */
196 NOT_FOUND /* user not found for uloc */
199 /* statistics gathering */
205 /* Function declarations */
207 /* found in bdump.c */
208 void bdump_get __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
210 void bdump_send __P((void));
211 void bdump_offer __P((struct sockaddr_in *who));
212 Code_t bdump_send_list_tcp __P((ZNotice_Kind_t kind, struct sockaddr_in *addr,
213 char *class_name, char *inst, char *opcode,
214 char *sender, char *recip, char **lyst,
216 int get_tgt __P((void));
218 /* found in class.c */
219 extern String *class_control, *class_admin, *class_hm;
220 extern String *class_ulogin, *class_ulocate;
221 int ZDest_eq __P((Destination *d1, Destination *d2));
222 Code_t triplet_register __P((Client *client, Destination *dest, Realm *realm));
223 Code_t triplet_deregister __P((Client *client, Destination *dest,
225 Code_t class_restrict __P((char *class, Acl *acl));
226 Code_t class_setup_restricted __P((char *class, Acl *acl));
227 Client **triplet_lookup __P((Destination *dest));
228 Acl *class_get_acl __P((String *class));
229 int dest_eq __P((Destination *d1, Destination *d2));
230 int order_dest_strings __P((Destination *d1, Destination *d2));
231 void triplet_dump_subs __P((FILE *fp));
233 /* found in client.c */
234 Code_t client_register __P((ZNotice_t *notice, struct in_addr *host,
235 Client **client_p, int wantdefaults));
236 void client_deregister __P((Client *client, int flush));
237 void client_flush_host __P((struct in_addr *host));
238 void client_dump_clients __P((FILE *fp));
239 Client *client_find __P((struct in_addr *host, unsigned int port));
240 Code_t client_send_clients __P((void));
242 /* found in common.c */
243 char *strsave __P((const char *str));
244 unsigned long hash __P((const char *));
245 void dump_quote __P((char *p, FILE *fp));
247 /* found in dispatch.c */
248 void handle_packet __P((void));
249 void clt_ack __P((ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent));
250 void nack_release __P((Client *client));
251 void sendit __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
252 int external, int local_dest));
253 void rexmit __P((void *));
254 void xmit __P((ZNotice_t *notice, struct sockaddr_in *dest, int auth,
256 Code_t hostm_dispatch __P((ZNotice_t *notice, int auth,
257 struct sockaddr_in *who, Server *server));
258 Code_t control_dispatch __P((ZNotice_t *notice, int auth,
259 struct sockaddr_in *who, Server *server));
260 Code_t xmit_frag __P((ZNotice_t *notice, char *buf, int len, int waitforack));
261 void hostm_shutdown __P((void));
263 /* found in kstuff.c */
265 int GetKerberosData __P((int, struct in_addr, AUTH_DAT *, char *, char *));
266 Code_t SendKerberosData __P((int, KTEXT, char *, char *));
267 void sweep_ticket_hash_table __P((void *));
271 /* found in kopt.c */
274 Sched *check_key_sched_cache __P((des_cblock key));
275 void add_to_key_sched_cache __P((des_cblock key, Sched *sched));
276 int krb_set_key __P((char *key, int cvt));
278 int krb_rd_req __P((KTEXT authent, char *service, char *instance,
279 unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn));
281 int krb_find_ticket __P((KTEXT authent, KTEXT ticket));
282 int krb_get_lrealm __P((char *r, int n));
287 /* found in server.c */
288 void server_timo __P((void *which));
289 void server_dump_servers __P((FILE *fp));
290 void server_init __P((void));
291 void server_shutdown __P((void));
292 void server_forward __P((ZNotice_t *notice, int auth,
293 struct sockaddr_in *who));
294 void server_kill_clt __P((Client *client));
295 void server_pending_free __P((Pending *pending));
296 void server_self_queue __P((ZNotice_t *, int, struct sockaddr_in *));
297 void server_send_queue __P((Server *));
298 void server_reset __P((void));
300 Server *server_which_server __P((struct sockaddr_in *who));
301 Pending *server_dequeue __P((Server *server));
302 Code_t server_dispatch __P((ZNotice_t *notice, int auth,
303 struct sockaddr_in *who));
304 Code_t server_adispatch __P((ZNotice_t *notice, int auth,
305 struct sockaddr_in *who, Server *server));
307 /* found in subscr.c */
308 Code_t subscr_foreign_user __P((ZNotice_t *, struct sockaddr_in *, Server *, Realm *));
309 Code_t subscr_cancel __P((struct sockaddr_in *sin, ZNotice_t *notice));
310 Code_t subscr_subscribe __P((Client *who, ZNotice_t *notice, Server *server));
311 Code_t subscr_send_subs __P((Client *client));
312 void subscr_cancel_client __P((Client *client));
313 void subscr_sendlist __P((ZNotice_t *notice, int auth,
314 struct sockaddr_in *who));
315 void subscr_dump_subs __P((FILE *fp, Destlist *subs));
316 void subscr_reset __P((void));
317 Code_t subscr_def_subs __P((Client *who));
319 /* found in uloc.c */
320 void uloc_hflush __P((struct in_addr *addr));
321 void uloc_flush_client __P((struct sockaddr_in *sin));
322 void uloc_dump_locs __P((FILE *fp));
323 Code_t ulogin_dispatch __P((ZNotice_t *notice, int auth,
324 struct sockaddr_in *who, Server *server));
325 Code_t ulocate_dispatch __P((ZNotice_t *notice, int auth,
326 struct sockaddr_in *who, Server *server));
327 Code_t uloc_send_locations __P((void));
329 /* found in realm.c */
330 int realm_sender_in_realm __P((char *realm, char *sender));
331 int realm_bound_for_my_galaxy __P((char *recip));
332 Realm *realm_which_realm __P((struct sockaddr_in *who));
333 Realm *realm_get_realm_by_name __P((char *name));
334 Realm *realm_get_realm_by_pid __P((int));
335 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, Realm *, int);
336 char *realm_expand_realm(char *);
337 void realm_init __P((void));
338 Code_t ZCheckRealmAuthentication __P((ZNotice_t *, struct sockaddr_in *,
340 Code_t realm_control_dispatch __P((ZNotice_t *, int, struct sockaddr_in *,
342 void realm_shutdown __P((void));
343 void realm_deathgram __P((Server *));
345 /* found in version.c */
346 char *get_version __P((void));
348 /* global identifiers */
350 /* found in main.c */
351 int packets_waiting __P((void));
352 extern struct sockaddr_in srv_addr; /* server socket address */
353 extern unsigned short hm_port; /* host manager receiver port */
354 extern unsigned short hm_srv_port; /* host manager server sending port */
355 extern int srv_socket; /* dgram sockets for clients
357 extern int bdump_socket; /* brain dump socket
358 (closed most of the time) */
360 extern fd_set interesting; /* the file descrips we are listening
362 extern int nfds; /* number to look at in select() */
364 extern galaxy_info *galaxy_list; /* list of all galaxies' servers */
365 extern int ngalaxies;
366 extern char myname[]; /* domain name of this host */
368 extern char srvtab_file[];
369 extern char my_krealm[];
371 extern char acl_dir[];
372 extern char subs_file[];
373 extern char localconf_file[];
374 extern u_long npackets; /* num of packets processed */
375 extern time_t uptime; /* time we started */
376 extern struct in_addr my_addr;
377 extern struct timeval t_local; /* current time */
379 /* found in bdump.c */
380 extern int bdumping; /* are we processing a bdump packet? */
381 extern int bdump_concurrent; /* set while processing a packet
382 * concurrently during a braindump. */
384 /* found in dispatch.c */
385 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
386 extern int rexmit_times[];
388 /* found in server.c */
389 extern char my_galaxy[]; /* local galaxy of this zserver */
390 extern Server *otherservers; /* array of servers */
391 extern int me_server_idx; /* me (in the array of servers) */
392 extern int nservers; /* number of other servers*/
394 /* found in subscr.c */
395 extern String *empty;
396 extern String *wildcard_instance;
398 extern Realm *otherrealms;
401 extern struct in_addr my_addr; /* my inet address */
403 #define class_is_control(classname) (classname == class_control)
404 #define class_is_admin(classname) (classname == class_admin)
405 #define class_is_hm(classname) (classname == class_hm)
406 #define class_is_ulogin(classname) (classname == class_ulogin)
407 #define class_is_ulocate(classname) (classname == class_ulocate)
409 #define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
410 #define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
411 #define ADMIN_SHUTDOWN "GOODBYE" /* Opcode: I am shutting down */
412 #define ADMIN_BDUMP "DUMP_AVAIL" /* Opcode: I will give you a dump */
413 #define ADMIN_DONE "DUMP_DONE" /* Opcode: brain dump for this server
415 #define ADMIN_NEWCLT "NEXT_CLIENT" /* Opcode: this is a new client */
416 #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */
417 #define ADMIN_STATUS "STATUS" /* Opcode: please send status */
419 #define ADMIN_NEWREALM "NEXT_REALM" /* Opcode: this is a new realm */
420 #define REALM_REQ_LOCATE "REQ_LOCATE" /* Opcode: request a location */
421 #define REALM_ANS_LOCATE "ANS_LOCATE" /* Opcode: answer to location */
422 #define REALM_BOOT "SENDSUBS" /* Opcode: first server in realm */
424 /* me_server_idx is the index into otherservers of this server descriptor. */
425 /* the 'limbo' server is always the first server */
427 #define me_server (&otherservers[me_server_idx])
428 #define limbo_server_idx() (0)
429 #define limbo_server (&otherservers[limbo_server_idx()])
431 #define msgs_queued() (ZQLength() || otherservers[me_server_idx].queue)
433 #define ack(a,b) clt_ack(a,b,SENT)
434 #define nack(a,b) clt_ack(a,b,NOT_SENT)
436 #define min(a,b) ((a) < (b) ? (a) : (b))
437 #define max(a,b) ((a) > (b) ? (a) : (b))
439 #define START_CRITICAL_CODE
440 #define END_CRITICAL_CODE
442 /* the instance that matches all instances */
443 #define WILDCARD_INSTANCE "*"
445 /* debugging macros */
447 #define zdbug(s1) if (zdebug) syslog s1;
452 #endif /* !__ZSERVER_H__ */