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