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