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 * $Id: zserver.h,v 1.51 1999/01/22 23:19:53 ghudson Exp $
10 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, see the file
15 #include <zephyr/mit-copyright.h>
18 #include <arpa/inet.h>
23 #include "zsrv_conf.h" /* configuration params */
30 /* Kerberos-specific library interfaces used only by the server. */
31 extern C_Block __Zephyr_session;
32 #define ZGetSession() (__Zephyr_session)
33 Code_t ZFormatAuthenticNotice __P((ZNotice_t*, char*, int, int*, C_Block));
36 /* For krb_rd_req prototype and definition. */
38 #define KRB_INT32 ZEPHYR_INT32
41 /* These macros are for insertion into and deletion from a singly-linked list
42 * with back pointers to the previous element's next pointer. In order to
43 * make these macros act like expressions, they use the comma operator for
44 * sequenced evaluations of assignment, and "a && b" for "evaluate assignment
45 * b if expression a is true". */
46 #define LIST_INSERT(head, elem) \
47 ((elem)->next = *(head), \
48 (*head) && ((*(head))->prev_p = &(elem)->next), \
49 (*head) = (elem), (elem)->prev_p = (head))
50 #define LIST_DELETE(elem) \
51 (*(elem)->prev_p = (elem)->next, \
52 (elem)->next && ((elem)->next->prev_p = (elem)->prev_p))
54 /* Current time as cached by main(); use instead of time(). */
55 #define NOW t_local.tv_sec
59 /* Kerberos shouldn't stick us with array types... */
66 typedef struct _Destination Destination;
67 typedef struct _Destlist Destlist;
68 typedef struct _Realm Realm;
69 typedef struct _Realmname Realmname;
70 typedef struct _Client Client;
71 typedef struct _Triplet Triplet;
72 typedef enum _Server_state Server_state;
73 typedef struct _Unacked Unacked;
74 typedef struct _Pending Pending;
75 typedef struct _Server Server;
76 typedef enum _Sent_type Sent_type;
77 typedef struct _Statistic Statistic;
87 struct _Destlist *next, **prev_p;
93 struct sockaddr_in *addrs;
94 int idx; /* which server we are connected to */
108 struct sockaddr_in addr; /* ipaddr/port of client */
109 Destlist *subs ; /* subscriptions */
111 C_Block session_key; /* session key for this client */
112 #endif /* HAVE_KRB4 */
113 String *principal; /* krb principal of user */
114 int last_send; /* Counter for last sent packet. */
115 time_t last_ack; /* Time of last received ack */
117 struct _Client *next, **prev_p;
125 struct _Triplet *next, **prev_p;
129 SERV_UP, /* Server is up */
130 SERV_TARDY, /* Server due for a hello */
131 SERV_DEAD, /* Server is considered dead */
132 SERV_STARTING /* Server is between dead and up */
136 Timer *timer; /* timer for retransmit */
137 Client *client; /* responsible client, or NULL */
138 short rexmits; /* number of retransmits */
139 short packsz; /* size of packet */
140 char *packet; /* ptr to packet */
141 ZUnique_Id_t uid; /* uid of packet */
142 struct sockaddr_in ack_addr;
143 union { /* address to send to */
144 struct sockaddr_in addr; /* client address */
145 int srv_idx; /* index of server */
147 int rlm_idx; /* index of realm */
148 int rlm_srv_idx; /* index of server in realm */
151 struct _Unacked *next, **prev_p;
155 char *packet; /* the notice (in pkt form) */
156 short len; /* len of pkt */
157 unsigned int auth; /* whether it is authentic */
158 struct sockaddr_in who; /* the addr of the sender */
159 struct _Pending *next;
163 Server_state state; /* server's state */
164 struct sockaddr_in addr; /* server's address */
165 long timeout; /* Length of timeout in sec */
166 Timer *timer; /* timer for this server */
167 Pending *queue; /* queue of packets to send
168 to this server when done dumping */
169 Pending *queue_last; /* last packet on queue */
170 short num_hello_sent; /* number of hello's sent */
171 unsigned int dumping; /* 1 if dumping, so we should queue */
172 char addr_str[16]; /* text version of address */
176 NOT_SENT, /* message was not xmitted */
177 SENT, /* message was xmitted */
178 AUTH_FAILED, /* authentication failed */
179 NOT_FOUND /* user not found for uloc */
182 /* statistics gathering */
188 /* Function declarations */
190 /* found in bdump.c */
191 void bdump_get __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
193 void bdump_send __P((void));
194 void bdump_offer __P((struct sockaddr_in *who));
195 Code_t bdump_send_list_tcp __P((ZNotice_Kind_t kind, struct sockaddr_in *addr,
196 char *class_name, char *inst, char *opcode,
197 char *sender, char *recip, char **lyst,
199 int get_tgt __P((void));
201 /* found in class.c */
202 extern String *class_control, *class_admin, *class_hm;
203 extern String *class_ulogin, *class_ulocate;
204 int ZDest_eq __P((Destination *d1, Destination *d2));
205 Code_t triplet_register __P((Client *client, Destination *dest, Realm *realm));
206 Code_t triplet_deregister __P((Client *client, Destination *dest,
208 Code_t class_restrict __P((char *class, Acl *acl));
209 Code_t class_setup_restricted __P((char *class, Acl *acl));
210 Client **triplet_lookup __P((Destination *dest));
211 Acl *class_get_acl __P((String *class));
212 int dest_eq __P((Destination *d1, Destination *d2));
213 int order_dest_strings __P((Destination *d1, Destination *d2));
214 void triplet_dump_subs __P((FILE *fp));
216 /* found in client.c */
217 Code_t client_register __P((ZNotice_t *notice, struct in_addr *host,
218 Client **client_p, int wantdefaults));
219 void client_deregister __P((Client *client, int flush));
220 void client_flush_host __P((struct in_addr *host));
221 void client_dump_clients __P((FILE *fp));
222 Client *client_find __P((struct in_addr *host, unsigned int port));
223 Code_t client_send_clients __P((void));
225 /* found in common.c */
226 char *strsave __P((const char *str));
227 unsigned long hash __P((const char *));
228 void dump_quote __P((char *p, FILE *fp));
230 /* found in dispatch.c */
231 void handle_packet __P((void));
232 void clt_ack __P((ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent));
233 void nack_release __P((Client *client));
234 void sendit __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
236 void rexmit __P((void *));
237 void xmit __P((ZNotice_t *notice, struct sockaddr_in *dest, int auth,
239 Code_t hostm_dispatch __P((ZNotice_t *notice, int auth,
240 struct sockaddr_in *who, Server *server));
241 Code_t control_dispatch __P((ZNotice_t *notice, int auth,
242 struct sockaddr_in *who, Server *server));
243 Code_t xmit_frag __P((ZNotice_t *notice, char *buf, int len, int waitforack));
244 void hostm_shutdown __P((void));
246 /* found in kstuff.c */
248 int GetKerberosData __P((int, struct in_addr, AUTH_DAT *, char *, char *));
249 Code_t SendKerberosData __P((int, KTEXT, char *, char *));
250 void sweep_ticket_hash_table __P((void *));
253 /* found in kopt.c */
256 Sched *check_key_sched_cache __P((des_cblock key));
257 void add_to_key_sched_cache __P((des_cblock key, Sched *sched));
258 int krb_set_key __P((char *key, int cvt));
259 int krb_rd_req __P((KTEXT authent, char *service, char *instance,
260 unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn));
261 int krb_find_ticket __P((KTEXT authent, KTEXT ticket));
262 int krb_get_lrealm __P((char *r, int n));
266 /* found in server.c */
267 void server_timo __P((void *which));
268 void server_dump_servers __P((FILE *fp));
269 void server_init __P((void));
270 void server_shutdown __P((void));
271 void server_forward __P((ZNotice_t *notice, int auth,
272 struct sockaddr_in *who));
273 void server_kill_clt __P((Client *client));
274 void server_pending_free __P((Pending *pending));
275 void server_self_queue __P((ZNotice_t *, int, struct sockaddr_in *));
276 void server_send_queue __P((Server *));
277 void server_reset __P((void));
279 Server *server_which_server __P((struct sockaddr_in *who));
280 Pending *server_dequeue __P((Server *server));
281 Code_t server_dispatch __P((ZNotice_t *notice, int auth,
282 struct sockaddr_in *who));
283 Code_t server_adispatch __P((ZNotice_t *notice, int auth,
284 struct sockaddr_in *who, Server *server));
286 /* found in subscr.c */
287 Code_t subscr_cancel __P((struct sockaddr_in *sin, ZNotice_t *notice));
288 Code_t subscr_subscribe __P((Client *who, ZNotice_t *notice));
289 Code_t subscr_send_subs __P((Client *client));
290 void subscr_cancel_client __P((Client *client));
291 void subscr_sendlist __P((ZNotice_t *notice, int auth,
292 struct sockaddr_in *who));
293 void subscr_dump_subs __P((FILE *fp, Destlist *subs));
294 void subscr_reset __P((void));
295 Code_t subscr_def_subs __P((Client *who));
297 /* found in uloc.c */
298 void uloc_hflush __P((struct in_addr *addr));
299 void uloc_flush_client __P((struct sockaddr_in *sin));
300 void uloc_dump_locs __P((FILE *fp));
301 Code_t ulogin_dispatch __P((ZNotice_t *notice, int auth,
302 struct sockaddr_in *who, Server *server));
303 Code_t ulocate_dispatch __P((ZNotice_t *notice, int auth,
304 struct sockaddr_in *who, Server *server));
305 Code_t uloc_send_locations __P((void));
307 /* found in realm.c */
308 Realm *realm_which_realm __P((struct sockaddr_in *who));
309 Realm *realm_get_realm_by_name __P((char *name));
310 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, Realm *, int);
311 char *realm_expand_realm(char *);
312 void realm_init __P((void));
313 Code_t ZCheckRealmAuthentication __P((ZNotice_t *, struct sockaddr_in *,
315 Code_t realm_control_dispatch __P((ZNotice_t *, int, struct sockaddr_in *,
318 /* found in version.c */
319 char *get_version __P((void));
321 /* global identifiers */
323 /* found in main.c */
324 int packets_waiting __P((void));
325 extern struct sockaddr_in srv_addr; /* server socket address */
326 extern unsigned short hm_port; /* host manager receiver port */
327 extern unsigned short hm_srv_port; /* host manager server sending port */
328 extern int srv_socket; /* dgram sockets for clients
330 extern int bdump_socket; /* brain dump socket
331 (closed most of the time) */
333 extern fd_set interesting; /* the file descrips we are listening
335 extern int nfds; /* number to look at in select() */
337 extern char myname[]; /* domain name of this host */
339 extern char list_file[];
342 extern char srvtab_file[];
343 extern char my_realm[];
345 extern char acl_dir[];
346 extern char subs_file[];
347 extern const char version[];
348 extern u_long npackets; /* num of packets processed */
349 extern time_t uptime; /* time we started */
350 extern struct in_addr my_addr;
351 extern struct timeval t_local; /* current time */
353 /* found in bdump.c */
354 extern int bdumping; /* are we processing a bdump packet? */
355 extern int bdump_concurrent; /* set while processing a packet
356 * concurrently during a braindump. */
358 /* found in dispatch.c */
359 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
360 extern int rexmit_times[];
362 /* found in server.c */
363 extern Server *otherservers; /* array of servers */
364 extern int me_server_idx; /* me (in the array of servers) */
365 extern int nservers; /* number of other servers*/
367 /* found in subscr.c */
368 extern String *empty;
369 extern String *wildcard_instance;
371 extern struct in_addr my_addr; /* my inet address */
373 #define class_is_control(classname) (classname == class_control)
374 #define class_is_admin(classname) (classname == class_admin)
375 #define class_is_hm(classname) (classname == class_hm)
376 #define class_is_ulogin(classname) (classname == class_ulogin)
377 #define class_is_ulocate(classname) (classname == class_ulocate)
379 #define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
380 #define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
381 #define ADMIN_SHUTDOWN "GOODBYE" /* Opcode: I am shutting down */
382 #define ADMIN_BDUMP "DUMP_AVAIL" /* Opcode: I will give you a dump */
383 #define ADMIN_DONE "DUMP_DONE" /* Opcode: brain dump for this server
385 #define ADMIN_NEWCLT "NEXT_CLIENT" /* Opcode: this is a new client */
386 #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */
387 #define ADMIN_STATUS "STATUS" /* Opcode: please send status */
389 #define ADMIN_NEWREALM "NEXT_REALM" /* Opcode: this is a new realm */
390 #define REALM_REQ_LOCATE "REQ_LOCATE" /* Opcode: request a location */
391 #define REALM_ANS_LOCATE "ANS_LOCATE" /* Opcode: answer to location */
393 /* me_server_idx is the index into otherservers of this server descriptor. */
394 /* the 'limbo' server is always the first server */
396 #define me_server (&otherservers[me_server_idx])
397 #define limbo_server_idx() (0)
398 #define limbo_server (&otherservers[limbo_server_idx()])
400 #define msgs_queued() (ZQLength() || otherservers[me_server_idx].queue)
402 #define ack(a,b) clt_ack(a,b,SENT)
403 #define nack(a,b) clt_ack(a,b,NOT_SENT)
405 #define min(a,b) ((a) < (b) ? (a) : (b))
406 #define max(a,b) ((a) > (b) ? (a) : (b))
408 #define START_CRITICAL_CODE
409 #define END_CRITICAL_CODE
411 /* the instance that matches all instances */
412 #define WILDCARD_INSTANCE "*"
414 /* debugging macros */
416 #define zdbug(s1) if (zdebug) syslog s1;
421 #endif /* !__ZSERVER_H__ */