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>
20 #include <arpa/inet.h>
25 #include "zsrv_conf.h" /* configuration params */
31 #if defined(HAVE_KRB4) || defined(HAVE_KRB5)
32 /* Kerberos-specific library interfaces used only by the server. */
33 extern C_Block __Zephyr_session;
34 #define ZGetSession() (__Zephyr_session)
35 void ZSetSession(krb5_keyblock *keyblock);
36 void ZSetSessionDES(C_Block *key);
38 Code_t ZFormatAuthenticNotice __P((ZNotice_t*, char*, int, int*, C_Block));
41 /* For krb_rd_req prototype and definition. */
43 #define KRB_INT32 ZEPHYR_INT32
46 /* These macros are for insertion into and deletion from a singly-linked list
47 * with back pointers to the previous element's next pointer. In order to
48 * make these macros act like expressions, they use the comma operator for
49 * sequenced evaluations of assignment, and "a && b" for "evaluate assignment
50 * b if expression a is true". */
51 #define LIST_INSERT(head, elem) \
52 ((elem)->next = *(head), \
53 (*head) && ((*(head))->prev_p = &(elem)->next), \
54 (*head) = (elem), (elem)->prev_p = (head))
55 #define LIST_DELETE(elem) \
56 (*(elem)->prev_p = (elem)->next, \
57 (elem)->next && ((elem)->next->prev_p = (elem)->prev_p))
59 /* Current time as cached by main(); use instead of time(). */
60 #define NOW t_local.tv_sec
64 /* 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 C_Block session_key; /* session key for this client */
128 #endif /* HAVE_KRB4 */
129 String *principal; /* krb principal of user */
130 int last_send; /* Counter for last sent packet. */
131 time_t last_ack; /* Time of last received ack */
133 struct _Client *next, **prev_p;
141 struct _Triplet *next, **prev_p;
145 SERV_UP, /* Server is up */
146 SERV_TARDY, /* Server due for a hello */
147 SERV_DEAD, /* Server is considered dead */
148 SERV_STARTING /* Server is between dead and up */
152 Timer *timer; /* timer for retransmit */
153 Client *client; /* responsible client, or NULL */
154 short rexmits; /* number of retransmits */
155 short packsz; /* size of packet */
156 char *packet; /* ptr to packet */
157 ZUnique_Id_t uid; /* uid of packet */
158 struct sockaddr_in ack_addr;
159 union { /* address to send to */
160 struct sockaddr_in addr; /* client address */
161 int srv_idx; /* index of server */
163 int rlm_idx; /* index of realm */
164 int rlm_srv_idx; /* index of server in realm */
167 struct _Unacked *next, **prev_p;
171 char *packet; /* the notice (in pkt form) */
172 short len; /* len of pkt */
173 unsigned int auth; /* whether it is authentic */
174 struct sockaddr_in who; /* the addr of the sender */
175 struct _Pending *next;
179 Server_state state; /* server's state */
180 struct sockaddr_in addr; /* server's address */
181 long timeout; /* Length of timeout in sec */
182 Timer *timer; /* timer for this server */
183 Pending *queue; /* queue of packets to send
184 to this server when done dumping */
185 Pending *queue_last; /* last packet on queue */
186 short num_hello_sent; /* number of hello's sent */
187 unsigned int dumping; /* 1 if dumping, so we should queue */
188 char addr_str[16]; /* text version of address */
192 NOT_SENT, /* message was not xmitted */
193 SENT, /* message was xmitted */
194 AUTH_FAILED, /* authentication failed */
195 NOT_FOUND /* user not found for uloc */
198 /* statistics gathering */
204 /* Function declarations */
206 /* found in bdump.c */
207 void bdump_get __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
209 void bdump_send __P((void));
210 void bdump_offer __P((struct sockaddr_in *who));
211 Code_t bdump_send_list_tcp __P((ZNotice_Kind_t kind, struct sockaddr_in *addr,
212 char *class_name, char *inst, char *opcode,
213 char *sender, char *recip, char **lyst,
215 int get_tgt __P((void));
217 /* found in class.c */
218 extern String *class_control, *class_admin, *class_hm;
219 extern String *class_ulogin, *class_ulocate;
220 int ZDest_eq __P((Destination *d1, Destination *d2));
221 Code_t triplet_register __P((Client *client, Destination *dest, ZRealm *realm));
222 Code_t triplet_deregister __P((Client *client, Destination *dest,
224 Code_t class_restrict __P((char *class, Acl *acl));
225 Code_t class_setup_restricted __P((char *class, Acl *acl));
226 Client **triplet_lookup __P((Destination *dest));
227 Acl *class_get_acl __P((String *class));
228 int dest_eq __P((Destination *d1, Destination *d2));
229 int order_dest_strings __P((Destination *d1, Destination *d2));
230 void triplet_dump_subs __P((FILE *fp));
232 /* found in client.c */
233 Code_t client_register __P((ZNotice_t *notice, struct in_addr *host,
234 Client **client_p, int wantdefaults));
235 void client_deregister __P((Client *client, int flush));
236 void client_flush_host __P((struct in_addr *host));
237 void client_dump_clients __P((FILE *fp));
238 Client *client_find __P((struct in_addr *host, unsigned int port));
239 Code_t client_send_clients __P((void));
241 /* found in common.c */
242 char *strsave __P((const char *str));
243 unsigned long hash __P((const char *));
244 void dump_quote __P((char *p, FILE *fp));
246 /* found in dispatch.c */
247 void handle_packet __P((void));
248 void clt_ack __P((ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent));
249 void nack_release __P((Client *client));
250 void sendit __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
252 void rexmit __P((void *));
253 void xmit __P((ZNotice_t *notice, struct sockaddr_in *dest, int auth,
255 Code_t hostm_dispatch __P((ZNotice_t *notice, int auth,
256 struct sockaddr_in *who, Server *server));
257 Code_t control_dispatch __P((ZNotice_t *notice, int auth,
258 struct sockaddr_in *who, Server *server));
259 Code_t xmit_frag __P((ZNotice_t *notice, char *buf, int len, int waitforack));
260 void hostm_shutdown __P((void));
262 /* found in kstuff.c */
264 int GetKerberosData __P((int, struct in_addr, AUTH_DAT *, char *, char *));
265 Code_t SendKerberosData __P((int, KTEXT, char *, char *));
266 void sweep_ticket_hash_table __P((void *));
269 /* found in kopt.c */
272 Sched *check_key_sched_cache __P((des_cblock key));
273 void add_to_key_sched_cache __P((des_cblock key, Sched *sched));
274 int krb_set_key __P((char *key, int cvt));
275 /* int krb_rd_req __P((KTEXT authent, char *service, char *instance,
276 unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn)); */
277 int krb_find_ticket __P((KTEXT authent, KTEXT ticket));
278 int krb_get_lrealm __P((char *r, int n));
282 /* found in server.c */
283 void server_timo __P((void *which));
284 void server_dump_servers __P((FILE *fp));
285 void server_init __P((void));
286 void server_shutdown __P((void));
287 void server_forward __P((ZNotice_t *notice, int auth,
288 struct sockaddr_in *who));
289 void server_kill_clt __P((Client *client));
290 void server_pending_free __P((Pending *pending));
291 void server_self_queue __P((ZNotice_t *, int, struct sockaddr_in *));
292 void server_send_queue __P((Server *));
293 void server_reset __P((void));
295 Server *server_which_server __P((struct sockaddr_in *who));
296 Pending *server_dequeue __P((Server *server));
297 Code_t server_dispatch __P((ZNotice_t *notice, int auth,
298 struct sockaddr_in *who));
299 Code_t server_adispatch __P((ZNotice_t *notice, int auth,
300 struct sockaddr_in *who, Server *server));
302 /* found in subscr.c */
303 Code_t subscr_foreign_user __P((ZNotice_t *, struct sockaddr_in *, Server *, ZRealm *));
304 Code_t subscr_cancel __P((struct sockaddr_in *sin, ZNotice_t *notice));
305 Code_t subscr_subscribe __P((Client *who, ZNotice_t *notice, Server *server));
306 Code_t subscr_send_subs __P((Client *client));
307 void subscr_cancel_client __P((Client *client));
308 void subscr_sendlist __P((ZNotice_t *notice, int auth,
309 struct sockaddr_in *who));
310 void subscr_dump_subs __P((FILE *fp, Destlist *subs));
311 void subscr_reset __P((void));
312 Code_t subscr_def_subs __P((Client *who));
314 /* found in uloc.c */
315 void uloc_hflush __P((struct in_addr *addr));
316 void uloc_flush_client __P((struct sockaddr_in *sin));
317 void uloc_dump_locs __P((FILE *fp));
318 Code_t ulogin_dispatch __P((ZNotice_t *notice, int auth,
319 struct sockaddr_in *who, Server *server));
320 Code_t ulocate_dispatch __P((ZNotice_t *notice, int auth,
321 struct sockaddr_in *who, Server *server));
322 Code_t uloc_send_locations __P((void));
324 /* found in realm.c */
325 int realm_sender_in_realm __P((char *realm, char *sender));
326 int realm_bound_for_realm __P((char *realm, char *recip));
327 ZRealm *realm_which_realm __P((struct sockaddr_in *who));
328 ZRealm *realm_get_realm_by_name __P((char *name));
329 ZRealm *realm_get_realm_by_pid __P((int));
330 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, ZRealm *, int);
331 char *realm_expand_realm(char *);
332 void realm_init __P((void));
333 Code_t ZCheckZRealmAuthentication __P((ZNotice_t *, struct sockaddr_in *,
335 Code_t realm_control_dispatch __P((ZNotice_t *, int, struct sockaddr_in *,
336 Server *, ZRealm *));
337 void realm_shutdown __P((void));
338 void realm_deathgram __P((Server *));
340 /* found in version.c */
341 char *get_version __P((void));
343 /* global identifiers */
345 /* found in main.c */
346 int packets_waiting __P((void));
347 extern struct sockaddr_in srv_addr; /* server socket address */
348 extern unsigned short hm_port; /* host manager receiver port */
349 extern unsigned short hm_srv_port; /* host manager server sending port */
350 extern int srv_socket; /* dgram sockets for clients
352 extern int bdump_socket; /* brain dump socket
353 (closed most of the time) */
355 extern fd_set interesting; /* the file descrips we are listening
357 extern int nfds; /* number to look at in select() */
359 extern char myname[]; /* domain name of this host */
360 extern char list_file[];
362 extern char keytab_file[];
363 extern krb5_ccache Z_krb5_ccache;
366 extern char srvtab_file[];
367 extern char my_realm[];
369 extern char acl_dir[];
370 extern char subs_file[];
371 extern const char version[];
372 extern u_long npackets; /* num of packets processed */
373 extern time_t uptime; /* time we started */
374 extern struct in_addr my_addr;
375 extern struct timeval t_local; /* current time */
377 /* found in bdump.c */
378 extern int bdumping; /* are we processing a bdump packet? */
379 extern int bdump_concurrent; /* set while processing a packet
380 * concurrently during a braindump. */
382 /* found in dispatch.c */
383 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
384 extern int rexmit_times[];
386 /* found in server.c */
387 extern Server *otherservers; /* array of servers */
388 extern int me_server_idx; /* me (in the array of servers) */
389 extern int nservers; /* number of other servers*/
391 /* found in subscr.c */
392 extern String *empty;
393 extern String *wildcard_instance;
395 extern ZRealm *otherrealms;
398 extern struct in_addr my_addr; /* my inet address */
400 #define class_is_control(classname) (classname == class_control)
401 #define class_is_admin(classname) (classname == class_admin)
402 #define class_is_hm(classname) (classname == class_hm)
403 #define class_is_ulogin(classname) (classname == class_ulogin)
404 #define class_is_ulocate(classname) (classname == class_ulocate)
406 #define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
407 #define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
408 #define ADMIN_SHUTDOWN "GOODBYE" /* Opcode: I am shutting down */
409 #define ADMIN_BDUMP "DUMP_AVAIL" /* Opcode: I will give you a dump */
410 #define ADMIN_DONE "DUMP_DONE" /* Opcode: brain dump for this server
412 #define ADMIN_NEWCLT "NEXT_CLIENT" /* Opcode: this is a new client */
413 #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */
414 #define ADMIN_STATUS "STATUS" /* Opcode: please send status */
416 #define ADMIN_NEWREALM "NEXT_REALM" /* Opcode: this is a new realm */
417 #define REALM_REQ_LOCATE "REQ_LOCATE" /* Opcode: request a location */
418 #define REALM_ANS_LOCATE "ANS_LOCATE" /* Opcode: answer to location */
419 #define REALM_BOOT "SENDSUBS" /* Opcode: first server in realm */
421 /* me_server_idx is the index into otherservers of this server descriptor. */
422 /* the 'limbo' server is always the first server */
424 #define me_server (&otherservers[me_server_idx])
425 #define limbo_server_idx() (0)
426 #define limbo_server (&otherservers[limbo_server_idx()])
428 #define msgs_queued() (ZQLength() || otherservers[me_server_idx].queue)
430 #define ack(a,b) clt_ack(a,b,SENT)
431 #define nack(a,b) clt_ack(a,b,NOT_SENT)
433 #define min(a,b) ((a) < (b) ? (a) : (b))
434 #define max(a,b) ((a) > (b) ? (a) : (b))
436 #define START_CRITICAL_CODE
437 #define END_CRITICAL_CODE
439 /* the instance that matches all instances */
440 #define WILDCARD_INSTANCE "*"
442 /* debugging macros */
444 #define zdbug(s1) if (zdebug) syslog s1;
449 #endif /* !__ZSERVER_H__ */