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