summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorGravatar Kenneth G Raeburn <raeburn@mit.edu>1990-11-13 12:02:59 +0000
committerGravatar Kenneth G Raeburn <raeburn@mit.edu>1990-11-13 12:02:59 +0000
commita36a075433165839ec7a02379ad83c03e08498a5 (patch)
treef6ad43e0f7a6e60f5e65d3e632b49edabf9a9a7a /server
parentdb89d0d2485f01c3d411c87952f2cd09e372f844 (diff)
C++ conversion and lots of modifications from summer & fall work
Diffstat (limited to 'server')
-rw-r--r--server/access.c158
-rw-r--r--server/bdump.c245
-rw-r--r--server/class.c307
-rw-r--r--server/client.c65
-rw-r--r--server/common.c57
-rw-r--r--server/dispatch.c250
-rw-r--r--server/hostm.c149
-rw-r--r--server/kstuff.c259
-rw-r--r--server/main.c223
-rw-r--r--server/server.c378
-rw-r--r--server/subscr.c487
-rw-r--r--server/timer.c56
-rw-r--r--server/timer.h15
-rw-r--r--server/uloc.c224
-rw-r--r--server/version.c25
-rw-r--r--server/zserver.h446
16 files changed, 2052 insertions, 1292 deletions
diff --git a/server/access.c b/server/access.c
index c877162..dc1afd8 100644
--- a/server/access.c
+++ b/server/access.c
@@ -13,20 +13,16 @@
#include <zephyr/mit-copyright.h>
-#ifndef lint
-#ifndef SABER
-static char rcsid_access_c[] = "$Header$";
-#endif SABER
-#endif lint
+#if !defined (lint) && !defined (SABER)
+static const char rcsid_access_c[] =
+ "$Header$";
+#endif
/*
*
* External routines:
*
- * int access_check(notice, acl, accesstype)
- * ZNotice_t *notice;
- * ZAcl_t *acl;
- * ZAccess_t accesstype;
+ * ZAcl_t::ok (ZString sender, ZAccess_t accesstype)
*
* void access_init();
*
@@ -40,60 +36,127 @@ static char rcsid_access_c[] = "$Header$";
* routines and the support needed by the Zephyr server.
*/
-#include "zserver.h" /* includes <sys/file.h>,
- <strings.h> */
#include <sys/param.h>
+#include "zserver.h"
+
+/*
+ * Our private types for the acl_types field in the ZAcl_t structure.
+ * -TYT 8/14/90
+ */
+#define ACL_XMT 1
+#define ACL_SUB 2
+#define ACL_IWS 4
+#define ACL_IUI 8
+
/*
* check access. return 1 if ok, 0 if not ok.
*/
int
-access_check(notice, acl, accesstype)
-ZNotice_t *notice;
-ZAcl_t *acl;
-ZAccess_t accesstype;
+ZAcl_t::ok (ZString sender, ZAccess_t accesstype)
{
char buf[MAXPATHLEN]; /* holds the real acl name */
char *prefix;
+ int flag;
switch (accesstype) {
case TRANSMIT:
prefix = "xmt";
+ flag = ACL_XMT;
break;
case SUBSCRIBE:
prefix = "sub";
+ flag = ACL_SUB;
break;
case INSTWILD:
prefix = "iws";
+ flag = ACL_IWS;
break;
case INSTUID:
prefix = "iui";
+ flag = ACL_IUI;
break;
default:
syslog(LOG_ERR, "unknown access type %d", (int) accesstype);
return(0);
}
+ if (!acl_types & flag) /* no acl ==> no restriction
+ ==> thumbs up */
+ return (1);
(void) sprintf(buf, "%s%s-%s.acl",
ZEPHYR_ACL_DIR,
prefix,
- acl->acl_filename);
- if (access(buf, F_OK)) /* no acl ==> no restriction
- ==> thumbs up */
- return(1);
- return(acl_check(buf, notice->z_sender));
+ acl_filename);
+ /*
+ * If we can't load it (because it probably doesn't exist),
+ * we grant access by default. Dangerous!
+ */
+#if 0
+ zdbug ((LOG_DEBUG, "checking %s for %s", buf, sender.value ()));
+#endif
+ return (acl_load (buf) < 0
+ || acl_check(buf, sender.value ()));
}
-void
-access_init()
+void ZAcl_t::check_acl_type (ZAccess_t accesstype, int typeflag)
+{
+ char buf[MAXPATHLEN]; /* holds the real acl name */
+ char *prefix;
+
+ switch (accesstype) {
+ case TRANSMIT:
+ prefix = "xmt";
+ break;
+ case SUBSCRIBE:
+ prefix = "sub";
+ break;
+ case INSTWILD:
+ prefix = "iws";
+ break;
+ case INSTUID:
+ prefix = "iui";
+ break;
+ default:
+ syslog(LOG_ERR, "unknown access type %d", (int) accesstype);
+ return;
+ }
+ (void) sprintf(buf, "%s%s-%s.acl",
+ ZEPHYR_ACL_DIR,
+ prefix,
+ acl_filename);
+ if (!access(buf, F_OK))
+ acl_types |= typeflag;
+}
+
+void ZAcl_t::check () {
+ acl_types = 0;
+ check_acl_type (TRANSMIT, ACL_XMT);
+ check_acl_type (SUBSCRIBE, ACL_SUB);
+ check_acl_type (INSTWILD, ACL_IWS);
+ check_acl_type (INSTUID, ACL_IUI);
+}
+
+/*
+ * Re-init code written by TYT, 8/14/90.
+ *
+ * General plan of action; we reread the registry list, and add any
+ * new restricted classes. If any restricted classes disappear (this
+ * should be rarely) the ZAcl_t structure is not deallocated; rather,
+ * the acl_types field will be left at zero, since there will be no
+ * acl files for the (non-)restricted class.
+ */
+
+static void
+access_setup (int first)
{
char buf[MAXPATHLEN];
- char class[512]; /* assume class names <= 511 bytes */
+ char class_name[512]; /* assume class names <= 511 bytes */
FILE *registry;
ZAcl_t *acl;
register int len;
register char *colon_idx;
- Code_t retval;
+ Code_t retval = 0;
(void) sprintf(buf, "%s%s", ZEPHYR_ACL_DIR, ZEPHYR_CLASS_REGISTRY);
@@ -101,25 +164,38 @@ access_init()
syslog(LOG_ERR, "no registry available, all classes are free");
return;
}
- while (fgets(class, 512, registry) != NULL) {
- if (colon_idx = index(class, ':'))
- *colon_idx = '\0';
- else if (len = strlen(class))
- class[len - 1] = '\0';
- acl = (ZAcl_t *) xmalloc(sizeof(ZAcl_t));
+ while (fgets(class_name, 512, registry) != NULL) {
+ if (colon_idx = index(class_name, ':'))
+ *colon_idx = '\0';
+ else if (len = strlen(class_name))
+ class_name[len - 1] = '\0';
+ acl = 0;
+ if (!first)
+ acl = class_get_acl (ZString (class_name, 1));
if (!acl) {
+ acl = new ZAcl_t (class_name);
+ if (!acl) {
syslog(LOG_ERR, "no mem acl alloc");
abort();
+ }
+ if (!first) {
+ /* Try to restrict already existing class */
+ retval = class_restrict (class_name, acl);
+ if (retval == ZSRV_NOCLASS)
+ retval = class_setup_restricted (class_name, acl);
+ }
+ else
+ retval = class_setup_restricted (class_name, acl);
}
- acl->acl_filename = strsave(class);
- retval = class_setup_restricted(class, acl);
if (retval) {
syslog(LOG_ERR, "can't restrict %s: %s",
- class, error_message(retval));
+ class_name, error_message(retval));
continue;
- } else if (zdebug)
- syslog(LOG_DEBUG, "restricted %s",
- class, acl->acl_filename);
+ }
+#if 1
+ else if (zdebug)
+ syslog(LOG_DEBUG, "restricted %s", class_name);
+#endif
}
(void) fclose(registry);
@@ -127,8 +203,14 @@ access_init()
}
void
-access_reinit()
+access_init (void)
{
- /* re-initialize the restricted classes */
+ access_setup (1);
}
+void
+access_reinit (void)
+{
+ acl_cache_reset ();
+ access_setup (0);
+}
diff --git a/server/bdump.c b/server/bdump.c
index 65b9d24..4f12bd4 100644
--- a/server/bdump.c
+++ b/server/bdump.c
@@ -15,7 +15,7 @@
#ifndef lint
#ifndef SABER
-static char rcsid_bdump_c[] = "$Header$";
+static const char rcsid_bdump_c[] = "$Header$";
#endif /* SABER */
#endif /* lint */
@@ -24,6 +24,14 @@ static char rcsid_bdump_c[] = "$Header$";
#include <signal.h>
#include <sys/param.h> /* for BSD */
+/* inconsistent header files... */
+#ifdef SignalIgnore
+#undef SIG_IGN
+#define SIG_IGN SignalIgnore
+#undef SIG_DFL
+#define SIG_DFL SignalDefault
+#endif
+
/*
* External functions are:
*
@@ -47,19 +55,33 @@ static char rcsid_bdump_c[] = "$Header$";
* int num;
*/
-static void close_bdump(), cleanup();
-static Code_t bdump_send_loop(), bdump_ask_for(), bdump_recv_loop();
-static Code_t get_packet(), extract_sin(), send_done(), send_list();
-static Code_t send_host_register(), sbd_loop(), gbd_loop(), send_normal_tcp();
-static int net_read(), net_write();
+static void close_bdump(void* arg),
+ cleanup(ZServerDesc_t *server, int omask);
+static Code_t bdump_send_loop(register ZServerDesc_t *server, char *vers),
+ bdump_ask_for(char *inst),
+ bdump_recv_loop(ZServerDesc_t *server);
+static Code_t get_packet(caddr_t packet, int len, int *retlen);
+static Code_t extract_sin(ZNotice_t *notice, struct sockaddr_in *target);
+static Code_t send_done(void);
+static Code_t send_list(ZNotice_Kind_t kind, u_short port, char *zclass,
+ char *inst, char *opcode, char *sender, char *recip,
+ char **lyst, int num);
+static Code_t send_host_register(ZHostList_t *host);
+static Code_t sbd_loop(struct sockaddr_in *from);
+static Code_t gbd_loop(ZServerDesc_t *server);
+static Code_t send_normal_tcp(ZNotice_Kind_t kind, u_short port, char *zclass,
+ char *inst, char *opcode, char *sender,
+ char *recip, char *message, int len);
+static int net_read(int fd, register char *buf, register int len);
+static int net_write(int fd, register char *buf, int len);
#ifdef KERBEROS
-static int get_tgt();
+static int get_tgt(void);
#endif /* KERBEROS */
static timer bdump_timer;
#ifdef KERBEROS
static long ticket_time = 0L;
-static char my_realm[REALM_SZ] = "\0";
+static char my_realm[REALM_SZ] = "";
#endif /* KERBEROS */
static int bdump_inited = 0;
static int live_socket = -1;
@@ -75,15 +97,16 @@ int bdumping = 0;
*/
void
-bdump_offer(who)
-struct sockaddr_in *who;
+bdump_offer(struct sockaddr_in *who)
{
Code_t retval;
char buf[512], *addr, *lyst[2];
#ifndef KERBEROS
int bdump_port = IPPORT_RESERVED - 1;
#endif /* !KERBEROS */
+#if 0
zdbug((LOG_DEBUG, "bd_offer"));
+#endif
#ifdef KERBEROS
/*
* when using Kerberos server-server authentication, we can
@@ -156,8 +179,10 @@ struct sockaddr_in *who;
(void) send_list(ACKED, sock_sin.sin_port, ZEPHYR_ADMIN_CLASS, "1",
ADMIN_BDUMP, myname, "", lyst, 2);
+#if 0
zdbug((LOG_DEBUG,"bd_offer: %s/%d\n",inet_ntoa(bdump_sin.sin_addr),
ntohs(bdump_sin.sin_port)));
+#endif
return;
}
@@ -166,7 +191,7 @@ struct sockaddr_in *who;
*/
void
-bdump_send()
+bdump_send(void)
{
struct sockaddr_in from;
ZServerDesc_t *server;
@@ -181,7 +206,9 @@ bdump_send()
unsigned short fromport;
#endif /* KERBEROS */
+#if 0
zdbug((LOG_DEBUG, "bdump_send"));
+#endif
/* accept the connection, and send the brain dump */
if ((live_socket = accept(bdump_socket, (struct sockaddr *)&from,
&fromlen)) < 0) {
@@ -208,7 +235,9 @@ bdump_send()
syslog(LOG_ERR,"unknown server?");
server = limbo_server;
}
+#if 0
zdbug((LOG_DEBUG, "sbd connected"));
+#endif
bdumping = 1;
server->zs_dumping = 1;
@@ -270,7 +299,9 @@ bdump_send()
cleanup(server, omask);
return;
} else {
+#if 0
zdbug((LOG_DEBUG, "sbd finished"));
+#endif
if (server != limbo_server) {
/* set this guy to be up,
and schedule a hello */
@@ -280,7 +311,9 @@ bdump_send()
}
}
}
+#if 0
zdbug((LOG_DEBUG,"cleanup sbd"));
+#endif
(void) close(live_socket);
(void) signal(SIGPIPE, SIG_DFL);
bdump_inited = 1;
@@ -297,11 +330,7 @@ bdump_send()
/*ARGSUSED*/
void
-bdump_get(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+bdump_get(ZNotice_t *notice, int auth, sockaddr_in *who, ZServerDesc_t *server)
{
struct sockaddr_in from;
Code_t retval;
@@ -314,8 +343,10 @@ ZServerDesc_t *server;
int reserved_port = IPPORT_RESERVED - 1;
#endif /* KERBEROS */
+#if 1
if (zdebug)
syslog(LOG_DEBUG, "bdump avail %s",inet_ntoa(who->sin_addr));
+#endif
/* version number 1 is the same as no version number */
if (strcmp(notice->z_class_inst, "1")
@@ -376,7 +407,9 @@ ZServerDesc_t *server;
if (setsockopt(live_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
sizeof (on)) < 0)
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
+#if 1
zdbug((LOG_DEBUG, "gbd connected"));
+#endif
/* Now begin the brain dump. */
@@ -393,7 +426,9 @@ ZServerDesc_t *server;
cleanup(server, omask);
return;
}
+#if 1
zdbug((LOG_DEBUG,"skd ok"));
+#endif
/* get his authenticator */
if ((retval = GetKerberosData(live_socket, from.sin_addr, &kdata, "zephyr",
@@ -417,14 +452,18 @@ ZServerDesc_t *server;
cleanup(server, omask);
return;
} else {
+#if 1
zdbug((LOG_DEBUG,"gbdl ok"));
+#endif
if ((retval = sbd_loop(&from)) != ZERR_NONE) {
syslog(LOG_WARNING, "sbd_loop failed: %s",
error_message(retval));
cleanup(server, omask);
return;
} else {
+#if 1
zdbug((LOG_DEBUG, "gbd finished"));
+#endif
/* set this guy to be up,
and schedule a hello */
server->zs_state = SERV_UP;
@@ -433,7 +472,9 @@ ZServerDesc_t *server;
}
}
+#if 1
zdbug((LOG_DEBUG,"cleanup gbd"));
+#endif
(void) close(live_socket);
(void) signal(SIGPIPE, SIG_DFL);
bdump_inited = 1;
@@ -453,26 +494,21 @@ ZServerDesc_t *server;
*/
Code_t
-bdump_send_list_tcp(kind, port, class, inst, opcode, sender, recip, lyst, num)
-ZNotice_Kind_t kind;
-u_short port;
-char *class, *inst, *opcode, *sender, *recip;
-char *lyst[];
-int num;
+bdump_send_list_tcp(ZNotice_Kind_t kind, u_short port, char *class_name,
+ char *inst, char *opcode, char *sender, char *recip,
+ const char **lyst, int num)
{
ZNotice_t notice;
- register ZNotice_t *pnotice; /* speed hack */
+ register ZNotice_t *const pnotice = &notice; /* speed hack */
char *pack;
int packlen, count;
Code_t retval;
u_short length;
-
- pnotice = &notice;
-
+
pnotice->z_kind = kind;
pnotice->z_port = port;
- pnotice->z_class = class;
+ pnotice->z_class = class_name;
pnotice->z_class_inst = inst;
pnotice->z_opcode = opcode;
pnotice->z_sender = sender;
@@ -480,7 +516,7 @@ int num;
pnotice->z_default_format = "";
pnotice->z_num_other_fields = 0;
- if ((retval = ZFormatNoticeList(pnotice, lyst, num, &pack, &packlen, ZNOAUTH)) != ZERR_NONE)
+ if ((retval = ZFormatNoticeList(pnotice, (char **) lyst, num, &pack, &packlen, ZNOAUTH)) != ZERR_NONE)
return(retval);
length = htons((u_short) packlen);
@@ -509,11 +545,11 @@ int num;
}
static void
-cleanup(server, omask)
-ZServerDesc_t *server;
-int omask;
+cleanup(ZServerDesc_t *server, int omask)
{
+#if 0
zdbug((LOG_DEBUG, "cleanup"));
+#endif
if (server != limbo_server) {
server->zs_state = SERV_DEAD;
timer_reset(server->zs_timer);
@@ -535,14 +571,13 @@ int omask;
#ifdef KERBEROS
#define TKTLIFETIME 96
static long
-tkt_lifetime(val)
-int val;
+tkt_lifetime(int val)
{
return((long) val * 5L * 60L);
}
static int
-get_tgt()
+get_tgt(void)
{
int retval;
if (!*my_realm)
@@ -561,9 +596,11 @@ get_tgt()
static char buf[INST_SZ] = "zephyr";
/* +15 for leeway */
+#if 1
zdbug((LOG_DEBUG,"get new tickets: %d %d %d",
ticket_time, NOW,
NOW - tkt_lifetime(TKTLIFETIME) + 15L));
+#endif
(void) dest_tkt();
retval = krb_get_svc_in_tkt ("zephyr", buf/*XXX*/, my_realm,
@@ -582,8 +619,7 @@ get_tgt()
#endif /* KERBEROS */
static Code_t
-sbd_loop(from)
-struct sockaddr_in *from;
+sbd_loop(struct sockaddr_in *from)
{
ZNotice_t bd_notice;
ZPacket_t pack;
@@ -591,6 +627,7 @@ struct sockaddr_in *from;
int packlen = sizeof(pack);
Code_t retval;
struct sockaddr_in bogus_from;
+ char buf[30];
char *zeph_version = NULL;
bogus_from = *from;
@@ -608,13 +645,25 @@ struct sockaddr_in *from;
error_message(retval));
return(retval);
}
- if (!zeph_version)
- zeph_version = strsave(bd_notice.z_version);
+ if (!zeph_version) {
+ int len = strlen (bd_notice.z_version) + 1;
+
+ /* combine these, and cfront complains... */
+ if (len < 30)
+ zeph_version = buf;
+ else {
+ void *v = LOCAL_ALLOC (len);
+ zeph_version = (char *) v;
+ }
+
+ strcpy (zeph_version, bd_notice.z_version);
+ }
#ifdef DEBUG
if (zdebug) {
char buf[4096];
- (void) sprintf(buf, "bdump:%s '%s' '%s' '%s' '%s' '%s'",
+ (void) sprintf(buf,
+ "bdump:%s '%s' '%s' '%s' '%s' '%s'",
pktypes[(int) bd_notice.z_kind],
bd_notice.z_class,
bd_notice.z_class_inst,
@@ -626,7 +675,9 @@ struct sockaddr_in *from;
#endif /* DEBUG */
if (!strcmp(bd_notice.z_class_inst, ADMIN_LIMBO)) {
/* he wants limbo */
+#if 1
zdbug((LOG_DEBUG, "limbo req"));
+#endif
if ((retval = bdump_send_loop(limbo_server,
zeph_version))
!= ZERR_NONE)
@@ -634,7 +685,9 @@ struct sockaddr_in *from;
continue;
} else if (!strcmp(bd_notice.z_class_inst, ADMIN_ME)) {
/* he wants his state */
+#if 1
zdbug((LOG_DEBUG, "his state req"));
+#endif
if (server = server_which_server(&bogus_from)) {
if ((retval = bdump_send_loop(server,
zeph_version))
@@ -648,7 +701,9 @@ struct sockaddr_in *from;
continue;
} else if (!strcmp(bd_notice.z_class_inst, ADMIN_YOU)) {
/* he wants my state */
+#if 1
zdbug((LOG_DEBUG, "my state req"));
+#endif
if ((retval = bdump_send_loop(me_server, zeph_version))
!= ZERR_NONE)
return(retval);
@@ -657,18 +712,19 @@ struct sockaddr_in *from;
break;
} else {
/* what does he want? */
+#if 1
zdbug((LOG_DEBUG, "unknown req"));
+#endif
break;
}
}
- if (zeph_version)
- xfree(zeph_version);
+ if (zeph_version && zeph_version != buf)
+ LOCAL_FREE (zeph_version);
return(ZERR_NONE);
}
static Code_t
-gbd_loop(server)
-ZServerDesc_t *server;
+gbd_loop(ZServerDesc_t *server)
{
Code_t retval;
@@ -703,17 +759,20 @@ ZServerDesc_t *server;
/*ARGSUSED*/
static void
-close_bdump(arg)
-caddr_t arg;
+close_bdump(void * arg)
{
if (bdump_socket >= 0) {
FD_CLR(bdump_socket, &interesting);
(void) close(bdump_socket);
nfildes = srv_socket + 1;
bdump_socket = -1;
+#if 0
zdbug((LOG_DEBUG, "bdump not used"));
+#endif
} else {
+#if 0
zdbug((LOG_DEBUG, "bdump not open"));
+#endif
}
return;
}
@@ -724,8 +783,7 @@ caddr_t arg;
*/
static Code_t
-bdump_ask_for(inst)
-char *inst;
+bdump_ask_for(char *inst)
{
Code_t retval;
@@ -741,8 +799,7 @@ char *inst;
*/
static Code_t
-bdump_recv_loop(server)
-ZServerDesc_t *server;
+bdump_recv_loop(ZServerDesc_t *server)
{
ZNotice_t notice;
ZPacket_t packet;
@@ -758,10 +815,12 @@ ZServerDesc_t *server;
#ifdef CONCURRENT
fd_set readable, initial;
int fd_ready;
- struct timeval tv;
+ struct timeval tv;
#endif /* CONCURRENT */
+#if 1
zdbug((LOG_DEBUG, "bdump recv loop"));
+#endif
#ifdef CONCURRENT
FD_ZERO(&initial);
@@ -773,9 +832,11 @@ ZServerDesc_t *server;
#ifdef CONCURRENT
readable = initial;
tv.tv_sec = tv.tv_usec = 0;
-
+
if (msgs_queued()) {
+#if 1
zdbug((LOG_DEBUG, "brl msgqued"));
+#endif
fd_ready = 1;
} else
fd_ready = select(srv_socket + 1, &readable,
@@ -787,7 +848,9 @@ ZServerDesc_t *server;
* know what's coming our way.
*/
if (fd_ready > 0) {
+#if 1
zdbug((LOG_DEBUG, "brl fdready"));
+#endif
handle_packet();
} else if (fd_ready < 0)
syslog(LOG_ERR, "brl select: %m");
@@ -803,11 +866,12 @@ ZServerDesc_t *server;
error_message(retval));
return(retval);
}
-#ifdef DEBUG
+#if defined (DEBUG)
if (zdebug) {
char buf[4096];
-
- (void) sprintf(buf, "bdump:%s '%s' '%s' '%s' '%s' '%s'",
+
+ (void) sprintf(buf,
+ "bdump:%s '%s' '%s' '%s' '%s' '%s'",
pktypes[(int) notice.z_kind],
notice.z_class,
notice.z_class_inst,
@@ -877,7 +941,10 @@ ZServerDesc_t *server;
/* a C_Block is there */
cp = notice.z_message +
strlen(notice.z_message) + 1;
- if ((retval = ZReadAscii(cp,strlen(cp),client->zct_cblock,sizeof(C_Block))) != ZERR_NONE) {
+ retval = ZReadAscii(cp,strlen(cp),
+ client->zct_cblock,
+ sizeof(C_Block));
+ if (retval != ZERR_NONE) {
bzero((caddr_t) client->zct_cblock,
sizeof(C_Block));
syslog(LOG_ERR,"brl bad cblk read: %s (%s)",
@@ -911,9 +978,7 @@ ZServerDesc_t *server;
*/
static Code_t
-bdump_send_loop(server, vers)
-register ZServerDesc_t *server;
-char *vers;
+bdump_send_loop(register ZServerDesc_t *server, char *vers)
{
register ZHostList_t *host;
register ZClientList_t *clist;
@@ -924,7 +989,9 @@ char *vers;
struct timeval tv;
#endif /* CONCURRENT */
+#if 1
zdbug((LOG_DEBUG, "bdump send loop"));
+#endif
#ifdef CONCURRENT
@@ -996,20 +1063,24 @@ char *vers;
*/
static Code_t
-send_host_register(host)
-ZHostList_t *host;
+send_host_register(ZHostList_t *host)
{
char buf[512], *addr, *lyst[2];
Code_t retval;
+#if 0
zdbug((LOG_DEBUG, "bdump_host_register"));
+#endif
addr = inet_ntoa(host->zh_addr.sin_addr);
(void) sprintf(buf, "%d", ntohs(host->zh_addr.sin_port));
lyst[0] = addr;
lyst[1] = buf;
/* myname is the hostname */
- if ((retval = bdump_send_list_tcp(HMCTL, bdump_sin.sin_port, ZEPHYR_CTL_CLASS, ZEPHYR_CTL_HM, HM_BOOT, myname, "", lyst, 2)) != ZERR_NONE)
+ retval = bdump_send_list_tcp (HMCTL, bdump_sin.sin_port,
+ ZEPHYR_CTL_CLASS, ZEPHYR_CTL_HM,
+ HM_BOOT, myname, "", lyst, 2);
+ if (retval != ZERR_NONE)
syslog(LOG_ERR, "shr send: %s",error_message(retval));
return(retval);
}
@@ -1019,11 +1090,13 @@ ZHostList_t *host;
*/
static Code_t
-send_done()
+send_done(void)
{
Code_t retval;
+#if 1
zdbug((LOG_DEBUG, "send_done"));
+#endif
retval = send_normal_tcp(SERVACK, bdump_sin.sin_port,
ZEPHYR_ADMIN_CLASS, "", ADMIN_DONE, myname,
"", (char *) NULL, 0);
@@ -1036,12 +1109,7 @@ send_done()
*/
static Code_t
-send_list(kind, port, class, inst, opcode, sender, recip, lyst, num)
-ZNotice_Kind_t kind;
-u_short port;
-char *class, *inst, *opcode, *sender, *recip;
-char *lyst[];
-int num;
+send_list(ZNotice_Kind_t kind, u_short port, char *class_name, char *inst, char *opcode, char *sender, char *recip, char **lyst, int num)
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
@@ -1054,7 +1122,7 @@ int num;
pnotice->z_kind = kind;
pnotice->z_port = port;
- pnotice->z_class = class;
+ pnotice->z_class = class_name;
pnotice->z_class_inst = inst;
pnotice->z_opcode = opcode;
pnotice->z_sender = sender;
@@ -1081,12 +1149,7 @@ int num;
*/
static Code_t
-send_normal_tcp(kind, port, class, inst, opcode, sender, recip, message, len)
-ZNotice_Kind_t kind;
-u_short port;
-char *class, *inst, *opcode, *sender, *recip;
-char *message;
-int len;
+send_normal_tcp(ZNotice_Kind_t kind, u_short port, char *class_name, char *inst, char *opcode, char *sender, char *recip, char *message, int len)
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
@@ -1100,7 +1163,7 @@ int len;
pnotice->z_kind = kind;
pnotice->z_port = port;
- pnotice->z_class = class;
+ pnotice->z_class = class_name;
pnotice->z_class_inst = inst;
pnotice->z_opcode = opcode;
pnotice->z_sender = sender;
@@ -1148,10 +1211,7 @@ int len;
*/
static Code_t
-get_packet(packet, len, retlen)
-caddr_t packet;
-int len;
-int *retlen; /* RETURN */
+get_packet(caddr_t packet, int len, int *retlen)
{
u_short length;
int result;
@@ -1160,7 +1220,7 @@ int *retlen; /* RETURN */
if (result < 0)
return(errno);
else {
- syslog(LOG_ERR, "get_pkt len: %d vs %d", result, sizeof(short));
+ syslog(LOG_ERR, "get_pkt len: %d vs %d (%m)", result, sizeof(short));
return(ZSRV_LEN);
}
}
@@ -1172,7 +1232,7 @@ int *retlen; /* RETURN */
if (result < 0)
return(errno);
else {
- syslog(LOG_ERR, "get_pkt: %d vs %d",result, length);
+ syslog(LOG_ERR, "get_pkt: %d vs %d (%m)",result, length);
return(ZSRV_LEN);
}
}
@@ -1181,17 +1241,16 @@ int *retlen; /* RETURN */
}
static Code_t
-extract_sin(notice, target)
-ZNotice_t *notice;
-struct sockaddr_in *target;
+extract_sin(ZNotice_t *notice, struct sockaddr_in *target)
{
register char *cp = notice->z_message;
char *buf;
- extern unsigned long inet_addr();
-
+
buf = cp;
if (!notice->z_message_len || *buf == '\0') {
+#if 0
zdbug((LOG_DEBUG,"no addr"));
+#endif
return(ZSRV_PKSHORT);
}
target->sin_addr.s_addr = inet_addr(cp);
@@ -1199,7 +1258,9 @@ struct sockaddr_in *target;
cp += (strlen(cp) + 1); /* past the null */
if ((cp >= notice->z_message + notice->z_message_len)
|| (*cp == '\0')) {
+#if 0
zdbug((LOG_DEBUG, "no port"));
+#endif
return(ZSRV_PKSHORT);
}
target->sin_port = htons((u_short) atoi(cp));
@@ -1208,10 +1269,7 @@ struct sockaddr_in *target;
}
static int
-net_read(fd, buf, len)
-int fd;
-register char *buf;
-register int len;
+net_read(int fd, register char *buf, register int len)
{
int cc, len2 = 0;
@@ -1231,10 +1289,7 @@ register int len;
}
static int
-net_write(fd, buf, len)
-int fd;
-register char *buf;
-int len;
+net_write(int fd, register char *buf, int len)
{
int cc;
register int wrlen = len;
diff --git a/server/class.c b/server/class.c
index 0525631..c5628e9 100644
--- a/server/class.c
+++ b/server/class.c
@@ -13,11 +13,10 @@
#include <zephyr/mit-copyright.h>
-#ifndef lint
-#ifndef SABER
-static char rcsid_class_c[] = "$Id$";
-#endif SABER
-#endif lint
+#if !defined (lint) && !defined (SABER)
+static const char rcsid_class_c[] =
+ "$Id$";
+#endif
#include "zserver.h" /* includes zephyr/zephyr.h */
@@ -40,26 +39,17 @@ static char rcsid_class_c[] = "$Id$";
* void class_free(lyst)
* ZClientList_t *lyst;
*
- * ZAcl_t *class_get_acl(subs)
+ * ZAcl_t *class_get_acl(ZString class_name)
*
- * int class_is_admin(subs)
- *
- * int class_is_hm(subs)
- *
- * int class_is_ulogin(subs)
- *
- * int class_is_ulocate(subs)
- *
- * int class_is_control(subs)
- * ZSubscr_t *subs;
- *
- * Code_t class_restrict(class, acl)
- * char *class;
+ * Code_t class_restrict(class_name, acl)
+ * char *class_name;
* ZAcl_t *acl;
*
- * Code_t class_setup_restricted(class, acl)
- * char *class;
+ * Code_t class_setup_restricted(class_name, acl)
+ * char *class_name;
* ZAcl_t *acl;
+ *
+ * and several ZDestination methods.
*/
/*
@@ -88,35 +78,73 @@ static char rcsid_class_c[] = "$Id$";
#define HASHMUL 243
static ZClass_t *class_bucket[511]; /* the hash table of pointers */
-static char class_buf[512]; /* scratch area for assembling
- class.instance */
+static ZString empty ("");
+
+static Code_t remove_client(ZClass_t *ptr, ZClient_t *client),
+ insert_client(ZClass_t *ptr, ZClient_t *client);
+static ZClientList_t *client_alloc(ZClient_t *client);
+static ZClass_t *class_alloc(const ZDestination&);
-static Code_t remove_client(), insert_client();
-static void free_class();
-static ZClientList_t *client_alloc();
-static ZClass_t *class_alloc();
-static unsigned int hash(), setup_class();
/* public routines */
+void ZDestination::print (char *buf) {
+#define S(z) (z ? z.value () : "<null>")
+ sprintf (buf, "%s/%s/%s", S (classname), S(inst), S(recip));
+#undef S
+}
+
+ZDestination::ZDestination (const ZString& c, const ZString& i, const ZString& r) : classname (c, 1), inst (i, 1), recip (r) {
+ set_hash ();
+}
+
+ZDestination::ZDestination (const char*c, const char*i, const char*r) : classname (c, 1), inst (i, 1), recip (r) {
+ set_hash ();
+}
+
+ZDestination::ZDestination (const ZDestination&d) : classname (d.classname), inst (d.inst), recip (d.recip) {
+ hash_value = d.hash_value;
+}
+
+int ZDestination::compare_strings (const ZDestination& z1, const ZDestination& z2) {
+ return (z1.classname != z2.classname
+ ? z1.classname < z2.classname
+ : (z1.inst != z2.inst
+ ? z1.inst < z2.inst
+ : z1.recip < z2.recip));
+}
+
+int operator== (const ZDestination& d1, const ZDestination& d2) {
+ return (d1.hash_value == d2.hash_value
+ && d1.classname == d2.classname
+ && d1.inst == d2.inst
+ && d1.recip == d2.recip);
+}
+
+#ifndef __GNUG__
+ZDestination::~ZDestination () {
+ /* implicit destruction of ZString objects... */
+}
+#endif
+
/* register the client as interested in class */
Code_t
-class_register(client, subs)
-ZClient_t *client;
-ZSubscr_t *subs;
+class_register(ZClient_t *client, ZSubscr_t *subs)
{
register ZClass_t *ptr, *ptr2;
- int hashval = setup_class(subs);
+ subs->zst_dest.set_hash ();
+ unsigned long hashval = subs->zst_dest.hash () % HASHSIZE;
if (!(ptr = class_bucket[hashval])) {
/* not registered */
- if (!(ptr = class_alloc(class_buf)))
+ if (!(ptr = class_alloc(subs->zst_dest)))
return(ENOMEM);
/* allocate the head of the bucket */
- if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
+ ptr2 = new ZClass_t;
+ if (!ptr2)
return(ENOMEM);
ptr2->q_forw = ptr;
@@ -129,12 +157,12 @@ ZSubscr_t *subs;
} else {
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
- /* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class_buf))
- return(insert_client(ptr2, client));
+ /* walk down the list, looking for a match */
+ if (ptr2->zct_dest == subs->zst_dest)
+ return(insert_client(ptr2, client));
/* fell off the end, no match */
- if (!(ptr2 = class_alloc(class_buf)))
+ if (!(ptr2 = class_alloc(subs->zst_dest)))
return(ENOMEM);
xinsque(ptr2, ptr); /* insert new class into hash bucket */
return(insert_client(ptr2, client));
@@ -144,30 +172,40 @@ ZSubscr_t *subs;
/* dissociate client from the class, garbage collecting if appropriate */
Code_t
-class_deregister(client, subs)
-ZClient_t *client;
-ZSubscr_t *subs;
+class_deregister(ZClient_t *client, ZSubscr_t *subs)
{
register ZClass_t *ptr, *ptr2;
int retval = -1;
- int hashval = setup_class(subs);
-
- zdbug((LOG_DEBUG, "class_dereg"));
+ subs->zst_dest.set_hash ();
+ unsigned long hashval = subs->zst_dest.hash() % HASHSIZE;
+
+#if 1
+ if (zdebug) {
+ char buf[BUFSIZ];
+ subs->zst_dest.print (buf);
+ syslog (LOG_DEBUG, "class_dereg: %s/%s/%d from %s",
+ client->zct_principal.value (),
+ inet_ntoa (client->zct_sin.sin_addr),
+ client->zct_sin.sin_port, buf);
+ }
+#endif
if (!(ptr = class_bucket[hashval]))
/* no such class to deregister */
return(ZSRV_BADASSOC);
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw) {
/* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class_buf)) {
+ if (ptr2->zct_dest == subs->zst_dest) {
if ((retval = remove_client(ptr2, client)) == EMPTY_CLASS) {
+#if 0
zdbug((LOG_DEBUG,"empty class"));
+#endif
/* Don't free up restricted classes. */
if (ptr2->zct_acl)
return(ZERR_NONE);
else {
xremque(ptr2);
- free_class(ptr2);
+ delete ptr2;
return(ZERR_NONE);
}
}
@@ -186,8 +224,7 @@ ZSubscr_t *subs;
/* return a linked list of what clients are interested in this class */
ZClientList_t *
-class_lookup(subs)
-ZSubscr_t *subs;
+class_lookup(ZSubscr_t *subs)
{
register ZClass_t *ptr, *ptr2;
register int count = 0, wc_count = 0, idx = 1;
@@ -195,26 +232,29 @@ ZSubscr_t *subs;
ZClientList_t *list = NULLZCLT;
ZClientList_t *wc_list = NULLZCLT;
ZSubscr_t wc_sub;
- int hashval = setup_class(subs);
+
+ subs->zst_dest.set_hash ();
+ unsigned long hashval = subs->zst_dest.hash() % HASHSIZE;
if (ptr = class_bucket[hashval])
/* go search the list for the class */
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw) {
/* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class_buf)) {
+ if (ptr2->zct_dest == subs->zst_dest) {
list = ptr2->zct_clientlist;
break;
}
}
/* list is the list of direct matches; now check for wildcards */
wc_sub = *subs;
- wc_sub.zst_classinst = WILDCARD_INSTANCE;
- hashval = setup_class(&wc_sub);
+ wc_sub.zst_dest.inst = ZString (WILDCARD_INSTANCE, 1);
+ wc_sub.zst_dest.set_hash ();
+ hashval = wc_sub.zst_dest.hash () % HASHSIZE;
if (ptr = class_bucket[hashval])
/* go search the list for the class */
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw) {
/* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class_buf)) {
+ if (ptr2->zct_dest == wc_sub.zst_dest) {
wc_list = ptr2->zct_clientlist;
break;
}
@@ -233,7 +273,8 @@ ZSubscr_t *subs;
if (!(wc_count + count))
return(NULLZCLT);
- list_return = (ZClientList_t *) xmalloc((count + wc_count + 1) * sizeof(ZClientList_t));
+ list_return = (ZClientList_t *) xmalloc((count + wc_count + 1)
+ * sizeof(ZClientList_t));
if (!list_return) {
syslog(LOG_ERR, "class_lookup no mem");
return(NULLZCLT);
@@ -260,72 +301,31 @@ ZSubscr_t *subs;
/* free up the storage used by a returned list */
void
-class_free(lyst)
-ZClientList_t *lyst;
+class_free(ZClientList_t *lyst)
{
xfree(lyst);
return;
}
/*
- * These routines return 0 or one depending on whether the indicated
- * notice is of the type named by the routine name.
- */
-
-int
-class_is_control(notice)
-ZNotice_t *notice;
-{
- return(!strcasecmp(notice->z_class, ZEPHYR_CTL_CLASS));
-}
-
-int
-class_is_admin(notice)
-ZNotice_t *notice;
-{
- return(!strcasecmp(notice->z_class, ZEPHYR_ADMIN_CLASS));
-}
-
-int
-class_is_hm(notice)
-ZNotice_t *notice;
-{
- return(!strcasecmp(notice->z_class, HM_CTL_CLASS));
-}
-
-int
-class_is_ulogin(notice)
-ZNotice_t *notice;
-{
- return(!strcasecmp(notice->z_class, LOGIN_CLASS));
-}
-
-int
-class_is_ulocate(notice)
-ZNotice_t *notice;
-{
- return(!strcasecmp(notice->z_class, LOCATE_CLASS));
-}
-
-/*
* return the acl structure associated with class, or NULLZACLT if there is
* no such acl struct
*/
ZAcl_t *
-class_get_acl(class)
-char *class;
+class_get_acl(ZString class_name)
{
register ZClass_t *ptr, *ptr2;
- int hashval = hash(class);
+ ZDestination d (class_name);
+ unsigned long hashval = d.hash () % HASHSIZE;
if (!(ptr = class_bucket[hashval]))
return(NULLZACLT);
/* walk down the list, looking for a match */
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
- if (!strcasecmp(ptr2->zct_classname, class))
- return(ptr2->zct_acl);
+ if (ptr2->zct_dest.classname == class_name)
+ return(ptr2->zct_acl);
/* fell off the end, no match ==> not restricted */
return(NULLZACLT);
@@ -338,20 +338,19 @@ char *class;
*/
Code_t
-class_restrict(class, acl)
-char *class;
-ZAcl_t *acl;
+class_restrict(char *class_name, ZAcl_t *acl)
{
register ZClass_t *ptr, *ptr2;
- int hashval = hash(class);
+ ZDestination d (class_name);
+ unsigned long hashval = d.hash() % HASHSIZE;
if (!(ptr = class_bucket[hashval]))
return(ZSRV_NOCLASS);
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
/* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class)) {
+ if (ptr2->zct_dest == d) {
if (ptr2->zct_acl)
- return(ZSRV_CLASSRESTRICTED);
+ return ZSRV_CLASSRESTRICTED;
ptr2->zct_acl = acl;
return(ZERR_NONE);
}
@@ -367,23 +366,24 @@ ZAcl_t *acl;
*/
Code_t
-class_setup_restricted(class, acl)
-char *class;
-ZAcl_t *acl;
+class_setup_restricted(char *class_name, ZAcl_t *acl)
{
register ZClass_t *ptr, *ptr2;
- int hashval = hash(class);
+ ZDestination d (class_name);
+ unsigned long hashval = d.hash () % HASHSIZE;
if (!(ptr = class_bucket[hashval])) {
/* not registered */
-
- if (!(ptr = class_alloc(class)))
+
+ ptr = class_alloc(d);
+ if (!ptr)
return(ENOMEM);
ptr->zct_acl = acl;
/* allocate the head of the bucket */
- if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
+ ptr2 = new ZClass_t;
+ if (!ptr2)
return(ENOMEM);
ptr2->q_forw = ptr;
@@ -396,9 +396,9 @@ ZAcl_t *acl;
} else {
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
/* walk down the list, looking for a match */
- if (!strcasecmp(ptr2->zct_classname, class))
+ if (ptr2->zct_dest == d)
return(ZSRV_CLASSXISTS);
- if (!(ptr2 = class_alloc(class)))
+ if (!(ptr2 = class_alloc (d)))
return(ENOMEM);
ptr2->zct_acl = acl;
xinsque(ptr2, ptr);
@@ -408,80 +408,33 @@ ZAcl_t *acl;
/* private routines */
-/* the hash function */
-
-static unsigned int
-hash(string)
-char *string;
-{
- register int hval = 0;
- register unsigned char *cp = (unsigned char *) string;
-
- while (*cp) {
- hval *= HASHMUL;
- hval += (isascii(*cp) && isupper(*cp)) ? tolower(*cp) : *cp;
- hval %= HASHSIZE;
- cp++;
- }
- return hval;
-}
-
-/* set up the class.instance in the class_buf, and return its hash val */
-
-static unsigned int
-setup_class(subs)
-ZSubscr_t *subs;
-{
- (void) strcpy(class_buf, subs->zst_class);
- (void) strcat(class_buf, ".");
- (void) strcat(class_buf, subs->zst_classinst);
-
- return(hash(class_buf));
-}
-
/* allocate space for a class structure */
static ZClass_t *
-class_alloc(class)
-char *class;
+class_alloc(const ZDestination& dest)
{
register ZClass_t *ptr;
ZClientList_t *clist;
- if (!(ptr = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
- return(NULLZCT);
-
- ptr->q_forw = ptr->q_back = ptr;
+ ptr = new ZClass_t (dest);
+ if (!ptr)
+ return(NULLZCT);
- ptr->zct_classname = strsave(class);
- if (!(clist = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
- xfree(ptr->zct_classname);
- xfree(ptr);
- return(NULLZCT);
+ clist = (ZClientList_t *) xmalloc (sizeof (ZClientList_t));
+ if (!clist) {
+ delete ptr;
+ return NULLZCT;
}
clist->q_forw = clist->q_back = clist;
ptr->zct_clientlist = clist;
- ptr->zct_acl = NULLZACLT;
- return(ptr);
-}
-
-/* free up the space used by this class structure */
-
-static void
-free_class(ptr)
-ZClass_t *ptr;
-{
- xfree(ptr->zct_classname);
- xfree(ptr->zct_clientlist);
- xfree(ptr);
+ return ptr;
}
/* allocate space for a client entry */
static ZClientList_t *
-client_alloc(client)
-ZClient_t *client;
+client_alloc(ZClient_t *client)
{
register ZClientList_t *ptr;
if (!(ptr = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
@@ -494,9 +447,7 @@ ZClient_t *client;
/* insert a client into the list associated with the class *ptr */
static Code_t
-insert_client(ptr, client)
-ZClass_t *ptr;
-ZClient_t *client;
+insert_client(ZClass_t *ptr, ZClient_t *client)
{
register ZClientList_t *listp, *clist;
@@ -519,9 +470,7 @@ ZClient_t *client;
* collecting if appropriate
*/
-static Code_t remove_client(ptr, client)
-ZClass_t *ptr;
-ZClient_t *client;
+static Code_t remove_client(ZClass_t *ptr, ZClient_t *client)
{
register ZClientList_t *listp = ptr->zct_clientlist;
register ZClientList_t *listp2;
diff --git a/server/client.c b/server/client.c
index 185d059..053f97f 100644
--- a/server/client.c
+++ b/server/client.c
@@ -13,11 +13,10 @@
#include <zephyr/mit-copyright.h>
-#ifndef lint
-#ifndef SABER
-static char rcsid_client_c[] = "$Header$";
-#endif SABER
-#endif lint
+#if !defined (lint) && !defined (SABER)
+static const char rcsid_client_c[] =
+ "$Header$";
+#endif
/*
* External functions:
@@ -46,8 +45,6 @@ static char rcsid_client_c[] = "$Header$";
#include "zserver.h"
#include <sys/socket.h>
-static void clt_free();
-
/*
* register a client: allocate space, find or insert the address in the
* server's list of hosts, initialize and insert the client into
@@ -58,12 +55,7 @@ static void clt_free();
*/
Code_t
-client_register(notice, who, client, server, wantdefaults)
-ZNotice_t *notice;
-struct sockaddr_in *who;
-register ZClient_t **client; /* RETURN */
-ZServerDesc_t *server;
-int wantdefaults;
+client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t **client, ZServerDesc_t *server, int wantdefaults)
{
register ZHostList_t *hlp = server->zs_hosts;
register ZHostList_t *hlp2;
@@ -93,11 +85,12 @@ int wantdefaults;
}
/* allocate a client struct */
- if (!(*client = (ZClient_t *) xmalloc(sizeof(ZClient_t))))
+ *client = new ZClient_t;
+ if (!*client)
return(ENOMEM);
if (!(clist = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
- xfree(*client);
+ delete *client;
return(ENOMEM);
}
@@ -105,13 +98,16 @@ int wantdefaults;
clist->zclt_client = *client;
/* initialize the struct */
- bzero((caddr_t) &(*client)->zct_sin, sizeof(struct sockaddr_in));
+ bzero((caddr_t) &(*client)->zct_sin,
+ sizeof(struct sockaddr_in));
+ bzero((caddr_t) &(*client)->zct_cblock,
+ sizeof((*client)->zct_cblock));
(*client)->zct_sin.sin_addr.s_addr = who->sin_addr.s_addr;
(*client)->zct_sin.sin_port = notice->z_port;
(*client)->zct_sin.sin_family = AF_INET;
(*client)->zct_subs = NULLZST;
(*client)->zct_subs = NULLZST;
- (*client)->zct_principal = strsave(notice->z_sender);
+ (*client)->zct_principal = ZString (notice->z_sender);
/* chain him in to the clients list in the host list*/
@@ -135,10 +131,7 @@ int wantdefaults;
*/
void
-client_deregister(client, host, flush)
-ZClient_t *client;
-ZHostList_t *host;
-int flush;
+client_deregister(ZClient_t *client, ZHostList_t *host, int flush)
{
ZClientList_t *clients;
int omask = sigblock(sigmask(SIGFPE)); /* don't let db dumps start */
@@ -161,7 +154,7 @@ int flush;
clients = clients->q_forw)
if (clients->zclt_client == client) {
xremque(clients);
- clt_free(client);
+ delete client;
xfree(clients);
(void) sigsetmask(omask);
return;
@@ -176,20 +169,22 @@ int flush;
*/
ZClient_t *
-client_which_client(who, notice)
-struct sockaddr_in *who;
-ZNotice_t *notice;
+client_which_client(struct sockaddr_in *who, ZNotice_t *notice)
{
register ZHostList_t *hlt;
register ZClientList_t *clients;
if (!(hlt = hostm_find_host(&who->sin_addr))) {
+#if 0
zdbug((LOG_DEBUG,"cl_wh_clt: host not found"));
+#endif
return(NULLZCNT);
}
if (!hlt->zh_clients) {
+#if 0
zdbug((LOG_DEBUG,"cl_wh_clt: no clients"));
+#endif
return(NULLZCNT);
}
@@ -200,39 +195,27 @@ ZNotice_t *notice;
return(clients->zclt_client);
}
+#if 0
zdbug((LOG_DEBUG, "cl_wh_clt: no port"));
+#endif
return(NULLZCNT);
}
/*
- * Free storage in use by client
- */
-
-static void
-clt_free(client)
-ZClient_t *client;
-{
- xfree(client->zct_principal);
- xfree(client);
-}
-
-/*
* dump info about clients in this clist onto the fp.
* assumed to be called with SIGFPE blocked
* (true if called from signal handler)
*/
void
-client_dump_clients(fp, clist)
-FILE *fp;
-ZClientList_t *clist;
+client_dump_clients(FILE *fp, ZClientList_t *clist)
{
register ZClientList_t *ptr;
for (ptr = clist->q_forw; ptr != clist; ptr = ptr->q_forw) {
(void) fprintf(fp, "\t%d (%s):\n",
ntohs(ptr->zclt_client->zct_sin.sin_port),
- ptr->zclt_client->zct_principal);
+ ptr->zclt_client->zct_principal.value ());
subscr_dump_subs(fp, ptr->zclt_client->zct_subs);
}
return;
diff --git a/server/common.c b/server/common.c
index e61f61e..1d1b7c1 100644
--- a/server/common.c
+++ b/server/common.c
@@ -15,30 +15,69 @@
#ifndef lint
#ifndef SABER
-static char rcsid_common_c[] = "$Header$";
+static const char rcsid_common_c[] =
+ "$Header$";
#endif SABER
#endif lint
#include <stdio.h>
-#include <zephyr/zsyslog.h>
-#include <strings.h>
-
-extern char *malloc();
+#include <assert.h>
+#include <ctype.h>
+#include "zserver.h"
/* common routines for the server */
/* copy the string into newly allocated area */
char *
-strsave(sp)
-char *sp;
+strsave (const char *sp)
{
register char *ret;
- if((ret = malloc((unsigned) strlen(sp)+1)) == NULL) {
- syslog(LOG_ERR, "no mem strsave'ing");
+ if((ret = (char *) xmalloc((unsigned) strlen(sp)+1)) == NULL) {
+ syslog(LOG_ERR, "no mem strdup'ing");
abort();
}
(void) strcpy(ret,sp);
return(ret);
}
+
+/* generic string hash function */
+
+unsigned long
+hash (const char *string)
+{
+ register int hval = 0;
+ register char cp;
+
+ while (1) {
+ cp = *string++;
+ if (!cp)
+ break;
+ hval += cp;
+
+ cp = *string++;
+ if (!cp)
+ break;
+ hval += cp * 9;
+
+ cp = *string++;
+ if (!cp)
+ break;
+ hval += cp * 17;
+
+ cp = *string++;
+ if (!cp)
+ break;
+ hval += cp * 65;
+
+ cp = *string++;
+ if (!cp)
+ break;
+ hval += cp * 129;
+
+ hval += (hval & 0x7fffff) * 256;
+ hval &= 0x7fffffff;
+ }
+ return hval;
+}
diff --git a/server/dispatch.c b/server/dispatch.c
index 7de098c..ac45ab7 100644
--- a/server/dispatch.c
+++ b/server/dispatch.c
@@ -15,7 +15,7 @@
#ifndef lint
#ifndef SABER
-static char rcsid_dispatch_c[] = "$Id$";
+static const char rcsid_dispatch_c[] = "$Id$";
#endif SABER
#endif lint
@@ -51,15 +51,17 @@ static char rcsid_dispatch_c[] = "$Id$";
* ZClient_t *client;
*/
-static void rexmit(), nack_cancel();
+static void rexmit(void *nackpacket),
+ nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who);
/* patchable magic numbers controlling the retransmission rate and count */
int num_rexmits = NUM_REXMITS;
long rexmit_secs = REXMIT_SECS;
long abs_timo = REXMIT_SECS*NUM_REXMITS + 10;
+int current_msg;
#ifdef DEBUG
-char *pktypes[] = {
+extern const char *pktypes[] = {
"UNSAFE",
"UNACKED",
"ACKED",
@@ -71,13 +73,19 @@ char *pktypes[] = {
};
#endif DEBUG
+extern const ZString class_control (ZEPHYR_CTL_CLASS, 1);
+extern const ZString class_admin (ZEPHYR_ADMIN_CLASS, 1);
+extern const ZString class_hm (HM_CTL_CLASS, 1);
+extern const ZString class_ulogin (LOGIN_CLASS, 1);
+extern const ZString class_ulocate (LOCATE_CLASS, 1);
+
/*
* Handle an input packet.
* Warning: this function may be called from within a brain dump.
*/
void
-handle_packet()
+handle_packet(void)
{
Code_t status;
ZPacket_t input_packet; /* from the network */
@@ -93,8 +101,10 @@ handle_packet()
if (otherservers[me_server_idx].zs_update_queue) {
/* something here for me; take care of it */
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "internal queue process");
+#endif
pending = otherservers[me_server_idx].zs_update_queue->q_forw;
host = hostm_find_host(&(pending->pend_who.sin_addr));
@@ -103,8 +113,10 @@ handle_packet()
we can't process other packets, esp. since we
may block since we don't really know if there
are things in the real queue. */
+#if 0
zdbug((LOG_DEBUG,"host %s is locked",
inet_ntoa(host->zh_addr.sin_addr)));
+#endif
return;
}
pending = server_dequeue(me_server); /* we can do it, remove */
@@ -171,7 +183,7 @@ handle_packet()
break;
}
if (whoisit.sin_port != hm_port &&
- strcasecmp(new_notice.z_class,ZEPHYR_ADMIN_CLASS) &&
+ strcasecmp (new_notice.z_class,ZEPHYR_ADMIN_CLASS) &&
whoisit.sin_port != sock_sin.sin_port &&
new_notice.z_kind != CLIENTACK) {
syslog(LOG_ERR,
@@ -188,77 +200,87 @@ handle_packet()
*/
void
-dispatch(notice, auth, who)
-register ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-{
+dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who) {
Code_t status;
int dispatched = 0;
+ Notice notice = n;
- /* assumes enums are allocated contiguous, increasing values */
+ current_msg++;
+ if (current_msg >= 9999)
+ current_msg = 0;
- if ((int) notice->z_kind < (int) UNSAFE ||
- (int) notice->z_kind > (int) CLIENTACK) {
+ if ((int) notice.notice->z_kind < (int) UNSAFE ||
+ (int) notice.notice->z_kind > (int) CLIENTACK) {
syslog(LOG_INFO, "bad notice kind 0x%x from %s",
- (int) notice->z_kind,
+ (int) notice.notice->z_kind,
inet_ntoa(who->sin_addr));
return;
}
-#ifdef DEBUG
+#if defined (DEBUG)
if (zdebug) {
- char buf[4096];
-
- (void) sprintf(buf, "disp:%s '%s' '%s' '%s' '%s' '%s' %s/%d/%d",
- pktypes[(int) notice->z_kind],
- notice->z_class,
- notice->z_class_inst,
- notice->z_opcode,
- notice->z_sender,
- notice->z_recipient,
- inet_ntoa(who->sin_addr),
- ntohs(who->sin_port),
- ntohs(notice->z_port));
- syslog(LOG_DEBUG, buf);
+ char buf[BUFSIZ];
+ (void) sprintf (buf,
+ "disp:%s '%s' '%s' '%s' notice to '%s' from '%s' %s/%d/%d",
+ pktypes[(int) notice.notice->z_kind],
+ notice.dest.classname.value (),
+ notice.dest.inst.value (),
+ notice.notice->z_opcode,
+ notice.dest.recip.value (),
+ notice.sender.value (),
+ inet_ntoa(who->sin_addr),
+ ntohs(who->sin_port),
+ ntohs(notice.notice->z_port));
+ syslog (LOG_DEBUG, "%s", buf);
+ }
+#endif
+#if 0
+ if (bdumping) {
+ zdbug ((LOG_DEBUG, "from %s/%d, class %s\n",
+ inet_ntoa (who->sin_addr), who->sin_port,
+ notice.dest.classname.value ()));
+ if (!server_which_server(who) && !class_is_admin (notice)) {
+ syslog (LOG_DEBUG, "brain-dumping, dropping packet");
+ return;
+ }
}
-#endif DEBUG
- if (notice->z_kind == CLIENTACK) {
- nack_cancel(notice, who);
+#endif
+ if (notice.notice->z_kind == CLIENTACK) {
+ nack_cancel(notice.notice, who);
return;
}
if (server_which_server(who)) {
- status = server_dispatch(notice, auth, who);
+ status = server_dispatch(notice.notice, auth, who);
dispatched = 1;
} else if (class_is_hm(notice)) {
- status = hostm_dispatch(notice, auth, who, me_server);
+ status = hostm_dispatch(notice.notice, auth, who, me_server);
dispatched = 1;
} else if (class_is_control(notice)) {
- status = control_dispatch(notice, auth, who, me_server);
+ status = control_dispatch(notice.notice, auth, who, me_server);
dispatched = 1;
} else if (class_is_ulogin(notice)) {
- status = ulogin_dispatch(notice, auth, who, me_server);
+ status = ulogin_dispatch(notice.notice, auth, who, me_server);
dispatched = 1;
} else if (class_is_ulocate(notice)) {
- status = ulocate_dispatch(notice, auth, who, me_server);
+ status = ulocate_dispatch(notice.notice, auth, who, me_server);
dispatched = 1;
} else if (class_is_admin(notice)) {
- status = server_adispatch(notice, auth, who, me_server);
+ status = server_adispatch(notice.notice, auth, who, me_server);
dispatched = 1;
}
if (dispatched) {
if (status == ZSRV_REQUEUE) {
#ifdef CONCURRENT
- server_self_queue(notice, auth, who);
+ server_self_queue(notice.notice, auth, who);
#else
syslog(LOG_ERR, "requeue while not concurr");
abort();
-#endif CONCURRENT
+#endif
}
return;
}
/* oh well, do the dirty work */
- sendit(notice, auth, who);
+ sendit(notice.notice, auth, who);
}
/*
@@ -266,16 +288,13 @@ struct sockaddr_in *who;
*/
void
-sendit(notice, auth, who)
-register ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+sendit(register ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
int acked = 0;
ZAcl_t *acl;
register ZClientList_t *clientlist, *ptr;
- if (acl = class_get_acl(notice->z_class)) {
+ if (acl = class_get_acl(ZString (notice->z_class, 1))) {
/* if controlled and not auth, fail */
if (!auth) {
syslog(LOG_WARNING, "sendit unauthentic %s from %s",
@@ -284,22 +303,28 @@ struct sockaddr_in *who;
return;
}
/* if not auth to transmit, fail */
- if (!access_check(notice, acl, TRANSMIT)) {
+ if (!access_check(notice->z_sender, acl, TRANSMIT)) {
syslog(LOG_WARNING, "sendit unauthorized %s from %s",
notice->z_class, notice->z_sender);
clt_ack(notice, who, AUTH_FAILED);
return;
}
/* sender != inst and not auth to send to others --> fail */
- if (strcmp(notice->z_sender, notice->z_class_inst) &&
- !access_check(notice, acl, INSTUID)) {
- syslog(LOG_WARNING,
- "sendit unauth uid %s %s.%s",
- notice->z_sender,
- notice->z_class,
- notice->z_class_inst);
- clt_ack(notice, who, AUTH_FAILED);
- return;
+ {
+ /* Need to write this funny so that cfront can deal... */
+ int xxx;
+ xxx = strcmp (notice->z_sender, notice->z_class_inst);
+ if (xxx)
+ xxx = !acl->ok (notice->z_sender, INSTUID);
+ if (xxx) {
+ syslog(LOG_WARNING,
+ "sendit unauth uid %s %s.%s",
+ notice->z_sender,
+ notice->z_class,
+ notice->z_class_inst);
+ clt_ack(notice, who, AUTH_FAILED);
+ return;
+ }
}
}
if (bcmp(&notice->z_sender_addr.s_addr, &who->sin_addr.s_addr,
@@ -338,8 +363,7 @@ struct sockaddr_in *who;
*/
void
-nack_release(client)
-ZClient_t *client;
+nack_release(ZClient_t *client)
{
register ZNotAcked_t *nacked, *nack2;
@@ -371,10 +395,7 @@ ZClient_t *client;
/* the arguments must be the same as the arguments to Z_XmitFragment */
/*ARGSUSED*/
Code_t
-xmit_frag(notice, buf, len, waitforack)
-ZNotice_t *notice;
-char *buf;
-int len, waitforack;
+xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack)
{
char *savebuf;
register ZNotAcked_t *nacked;
@@ -425,19 +446,16 @@ int len, waitforack;
*/
void
-xmit(notice, dest, auth, client)
-register ZNotice_t *notice;
-struct sockaddr_in *dest;
-int auth;
-ZClient_t *client;
+xmit(register ZNotice_t *notice, struct sockaddr_in *dest, int auth, ZClient_t *client)
{
caddr_t noticepack;
register ZNotAcked_t *nacked;
int packlen;
Code_t retval;
+#if 0
zdbug((LOG_DEBUG,"xmit"));
-
+#endif
if (!(noticepack = (caddr_t) xmalloc(sizeof(ZPacket_t)))) {
syslog(LOG_ERR, "xmit malloc");
@@ -488,8 +506,10 @@ ZClient_t *client;
return; /* DON'T put on nack list */
}
}
+#if 0
zdbug((LOG_DEBUG," to %s/%d",inet_ntoa(dest->sin_addr),
ntohs(dest->sin_port)));
+#endif
if ((retval = ZSetDestAddr(dest)) != ZERR_NONE) {
syslog(LOG_WARNING, "xmit set addr: %s",
error_message(retval));
@@ -537,14 +557,16 @@ ZClient_t *client;
*/
static void
-rexmit(nackpacket)
-register ZNotAcked_t *nackpacket;
+rexmit(void *arg)
{
+ register ZNotAcked_t *nackpacket = (ZNotAcked_t*) arg;
int retval;
ZNotice_t dummy_notice;
register ZClient_t *client;
+#if 0
zdbug((LOG_DEBUG,"rexmit"));
+#endif
if (++(nackpacket->na_rexmits) > num_rexmits ||
NOW > nackpacket->na_abstimo) {
@@ -568,9 +590,11 @@ register ZNotAcked_t *nackpacket;
/* retransmit the packet */
+#if 0
zdbug((LOG_DEBUG," to %s/%d",
inet_ntoa(nackpacket->na_addr.sin_addr),
ntohs(nackpacket->na_addr.sin_port)));
+#endif
if ((retval = ZSetDestAddr(&nackpacket->na_addr))
!= ZERR_NONE) {
syslog(LOG_WARNING, "rexmit set addr: %s",
@@ -599,49 +623,62 @@ requeue:
*/
void
-clt_ack(notice, who, sent)
-ZNotice_t *notice;
-struct sockaddr_in *who;
-ZSentType sent;
+clt_ack(ZNotice_t *notice, struct sockaddr_in *who, ZSentType sent)
{
ZNotice_t acknotice;
ZPacket_t ackpack;
int packlen;
int notme = 0;
+ char *sent_name;
Code_t retval;
if (bdumping) { /* don't ack while dumping */
+#if 1
zdbug((LOG_DEBUG,"bdumping, no ack"));
+#endif
return;
}
- zdbug((LOG_DEBUG,"clt_ack type %d for %d to %s/%d",
- (int) sent,
- ntohs(notice->z_port),
- inet_ntoa(who->sin_addr),
- ntohs(who->sin_port)));
- if (!server_which_server(who) &&
- (hostm_find_server(&who->sin_addr) != me_server)) {
- zdbug((LOG_DEBUG,"not me"));
- notme = 1;
- }
acknotice = *notice;
acknotice.z_kind = SERVACK;
switch (sent) {
case SENT:
acknotice.z_message = ZSRVACK_SENT;
+ sent_name = "sent";
break;
case NOT_FOUND:
acknotice.z_message = ZSRVACK_FAIL;
acknotice.z_kind = SERVNAK;
+ sent_name = "fail";
break;
case AUTH_FAILED:
acknotice.z_kind = SERVNAK;
- /* fall thru */
+ acknotice.z_message = ZSRVACK_NOTSENT;
+ sent_name = "nak/not_sent";
+ break;
case NOT_SENT:
acknotice.z_message = ZSRVACK_NOTSENT;
+ sent_name = "not_sent";
break;
+ default:
+ abort ();
+ }
+
+#if 1
+ zdbug((LOG_DEBUG,"clt_ack type %s for %d to %s/%d",
+ sent_name,
+ ntohs(notice->z_port),
+ inet_ntoa(who->sin_addr),
+ ntohs(who->sin_port)));
+#endif
+
+ if (!server_which_server(who) &&
+ (hostm_find_server(&who->sin_addr) != me_server)) {
+#if 0
+ zdbug((LOG_DEBUG,"not me"));
+#endif
+ notme = 1;
}
acknotice.z_multinotice = "";
@@ -666,6 +703,8 @@ ZSentType sent;
syslog(LOG_WARNING, "clt_ack xmit: %s", error_message(retval));
return;
}
+ else
+ zdbug ((LOG_DEBUG, "packet sent"));
if (notme)
hostm_deathgram(who, me_server);
return;
@@ -677,14 +716,17 @@ ZSentType sent;
*/
static void
-nack_cancel(notice, who)
-register ZNotice_t *notice;
-struct sockaddr_in *who;
+nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
{
register ZNotAcked_t *nacked;
/* search the not-yet-acked list for this packet, and
flush it. */
+#if 1
+ zdbug((LOG_DEBUG, "nack_cancel: %s:%08X,%08X",
+ inet_ntoa (notice->z_uid.zuid_addr),
+ notice->z_uid.tv.tv_sec, notice->z_uid.tv.tv_usec));
+#endif
for (nacked = nacklist->q_forw;
nacked != nacklist;
nacked = nacked->q_forw)
@@ -697,7 +739,9 @@ struct sockaddr_in *who;
xfree(nacked);
return;
}
+#if 0
zdbug((LOG_DEBUG,"nack not found"));
+#endif
return;
}
@@ -711,11 +755,7 @@ struct sockaddr_in *who;
*/
Code_t
-control_dispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+control_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
{
register char *opcode = notice->z_opcode;
ZClient_t *client;
@@ -731,10 +771,12 @@ ZServerDesc_t *server;
* CLIENT_CANCELSUB: ""
*/
- if (!strcasecmp(notice->z_class_inst, ZEPHYR_CTL_HM))
+ zdbug ((LOG_DEBUG, "ctl_disp: opc=%s", opcode));
+
+ if (!strcasecmp (notice->z_class_inst, ZEPHYR_CTL_HM))
return(hostm_dispatch(notice, auth, who, server));
- else if (!strcmp(opcode, CLIENT_GIMMESUBS) ||
- !strcmp(opcode, CLIENT_GIMMEDEFS)) {
+ else if (!strcmp (opcode, CLIENT_GIMMESUBS) ||
+ !strcmp (opcode, CLIENT_GIMMEDEFS)) {
/* this special case is before the auth check so that
someone who has no subscriptions does NOT get a SERVNAK
but rather an empty list. Note we must therefore
@@ -742,7 +784,7 @@ ZServerDesc_t *server;
#ifdef OLD_COMPAT
/* only acknowledge if *not* old version; the old version
acknowledges the packet with the reply */
- if (strcmp(notice->z_version, OLD_ZEPHYR_VERSION))
+ if (strcmp (notice->z_version, OLD_ZEPHYR_VERSION))
ack(notice, who);
#else /* !OLD_COMPAT */
ack(notice, who);
@@ -750,7 +792,9 @@ ZServerDesc_t *server;
subscr_sendlist(notice, auth, who);
return(ZERR_NONE);
} else if (!auth) {
+#if 0
zdbug((LOG_DEBUG,"unauth ctrl_disp"));
+#endif
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
return(ZERR_NONE);
@@ -762,8 +806,8 @@ ZServerDesc_t *server;
if (host && host->zh_locked)
return(ZSRV_REQUEUE);
- wantdefs = strcmp(opcode, CLIENT_SUBSCRIBE_NODEFS);
- if (!wantdefs || !strcmp(opcode, CLIENT_SUBSCRIBE)) {
+ wantdefs = strcmp (opcode, CLIENT_SUBSCRIBE_NODEFS);
+ if (!wantdefs || !strcmp (opcode, CLIENT_SUBSCRIBE)) {
/* subscription notice */
if (!(client = client_which_client(who, notice))) {
if ((retval = client_register(notice,
@@ -791,7 +835,7 @@ ZServerDesc_t *server;
abort();
}
}
- if (strcmp(client->zct_principal, notice->z_sender)) {
+ if (strcmp (client->zct_principal.value (), notice->z_sender)) {
/* you may only subscribe for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -811,7 +855,7 @@ ZServerDesc_t *server;
}
} else if (!strcmp(opcode, CLIENT_UNSUBSCRIBE)) {
if ((client = client_which_client(who,notice))) {
- if (strcmp(client->zct_principal, notice->z_sender)) {
+ if (strcmp(client->zct_principal.value (), notice->z_sender)) {
/* you may only cancel for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -826,7 +870,7 @@ ZServerDesc_t *server;
/* canceling subscriptions implies I can punt info about
this client */
if ((client = client_which_client(who,notice))) {
- if (strcmp(client->zct_principal, notice->z_sender)) {
+ if (strcmp(client->zct_principal.value (), notice->z_sender)) {
/* you may only cancel for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -835,16 +879,20 @@ ZServerDesc_t *server;
if (host) {
/* don't flush locations here, let him
do it explicitly */
+#if 0
if (zdebug)
syslog(LOG_DEBUG,
"cancelsub clt_dereg");
+#endif
hostm_lose_ignore(client);
(void) client_deregister(client, host, 0);
}
}
if (!client || !host) {
+#if 0
zdbug((LOG_DEBUG,"can_sub not found client"));
+#endif
if (server == me_server)
nack(notice, who);
return(ZERR_NONE);
diff --git a/server/hostm.c b/server/hostm.c
index b7ad656..377387e 100644
--- a/server/hostm.c
+++ b/server/hostm.c
@@ -16,8 +16,8 @@
#ifndef lint
#ifndef SABER
static char rcsid_hostm_c[] = "$Header$";
-#endif SABER
-#endif lint
+#endif
+#endif
#include "zserver.h"
#include <sys/socket.h> /* for AF_INET */
@@ -98,9 +98,13 @@ static long lose_timo = LOSE_TIMO;
static losinghost *losing_hosts = NULLLH; /* queue of pings for hosts we
doubt are really there */
-static void host_detach(), insert_host(), remove_host();
-static void host_not_losing(), host_lost(), ping();
-static Code_t host_attach();
+static void host_detach(register ZHostList_t *host, ZServerDesc_t *server),
+ insert_host(ZHostList_t *host, ZServerDesc_t *server),
+ remove_host(ZHostList_t *host);
+static void host_not_losing(struct sockaddr_in *who),
+ host_lost(void *which),
+ ping(struct sockaddr_in *sin);
+static Code_t host_attach(struct sockaddr_in *who, ZServerDesc_t *server);
/*
* We received a HostManager packet. process accordingly.
@@ -108,19 +112,16 @@ static Code_t host_attach();
/*ARGSUSED*/
Code_t
-hostm_dispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
{
ZServerDesc_t *owner;
ZHostList_t *host = NULLZHLT;
char *opcode = notice->z_opcode;
Code_t retval;
-
+#if 0
zdbug((LOG_DEBUG,"hm_disp"));
+#endif
host = hostm_find_host(&who->sin_addr);
if (host && host->zh_locked)
@@ -130,21 +131,29 @@ ZServerDesc_t *server;
host_not_losing(who);
return(ZERR_NONE);
} else if (notice->z_kind != HMCTL) {
+#if 0
zdbug((LOG_DEBUG, "bogus HM packet"));
+#endif
clt_ack(notice, who, AUTH_FAILED);
return(ZERR_NONE);
}
owner = hostm_find_server(&who->sin_addr);
if (!strcmp(opcode, HM_ATTACH)) {
+#if 0
zdbug((LOG_DEBUG,"attach %s",inet_ntoa(who->sin_addr)));
+#endif
if (owner == server) {
+#if 0
zdbug((LOG_DEBUG,"no change"));
+#endif
/* Same server owns him. do nothing */
} else if (owner) {
/* He has switched servers.
he was lost but has asked server to work for him.
We need to transfer him to server */
+#if 0
zdbug((LOG_DEBUG,"hm_disp transfer"));
+#endif
hostm_transfer(host, server);
} else {
/* no owner. attach him to server. */
@@ -161,7 +170,9 @@ ZServerDesc_t *server;
ack(notice, who);
}
} else if (!strcmp(opcode, HM_BOOT)) {
+#if 0
zdbug((LOG_DEBUG, "boot %s",inet_ntoa(who->sin_addr)));
+#endif
/* Booting is just like flushing and attaching */
if (owner) /* if owned, flush */
hostm_flush(host, owner);
@@ -175,7 +186,9 @@ ZServerDesc_t *server;
ack(notice, who);
}
} else if (!strcmp(opcode, HM_FLUSH)) {
+#if 0
zdbug((LOG_DEBUG, "hm_flush %s",inet_ntoa(who->sin_addr)));
+#endif
if (!owner)
return(ZERR_NONE);
/* flush him */
@@ -183,7 +196,9 @@ ZServerDesc_t *server;
if (server == me_server)
server_forward(notice, auth, who);
} else if (!strcmp(opcode, HM_DETACH)) {
+#if 0
zdbug((LOG_DEBUG, "hm_detach %s",inet_ntoa(who->sin_addr)));
+#endif
/* ignore it */
} else {
syslog(LOG_WARNING, "hm_disp: unknown opcode %s",opcode);
@@ -201,9 +216,7 @@ ZServerDesc_t *server;
*/
void
-hostm_flush(host, server)
-ZHostList_t *host;
-ZServerDesc_t *server;
+hostm_flush(ZHostList_t *host, ZServerDesc_t *server)
{
register ZClientList_t *clist = NULLZCLT, *clt;
losinghost *lhp, *lhp2;
@@ -214,7 +227,9 @@ ZServerDesc_t *server;
return;
}
+#if 0
zdbug((LOG_DEBUG,"hostm_flush"));
+#endif
if (losing_hosts)
for (lhp = losing_hosts->q_forw;
@@ -232,8 +247,10 @@ ZServerDesc_t *server;
for (clt = clist->q_forw; clt != clist; clt = clist->q_forw) {
/* client_deregister frees this client & subscriptions
& locations and remque()s the client */
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "hostm_flush clt_dereg");
+#endif
client_deregister(clt->zclt_client, host, 1);
}
@@ -248,13 +265,15 @@ ZServerDesc_t *server;
*/
void
-hostm_shutdown()
+hostm_shutdown(void)
{
register ZHostList_t *hosts = otherservers[me_server_idx].zs_hosts;
register ZHostList_t *host;
int newserver, i;
+#if 0
zdbug((LOG_DEBUG,"hostm_shutdown"));
+#endif
if (!hosts)
return;
@@ -294,13 +313,13 @@ hostm_shutdown()
*/
void
-hostm_losing(client, host)
-ZClient_t *client;
-ZHostList_t *host;
+hostm_losing(ZClient_t *client, ZHostList_t *host)
{
losinghost *newhost;
+#if 0
zdbug((LOG_DEBUG,"losing host"));
+#endif
if (!losing_hosts) {
if (!(losing_hosts = (losinghost *) xmalloc(sizeof(losinghost)))) {
syslog(LOG_ERR, "no mem losing host");
@@ -312,7 +331,9 @@ ZHostList_t *host;
newhost != losing_hosts;
newhost = newhost->q_forw)
if (newhost->lh_client == client) {
+#if 0
zdbug((LOG_DEBUG,"clt already losing"));
+#endif
return;
}
if (!(newhost = (losinghost *) xmalloc(sizeof(losinghost)))) {
@@ -334,9 +355,9 @@ ZHostList_t *host;
*/
static void
-host_lost(which)
-losinghost *which;
+host_lost(void* arg)
{
+ losinghost *which = (losinghost *) arg;
ZServerDesc_t *server;
ZNotice_t notice;
struct sockaddr_in who;
@@ -346,11 +367,15 @@ losinghost *which;
int omask = sigblock(sigmask(SIGFPE)); /* don't start db dumps */
+#if 0
zdbug((LOG_DEBUG,"lost host %s",
inet_ntoa(which->lh_host->zh_addr.sin_addr)));
+#endif
if (!(server = hostm_find_server(&which->lh_host->zh_addr.sin_addr))) {
+#if 0
zdbug((LOG_DEBUG,"no server"));
+#endif
xremque(which);
xfree(which);
(void) sigsetmask(omask);
@@ -398,8 +423,7 @@ losinghost *which;
*/
static void
-host_not_losing(who)
-struct sockaddr_in *who;
+host_not_losing(struct sockaddr_in *who)
{
losinghost *lhp, *lhp2;
int omask;
@@ -413,13 +437,17 @@ struct sockaddr_in *who;
/* go back, since remque will change things */
lhp2 = lhp->q_back;
timer_reset(lhp->lh_timer);
+#if 0
zdbug((LOG_DEBUG,"lost client %s/%d",
inet_ntoa(lhp->lh_client->zct_sin.sin_addr),
ntohs(lhp->lh_client->zct_sin.sin_port)));
+#endif
/* deregister all subscriptions, and flush locations
associated with the client. */
+#if 0
if (zdebug)
syslog(LOG_DEBUG,"h_not_lose clt_dereg");
+#endif
client_deregister(lhp->lh_client, lhp->lh_host, 1);
server_kill_clt(lhp->lh_client);
xremque(lhp);
@@ -439,8 +467,7 @@ struct sockaddr_in *who;
*/
void
-hostm_lose_ignore(client)
-ZClient_t *client;
+hostm_lose_ignore(ZClient_t *client)
{
losinghost *lhp, *lhp2;
int omask;
@@ -455,9 +482,11 @@ ZClient_t *client;
/* go back, since remque will change things */
lhp2 = lhp->q_back;
timer_reset(lhp->lh_timer);
+#if 0
zdbug((LOG_DEBUG,"hm_l_ign client %s/%d",
inet_ntoa(client->zct_sin.sin_addr),
ntohs(client->zct_sin.sin_port)));
+#endif
xremque(lhp);
xfree(lhp);
/* now that the remque adjusted the linked list,
@@ -475,15 +504,15 @@ ZClient_t *client;
*/
void
-hostm_transfer(host, server)
-ZHostList_t *host;
-ZServerDesc_t *server;
+hostm_transfer(ZHostList_t *host, ZServerDesc_t *server)
{
int omask;
/* we need to unlink and relink him, and change the table entry */
+#if 0
zdbug((LOG_DEBUG, "hostm_transfer 0x%x to 0x%x", host, server));
+#endif
/* is this the same server? */
if (hostm_find_server(&host->zh_addr.sin_addr) == server)
@@ -509,9 +538,7 @@ ZServerDesc_t *server;
*/
static Code_t
-host_attach(who, server)
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+host_attach(struct sockaddr_in *who, ZServerDesc_t *server)
{
register ZHostList_t *hlist;
register ZClientList_t *clist;
@@ -552,9 +579,7 @@ ZServerDesc_t *server;
*/
static void
-host_detach(host, server)
-register ZHostList_t *host;
-ZServerDesc_t *server;
+host_detach(register ZHostList_t *host, ZServerDesc_t *server)
{
/* undo what we did in host_attach */
int omask = sigblock(sigmask(SIGFPE)); /* don't start db dumps */
@@ -586,16 +611,16 @@ ZServerDesc_t *server;
*/
void
-hostm_deathgram(sin, server)
-struct sockaddr_in *sin;
-ZServerDesc_t *server;
+hostm_deathgram(struct sockaddr_in *sin, ZServerDesc_t *server)
{
Code_t retval;
int shutlen;
ZNotice_t shutnotice;
char *shutpack;
+#if 0
zdbug((LOG_DEBUG,"deathgram %s",inet_ntoa(sin->sin_addr)));
+#endif
/* fill in the shutdown notice */
@@ -612,7 +637,9 @@ ZServerDesc_t *server;
if (server) {
shutnotice.z_message = inet_ntoa(server->zs_addr.sin_addr);
shutnotice.z_message_len = strlen(shutnotice.z_message) + 1;
+#if 0
zdbug((LOG_DEBUG, "suggesting %s",shutnotice.z_message));
+#endif
} else {
shutnotice.z_message = NULL;
shutnotice.z_message_len = 0;
@@ -646,15 +673,16 @@ ZServerDesc_t *server;
*/
static void
-ping(sin)
-struct sockaddr_in *sin;
+ping(struct sockaddr_in *sin)
{
Code_t retval;
int shutlen;
ZNotice_t shutnotice;
char *shutpack;
+#if 0
zdbug((LOG_DEBUG,"ping %s",inet_ntoa(sin->sin_addr)));
+#endif
/* fill in the shutdown notice */
@@ -702,8 +730,7 @@ struct sockaddr_in *sin;
*/
ZHostList_t *
-hostm_find_host(addr)
-struct in_addr *addr;
+hostm_find_host(struct in_addr *addr)
{
register int i, rlo, rhi;
@@ -735,8 +762,7 @@ struct in_addr *addr;
*/
ZServerDesc_t *
-hostm_find_server(addr)
-struct in_addr *addr;
+hostm_find_server(struct in_addr *addr)
{
register int i, rlo, rhi;
@@ -768,15 +794,13 @@ struct in_addr *addr;
*/
static void
-insert_host(host, server)
-ZHostList_t *host;
-ZServerDesc_t *server;
+insert_host(ZHostList_t *host, ZServerDesc_t *server)
{
struct hostlist *oldlist;
register int i = 0;
int omask;
-#ifdef DEBUG
+#if defined (DEBUG) && 0
char buf[512];
if (zdebug) {
(void) strcpy(buf, inet_ntoa(host->zh_addr.sin_addr));
@@ -784,7 +808,7 @@ ZServerDesc_t *server;
buf,
inet_ntoa(server->zs_addr.sin_addr));
}
-#endif DEBUG
+#endif
if (hostm_find_host(&host->zh_addr.sin_addr))
return;
@@ -822,7 +846,7 @@ ZServerDesc_t *server;
}
xfree(oldlist);
(void) sigsetmask(omask);
-#ifdef DEBUG
+#if defined (DEBUG) && 0
if (zdebug) {
register int i = 0;
char buf[512];
@@ -841,20 +865,23 @@ ZServerDesc_t *server;
*/
static void
-remove_host(host)
-ZHostList_t *host;
+remove_host(ZHostList_t *host)
{
struct hostlist *oldlist;
register int i = 0;
int omask;
+#if 0
zdbug((LOG_DEBUG,"remove_host %s", inet_ntoa(host->zh_addr.sin_addr)));
+#endif
if (!hostm_find_host(&host->zh_addr.sin_addr))
return;
omask = sigblock(sigmask(SIGFPE)); /* don't start db dumps */
if (--num_hosts == 0) {
+#if 0
zdbug((LOG_DEBUG,"last host"));
+#endif
xfree(all_hosts);
all_hosts = NULLHLT;
(void) sigsetmask(omask);
@@ -892,8 +919,7 @@ ZHostList_t *host;
*/
void
-hostm_dump_hosts(fp)
-FILE *fp;
+hostm_dump_hosts(FILE *fp)
{
register int i;
for (i = 0; i < num_hosts; i++) {
@@ -904,3 +930,22 @@ FILE *fp;
}
return;
}
+
+/*
+ * Readjust server-array indices according to the supplied new vector.
+ */
+
+void
+hostm_renumber_servers (int *srv)
+{
+ int i;
+ for (i = 0; i < num_hosts; i++) {
+ int idx = srv[all_hosts[i].server_index];
+ if (idx < 0) {
+ syslog (LOG_ERR, "hostm_renumber_servers error: [%d] = %d",
+ all_hosts[i].server_index, idx);
+ idx = 0;
+ }
+ all_hosts[i].server_index = idx;
+ }
+}
diff --git a/server/kstuff.c b/server/kstuff.c
index 1c12328..ca4ab3f 100644
--- a/server/kstuff.c
+++ b/server/kstuff.c
@@ -14,16 +14,17 @@
*/
#ifndef lint
-static char rcsid_kstuff_c[] = "$Header$";
-#endif lint
+static const char rcsid_kstuff_c[] = "$Header$";
+#endif
#include "zserver.h"
-#include <zephyr/krb_err.h>
+extern "C" {
#include <ctype.h>
#include <netdb.h>
-
-char *index();
+#include <strings.h>
+#include <zephyr/zephyr_internal.h>
+}
/*
@@ -34,12 +35,12 @@ char *index();
* the value of rd_ap_req() applied to the ticket.
*/
int
-GetKerberosData(fd, haddr, kdata, service, srvtab)
- int fd; /* file descr. to read from */
- struct in_addr haddr; /* address of foreign host on fd */
- AUTH_DAT *kdata; /* kerberos data (returned) */
- char *service; /* service principal desired */
- char *srvtab; /* file to get keys from */
+GetKerberosData(int fd, struct in_addr haddr, AUTH_DAT *kdata, char *service, char *srvtab)
+ /* file descr. to read from */
+ /* address of foreign host on fd */
+ /* kerberos data (returned) */
+ /* service principal desired */
+ /* file to get keys from */
{
char p[20];
@@ -90,37 +91,41 @@ GetKerberosData(fd, haddr, kdata, service, srvtab)
* get the ticket and write it to the file descriptor
*/
-SendKerberosData(fd, ticket, service, host)
-int fd; /* file descriptor to write onto */
-KTEXT ticket; /* where to put ticket (return) */
-char *service, *host; /* service name, foreign host */
+SendKerberosData(int fd, KTEXT ticket, char *service, char *host)
+ /* file descriptor to write onto */
+ /* where to put ticket (return) */
+ /* service name, foreign host */
{
int rem;
char p[32];
char krb_realm[REALM_SZ];
+ static int failed = 0;
int written;
rem=KSUCCESS;
+ if (failed) abort();
+
rem = krb_get_lrealm(krb_realm,1);
if (rem != KSUCCESS)
- return rem + ERROR_TABLE_BASE_krb;
+ return rem + krb_err_base;
rem = krb_mk_req( ticket, service, host, krb_realm, (u_long)0 );
if (rem != KSUCCESS)
- return rem + ERROR_TABLE_BASE_krb;
+ return rem + krb_err_base;
(void) sprintf(p,"%d ",ticket->length);
- if ((written = write(fd, p, strlen(p))) != strlen(p))
+ int size_to_write = strlen (p);
+ if ((written = write(fd, p, size_to_write)) != size_to_write)
if (written < 0)
return errno;
else
- return(ZSRV_PKSHORT);
+ return ZSRV_PKSHORT;
if ((written = write(fd, (caddr_t) (ticket->dat), ticket->length)) != ticket->length)
if (written < 0)
return errno;
else
- return(ZSRV_PKSHORT);
+ return ZSRV_PKSHORT;
return 0;
}
@@ -130,8 +135,216 @@ static char tkt_file[] = ZEPHYR_TKFILE;
/* Hack to replace the kerberos library's idea of the ticket file with
our idea */
char *
-tkt_string()
+tkt_string(void)
{
- return(tkt_file);
+ return tkt_file;
+}
+
+/* Check authentication of the notice.
+ If it looks authentic but fails the Kerberos check, return -1.
+ If it looks authentic and passes the Kerberos check, return 1.
+ If it doesn't look authentic, return 0
+
+ When not using Kerberos, return (looks-authentic-p)
+ */
+struct AuthEnt {
+ const char *data;
+ int len;
+ ZString principal;
+#ifndef NOENCRYPTION
+ C_Block session_key;
+#endif
+ long expire_time;
+ sockaddr_in from;
+ AuthEnt () {
+ data = 0;
+ }
+ void expire () {
+ if (data) {
+ zfree ((void *) data, strlen (data) + 1);
+ data = 0;
+ }
+ len = 0;
+ expire_time = 0;
+ principal = 0;
+ }
+};
+
+#define HASH_SIZE_1 513
+#define HASH_SIZE_2 3
+static AuthEnt auth_cache[HASH_SIZE_1][HASH_SIZE_2];
+
+static int auth_hash (const char *str, int len) {
+ unsigned long hash;
+ if (len <= 3)
+ return str[0];
+ hash = str[len - 1] * 256 + str[len-2] * 16 + str[len-3];
+ hash %= HASH_SIZE_1;
+ return hash;
+}
+
+static int check_cache (ZNotice_t *notice, sockaddr_in *from) {
+ const char *str = notice->z_ascii_authent;
+ int len = strlen (str), i;
+ unsigned int hash = 0;
+ unsigned long now = time(0);
+ AuthEnt *a;
+
+ hash = auth_hash (str, len);
+ for (i = 0; i < HASH_SIZE_2; i++) {
+ a = &auth_cache[hash][i];
+ if (!a->data) {
+ continue;
+ }
+ if (now > a->expire_time) {
+ a->expire ();
+ continue;
+ }
+ if (len != a->len) {
+ continue;
+ }
+ if (strcmp (notice->z_ascii_authent, a->data)) {
+ continue;
+ }
+ /* Okay, we know we've got the same authenticator. */
+ if (strcmp (notice->z_sender, a->principal.value ())) {
+ return ZAUTH_FAILED;
+ }
+ if (from->sin_addr.s_addr != a->from.sin_addr.s_addr) {
+ return ZAUTH_FAILED;
+ }
+#ifndef NOENCRYPTION
+ bcopy (a->session_key, __Zephyr_session, sizeof (C_Block));
+#endif
+ return ZAUTH_YES;
+ }
+ return ZAUTH_NO;
+}
+
+void add_to_cache (const AuthEnt& a) {
+ int len = a.len, i, j;
+ AuthEnt *entries;
+ unsigned int hash = 0;
+
+ hash = auth_hash (a.data, len);
+ entries = auth_cache[hash];
+ j = 0;
+ for (i = 0; i < HASH_SIZE_2; i++) {
+ if (entries[i].data == 0) {
+ j = i;
+ goto ok;
+ }
+ if (i == j)
+ continue;
+ if (entries[i].expire_time < entries[j].expire_time)
+ j = i;
+ }
+ok:
+ if (entries[j].data)
+ entries[j].expire ();
+ entries[j] = a;
}
-#endif KERBEROS
+
+int ZCheckAuthentication(ZNotice_t *notice, sockaddr_in *from) {
+ int result;
+ char srcprincipal[ANAME_SZ+INST_SZ+REALM_SZ+4];
+ KTEXT_ST authent;
+ AUTH_DAT dat;
+ ZChecksum_t our_checksum;
+ CREDENTIALS cred;
+ AuthEnt a;
+ int auth_len = 0;
+
+ if (!notice->z_auth) {
+ return (ZAUTH_NO);
+ }
+
+ if (__Zephyr_server) {
+
+ if (notice->z_authent_len <= 0) { /* bogus length */
+#if 1
+ syslog (LOG_DEBUG, "z_authent_len = %d -> AUTH_FAILED",
+ notice->z_authent_len);
+#endif
+ return(ZAUTH_FAILED);
+ }
+
+ auth_len = strlen (notice->z_ascii_authent);
+ if (ZReadAscii(notice->z_ascii_authent, auth_len + 1,
+ (unsigned char *)authent.dat,
+ notice->z_authent_len) == ZERR_BADFIELD) {
+#if 1
+ syslog (LOG_DEBUG, "ZReadAscii failed (len:%s) -> AUTH_FAILED",
+ error_message (ZERR_BADFIELD));
+#endif
+ return (ZAUTH_FAILED);
+ }
+ authent.length = notice->z_authent_len;
+ result = check_cache (notice, from);
+ if (result != ZAUTH_NO)
+ return result;
+
+ /* Well, it's not in the cache... decode it. */
+ result = krb_rd_req(&authent, SERVER_SERVICE,
+ SERVER_INSTANCE, from->sin_addr.s_addr,
+ &dat, SERVER_SRVTAB);
+ if (result == RD_AP_OK) {
+ bcopy ((void *) dat.session, (void *) a.session_key,
+ sizeof(C_Block));
+ bcopy((char *)dat.session, (char *)__Zephyr_session,
+ sizeof(C_Block));
+ (void) sprintf(srcprincipal, "%s%s%s@%s", dat.pname,
+ dat.pinst[0]?".":"", dat.pinst, dat.prealm);
+ if (strcmp(srcprincipal, notice->z_sender)) {
+#if 1
+ syslog (LOG_DEBUG, "principal mismatch->AUTH_FAILED");
+#endif
+ return (ZAUTH_FAILED);
+ }
+ a.principal = srcprincipal;
+ a.expire_time = time (0) + 5 * 60; /* add 5 minutes */
+ a.from = *from;
+ char *s = (char *) zalloc (auth_len + 1);
+ strcpy (s, notice->z_ascii_authent);
+ a.data = s;
+ a.len = auth_len;
+ add_to_cache (a);
+ return(ZAUTH_YES);
+ } else {
+#if 1
+ syslog (LOG_DEBUG, "krb_rd_req failed->AUTH_FAILED: %s",
+ krb_err_txt [result]);
+#endif
+ return (ZAUTH_FAILED); /* didn't decode correctly */
+ }
+ }
+
+ if (result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
+ __Zephyr_realm, &cred)) {
+#if 1
+ syslog (LOG_DEBUG, "krb_get_cred failed->AUTH_NO: %s",
+ krb_err_txt [result]);
+#endif
+ return (ZAUTH_NO);
+ }
+
+#ifdef NOENCRYPTION
+ our_checksum = 0;
+#else
+ our_checksum = (ZChecksum_t)des_quad_cksum(notice->z_packet, NULL,
+ notice->z_default_format+
+ strlen(notice->z_default_format)+1-
+ notice->z_packet, 0, cred.session);
+#endif
+ /* if mismatched checksum, then the packet was corrupted */
+ if (our_checksum == notice->z_checksum) {
+ return ZAUTH_YES;
+ }
+ else {
+#if 1
+ syslog (LOG_DEBUG, "checksum mismatch->AUTH_FAILED");
+#endif
+ return ZAUTH_FAILED;
+ }
+}
+#endif /* KERBEROS */
diff --git a/server/main.c b/server/main.c
index befcf7f..0626add 100644
--- a/server/main.c
+++ b/server/main.c
@@ -16,8 +16,8 @@
#ifndef lint
#ifndef SABER
static char rcsid_main_c[] = "$Id$";
-#endif SABER
-#endif lint
+#endif
+#endif
/*
* Server loop for Zephyr.
@@ -46,6 +46,10 @@ static char rcsid_main_c[] = "$Id$";
(if the client has not acknowledged a packet after a given timeout).
*/
+#include <new.h>
+#ifndef __GNUG__
+#define NO_INLINING /* bugs in cfront inlining... */
+#endif
#include "zserver.h" /* which includes
zephyr/zephyr.h
<errno.h>
@@ -61,22 +65,33 @@ static char rcsid_main_c[] = "$Id$";
zsrv_err.h
*/
+extern "C" {
#include <netdb.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
+#include <sys/wait.h>
+}
#define EVER (;;) /* don't stop looping */
-static int do_net_setup(), initialize();
-static void usage(), do_reset();
-static int bye(), dbug_on(), dbug_off(), dump_db(), reset();
+static int do_net_setup(void), initialize(void);
+static void usage(void), do_reset (void);
+#ifdef __GNUG__
+typedef int SIGNAL_RETURN_TYPE;
+#define SIG_RETURN return 0
+#else
+#define SIGNAL_RETURN_TYPE void
+#define SIG_RETURN return
+#endif
+static SIGNAL_RETURN_TYPE bye(int sig), dbug_on(int), dbug_off(int);
+static SIGNAL_RETURN_TYPE dump_db(int), reset(int), reap(int);
+static SIGNAL_RETURN_TYPE dump_strings(int);
#ifndef DEBUG
-static void detach();
+static void detach(void);
#endif DEBUG
-/* So lint shuts up: */
-void perror();
+extern "C" void perror(const char *);
static short doreset = 0; /* if it becomes 1, perform
reset functions */
@@ -90,7 +105,6 @@ fd_set interesting; /* the file descrips we are listening
int nfildes; /* number to look at in select() */
struct sockaddr_in sock_sin; /* address of the socket */
struct sockaddr_in bdump_sin; /* addr of brain dump socket */
-struct in_addr my_addr; /* for convenience, my IP address */
struct timeval nexthost_tv; /* time till next timeout for select */
ZNotAcked_t *nacklist; /* list of packets waiting for ack's */
@@ -105,10 +119,9 @@ int zalone = 0;
#endif DEBUG
u_long npackets = 0; /* number of packets processed */
long uptime; /* when we started operations */
+static int nofork;
-main(argc,argv)
-int argc;
-char **argv;
+main(int argc, char **argv)
{
int nfound; /* #fildes ready on select */
fd_set readable;
@@ -118,6 +131,12 @@ char **argv;
extern char *optarg;
extern int optind;
+#ifndef __GNUG__
+ set_new_handler ((void(*)()) abort);
+#else
+ set_new_handler (abort);
+#endif
+
/* set name */
if (programname = rindex(argv[0],'/'))
programname++;
@@ -125,7 +144,7 @@ char **argv;
/* process arguments */
- while ((optchar = getopt(argc, argv, "ds")) != EOF) {
+ while ((optchar = getopt(argc, argv, "ds3")) != EOF) {
switch(optchar) {
case 'd':
zdebug = 1;
@@ -134,7 +153,10 @@ char **argv;
case 's':
zalone = 1;
break;
-#endif DEBUG
+#endif
+ case '3':
+ nofork = 1;
+ break;
case '?':
default:
usage();
@@ -158,19 +180,21 @@ char **argv;
#endif KERBEROS
#ifndef DEBUG
- detach();
+ if (!nofork)
+ detach();
#endif DEBUG
/* open log */
OPENLOG(programname, LOG_PID, LOG_LOCAL6);
-#ifdef DEBUG
+#if defined (DEBUG) && 0
if (zalone)
syslog(LOG_DEBUG, "standalone operation");
-
-#endif DEBUG
+#endif
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "debugging on");
+#endif
/* set up sockets & my_addr and myname,
find other servers and set up server table, initialize queues
@@ -180,12 +204,14 @@ char **argv;
if (initialize())
exit(1);
+#ifndef __SABER__
/* chdir to somewhere where a core dump will survive */
if (chdir("/usr/tmp") != 0)
syslog(LOG_ERR,"chdir failed (%m) (execution continuing)");
if (setpriority(PRIO_PROCESS, getpid(), -10))
syslog(LOG_ERR,"setpriority failed (%m)");
+#endif
FD_ZERO(&interesting);
FD_SET(srv_socket, &interesting);
@@ -199,6 +225,10 @@ char **argv;
(void) signal(SIGALRM, bye);
(void) signal(SIGTERM, bye);
+#ifdef SignalIgnore
+#undef SIG_IGN
+#define SIG_IGN SignalIgnore
+#endif
(void) signal(SIGINT, SIG_IGN);
syslog(LOG_INFO, "Ready for action");
#else
@@ -207,7 +237,9 @@ char **argv;
#endif DEBUG
(void) signal(SIGUSR1, dbug_on);
(void) signal(SIGUSR2, dbug_off);
+ (void) signal(SIGCHLD, reap);
(void) signal(SIGFPE, dump_db);
+ (void) signal(SIGEMT, dump_strings);
(void) signal(SIGHUP, reset);
/* GO! */
@@ -257,12 +289,12 @@ char **argv;
else {
if ((bdump_socket >= 0) &&
FD_ISSET(bdump_socket,&readable))
- bdump_send();
+ bdump_send();
else if (msgs_queued() ||
FD_ISSET(srv_socket, &readable)) {
- handle_packet();
+ handle_packet();
} else
- syslog(LOG_ERR, "select weird?!?!");
+ syslog(LOG_ERR, "select weird?!?!");
}
}
}
@@ -275,7 +307,7 @@ char **argv;
*/
static int
-initialize()
+initialize(void)
{
if (do_net_setup())
return(1);
@@ -310,7 +342,7 @@ initialize()
*/
static int
-do_net_setup()
+do_net_setup(void)
{
struct servent *sp;
struct hostent *hp;
@@ -368,7 +400,7 @@ do_net_setup()
*/
static void
-usage()
+usage(void)
{
#ifdef DEBUG
fprintf(stderr,"Usage: %s [-d] [-s]\n",programname);
@@ -382,9 +414,8 @@ usage()
* interrupt routine
*/
-static int
-bye(sig)
-int sig;
+static SIGNAL_RETURN_TYPE
+bye(int sig)
{
server_shutdown(); /* tell other servers */
hostm_shutdown(); /* tell our hosts */
@@ -396,31 +427,62 @@ int sig;
/*NOTREACHED*/
}
-static int
-dbug_on()
+static SIGNAL_RETURN_TYPE
+dbug_on(int sig)
{
syslog(LOG_DEBUG, "debugging turned on");
zdebug = 1;
- return(0);
+ SIG_RETURN;
}
-static int
-dbug_off()
+static SIGNAL_RETURN_TYPE
+dbug_off(int sig)
{
syslog(LOG_DEBUG, "debugging turned off");
zdebug = 0;
- return(0);
+ SIG_RETURN;
}
-static int
-dump_db()
+int fork_for_dump = 0;
+
+static SIGNAL_RETURN_TYPE
+dump_strings (int sig) {
+ FILE *fp;
+ fp = fopen ("/usr/tmp/zephyr.strings", "w");
+ if (!fp) {
+ syslog (LOG_ERR, "can't open strings dump file: %m");
+ SIG_RETURN;
+ }
+ syslog (LOG_INFO, "dumping strings to disk");
+ ZString::print (fp);
+ if (fclose (fp) == EOF)
+ syslog (LOG_ERR, "error writing strings dump file");
+ SIG_RETURN;
+}
+
+static SIGNAL_RETURN_TYPE
+dump_db(int sig)
{
/* dump the in-core database to human-readable form on disk */
FILE *fp;
+ int pid;
+#ifdef __SABER__
+ pid = -1;
+#else
+ if (fork_for_dump) {
+ moncontrol (0);
+ pid = fork ();
+ moncontrol (1);
+ }
+ else
+ pid = -1;
+#endif
+ if (pid > 0)
+ SIG_RETURN;
if ((fp = fopen("/usr/tmp/zephyr.db", "w")) == (FILE *)0) {
syslog(LOG_ERR, "can't open dump database");
- return(0);
+ SIG_RETURN;
}
syslog(LOG_INFO, "dumping to disk");
server_dump_servers(fp);
@@ -430,25 +492,46 @@ dump_db()
if (fclose(fp) == EOF) {
syslog(LOG_ERR, "can't close dump db");
}
- return(0);
+ if (pid == 0)
+ exit (0);
+ SIG_RETURN;
}
-static int
-reset()
+static SIGNAL_RETURN_TYPE
+reset(int sig)
{
+#if 0
zdbug((LOG_DEBUG,"reset()"));
+#endif
doreset = 1;
- return(0);
+ SIG_RETURN;
+}
+
+#ifdef __GNUG__
+#define wait WaitStatus
+#endif
+
+static SIGNAL_RETURN_TYPE
+reap(int sig)
+{
+ wait waitb;
+ (void) wait3 (&waitb, WNOHANG, (struct rusage*) 0);
+ SIG_RETURN;
}
static void
-do_reset()
+do_reset(void)
{
+#if 0
zdbug((LOG_DEBUG,"do_reset()"));
+#endif
/* reset various things in the server's state */
+ SignalBlock no_hups (sigmask (SIGHUP));
+
subscr_reset();
server_reset();
access_reinit();
+ syslog (LOG_INFO, "restart completed");
doreset = 0;
}
@@ -458,12 +541,20 @@ do_reset()
*/
static void
-detach()
+detach(void)
{
/* detach from terminal and fork. */
register int i, size = getdtablesize();
- if (i = fork()) {
+ /* profiling seems to get confused by fork() */
+#ifndef __SABER__
+ moncontrol (0);
+#endif
+ i = fork ();
+#ifndef __SABER__
+ moncontrol (1);
+#endif
+ if (i) {
if (i < 0)
perror("fork");
exit(0);
@@ -478,3 +569,49 @@ detach()
}
#endif !DEBUG
+
+static /*const*/ ZString popular_ZStrings[] = {
+ "filsrv",
+ "",
+ "login",
+ "message",
+ "personal",
+ "operations",
+ "athena.mit.edu:root.cell",
+ "athena.mit.edu",
+ "artemis.mit.edu",
+ "athena.mit.edu:contrib",
+ "athena.mit.edu:contrib.sipb",
+ "talos.mit.edu",
+ "unix:0.0",
+ "aphrodite.mit.edu",
+ "mail",
+ "*",
+ "cyrus.mit.edu",
+ "odysseus.mit.edu",
+ "discuss",
+ "themis.mit.edu",
+ "pop",
+ "cyrus.mit.edu:/u2/lockers/games",
+ "athena.mit.edu:contrib.xpix.nb",
+ "talos.mit.edu:/u2/lockers/athenadoc",
+ "pollux.mit.edu",
+ "popret",
+ "syslog",
+ "maeander.mit.edu",
+ "athena.mit.edu:contrib.consult",
+ "athena.mit.edu:astaff",
+ "athena.mit.edu:project",
+ "aeneas.mit.edu",
+ "aeneas.mit.edu:/u1/x11r3",
+ "athena.mit.edu:project.gnu.nb",
+ "odysseus.mit.edu:/u3/lockers/softbone",
+ "urgent",
+ "aphrodite.mit.edu:/u2/lockers/andrew",
+ "helen.mit.edu",
+ "help",
+ "consult",
+ "athena.mit.edu:contrib.watchmaker",
+ "%me%",
+ "testers.athena.mit.edu:x11r4",
+};
diff --git a/server/server.c b/server/server.c
index ef9958c..de9daa2 100644
--- a/server/server.c
+++ b/server/server.c
@@ -20,9 +20,12 @@ static char rcsid_server_c[] = "$Id$";
#endif lint
#include "zserver.h"
+extern "C" {
#include <sys/socket.h> /* for AF_INET */
#include <netdb.h> /* for gethostbyname */
#include <sys/param.h> /* for BSD */
+}
+
/*
* Server manager. Deal with traffic to and from other servers.
*
@@ -64,21 +67,38 @@ static char rcsid_server_c[] = "$Id$";
* void server_reset();
*/
-static void server_hello(), server_flush(), setup_server();
-static void hello_respond(), srv_responded(), send_msg(), send_msg_list();
-static void srv_nack_cancel(), srv_rexmit(), srv_nack_release();
-static void srv_nack_move();
-static void server_lost();
-static void send_stats(), server_queue(), server_forw_reliable();
-static Code_t admin_dispatch(), recover_clt(), kill_clt();
+static void server_hello(ZServerDesc_t *which, int auth),
+ server_flush(register ZServerDesc_t *which),
+ setup_server(register ZServerDesc_t *server, struct in_addr *addr);
+static void hello_respond(struct sockaddr_in *who, int adj, int auth),
+ srv_responded(struct sockaddr_in *who),
+ send_msg(struct sockaddr_in *who, char *opcode, int auth),
+ send_msg_list(struct sockaddr_in *who, char *opcode, char **lyst, int num,
+ int auth);
+static void srv_nack_cancel(register ZNotice_t *notice,
+ struct sockaddr_in *who),
+ srv_rexmit(void *nackpacket),
+ srv_nack_release(ZServerDesc_t *server);
+static void srv_nack_renumber (register int *);
+static void server_lost(ZServerDesc_t *server);
+static void send_stats(struct sockaddr_in *who),
+ server_queue(ZServerDesc_t *server, int len, caddr_t pack, int auth,
+ struct sockaddr_in *who),
+ server_forw_reliable(ZServerDesc_t *server, caddr_t pack, int packlen,
+ ZNotice_t *notice);
+static Code_t admin_dispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server),
+ recover_clt(register ZNotice_t *notice, ZServerDesc_t *server),
+ kill_clt(ZNotice_t *notice);
+static Code_t extract_addr (ZNotice_t *notice, struct sockaddr_in *who);
#ifdef notdef
static Code_t server_register();
#endif notdef
-static struct in_addr *get_server_addrs();
+static struct in_addr *get_server_addrs(int *number);
#ifndef HESIOD
-static char **get_server_list();
-static void free_server_list();
+static char **get_server_list(char *file);
+static void free_server_list(register char **list);
#endif !HESIOD
ZNotAcked_t *srv_nacklist; /* not acked list for server-server
@@ -92,9 +112,9 @@ int me_server_idx; /* # of my entry in the array */
#define DONT_ADJUST (0) /* don't adjust timeout */
/* parameters controlling the transitions of the FSM's--patchable with adb */
-int timo_up = TIMO_UP;
-int timo_tardy = TIMO_TARDY;
-int timo_dead = TIMO_DEAD;
+long timo_up = TIMO_UP;
+long timo_tardy = TIMO_TARDY;
+long timo_dead = TIMO_DEAD;
long srv_rexmit_secs = REXMIT_SECS;
@@ -121,7 +141,7 @@ extern int zalone;
*/
void
-server_init()
+server_init(void)
{
register int i;
struct in_addr *serv_addr, *server_addrs, limbo_addr;
@@ -165,7 +185,9 @@ server_init()
otherservers[i].zs_timer = (timer) NULL;
otherservers[i].zs_update_queue = NULLZSPT;
otherservers[i].zs_dumping = 0;
+#if 0
zdbug((LOG_DEBUG,"found myself"));
+#endif
}
}
@@ -221,7 +243,7 @@ server_init()
* handle on a particular server other than by indexing on otherservers[].
*/
void
-server_reset()
+server_reset(void)
{
int num_servers;
struct in_addr *server_addrs;
@@ -231,7 +253,9 @@ server_reset()
int *ok_list_new, *ok_list_old;
int num_ok, new_num;
+#if 0
zdbug((LOG_DEBUG, "server_reset"));
+#endif
#ifdef DEBUG
if (zalone) {
syslog(LOG_INFO, "server_reset while alone, punt");
@@ -244,13 +268,13 @@ server_reset()
syslog(LOG_ERR, "server_reset no servers. nothing done.");
return;
}
- if ((ok_list_new = (int *)xmalloc(num_servers * sizeof(int))) ==
- (int *) 0) {
+ ok_list_new = (int *) LOCAL_ALLOC (num_servers * sizeof (int));
+ if (ok_list_new == (int *) 0) {
syslog(LOG_ERR, "server_reset no mem new");
return;
}
- if ((ok_list_old = (int *)xmalloc(nservers * sizeof(int))) ==
- (int *) 0) {
+ ok_list_old = (int *) LOCAL_ALLOC (nservers * sizeof (int));
+ if (ok_list_old == (int *) 0) {
syslog(LOG_ERR, "server_reset no mem old");
xfree(ok_list_new);
return;
@@ -290,6 +314,7 @@ server_reset()
/* remove any dead servers on old list not on new list. */
if (num_ok < nservers) {
+ int *srv;
new_num = 1; /* limbo */
/* count number of servers to keep */
for (j = 1; j < nservers; j++)
@@ -310,20 +335,27 @@ server_reset()
i = 1;
servers[0] = otherservers[0]; /* copy limbo */
+ srv = (int*) LOCAL_ALLOC (nservers * sizeof (int));
+ bzero (srv, nservers * sizeof (int));
+
/* copy the kept servers */
for (j = 1; j < nservers; j++) { /* skip limbo */
if (ok_list_old[j] ||
otherservers[j].zs_state != SERV_DEAD) {
servers[i] = otherservers[j];
- srv_nack_move(j,i);
+ srv[j] = i;
i++;
} else {
syslog(LOG_INFO, "flushing server %s",
inet_ntoa(otherservers[j].zs_addr.sin_addr));
server_flush(&otherservers[j]);
+ srv[j] = -1;
}
}
+ srv_nack_renumber (srv);
+ hostm_renumber_servers (srv);
+
xfree(otherservers);
otherservers = servers;
nservers = new_num;
@@ -336,6 +368,7 @@ server_reset()
new_num++;
/* new_num is number of extras. */
nservers += new_num;
+/* otherservers = new ZServerDesc_t [nservers];*/
otherservers = (ZServerDesc_t *)realloc((caddr_t) otherservers, (unsigned) (nservers * sizeof(ZServerDesc_t)));
if (!otherservers) {
syslog(LOG_CRIT, "server_reset realloc");
@@ -376,13 +409,17 @@ server_reset()
otherservers[i].zs_timer =
timer_set_rel(0L, server_timo,
(caddr_t) &otherservers[i]);
+#if 0
zdbug((LOG_DEBUG, "reset timer for %s",
inet_ntoa(otherservers[i].zs_addr.sin_addr)));
+#endif
}
- xfree(ok_list_old);
- xfree(ok_list_new);
+ LOCAL_FREE (ok_list_old);
+ LOCAL_FREE (ok_list_new);
+#if 0
zdbug((LOG_DEBUG, "server_reset: %d servers now", nservers));
+#endif
return;
}
@@ -405,12 +442,14 @@ srv_states[] = {
*/
void
-server_timo(which)
-ZServerDesc_t *which;
+server_timo(void* arg)
{
+ ZServerDesc_t *which = (ZServerDesc_t *) arg;
int auth;
+#if 0
zdbug((LOG_DEBUG,"srv_timo: %s", inet_ntoa(which->zs_addr.sin_addr)));
+#endif
/* change state and reset if appropriate */
switch(which->zs_state) {
case SERV_DEAD: /* leave him dead */
@@ -442,8 +481,10 @@ ZServerDesc_t *which;
}
/* now he's either TARDY, STARTING, or DEAD
We send a "hello," which increments the counter */
+#if 0
zdbug((LOG_DEBUG, "srv %s is %s",inet_ntoa(which->zs_addr.sin_addr),
srv_states[(int) which->zs_state]));
+#endif
server_hello(which, auth);
/* reschedule the timer */
which->zs_timer = timer_set_rel(which->zs_timeout, server_timo,
@@ -456,27 +497,27 @@ ZServerDesc_t *which;
/*ARGSUSED*/
Code_t
-server_dispatch(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+server_dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who)
{
ZServerDesc_t *server;
struct sockaddr_in newwho;
Code_t status;
+ Notice notice = n;
+#if 1
zdbug((LOG_DEBUG, "server_dispatch"));
+#endif
- if (notice->z_kind == SERVACK) {
- srv_nack_cancel(notice, who);
+ if (notice.notice->z_kind == SERVACK) {
+ srv_nack_cancel(notice.notice, who);
srv_responded(who);
return(ZERR_NONE);
}
/* set up a who for the real origin */
bzero((caddr_t) &newwho, sizeof(newwho));
newwho.sin_family = AF_INET;
- newwho.sin_addr.s_addr = notice->z_sender_addr.s_addr;
- newwho.sin_port = notice->z_port;
+ newwho.sin_addr.s_addr = notice.notice->z_sender_addr.s_addr;
+ newwho.sin_port = notice.notice->z_port;
server = server_which_server(who);
@@ -488,20 +529,21 @@ struct sockaddr_in *who;
if (class_is_admin(notice)) {
/* admins don't get acked, else we get a packet loop */
/* will return requeue if bdump request and dumping */
- return(admin_dispatch(notice, auth, who, server));
+ return(admin_dispatch(notice.notice, auth, who, server));
} else if (class_is_control(notice))
- status = control_dispatch(notice, auth, &newwho, server);
+ status = control_dispatch(notice.notice, auth, &newwho, server);
else if (class_is_ulogin(notice))
- status = ulogin_dispatch(notice, auth, &newwho, server);
+ status = ulogin_dispatch(notice.notice, auth, &newwho, server);
else if (class_is_ulocate(notice))
- status = ulocate_dispatch(notice, auth, &newwho, server);
+ status = ulocate_dispatch(notice.notice, auth, &newwho, server);
else {
/* shouldn't come from another server */
- syslog(LOG_WARNING, "srv_disp: pkt cls %s",notice->z_class);
+ syslog(LOG_WARNING, "srv_disp: pkt cls %s",
+ notice.notice->z_class);
status = ZERR_NONE; /* XXX */
}
if (status != ZSRV_REQUEUE)
- ack(notice, who); /* acknowledge it if processed */
+ ack(notice.notice, who); /* acknowledge it if processed */
return(status);
}
@@ -523,15 +565,19 @@ struct sockaddr_in *who;
int omask = sigblock(sigmask(SIGFPE)); /* don't do ascii dumps */
if (who->sin_port != sock_sin.sin_port) {
+#if 0
zdbug((LOG_DEBUG, "srv_register wrong port %d",
ntohs(who->sin_port)));
+#endif
(void) sigsetmask(omask);
return(1);
}
/* Not yet... talk to ken about authenticators */
#ifdef notdef
if (!auth) {
+#if 0
zdbug((LOG_DEBUG, "srv_register unauth"));
+#endif
(void) sigsetmask(omask);
return(1);
}
@@ -562,9 +608,11 @@ struct sockaddr_in *who;
otherservers[nservers].zs_dumping = 0;
nservers++;
+#if 0
zdbug((LOG_DEBUG, "srv %s is %s",
inet_ntoa(otherservers[nservers].zs_addr.sin_addr),
srv_states[(int) otherservers[nservers].zs_state]));
+#endif
(void) sigsetmask(omask);
return(0);
}
@@ -576,17 +624,20 @@ struct sockaddr_in *who;
*/
void
-server_recover(client)
-ZClient_t *client;
+server_recover(ZClient_t *client)
{
ZServerDesc_t *server;
char *lyst[2];
char buf[512];
+#if 0
zdbug((LOG_DEBUG,"server recover"));
+#endif
if ((server = hostm_find_server(&client->zct_sin.sin_addr))) {
if (server == limbo_server) {
+#if 0
zdbug((LOG_DEBUG, "no server to recover"));
+#endif
return;
} else if (server == me_server) {
/* send a ping, set up a timeout, and return */
@@ -611,8 +662,7 @@ ZClient_t *client;
*/
void
-server_kill_clt(client)
-ZClient_t *client;
+server_kill_clt(ZClient_t *client)
{
register int i;
char buf[512], *lyst[2];
@@ -622,12 +672,14 @@ ZClient_t *client;
int packlen, auth;
Code_t retval;
-
- zdbug((LOG_DEBUG, "server kill clt"));
lyst[0] = inet_ntoa(client->zct_sin.sin_addr),
(void) sprintf(buf, "%d", ntohs(client->zct_sin.sin_port));
lyst[1] = buf;
+#if 1
+ zdbug((LOG_DEBUG, "server kill clt %s/%s", lyst[0], lyst[1]));
+#endif
+
pnotice = &notice;
pnotice->z_kind = ACKED;
@@ -665,14 +717,15 @@ ZClient_t *client;
*/
static Code_t
-kill_clt(notice)
-ZNotice_t *notice;
+kill_clt(ZNotice_t *notice)
{
struct sockaddr_in who;
ZHostList_t *host;
ZClient_t *client;
+#if 0
zdbug((LOG_DEBUG, "kill_clt"));
+#endif
if (extract_addr(notice, &who) != ZERR_NONE)
return(ZERR_NONE); /* XXX */
if (!(host = hostm_find_host(&who.sin_addr))) {
@@ -685,8 +738,10 @@ ZNotice_t *notice;
syslog(LOG_WARNING, "no clt kill_clt");
return(ZERR_NONE); /* XXX */
}
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "kill_clt clt_dereg");
+#endif
hostm_lose_ignore(client);
/* remove the locations, too */
@@ -698,9 +753,7 @@ ZNotice_t *notice;
* Another server asked us to initiate recovery protocol with the hostmanager
*/
static Code_t
-recover_clt(notice, server)
-register ZNotice_t *notice;
-ZServerDesc_t *server;
+recover_clt(register ZNotice_t *notice, ZServerDesc_t *server)
{
struct sockaddr_in who;
ZClient_t *client;
@@ -735,12 +788,9 @@ ZServerDesc_t *server;
*/
static Code_t
-extract_addr(notice, who)
-ZNotice_t *notice;
-struct sockaddr_in *who;
+extract_addr(ZNotice_t *notice, struct sockaddr_in *who)
{
register char *cp = notice->z_message;
- extern unsigned long inet_addr();
if (!notice->z_message_len) {
syslog(LOG_WARNING, "bad addr pkt");
@@ -755,8 +805,10 @@ struct sockaddr_in *who;
}
who->sin_port = notice->z_port = htons((u_short) atoi(cp));
who->sin_family = AF_INET;
+#if 0
zdbug((LOG_DEBUG,"ext %s/%d", inet_ntoa(who->sin_addr),
ntohs(who->sin_port)));
+#endif
return(ZERR_NONE);
}
@@ -765,12 +817,13 @@ struct sockaddr_in *who;
*/
static void
-server_flush(which)
-register ZServerDesc_t *which;
+server_flush(register ZServerDesc_t *which)
{
register ZHostList_t *hst;
+#if 0
zdbug((LOG_DEBUG, "server_flush"));
+#endif
if (!which->zs_hosts) /* no data to flush */
return;
@@ -789,9 +842,7 @@ register ZServerDesc_t *which;
*/
static void
-server_hello(which, auth)
-ZServerDesc_t *which;
-int auth;
+server_hello(ZServerDesc_t *which, int auth)
{
send_msg(&which->zs_addr, ADMIN_HELLO, auth);
(which->zs_numsent)++;
@@ -804,23 +855,23 @@ int auth;
/*ARGSUSED*/
static Code_t
-admin_dispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+admin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
{
register char *opcode = notice->z_opcode;
Code_t status = ZERR_NONE;
+#if 0
zdbug((LOG_DEBUG, "ADMIN received"));
+#endif
if (!strcmp(opcode, ADMIN_HELLO)) {
hello_respond(who, ADJUST, auth);
} else if (!strcmp(opcode, ADMIN_IMHERE)) {
srv_responded(who);
} else if (!strcmp(opcode, ADMIN_SHUTDOWN)) {
+#if 0
zdbug((LOG_DEBUG, "server shutdown"));
+#endif
/* we need to transfer all of its hosts to limbo */
if (server) {
server_lost(server);
@@ -828,15 +879,17 @@ ZServerDesc_t *server;
server->zs_timeout = timo_dead;
/* don't worry about the timer, it will
be set appropriately on the next send */
+#if 0
zdbug((LOG_DEBUG, "srv %s is %s",
inet_ntoa(server->zs_addr.sin_addr),
srv_states[(int) server->zs_state]));
+#endif
}
} else if (!strcmp(opcode, ADMIN_BDUMP)) {
#ifdef CONCURRENT
if (bdumping)
return(ZSRV_REQUEUE);
-#endif CONCURRENT
+#endif
bdump_get(notice, auth, who, server);
} else if (!strcmp(opcode, ADMIN_LOST_CLT)) {
status = recover_clt(notice, server);
@@ -854,8 +907,7 @@ ZServerDesc_t *server;
*/
static void
-server_lost(server)
-ZServerDesc_t *server;
+server_lost(ZServerDesc_t *server)
{
register ZHostList_t *host, *hishost;
@@ -877,11 +929,7 @@ ZServerDesc_t *server;
/*ARGSUSED*/
Code_t
-server_adispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+server_adispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
{
/* this had better be a HELLO message--start of acquisition
@@ -910,14 +958,16 @@ ZServerDesc_t *server;
}
static void
-send_stats(who)
-struct sockaddr_in *who;
+send_stats(struct sockaddr_in *who)
{
register int i;
char buf[BUFSIZ];
char **responses;
int num_resp;
char *vers, *pkts, *upt;
+ char *__t;
+#define lstrdup(X) (__t=(char*)LOCAL_ALLOC(strlen(X)+1),strcpy(__t,X),__t)
+
#if defined(OLD_COMPAT) || defined(NEW_COMPAT)
int extrafields = 0;
#endif /* OLD_ or NEW_COMPAT */
@@ -942,12 +992,12 @@ struct sockaddr_in *who;
#ifdef NeXT
(void) strcat(buf, "NeXT");
#endif /* NeXT */
- vers = strsave(buf);
+ vers = lstrdup (buf);
(void) sprintf(buf, "%d pkts", npackets);
- pkts = strsave(buf);
+ pkts = lstrdup (buf);
(void) sprintf(buf, "%d seconds operational",NOW - uptime);
- upt = strsave(buf);
+ upt = lstrdup (buf);
#ifdef OLD_COMPAT
if (old_compat_count_uloc) extrafields++;
@@ -959,10 +1009,11 @@ struct sockaddr_in *who;
if (new_compat_count_subscr) extrafields++;
#endif /* NEW_COMPAT */
#if defined(OLD_COMPAT) || defined(NEW_COMPAT)
- responses = (char **) xmalloc((NUM_FIXED + nservers +
- extrafields) * sizeof(char **));
+ responses = (char **) LOCAL_ALLOC ((NUM_FIXED + nservers +
+ extrafields) * sizeof(char **));
#else
- responses = (char **) xmalloc((NUM_FIXED + nservers)*sizeof(char **));
+ responses = (char **) LOCAL_ALLOC ((NUM_FIXED + nservers)
+ *sizeof(char **));
#endif /* OLD_ or NEW_COMPAT */
responses[0] = vers;
responses[1] = pkts;
@@ -975,42 +1026,42 @@ struct sockaddr_in *who;
inet_ntoa(otherservers[i].zs_addr.sin_addr),
srv_states[(int) otherservers[i].zs_state],
otherservers[i].zs_dumping ? " (DUMPING)" : "");
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
#ifdef OLD_COMPAT
if (old_compat_count_uloc) {
(void) sprintf(buf, "%d old old location requests",
old_compat_count_uloc);
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
if (old_compat_count_ulocate) {
(void) sprintf(buf, "%d old old loc lookup requests",
old_compat_count_ulocate);
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
if (old_compat_count_subscr) {
(void) sprintf(buf, "%d old old subscr requests",
old_compat_count_subscr);
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
#endif /* OLD_COMPAT */
#ifdef NEW_COMPAT
if (new_compat_count_uloc) {
(void) sprintf(buf, "%d new old location requests",
new_compat_count_uloc);
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
if (new_compat_count_subscr) {
(void) sprintf(buf, "%d new old subscr requests",
new_compat_count_subscr);
- responses[num_resp++] = strsave(buf);
+ responses[num_resp++] = lstrdup (buf);
}
#endif /* NEW_COMPAT */
send_msg_list(who, ADMIN_STATUS, responses, num_resp, 0);
for (i = 0; i < num_resp; i++)
- xfree(responses[i]);
- xfree(responses);
+ LOCAL_FREE (responses[i]);
+ LOCAL_FREE (responses);
return;
}
#ifdef HESIOD
@@ -1026,8 +1077,8 @@ struct sockaddr_in *who;
#endif HESIOD
static struct in_addr *
-get_server_addrs(number)
-int *number; /* RETURN */
+get_server_addrs(int *number)
+ /* RETURN */
{
register int i;
char **server_hosts;
@@ -1079,8 +1130,7 @@ static int nhosts = 0;
*/
static char **
-get_server_list(file)
-char *file;
+get_server_list(char *file)
{
FILE *fp;
char buf[MAXHOSTNAMELEN];
@@ -1109,7 +1159,7 @@ char *file;
(unsigned) nhosts * 2);
nhosts = nhosts * 2;
}
- ret_list[nused++] = strsave(buf);
+ ret_list[nused++] = strsave (buf);
}
(void) fclose(fp);
ret_list[nused] = (char *)0;
@@ -1120,10 +1170,8 @@ char *file;
* free storage allocated by get_server_list
*/
static void
-free_server_list(list)
-register char **list;
+free_server_list(register char **list)
{
- register int i;
char **orig_list = list;
if (!nhosts) /* nothing allocated */
@@ -1141,12 +1189,9 @@ register char **list;
*/
static void
-setup_server(server, addr)
-register ZServerDesc_t *server;
-struct in_addr *addr;
+setup_server(register ZServerDesc_t *server, struct in_addr *addr)
{
register ZHostList_t *host;
- extern int timo_dead;
server->zs_state = SERV_DEAD;
server->zs_timeout = timo_dead;
@@ -1177,14 +1222,13 @@ struct in_addr *addr;
*/
static void
-hello_respond(who, adj, auth)
-struct sockaddr_in *who;
-int adj;
-int auth;
+hello_respond(struct sockaddr_in *who, int adj, int auth)
{
register ZServerDesc_t *which;
+#if 0
zdbug((LOG_DEBUG, "hello from %s", inet_ntoa(who->sin_addr)));
+#endif
send_msg(who, ADMIN_IMHERE, auth);
if (adj != ADJUST)
@@ -1217,8 +1261,7 @@ int auth;
*/
ZServerDesc_t *
-server_which_server(who)
-struct sockaddr_in *who;
+server_which_server(struct sockaddr_in *who)
{
register ZServerDesc_t *server;
register int i;
@@ -1239,12 +1282,13 @@ struct sockaddr_in *who;
* appropriately.
*/
static void
-srv_responded(who)
-struct sockaddr_in *who;
+srv_responded(struct sockaddr_in *who)
{
register ZServerDesc_t *which = server_which_server(who);
+#if 0
zdbug((LOG_DEBUG, "srv_responded %s", inet_ntoa(who->sin_addr)));
+#endif
if (!which) {
syslog(LOG_ERR, "hello input from non-server?!");
@@ -1279,8 +1323,10 @@ struct sockaddr_in *who;
(caddr_t) which);
break;
}
+#if 0
zdbug((LOG_DEBUG, "srv %s is %s",inet_ntoa(which->zs_addr.sin_addr),
srv_states[(int) which->zs_state]));
+#endif
return;
}
@@ -1289,7 +1335,7 @@ struct sockaddr_in *who;
*/
void
-server_shutdown()
+server_shutdown(void)
{
register int i;
@@ -1306,10 +1352,7 @@ server_shutdown()
*/
static void
-send_msg(who, opcode, auth)
-struct sockaddr_in *who;
-char *opcode;
-int auth;
+send_msg(struct sockaddr_in *who, char *opcode, int auth)
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
@@ -1337,7 +1380,8 @@ int auth;
if ((retval = ZFormatNotice(pnotice, &pack, &packlen,
auth ? ZAUTH : ZNOAUTH)) != ZERR_NONE) {
- syslog(LOG_WARNING, "snd_msg format: %s", error_message(retval));
+ syslog(LOG_WARNING, "snd_msg format: %s",
+ error_message(retval));
return;
}
if ((retval = ZSetDestAddr(who)) != ZERR_NONE) {
@@ -1363,12 +1407,8 @@ int auth;
*/
static void
-send_msg_list(who, opcode, lyst, num, auth)
-struct sockaddr_in *who;
-char *opcode;
-char *lyst[];
-int num;
-int auth;
+send_msg_list(struct sockaddr_in *who, char *opcode, char **lyst, int num,
+ int auth)
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
@@ -1394,7 +1434,9 @@ int auth;
/* XXX for now, we don't do authentication */
auth = 0;
- if ((retval = ZFormatNoticeList(pnotice, lyst, num, &pack, &packlen, auth ? ZAUTH : ZNOAUTH)) != ZERR_NONE) {
+ retval = ZFormatNoticeList (pnotice, lyst, num, &pack, &packlen,
+ auth ? ZAUTH : ZNOAUTH);
+ if (retval != ZERR_NONE) {
syslog(LOG_WARNING, "snd_msg_lst format: %s", error_message(retval));
return;
}
@@ -1418,18 +1460,16 @@ int auth;
*/
/*ARGSUSED*/
void
-server_forward(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+server_forward(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
register int i;
caddr_t pack;
int packlen;
Code_t retval;
-
+#if 0
zdbug((LOG_DEBUG, "srv_forw"));
+#endif
/* don't send to limbo */
for (i = 1; i < nservers; i++) {
if (i == me_server_idx) /* don't xmit to myself */
@@ -1440,7 +1480,7 @@ struct sockaddr_in *who;
queue it, even if he's dead */
continue;
- if (!(pack = xmalloc(sizeof(ZPacket_t)))) {
+ if (!(pack = (caddr_t) xmalloc(sizeof(ZPacket_t)))) {
syslog(LOG_CRIT, "srv_fwd malloc");
abort();
}
@@ -1460,11 +1500,7 @@ struct sockaddr_in *who;
}
static void
-server_forw_reliable(server, pack, packlen, notice)
-ZServerDesc_t *server;
-caddr_t pack;
-int packlen;
-ZNotice_t *notice;
+server_forw_reliable(ZServerDesc_t *server, caddr_t pack, int packlen, ZNotice_t *notice)
{
Code_t retval;
register ZNotAcked_t *nacked;
@@ -1512,8 +1548,7 @@ ZNotice_t *notice;
*/
void
-server_send_queue(server)
-ZServerDesc_t *server;
+server_send_queue(ZServerDesc_t *server)
{
register ZSrvPending_t *pending;
ZNotice_t notice;
@@ -1536,7 +1571,7 @@ ZServerDesc_t *server;
}
}
}
-#endif CONCURRENT
+#endif
/*
* a server has acknowledged a message we sent to him; remove it from
@@ -1544,9 +1579,7 @@ ZServerDesc_t *server;
*/
static void
-srv_nack_cancel(notice, who)
-register ZNotice_t *notice;
-struct sockaddr_in *who;
+srv_nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
{
register ZServerDesc_t *which = server_which_server(who);
register ZNotAcked_t *nacked;
@@ -1566,7 +1599,9 @@ struct sockaddr_in *who;
xfree(nacked);
return;
}
+#if 0
zdbug((LOG_DEBUG, "srv_nack not found"));
+#endif
return;
}
@@ -1575,18 +1610,21 @@ struct sockaddr_in *who;
*/
static void
-srv_rexmit(nackpacket)
-register ZNotAcked_t *nackpacket;
+srv_rexmit(void *arg)
{
+ ZNotAcked_t *nackpacket = (ZNotAcked_t *) arg;
Code_t retval;
/* retransmit the packet */
+#if 0
zdbug((LOG_DEBUG,"srv_rexmit to %s/%d",
inet_ntoa(otherservers[nackpacket->na_srv_idx].zs_addr.sin_addr),
ntohs(otherservers[nackpacket->na_srv_idx].zs_addr.sin_port)));
-
+#endif
if (otherservers[nackpacket->na_srv_idx].zs_state == SERV_DEAD) {
+#if 0
zdbug((LOG_DEBUG, "canceling send to dead server"));
+#endif
xremque(nackpacket);
xfree(nackpacket->na_packet);
srv_nack_release(&otherservers[nackpacket->na_srv_idx]);
@@ -1618,8 +1656,7 @@ requeue:
*/
static void
-srv_nack_release(server)
-ZServerDesc_t *server;
+srv_nack_release(ZServerDesc_t *server)
{
/* XXX release any private queue for this server */
@@ -1645,37 +1682,36 @@ ZServerDesc_t *server;
}
/*
- * Clean up the not-yet-acked queue and release anything destined
- * to the server.
+ * Adjust indices of not-yet-acked packets sent to other servers to
+ * continue to refer to the correct server.
*/
static void
-srv_nack_move(from, to)
-register int from, to;
+srv_nack_renumber (register int* new_idx)
{
- /* XXX release any private queue for this server */
-
- register ZNotAcked_t *nacked;
-
- /* search the not-yet-acked list for anything destined to 'from', and
- change the index to 'to'. */
- for (nacked = nacklist->q_forw;
- nacked != nacklist;)
- if (nacked->na_srv_idx == from)
- nacked->na_srv_idx = to;
- return;
+ /* XXX release any private queue for this server */
+
+ register ZNotAcked_t *nacked;
+
+ /* search the not-yet-acked list for anything destined to 'from', and
+ change the index to 'to'. */
+ for (nacked = nacklist->q_forw; nacked != nacklist;) {
+ int idx = new_idx[nacked->na_srv_idx];
+ if (idx < 0) {
+ syslog (LOG_ERR,
+ "srv_nack_renumber error: [%d]=%d",
+ nacked->na_srv_idx, idx);
+ idx = 0;
+ }
+ nacked->na_srv_idx = idx;
+ }
}
/*
* Queue this notice to be transmitted to the server when it is ready.
*/
static void
-server_queue(server, len, pack, auth, who)
-ZServerDesc_t *server;
-int len;
-caddr_t pack;
-int auth;
-struct sockaddr_in *who;
+server_queue(ZServerDesc_t *server, int len, caddr_t pack, int auth, struct sockaddr_in *who)
{
register ZSrvPending_t *pending;
@@ -1707,8 +1743,7 @@ struct sockaddr_in *who;
*/
ZSrvPending_t *
-server_dequeue(server)
-register ZServerDesc_t *server;
+server_dequeue(register ZServerDesc_t *server)
{
ZSrvPending_t *pending;
@@ -1730,8 +1765,7 @@ register ZServerDesc_t *server;
*/
void
-server_pending_free(pending)
-register ZSrvPending_t *pending;
+server_pending_free(register ZSrvPending_t *pending)
{
xfree(pending->pend_packet);
xfree(pending);
@@ -1744,10 +1778,7 @@ register ZSrvPending_t *pending;
*/
void
-server_self_queue(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+server_self_queue(ZNotice_t* notice, int auth, sockaddr_in * who)
{
caddr_t pack;
int packlen;
@@ -1762,7 +1793,7 @@ struct sockaddr_in *who;
server_queue(me_server, packlen, pack, auth, who);
return;
}
-#endif CONCURRENT
+#endif
/*
* dump info about servers onto the fp.
@@ -1770,8 +1801,7 @@ struct sockaddr_in *who;
* (true if called from signal handler)
*/
void
-server_dump_servers(fp)
-FILE *fp;
+server_dump_servers(FILE *fp)
{
register int i;
diff --git a/server/subscr.c b/server/subscr.c
index fe071bb..1fb8515 100644
--- a/server/subscr.c
+++ b/server/subscr.c
@@ -62,39 +62,43 @@ static char rcsid_subscr_c[] = "$Id$";
#include "zserver.h"
#include <ctype.h>
+#include <strings.h>
#include <sys/stat.h>
/* for compatibility when sending subscription information to old clients */
#ifdef OLD_COMPAT
#define OLD_ZEPHYR_VERSION "ZEPH0.0"
#define OLD_CLIENT_INCOMPSUBS "INCOMP"
-static void old_compat_subscr_sendlist();
+static void old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who);
extern int old_compat_count_subscr; /* counter of old use */
#endif /* OLD_COMPAT */
#ifdef NEW_COMPAT
#define NEW_OLD_ZEPHYR_VERSION "ZEPH0.1"
-static void new_old_compat_subscr_sendlist();
+static void new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who);
extern int new_compat_count_subscr; /* counter of old use */
#endif /* NEW_COMPAT */
-extern char *re_comp(), *re_conv(), *rindex(), *index();
-static ZSubscr_t *extract_subscriptions();
-static int subscr_equiv(), clt_unique();
-static void free_subscriptions(), free_sub();
-static char **subscr_marshal_subs();
-static Code_t subscr_subscribe_real();
-static ZSubscr_t *subscr_copy_def_subs();
+extern char *re_comp(), *re_conv();
+static ZSubscr_t *extract_subscriptions(register ZNotice_t *notice);
+static int clt_unique(ZClient_t *clt, ZClientList_t *clist);
+static void free_subscriptions(register ZSubscr_t *subs);
+static const char **subscr_marshal_subs(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who,
+ register int *found);
+static Code_t subscr_subscribe_real(ZClient_t *who, ZSubscr_t *newsubs,
+ ZNotice_t *notice);
+static ZSubscr_t *subscr_copy_def_subs(const ZString&);
+static int cl_match (ZNotice_t*, ZClient_t *);
static int defaults_read = 0; /* set to 1 if the default subs
are in memory */
static ZNotice_t default_notice; /* contains default subscriptions */
-static ZSubscr_t matchall_sub = {
- (ZSubscr_t *) 0,
- (ZSubscr_t *) 0,
- MATCHALL_CLASS,
- "",
- "" };
+extern const ZString wildcard_class (MATCHALL_CLASS, 1);
+extern const ZString wildcard_instance (WILDCARD_INSTANCE, 1);
+
+static ZString empty ("");
+static ZSubscr_t matchall_sub (wildcard_class, empty, empty);
/* WARNING: make sure this is the same as the number of strings you */
/* plan to hand back to the user in response to a subscription check, */
@@ -106,18 +110,16 @@ static ZSubscr_t matchall_sub = {
*/
Code_t
-subscr_subscribe(who, notice)
-ZClient_t *who;
-ZNotice_t *notice;
+subscr_subscribe(ZClient_t *who, ZNotice_t *notice)
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t))))
+ subs = new ZSubscr_t;
+ if (!subs)
return(ENOMEM);
- subs->q_forw = subs->q_back = subs;
who->zct_subs = subs;
}
@@ -128,15 +130,12 @@ ZNotice_t *notice;
}
static Code_t
-subscr_subscribe_real(who, newsubs, notice)
-ZClient_t *who;
-register ZSubscr_t *newsubs;
-ZNotice_t *notice;
+subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *notice)
{
- int relation;
int omask;
Code_t retval;
ZAcl_t *acl;
+ ZString sender (notice->z_sender);
register ZSubscr_t *subs2, *subs3, *subs;
omask = sigblock(sigmask(SIGFPE)); /* don't let db dumps start */
@@ -145,43 +144,54 @@ ZNotice_t *notice;
subs = subs->q_forw) {
/* for each new subscription */
- if (!bdumping && *(subs->zst_recipient) &&
- strcmp(subs->zst_recipient, notice->z_sender)) {
+#if 1
+ zdbug ((LOG_DEBUG, "subscr: %s/%s/%s",
+ subs->zst_dest.classname.value (),
+ subs->zst_dest.inst.value (),
+ subs->zst_dest.recip.value ()));
+#endif
+
+ if (!bdumping
+ && *(subs->zst_dest.recip.value ())
+ && subs->zst_dest.recip != sender) {
syslog(LOG_WARNING, "subscr unauth to rcpt %s by %s",
- subs->zst_recipient,
- notice->z_sender);
+ subs->zst_dest.recip.value (),
+ sender.value ());
continue;
}
- acl = class_get_acl(subs->zst_class);
- if (acl && !bdumping) {
- if (!access_check(notice, acl, SUBSCRIBE)) {
+ if (!bdumping) {
+ acl = class_get_acl(subs->zst_dest.classname);
+ if (acl) {
+ if (!acl->ok (sender, SUBSCRIBE)) {
syslog(LOG_WARNING, "subscr unauth %s %s",
- notice->z_sender, subs->zst_class);
+ sender.value (),
+ subs->zst_dest.classname.value ());
continue; /* the for loop */
}
- if (!strcmp(WILDCARD_INSTANCE, subs->zst_classinst)) {
- if (!access_check(notice, acl, INSTWILD)) {
- syslog(LOG_WARNING,
- "subscr unauth wild %s %s.*",
- notice->z_sender,
- subs->zst_class);
- continue;
- }
+ if (wildcard_instance == subs->zst_dest.inst) {
+ if (!acl->ok (sender, INSTWILD)) {
+ syslog(LOG_WARNING,
+ "subscr unauth wild %s %s.*",
+ notice->z_sender,
+ subs->zst_dest.classname.value ());
+ continue;
+ }
}
+ }
}
for (subs2 = who->zct_subs->q_forw;
subs2 != who->zct_subs;
subs2 = subs2->q_forw) {
/* for each existing subscription */
- relation = strcasecmp(subs->zst_class, subs2->zst_class);
- if (relation > 0) /* we have passed the last
- possible one */
+ if (*subs >= *subs2)
break;
- if (relation < 0) /* nope... */
- continue;
- if (subscr_equiv(subs, subs2)) /* duplicate? */
- goto duplicate;
}
+ /*
+ * Can't put a goto in place of the break above,
+ * because cfront can't cope.
+ */
+ if (subs2 != who->zct_subs && *subs == *subs2)
+ continue;
/* subs2 now points to the first class which is greater
than the new class. We need to back up so that the
insertion below goes BEFORE this one (i.e. after the
@@ -190,29 +200,22 @@ ZNotice_t *notice;
/* ok, we are a new subscription. register and chain on. */
- if (!(subs3 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs3 = new ZSubscr_t (*subs);
+ if (!subs3) {
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(ENOMEM);
}
if ((retval = class_register(who, subs)) != ZERR_NONE) {
- xfree(subs3);
+ delete subs3;
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(retval);
}
- subs3->zst_class = strsave(subs->zst_class);
- subs3->zst_classinst = strsave(subs->zst_classinst);
- subs3->zst_recipient = strsave(subs->zst_recipient);
-
- subs3->q_forw = subs3->q_back = subs3;
-
/* subs2 was adjusted above */
xinsque(subs3, subs2);
-
-duplicate: ; /* just go on to the next */
}
(void) sigsetmask(omask);
@@ -225,18 +228,17 @@ duplicate: ; /* just go on to the next */
*/
Code_t
-subscr_def_subs(who)
-ZClient_t *who;
+subscr_def_subs(ZClient_t *who)
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs = new ZSubscr_t;
+ if (!subs) {
syslog(LOG_ERR, "no mem subscr_def_subs");
return(ENOMEM);
}
- subs->q_forw = subs->q_back = subs;
who->zct_subs = subs;
}
@@ -245,16 +247,18 @@ ZClient_t *who;
}
void
-subscr_reset()
+subscr_reset(void)
{
+#if 0
zdbug((LOG_DEBUG, "subscr_reset()"));
+#endif
xfree(default_notice.z_message);
+ default_notice.z_message = 0;
defaults_read = 0;
}
static ZSubscr_t *
-subscr_copy_def_subs(person)
-char *person;
+subscr_copy_def_subs(const ZString& person)
{
int retval;
int fd;
@@ -265,7 +269,9 @@ char *person;
register ZSubscr_t *subs2;
if (!defaults_read) {
+#if 1
zdbug((LOG_DEBUG, "reading default subscription file"));
+#endif
fd = open(DEFAULT_SUBS_FILE, O_RDONLY, 0666);
if (fd < 0) {
syslog(LOG_ERR, "can't open %s:%m", DEFAULT_SUBS_FILE);
@@ -278,7 +284,7 @@ char *person;
(void) close(fd);
return((ZSubscr_t *)0);
}
- if (!(def_sub_area = xmalloc(statbuf.st_size + 1))) {
+ if (!(def_sub_area = (char *) xmalloc(statbuf.st_size + 1))) {
syslog(LOG_ERR, "no mem copy_def_subs");
(void) close(fd);
return((ZSubscr_t *)0);
@@ -319,21 +325,21 @@ char *person;
if ((*cp == '\n') || (*cp == ','))
*cp = '\0';
default_notice.z_message = def_sub_area;
- default_notice.z_message_len = statbuf.st_size + 1;
+ default_notice.z_message_len = (int) statbuf.st_size + 1;
default_notice.z_auth = 1;
defaults_read = 1;
}
/* needed later for access_check() */
- default_notice.z_sender = person;
+ default_notice.z_sender = (char *) person.value ();
subs = extract_subscriptions(&default_notice);
/* replace any non-* recipients with "person" */
for (subs2 = subs->q_forw; subs2 != subs; subs2 = subs2->q_forw)
/* if not a wildcard, replace it with person */
- if (strcmp(subs2->zst_recipient, "*")) {
- subs2->zst_recipient = person;
+ if (strcmp(subs2->zst_dest.recip.value (), "*")) {
+ subs2->zst_dest.recip = person;
} else { /* replace with null recipient */
- subs2->zst_recipient = "";
+ subs2->zst_dest.recip = empty;
}
return(subs);
}
@@ -343,17 +349,17 @@ char *person;
*/
Code_t
-subscr_cancel(sin, notice)
-struct sockaddr_in *sin;
-ZNotice_t *notice;
+subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice)
{
ZClient_t *who;
register ZSubscr_t *subs, *subs2, *subs3, *subs4;
Code_t retval;
- int found = 0, relation;
+ int found = 0;
int omask;
+#if 0
zdbug((LOG_DEBUG,"subscr_cancel"));
+#endif
if (!(who = client_which_client(sin, notice)))
return(ZSRV_NOCLT);
@@ -372,35 +378,33 @@ ZNotice_t *notice;
subs2 != who->zct_subs;) {
/* for each existing subscription */
/* is this what we are canceling? */
- relation = strcasecmp(subs4->zst_class, subs2->zst_class);
- if (relation > 0) /* we have passed the last
- possible one */
- break;
- if (relation < 0) { /* nope... */
- subs2 = subs2->q_forw;
- continue;
+ if (subs4->zst_dest.classname != subs2->zst_dest.classname) {
+ subs2 = subs2->q_forw;
+ continue;
}
- if (subscr_equiv(subs4, subs2)) {
- /* go back, since remque will change things */
- subs3 = subs2->q_back;
- xremque(subs2);
- (void) class_deregister(who, subs2);
- free_sub(subs2);
- found = 1;
- /* now that the remque adjusted the linked
- list, we go forward again */
- subs2 = subs3->q_forw;
+ if (*subs4 == *subs2) {
+ /* go back, since remque will change things */
+ subs3 = subs2->q_back;
+ xremque(subs2);
+ (void) class_deregister(who, subs2);
+ delete subs2;
+ found = 1;
+ /* now that the remque adjusted the linked
+ list, we go forward again */
+ subs2 = subs3->q_forw;
+ } else if (*subs4 >= *subs2) {
+ break;
} else {
- zdbug((LOG_DEBUG, "not %s.%s.%s",
- subs2->zst_class,
- subs2->zst_classinst,
- subs2->zst_recipient));
- subs2 = subs2->q_forw;
-
+#if 0
+ zdbug((LOG_DEBUG, "not %s.%s.%s",
+ subs2->zst_dest.classname.value(),
+ subs2->zst_dest.inst.value(),
+ subs2->zst_dest.recip.value()));
+#endif
+ subs2 = subs2->q_forw;
}
}
- /* make sure we are still registered for all the
- classes */
+ /* make sure we are still registered for all the classes */
if (found)
for (subs2 = who->zct_subs->q_forw;
subs2 != who->zct_subs;
@@ -413,10 +417,14 @@ ZNotice_t *notice;
(void) sigsetmask(omask);
free_subscriptions(subs);
if (found) {
+#if 0
zdbug((LOG_DEBUG, "found & removed"));
+#endif
return(ZERR_NONE);
} else {
+#if 0
zdbug((LOG_DEBUG, "not found"));
+#endif
return(ZSRV_NOSUB);
}
}
@@ -426,13 +434,14 @@ ZNotice_t *notice;
*/
void
-subscr_cancel_client(client)
-register ZClient_t *client;
+subscr_cancel_client(register ZClient_t *client)
{
register ZSubscr_t *subs;
int omask;
+#if 1
zdbug((LOG_DEBUG,"subscr_cancel_client"));
+#endif
if (!client->zct_subs)
return;
@@ -440,18 +449,23 @@ register ZClient_t *client;
for (subs = client->zct_subs->q_forw;
subs != client->zct_subs;
subs = client->zct_subs->q_forw) {
- zdbug((LOG_DEBUG,"sub_can %s",subs->zst_class));
+#if 1
+ zdbug((LOG_DEBUG,"sub_can %s",
+ subs->zst_dest.classname.value()));
+#endif
if (class_deregister(client, subs) != ZERR_NONE) {
+#if 1
zdbug((LOG_DEBUG,"sub_can_clt: not registered!"));
+#endif
}
xremque(subs);
- free_sub(subs);
+ delete subs;
}
/* also flush the head of the queue */
/* subs is now client->zct_subs */
- xfree(subs);
+ delete subs;
client->zct_subs = NULLZST;
(void) sigsetmask(omask);
@@ -484,7 +498,7 @@ struct in_addr *addr;
(void) sigsetmask(omask);
return(ZERR_NONE);
}
-#endif notdef
+#endif
/*
* Here is the bulk of the work in the subscription manager.
@@ -494,55 +508,35 @@ struct in_addr *addr;
*/
ZClientList_t *
-subscr_match_list(notice)
-ZNotice_t *notice;
+subscr_match_list(ZNotice_t *notice)
{
register ZClientList_t *hits, *clients, *majik, *clients2, *hit2;
- register char *cp;
- char *newclass, *saveclass, *newclinst, *saveclinst;
- ZSubscr_t check_sub;
+ char *saveclass, *saveclinst;
+ ZString newclass, newclinst;
+ /* Use this where we can't use "goto" thanks to cfront... */
+ int get_out = 0;
if (!(hits = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
return(NULLZCLT);
hits->q_forw = hits->q_back = hits;
-
+
saveclass = notice->z_class;
- cp = newclass = strsave(notice->z_class);
+ newclass = ZString (notice->z_class, 1);
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
saveclinst = notice->z_class_inst;
- cp = newclinst = strsave(notice->z_class_inst);
-
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
+ newclinst = ZString (saveclinst, 1);
- check_sub.zst_class = newclass;
- check_sub.zst_classinst = newclinst;
- check_sub.zst_recipient = notice->z_recipient;
+ ZSubscr_t check_sub (newclass, newclinst, notice->z_recipient);
check_sub.q_forw = check_sub.q_back = &check_sub;
- if (!(clients = class_lookup(&check_sub))) {
- if (!(majik = class_lookup(&matchall_sub))) {
- notice->z_class = saveclass;
- notice->z_class_inst = saveclinst;
- xfree(newclass);
- xfree(newclinst);
- xfree(hits);
- return(NULLZCLT);
- }
- } else
- majik = class_lookup(&matchall_sub);
+ clients = class_lookup (&check_sub);
+ majik = class_lookup (&matchall_sub);
+ if (!clients && !majik)
+ return NULLZCLT;
- notice->z_class = newclass;
- notice->z_class_inst = newclinst;
+ notice->z_class = (char *) newclass.value ();
+ notice->z_class_inst = (char *) newclinst.value ();
if (clients) {
for (clients2 = clients->q_forw;
clients2 != clients;
@@ -554,19 +548,17 @@ ZNotice_t *notice;
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match: punting/no mem");
- notice->z_class = saveclass;
- xfree(newclass);
- notice->z_class_inst = saveclinst;
- xfree(newclinst);
- return(hits);
+ get_out = 1;
+ break;
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- class_free(clients);
+ if (!get_out)
+ class_free(clients);
}
- if (majik) {
+ if (!get_out && majik) {
for (clients2 = majik->q_forw;
clients2 != majik;
clients2 = clients2->q_forw) {
@@ -576,23 +568,20 @@ ZNotice_t *notice;
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match(majik): punting/no mem");
- notice->z_class = saveclass;
- xfree(newclass);
- notice->z_class_inst = saveclinst;
- xfree(newclinst);
- return(hits);
+ get_out = 1;
+ break;
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- class_free(majik);
+ if (!get_out)
+ class_free(majik);
}
+/* out:*/
notice->z_class = saveclass;
- xfree(newclass);
notice->z_class_inst = saveclinst;
- xfree(newclinst);
if (hits->q_forw == hits) {
xfree(hits);
return(NULLZCLT);
@@ -605,8 +594,7 @@ ZNotice_t *notice;
*/
void
-subscr_free_list(list)
-ZClientList_t *list;
+subscr_free_list(ZClientList_t *list)
{
register ZClientList_t *lyst;
@@ -623,12 +611,9 @@ ZClientList_t *list;
*/
void
-subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
- char **answer;
+ const char **answer;
int found;
struct sockaddr_in send_to_who;
Code_t retval;
@@ -668,8 +653,8 @@ struct sockaddr_in *who;
/* use xmit_frag() to send each piece of the notice */
- if ((retval = ZSrvSendRawList(notice, answer, found*NUM_FIELDS,
- xmit_frag))
+ if ((retval = ZSrvSendRawList(notice, (char **) answer,
+ found*NUM_FIELDS, xmit_frag))
!= ZERR_NONE) {
syslog(LOG_WARNING, "subscr_sendlist xmit: %s",
error_message(retval));
@@ -679,15 +664,11 @@ struct sockaddr_in *who;
return;
}
-static char **
-subscr_marshal_subs(notice, auth, who, found)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-register int *found;
+static const char **
+subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, register int *found)
{
ZNotice_t reply;
- char **answer = (char **) NULL;
+ const char **answer = (const char **) NULL;
int temp;
Code_t retval;
ZClient_t *client;
@@ -695,7 +676,9 @@ register int *found;
register int i;
int defsubs = 0;
+#if 0
zdbug((LOG_DEBUG, "subscr_marshal"));
+#endif
*found = 0;
/* Note that the following code is an incredible crock! */
@@ -732,7 +715,9 @@ register int *found;
if (client)
subs2 = client->zct_subs;
} else if (!strcmp(notice->z_opcode, CLIENT_GIMMEDEFS)) {
+#if 0
zdbug((LOG_DEBUG, "gimmedefs"));
+#endif
/* subscr_copy_def_subs allocates new pointer rings, so
it must be freed when finished.
the string areas pointed to are static, however.*/
@@ -772,9 +757,9 @@ register int *found;
for (i = 0, subs = subs2->q_forw;
i < *found ;
i++, subs = subs->q_forw) {
- answer[i*NUM_FIELDS] = subs->zst_class;
- answer[i*NUM_FIELDS + 1] = subs->zst_classinst;
- answer[i*NUM_FIELDS + 2] = subs->zst_recipient;
+ answer[i*NUM_FIELDS] = subs->zst_dest.classname.value ();
+ answer[i*NUM_FIELDS + 1] = subs->zst_dest.inst.value ();
+ answer[i*NUM_FIELDS + 2] = subs->zst_dest.recip.value ();
}
}
if (defsubs)
@@ -784,17 +769,14 @@ register int *found;
#ifdef NEW_COMPAT
static void
-new_old_compat_subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
Code_t retval;
ZNotice_t reply;
ZPacket_t reppacket;
int packlen, found, count, initfound, zerofound;
char buf[64];
- char **answer;
+ const char **answer;
struct sockaddr_in send_to_who;
register int i;
@@ -825,8 +807,10 @@ struct sockaddr_in *who;
/* send 5 at a time until we are finished */
count = found?((found-1) / 5 + 1):1; /* total # to be sent */
i = 0; /* pkt # counter */
+#if 0
zdbug((LOG_DEBUG,"Found %d subscriptions for %d packets",
found,count));
+#endif
initfound = found;
zerofound = (found == 0);
while (found > 0 || zerofound) {
@@ -855,7 +839,9 @@ struct sockaddr_in *who;
found -= 5;
zerofound = 0;
}
+#if 0
zdbug((LOG_DEBUG,"subscr_sendlist acked"));
+#endif
if (answer)
xfree(answer);
return;
@@ -864,10 +850,7 @@ struct sockaddr_in *who;
#ifdef OLD_COMPAT
static void
-old_compat_subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
ZClient_t *client = client_which_client(who, notice);
register ZSubscr_t *subs;
@@ -951,7 +934,9 @@ struct sockaddr_in *who;
xfree(answer);
return;
}
+#if 0
zdbug((LOG_DEBUG,"subscr_sendlist acked"));
+#endif
if (answer)
xfree(answer);
return;
@@ -967,20 +952,21 @@ struct sockaddr_in *who;
/*ARGSUSED*/
Code_t
-subscr_send_subs(client, vers)
-ZClient_t *client;
-char *vers;
+subscr_send_subs(ZClient_t *client, char *vers)
{
register int i = 0;
register ZSubscr_t *sub;
#ifdef KERBEROS
char buf[512];
#endif /* KERBEROS */
- char buf2[512], *lyst[7 * NUM_FIELDS];
+ char buf2[512];
+ const char *lyst[7 * NUM_FIELDS];
int num = 0;
Code_t retval;
+#if 0
zdbug((LOG_DEBUG, "send_subs"));
+#endif
(void) sprintf(buf2, "%d",ntohs(client->zct_sin.sin_port));
lyst[num++] = buf2;
@@ -988,17 +974,22 @@ char *vers;
#ifdef KERBEROS
if ((retval = ZMakeAscii(buf, sizeof(buf), client->zct_cblock,
sizeof(C_Block))) != ZERR_NONE) {
+#if 0
zdbug((LOG_DEBUG,"zmakeascii failed: %s",
error_message(retval)));
+#endif
} else {
lyst[num++] = buf;
+#if 0
zdbug((LOG_DEBUG,"cblock %s",buf));
+#endif
}
#endif KERBEROS
if ((retval = bdump_send_list_tcp(SERVACK, client->zct_sin.sin_port,
ZEPHYR_ADMIN_CLASS,
num > 1 ? "CBLOCK" : "",
- ADMIN_NEWCLT, client->zct_principal,
+ ADMIN_NEWCLT,
+ (char*)client->zct_principal.value(),
"", lyst, num)) != ZERR_NONE ) {
syslog(LOG_ERR, "subscr_send_subs newclt: %s",
error_message(retval));
@@ -1011,9 +1002,9 @@ char *vers;
sub != client->zct_subs;
sub = sub->q_forw) {
/* for each subscription */
- lyst[i * NUM_FIELDS] = sub->zst_class;
- lyst[i * NUM_FIELDS + 1] = sub->zst_classinst;
- lyst[i * NUM_FIELDS + 2] = sub->zst_recipient;
+ lyst[i * NUM_FIELDS] = sub->zst_dest.classname.value ();
+ lyst[i * NUM_FIELDS + 1] = sub->zst_dest.inst.value ();
+ lyst[i * NUM_FIELDS + 2] = sub->zst_dest.recip.value ();
i++;
if (i >= 7) {
/* we only put 7 in each packet, so we don't
@@ -1052,9 +1043,7 @@ char *vers;
*/
static int
-clt_unique(clt, clist)
-ZClient_t *clt;
-ZClientList_t *clist;
+clt_unique(ZClient_t *clt, ZClientList_t *clist)
{
register ZClientList_t *client;
@@ -1071,12 +1060,9 @@ ZClientList_t *clist;
*/
static int
-cl_match(notice, client)
-register ZNotice_t *notice;
-register ZClient_t *client;
+cl_match(register ZNotice_t *notice, register ZClient_t *client)
{
register ZSubscr_t *subs;
- int relation;
if (client->zct_subs == NULLZST) {
syslog(LOG_WARNING, "cl_match w/ no subs");
@@ -1087,15 +1073,20 @@ register ZClient_t *client;
subs != client->zct_subs;
subs = subs->q_forw) {
/* for each subscription, do matching */
- relation = strcasecmp(notice->z_class, subs->zst_class);
+#if 0
+ int relation;
+ relation = strcasecmp(notice->z_class,
+ subs->zst_class.value ());
if (relation > 0) /* past the last possible one */
return(0);
if (relation < 0)
continue; /* no match */
- if (strcmp(subs->zst_classinst, WILDCARD_INSTANCE) &&
- strcasecmp(subs->zst_classinst, notice->z_class_inst))
- continue;
- if (strcmp(notice->z_recipient, subs->zst_recipient))
+#endif
+ if (subs->zst_dest.inst != wildcard_instance
+ && strcasecmp(subs->zst_dest.inst.value (),
+ notice->z_class_inst))
+ continue;
+ if (strcmp(notice->z_recipient, subs->zst_dest.recip.value ()))
continue;
return(1);
}
@@ -1104,53 +1095,22 @@ register ZClient_t *client;
}
/*
- * Free up a subscription
- */
-
-static void
-free_sub(sub)
-ZSubscr_t *sub;
-{
- xfree(sub->zst_class);
- xfree(sub->zst_classinst);
- xfree(sub->zst_recipient);
- xfree(sub);
- return;
-}
-
-/*
* free the memory allocated for the list of subscriptions.
*/
static void
-free_subscriptions(subs)
-register ZSubscr_t *subs;
+free_subscriptions(register ZSubscr_t *subs)
{
register ZSubscr_t *sub;
for (sub = subs->q_forw; sub != subs; sub = subs->q_forw) {
xremque(sub);
- xfree(sub);
+ delete sub;
}
- xfree(subs);
+ delete subs;
return;
}
-/*
- * are the subscriptions the same? 1=yes, 0=no
- */
-
-static int
-subscr_equiv(s1, s2)
-register ZSubscr_t *s1, *s2;
-{
- if (strcasecmp(s1->zst_classinst,s2->zst_classinst))
- return(0);
- if (strcmp(s1->zst_recipient,s2->zst_recipient))
- return(0);
- return(1);
-}
-
#define ADVANCE(xx) { cp += (strlen(cp) + 1); \
if (cp >= notice->z_message + notice->z_message_len) { \
syslog(LOG_WARNING, "malformed subscription %d", xx); \
@@ -1163,60 +1123,45 @@ register ZSubscr_t *s1, *s2;
*/
static ZSubscr_t *
-extract_subscriptions(notice)
-register ZNotice_t *notice;
+extract_subscriptions(register ZNotice_t *notice)
{
register ZSubscr_t *subs = NULLZST, *subs2;
- register char *recip, *class, *classinst;
+ register char *recip, *class_name, *classinst;
register char *cp = notice->z_message;
/* parse the data area for the subscriptions */
while (cp < notice->z_message + notice->z_message_len) {
- class = cp;
+ class_name = cp;
if (*cp == '\0')
/* we've exhausted the subscriptions */
return(subs);
- /* we lowercase the class and class instance
- so we can be case insensitive on comparisons */
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
- cp = class;
ADVANCE(1);
classinst = cp;
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
- cp = classinst;
ADVANCE(2);
recip = cp;
- zdbug((LOG_DEBUG,"CLS: %s INST: %s RCPT: %s",
- class, classinst, cp));
+#if 0
+ zdbug((LOG_DEBUG, "ext_sub: CLS %s INST %s RCPT %s",
+ class_name, classinst, cp));
+#endif
cp += (strlen(cp) + 1);
if (cp > notice->z_message + notice->z_message_len) {
syslog(LOG_WARNING, "malformed sub 3");
return(subs);
}
if (!subs) {
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs = new ZSubscr_t;
+ if (!subs) {
syslog(LOG_WARNING, "ex_subs: no mem");
return(NULLZST);
}
- subs->q_forw = subs->q_back = subs;
- subs->zst_class = subs->zst_classinst = subs->zst_recipient = NULL;
}
- if (!(subs2 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs2 = new ZSubscr_t (ZString (class_name, 1),
+ ZString (classinst, 1),
+ ZString (recip));
+ if (!subs2) {
syslog(LOG_WARNING, "ex_subs: no mem 2");
return(subs);
}
- subs2->zst_class = class;
- subs2->zst_classinst = classinst;
- subs2->zst_recipient = recip;
- subs2->q_forw = subs2->q_back = subs2;
xinsque(subs2, subs);
}
@@ -1230,9 +1175,7 @@ register ZNotice_t *notice;
*/
void
-subscr_dump_subs(fp, subs)
-FILE *fp;
-ZSubscr_t *subs;
+subscr_dump_subs(FILE *fp, ZSubscr_t *subs)
{
register ZSubscr_t *ptr;
@@ -1241,11 +1184,11 @@ ZSubscr_t *subs;
for (ptr = subs->q_forw; ptr != subs; ptr = ptr->q_forw) {
fputs("\t\t'", fp);
- fputs(ptr->zst_class, fp);
+ fputs(ptr->zst_dest.classname.value (), fp);
fputs("' '", fp);
- fputs(ptr->zst_classinst, fp);
+ fputs(ptr->zst_dest.inst.value (), fp);
fputs("' '", fp);
- fputs(ptr->zst_recipient, fp);
+ fputs(ptr->zst_dest.recip.value (), fp);
fputs("'\n", fp);
}
return;
diff --git a/server/timer.c b/server/timer.c
index 338f79b..0f152e2 100644
--- a/server/timer.c
+++ b/server/timer.c
@@ -9,11 +9,8 @@
*
*/
-#ifndef lint
-#ifndef SABER
-static char rcsid_timer_c[] = "$Header$";
-#endif SABER
-#endif lint
+static char rcsid[] =
+ "$Header$";
/*
* timer_manager_ -- routines for handling timers in login_shell
@@ -68,8 +65,7 @@ long nexttimo = 0L; /* the Unix time of the next
static timer timers = NULL;
static long right_now;
-char *calloc(), *malloc(), *realloc();
-static void timer_botch(), insert_timer(), add_timer();
+static void timer_botch(void*), insert_timer(timer), add_timer(timer);
/*
* timer_set_rel(time_rel, proc)
@@ -79,11 +75,7 @@ static void timer_botch(), insert_timer(), add_timer();
* creates a "timer" and adds it to the current list, returns "timer"
*/
-timer timer_set_rel (time_rel, proc, arg)
- long time_rel;
- void (*proc)();
- caddr_t arg;
-{
+timer timer_set_rel (long time_rel, void (*proc)(void*), void *arg) {
timer new_t;
right_now = NOW;
new_t = (timer) xmalloc(TIMER_SIZE);
@@ -94,7 +86,7 @@ timer timer_set_rel (time_rel, proc, arg)
ALARM_PREV(new_t) = NULL;
ALARM_ARG(new_t) = arg;
add_timer(new_t);
- return(new_t);
+ return new_t;
}
#ifdef notdef
@@ -124,7 +116,7 @@ timer timer_set_abs (time_abs, proc, arg)
ALARM_PREV(new_t) = NULL;
ALARM_ARG(new_t) = arg;
add_timer(new_t);
- return(new_t);
+ return new_t;
}
#endif notdef
@@ -139,15 +131,13 @@ timer timer_set_abs (time_abs, proc, arg)
*/
void
-timer_reset(tmr)
- timer tmr;
-{
+timer_reset(timer tmr) {
if (!ALARM_PREV(tmr) || !ALARM_NEXT(tmr)) {
- zdbug((LOG_DEBUG,"timer_reset() of unscheduled timer\n"));
+ syslog (LOG_ERR, "timer_reset() of unscheduled timer\n");
abort();
}
if (tmr == timers) {
- zdbug((LOG_DEBUG,"timer_reset of timer head\n"));
+ syslog (LOG_ERR,"timer_reset of timer head\n");
abort();
}
xremque(tmr);
@@ -155,11 +145,10 @@ timer_reset(tmr)
ALARM_NEXT(tmr) = NULL;
xfree(tmr);
if (timers == NULL) {
- zdbug((LOG_DEBUG,"reset with no timers\n"));
+ syslog (LOG_ERR,"reset with no timers\n");
abort();
}
nexttimo = ALARM_TIME(ALARM_NEXT(timers));
- return;
}
@@ -176,15 +165,12 @@ timer_reset(tmr)
*
*/
static void
-add_timer(new_t)
- timer new_t;
-{
+add_timer(timer new_t) {
if (ALARM_PREV(new_t) || ALARM_NEXT(new_t)) {
- zdbug((LOG_DEBUG,"add_timer of enqueued timer\n"));
+ syslog (LOG_ERR,"add_timer of enqueued timer\n");
abort();
}
insert_timer(new_t);
- return;
}
/*
@@ -195,9 +181,7 @@ add_timer(new_t)
*/
static void
-insert_timer(new_t)
- timer new_t;
-{
+insert_timer(timer new_t) {
register timer t;
if (timers == NULL) {
@@ -216,7 +200,6 @@ insert_timer(new_t)
}
xinsque(new_t, ALARM_PREV(timers));
nexttimo = ALARM_TIME(ALARM_NEXT(timers));
- return;
}
/*
@@ -226,11 +209,10 @@ insert_timer(new_t)
*/
void
-timer_process()
-{
- register struct _timer *t;
- void (*queue)();
- caddr_t queue_arg;
+timer_process(void) {
+ register timer t;
+ timer_proc queue;
+ void * queue_arg;
int valid = 0;
right_now = NOW;
@@ -258,12 +240,10 @@ timer_process()
if (valid) {
(queue)(queue_arg);
}
- return;
}
static void
-timer_botch()
-{
+timer_botch(void *arg) {
syslog(LOG_CRIT, "Timer botch\n");
abort();
}
diff --git a/server/timer.h b/server/timer.h
index 31b59ee..342340f 100644
--- a/server/timer.h
+++ b/server/timer.h
@@ -41,9 +41,9 @@ typedef struct _timer {
/* time for timer to go off, absolute time */
long alarm_time;
/* procedure to call when timer goes off */
- void (*func)();
+ void (*func)(void*);
/* argument for that procedure */
- caddr_t arg;
+ void * arg;
} *timer;
#define ALARM_TIME(x) ((x)->alarm_time)
@@ -53,10 +53,15 @@ typedef struct _timer {
#define ALARM_ARG(x) ((x)->arg)
#define TIMER_SIZE sizeof(struct _timer)
-time_t time();
+#ifdef mips
+#define time_t long /* sigh */
+#endif
+extern "C" time_t time(time_t*);
#define NOW (time((time_t *)NULL))
-extern timer timer_set_rel(), timer_set_abs();
-extern void timer_reset(), timer_process();
+typedef void (*timer_proc) (void *);
+extern timer timer_set_rel(long, timer_proc, void*);
+extern timer timer_set_abs(long, timer_proc, void*);
+extern void timer_reset(timer), timer_process(void);
#define timer_when(x) ALARM_TIME(x)
diff --git a/server/uloc.c b/server/uloc.c
index 5f4579d..69bc508 100644
--- a/server/uloc.c
+++ b/server/uloc.c
@@ -82,10 +82,11 @@ typedef struct _ZLocation_t {
for removing old entries */
} ZLocation_t;
-#define NULLZLT ((ZLocation_t *) 0)
-#define NOLOC (1)
-#define QUIET (-1)
-#define UNAUTH (-2)
+static ZLocation_t* const NULLZLT = 0;
+static const int NOLOC = 1;
+static const int QUIET = -1;
+static const int UNAUTH = -2;
+
#ifdef OLD_COMPAT
#define OLD_ZEPHYR_VERSION "ZEPH0.0"
#define LOGIN_QUIET_LOGIN "QUIET_LOGIN"
@@ -97,15 +98,27 @@ extern int old_compat_count_uloc; /* counter of old use */
extern int new_compat_count_uloc; /* counter of old use */
#endif NEW_COMPAT
#if defined(OLD_COMPAT) || defined(NEW_COMPAT)
-static void old_compat_ulogin_locate();
+static void old_compat_ulogin_locate(ZNotice_t *notice,
+ struct sockaddr_in *who);
#endif /* OLD_COMPAT || NEW_COMPAT */
-static void ulogin_locate(), ulogin_add_user(), ulogin_flush_user();
-static ZLocation_t *ulogin_find();
-static int ulogin_setup(), ulogin_parse(), ul_equiv(), ulogin_expose_user();
-static exposure_type ulogin_remove_user();
-static void login_sendit(), sense_logout(), free_loc();
-static char **ulogin_marshal_locs();
+static void ulogin_locate(ZNotice_t *, struct sockaddr_in *who, int auth),
+ ulogin_add_user(ZNotice_t *notice, exposure_type exposure,
+ struct sockaddr_in *who),
+ ulogin_flush_user(ZNotice_t *notice);
+static ZLocation_t *ulogin_find(ZNotice_t *notice, int strict);
+static int ulogin_setup(ZNotice_t *notice, ZLocation_t *locs,
+ exposure_type exposure, struct sockaddr_in *who),
+ ulogin_parse(ZNotice_t *notice, ZLocation_t *locs),
+ ul_equiv(ZLocation_t *l1, ZLocation_t *l2),
+ ulogin_expose_user(ZNotice_t *notice, exposure_type exposure);
+static exposure_type ulogin_remove_user(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who,
+ int *err_return);
+static void login_sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who),
+ sense_logout(ZNotice_t *notice, struct sockaddr_in *who),
+ free_loc(ZLocation_t *loc);
+static char **ulogin_marshal_locs(ZNotice_t *notice, int *found, int auth);
static ZLocation_t *locations = NULLZLT; /* ptr to first in array */
static int num_locs = 0; /* number in array */
@@ -115,31 +128,34 @@ static int num_locs = 0; /* number in array */
*/
Code_t
-ulogin_dispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+ulogin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
+ ZServerDesc_t *server)
{
exposure_type retval;
int err_ret;
ZHostList_t *host;
- zdbug((LOG_DEBUG,"ulogin_disp"));
+#if 1
+ zdbug((LOG_DEBUG,"ulogin_dispatch"));
+#endif
host = hostm_find_host(&who->sin_addr);
if (host && host->zh_locked)
return(ZSRV_REQUEUE);
if (!strcmp(notice->z_opcode, LOGIN_USER_LOGOUT)) {
+#if 0
zdbug((LOG_DEBUG,"logout"));
+#endif
retval = ulogin_remove_user(notice, auth, who, &err_ret);
switch (retval) {
case NONE:
if (err_ret == UNAUTH) {
+#if 0
zdbug((LOG_DEBUG, "unauth logout: %s %d",
inet_ntoa(who->sin_addr),
ntohs(notice->z_port)));
+#endif
if (server == me_server) {
clt_ack(notice, who, AUTH_FAILED);
sense_logout(notice, who);
@@ -181,11 +197,15 @@ ZServerDesc_t *server;
return(ZERR_NONE);
}
if (!auth || strcmp(notice->z_sender, notice->z_class_inst)) {
- zdbug((LOG_DEBUG,"unauthentic ulogin"));
+#if 1
+ zdbug((LOG_DEBUG,"unauthentic ulogin: %d %s %s", auth,
+ notice->z_sender, notice->z_class_inst));
+#endif
sense_logout(notice, who);
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
- return(ZERR_NONE);
+ if (!bdumping /* XXX: inter-server and tcp */)
+ return(ZERR_NONE);
}
#ifdef OLD_COMPAT
if (!strcmp(notice->z_opcode, LOGIN_USER_LOGIN)) {
@@ -205,17 +225,23 @@ ZServerDesc_t *server;
} else
#endif /* OLD_COMPAT */
if (!strcmp(notice->z_opcode, LOGIN_USER_FLUSH)) {
+#if 0
zdbug((LOG_DEBUG, "user flush"));
+#endif
ulogin_flush_user(notice);
if (server == me_server)
ack(notice, who);
} else if (!strcmp(notice->z_opcode, EXPOSE_NONE)) {
+#if 0
zdbug((LOG_DEBUG,"no expose"));
+#endif
(void) ulogin_remove_user(notice, auth, who, &err_ret);
if (err_ret == UNAUTH) {
+#if 0
zdbug((LOG_DEBUG, "unauth noexpose: %s/%d",
inet_ntoa(who->sin_addr),
ntohs(notice->z_port)));
+#endif
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
return(ZERR_NONE);
@@ -230,28 +256,38 @@ ZServerDesc_t *server;
}
return(ZERR_NONE);
} else if (!strcmp(notice->z_opcode, EXPOSE_OPSTAFF)) {
+#if 1
zdbug((LOG_DEBUG,"opstaff"));
+#endif
ulogin_add_user(notice, OPSTAFF_VIS, who);
if (server == me_server)
ack(notice, who);
} else if (!strcmp(notice->z_opcode, EXPOSE_REALMVIS)) {
+#if 1
zdbug((LOG_DEBUG,"realmvis"));
+#endif
ulogin_add_user(notice, REALM_VIS, who);
if (server == me_server) /* realm vis is not broadcast,
so we ack it here */
ack(notice, who);
} else if (!strcmp(notice->z_opcode, EXPOSE_REALMANN)) {
+#if 1
zdbug((LOG_DEBUG,"realmann"));
+#endif
ulogin_add_user(notice, REALM_ANN, who);
if (server == me_server) /* announce to the realm */
login_sendit(notice, auth, who);
} else if (!strcmp(notice->z_opcode, EXPOSE_NETVIS)) {
+#if 1
zdbug((LOG_DEBUG,"netvis"));
+#endif
ulogin_add_user(notice, NET_VIS, who);
if (server == me_server) /* announce to the realm */
login_sendit(notice, auth, who);
} else if (!strcmp(notice->z_opcode, EXPOSE_NETANN)) {
+#if 1
zdbug((LOG_DEBUG,"netann"));
+#endif
ulogin_add_user(notice, NET_ANN, who);
if (server == me_server) /* tell the world */
login_sendit(notice, auth, who);
@@ -267,10 +303,7 @@ ZServerDesc_t *server;
}
static void
-login_sendit(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+login_sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
ZNotice_t log_notice;
@@ -288,9 +321,7 @@ struct sockaddr_in *who;
/*ARGSUSED*/
static void
-sense_logout(notice, who)
-ZNotice_t *notice;
-struct sockaddr_in *who;
+sense_logout(ZNotice_t *notice, struct sockaddr_in *who)
{
ZNotice_t sense_notice;
ZLocation_t *loc;
@@ -351,13 +382,11 @@ struct sockaddr_in *who;
*/
Code_t
-ulocate_dispatch(notice, auth, who, server)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-ZServerDesc_t *server;
+ulocate_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
{
+#if 0
zdbug((LOG_DEBUG,"ulocate_disp"));
+#endif
#ifdef OLD_COMPAT
if (!strcmp(notice->z_version, OLD_ZEPHYR_VERSION) &&
@@ -365,17 +394,21 @@ ZServerDesc_t *server;
/* we support locates on the old version */
syslog(LOG_INFO, "old locate, %s", inet_ntoa(who->sin_addr));
old_compat_count_ulocate++;
- ulogin_locate(notice, who);
+ ulogin_locate(notice, who, auth);
/* does xmit and ack itself, so return */
return(ZERR_NONE);
}
#endif /* OLD_COMPAT */
+#if 0 /* Now we support unauthentic locate for net-visible. */
if (!auth) {
+#if 0
zdbug((LOG_DEBUG,"unauthentic ulocate"));
+#endif
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
return(ZERR_NONE);
}
+#endif
#ifdef OLD_COMPAT
if (!strcmp(notice->z_version, OLD_ZEPHYR_VERSION)) {
ZHostList_t *host = hostm_find_host(&who->sin_addr);
@@ -404,7 +437,9 @@ ZServerDesc_t *server;
} else
#endif /* OLD_COMPAT */
if (!strcmp(notice->z_opcode, LOCATE_LOCATE)) {
+#if 0
zdbug((LOG_DEBUG,"locate"));
+#endif
#if defined(NEW_COMPAT) || defined(OLD_COMPAT)
if (strcmp(notice->z_version, NEW_OLD_ZEPHYR_VERSION) &&
strcmp(notice->z_version, OLD_ZEPHYR_VERSION))
@@ -412,7 +447,7 @@ ZServerDesc_t *server;
/* we are talking to a current-rev client; send an
acknowledgement-message */
ack(notice, who);
- ulogin_locate(notice, who);
+ ulogin_locate(notice, who, auth);
return(ZERR_NONE);
} else {
syslog(LOG_ERR, "unknown uloc opcode %s", notice->z_opcode);
@@ -431,8 +466,7 @@ ZServerDesc_t *server;
*/
void
-uloc_hflush(addr)
-struct in_addr *addr;
+uloc_hflush(struct in_addr *addr)
{
ZLocation_t *loc;
register int i = 0, new_num = 0;
@@ -455,11 +489,13 @@ struct in_addr *addr;
if (locations[i].zlt_addr.s_addr != addr->s_addr)
loc[new_num++] = locations[i];
else {
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "uloc hflushing %s/%s/%s",
locations[i].zlt_user,
locations[i].zlt_machine,
locations[i].zlt_tty);
+#endif
free_loc(&locations[i]);
}
i++;
@@ -468,7 +504,9 @@ struct in_addr *addr;
xfree(locations);
if (!new_num) {
+#if 0
zdbug((LOG_DEBUG,"no more locs"));
+#endif
xfree(loc);
locations = NULLZLT;
num_locs = new_num;
@@ -494,8 +532,7 @@ struct in_addr *addr;
}
void
-uloc_flush_client(sin)
-struct sockaddr_in *sin;
+uloc_flush_client(struct sockaddr_in *sin)
{
ZLocation_t *loc;
register int i = 0, new_num = 0;
@@ -519,11 +556,13 @@ struct sockaddr_in *sin;
|| (locations[i].zlt_port != sin->sin_port))
loc[new_num++] = locations[i];
else {
+#if 0
if (zdebug)
syslog(LOG_DEBUG, "uloc cflushing %s/%s/%s",
locations[i].zlt_user,
locations[i].zlt_machine,
locations[i].zlt_tty);
+#endif
free_loc(&locations[i]);
}
i++;
@@ -532,7 +571,9 @@ struct sockaddr_in *sin;
xfree(locations);
if (!new_num) {
+#if 0
zdbug((LOG_DEBUG,"no more locs"));
+#endif
xfree(loc);
locations = NULLZLT;
num_locs = new_num;
@@ -563,9 +604,7 @@ struct sockaddr_in *sin;
/*ARGSUSED*/
Code_t
-uloc_send_locations(host, vers)
-ZHostList_t *host;
-char *vers;
+uloc_send_locations(ZHostList_t *host, char *vers)
{
register ZLocation_t *loc;
register int i;
@@ -643,20 +682,21 @@ char *vers;
*/
static void
-ulogin_add_user(notice, exposure, who)
-ZNotice_t *notice;
-exposure_type exposure;
-struct sockaddr_in *who;
+ulogin_add_user(ZNotice_t *notice, exposure_type exposure, struct sockaddr_in *who)
{
ZLocation_t *oldlocs, newloc;
register int i = 0;
int omask;
+#if 1
zdbug((LOG_DEBUG,"ul_add: %s type %d", notice->z_sender,
(int) exposure));
+#endif
if ((oldlocs = ulogin_find(notice, 1))) {
+#if 1
zdbug((LOG_DEBUG,"ul_add: already here"));
+#endif
(void) ulogin_expose_user(notice, exposure);
return;
}
@@ -731,11 +771,7 @@ struct sockaddr_in *who;
*/
static int
-ulogin_setup(notice, locs, exposure, who)
-ZNotice_t *notice;
-register ZLocation_t *locs;
-exposure_type exposure;
-struct sockaddr_in *who;
+ulogin_setup(ZNotice_t *notice, register ZLocation_t *locs, exposure_type exposure, struct sockaddr_in *who)
{
if (ulogin_parse(notice, locs))
return(1);
@@ -743,13 +779,13 @@ struct sockaddr_in *who;
syslog(LOG_ERR, "zloc bad format");
return(1);
}
- locs->zlt_user = strsave(locs->zlt_user);
+ locs->zlt_user = strsave (locs->zlt_user);
if (!locs->zlt_machine) {
syslog(LOG_ERR, "zloc bad format");
xfree(locs->zlt_user);
return(1);
}
- locs->zlt_machine = strsave(locs->zlt_machine);
+ locs->zlt_machine = strsave (locs->zlt_machine);
if (!locs->zlt_tty) {
syslog(LOG_ERR, "zloc bad format");
xfree(locs->zlt_user);
@@ -764,7 +800,7 @@ struct sockaddr_in *who;
xfree(locs->zlt_tty);
return(1);
}
- locs->zlt_time = strsave(locs->zlt_time);
+ locs->zlt_time = strsave (locs->zlt_time);
locs->zlt_exposure = exposure;
locs->zlt_addr = who->sin_addr;
locs->zlt_port = notice->z_port;
@@ -776,9 +812,7 @@ struct sockaddr_in *who;
*/
static int
-ulogin_parse(notice, locs)
-register ZNotice_t *notice;
-register ZLocation_t *locs;
+ulogin_parse(register ZNotice_t *notice, register ZLocation_t *locs)
{
register char *cp, *base;
@@ -790,10 +824,14 @@ register ZLocation_t *locs;
locs->zlt_user = notice->z_class_inst;
cp = base = notice->z_message;
+#if 0
zdbug((LOG_DEBUG,"user %s",notice->z_class_inst));
+#endif
locs->zlt_machine = cp;
+#if 0
zdbug((LOG_DEBUG,"mach %s",cp));
+#endif
cp += (strlen(cp) + 1);
if (cp >= base + notice->z_message_len) {
@@ -801,14 +839,18 @@ register ZLocation_t *locs;
return(1);
}
locs->zlt_time = cp;
+#if 0
zdbug((LOG_DEBUG,"time %s",cp));
+#endif
cp += (strlen(cp) + 1);
#ifdef OLD_COMPAT
if (cp == base + notice->z_message_len) {
/* no tty--for backwards compat, we allow this */
+#if 0
zdbug((LOG_DEBUG, "no tty"));
+#endif
locs->zlt_tty = "";
} else
#endif OLD_COMPAT
@@ -817,7 +859,9 @@ register ZLocation_t *locs;
return(1);
} else {
locs->zlt_tty = cp;
+#if 0
zdbug((LOG_DEBUG,"tty %s",cp));
+#endif
cp += (strlen(cp) + 1);
}
if (cp > base + notice->z_message_len) {
@@ -835,9 +879,7 @@ register ZLocation_t *locs;
*/
static ZLocation_t *
-ulogin_find(notice, strict)
-ZNotice_t *notice;
-int strict;
+ulogin_find(ZNotice_t *notice, int strict)
{
register int i, rlo, rhi;
int compar;
@@ -860,13 +902,17 @@ int strict;
else
rhi = i - 1;
if (rhi - rlo < 0) {
+#if 0
zdbug((LOG_DEBUG,"ul_find not found"));
+#endif
return(NULLZLT);
}
i = (rhi + rlo) >> 1; /* split the diff */
}
if (strict && ulogin_parse(notice, &tmploc)) {
+#if 0
zdbug((LOG_DEBUG,"ul_find bad fmt"));
+#endif
return(NULLZLT);
}
/* back up to the first of this guy */
@@ -881,7 +927,9 @@ int strict;
i++;
if ((i == num_locs) || strcmp(locations[i].zlt_user, notice->z_class_inst)) {
+#if 0
zdbug((LOG_DEBUG,"ul_find final match loss"));
+#endif
return(NULLZLT);
}
return(&locations[i]);
@@ -892,8 +940,7 @@ int strict;
*/
static int
-ul_equiv(l1, l2)
-register ZLocation_t *l1, *l2;
+ul_equiv(register ZLocation_t *l1, register ZLocation_t *l2)
{
if (strcasecmp(l1->zlt_machine, l2->zlt_machine))
return(0);
@@ -907,11 +954,7 @@ register ZLocation_t *l1, *l2;
*/
static exposure_type
-ulogin_remove_user(notice, auth, who, err_return)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-int *err_return;
+ulogin_remove_user(ZNotice_t *notice, int auth, struct sockaddr_in *who, int *err_return)
{
ZLocation_t *loc, *loc2;
register int i = 0;
@@ -920,7 +963,9 @@ int *err_return;
*err_return = 0;
if (!(loc2 = ulogin_find(notice, 1))) {
+#if 0
zdbug((LOG_DEBUG,"ul_rem: not here"));
+#endif
*err_return = NOLOC;
return(NONE);
}
@@ -937,7 +982,9 @@ int *err_return;
omask = sigblock(sigmask(SIGFPE)); /* don't let disk db dumps start */
if (--num_locs == 0) { /* last one */
+#if 0
zdbug((LOG_DEBUG,"last loc"));
+#endif
xfree(locations);
locations = NULLZLT;
(void) sigsetmask(omask);
@@ -990,8 +1037,7 @@ int *err_return;
*/
static void
-ulogin_flush_user(notice)
-ZNotice_t *notice;
+ulogin_flush_user(ZNotice_t *notice)
{
register ZLocation_t *loc, *loc2;
register int i, j, num_match, num_left;
@@ -1000,7 +1046,9 @@ ZNotice_t *notice;
i = num_match = num_left = 0;
if (!(loc2 = ulogin_find(notice, 0))) {
+#if 0
zdbug((LOG_DEBUG,"ul_rem: not here"));
+#endif
return;
}
@@ -1015,7 +1063,9 @@ ZNotice_t *notice;
num_left--;
}
if (num_locs == num_match) { /* no other locations left */
+#if 0
zdbug((LOG_DEBUG,"last loc"));
+#endif
for (j = 0; j < num_match; j++)
free_loc(&loc2[j]); /* free storage */
xfree(locations);
@@ -1076,21 +1126,23 @@ ZNotice_t *notice;
*/
static int
-ulogin_expose_user(notice, exposure)
-ZNotice_t *notice;
-exposure_type exposure;
+ulogin_expose_user(ZNotice_t *notice, exposure_type exposure)
{
ZLocation_t *loc, loc2;
int idx, notfound = 1;
+#if 0
zdbug((LOG_DEBUG,"ul_expose: %s type %d", notice->z_sender,
(int) exposure));
+#endif
if (ulogin_parse(notice, &loc2))
return(1);
if (!(loc = ulogin_find(notice, 0))) {
+#if 0
zdbug((LOG_DEBUG,"ul_hide: not here"));
+#endif
return(1);
}
idx = loc - locations;
@@ -1118,9 +1170,7 @@ exposure_type exposure;
static void
-ulogin_locate(notice, who)
-ZNotice_t *notice;
-struct sockaddr_in *who;
+ulogin_locate(ZNotice_t *notice, struct sockaddr_in *who, int auth)
{
char **answer;
int found;
@@ -1132,11 +1182,11 @@ struct sockaddr_in *who;
!strcmp(notice->z_version, OLD_ZEPHYR_VERSION)) {
/* we are talking to a new old client; use the new-old-style
acknowledgement-message */
- old_compat_ulogin_locate(notice, who);
+ old_compat_ulogin_locate(notice, who, auth);
return;
}
#endif /* NEW_COMPAT || OLD_COMPAT */
- answer = ulogin_marshal_locs(notice, &found);
+ answer = ulogin_marshal_locs(notice, &found, auth);
send_to_who = *who;
send_to_who.sin_port = notice->z_port;
@@ -1170,9 +1220,7 @@ struct sockaddr_in *who;
*/
static char **
-ulogin_marshal_locs(notice, found)
-ZNotice_t *notice;
-register int *found;
+ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
{
ZLocation_t **matches = (ZLocation_t **) 0;
ZLocation_t *loc;
@@ -1189,13 +1237,19 @@ register int *found;
while ((i < num_locs) &&
!strcmp(notice->z_class_inst, locations[i].zlt_user)) {
/* these locations match */
+#if 0
zdbug((LOG_DEBUG,"match %s", locations[i].zlt_user));
+#endif
switch (locations[i].zlt_exposure) {
case OPSTAFF_VIS:
i++;
continue;
case REALM_VIS:
case REALM_ANN:
+ if (!auth) {
+ i++;
+ continue;
+ }
case NET_VIS:
case NET_ANN:
default:
@@ -1249,9 +1303,7 @@ register int *found;
#if defined(OLD_COMPAT) || defined(NEW_COMPAT)
static void
-old_compat_ulogin_locate(notice, who)
-ZNotice_t *notice;
-struct sockaddr_in *who;
+old_compat_ulogin_locate(ZNotice_t *notice, struct sockaddr_in *who, int auth)
{
char **answer;
int found;
@@ -1266,7 +1318,7 @@ struct sockaddr_in *who;
syslog(LOG_INFO, "new old locate, %s", inet_ntoa(who->sin_addr));
}
#endif
- answer = ulogin_marshal_locs(notice, &found);
+ answer = ulogin_marshal_locs(notice, &found, auth);
reply = *notice;
reply.z_kind = SERVACK;
@@ -1299,7 +1351,9 @@ struct sockaddr_in *who;
xfree(answer);
return;
}
+#if 0
zdbug((LOG_DEBUG,"ulog_loc acked"));
+#endif
if (answer)
xfree(answer);
return;
@@ -1307,8 +1361,7 @@ struct sockaddr_in *who;
#endif /* OLD_COMPAT || NEW_COMPAT */
void
-uloc_dump_locs(fp)
-register FILE *fp;
+uloc_dump_locs(register FILE *fp)
{
register int i;
@@ -1350,8 +1403,7 @@ register FILE *fp;
}
static void
-free_loc(loc)
-register ZLocation_t *loc;
+free_loc(register ZLocation_t *loc)
{
xfree(loc->zlt_user);
xfree(loc->zlt_machine);
diff --git a/server/version.c b/server/version.c
index 3061d2a..fe0400c 100644
--- a/server/version.c
+++ b/server/version.c
@@ -14,18 +14,19 @@
#include <zephyr/mit-copyright.h>
#ifdef DEBUG
-char version[] = "Zephyr Server (DEBUG) $Revision$";
+extern const char version[] = "Zephyr Server (DEBUG) $Revision$";
#else
-char version[] = "Zephyr Server $Revision$";
-#endif DEBUG
-#ifndef lint
-#ifndef SABER
-static char rcsid_version_c[] = "$Id$";
-char copyright[] = "Copyright (c) 1987,1988,1989 Massachusetts Institute of Technology.\n";
+extern const char version[] = "Zephyr Server $Revision$";
+#endif
+
+#if !defined (lint) && !defined (SABER)
+static const char rcsid_version_c[] =
+ "$Id$";
+extern const char copyright[] =
+ "Copyright (c) 1987,1988,1989,1990 Massachusetts Institute of Technology.\n";
#ifdef CONCURRENT
-char concurrent[] = "Brain-dump concurrency enabled";
+extern const char concurrent[] = "Brain-dump concurrency enabled";
#else
-char concurrent[] = "no brain-dump concurrency";
-#endif CONCURRENT
-#endif SABER
-#endif lint
+extern const char concurrent[] = "no brain-dump concurrency";
+#endif
+#endif
diff --git a/server/zserver.h b/server/zserver.h
index 5fd8b59..9afeba2 100644
--- a/server/zserver.h
+++ b/server/zserver.h
@@ -22,89 +22,183 @@
<sys/time.h>,
<stdio.h>,
<krb.h> */
+extern "C" {
#include <arpa/inet.h>
#include <zephyr/acl.h>
#include <sys/file.h>
#include <zephyr/zsyslog.h>
+
#include <strings.h>
#include <signal.h>
#ifdef lint
#include <sys/uio.h> /* so it shuts up about struct iovec */
#endif /* lint */
-#include "timer.h"
#include "zsrv_err.h"
+}
+
+#include "timer.h"
#include "zsrv_conf.h" /* configuration params */
+#include "ZString.h"
+#include "access.h"
+#include "unix.h"
+
/* definitions for the Zephyr server */
/* structures */
-typedef struct _ZSubscr_t {
- struct _ZSubscr_t *q_forw; /* links in client's subscr. queue */
- struct _ZSubscr_t *q_back;
- char *zst_class; /* class of messages */
- char *zst_classinst; /* class-inst of messages */
- char *zst_recipient; /* recipient of messages */
-} ZSubscr_t;
-
-typedef struct _ZClient_t {
+
+/*
+ * ZDestination: Where is this notice going to? This includes class,
+ * instance, and recipient at the moment.
+ */
+
+struct ZDestination {
+ unsigned long hash_value;
+public:
+ ZString classname;
+ ZString inst;
+ ZString recip;
+ void set_hash ();
+ unsigned long hash ();
+ friend int operator== (const ZDestination&, const ZDestination&);
+ ZDestination (const char*, const char* =0, const char* =0);
+ ZDestination (const ZString& = null_string,
+ const ZString& = null_string,
+ const ZString& = null_string);
+ ZDestination (const ZDestination&);
+ void print (char *buf);
+ static int compare_strings (const ZDestination&, const ZDestination&);
+#ifndef __GNUG__
+ ~ZDestination ();
+#endif
+};
+
+inline void ZDestination::set_hash () {
+ hash_value = classname.hash () ^ inst.hash () ^ recip.hash ();
+}
+
+const static ZDestination null_destination = 0;
+
+inline unsigned long ZDestination::hash () {
+ return hash_value;
+}
+
+extern int operator== (const ZDestination&, const ZDestination&);
+
+inline operator< (const ZDestination& z1, const ZDestination& z2) {
+ return (z1.hash_value != z2.hash_value
+ ? z1.hash_value < z2.hash_value
+ : ZDestination::compare_strings (z1, z2) < 0);
+}
+
+inline operator> (const ZDestination& z1, const ZDestination& z2) {
+ return (z1 == z2) ? 0 : !(z1 < z2);
+}
+
+inline operator >= (const ZDestination& z1, const ZDestination& z2) {
+ return !(z1 < z2);
+}
+
+struct Notice {
+ ZNotice_t *notice;
+ ZDestination dest;
+ ZString sender;
+ int msg_no;
+ static int current_msg;
+ Notice (ZNotice_t *);
+};
+
+struct ZSubscr_t {
+ ZSubscr_t *q_forw; /* links in client's subscr. queue */
+ ZSubscr_t *q_back;
+ ZDestination zst_dest; /* destination of messages */
+
+ ZSubscr_t (const ZString& = null_string,
+ const ZString& = null_string,
+ const ZString& = null_string);
+ ZSubscr_t (const ZSubscr_t&);
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (ZSubscr_t)); }
+#endif
+};
+
+extern int operator== (const ZSubscr_t&, const ZSubscr_t&);
+extern int operator>= (const ZSubscr_t&, const ZSubscr_t&);
+
+typedef struct ZClient_t {
struct sockaddr_in zct_sin; /* ipaddr/port of client */
- struct _ZSubscr_t *zct_subs; /* subscriptions */
+ struct ZSubscr_t *zct_subs; /* subscriptions */
#ifdef KERBEROS
C_Block zct_cblock; /* session key for this client */
#endif /* KERBEROS */
- char *zct_principal; /* krb principal of user */
-} ZClient_t;
+ ZString zct_principal; /* krb principal of user */
+ long last_msg; /* last message sent to this client */
+ long last_check; /* actually, last time the other
+ server was asked to check... */
+ ZClient_t () {
+ last_msg = last_check = 0;
+ }
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (ZClient_t)); }
+#endif
+};
-typedef struct _ZClientList_t {
- struct _ZClientList_t *q_forw;
- struct _ZClientList_t *q_back;
+struct ZClientList_t {
+ ZClientList_t *q_forw;
+ ZClientList_t *q_back;
ZClient_t *zclt_client;
-} ZClientList_t;
-
-typedef struct _ZAcl_t {
- char *acl_filename;
-} ZAcl_t;
-
-typedef enum _ZAccess_t {
- TRANSMIT, /* use transmission acl */
- SUBSCRIBE, /* use subscription acl */
- INSTWILD, /* use instance wildcard acl */
- INSTUID /* use instance UID identity acl */
-} ZAccess_t;
-
-typedef struct _ZClass_t {
- struct _ZClass_t *q_forw;
- struct _ZClass_t *q_back;
- char *zct_classname;
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (ZClientList_t)); }
+#endif
+};
+
+struct ZClass_t {
+ ZClass_t *q_forw;
+ ZClass_t *q_back;
+ ZDestination zct_dest;
ZAcl_t *zct_acl;
ZClientList_t *zct_clientlist;
-} ZClass_t;
+
+ ZClass_t (const ZDestination& = null_destination);
+ ~ZClass_t ();
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (ZClass_t)); }
+#endif
+};
typedef struct _ZHostList_t {
struct _ZHostList_t *q_forw;
struct _ZHostList_t *q_back;
- struct _ZClientList_t *zh_clients;
- struct sockaddr_in zh_addr; /* IP addr/port of hostmanager */
- int zh_locked; /* 1 if this host is locked for
+ ZClientList_t *zh_clients;
+ sockaddr_in zh_addr; /* IP addr/port of hostmanager */
+ unsigned int zh_locked : 1; /* 1 if this host is locked for
a braindump */
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (_ZHostList_t)); }
+#endif
} ZHostList_t;
-typedef enum _server_state {
+enum server_state {
SERV_UP, /* Server is up */
SERV_TARDY, /* Server due for a hello */
SERV_DEAD, /* Server is considered dead */
SERV_STARTING /* Server is between dead and up */
-} server_state;
+};
typedef struct _ZNotAcked_t {
struct _ZNotAcked_t *q_forw; /* link to next */
struct _ZNotAcked_t *q_back; /* link to prev */
timer na_timer; /* timer for retransmit */
long na_abstimo; /* absolute timeout to drop after */
- int na_rexmits; /* number of retransmits */
+ short na_rexmits; /* number of retransmits */
+ short na_packsz; /* size of packet */
caddr_t na_packet; /* ptr to packet */
- int na_packsz; /* size of packet */
ZUnique_Id_t na_uid; /* uid of packet */
union { /* address to send to */
struct sockaddr_in na_sin; /* client address */
@@ -112,116 +206,189 @@ typedef struct _ZNotAcked_t {
} dest;
#define na_addr dest.na_sin
#define na_srv_idx dest.srv_idx
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (_ZNotAcked_t)); }
+#endif
} ZNotAcked_t;
typedef struct _ZSrvPending_t {
struct _ZSrvPending_t *q_forw; /* link to next */
struct _ZSrvPending_t *q_back; /* link to prev */
caddr_t pend_packet; /* the notice (in pkt form) */
- int pend_len; /* len of pkt */
- int pend_auth; /* whether it is authentic */
+ short pend_len; /* len of pkt */
+ unsigned int pend_auth : 1; /* whether it is authentic */
struct sockaddr_in pend_who; /* the addr of the sender */
+#ifndef __GNUG__
+ void *operator new (unsigned int sz) { return zalloc (sz); }
+ void operator delete (void *ptr) { zfree (ptr, sizeof (_ZSrvPending_t)); }
+#endif
} ZSrvPending_t;
-typedef struct _ZServerDesc_t {
- server_state zs_state; /* server's state */
+struct ZServerDesc_t {
struct sockaddr_in zs_addr; /* server's address */
long zs_timeout; /* Length of timeout in sec */
timer zs_timer; /* timer struct for this server */
- int zs_numsent; /* number of hello's sent */
ZHostList_t *zs_hosts; /* pointer to list of info from this
server */
ZSrvPending_t *zs_update_queue; /* queue of packets to send
to this server when done dumping */
- int zs_dumping; /* 1 if dumping, so we should queue */
-} ZServerDesc_t;
+ short zs_numsent; /* number of hello's sent */
+ server_state zs_state : 4; /* server's state */
+ unsigned int zs_dumping : 1; /* 1 if dumping, so we should queue */
+};
-typedef enum _ZSentType {
+enum ZSentType {
NOT_SENT, /* message was not xmitted */
SENT, /* message was xmitted */
AUTH_FAILED, /* authentication failed */
NOT_FOUND /* user not found for uloc */
-} ZSentType;
+};
-/* this is just for lint */
-struct qelem {
- struct qelem *q_forw;
- struct qelem *q_back;
- char *q_data;
+class SignalBlock {
+ int old_mask;
+public:
+ SignalBlock (int mask) {
+ old_mask = sigblock (mask);
+ }
+ ~SignalBlock () {
+ (void) sigsetmask (old_mask);
+ }
};
+
/* Function declarations */
-/* found in access.c */
-extern int access_check();
-extern void access_init(), access_reinit();
-
-/* found in brain_dump.c */
-extern void bdump_get(), bdump_send(), bdump_offer();
-extern Code_t bdump_send_list_tcp();
+/* found in bdump.c */
+extern void bdump_get(ZNotice_t *notice, int auth, struct sockaddr_in *who,
+ ZServerDesc_t *server);
+extern void bdump_send(void),
+ bdump_offer(struct sockaddr_in *who);
+extern Code_t bdump_send_list_tcp(ZNotice_Kind_t kind, u_short port,
+ char *z_class, char *inst, char *opcode,
+ char *sender, char *recip,
+ const char **lyst, int num);
/* found in class.c */
-extern Code_t class_register(), class_deregister(), class_restrict();
-extern Code_t class_setup_restricted();
-extern ZClientList_t *class_lookup();
-extern ZAcl_t *class_get_acl();
-extern int class_is_control(), class_is_admin(), class_is_hm();
-extern int class_is_ulogin(), class_is_uloc();
-extern void class_free();
+extern Code_t class_register(ZClient_t *client, ZSubscr_t *subs),
+ class_deregister(ZClient_t *client, ZSubscr_t *subs),
+ class_restrict(char *z_class, ZAcl_t *acl),
+ class_setup_restricted(char *z_class, ZAcl_t *acl);
+extern ZClientList_t *class_lookup(ZSubscr_t *subs);
+extern ZAcl_t *class_get_acl(ZString z_class);
+extern void class_free(ZClientList_t *lyst);
+extern const ZString class_control, class_admin, class_hm;
+extern const ZString class_ulogin, class_ulocate;
+
+inline int class_is_control (const Notice& notice) {
+ return notice.dest.classname == class_control;
+}
+inline int class_is_admin (const Notice& notice) {
+ return notice.dest.classname == class_admin;
+}
+inline int class_is_hm (const Notice& notice) {
+ return notice.dest.classname == class_hm;
+}
+inline int class_is_ulogin (const Notice& notice) {
+ return notice.dest.classname == class_ulogin;
+}
+inline int class_is_ulocate (const Notice& notice) {
+ return notice.dest.classname == class_ulocate;
+}
/* found in client.c */
-extern Code_t client_register();
-extern void client_deregister(), client_dump_clients();
-extern ZClient_t *client_which_client();
+extern Code_t client_register(ZNotice_t *notice, struct sockaddr_in *who,
+ register ZClient_t **client,
+ ZServerDesc_t *server, int wantdefaults);
+extern void client_deregister(ZClient_t *client, ZHostList_t *host, int flush);
+extern void client_dump_clients(FILE *fp, ZClientList_t *clist);
+extern ZClient_t *client_which_client(struct sockaddr_in *who,
+ ZNotice_t *notice);
/* found in common.c */
-extern char *strsave();
+extern char *strsave(const char *str);
+extern unsigned long hash (const char *);
/* found in dispatch.c */
-extern void handle_packet(), dispatch(), clt_ack(), nack_release(), sendit();
-extern void xmit();
-extern Code_t control_dispatch(), xmit_frag();
+extern void handle_packet(void);
+extern void dispatch(register ZNotice_t *notice, int auth,
+ struct sockaddr_in *who);
+extern void clt_ack(ZNotice_t *notice, struct sockaddr_in *who,
+ ZSentType sent);
+extern void nack_release(ZClient_t *client);
+extern void sendit(register ZNotice_t *notice, int auth,
+ struct sockaddr_in *who);
+extern void xmit(register ZNotice_t *notice, struct sockaddr_in *dest,
+ int auth, ZClient_t *client);
+extern Code_t control_dispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server);
+extern Code_t xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack);
+extern int current_msg;
/* found in hostm.c */
-extern void hostm_flush(), hostm_shutdown(), hostm_losing();
-extern ZHostList_t *hostm_find_host();
-extern ZServerDesc_t *hostm_find_server();
-extern void hostm_transfer(), hostm_deathgram(), hostm_dump_hosts();
-extern Code_t hostm_dispatch();
-extern void hostm_lose_ignore();
+extern void hostm_flush(ZHostList_t *host, ZServerDesc_t *server);
+extern void hostm_shutdown(void);
+extern void hostm_losing(ZClient_t *client, ZHostList_t *host);
+extern ZHostList_t *hostm_find_host(struct in_addr *addr);
+extern ZServerDesc_t *hostm_find_server(struct in_addr *addr);
+extern void hostm_transfer(ZHostList_t *host, ZServerDesc_t *server);
+extern void hostm_deathgram(struct sockaddr_in *sin, ZServerDesc_t *server);
+extern void hostm_dump_hosts(FILE *fp);
+extern Code_t hostm_dispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server);
+extern void hostm_lose_ignore(ZClient_t *client);
+extern void hostm_renumber_servers (int *);
+
+/* found in kstuff.c */
+extern int GetKerberosData (int, struct in_addr, AUTH_DAT*, char*, char*);
+extern Code_t SendKerberosData (int, KTEXT, char*, char*);
/* found in server.c */
-extern void server_timo(), server_recover(), server_dump_servers();
-extern void server_init(), server_shutdown();
-extern void server_forward(), server_kill_clt(), server_pending_free();
-extern void server_self_queue(), server_send_queue(), server_reset();
+extern void server_timo(void *which);
+extern void server_recover(ZClient_t *client),
+ server_dump_servers(FILE *fp);
+extern void server_init(void),
+ server_shutdown(void);
+extern void server_forward(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who);
+extern void server_kill_clt(ZClient_t *client);
+extern void server_pending_free(register ZSrvPending_t *pending);
+extern void server_self_queue(ZNotice_t*, int, struct sockaddr_in *),
+ server_send_queue(ZServerDesc_t *),
+ server_reset(void);
extern int is_server();
-extern ZServerDesc_t *server_which_server();
-extern ZSrvPending_t *server_dequeue();
-extern Code_t server_dispatch(), server_adispatch();
+extern ZServerDesc_t *server_which_server(struct sockaddr_in *who);
+extern ZSrvPending_t *server_dequeue(register ZServerDesc_t *server);
+extern Code_t server_dispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who);
+extern Code_t server_adispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server);
/* found in subscr.c */
-extern Code_t subscr_cancel(), subscr_subscribe(), subscr_send_subs();;
-extern ZClientList_t *subscr_match_list();
-extern void subscr_free_list(), subscr_cancel_client(), subscr_sendlist();
-extern void subscr_dump_subs(), subscr_reset();
-extern Code_t subscr_def_subs();
+extern Code_t subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice),
+ subscr_subscribe(ZClient_t *who, ZNotice_t *notice),
+ subscr_send_subs(ZClient_t *client, char *vers);;
+extern ZClientList_t *subscr_match_list(ZNotice_t *notice);
+extern void subscr_free_list(ZClientList_t *list),
+ subscr_cancel_client(register ZClient_t *client),
+ subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who);
+extern void subscr_dump_subs(FILE *fp, ZSubscr_t *subs),
+ subscr_reset(void);
+extern Code_t subscr_def_subs(ZClient_t *who);
/* found in uloc.c */
-extern void uloc_hflush(), uloc_flush_client(), uloc_dump_locs();
-extern Code_t ulogin_dispatch(), ulocate_dispatch(), uloc_send_locations();
-
-/* found in libc.a */
-char *malloc(), *realloc();
-long random();
-
-/* From the Error table library */
-char *error_message();
+extern void uloc_hflush(struct in_addr *addr),
+ uloc_flush_client(struct sockaddr_in *sin),
+ uloc_dump_locs(register FILE *fp);
+extern Code_t ulogin_dispatch(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server),
+ ulocate_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
+ ZServerDesc_t *server),
+ uloc_send_locations(ZHostList_t *host, char *vers);
/* global identifiers */
/* found in main.c */
-extern struct in_addr my_addr; /* my inet address */
extern struct sockaddr_in sock_sin; /* socket descriptors */
extern u_short hm_port; /* port # of hostmanagers */
extern int srv_socket; /* dgram sockets for clients
@@ -250,9 +417,10 @@ extern int nservers; /* number of other servers*/
#ifdef DEBUG
/* found in dispatch.c */
-extern char *pktypes[]; /* names of the packet types */
+extern const char *pktypes[]; /* names of the packet types */
#endif /* DEBUG */
+extern "C" struct in_addr my_addr; /* my inet address */
#define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
#define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
@@ -269,42 +437,41 @@ extern char *pktypes[]; /* names of the packet types */
#define ADMIN_YOU "YOUR_STATE" /* Class inst: please send your state*/
#define ADMIN_ME "MY_STATE" /* Class inst: please send my info */
-#define NULLZCT ((ZClass_t *) 0)
-#define NULLZCNT ((ZClient_t *) 0)
-#define NULLZCLT ((ZClientList_t *) 0)
-#define NULLHMCT ((ZHMClient_t *) 0)
-#define NULLZST ((ZSubscr_t *) 0)
-#define NULLZHLT ((ZHostList_t *) 0)
-#define NULLZNAT ((ZNotAcked_t *) 0)
-#define NULLZACLT ((ZAcl_t *) 0)
-#define NULLZPT ((ZPacket_t *) 0)
-#define NULLZSDT ((ZServerDesc_t *) 0)
-#define NULLZSPT ((ZSrvPending_t *) 0)
+ZClass_t * const NULLZCT = 0;
+ZClient_t * const NULLZCNT = 0;
+ZClientList_t * const NULLZCLT = 0;
+ZSubscr_t * const NULLZST = 0;
+ZHostList_t * const NULLZHLT = 0;
+ZNotAcked_t * const NULLZNAT = 0;
+ZAcl_t * const NULLZACLT = 0;
+ZPacket_t * const NULLZPT = 0;
+ZServerDesc_t * const NULLZSDT = 0;
+ZSrvPending_t * const NULLZSPT = 0;
/* me_server_idx is the index into otherservers of this server descriptor. */
/* the 'limbo' server is always the first server */
#define me_server (&otherservers[me_server_idx])
-#define limbo_server_idx() (0)
+inline int limbo_server_idx () {
+ return 0;
+}
#define limbo_server (&otherservers[limbo_server_idx()])
-#define msgs_queued() (ZQLength() || otherservers[me_server_idx].zs_update_queue)
+inline int msgs_queued () {
+ return ZQLength () || otherservers[me_server_idx].zs_update_queue;
+}
#define ack(a,b) clt_ack(a,b,SENT)
#define nack(a,b) clt_ack(a,b,NOT_SENT)
#define max(a,b) ((a) > (b) ? (a) : (b))
-/* these are to keep lint happy */
-#define xfree(foo) free((caddr_t) (foo))
-#define xinsque(a,b) insque((struct qelem *)(a), (struct qelem *)(b))
-#define xremque(a) remque((struct qelem *)(a))
-#define xmalloc(a) malloc((unsigned)(a))
-
/* the magic class to match all packets */
#define MATCHALL_CLASS "zmatch_all"
+extern const ZString wildcard_class;
/* the instance that matches all instances */
#define WILDCARD_INSTANCE "*"
+extern const ZString wildcard_instance;
/* SERVER_SRVTAB is defined in zephyr.h */
#define ZEPHYR_SRVTAB SERVER_SRVTAB
@@ -316,4 +483,35 @@ extern char *pktypes[]; /* names of the packet types */
#define zdbug(s1)
#endif /* DEBUG */
+inline Notice::Notice (ZNotice_t *n) : notice (n), dest (n->z_class, n->z_class_inst, n->z_recipient), sender (n->z_sender) {
+ msg_no = current_msg;
+}
+
+inline ZSubscr_t::ZSubscr_t (const ZString& cls, const ZString& inst, const ZString& recip) : zst_dest (cls, inst, recip) {
+ q_forw = q_back = this;
+}
+
+inline ZSubscr_t::ZSubscr_t (const ZSubscr_t& z) : zst_dest (z.zst_dest) {
+ q_forw = q_back = this;
+}
+
+inline int operator== (const ZSubscr_t& s1, const ZSubscr_t& s2) {
+ return s1.zst_dest == s2.zst_dest;
+}
+
+inline int operator >= (const ZSubscr_t& s1, const ZSubscr_t& s2) {
+ return s1.zst_dest >= s2.zst_dest;
+}
+
+inline ZClass_t::ZClass_t (const ZDestination& dest) : zct_dest (dest) {
+ q_forw = q_back = this;
+ zct_clientlist = 0;
+ zct_acl = 0;
+}
+
+inline ZClass_t::~ZClass_t () {
+ if (zct_clientlist)
+ xfree (zct_clientlist);
+}
+
#endif /* !__ZSERVER_H__ */