]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/server/zserver.h
541600e8490a90d932a7118f94b8344cd01259d2
[1ts-debian.git] / zephyr / server / zserver.h
1 #ifndef __ZSERVER_H__
2 #define __ZSERVER_H__
3 /* This file is part of the Project Athena Zephyr Notification System.
4  * It contains declarations for use in the server.
5  *
6  *      Created by:     John T. Kohl
7  *
8  *      $Source: /afs/dev.mit.edu/source/repository/athena/lib/zephyr/server/zserver.h,v $
9  *      $Author: zacheiss $
10  *      $Zephyr: /mit/zephyr/src/server/RCS/zserver.h,v 1.34 91/03/08 12:53:24 raeburn Exp $
11  *
12  *      Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
13  *      For copying and distribution information, see the file
14  *      "mit-copyright.h". 
15  */
16
17 #include <zephyr/mit-copyright.h>
18
19 #include <internal.h>
20 #include <arpa/inet.h>
21
22 #include "zsrv_err.h"
23
24 #include "timer.h"
25 #include "zsrv_conf.h"                  /* configuration params */
26
27 #include "zstring.h"
28 #include "access.h"
29 #include "acl.h"
30
31 #ifdef HAVE_KRB4
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));
36 #endif
37
38 /* For krb_rd_req prototype and definition. */
39 #ifndef KRB_INT32
40 #define KRB_INT32 ZEPHYR_INT32
41 #endif
42
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))
55
56 /* Current time as cached by main(); use instead of time(). */
57 #define NOW t_local.tv_sec
58
59 #ifdef HAVE_KRB4
60 #ifndef NOENCRYPTION
61 /* Kerberos shouldn't stick us with array types... */
62 typedef struct {
63     des_key_schedule s;
64 } Sched;
65 #endif
66 #endif
67
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;
81
82 struct _Destination {
83     String              *classname;
84     String              *inst;
85     String              *recip;
86 };
87
88 struct _Destlist {
89     Destination dest;
90     struct _Destlist    *next, **prev_p;
91 };
92
93 enum _Realm_state {
94     REALM_UP,                           /* Realm is up */
95     REALM_TARDY,                        /* Realm due for a hello XXX */
96     REALM_DEAD,                         /* Realm is considered dead */
97     REALM_STARTING                      /* Realm is between dead and up */
98 };
99
100 struct _Realm {
101     char name[REALM_SZ];
102     int count;
103     struct sockaddr_in *addrs;
104     int idx;                            /* which server we are connected to */
105     Destlist *subs;                     /* what their clients sub to */
106     Destlist *remsubs;                  /* our subs on their end */
107     Client *client;                     
108     int child_pid;
109     int have_tkt;
110     Realm_state state;
111 };
112
113 struct _Realmname {
114     char name[REALM_SZ];
115     char **servers;
116     int nused;
117     int nservers;
118 };
119
120 struct _Client {
121     struct sockaddr_in  addr;           /* ipaddr/port of client */
122     Destlist            *subs   ;       /* subscriptions */
123 #ifdef HAVE_KRB4
124     C_Block             session_key;    /* session key for this client */
125 #endif /* HAVE_KRB4 */
126     String              *principal;     /* krb principal of user */
127     int                 last_send;      /* Counter for last sent packet. */
128     time_t              last_ack;       /* Time of last received ack */
129     Realm               *realm;
130     struct _Client      *next, **prev_p;
131 };
132
133 struct _Triplet {
134     Destination         dest;
135     Acl                 *acl;
136     Client              **clients;
137     int                 clients_size;
138     struct _Triplet     *next, **prev_p;
139 };
140
141 enum _Server_state {
142     SERV_UP,                            /* Server is up */
143     SERV_TARDY,                         /* Server due for a hello */
144     SERV_DEAD,                          /* Server is considered dead */
145     SERV_STARTING                       /* Server is between dead and up */
146 };
147
148 struct _Unacked {
149     Timer               *timer;         /* timer for retransmit */
150     Client              *client;        /* responsible client, or NULL */
151     short               rexmits;        /* number of retransmits */
152     short               packsz;         /* size of packet */
153     char                *packet;        /* ptr to packet */
154     ZUnique_Id_t        uid;            /* uid of packet */
155     struct sockaddr_in  ack_addr;
156     union {                             /* address to send to */
157         struct sockaddr_in addr;        /* client address */
158         int     srv_idx;                /* index of server */
159         struct {
160             int rlm_idx;                /* index of realm */
161             int rlm_srv_idx;            /* index of server in realm */
162         } rlm;
163     } dest;
164     struct _Unacked *next, **prev_p;
165 };
166
167 struct _Pending {
168     char                *packet;        /* the notice (in pkt form) */
169     short               len;            /* len of pkt */
170     unsigned int        auth;           /* whether it is authentic */
171     struct sockaddr_in who;             /* the addr of the sender */
172     struct _Pending *next;
173 };
174
175 struct _Server {
176     Server_state        state;          /* server's state */
177     struct sockaddr_in  addr;           /* server's address */
178     long                timeout;        /* Length of timeout in sec */
179     Timer               *timer;         /* timer for this server */
180     Pending             *queue;         /* queue of packets to send
181                                            to this server when done dumping */
182     Pending             *queue_last;    /* last packet on queue */
183     short               num_hello_sent; /* number of hello's sent */
184     unsigned int        dumping;        /* 1 if dumping, so we should queue */
185     char                addr_str[16];   /* text version of address */
186 };
187
188 enum _Sent_type {
189     NOT_SENT,                           /* message was not xmitted */
190     SENT,                               /* message was xmitted */
191     AUTH_FAILED,                        /* authentication failed */
192     NOT_FOUND                           /* user not found for uloc */
193 };
194
195 /* statistics gathering */
196 struct _Statistic {
197     int                 val;
198     char                *str;
199 };
200
201 /* Function declarations */
202         
203 /* found in bdump.c */
204 void bdump_get __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
205                     Server *server));
206 void bdump_send __P((void));
207 void bdump_offer __P((struct sockaddr_in *who));
208 Code_t bdump_send_list_tcp __P((ZNotice_Kind_t kind, struct sockaddr_in *addr,
209                                 char *class_name, char *inst, char *opcode,
210                                 char *sender, char *recip, char **lyst,
211                                 int num));
212 int get_tgt __P((void));
213
214 /* found in class.c */
215 extern String *class_control, *class_admin, *class_hm;
216 extern String *class_ulogin, *class_ulocate;
217 int ZDest_eq __P((Destination *d1, Destination *d2));
218 Code_t triplet_register __P((Client *client, Destination *dest, Realm *realm));
219 Code_t triplet_deregister __P((Client *client, Destination *dest,
220                                Realm *realm));
221 Code_t class_restrict __P((char *class, Acl *acl));
222 Code_t class_setup_restricted __P((char *class, Acl *acl));
223 Client **triplet_lookup __P((Destination *dest));
224 Acl *class_get_acl __P((String *class));
225 int dest_eq __P((Destination *d1, Destination *d2));
226 int order_dest_strings __P((Destination *d1, Destination *d2));
227 void triplet_dump_subs __P((FILE *fp));
228
229 /* found in client.c */
230 Code_t client_register __P((ZNotice_t *notice, struct in_addr *host,
231                             Client **client_p, int wantdefaults));
232 void client_deregister __P((Client *client, int flush)); 
233 void client_flush_host __P((struct in_addr *host));
234 void client_dump_clients __P((FILE *fp));
235 Client *client_find __P((struct in_addr *host, unsigned int port));
236 Code_t client_send_clients __P((void));
237
238 /* found in common.c */
239 char *strsave __P((const char *str));
240 unsigned long hash  __P((const char *));
241 void dump_quote __P((char *p, FILE *fp));
242
243 /* found in dispatch.c */
244 void handle_packet __P((void));
245 void clt_ack __P((ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent));
246 void nack_release __P((Client *client));
247 void sendit __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
248                  int external));
249 void rexmit __P((void *));
250 void xmit __P((ZNotice_t *notice, struct sockaddr_in *dest, int auth,
251                Client *client));
252 Code_t hostm_dispatch __P((ZNotice_t *notice, int auth,
253                            struct sockaddr_in *who, Server *server));
254 Code_t control_dispatch __P((ZNotice_t *notice, int auth,
255                              struct sockaddr_in *who, Server *server));
256 Code_t xmit_frag __P((ZNotice_t *notice, char *buf, int len, int waitforack));
257 void hostm_shutdown __P((void));
258
259 /* found in kstuff.c */
260 #ifdef HAVE_KRB4
261 int GetKerberosData  __P((int, struct in_addr, AUTH_DAT *, char *, char *));
262 Code_t SendKerberosData  __P((int, KTEXT, char *, char *));
263 void sweep_ticket_hash_table __P((void *));
264 #endif
265
266 /* found in kopt.c */
267 #ifdef HAVE_KRB4
268 #ifndef NOENCRYPTION
269 Sched *check_key_sched_cache __P((des_cblock key));
270 void add_to_key_sched_cache __P((des_cblock key, Sched *sched));
271 int krb_set_key __P((char *key, int cvt));
272 /* int krb_rd_req __P((KTEXT authent, char *service, char *instance,
273                     unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn)); */
274 int krb_find_ticket __P((KTEXT authent, KTEXT ticket));
275 int krb_get_lrealm __P((char *r, int n));
276 #endif
277 #endif
278
279 /* found in server.c */
280 void server_timo __P((void *which));
281 void server_dump_servers __P((FILE *fp));
282 void server_init __P((void));
283 void server_shutdown __P((void));
284 void server_forward __P((ZNotice_t *notice, int auth,
285                          struct sockaddr_in *who));
286 void server_kill_clt __P((Client *client));
287 void server_pending_free __P((Pending *pending));
288 void server_self_queue __P((ZNotice_t *, int, struct sockaddr_in *));
289 void server_send_queue __P((Server *));
290 void server_reset __P((void));
291 int is_server();
292 Server *server_which_server __P((struct sockaddr_in *who));
293 Pending *server_dequeue __P((Server *server));
294 Code_t server_dispatch __P((ZNotice_t *notice, int auth,
295                             struct sockaddr_in *who));
296 Code_t server_adispatch __P((ZNotice_t *notice, int auth,
297                              struct sockaddr_in *who, Server *server));
298
299 /* found in subscr.c */
300 Code_t subscr_foreign_user __P((ZNotice_t *, struct sockaddr_in *, Server *, Realm *));
301 Code_t subscr_cancel __P((struct sockaddr_in *sin, ZNotice_t *notice));
302 Code_t subscr_subscribe __P((Client *who, ZNotice_t *notice, Server *server));
303 Code_t subscr_send_subs __P((Client *client));
304 void subscr_cancel_client __P((Client *client));
305 void subscr_sendlist __P((ZNotice_t *notice, int auth,
306                           struct sockaddr_in *who));
307 void subscr_dump_subs __P((FILE *fp, Destlist *subs));
308 void subscr_reset __P((void));
309 Code_t subscr_def_subs __P((Client *who));
310
311 /* found in uloc.c */
312 void uloc_hflush __P((struct in_addr *addr));
313 void uloc_flush_client __P((struct sockaddr_in *sin));
314 void uloc_dump_locs __P((FILE *fp));
315 Code_t ulogin_dispatch __P((ZNotice_t *notice, int auth,
316                             struct sockaddr_in *who, Server *server));
317 Code_t ulocate_dispatch __P((ZNotice_t *notice, int auth,
318                              struct sockaddr_in *who, Server *server));
319 Code_t uloc_send_locations __P((void));
320
321 /* found in realm.c */
322 int realm_sender_in_realm __P((char *realm, char *sender));
323 int realm_bound_for_realm __P((char *realm, char *recip));
324 Realm *realm_which_realm __P((struct sockaddr_in *who));
325 Realm *realm_get_realm_by_name __P((char *name));
326 Realm *realm_get_realm_by_pid __P((int));
327 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, Realm *, int);
328 char *realm_expand_realm(char *);
329 void realm_init __P((void));
330 Code_t ZCheckRealmAuthentication __P((ZNotice_t *, struct sockaddr_in *,
331                                       char *));
332 Code_t realm_control_dispatch __P((ZNotice_t *, int, struct sockaddr_in *,
333                                    Server *, Realm *));
334 void realm_shutdown __P((void));
335 void realm_deathgram __P((Server *));
336
337 /* found in version.c */
338 char *get_version __P((void));
339
340 /* global identifiers */
341
342 /* found in main.c */
343 int packets_waiting __P((void));
344 extern struct sockaddr_in srv_addr;     /* server socket address */
345 extern unsigned short hm_port;          /* host manager receiver port */
346 extern unsigned short hm_srv_port;      /* host manager server sending port */
347 extern int srv_socket;                  /* dgram sockets for clients
348                                            and other servers */
349 extern int bdump_socket;                /* brain dump socket
350                                            (closed most of the time) */
351
352 extern fd_set interesting;              /* the file descrips we are listening
353                                          to right now */
354 extern int nfds;                        /* number to look at in select() */
355 extern int zdebug;
356 extern char myname[];                   /* domain name of this host */
357 extern char list_file[];
358 #ifdef HAVE_KRB4
359 extern char srvtab_file[];
360 extern char my_realm[];
361 #endif
362 extern char acl_dir[];
363 extern char subs_file[];
364 extern const char version[];
365 extern u_long npackets;                 /* num of packets processed */
366 extern time_t uptime;                   /* time we started */
367 extern struct in_addr my_addr;
368 extern struct timeval t_local;          /* current time */
369
370 /* found in bdump.c */
371 extern int bdumping;                    /* are we processing a bdump packet? */
372 extern int bdump_concurrent;            /* set while processing a packet
373                                          * concurrently during a braindump. */
374
375 /* found in dispatch.c */
376 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
377 extern int rexmit_times[];
378
379 /* found in server.c */
380 extern Server *otherservers;            /* array of servers */
381 extern int me_server_idx;               /* me (in the array of servers) */
382 extern int nservers;                    /* number of other servers*/
383
384 /* found in subscr.c */
385 extern String *empty;
386 extern String *wildcard_instance;
387
388 extern Realm *otherrealms;
389 extern int nrealms;
390
391 extern struct in_addr my_addr;  /* my inet address */
392
393 #define class_is_control(classname) (classname == class_control)
394 #define class_is_admin(classname) (classname == class_admin)
395 #define class_is_hm(classname) (classname == class_hm)
396 #define class_is_ulogin(classname) (classname == class_ulogin)
397 #define class_is_ulocate(classname) (classname == class_ulocate)
398
399 #define ADMIN_HELLO     "HELLO"         /* Opcode: hello, are you there */
400 #define ADMIN_IMHERE    "IHEARDYOU"     /* Opcode: yes, I am here */
401 #define ADMIN_SHUTDOWN  "GOODBYE"       /* Opcode: I am shutting down */
402 #define ADMIN_BDUMP     "DUMP_AVAIL"    /* Opcode: I will give you a dump */
403 #define ADMIN_DONE      "DUMP_DONE"     /* Opcode: brain dump for this server
404                                            is complete */
405 #define ADMIN_NEWCLT    "NEXT_CLIENT"   /* Opcode: this is a new client */
406 #define ADMIN_KILL_CLT  "KILL_CLIENT"   /* Opcode: client is dead, remove */
407 #define ADMIN_STATUS    "STATUS"        /* Opcode: please send status */
408
409 #define ADMIN_NEWREALM  "NEXT_REALM"    /* Opcode: this is a new realm */
410 #define REALM_REQ_LOCATE "REQ_LOCATE"   /* Opcode: request a location */
411 #define REALM_ANS_LOCATE "ANS_LOCATE"   /* Opcode: answer to location */
412 #define REALM_BOOT      "SENDSUBS"      /* Opcode: first server in realm */
413
414 /* me_server_idx is the index into otherservers of this server descriptor. */
415 /* the 'limbo' server is always the first server */
416
417 #define me_server       (&otherservers[me_server_idx])
418 #define limbo_server_idx()      (0)
419 #define limbo_server    (&otherservers[limbo_server_idx()])
420
421 #define msgs_queued()   (ZQLength() || otherservers[me_server_idx].queue)
422
423 #define ack(a,b)        clt_ack(a,b,SENT)
424 #define nack(a,b)       clt_ack(a,b,NOT_SENT)
425
426 #define min(a,b)        ((a) < (b) ? (a) : (b))
427 #define max(a,b)        ((a) > (b) ? (a) : (b))
428
429 #define START_CRITICAL_CODE
430 #define END_CRITICAL_CODE
431
432 /* the instance that matches all instances */
433 #define WILDCARD_INSTANCE       "*"
434
435 /* debugging macros */
436 #ifdef DEBUG
437 #define zdbug(s1)       if (zdebug) syslog s1;
438 #else /* !DEBUG */
439 #define zdbug(s1)
440 #endif /* DEBUG */
441
442 #endif /* !__ZSERVER_H__ */