]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/server/zserver.h
61b1c2d4fb8cc8b8d23fa04415986b7d39228990
[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(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(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(ZNotice_t *notice, int auth, struct sockaddr_in *who,
223                     Server *server);
224 void bdump_send(void);
225 void bdump_offer(struct sockaddr_in *who);
226 Code_t bdump_send_list_tcp(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(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(Destination *d1, Destination *d2);
236 Code_t triplet_register(Client *client, Destination *dest, ZRealm *realm);
237 Code_t triplet_deregister(Client *client, Destination *dest,
238                                ZRealm *realm);
239 Code_t class_restrict(char *class, Acl *acl);
240 Code_t class_setup_restricted(char *class, Acl *acl);
241 Client **triplet_lookup(Destination *dest);
242 Acl *class_get_acl(String *class);
243 int dest_eq(Destination *d1, Destination *d2);
244 int order_dest_strings(Destination *d1, Destination *d2);
245 void triplet_dump_subs(FILE *fp);
246
247 /* found in client.c */
248 Code_t client_register(ZNotice_t *notice, struct in_addr *host,
249                             Client **client_p, int wantdefaults);
250 void client_deregister(Client *client, int flush);
251 void client_flush_host(struct in_addr *host);
252 void client_dump_clients(FILE *fp);
253 Client *client_find(struct in_addr *host, unsigned int port);
254 Code_t client_send_clients(void);
255
256 /* found in common.c */
257 char *strsave(const char *str);
258 unsigned long hash (const char *);
259 void dump_quote(char *p, FILE *fp);
260
261 /* found in dispatch.c */
262 void handle_packet(void);
263 void clt_ack(ZNotice_t *notice, struct sockaddr_in *who, Sent_type sent);
264 void nack_release(Client *client);
265 void sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who,
266                  int external);
267 void rexmit(void *);
268 void xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth,
269                Client *client);
270 Code_t hostm_dispatch(ZNotice_t *notice, int auth,
271                            struct sockaddr_in *who, Server *server);
272 Code_t control_dispatch(ZNotice_t *notice, int auth,
273                              struct sockaddr_in *who, Server *server);
274 Code_t xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack);
275 void hostm_shutdown(void);
276
277 /* found in kstuff.c */
278 #ifdef HAVE_KRB4
279 int GetKerberosData (int, struct in_addr, AUTH_DAT *, char *, char *);
280 Code_t SendKerberosData (int, KTEXT, char *, char *);
281 void sweep_ticket_hash_table(void *);
282 #endif
283
284 /* found in kopt.c */
285 #ifdef HAVE_KRB4
286 #ifndef NOENCRYPTION
287 Sched *check_key_sched_cache(des_cblock key);
288 void add_to_key_sched_cache(des_cblock key, Sched *sched);
289 /*int krb_set_key(void *key, int cvt);*/
290 /* int krb_rd_req(KTEXT authent, char *service, char *instance,
291                     unsigned KRB_INT32 from_addr, AUTH_DAT *ad, char *fn); */
292 int krb_find_ticket(KTEXT authent, KTEXT ticket);
293 int krb_get_lrealm(char *r, int n);
294 #endif
295 #endif
296
297 /* found in server.c */
298 void server_timo(void *which);
299 void server_dump_servers(FILE *fp);
300 void server_init(void);
301 void server_shutdown(void);
302 void server_forward(ZNotice_t *notice, int auth,
303                          struct sockaddr_in *who);
304 void server_kill_clt(Client *client);
305 void server_pending_free(Pending *pending);
306 void server_self_queue(ZNotice_t *, int, struct sockaddr_in *);
307 void server_send_queue(Server *);
308 void server_reset(void);
309 Server *server_which_server(struct sockaddr_in *who);
310 Pending *server_dequeue(Server *server);
311 Code_t server_dispatch(ZNotice_t *notice, int auth,
312                             struct sockaddr_in *who);
313 Code_t server_adispatch(ZNotice_t *notice, int auth,
314                              struct sockaddr_in *who, Server *server);
315
316 /* found in subscr.c */
317 Code_t subscr_foreign_user(ZNotice_t *, struct sockaddr_in *, Server *, ZRealm *);
318 Code_t subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice);
319 Code_t subscr_subscribe(Client *who, ZNotice_t *notice, Server *server);
320 Code_t subscr_send_subs(Client *client);
321 void subscr_cancel_client(Client *client);
322 void subscr_sendlist(ZNotice_t *notice, int auth,
323                           struct sockaddr_in *who);
324 void subscr_dump_subs(FILE *fp, Destlist *subs);
325 void subscr_reset(void);
326 Code_t subscr_def_subs(Client *who);
327
328 /* found in uloc.c */
329 void uloc_hflush(struct in_addr *addr);
330 void uloc_flush_client(struct sockaddr_in *sin);
331 void uloc_dump_locs(FILE *fp);
332 Code_t ulogin_dispatch(ZNotice_t *notice, int auth,
333                             struct sockaddr_in *who, Server *server);
334 Code_t ulocate_dispatch(ZNotice_t *notice, int auth,
335                              struct sockaddr_in *who, Server *server);
336 Code_t uloc_send_locations(void);
337
338 /* found in realm.c */
339 int realm_sender_in_realm(char *realm, char *sender);
340 int realm_bound_for_realm(char *realm, char *recip);
341 ZRealm *realm_which_realm(struct sockaddr_in *who);
342 ZRealm *realm_get_realm_by_name(char *name);
343 ZRealm *realm_get_realm_by_pid(int);
344 void realm_handoff(ZNotice_t *, int, struct sockaddr_in *, ZRealm *, int);
345 char *realm_expand_realm(char *);
346 void realm_init(void);
347 Code_t ZCheckZRealmAuthentication(ZNotice_t *, struct sockaddr_in *,
348                                       char *);
349 Code_t realm_control_dispatch(ZNotice_t *, int, struct sockaddr_in *,
350                                    Server *, ZRealm *);
351 void realm_shutdown(void);
352 void realm_deathgram(Server *);
353
354 /* found in version.c */
355 char *get_version(void);
356
357 /* global identifiers */
358
359 /* found in main.c */
360 int packets_waiting(void);
361 extern struct sockaddr_in srv_addr;     /* server socket address */
362 extern unsigned short hm_port;          /* host manager receiver port */
363 extern unsigned short hm_srv_port;      /* host manager server sending port */
364 extern int srv_socket;                  /* dgram sockets for clients
365                                            and other servers */
366 extern int bdump_socket;                /* brain dump socket
367                                            (closed most of the time) */
368
369 extern fd_set interesting;              /* the file descrips we are listening
370                                          to right now */
371 extern int nfds;                        /* number to look at in select() */
372 extern int zdebug;
373 extern char myname[];                   /* domain name of this host */
374 extern char list_file[];
375 #ifdef HAVE_KRB5
376 extern char keytab_file[];
377 extern krb5_ccache Z_krb5_ccache;
378 #endif
379 #ifdef HAVE_KRB4
380 extern char srvtab_file[];
381 extern char my_realm[];
382 #endif
383 extern char acl_dir[];
384 extern char subs_file[];
385 extern const char version[];
386 extern u_long npackets;                 /* num of packets processed */
387 extern time_t uptime;                   /* time we started */
388 extern struct in_addr my_addr;
389 extern struct timeval t_local;          /* current time */
390
391 /* found in bdump.c */
392 extern int bdumping;                    /* are we processing a bdump packet? */
393 extern int bdump_concurrent;            /* set while processing a packet
394                                          * concurrently during a braindump. */
395
396 /* found in dispatch.c */
397 extern Statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
398 extern int rexmit_times[];
399
400 /* found in server.c */
401 extern Server *otherservers;            /* array of servers */
402 extern int me_server_idx;               /* me (in the array of servers) */
403 extern int nservers;                    /* number of other servers*/
404
405 /* found in subscr.c */
406 extern String *empty;
407 extern String *wildcard_instance;
408
409 extern ZRealm *otherrealms;
410 extern int nrealms;
411
412 extern struct in_addr my_addr;  /* my inet address */
413
414 #define class_is_control(classname) (classname == class_control)
415 #define class_is_admin(classname) (classname == class_admin)
416 #define class_is_hm(classname) (classname == class_hm)
417 #define class_is_ulogin(classname) (classname == class_ulogin)
418 #define class_is_ulocate(classname) (classname == class_ulocate)
419
420 #define ADMIN_HELLO     "HELLO"         /* Opcode: hello, are you there */
421 #define ADMIN_IMHERE    "IHEARDYOU"     /* Opcode: yes, I am here */
422 #define ADMIN_SHUTDOWN  "GOODBYE"       /* Opcode: I am shutting down */
423 #define ADMIN_BDUMP     "DUMP_AVAIL"    /* Opcode: I will give you a dump */
424 #define ADMIN_DONE      "DUMP_DONE"     /* Opcode: brain dump for this server
425                                            is complete */
426 #define ADMIN_NEWCLT    "NEXT_CLIENT"   /* Opcode: this is a new client */
427 #define ADMIN_KILL_CLT  "KILL_CLIENT"   /* Opcode: client is dead, remove */
428 #define ADMIN_STATUS    "STATUS"        /* Opcode: please send status */
429
430 #define ADMIN_NEWREALM  "NEXT_REALM"    /* Opcode: this is a new realm */
431 #define REALM_REQ_LOCATE "REQ_LOCATE"   /* Opcode: request a location */
432 #define REALM_ANS_LOCATE "ANS_LOCATE"   /* Opcode: answer to location */
433 #define REALM_BOOT      "SENDSUBS"      /* Opcode: first server in realm */
434
435 /* me_server_idx is the index into otherservers of this server descriptor. */
436 /* the 'limbo' server is always the first server */
437
438 #define me_server       (&otherservers[me_server_idx])
439 #define limbo_server_idx()      (0)
440 #define limbo_server    (&otherservers[limbo_server_idx()])
441
442 #define msgs_queued()   (ZQLength() || otherservers[me_server_idx].queue)
443
444 #define ack(a,b)        clt_ack(a,b,SENT)
445 #define nack(a,b)       clt_ack(a,b,NOT_SENT)
446
447 #define min(a,b)        ((a) < (b) ? (a) : (b))
448 #define max(a,b)        ((a) > (b) ? (a) : (b))
449
450 #define START_CRITICAL_CODE
451 #define END_CRITICAL_CODE
452
453 /* the instance that matches all instances */
454 #define WILDCARD_INSTANCE       "*"
455
456 /* debugging macros */
457 #ifdef DEBUG
458 #define zdbug(s1)       if (zdebug) syslog s1;
459 #else /* !DEBUG */
460 #define zdbug(s1)
461 #endif /* DEBUG */
462
463 #endif /* !__ZSERVER_H__ */