]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - server/zserver.h
Merge in changes from sourceforge1 to sourceforge2
[1ts-debian.git] / 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$
9  *      $Author$
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 typedef struct _galaxy_info {
94     Z_GalaxyConfig galaxy_config;
95 } galaxy_info;
96
97 enum _Realm_state {
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 */
102 };
103
104 struct _Realm {
105     char name[REALM_SZ];
106     int count;
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 */
111     Client *client;                     
112     int child_pid;
113     int have_tkt;
114     Realm_state state;
115 };
116
117 struct _Realmname {
118     char name[REALM_SZ];
119     char **servers;
120     int nused;
121     int nservers;
122 };
123
124 struct _Client {
125     struct sockaddr_in  addr;           /* ipaddr/port of client */
126     Destlist            *subs   ;       /* subscriptions */
127 #ifdef HAVE_KRB4
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 */
133     Realm               *realm;
134     struct _Client      *next, **prev_p;
135 };
136
137 struct _Triplet {
138     Destination         dest;
139     Acl                 *acl;
140     Client              **clients;
141     int                 clients_size;
142     struct _Triplet     *next, **prev_p;
143 };
144
145 enum _Server_state {
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 */
150 };
151
152 struct _Unacked {
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 */
163         struct {
164             int rlm_idx;                /* index of realm */
165             int rlm_srv_idx;            /* index of server in realm */
166         } rlm;
167     } dest;
168     struct _Unacked *next, **prev_p;
169 };
170
171 struct _Pending {
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;
177 };
178
179 struct _Server {
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 */
190 };
191
192 enum _Sent_type {
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 */
197 };
198
199 /* statistics gathering */
200 struct _Statistic {
201     int                 val;
202     char                *str;
203 };
204
205 /* Function declarations */
206         
207 /* found in bdump.c */
208 void bdump_get __P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
209                     Server *server));
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,
215                                 int num));
216 int get_tgt __P((void));
217
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,
224                                Realm *realm));
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));
232
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));
241
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));
246
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,
255                Client *client));
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));
262
263 /* found in kstuff.c */
264 #ifdef HAVE_KRB4
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 *));
268 #endif
269
270 #if 0
271 /* found in kopt.c */
272 #ifdef HAVE_KRB4
273 #ifndef NOENCRYPTION
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));
277 #if 0
278 int krb_rd_req __P((KTEXT authent, char *service, char *instance,
279                     unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn));
280 #endif
281 int krb_find_ticket __P((KTEXT authent, KTEXT ticket));
282 int krb_get_lrealm __P((char *r, int n));
283 #endif
284 #endif
285 #endif
286
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));
299 int is_server();
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));
306
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));
318
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));
328
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 *,
339                                       char *));
340 Code_t realm_control_dispatch __P((ZNotice_t *, int, struct sockaddr_in *,
341                                    Server *, Realm *));
342 void realm_shutdown __P((void));
343 void realm_deathgram __P((Server *));
344
345 /* found in version.c */
346 char *get_version __P((void));
347
348 /* global identifiers */
349
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
356                                            and other servers */
357 extern int bdump_socket;                /* brain dump socket
358                                            (closed most of the time) */
359
360 extern fd_set interesting;              /* the file descrips we are listening
361                                          to right now */
362 extern int nfds;                        /* number to look at in select() */
363 extern int zdebug;
364 extern galaxy_info *galaxy_list;        /* list of all galaxies' servers */
365 extern int ngalaxies;
366 extern char myname[];                   /* domain name of this host */
367 #ifdef HAVE_KRB4
368 extern char srvtab_file[];
369 extern char my_krealm[];
370 #endif
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 */
378
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. */
383
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[];
387
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*/
393
394 /* found in subscr.c */
395 extern String *empty;
396 extern String *wildcard_instance;
397
398 extern Realm *otherrealms;
399 extern int nrealms;
400
401 extern struct in_addr my_addr;  /* my inet address */
402
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)
408
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
414                                            is complete */
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 */
418
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 */
423
424 /* me_server_idx is the index into otherservers of this server descriptor. */
425 /* the 'limbo' server is always the first server */
426
427 #define me_server       (&otherservers[me_server_idx])
428 #define limbo_server_idx()      (0)
429 #define limbo_server    (&otherservers[limbo_server_idx()])
430
431 #define msgs_queued()   (ZQLength() || otherservers[me_server_idx].queue)
432
433 #define ack(a,b)        clt_ack(a,b,SENT)
434 #define nack(a,b)       clt_ack(a,b,NOT_SENT)
435
436 #define min(a,b)        ((a) < (b) ? (a) : (b))
437 #define max(a,b)        ((a) > (b) ? (a) : (b))
438
439 #define START_CRITICAL_CODE
440 #define END_CRITICAL_CODE
441
442 /* the instance that matches all instances */
443 #define WILDCARD_INSTANCE       "*"
444
445 /* debugging macros */
446 #ifdef DEBUG
447 #define zdbug(s1)       if (zdebug) syslog s1;
448 #else /* !DEBUG */
449 #define zdbug(s1)
450 #endif /* DEBUG */
451
452 #endif /* !__ZSERVER_H__ */