summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lucien Van Elsen <lwvanels@mit.edu>1991-12-04 08:25:09 +0000
committerGravatar Lucien Van Elsen <lwvanels@mit.edu>1991-12-04 08:25:09 +0000
commit1bd4094341bcada53540b6f51833c30d61f1dcd6 (patch)
tree917cfd1e4ff9e34dcf7f7a7aaaa78d875bf6d0b8
parentfe7095d1dc0a6a79810cc2e81df3fa70370385be (diff)
Converted back to ANSI C (with ifdef's for standard C)
-rw-r--r--server/Imakefile74
-rw-r--r--server/access.c122
-rw-r--r--server/access.h42
-rw-r--r--server/acl_files.c54
-rw-r--r--server/bdump.c339
-rw-r--r--server/class.c270
-rw-r--r--server/client.c67
-rw-r--r--server/common.c18
-rw-r--r--server/dispatch.c335
-rw-r--r--server/hostm.c187
-rw-r--r--server/kopt.c4
-rw-r--r--server/kstuff.c157
-rw-r--r--server/main.c260
-rw-r--r--server/server.c444
-rw-r--r--server/subscr.c449
-rw-r--r--server/timer.c51
-rw-r--r--server/timer.h20
-rw-r--r--server/uloc.c545
-rw-r--r--server/unix.h98
-rw-r--r--server/version.c68
-rw-r--r--server/zalloc.c101
-rw-r--r--server/zalloc.h29
-rw-r--r--server/zserver.h552
-rw-r--r--server/zsrv_conf.h10
-rw-r--r--server/zstring.c77
-rw-r--r--server/zstring.h18
26 files changed, 2506 insertions, 1885 deletions
diff --git a/server/Imakefile b/server/Imakefile
index b0627d0..3837149 100644
--- a/server/Imakefile
+++ b/server/Imakefile
@@ -21,73 +21,77 @@ LINTLIBS= ${ZEPHYR_LINTLIB} ${COMERR_LINTLIB} ${HES_LINTLIB} \
HDRS= zserver.h \
zsrv_conf.h \
timer.h \
- ZString.h ZStringTable.h ZStringRep.h \
- Set.hT Set.CT \
+ zstring.h \
unix.h \
zalloc.h \
- access.h \
- template_macros.h \
- new.h
+ access.h
-SRCS= main.C \
- access.C \
- bdump.C \
- class.C \
- client.C \
- common.C \
- dispatch.C \
- hostm.C \
- server.C \
- subscr.C \
- timer.C \
- uloc.C \
- kstuff.C \
- version.C \
- ZString.C ZStringTable.C \
- kopt.c \
+SRCS= access.c \
acl_files.c \
- xxx.c \
- zalloc.C
+ bdump.c \
+ class.c \
+ client.c \
+ common.c \
+ dispatch.c \
+ hostm.c \
+ kopt.c \
+ kstuff.c \
+ main.c \
+ server.c \
+ subscr.c \
+ timer.c \
+ uloc.c \
+ version.c \
+ zsrv_err.c \
+ zstring.c
-OBJS= main.o \
- zsrv_err.o \
- access.o \
+OBJS= access.o \
+ acl_files.o \
bdump.o \
class.o \
client.o \
common.o \
dispatch.o \
hostm.o \
+ kopt.o \
+ kstuff.o \
+ main.o \
server.o \
subscr.o \
timer.o \
uloc.o \
- kstuff.o \
version.o \
- ZString.o ZStringTable.o \
- kopt.o \
- acl_files.o \
- xxx.o \
- zalloc.o
+ zsrv_err.o \
+ zstring.o
OTHERSRCS= zsrv_err.et
CONFIG_FILES= default.subscriptions
SRCDIR= ${SRCTOP}/server
CODE= ${SRCS} ${HDRS} ${OTHERSRCS} ${CONFIG_FILES} Imakefile
-DEFINES=-DNDEBUG -DCONCURRENT
+DEFINES=-DDEBUG -DCONCURRENT
normal_obj_rule()
-cplusplus_program(zephyrd,${OBJS},,${LIBS},${USRETCDIR})
+zephyrd:: new_vers.sh
+ -$(RM) zephyrd
+ sh new_vers.sh
+
+program(zephyrd,${OBJS},,${LIBS},${USRETCDIR})
+
+saber_program(zephyrd, ${SRCS}, ${OBJS}, , ${LIBS})
error_table_noprof(zsrv_err)
src:: zsrv_err.h
-depend:: zsrv_err.h
+depend:: zsrv_err.h version.h
install::
-mkdir ${DESTDIR}${ACLDIR}
-rm -f ${DESTDIR}${ACLDIR}/?*.acl
cp acldir/?* ${DESTDIR}${ACLDIR}
${INSTALLFILE} default.subscriptions ${DESTDIR}${ACLDIR}/default.subscriptions
+
+
+version.h::
+ sh new_vers.sh
diff --git a/server/access.c b/server/access.c
index dc1afd8..05e66ef 100644
--- a/server/access.c
+++ b/server/access.c
@@ -14,15 +14,18 @@
#include <zephyr/mit-copyright.h>
#if !defined (lint) && !defined (SABER)
-static const char rcsid_access_c[] =
- "$Header$";
+static char rcsid_access_c[] =
+ "$Id$";
#endif
/*
*
* External routines:
*
- * ZAcl_t::ok (ZString sender, ZAccess_t accesstype)
+ * int access_check(notice, acl, accesstype)
+ * ZNotice_t *notice;
+ * ZAcl_t *acl;
+ * ZAccess_t accesstype;
*
* void access_init();
*
@@ -49,12 +52,28 @@ static const char rcsid_access_c[] =
#define ACL_IWS 4
#define ACL_IUI 8
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void check_acl P((ZAcl_t *acl));
+static void check_acl_type P((ZAcl_t *acl, ZAccess_t accesstype,
+ int typeflag));
+static void access_setup P((int first));
+
+#undef P
+
/*
* check access. return 1 if ok, 0 if not ok.
*/
int
-ZAcl_t::ok (ZString sender, ZAccess_t accesstype)
+access_check(sender, acl, accesstype)
+ char *sender;
+ ZAcl_t *acl;
+ ZAccess_t accesstype;
{
char buf[MAXPATHLEN]; /* holds the real acl name */
char *prefix;
@@ -81,61 +100,69 @@ ZAcl_t::ok (ZString sender, ZAccess_t accesstype)
syslog(LOG_ERR, "unknown access type %d", (int) accesstype);
return(0);
}
- if (!acl_types & flag) /* no acl ==> no restriction
+ if (!(acl->acl_types) & flag) /* no acl ==> no restriction
==> thumbs up */
return (1);
(void) sprintf(buf, "%s%s-%s.acl",
ZEPHYR_ACL_DIR,
prefix,
- acl_filename);
+ acl->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 ()));
+ zdbug ((LOG_DEBUG, "checking %s for %s", buf, sender->string));
#endif
return (acl_load (buf) < 0
- || acl_check(buf, sender.value ()));
+ || acl_check(buf, sender));
}
-void ZAcl_t::check_acl_type (ZAccess_t accesstype, int typeflag)
+static void
+check_acl(acl)
+ ZAcl_t *acl;
{
- 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;
+ acl->acl_types = 0;
+ check_acl_type (acl, TRANSMIT, ACL_XMT);
+ check_acl_type (acl, SUBSCRIBE, ACL_SUB);
+ check_acl_type (acl, INSTWILD, ACL_IWS);
+ check_acl_type (acl, INSTUID, ACL_IUI);
}
-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);
+static void
+check_acl_type(acl, accesstype, typeflag)
+ ZAcl_t *acl;
+ 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->acl_filename);
+ if (!access(buf, F_OK))
+ acl->acl_types |= typeflag;
}
+
/*
* Re-init code written by TYT, 8/14/90.
@@ -170,14 +197,21 @@ access_setup (int first)
else if (len = strlen(class_name))
class_name[len - 1] = '\0';
acl = 0;
- if (!first)
- acl = class_get_acl (ZString (class_name, 1));
+ if (!first) {
+ ZSTRING *z;
+ z = make_zstring(class_name,1);
+ acl = class_get_acl(z);
+ free_zstring(z);
+ }
if (!acl) {
- acl = new ZAcl_t (class_name);
+ acl = (ZAcl_t *) xmalloc(sizeof(ZAcl_t));
if (!acl) {
syslog(LOG_ERR, "no mem acl alloc");
abort();
}
+ acl->acl_filename = strsave(class_name);
+ check_acl(acl);
+
if (!first) {
/* Try to restrict already existing class */
retval = class_restrict (class_name, acl);
diff --git a/server/access.h b/server/access.h
index 43e0d77..df1201d 100644
--- a/server/access.h
+++ b/server/access.h
@@ -18,7 +18,7 @@
#include <zephyr/mit-copyright.h>
#include <zephyr/acl.h>
-#include "ZString.h"
+#include "zstring.h"
#include "unix.h"
typedef enum _ZAccess_t {
@@ -28,35 +28,25 @@ typedef enum _ZAccess_t {
INSTUID /* use instance UID identity acl */
} ZAccess_t;
-class ZAcl_t {
- char *acl_filename;
- int acl_types; /* Flag field indcating which acls
- are present. Used ONLY in access.c */
- public:
- int ok (ZString, ZAccess_t);
- ZAcl_t (const char *path) {
- extern char * strsave (const char *);
- acl_filename = strsave (path);
- acl_types = 0;
- check ();
- }
- ~ZAcl_t () {
- xfree (acl_filename);
- }
- private:
- void check (void);
- void check_acl_type (ZAccess_t, int);
-};
-
-inline int access_check(ZString sender, ZAcl_t *acl, ZAccess_t accesstype) {
- return acl->ok (sender, accesstype);
-}
+typedef struct _ZAcl_t {
+ char *acl_filename;
+ int acl_types; /* Flag field indcating which acls
+ are present. Used ONLY in access.c */
+} ZAcl_t;
+
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
/* found in access.c */
-extern void access_init (void), access_reinit (void);
+extern void access_init P((void)), access_reinit P((void));
/* found in acl_files.c */
-extern "C" int acl_load (char *);
+extern int acl_load P((char *));
+
+#undef P
/* external data relevant */
extern int zdebug;
diff --git a/server/acl_files.c b/server/acl_files.c
index 203274c..77a1783 100644
--- a/server/acl_files.c
+++ b/server/acl_files.c
@@ -21,9 +21,11 @@
#include <zephyr/mit-copyright.h>
+#ifndef SABER
#ifndef lint
static char rcsid_acl_files_c[] = "$Id$";
-#endif lint
+#endif /* lint */
+#endif /* SABER */
/*** Routines for manipulating access control list files ***/
@@ -63,10 +65,11 @@ extern time_t time();
/* Canonicalized form is put in canon, which must be big enough to hold
MAX_PRINCIPAL_SIZE characters */
acl_canonicalize_principal(principal, canon)
-char *principal;
-char *canon;
+ char *principal;
+ char *canon;
{
- char *dot, *atsign, *end;
+ char *end;
+ char *dot, *atsign;
int len;
dot = index(principal, INST_SEP);
@@ -234,9 +237,10 @@ FILE *f;
/* Creates the file with permissions perm if it does not exist */
/* Erases it if it does */
/* Returns return value of acl_commit */
-int acl_initialize(acl_file, perm)
-char *acl_file;
-int perm;
+int
+acl_initialize(acl_file, perm)
+ char *acl_file;
+ int perm;
{
FILE *new;
int fd;
@@ -306,8 +310,9 @@ destroy_hash(h)
}
/* Compute hash value for a string */
-static unsigned hashval(s)
-register char *s;
+static unsigned int
+hashval(s)
+ char *s;
{
register unsigned hv;
@@ -354,9 +359,10 @@ char *el;
}
/* Returns nonzero if el is in h */
-static check_hash(h, el)
-struct hashtbl *h;
-char *el;
+static int
+check_hash(h, el)
+ struct hashtbl *h;
+ char *el;
{
unsigned hv;
@@ -394,9 +400,9 @@ static int acl_cache_next = 0;
/* Returns index into acl_cache otherwise */
/* Note that if acl is already loaded, this is just a lookup */
int acl_load(name)
-char *name;
+ char *name;
{
- int i,fd;
+ int i;
FILE *f;
char buf[MAX_PRINCIPAL_SIZE];
char canon[MAX_PRINCIPAL_SIZE];
@@ -457,6 +463,7 @@ char *name;
* This destroys all cached ACL's so that new ones will be loaded in
* the next time they are requested.
*/
+void
acl_cache_reset()
{
int i;
@@ -475,8 +482,8 @@ acl_cache_reset()
/* Returns nonzero if it can be determined that acl contains principal */
/* Principal is not canonicalized, and no wildcarding is done */
acl_exact_match(acl, principal)
-char *acl;
-char *principal;
+ char *acl;
+ char *principal;
{
int idx;
@@ -490,9 +497,10 @@ char *principal;
/* Returns nonzero if it can be determined that acl contains principal */
/* Recognizes wildcards in acl of the form
name.*@realm, *.*@realm, and *.*@* */
+int
acl_check(acl, principal)
-char *acl;
-char *principal;
+ char *acl;
+ char *principal;
{
char buf[MAX_PRINCIPAL_SIZE];
char canon[MAX_PRINCIPAL_SIZE];
@@ -520,9 +528,10 @@ char *principal;
#ifdef notdef
/* Adds principal to acl */
/* Wildcards are interpreted literally */
+int
acl_add(acl, principal)
-char *acl;
-char *principal;
+ char *acl;
+ char *principal;
{
int idx;
int i;
@@ -554,9 +563,10 @@ char *principal;
/* Removes principal from acl */
/* Wildcards are interpreted literally */
+int
acl_delete(acl, principal)
-char *acl;
-char *principal;
+ char *acl;
+ char *principal;
{
int idx;
int i;
diff --git a/server/bdump.c b/server/bdump.c
index 4b48d71..3dce37a 100644
--- a/server/bdump.c
+++ b/server/bdump.c
@@ -16,7 +16,7 @@
#ifndef lint
#ifndef SABER
-static const char rcsid_bdump_c[] = "$Zephyr: /mit/zephyr/src/server/RCS/bdump.C,v 1.37 91/01/28 15:31:53 raeburn Exp Locker: raeburn $";
+static char rcsid_bdump_c[] = "$Id$";
#endif /* SABER */
#endif /* lint */
@@ -56,34 +56,50 @@ static const char rcsid_bdump_c[] = "$Zephyr: /mit/zephyr/src/server/RCS/bdump.C
* int num;
*/
-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,
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void close_bdump P((void* arg)),
+ cleanup P((ZServerDesc_t *server, int omask));
+static Code_t bdump_send_loop P((register ZServerDesc_t *server, char *vers)),
+ bdump_ask_for P((char *inst)),
+ bdump_recv_loop P((ZServerDesc_t *server));
+static void bdump_get_v1 P((ZNotice_t *, int, struct sockaddr_in *,
+ ZServerDesc_t *));
+static void bdump_get_v1a P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server));
+static Code_t get_packet P((caddr_t packet, int len, int *retlen));
+static Code_t extract_sin P((ZNotice_t *notice, struct sockaddr_in *target));
+static Code_t send_done P((void));
+static Code_t send_list P((ZNotice_Kind_t kind, int port, char *class_name,
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(FILE *f, register char *buf, register int len);
-static int net_write(FILE *f, register char *buf, int len);
-static int setup_file_pointers (void);
-static void shutdown_file_pointers (void);
+ char **lyst, int num));
+static Code_t send_host_register P((ZHostList_t *host));
+static Code_t sbd_loop P((struct sockaddr_in *from));
+static Code_t gbd_loop P((ZServerDesc_t *server));
+static Code_t send_normal_tcp P((ZNotice_Kind_t kind, int port,
+ char *class_name,
+ char *inst, char *opcode, char *sender,
+ char *recip, char *message, int len));
+static int net_read P((FILE *f, register char *buf, register int len));
+static int net_write P((FILE *f, register char *buf, int len));
+static int setup_file_pointers P((void));
+static void shutdown_file_pointers P((void));
#ifdef KERBEROS
-static int get_tgt(void);
+static int get_tgt P((void));
static long ticket_time;
static char my_realm[REALM_SZ];
+
+#define TKTLIFETIME 96
+#define tkt_lifetime(val) ((long) val * 5L * 60L)
#endif /* KERBEROS */
+#undef P
+
static timer bdump_timer;
static int bdump_inited;
static int live_socket = -1;
@@ -92,6 +108,7 @@ static struct sockaddr_in bdump_sin;
static int cancel_outgoing_dump;
int bdumping;
+
/*
* Functions for performing a brain dump between servers.
@@ -102,7 +119,8 @@ int bdumping;
*/
void
-bdump_offer(struct sockaddr_in *who)
+bdump_offer(who)
+ struct sockaddr_in *who;
{
Code_t retval;
char buf[512], *addr, *lyst[2];
@@ -163,7 +181,7 @@ bdump_offer(struct sockaddr_in *who)
#endif /* KERBEROS */
(void) listen(bdump_socket, 1);
- bdump_timer = timer_set_rel(20L, close_bdump, (caddr_t) 0);
+ bdump_timer = timer_set_rel(20L, close_bdump, (void *) 0);
FD_SET(bdump_socket, &interesting);
nfildes = max(bdump_socket, srv_socket) + 1;
@@ -205,6 +223,14 @@ bdump_send(void)
int fromlen = sizeof(from);
int omask;
int on = 1;
+#ifdef _POSIX_SOURCE
+ struct sigaction action;
+ /* Set up sigaction structure */
+ /* This is all done because the RS/6000 emulation of signal sets the */
+ /* signal action back to the default action when the signal handler is */
+ /* called, instead of leaving well enough alone.. */
+#endif /* _POSIX_SOURCE */
+
#ifdef KERBEROS
KTEXT_ST ticket;
AUTH_DAT kdata;
@@ -232,7 +258,14 @@ bdump_send(void)
omask = sigblock(sigmask(SIGFPE)); /* don't let ascii dumps start */
+#ifdef _POSIX_SOURCE
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &action, NULL);
+#else
(void) signal(SIGPIPE, SIG_IGN); /* so we can detect failures */
+#endif /* _POSIX_SOURCE */
from.sin_port = sock_sin.sin_port; /* we don't care what port
it came from, and we need to
@@ -289,13 +322,12 @@ bdump_send(void)
#ifdef KERBEROS
/* receive the authenticator */
- retval = GetKerberosData(live_socket, from.sin_addr, &kdata, "zephyr",
- ZEPHYR_SRVTAB);
- if (retval != KSUCCESS) {
- syslog(LOG_ERR, "bdump_send: getkdata: %s",
- krb_err_txt[retval]);
- cleanup(server, omask);
- return;
+ if ((retval = GetKerberosData(live_socket, from.sin_addr, &kdata,
+ "zephyr", ZEPHYR_SRVTAB)) != KSUCCESS) {
+ syslog(LOG_ERR, "bdump_send: getkdata: %s",
+ krb_err_txt[retval]);
+ cleanup(server, omask);
+ return;
}
if (strcmp(kdata.pname,"zephyr") || strcmp(kdata.pinst,"zephyr")) {
syslog(LOG_ERR, "bdump_send: peer not zephyr: %s.%s@%s",
@@ -308,12 +340,12 @@ bdump_send(void)
cleanup(server, omask);
return;
}
- retval = SendKerberosData(live_socket, &ticket, "zephyr", "zephyr");
- if (retval) {
- syslog(LOG_ERR,"bdump_send: SendKerberosData: %s",
- error_message (retval));
- cleanup(server, omask);
- return;
+ if ((retval = SendKerberosData(live_socket, &ticket, "zephyr",
+ "zephyr"))) {
+ syslog(LOG_ERR,"bdump_send: SendKerberosData: %s",
+ error_message (retval));
+ cleanup(server, omask);
+ return;
}
#else /* !KERBEROS */
if ((fromport > IPPORT_RESERVED) ||
@@ -325,8 +357,7 @@ bdump_send(void)
}
#endif /* KERBEROS */
- retval = setup_file_pointers ();
- if (retval) {
+ if ((retval = setup_file_pointers())) {
syslog (LOG_WARNING, "bdump_send: can't set up file pointers: %s",
error_message (retval));
cleanup (server, omask);
@@ -349,15 +380,21 @@ bdump_send(void)
#endif
if (server != limbo_server) {
/* set this guy to be up, and schedule a hello */
- server->set_state (SERV_UP);
+ server->zs_state = SERV_UP;
timer_reset(server->zs_timer);
- server->zs_timer = timer_set_rel(0L, server_timo, (caddr_t) server);
+ server->zs_timer = timer_set_rel(0L, server_timo, (void *) server);
}
#if 0
zdbug((LOG_DEBUG,"cleanup sbd"));
#endif
shutdown_file_pointers ();
+
+#ifdef _POSIX_SOURCE
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGPIPE, &action, NULL);
+#else
(void) signal(SIGPIPE, SIG_DFL);
+#endif /* _POSIX_SOURCE */
bdump_inited = 1;
bdumping = 0;
server->zs_dumping = 0;
@@ -372,13 +409,19 @@ bdump_send(void)
/*ARGSUSED*/
static void
-bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
- ZServerDesc_t *server)
+bdump_get_v1_guts (notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
struct sockaddr_in from;
Code_t retval;
int omask;
int on = 1;
+#ifdef _POSIX_SOURCE
+ struct sigaction action;
+#endif /* _POSIX_SOURCE */
#ifdef KERBEROS
KTEXT_ST ticket;
AUTH_DAT kdata;
@@ -389,11 +432,23 @@ bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
bdumping = 1;
server->zs_dumping = 1;
+#ifdef _POSIX_SOURCE
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &action, NULL);
+#else
(void) signal(SIGPIPE, SIG_IGN); /* so we can detect problems */
+#endif /* _POSIX_SOURCE */
if ((retval = extract_sin(notice, &from)) != ZERR_NONE) {
syslog(LOG_ERR, "bdump_get: sin: %s", error_message(retval));
+#ifdef _POSIX_SOURCE
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGPIPE, &action, NULL);
+#else
(void) signal(SIGPIPE, SIG_DFL);
+#endif /* _POSIX_SOURCE */
bdumping = 0;
server->zs_dumping = 0;
return;
@@ -437,8 +492,8 @@ bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
cleanup(server, omask);
return;
}
- retval = SendKerberosData(live_socket, &ticket, "zephyr", "zephyr");
- if (retval){
+ if ((retval = SendKerberosData(live_socket, &ticket, "zephyr",
+ "zephyr"))) {
syslog(LOG_ERR,"bdump_get: %s",
error_message (retval));
cleanup(server, omask);
@@ -465,8 +520,7 @@ bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
return;
}
#endif /* KERBEROS */
- retval = setup_file_pointers ();
- if (retval) {
+ if ((retval = setup_file_pointers())) {
syslog (LOG_WARNING, "bdump_get: can't set up file pointers: %s",
error_message (retval));
cleanup (server, omask);
@@ -491,15 +545,20 @@ bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
zdbug((LOG_DEBUG, "bdump_get: gbd finished"));
#endif
/* set this guy to be up, and schedule a hello */
- server->set_state (SERV_UP);
+ server->zs_state = SERV_UP;
timer_reset(server->zs_timer);
- server->zs_timer = timer_set_rel(0L, server_timo, (caddr_t) server);
+ server->zs_timer = timer_set_rel(0L, server_timo, (void *) server);
#if 1
zdbug((LOG_DEBUG,"cleanup gbd"));
#endif
shutdown_file_pointers ();
+#ifdef _POSIX_SOURCE
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGPIPE, &action, NULL);
+#else
(void) signal(SIGPIPE, SIG_DFL);
+#endif
bdump_inited = 1;
bdumping = 0;
server->zs_dumping = 0;
@@ -513,8 +572,16 @@ bdump_get_v1_guts (ZNotice_t *notice, int auth, sockaddr_in *who,
}
static void
-bdump_get_v1(ZNotice_t *notice, int auth, sockaddr_in *who,
+#ifdef __STDC__
+bdump_get_v1(ZNotice_t *notice, int auth, struct sockaddr_in *who,
ZServerDesc_t *server)
+#else
+bdump_get_v1(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
+#endif
{
if (bdump_socket >= 0) {
/* We cannot go get a brain dump when someone may
@@ -533,8 +600,16 @@ bdump_get_v1(ZNotice_t *notice, int auth, sockaddr_in *who,
}
static void
-bdump_get_v1a(ZNotice_t *notice, int auth, sockaddr_in *who,
+#ifdef __STDC__
+bdump_get_v1a( ZNotice_t *notice, int auth, struct sockaddr_in *who,
ZServerDesc_t *server)
+#else
+bdump_get_v1a(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
+#endif
{
/* In version 1A, leave the listening file descriptor open; if we
get a connection while we're dumping, one of the two will be
@@ -543,17 +618,28 @@ bdump_get_v1a(ZNotice_t *notice, int auth, sockaddr_in *who,
}
void
-bdump_get(ZNotice_t *notice, int auth, sockaddr_in *who, ZServerDesc_t *server)
+bdump_get(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+ void (*proc) P((ZNotice_t *, int, struct sockaddr_in *, ZServerDesc_t *));
+
+#undef P
+ proc = NULL;
+
#if 1
if (zdebug)
syslog(LOG_DEBUG, "bdump_get: bdump v%s avail %s",
notice->z_class_inst, inet_ntoa(who->sin_addr));
#endif
-
- /* version number 1 is the same as no version number */
- auto void (*proc)(ZNotice_t *, int, sockaddr_in *, ZServerDesc_t *);
- proc = 0;
if (!strcmp (notice->z_class_inst, "1")
|| !strcmp (notice->z_class_inst, ""))
proc = bdump_get_v1;
@@ -573,13 +659,21 @@ bdump_get(ZNotice_t *notice, int auth, sockaddr_in *who, ZServerDesc_t *server)
* Send a list off as the specified notice
*/
-Code_t
-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)
+int
+bdump_send_list_tcp(kind, port, class_name, inst, opcode, sender, recip,
+ lyst, num)
+ ZNotice_Kind_t kind;
+ int port;
+ char *class_name;
+ char *inst;
+ char *opcode;
+ char *sender;
+ char *recip;
+ char **lyst;
+ int num;
{
ZNotice_t notice;
- register ZNotice_t *const pnotice = &notice; /* speed hack */
+ register ZNotice_t *Zconst pnotice = &notice; /* speed hack */
char *pack;
int packlen, count;
Code_t retval;
@@ -643,19 +737,32 @@ shutdown_file_pointers () {
}
static void
-cleanup(ZServerDesc_t *server, int omask)
+cleanup(server, omask)
+ ZServerDesc_t *server;
+ int omask;
{
+#ifdef _POSIX_SOURCE
+ struct sigaction action;
+#endif /* _POSIX_SOURCE */
+
#if 1
zdbug((LOG_DEBUG, "bdump cleanup"));
#endif
if (server != limbo_server) {
- server->set_state (SERV_DEAD);
+ server->zs_state = SERV_DEAD;
timer_reset(server->zs_timer);
server->zs_timer =
- timer_set_rel(0L, server_timo, (caddr_t) server);
+ timer_set_rel(0L, server_timo, (void *) server);
}
shutdown_file_pointers ();
+#ifdef _POSIX_SOURCE
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGPIPE,&action, NULL);
+#else
(void) signal(SIGPIPE, SIG_DFL);
+#endif /* _POSIX_SOURCE */
bdumping = 0;
server->zs_dumping = 0;
#ifdef CONCURRENT
@@ -664,17 +771,10 @@ cleanup(ZServerDesc_t *server, int omask)
(void) sigsetmask(omask);
return;
}
-
+
#ifdef KERBEROS
-#define TKTLIFETIME 96
-static inline long
-tkt_lifetime(int val)
-{
- return((long) val * 5L * 60L);
-}
-
static int
-get_tgt(void)
+get_tgt()
{
int retval;
if (!*my_realm)
@@ -719,7 +819,8 @@ get_tgt(void)
#endif /* KERBEROS */
static Code_t
-sbd_loop(struct sockaddr_in *from)
+sbd_loop(from)
+ struct sockaddr_in *from;
{
ZNotice_t bd_notice;
ZPacket_t pack;
@@ -727,7 +828,6 @@ sbd_loop(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;
@@ -746,17 +846,7 @@ sbd_loop(struct sockaddr_in *from)
return(retval);
}
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);
+ zeph_version = strsave(bd_notice.z_version);
}
#ifdef DEBUG
if (zdebug) {
@@ -818,13 +908,14 @@ sbd_loop(struct sockaddr_in *from)
break;
}
}
- if (zeph_version && zeph_version != buf)
- LOCAL_FREE (zeph_version);
+ if (zeph_version)
+ xfree(zeph_version);
return(ZERR_NONE);
}
static Code_t
-gbd_loop(ZServerDesc_t *server)
+gbd_loop(server)
+ ZServerDesc_t *server;
{
Code_t retval;
@@ -861,18 +952,19 @@ gbd_loop(ZServerDesc_t *server)
/*ARGSUSED*/
static void
-close_bdump(void * arg)
+close_bdump(arg)
+ void * arg;
{
if (bdump_socket >= 0) {
FD_CLR(bdump_socket, &interesting);
(void) close(bdump_socket);
nfildes = srv_socket + 1;
bdump_socket = -1;
-#if 0
+#if 1
zdbug((LOG_DEBUG, "bdump not used"));
#endif
} else {
-#if 0
+#if 1
zdbug((LOG_DEBUG, "bdump not open"));
#endif
}
@@ -885,7 +977,8 @@ close_bdump(void * arg)
*/
static Code_t
-bdump_ask_for(char *inst)
+bdump_ask_for(inst)
+ char *inst;
{
Code_t retval;
@@ -901,7 +994,8 @@ bdump_ask_for(char *inst)
*/
static Code_t
-bdump_recv_loop(ZServerDesc_t *server)
+bdump_recv_loop(server)
+ ZServerDesc_t *server;
{
ZNotice_t notice;
ZPacket_t packet;
@@ -1085,7 +1179,9 @@ bdump_recv_loop(ZServerDesc_t *server)
*/
static Code_t
-bdump_send_loop(register ZServerDesc_t *server, char *vers)
+bdump_send_loop(server, vers)
+ ZServerDesc_t *server;
+ char *vers;
{
register ZHostList_t *host;
register ZClientList_t *clist;
@@ -1174,7 +1270,8 @@ bdump_send_loop(register ZServerDesc_t *server, char *vers)
*/
static Code_t
-send_host_register(ZHostList_t *host)
+send_host_register(host)
+ ZHostList_t *host;
{
char buf[512], *addr, *lyst[2];
Code_t retval;
@@ -1188,7 +1285,7 @@ send_host_register(ZHostList_t *host)
lyst[1] = buf;
/* myname is the hostname */
- retval = bdump_send_list_tcp (HMCTL, bdump_sin.sin_port,
+ retval = bdump_send_list_tcp (HMCTL, (int) bdump_sin.sin_port,
ZEPHYR_CTL_CLASS, ZEPHYR_CTL_HM,
HM_BOOT, myname, "", lyst, 2);
if (retval != ZERR_NONE)
@@ -1201,7 +1298,7 @@ send_host_register(ZHostList_t *host)
*/
static Code_t
-send_done(void)
+send_done()
{
Code_t retval;
@@ -1220,7 +1317,16 @@ send_done(void)
*/
static Code_t
-send_list(ZNotice_Kind_t kind, u_short port, char *class_name, char *inst, char *opcode, char *sender, char *recip, char **lyst, int num)
+send_list(kind, port, class_name, inst, opcode, sender, recip, lyst, num)
+ ZNotice_Kind_t kind;
+ int 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 */
@@ -1260,7 +1366,17 @@ send_list(ZNotice_Kind_t kind, u_short port, char *class_name, char *inst, char
*/
static Code_t
-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)
+send_normal_tcp(kind, port, class_name, inst, opcode, sender, recip,
+ message, len)
+ ZNotice_Kind_t kind;
+ int 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 */
@@ -1322,7 +1438,10 @@ send_normal_tcp(ZNotice_Kind_t kind, u_short port, char *class_name, char *inst,
*/
static Code_t
-get_packet(caddr_t packet, int len, int *retlen)
+get_packet(packet, len, retlen)
+ caddr_t packet;
+ int len;
+ int *retlen;
{
u_short length;
int result;
@@ -1352,7 +1471,9 @@ get_packet(caddr_t packet, int len, int *retlen)
}
static Code_t
-extract_sin(ZNotice_t *notice, struct sockaddr_in *target)
+extract_sin(notice, target)
+ ZNotice_t *notice;
+ struct sockaddr_in *target;
{
register char *cp = notice->z_message;
char *buf;
@@ -1380,7 +1501,10 @@ extract_sin(ZNotice_t *notice, struct sockaddr_in *target)
}
static int
-net_read(FILE *f, register char *buf, register int len)
+net_read(f, buf, len)
+ FILE *f;
+ register char *buf;
+ register int len;
{
int cc, len2 = 0;
@@ -1398,7 +1522,10 @@ net_read(FILE *f, register char *buf, register int len)
}
static int
-net_write(FILE *f, register char *buf, int len)
+net_write(f, buf, len)
+ FILE *f;
+ register char *buf;
+ int len;
{
int cc;
register int wrlen = len;
@@ -1415,11 +1542,13 @@ net_write(FILE *f, register char *buf, int len)
static int
setup_file_pointers ()
{
+ int fd;
+
input = fdopen (live_socket, "r");
if (!input)
return errno;
- int fd = dup (live_socket);
+ fd = dup (live_socket);
if (fd < 0)
return errno;
output = fdopen (fd, "w");
diff --git a/server/class.c b/server/class.c
index 3ab96c4..9433cf5 100644
--- a/server/class.c
+++ b/server/class.c
@@ -14,7 +14,7 @@
#include <zephyr/mit-copyright.h>
#if !defined (lint) && !defined (SABER)
-static const char rcsid_class_c[] =
+static char rcsid_class_c[] =
"$Id$";
#endif
@@ -77,74 +77,92 @@ static const char rcsid_class_c[] =
#define HASHSIZE 511
#define HASHMUL 243
-static ZClass_t *class_bucket[511]; /* the hash table of pointers */
-static ZString empty ("");
+static ZClass_t *class_bucket[HASHSIZE]; /* the hash table of pointers */
-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&);
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+static Code_t remove_client P((ZClass_t *ptr, ZClient_t *client)),
+ insert_client P((ZClass_t *ptr, ZClient_t *client));
+static ZClientList_t *client_alloc P((ZClient_t *client));
+static ZClass_t *class_alloc P((ZSTRING *classname, ZSTRING *inst));
+static void free_class P((ZClass_t *));
/* 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
+void
+set_ZDestination_hash(zd)
+ ZDestination *zd;
+{
+ zd->hash_value = (zd->classname->hash_val ^ zd->inst->hash_val) % HASHSIZE;
}
-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 ();
+int ZDest_eq(d1, d2)
+ ZDestination *d1, *d2;
+{
+ return((d1->hash_value == d2->hash_value) &&
+ (d1->classname == d2->classname) &&
+ (d1->inst == d2->inst));
}
-ZDestination::ZDestination (const ZDestination&d) : classname (d.classname), inst (d.inst), recip (d.recip) {
- hash_value = d.hash_value;
+int order_dest_strings(d1, d2)
+ ZDestination *d1, *d2;
+{
+ int i;
+
+ i = strcmp(d1->classname->string, d2->classname->string);
+ if (i != 0)
+ return (i);
+ i = strcmp(d1->inst->string, d2->inst->string);
+ if (i != 0)
+ return(i);
+ i = strcmp(d1->recip->string, d2->recip->string);
+ if (i != 0)
+ return(i);
+ syslog(LOG_WARNING,"order_dest_strings equual");
+ return(1); /* be arbitrary */
}
-int ZDestination::order_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 ZDest_geq(d1, d2)
+ ZDestination *d1, *d2;
+{
+ return((d1->hash_value != d2->hash_value) ?
+ (d1->hash_value < d2->hash_value) :
+ ((order_dest_strings(d1,d2) < 0)));
}
-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);
-}
-ZDestination::~ZDestination () {
- /* implicit destruction of ZString objects... */
-}
/* register the client as interested in class */
Code_t
-class_register(ZClient_t *client, ZSubscr_t *subs)
+class_register(client, subs)
+ ZClient_t *client;
+ ZSubscr_t *subs;
{
register ZClass_t *ptr, *ptr2;
- subs->zst_dest.set_hash ();
- unsigned long hashval = subs->zst_dest.hash () % HASHSIZE;
+ unsigned long hashval;
+ set_ZDestination_hash(&subs->zst_dest);
+ hashval = subs->zst_dest.hash_value;
if (!(ptr = class_bucket[hashval])) {
/* not registered */
- if (!(ptr = class_alloc(subs->zst_dest)))
+ if (!(ptr = class_alloc(subs->zst_dest.classname,
+ subs->zst_dest.inst)))
return(ENOMEM);
/* allocate the head of the bucket */
- ptr2 = new ZClass_t;
- if (!ptr2)
- return(ENOMEM);
+ if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
+ return(ENOMEM);
+
+ ptr2->zct_clientlist = 0;
+ ptr2->zct_acl = 0;
ptr2->q_forw = ptr;
ptr2->q_back = ptr;
ptr->q_forw = ptr2;
@@ -156,12 +174,14 @@ class_register(ZClient_t *client, ZSubscr_t *subs)
} else {
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
/* walk down the list, looking for a match */
- if (ptr2->zct_dest == subs->zst_dest)
- return(insert_client(ptr2, client));
+ if (ZDest_eq(&ptr2->zct_dest,&subs->zst_dest))
+ return(insert_client(ptr2, client));
/* fell off the end, no match */
- if (!(ptr2 = class_alloc(subs->zst_dest)))
+ if (!(ptr2 = class_alloc(subs->zst_dest.classname,
+ subs->zst_dest.inst)))
return(ENOMEM);
+
xinsque(ptr2, ptr); /* insert new class into hash bucket */
return(insert_client(ptr2, client));
}
@@ -170,22 +190,20 @@ class_register(ZClient_t *client, ZSubscr_t *subs)
/* dissociate client from the class, garbage collecting if appropriate */
Code_t
-class_deregister(ZClient_t *client, ZSubscr_t *subs)
+class_deregister(client, subs)
+ ZClient_t *client;
+ ZSubscr_t *subs;
{
register ZClass_t *ptr, *ptr2;
int retval = -1;
- subs->zst_dest.set_hash ();
- unsigned long hashval = subs->zst_dest.hash() % HASHSIZE;
-
-#if 0
- 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);
- }
+ unsigned long hashval;
+
+ set_ZDestination_hash(&subs->zst_dest);
+ hashval = subs->zst_dest.hash_value % HASHSIZE;
+#if 1
+ zdbug((LOG_DEBUG, "class_dereg: %s %s",
+ subs->zst_dest.classname->string,
+ subs->zst_dest.inst->string));
#endif
if (!(ptr = class_bucket[hashval]))
/* no such class to deregister */
@@ -193,9 +211,9 @@ class_deregister(ZClient_t *client, ZSubscr_t *subs)
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw) {
/* walk down the list, looking for a match */
- if (ptr2->zct_dest == subs->zst_dest) {
+ if (ZDest_eq(&ptr2->zct_dest,&subs->zst_dest)) {
if ((retval = remove_client(ptr2, client)) == EMPTY_CLASS) {
-#if 0
+#if 1
zdbug((LOG_DEBUG,"empty class"));
#endif
/* Don't free up restricted classes. */
@@ -203,7 +221,7 @@ class_deregister(ZClient_t *client, ZSubscr_t *subs)
return(ZERR_NONE);
else {
xremque(ptr2);
- delete ptr2;
+ free_class(ptr2);
return(ZERR_NONE);
}
}
@@ -222,7 +240,8 @@ class_deregister(ZClient_t *client, ZSubscr_t *subs)
/* return a linked list of what clients are interested in this class */
ZClientList_t *
-class_lookup(ZSubscr_t *subs)
+class_lookup(subs)
+ ZSubscr_t *subs;
{
register ZClass_t *ptr, *ptr2;
register int count = 0, wc_count = 0, idx = 1;
@@ -230,29 +249,30 @@ class_lookup(ZSubscr_t *subs)
ZClientList_t *list = NULLZCLT;
ZClientList_t *wc_list = NULLZCLT;
ZSubscr_t wc_sub;
+ unsigned long hashval;
- subs->zst_dest.set_hash ();
- unsigned long hashval = subs->zst_dest.hash() % HASHSIZE;
+ set_ZDestination_hash(&subs->zst_dest);
+ hashval = subs->zst_dest.hash_value;
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 (ptr2->zct_dest == subs->zst_dest) {
+ if (ZDest_eq(&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_dest.inst = ZString (WILDCARD_INSTANCE, 1);
- wc_sub.zst_dest.set_hash ();
- hashval = wc_sub.zst_dest.hash () % HASHSIZE;
+ wc_sub.zst_dest.inst = wildcard_instance;
+ set_ZDestination_hash(&wc_sub.zst_dest);
+ hashval = wc_sub.zst_dest.hash_value;
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 (ptr2->zct_dest == wc_sub.zst_dest) {
+ if (ZDest_eq(&ptr2->zct_dest,&wc_sub.zst_dest)) {
wc_list = ptr2->zct_clientlist;
break;
}
@@ -299,7 +319,8 @@ class_lookup(ZSubscr_t *subs)
/* free up the storage used by a returned list */
void
-class_free(ZClientList_t *lyst)
+class_free(lyst)
+ ZClientList_t *lyst;
{
xfree(lyst);
return;
@@ -311,18 +332,21 @@ class_free(ZClientList_t *lyst)
*/
ZAcl_t *
-class_get_acl(ZString class_name)
+class_get_acl(class_name)
+ ZSTRING *class_name;
{
register ZClass_t *ptr, *ptr2;
- ZDestination d (class_name);
- unsigned long hashval = d.hash () % HASHSIZE;
+ unsigned long hashval;
+
+
+ hashval = class_name->hash_val % 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 (ptr2->zct_dest == d)
+ if (ptr2->zct_dest.classname == class_name)
return(ptr2->zct_acl);
/* fell off the end, no match ==> not restricted */
@@ -336,24 +360,31 @@ class_get_acl(ZString class_name)
*/
Code_t
-class_restrict(char *class_name, ZAcl_t *acl)
+class_restrict(class_name, acl)
+ char *class_name;
+ ZAcl_t *acl;
{
register ZClass_t *ptr, *ptr2;
- ZDestination d (class_name);
- unsigned long hashval = d.hash() % HASHSIZE;
+ ZSTRING *d;
+ unsigned long hashval;
+
+ d = make_zstring(class_name,1);
+ hashval = d->hash_val % 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 (ptr2->zct_dest == d) {
+ if (ptr2->zct_dest.classname == d) {
if (ptr2->zct_acl)
return ZSRV_CLASSRESTRICTED;
ptr2->zct_acl = acl;
+ free_zstring(d);
return(ZERR_NONE);
}
/* fell off the end, no match */
+ free_zstring(d);
return(ZSRV_NOCLASS);
}
@@ -364,25 +395,28 @@ class_restrict(char *class_name, ZAcl_t *acl)
*/
Code_t
-class_setup_restricted(char *class_name, ZAcl_t *acl)
+class_setup_restricted(class_name, acl)
+ char *class_name;
+ ZAcl_t *acl;
{
register ZClass_t *ptr, *ptr2;
- ZDestination d (class_name);
- unsigned long hashval = d.hash () % HASHSIZE;
+ ZSTRING *d;
+ unsigned long hashval;
+
+ d = make_zstring(class_name,1);
+ hashval = d->hash_val % HASHSIZE;
if (!(ptr = class_bucket[hashval])) {
/* not registered */
- ptr = class_alloc(d);
- if (!ptr)
- return(ENOMEM);
+ if (!(ptr = class_alloc(d,empty)))
+ return(ENOMEM);
ptr->zct_acl = acl;
/* allocate the head of the bucket */
- ptr2 = new ZClass_t;
- if (!ptr2)
- return(ENOMEM);
+ if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
+ return(ENOMEM);
ptr2->q_forw = ptr;
ptr2->q_back = ptr;
@@ -394,10 +428,15 @@ class_setup_restricted(char *class_name, ZAcl_t *acl)
} else {
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
/* walk down the list, looking for a match */
- if (ptr2->zct_dest == d)
- return(ZSRV_CLASSXISTS);
- if (!(ptr2 = class_alloc (d)))
- return(ENOMEM);
+ if (ptr2->zct_dest.classname == d) {
+ free_zstring(d);
+ return(ZSRV_CLASSXISTS);
+ }
+ if (!(ptr2 = class_alloc(d,empty))) {
+ free_zstring(d);
+ return(ENOMEM);
+ }
+
ptr2->zct_acl = acl;
xinsque(ptr2, ptr);
return(ZERR_NONE);
@@ -409,43 +448,58 @@ class_setup_restricted(char *class_name, ZAcl_t *acl)
/* allocate space for a class structure */
static ZClass_t *
-class_alloc(const ZDestination& dest)
+class_alloc(classname,inst)
+ ZSTRING *classname;
+ ZSTRING *inst;
{
register ZClass_t *ptr;
ZClientList_t *clist;
- ptr = new ZClass_t (dest);
- if (!ptr)
+ if (!(ptr = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
return(NULLZCT);
- clist = (ZClientList_t *) xmalloc (sizeof (ZClientList_t));
- if (!clist) {
- delete ptr;
- return NULLZCT;
+ ptr->q_forw = ptr->q_back = ptr;
+ ptr->zct_dest.classname = classname;
+ ptr->zct_dest.classname->ref_count++;
+ ptr->zct_dest.inst = inst;
+ ptr->zct_dest.inst->ref_count++;
+ ptr->zct_dest.recip = empty;
+ ptr->zct_dest.recip->ref_count++;
+ set_ZDestination_hash(&ptr->zct_dest);
+
+ if (!(clist = (ZClientList_t *) xmalloc (sizeof (ZClientList_t)))) {
+ xfree(ptr);
+ return(NULLZCT);
}
clist->q_forw = clist->q_back = clist;
ptr->zct_clientlist = clist;
+ ptr->zct_acl = NULLZACLT;
- return ptr;
+ return (ptr);
}
/* allocate space for a client entry */
static ZClientList_t *
-client_alloc(ZClient_t *client)
+client_alloc(client)
+ ZClient_t *client;
{
register ZClientList_t *ptr;
if (!(ptr = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
return(NULLZCLT);
+ ptr->q_forw = ptr->q_back = ptr;
ptr->zclt_client = client;
+
return(ptr);
}
/* insert a client into the list associated with the class *ptr */
static Code_t
-insert_client(ZClass_t *ptr, ZClient_t *client)
+insert_client(ptr, client)
+ ZClass_t *ptr;
+ ZClient_t *client;
{
register ZClientList_t *listp, *clist;
@@ -468,7 +522,9 @@ insert_client(ZClass_t *ptr, ZClient_t *client)
* collecting if appropriate
*/
-static Code_t remove_client(ZClass_t *ptr, ZClient_t *client)
+static Code_t remove_client(ptr, client)
+ ZClass_t *ptr;
+ ZClient_t *client;
{
register ZClientList_t *listp = ptr->zct_clientlist;
register ZClientList_t *listp2;
@@ -489,3 +545,17 @@ static Code_t remove_client(ZClass_t *ptr, ZClient_t *client)
}
return(ZSRV_BADASSOC);
}
+
+static void free_class(class)
+ ZClass_t *class;
+{
+ free_zstring(class->zct_dest.classname);
+ free_zstring(class->zct_dest.inst);
+ free_zstring(class->zct_dest.recip);
+ if (class->zct_acl != NULL)
+ xfree(class->zct_acl);
+ if (class->zct_clientlist != NULL)
+ xfree(class->zct_clientlist);
+ xfree(class);
+}
+
diff --git a/server/client.c b/server/client.c
index ee4ea46..6970736 100644
--- a/server/client.c
+++ b/server/client.c
@@ -14,8 +14,8 @@
#include <zephyr/mit-copyright.h>
#if !defined (lint) && !defined (SABER)
-static const char rcsid_client_c[] =
- "$Zephyr: /afs/athena.mit.edu/astaff/project/zephyr/src/server/RCS/client.C,v 1.19 90/11/13 17:05:00 raeburn Exp $";
+static char rcsid_client_c[] =
+ "$Id$";
#endif
/*
@@ -54,8 +54,23 @@ static const char rcsid_client_c[] =
* The caller should check by calling client_which_client
*/
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void clt_free P((ZClient_t *client));
+
+#undef P
+
Code_t
-client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t **client, ZServerDesc_t *server, int wantdefaults)
+client_register(notice, who, client, server, wantdefaults)
+ 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;
@@ -69,9 +84,11 @@ client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t *
abort();
}
+#if 1
zdbug ((LOG_DEBUG, "client_register: adding %s at %s/%d",
notice->z_sender, inet_ntoa (who->sin_addr),
ntohs (notice->z_port)));
+#endif
if (!notice->z_port) {
/* must be a non-zero port # */
@@ -89,12 +106,14 @@ client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t *
}
/* allocate a client struct */
- *client = new ZClient_t;
- if (!*client)
- return(ENOMEM);
+ if (!(*client = (ZClient_t *) xmalloc(sizeof(ZClient_t))))
+ return(ENOMEM);
+
+ (*client)->last_msg = 0;
+ (*client)->last_check = 0;
if (!(clist = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
- delete *client;
+ xfree(*client);
return(ENOMEM);
}
@@ -112,8 +131,7 @@ client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t *
(*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 = ZString (notice->z_sender);
+ (*client)->zct_principal = make_zstring(notice->z_sender,0);
/* chain him in to the clients list in the host list*/
@@ -137,7 +155,10 @@ client_register(ZNotice_t *notice, struct sockaddr_in *who, register ZClient_t *
*/
void
-client_deregister(ZClient_t *client, ZHostList_t *host, int flush)
+client_deregister(client, host, flush)
+ ZClient_t *client;
+ ZHostList_t *host;
+ int flush;
{
ZClientList_t *clients;
int omask = sigblock(sigmask(SIGFPE)); /* don't let db dumps start */
@@ -160,7 +181,7 @@ client_deregister(ZClient_t *client, ZHostList_t *host, int flush)
clients = clients->q_forw)
if (clients->zclt_client == client) {
xremque(clients);
- delete client;
+ clt_free(client);
xfree(clients);
(void) sigsetmask(omask);
return;
@@ -175,20 +196,22 @@ client_deregister(ZClient_t *client, ZHostList_t *host, int flush)
*/
ZClient_t *
-client_which_client(struct sockaddr_in *who, ZNotice_t *notice)
+client_which_client(who, notice)
+ 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
+#if 1
zdbug((LOG_DEBUG,"cl_wh_clt: host not found"));
#endif
return(NULLZCNT);
}
if (!hlt->zh_clients) {
-#if 0
+#if 1
zdbug((LOG_DEBUG,"cl_wh_clt: no clients"));
#endif
return(NULLZCNT);
@@ -201,7 +224,7 @@ client_which_client(struct sockaddr_in *who, ZNotice_t *notice)
return(clients->zclt_client);
}
-#if 0
+#if 1
zdbug((LOG_DEBUG, "cl_wh_clt: no port"));
#endif
return(NULLZCNT);
@@ -214,15 +237,25 @@ client_which_client(struct sockaddr_in *who, ZNotice_t *notice)
*/
void
-client_dump_clients(FILE *fp, ZClientList_t *clist)
+client_dump_clients(fp, clist)
+ 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.value ());
+ ptr->zclt_client->zct_principal->string);
subscr_dump_subs(fp, ptr->zclt_client->zct_subs);
}
return;
}
+
+static void
+clt_free(client)
+ ZClient_t *client;
+{
+ free_zstring(client->zct_principal);
+ xfree(client);
+}
diff --git a/server/common.c b/server/common.c
index dc8ed92..7d74ca5 100644
--- a/server/common.c
+++ b/server/common.c
@@ -15,22 +15,24 @@
#ifndef lint
#ifndef SABER
-static const char rcsid_common_c[] =
- "$Header$";
-#endif SABER
-#endif lint
+static char rcsid_common_c[] =
+ "$Id$";
+#endif /* SABER */
+#endif /* lint */
+#include <zephyr/zephyr.h>
#include <stdio.h>
-#include <assert.h>
#include <ctype.h>
-#include "zserver.h"
+#include <syslog.h>
+#include <string.h>
+#include "unix.h"
/* common routines for the server */
/* copy the string into newly allocated area */
char *
-strsave (const char *sp)
+strsave (Zconst char *sp)
{
register char *ret;
@@ -45,7 +47,7 @@ strsave (const char *sp)
/* generic string hash function */
unsigned long
-hash (const char *string)
+hash (Zconst char *string)
{
register unsigned long hval = 0;
register char cp;
diff --git a/server/dispatch.c b/server/dispatch.c
index ea873d9..d42757a 100644
--- a/server/dispatch.c
+++ b/server/dispatch.c
@@ -15,14 +15,19 @@
#ifndef lint
#ifndef SABER
-static const char rcsid_dispatch_c[] =
- "$Zephyr: dispatch.C,v 1.36 91/03/08 13:07:11 raeburn Exp $";
+static char rcsid_dispatch_c[] =
+ "$Id$";
#endif
#endif
#include "zserver.h"
#include <sys/socket.h>
+#ifdef DEBUG
+Zconst char *ZNoticeKinds[9] = {"UNSAFE", "UNACKED", "ACKED", "HMACK",
+ "HMCTL", "SERVACK", "SERVNAK", "CLIENTACK",
+ "STAT"};
+#endif
/*
*
* External Routines:
@@ -52,49 +57,65 @@ static const char rcsid_dispatch_c[] =
* ZClient_t *client;
*/
-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;
-
-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);
-
-static void dispatch(ZNotice_t *, int, sockaddr_in *, int);
-
-statistic interserver_notices ("inter-server notices");
-statistic hm_packets ("hostmanager packets");
-statistic control_notices ("client control notices");
-statistic message_notices ("message notices");
-statistic login_notices ("login notices");
-statistic i_s_ctls ("inter-server control notices");
-statistic i_s_logins ("inter-server login notices");
-statistic i_s_admins ("inter-server admin notices");
-statistic i_s_locates ("inter-server locate notices");
-statistic locate_notices ("locate notices");
-statistic admin_notices ("admin notices");
-
-static void dump_stats (void *arg) {
- hm_packets.log ();
- control_notices.log ();
- message_notices.log ();
- login_notices.log ();
- locate_notices.log ();
- admin_notices.log ();
- interserver_notices.log ();
- i_s_ctls.log ();
- i_s_logins.log ();
- i_s_admins.log ();
- i_s_locates.log ();
- /* log stuff once an hour */
- (void) timer_set_rel (6*60*60, dump_stats, arg);
+
+ZSTRING *class_control, *class_admin, *class_hm, *class_ulogin,
+ *class_ulocate;
+
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void nack_cancel P((register ZNotice_t *, struct sockaddr_in *));
+static void dispatch P((ZNotice_t *, int, struct sockaddr_in *, int));
+
+#undef P
+
+ZStatistic interserver_notices = {0, "inter-server notices"};
+ZStatistic hm_packets = {0, "hostmanager packets"};
+ZStatistic control_notices = {0, "client control notices"};
+ZStatistic message_notices = {0, "message notices"};
+ZStatistic login_notices = {0, "login notices"};
+ZStatistic i_s_ctls = {0, "inter-server control notices"};
+ZStatistic i_s_logins = {0, "inter-server login notices"};
+ZStatistic i_s_admins = {0, "inter-server admin notices"};
+ZStatistic i_s_locates = {0, "inter-server locate notices"};
+ZStatistic locate_notices = {0, "locate notices"};
+ZStatistic admin_notices = {0, "admin notices"};
+
+static void
+#ifdef __STDC__
+dump_stats (void *arg)
+#else
+dump_stats (arg)
+void *arg;
+#endif
+{
+ syslog(LOG_INFO, "stats: %s: %d", hm_packets.str, hm_packets.val);
+ syslog(LOG_INFO, "stats: %s: %d", control_notices.str,
+ control_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", message_notices.str,
+ message_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", login_notices.str,
+ login_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", locate_notices.str,
+ locate_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", admin_notices.str,
+ admin_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", interserver_notices.str,
+ interserver_notices.val);
+ syslog(LOG_INFO, "stats: %s: %d", i_s_ctls.str, i_s_ctls.val);
+ syslog(LOG_INFO, "stats: %s: %d", i_s_logins.str, i_s_logins.val);
+ syslog(LOG_INFO, "stats: %s: %d", i_s_admins.str, i_s_admins.val);
+ syslog(LOG_INFO, "stats: %s: %d", i_s_locates.str, i_s_locates.val);
+ /* log stuff once an hour */
+ (void) timer_set_rel ((long) 6*60*60, dump_stats, arg);
}
/*
@@ -103,43 +124,45 @@ static void dump_stats (void *arg) {
*/
void
-handle_packet(void)
+handle_packet()
{
- {
- static int first_time = 1;
- if (first_time) {
- first_time = 0;
- (void) timer_set_rel (5*60, dump_stats, 0);
- }
- }
Code_t status;
ZPacket_t input_packet; /* from the network */
ZNotice_t new_notice; /* parsed from input_packet */
int input_len; /* len of packet */
- struct sockaddr_in input_sin; /* constructed for authent */
+ struct sockaddr_in input_sin; /* Zconstructed for authent */
struct sockaddr_in whoisit; /* for holding peer's address */
int authentic; /* authentic flag */
ZSrvPending_t *pending; /* pending packet */
ZHostList_t *host; /* host ptr */
int from_server; /* packet is from another server */
+#ifdef DEBUG
+ static int first_time = 1;
+#endif
+#ifdef DEBUG
+ /* Dump statistics five minutes after startup */
+ if (first_time) {
+ first_time = 0;
+ (void) timer_set_rel (5*60, dump_stats, (void *) 0);
+ }
+#endif
/* handle traffic */
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");
+#if 1
+ zdbug((LOG_DEBUG, "internal queue process"));
#endif
- pending = otherservers[me_server_idx].zs_update_queue->q_forw;
+ pending = otherservers[me_server_idx].zs_update_queue->q_forw;
host = hostm_find_host(&(pending->pend_who.sin_addr));
if (host && host->zh_locked) {
/* can't deal with it now. to preserve ordering,
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
+#if 1
zdbug((LOG_DEBUG,"host %s is locked",
inet_ntoa(host->zh_addr.sin_addr)));
#endif
@@ -219,7 +242,7 @@ handle_packet(void)
ntohs(whoisit.sin_port));
return;
}
- message_notices++;
+ message_notices.val++;
dispatch(&new_notice, authentic, &whoisit, from_server);
return;
}
@@ -228,79 +251,89 @@ handle_packet(void)
*/
static void
-dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who, int from_server) {
+dispatch(notice, auth, who, from_server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ int from_server;
+{
Code_t status;
- Notice notice = n;
-
- current_msg++;
- if (current_msg >= 9999)
- current_msg = 0;
+ ZSTRING *notice_class;
+ struct sockaddr_in who2;
+#ifdef DEBUG
+ char dbg_buf[BUFSIZ];
+#endif
- if ((int) notice.notice->z_kind < (int) UNSAFE ||
- (int) notice.notice->z_kind > (int) CLIENTACK) {
+ if ((int) notice->z_kind < (int) UNSAFE ||
+ (int) notice->z_kind > (int) CLIENTACK) {
syslog(LOG_INFO, "bad notice kind 0x%x from %s",
- (int) notice.notice->z_kind,
+ (int) notice->z_kind,
inet_ntoa(who->sin_addr));
return;
}
#if defined (DEBUG)
if (zdebug) {
- char buf[BUFSIZ];
- (void) sprintf (buf,
+ (void) sprintf (dbg_buf,
"disp:%s '%s' '%s' '%s' notice to '%s' from '%s' %s/%d/%d",
- ZNoticeKinds[(int) notice.notice->z_kind],
- notice.dest.classname.value (),
- notice.dest.inst.value (),
- notice.notice->z_opcode,
- notice.dest.recip.value (),
- notice.sender.value (),
+ ZNoticeKinds[(int) notice->z_kind],
+ notice->z_class,
+ notice->z_class_inst,
+ notice->z_opcode,
+ notice->z_recipient,
+ notice->z_sender,
inet_ntoa(who->sin_addr),
ntohs(who->sin_port),
- ntohs(notice.notice->z_port));
- syslog (LOG_DEBUG, "%s", buf);
+ ntohs(notice->z_port));
+ syslog (LOG_DEBUG, "%s", dbg_buf);
}
#endif
- if (notice.notice->z_kind == CLIENTACK) {
- nack_cancel(notice.notice, who);
+ if (notice->z_kind == CLIENTACK) {
+ nack_cancel(notice, who);
return;
}
- struct sockaddr_in who2 = *who;
+ who2 = *who;
+#if 0
if (0 && from_server) {
/* incorporate server_dispatch here */
}
+#endif
+ notice_class = make_zstring(notice->z_class,1);
+
if (from_server) {
- interserver_notices++;
- status = server_dispatch(notice.notice, auth, who);
- } else if (class_is_hm(notice)) {
- hm_packets++;
- status = hostm_dispatch(notice.notice, auth, who, me_server);
- } else if (class_is_control(notice)) {
- control_notices++;
- status = control_dispatch(notice.notice, auth, who, me_server);
- } else if (class_is_ulogin(notice)) {
- login_notices++;
- status = ulogin_dispatch(notice.notice, auth, who, me_server);
- } else if (class_is_ulocate(notice)) {
- locate_notices++;
- status = ulocate_dispatch(notice.notice, auth, who, me_server);
- } else if (class_is_admin(notice)) {
- admin_notices++;
- status = server_adispatch(notice.notice, auth, who, me_server);
+ interserver_notices.val++;
+ status = server_dispatch(notice, auth, who);
+ } else if (class_is_hm(notice_class)) {
+ hm_packets.val++;
+ status = hostm_dispatch(notice, auth, who, me_server);
+ } else if (class_is_control(notice_class)) {
+ control_notices.val++;
+ status = control_dispatch(notice, auth, who, me_server);
+ } else if (class_is_ulogin(notice_class)) {
+ login_notices.val++;
+ status = ulogin_dispatch(notice, auth, who, me_server);
+ } else if (class_is_ulocate(notice_class)) {
+ locate_notices.val++;
+ status = ulocate_dispatch(notice, auth, who, me_server);
+ } else if (class_is_admin(notice_class)) {
+ admin_notices.val++;
+ status = server_adispatch(notice, auth, who, me_server);
} else {
- sendit (notice.notice, auth, who);
+ sendit (notice, auth, who);
+ free_zstring(notice_class);
return;
}
if (status == ZSRV_REQUEUE) {
#ifdef CONCURRENT
- server_self_queue(notice.notice, auth, who);
+ server_self_queue(notice, auth, who);
#else
syslog(LOG_ERR, "requeue while not concurr");
abort();
#endif
}
+ free_zstring(notice_class);
}
/*
@@ -308,13 +341,19 @@ dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who, int from_server) {
*/
void
-sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+sendit(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
int acked = 0;
ZAcl_t *acl;
register ZClientList_t *clientlist, *ptr;
+ ZSTRING *z;
- if (acl = class_get_acl(ZString (notice->z_class, 1))) {
+ z = make_zstring(notice->z_class,1);
+ if (acl = class_get_acl(z)) {
+ free_zstring(z);
/* if controlled and not auth, fail */
if (!auth) {
syslog(LOG_WARNING, "sendit unauthentic %s from %s",
@@ -329,25 +368,20 @@ sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
clt_ack(notice, who, AUTH_FAILED);
return;
}
- /* sender != inst and not auth to send to others --> fail */
- {
- /* 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;
- }
- }
+ /* sender != inst and not auth to send to others --> fail */
+ if ((strcmp (notice->z_sender, notice->z_class_inst)) &&
+ (!access_check(notice->z_sender, 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;
+ }
}
- if (notice->z_sender_addr.s_addr != who->sin_addr.s_addr) {
+ if (bcmp(&notice->z_sender_addr.s_addr, &who->sin_addr.s_addr,
+ sizeof(notice->z_sender_addr.s_addr))) {
/* someone is playing games... */
/* inet_ntoa returns pointer to static area */
/* max size is 255.255.255.255 */
@@ -382,7 +416,8 @@ sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
*/
void
-nack_release(ZClient_t *client)
+nack_release(client)
+ ZClient_t *client;
{
register ZNotAcked_t *nacked, *nack2;
@@ -414,7 +449,11 @@ nack_release(ZClient_t *client)
/* the arguments must be the same as the arguments to Z_XmitFragment */
/*ARGSUSED*/
Code_t
-xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack)
+xmit_frag(notice, buf, len, waitforack)
+ ZNotice_t *notice;
+ char *buf;
+ int len;
+ int waitforack;
{
char *savebuf;
register ZNotAcked_t *nacked;
@@ -453,7 +492,7 @@ xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack)
/* set a timer to retransmit when done */
nacked->na_timer = timer_set_rel(rexmit_secs,
rexmit,
- (caddr_t) nacked);
+ (void *) nacked);
/* chain in */
xinsque(nacked, nacklist);
return(ZERR_NONE);
@@ -465,7 +504,11 @@ xmit_frag(ZNotice_t *notice, char *buf, int len, int waitforack)
*/
void
-xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth, ZClient_t *client)
+xmit(notice, dest, auth, client)
+ ZNotice_t *notice;
+ struct sockaddr_in *dest;
+ int auth;
+ ZClient_t *client;
{
caddr_t noticepack;
register ZNotAcked_t *nacked;
@@ -525,7 +568,7 @@ xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth, ZClient_t *client)
return; /* DON'T put on nack list */
}
}
-#if 0
+#if 1
zdbug((LOG_DEBUG," to %s/%d",inet_ntoa(dest->sin_addr),
ntohs(dest->sin_port)));
#endif
@@ -563,27 +606,33 @@ xmit(ZNotice_t *notice, struct sockaddr_in *dest, int auth, ZClient_t *client)
/* set a timer to retransmit when done */
nacked->na_timer = timer_set_rel(rexmit_secs,
rexmit,
- (caddr_t) nacked);
+ (void *) nacked);
/* chain in */
xinsque(nacked, nacklist);
}
+
/*
* Retransmit the packet specified. If we have timed out or retransmitted
* too many times, punt the packet and initiate the host recovery algorithm
* Else, increment the count and re-send the notice packet.
*/
-static void
+void
+#ifdef __STDC__
rexmit(void *arg)
+#else
+rexmit(arg)
+ void *arg;
+#endif
{
register ZNotAcked_t *nackpacket = (ZNotAcked_t*) arg;
int retval;
ZNotice_t dummy_notice;
register ZClient_t *client;
-#if 0
+#if 1
zdbug((LOG_DEBUG,"rexmit"));
#endif
@@ -609,7 +658,7 @@ rexmit(void *arg)
/* retransmit the packet */
-#if 0
+#if 1
zdbug((LOG_DEBUG," to %s/%d",
inet_ntoa(nackpacket->na_addr.sin_addr),
ntohs(nackpacket->na_addr.sin_port)));
@@ -629,7 +678,7 @@ requeue:
/* reset the timer */
nackpacket->na_timer = timer_set_rel(rexmit_secs,
rexmit,
- (caddr_t) nackpacket);
+ (void *) nackpacket);
return;
}
@@ -642,7 +691,10 @@ requeue:
*/
void
-clt_ack(ZNotice_t *notice, struct sockaddr_in *who, ZSentType sent)
+clt_ack(notice, who, sent)
+ ZNotice_t *notice;
+ struct sockaddr_in *who;
+ ZSentType sent;
{
ZNotice_t acknotice;
ZPacket_t ackpack;
@@ -735,13 +787,15 @@ clt_ack(ZNotice_t *notice, struct sockaddr_in *who, ZSentType sent)
*/
static void
-nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
+nack_cancel(notice, who)
+ 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 0
+#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));
@@ -776,8 +830,11 @@ nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
*/
Code_t
-control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
- ZServerDesc_t *server)
+control_dispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
register char *opcode = notice->z_opcode;
ZClient_t *client;
@@ -857,7 +914,7 @@ control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
abort();
}
}
- if (strcmp (client->zct_principal.value (), notice->z_sender)) {
+ if (strcmp (client->zct_principal->string, notice->z_sender)) {
/* you may only subscribe for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -867,7 +924,7 @@ control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
bcopy((caddr_t) ZGetSession(), /* in case it's changed */
(caddr_t) client->zct_cblock,
sizeof(C_Block));
-#endif KERBEROS
+#endif /* KERBEROS */
if ((retval = subscr_subscribe(client,notice)) != ZERR_NONE) {
syslog(LOG_WARNING, "subscr failed: %s",
error_message(retval));
@@ -877,7 +934,7 @@ control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
}
} else if (!strcmp(opcode, CLIENT_UNSUBSCRIBE)) {
if ((client = client_which_client(who,notice))) {
- if (strcmp(client->zct_principal.value (), notice->z_sender)) {
+ if (strcmp(client->zct_principal->string, notice->z_sender)) {
/* you may only cancel for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -907,7 +964,7 @@ control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
/* canceling subscriptions implies I can punt info about
this client */
if ((client = client_which_client(who,notice))) {
- if (strcmp(client->zct_principal.value (), notice->z_sender)) {
+ if (strcmp(client->zct_principal->string, notice->z_sender)) {
/* you may only cancel for your own clients */
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
@@ -917,11 +974,9 @@ control_dispatch(ZNotice_t *notice, int auth, sockaddr_in *who,
/* don't flush locations here, let him
do it explicitly */
#if 1
- if (zdebug)
- syslog(LOG_DEBUG,
- "cancelsub clt_dereg %s/%d",
- inet_ntoa (who->sin_addr),
- ntohs (who->sin_port));
+ zdbug((LOG_DEBUG, "cancelsub clt_dereg %s/%d",
+ inet_ntoa (who->sin_addr),
+ ntohs (who->sin_port)));
#endif
hostm_lose_ignore(client);
(void) client_deregister(client, host, 0);
diff --git a/server/hostm.c b/server/hostm.c
index cc74466..7026c12 100644
--- a/server/hostm.c
+++ b/server/hostm.c
@@ -15,7 +15,7 @@
#ifndef lint
#ifndef SABER
-static char rcsid_hostm_c[] = "$Header$";
+static char rcsid_hostm_c[] = "$Id$";
#endif
#endif
@@ -77,25 +77,15 @@ static char rcsid_hostm_c[] = "$Header$";
struct hostlist {
ZHostList_t *host; /* ptr to host struct */
int server_index; /* index of server in the table */
-#if 0 /* always allocated in arrays */
-#if !defined(__GNUG__) || defined(FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (hostlist)); }
-#endif
-#endif
};
-struct losinghost {
- losinghost *q_forw;
- losinghost *q_back;
- ZHostList_t *lh_host;
+typedef struct _losinghost {
+ struct _losinghost *q_forw;
+ struct _losinghost *q_back;
+ struct _ZHostList_t *lh_host;
timer lh_timer;
- ZClient_t *lh_client;
-#if !defined(__GNUG__) || defined(FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (losinghost)); }
-#endif
-};
+ struct _ZClient_t *lh_client;
+} losinghost;
#define NULLHLT ((struct hostlist *) 0)
@@ -107,13 +97,21 @@ static long lose_timo = LOSE_TIMO;
static losinghost *losing_hosts; /* queue of pings for hosts we
doubt are really there */
-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);
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void host_detach P((register ZHostList_t *host, ZServerDesc_t *server)),
+ insert_host P((ZHostList_t *host, ZServerDesc_t *server)),
+ remove_host P((ZHostList_t *host));
+static void host_not_losing P((struct sockaddr_in *who)),
+ host_lost P((void *which)),
+ ping P((struct sockaddr_in *sin));
+static Code_t host_attach P((struct sockaddr_in *who, ZServerDesc_t *server));
+
+#undef P
/*
* We received a HostManager packet. process accordingly.
@@ -121,8 +119,11 @@ static Code_t host_attach(struct sockaddr_in *who, ZServerDesc_t *server);
/*ARGSUSED*/
Code_t
-hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
- ZServerDesc_t *server)
+hostm_dispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
ZServerDesc_t *owner;
ZHostList_t *host = NULLZHLT;
@@ -181,9 +182,9 @@ hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
}
} else if (!strcmp(opcode, HM_BOOT)) {
#if 1
- if (zdebug)
- syslog (LOG_DEBUG, "boot %s (server %s)",
- inet_ntoa(*who), server->addr);
+ zdbug((LOG_DEBUG, "boot %s (server %s)",
+ inet_ntoa(who->sin_addr),
+ server->addr));
#endif
/* Booting is just like flushing and attaching */
if (owner) /* if owned, flush */
@@ -199,9 +200,9 @@ hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
}
} else if (!strcmp(opcode, HM_FLUSH)) {
#if 1
- if (zdebug)
- syslog(LOG_DEBUG, "hm_flush %s (server %s)",
- inet_ntoa(*who), server->addr);
+ zdbug((LOG_DEBUG, "hm_flush %s (server %s)",
+ inet_ntoa(who->sin_addr),
+ server->addr));
#endif
if (!owner)
return(ZERR_NONE);
@@ -211,7 +212,7 @@ hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
server_forward(notice, auth, who);
} else if (!strcmp(opcode, HM_DETACH)) {
#if 0
- zdbug((LOG_DEBUG, "hm_detach %s",inet_ntoa(who)));
+ zdbug((LOG_DEBUG, "hm_detach %s",inet_ntoa(who_sin_addr)));
#endif
/* ignore it */
} else {
@@ -230,7 +231,9 @@ hostm_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
*/
void
-hostm_flush(ZHostList_t *host, ZServerDesc_t *server)
+hostm_flush(host, server)
+ ZHostList_t *host;
+ ZServerDesc_t *server;
{
register ZClientList_t *clist = NULLZCLT, *clt;
losinghost *lhp, *lhp2;
@@ -252,25 +255,23 @@ hostm_flush(ZHostList_t *host, ZServerDesc_t *server)
lhp2 = lhp->q_back;
timer_reset(lhp->lh_timer);
xremque(lhp);
- delete lhp;
+ xfree(lhp);
lhp = lhp2->q_forw;
} else
lhp = lhp->q_forw;
if ((clist = host->zh_clients)) {
- char buf[16];
- strcpy (buf, inet_ntoa (host->zh_addr.sin_addr));
- for (clt = clist->q_forw; clt != clist; clt = clist->q_forw) {
- /* client_deregister frees this client & subscriptions
- & locations and remque()s the client */
+ for (clt = clist->q_forw; clt != clist; clt = clist->q_forw) {
+ /* client_deregister frees this client & subscriptions
+ & locations and remque()s the client */
#if 1
- if (zdebug)
- syslog (LOG_DEBUG, "hostm_flush clt_dereg %s/%d",
- buf,
- ntohs (clt->zclt_client->zct_sin.sin_port));
+ if (zdebug)
+ syslog (LOG_DEBUG, "hostm_flush clt_dereg %s/%d",
+ inet_ntoa(host->zh_addr.sin_addr),
+ ntohs (clt->zclt_client->zct_sin.sin_port));
#endif
- client_deregister(clt->zclt_client, host, 1);
- }
+ client_deregister(clt->zclt_client, host, 1);
+ }
}
uloc_hflush(&host->zh_addr.sin_addr);
@@ -284,7 +285,7 @@ hostm_flush(ZHostList_t *host, ZServerDesc_t *server)
*/
void
-hostm_shutdown(void)
+hostm_shutdown()
{
register ZHostList_t *hosts = otherservers[me_server_idx].zs_hosts;
register ZHostList_t *host;
@@ -298,7 +299,7 @@ hostm_shutdown(void)
for (i = 0; i < nservers; i++){
if (i == me_server_idx) continue;
- if (otherservers[i].state() == SERV_UP)
+ if (otherservers[i].zs_state == SERV_UP)
break;
}
if (i == nservers) /* no other servers are up */
@@ -315,8 +316,8 @@ hostm_shutdown(void)
do
newserver = (int) (random() % (nservers - 1)) + 1;
while (newserver == limbo_server_idx() ||
- (otherservers[newserver].state() != SERV_UP &&
- otherservers[newserver].state() != SERV_TARDY) ||
+ (otherservers[newserver].zs_state != SERV_UP &&
+ otherservers[newserver].zs_state != SERV_TARDY) ||
newserver == me_server_idx);
hostm_deathgram(&host->zh_addr, &otherservers[newserver]);
} else
@@ -332,7 +333,9 @@ hostm_shutdown(void)
*/
void
-hostm_losing(ZClient_t *client, ZHostList_t *host)
+hostm_losing(client, host)
+ ZClient_t *client;
+ ZHostList_t *host;
{
losinghost *newhost;
@@ -340,8 +343,8 @@ hostm_losing(ZClient_t *client, ZHostList_t *host)
zdbug((LOG_DEBUG,"losing host"));
#endif
if (!losing_hosts) {
- losing_hosts = new losinghost;
- if (!losing_hosts) {
+ if (!(losing_hosts = (losinghost *)
+ xmalloc(sizeof(losinghost)))) {
syslog(LOG_ERR, "no mem losing host");
return;
}
@@ -356,8 +359,7 @@ hostm_losing(ZClient_t *client, ZHostList_t *host)
#endif
return;
}
- newhost = new losinghost;
- if (!newhost) {
+ if (!(newhost = (losinghost *) xmalloc(sizeof(losinghost)))) {
syslog(LOG_ERR, "no mem losing host 2");
return;
}
@@ -366,7 +368,7 @@ hostm_losing(ZClient_t *client, ZHostList_t *host)
ping(&host->zh_addr);
newhost->lh_host = host;
newhost->lh_client = client;
- newhost->lh_timer = timer_set_rel(lose_timo, host_lost, (caddr_t) newhost);
+ newhost->lh_timer = timer_set_rel(lose_timo, host_lost, (void *) newhost);
xinsque(newhost, losing_hosts);
return;
}
@@ -376,7 +378,8 @@ hostm_losing(ZClient_t *client, ZHostList_t *host)
*/
static void
-host_lost(void* arg)
+host_lost(arg)
+ void* arg;
{
losinghost *which = (losinghost *) arg;
ZServerDesc_t *server;
@@ -400,7 +403,7 @@ host_lost(void* arg)
zdbug((LOG_DEBUG,"no server"));
#endif
xremque(which);
- delete which;
+ xfree(which);
(void) sigsetmask(omask);
return;
}
@@ -436,7 +439,7 @@ host_lost(void* arg)
server_forward(&notice, 0, &who); /* unauthentic */
- delete which;
+ xfree(which);
(void) sigsetmask(omask);
return;
}
@@ -446,7 +449,8 @@ host_lost(void* arg)
*/
static void
-host_not_losing(struct sockaddr_in *who)
+host_not_losing(who)
+ struct sockaddr_in *who;
{
losinghost *lhp, *lhp2;
int omask;
@@ -475,7 +479,7 @@ host_not_losing(struct sockaddr_in *who)
client_deregister(lhp->lh_client, lhp->lh_host, 1);
server_kill_clt(lhp->lh_client);
xremque(lhp);
- delete lhp;
+ xfree(lhp);
/* now that the remque adjusted the linked list,
we go forward again */
lhp = lhp2->q_forw;
@@ -491,7 +495,8 @@ host_not_losing(struct sockaddr_in *who)
*/
void
-hostm_lose_ignore(ZClient_t *client)
+hostm_lose_ignore(client)
+ ZClient_t *client;
{
losinghost *lhp, *lhp2;
int omask;
@@ -512,7 +517,7 @@ hostm_lose_ignore(ZClient_t *client)
ntohs(client->zct_sin.sin_port)));
#endif
xremque(lhp);
- delete lhp;
+ xfree(lhp);
/* now that the remque adjusted the linked list,
we go forward again */
lhp = lhp2->q_forw;
@@ -528,7 +533,9 @@ hostm_lose_ignore(ZClient_t *client)
*/
void
-hostm_transfer(ZHostList_t *host, ZServerDesc_t *server)
+hostm_transfer(host, server)
+ ZHostList_t *host;
+ ZServerDesc_t *server;
{
int omask;
@@ -564,7 +571,9 @@ hostm_transfer(ZHostList_t *host, ZServerDesc_t *server)
*/
static Code_t
-host_attach(struct sockaddr_in *who, ZServerDesc_t *server)
+host_attach(who, server)
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
register ZHostList_t *hlist;
register ZClientList_t *clist;
@@ -576,18 +585,18 @@ host_attach(struct sockaddr_in *who, ZServerDesc_t *server)
inet_ntoa (who->sin_addr), server->addr);
#endif
/* allocate a header */
- hlist = new ZHostList_t;
- if (!hlist) {
+ if (!(hlist = (ZHostList_t *) xmalloc(sizeof(ZHostList_t)))) {
syslog(LOG_WARNING, "hm_attach alloc");
(void) sigsetmask(omask);
return(ENOMEM);
}
/* set up */
if (!(clist = (ZClientList_t *)xmalloc(sizeof(ZClientList_t)))) {
- delete hlist;
+ xfree(hlist);
(void) sigsetmask(omask);
return(ENOMEM);
}
+ clist->zclt_client = NULLZCNT;
clist->q_forw = clist->q_back = clist;
hlist->zh_clients = clist;
@@ -611,7 +620,9 @@ host_attach(struct sockaddr_in *who, ZServerDesc_t *server)
*/
static void
-host_detach(register ZHostList_t *host, ZServerDesc_t *server)
+host_detach(host, server)
+ register ZHostList_t *host;
+ ZServerDesc_t *server;
{
/* undo what we did in host_attach */
int omask = sigblock(sigmask(SIGFPE)); /* don't start db dumps */
@@ -621,7 +632,8 @@ host_detach(register ZHostList_t *host, ZServerDesc_t *server)
syslog(LOG_WARNING,
"host_detach: wrong server: %s from %s, found %s",
inet_ntoa (host->zh_addr.sin_addr),
- server->addr, server2->addr);
+ server->addr,
+ server2->addr);
(void) sigsetmask(omask);
return;
}
@@ -636,7 +648,7 @@ host_detach(register ZHostList_t *host, ZServerDesc_t *server)
/* remove from table */
remove_host(host);
- delete host;
+ xfree(host);
(void) sigsetmask(omask);
return;
}
@@ -644,18 +656,19 @@ host_detach(register ZHostList_t *host, ZServerDesc_t *server)
/*
* Build hostmanager recipient name.
*/
-static inline char *
+static char *
hm_recipient ()
{
static char *recipient;
+ char *realm;
if (recipient)
return recipient;
- const char *realm = ZGetRealm ();
+ realm = ZGetRealm ();
if (!realm)
realm = "???";
- recipient = (char *) zalloc (strlen (realm) + 4);
+ recipient = (char *) xmalloc (strlen (realm) + 4);
strcpy (recipient, "hm@");
strcat (recipient, realm);
return recipient;
@@ -667,7 +680,9 @@ hm_recipient ()
*/
void
-hostm_deathgram(struct sockaddr_in *sin, ZServerDesc_t *server)
+hostm_deathgram(sin, server)
+ struct sockaddr_in *sin;
+ ZServerDesc_t *server;
{
Code_t retval;
int shutlen;
@@ -729,7 +744,8 @@ hostm_deathgram(struct sockaddr_in *sin, ZServerDesc_t *server)
*/
static void
-ping(struct sockaddr_in *sin)
+ping(sin)
+ struct sockaddr_in *sin;
{
Code_t retval;
int shutlen;
@@ -786,7 +802,8 @@ ping(struct sockaddr_in *sin)
*/
ZHostList_t *
-hostm_find_host(struct in_addr *addr)
+hostm_find_host(addr)
+ struct in_addr *addr;
{
register int i, rlo, rhi;
@@ -818,7 +835,8 @@ hostm_find_host(struct in_addr *addr)
*/
ZServerDesc_t *
-hostm_find_server(struct in_addr *addr)
+hostm_find_server(addr)
+ struct in_addr *addr;
{
register int i, rlo, rhi;
@@ -850,7 +868,9 @@ hostm_find_server(struct in_addr *addr)
*/
static void
-insert_host(ZHostList_t *host, ZServerDesc_t *server)
+insert_host(host, server)
+ ZHostList_t *host;
+ ZServerDesc_t *server;
{
struct hostlist *oldlist;
register int i = 0;
@@ -914,7 +934,8 @@ insert_host(ZHostList_t *host, ZServerDesc_t *server)
*/
static void
-remove_host(ZHostList_t *host)
+remove_host(host)
+ ZHostList_t *host;
{
struct hostlist *oldlist;
register int i = 0;
@@ -968,7 +989,8 @@ remove_host(ZHostList_t *host)
*/
void
-hostm_dump_hosts(FILE *fp)
+hostm_dump_hosts(fp)
+ FILE *fp;
{
register int i;
for (i = 0; i < num_hosts; i++) {
@@ -985,7 +1007,8 @@ hostm_dump_hosts(FILE *fp)
*/
void
-hostm_renumber_servers (int *srv)
+hostm_renumber_servers (srv)
+ int *srv;
{
int i;
for (i = 0; i < num_hosts; i++) {
diff --git a/server/kopt.c b/server/kopt.c
index 6a7b47f..7cd41db 100644
--- a/server/kopt.c
+++ b/server/kopt.c
@@ -17,9 +17,11 @@
*/
#ifndef lint
+#ifndef SABER
static char *rcsid_rd_req_c =
- "$Header$";
+ "$Id$";
#endif /* lint */
+#endif /* SABER */
#ifdef KERBEROS
#ifndef NOENCRYPTION
diff --git a/server/kstuff.c b/server/kstuff.c
index b0e2955..d29492d 100644
--- a/server/kstuff.c
+++ b/server/kstuff.c
@@ -14,18 +14,35 @@
*/
#ifndef lint
-static const char rcsid_kstuff_c[] = "$Header$";
+#ifndef SABER
+static char rcsid_kstuff_c[] = "$Id$";
+#endif
#endif
#include "zserver.h"
-extern "C" {
#include <ctype.h>
#include <netdb.h>
#include <strings.h>
#include <zephyr/zephyr_internal.h>
-}
+static char tkt_file[] = ZEPHYR_TKFILE;
+
+
+struct AuthEnt {
+ Zconst char *data;
+ int len;
+ ZSTRING *principal;
+#ifndef NOENCRYPTION
+ C_Block session_key;
+#endif
+ long expire_time;
+ struct sockaddr_in from;
+};
+
+#define HASH_SIZE_1 513
+#define HASH_SIZE_2 3
+static struct AuthEnt auth_cache[HASH_SIZE_1][HASH_SIZE_2];
/*
* GetKerberosData
@@ -35,14 +52,13 @@ extern "C" {
* the value of rd_ap_req() applied to the ticket.
*/
int
-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 */
+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 */
{
-
char p[20];
KTEXT_ST ticket; /* will get Kerberos ticket from client */
int i;
@@ -91,15 +107,18 @@ GetKerberosData(int fd, struct in_addr haddr, AUTH_DAT *kdata, char *service, ch
* get the ticket and write it to the file descriptor
*/
-SendKerberosData(int fd, /* file descriptor to write onto */
- KTEXT ticket, /* where to put ticket (return) */
- char *service, /* service name, foreign host */
- char *host)
+int
+SendKerberosData(fd, ticket, service, host)
+ int fd; /* file descriptor to write onto */
+ KTEXT ticket; /* where to put ticket (return) */
+ char *service; /* service name, foreign host */
+ char *host;
{
int rem;
char p[32];
char krb_realm[REALM_SZ];
int written;
+ int size_to_write;
rem = krb_get_lrealm(krb_realm,1);
if (rem != KSUCCESS)
@@ -110,7 +129,7 @@ SendKerberosData(int fd, /* file descriptor to write onto */
return rem + krb_err_base;
(void) sprintf(p,"%d ",ticket->length);
- int size_to_write = strlen (p);
+ size_to_write = strlen (p);
if ((written = write(fd, p, size_to_write)) != size_to_write)
if (written < 0)
return errno;
@@ -125,12 +144,10 @@ SendKerberosData(int fd, /* file descriptor to write onto */
return 0;
}
-static char tkt_file[] = ZEPHYR_TKFILE;
-
/* Hack to replace the kerberos library's idea of the ticket file with
our idea */
char *
-tkt_string(void)
+tkt_string()
{
return tkt_file;
}
@@ -142,34 +159,25 @@ tkt_string(void)
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 void
+ae_expire(ae)
+ struct AuthEnt *ae;
+{
+ if (ae->data) {
+ xfree((void *) ae->data);
+ ae->data = 0;
+ }
+ ae->len = 0;
+ ae->expire_time = 0;
+ ae->principal = 0;
+}
-static int auth_hash (const char *str, int len) {
+static int
+auth_hash (str, len)
+ Zconst char *str;
+ int len;
+{
unsigned long hash;
if (len <= 3)
return str[0];
@@ -178,21 +186,26 @@ static int auth_hash (const char *str, int len) {
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;
+static int
+check_cache (notice, from)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
+ {
+ Zconst char *str = notice->z_ascii_authent;
+ int len, i;
+ unsigned int hash_val = 0;
unsigned long now = time(0);
- AuthEnt *a;
+ struct AuthEnt *a;
- hash = auth_hash (str, len);
+ len = strlen (str);
+ hash_val = auth_hash (str, len);
for (i = 0; i < HASH_SIZE_2; i++) {
- a = &auth_cache[hash][i];
+ a = &auth_cache[hash_val][i];
if (!a->data) {
continue;
}
if (now > a->expire_time) {
- a->expire ();
+ ae_expire(a);
continue;
}
if (len != a->len) {
@@ -202,7 +215,7 @@ static int check_cache (ZNotice_t *notice, sockaddr_in *from) {
continue;
}
/* Okay, we know we've got the same authenticator. */
- if (strcmp (notice->z_sender, a->principal.value ())) {
+ if (strcmp (notice->z_sender, a->principal->string)) {
return ZAUTH_FAILED;
}
if (from->sin_addr.s_addr != a->from.sin_addr.s_addr) {
@@ -216,13 +229,17 @@ static int check_cache (ZNotice_t *notice, sockaddr_in *from) {
return ZAUTH_NO;
}
-void add_to_cache (const AuthEnt& a) {
- int len = a.len, i, j;
- AuthEnt *entries;
- unsigned int hash = 0;
+void
+add_to_cache (a)
+ struct AuthEnt *a;
+{
+ int len, i, j;
+ struct AuthEnt *entries;
+ unsigned int hash_val = 0;
- hash = auth_hash (a.data, len);
- entries = auth_cache[hash];
+ len = a->len;
+ hash_val = auth_hash (a->data, len);
+ entries = auth_cache[hash_val];
j = 0;
for (i = 0; i < HASH_SIZE_2; i++) {
if (entries[i].data == 0) {
@@ -236,20 +253,26 @@ void add_to_cache (const AuthEnt& a) {
}
ok:
if (entries[j].data)
- entries[j].expire ();
- entries[j] = a;
+ ae_expire(&entries[j]);
+ entries[j] = *a;
}
-int ZCheckAuthentication(ZNotice_t *notice, sockaddr_in *from) {
+int
+ZCheckAuthentication(notice, from)
+ ZNotice_t *notice;
+ struct 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;
+ struct AuthEnt a;
+ char *s;
int auth_len = 0;
+
if (!notice->z_auth) {
return (ZAUTH_NO);
}
@@ -280,7 +303,7 @@ int ZCheckAuthentication(ZNotice_t *notice, sockaddr_in *from) {
/* Well, it's not in the cache... decode it. */
result = krb_rd_req(&authent, SERVER_SERVICE,
- SERVER_INSTANCE, from->sin_addr.s_addr,
+ SERVER_INSTANCE, (int) from->sin_addr.s_addr,
&dat, SERVER_SRVTAB);
if (result == RD_AP_OK) {
bcopy ((void *) dat.session, (void *) a.session_key,
@@ -293,14 +316,14 @@ int ZCheckAuthentication(ZNotice_t *notice, sockaddr_in *from) {
syslog (LOG_DEBUG, "principal mismatch->AUTH_FAILED");
return (ZAUTH_FAILED);
}
- a.principal = srcprincipal;
+ a.principal = make_zstring(srcprincipal,0);
a.expire_time = time (0) + 5 * 60; /* add 5 minutes */
a.from = *from;
- char *s = (char *) zalloc (auth_len + 1);
+ s = (char *) xmalloc (auth_len + 1);
strcpy (s, notice->z_ascii_authent);
a.data = s;
a.len = auth_len;
- add_to_cache (a);
+ add_to_cache (&a);
return(ZAUTH_YES);
} else {
syslog (LOG_DEBUG, "krb_rd_req failed (%s)->AUTH_FAILED (from %s)",
diff --git a/server/main.c b/server/main.c
index f503bed..08ff333 100644
--- a/server/main.c
+++ b/server/main.c
@@ -16,7 +16,7 @@
#ifndef lint
#ifndef SABER
static char rcsid_main_c[] =
- "$Zephyr: main.C,v 1.45 91/03/08 14:09:46 raeburn Exp $";
+ "$Id$";
#endif
#endif
@@ -47,33 +47,36 @@ static char rcsid_main_c[] =
(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>
- <sys/types.h>
- <netinet/in.h>
- <sys/time.h>
- <stdio.h>
- <sys/file.h>
- <syslog.h>
- <strings.h>
- <signal.h>
- timer.h
- zsrv_err.h
- */
-
-extern "C" {
+#include "zserver.h"
+/* which includes
+ zephyr/zephyr.h
+ <errno.h>
+ <sys/types.h>
+ <netinet/in.h>
+ <sys/time.h>
+ <stdio.h>
+ <sys/file.h>
+ <syslog.h>
+ <strings.h>
+ <signal.h>
+ timer.h
+ zsrv_err.h
+ */
+
#include <netdb.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/wait.h>
-}
+
+#ifdef _POSIX_SOURCE
+#define SIGNAL_RETURN_TYPE void
+#define SIG_RETURN return
+#else
+#define SIGNAL_RETURN_TYPE int
+#define SIG_RETURN return(0)
+#endif
#if !defined(__SABER__) && (defined (vax) || defined (ibm032))
#define MONCONTROL moncontrol
@@ -83,22 +86,24 @@ extern "C" {
#define EVER (;;) /* don't stop looping */
-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
+#ifdef __STDC__
+# define P(s) s
#else
-#define SIGNAL_RETURN_TYPE void
-#define SIG_RETURN return
+# define P(s) ()
#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);
+
+static int do_net_setup P((void)), initialize P((void));
+static void usage P((void)), do_reset P((void));
+static SIGNAL_RETURN_TYPE bye P((int sig)), dbug_on P((int)),
+ dbug_off P((int));
+static SIGNAL_RETURN_TYPE dump_db P((int)), reset P((int)), reap P((int));
+static SIGNAL_RETURN_TYPE dump_strings P((int));
#ifndef DEBUG
-static void detach(void);
-#endif DEBUG
-extern "C" void perror(const char *);
+static void detach P((void));
+#endif /* DEBUG */
+extern void perror P((Zconst char *));
+
+#undef P
static short doreset = 0; /* if it becomes 1, perform
reset functions */
@@ -122,28 +127,33 @@ char myname[MAXHOSTNAMELEN]; /* my host name */
int zdebug;
#ifdef DEBUG
int zalone;
-#endif DEBUG
+#endif /* DEBUG */
u_long npackets; /* number of packets processed */
long uptime; /* when we started operations */
static int nofork;
+struct in_addr my_addr;
int
-main(int argc, char **argv)
+main(argc, argv)
+ int argc;
+ char **argv;
{
int nfound; /* #fildes ready on select */
fd_set readable;
struct timeval *tvp;
+#ifdef _POSIX_SOURCE
+ struct sigaction action;
+ /* Set up sigaction structure */
+ /* This is all done because the RS/6000 emulation of signal sets the */
+ /* signal action back to the default action when the signal handler is */
+ /* called, instead of leaving well enough alone.. */
+#endif /* _POSIX_SOURCE */
+
int optchar; /* option processing */
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++;
@@ -151,7 +161,7 @@ main(int argc, char **argv)
/* process arguments */
- while ((optchar = getopt(argc, argv, "ds3")) != EOF) {
+ while ((optchar = getopt(argc, argv, "dsn")) != EOF) {
switch(optchar) {
case 'd':
zdebug = 1;
@@ -161,7 +171,7 @@ main(int argc, char **argv)
zalone = 1;
break;
#endif
- case '3':
+ case 'n':
nofork = 1;
break;
case '?':
@@ -178,18 +188,18 @@ main(int argc, char **argv)
if (access(ZEPHYR_SRVTAB, R_OK)
#ifdef DEBUG
&& !zalone
-#endif DEBUG
+#endif /* DEBUG */
) {
fprintf(stderr, "NO ZEPHYR SRVTAB (%s) available; exiting\n",
ZEPHYR_SRVTAB);
exit(1);
}
-#endif KERBEROS
+#endif /* KERBEROS */
#ifndef DEBUG
if (!nofork)
detach();
-#endif DEBUG
+#endif /* DEBUG */
/* open log */
OPENLOG(programname, LOG_PID, LOG_LOCAL6);
@@ -231,28 +241,68 @@ main(int argc, char **argv)
nfildes = srv_socket + 1;
+#ifdef _POSIX_SOURCE
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+#endif /* _POSIX_SOURCE */
#ifdef DEBUG
/* DBX catches sigterm and does the wrong thing with sigint,
so we provide another hook */
+#ifdef _POSIX_SOURCE
+ action.sa_handler = bye;
+ sigaction(SIGALRM, &action, NULL);
+ sigaction(SIGTERM, &action, NULL);
+#else /* posix */
(void) signal(SIGALRM, bye);
-
(void) signal(SIGTERM, bye);
+#endif /* _POSIX_SOURCE */
#ifdef SignalIgnore
#undef SIG_IGN
#define SIG_IGN SignalIgnore
-#endif
+#endif /* SignalIgnore */
+#ifdef _POSIX_SOURCE
+ action.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &action, NULL);
+#else /* posix */
(void) signal(SIGINT, SIG_IGN);
-#else
+#endif /* _POSIX_SOURCE */
+#else /* ! debug */
+#ifdef _POSIX_SOURCE
+ action.sa_handler = bye;
+ sigaction(SIGINT, &action, NULL);
+ sigaction(SIGTERM, &action, NULL);
+#else /* posix */
(void) signal(SIGINT, bye);
(void) signal(SIGTERM, bye);
-#endif
+#endif /* _POSIX_SOURCE */
+#endif /* DEBUG */
syslog(LOG_INFO, "Ready for action");
+#ifdef _POSIX_SOURCE
+ action.sa_handler = dbug_on;
+ sigaction(SIGUSR1, &action, NULL);
+
+ action.sa_handler = dbug_off;
+ sigaction(SIGUSR2, &action, NULL);
+
+ action.sa_handler = reap;
+ sigaction(SIGCHLD, &action, NULL);
+
+ action.sa_handler = dump_db;
+ sigaction(SIGFPE, &action, NULL);
+
+ action.sa_handler = dump_strings;
+ sigaction(SIGEMT, &action, NULL);
+
+ action.sa_handler = reset;
+ sigaction(SIGHUP, &action, NULL);
+#else /* !posix */
(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);
+#endif /* _POSIX_SOURCE */
/* GO! */
uptime = NOW;
@@ -319,7 +369,7 @@ main(int argc, char **argv)
*/
static int
-initialize(void)
+initialize()
{
if (do_net_setup())
return(1);
@@ -351,6 +401,24 @@ initialize(void)
(void) ZSetFD(srv_socket); /* set up the socket as the
input fildes */
+ /* set up default strings */
+
+ class_control = make_zstring(ZEPHYR_CTL_CLASS, 1);
+ class_admin = make_zstring(ZEPHYR_ADMIN_CLASS, 1);
+ class_hm = make_zstring(HM_CTL_CLASS, 1);
+ class_ulogin = make_zstring(LOGIN_CLASS, 1);
+ class_ulocate = make_zstring(LOCATE_CLASS, 1);
+ wildcard_class = make_zstring(MATCHALL_CLASS, 1);
+ wildcard_instance = make_zstring(WILDCARD_INSTANCE, 1);
+ empty = make_zstring("", 0);
+
+ matchall_sub.q_forw = &matchall_sub;
+ matchall_sub.q_back = &matchall_sub;
+ matchall_sub.zst_dest.classname = wildcard_class;
+ matchall_sub.zst_dest.inst = empty;
+ matchall_sub.zst_dest.recip = empty;
+
+ set_ZDestination_hash(&matchall_sub.zst_dest);
/* restrict certain classes */
access_init();
return(0);
@@ -361,7 +429,7 @@ initialize(void)
*/
static int
-do_net_setup(void)
+do_net_setup()
{
struct servent *sp;
struct hostent *hp;
@@ -419,13 +487,13 @@ do_net_setup(void)
*/
static void
-usage(void)
+usage()
{
#ifdef DEBUG
- fprintf(stderr,"Usage: %s [-d] [-s]\n",programname);
+ fprintf(stderr,"Usage: %s [-d] [-s] [-n]\n",programname);
#else
- fprintf(stderr,"Usage: %s [-d]\n",programname);
-#endif DEBUG
+ fprintf(stderr,"Usage: %s [-d] [-n]\n",programname);
+#endif /* DEBUG */
exit(2);
}
@@ -475,7 +543,7 @@ dump_strings (int sig) {
SIG_RETURN;
}
syslog (LOG_INFO, "dumping strings to disk");
- ZString::print (fp);
+ print_zstring_table(fp);
if (fclose (fp) == EOF)
syslog (LOG_ERR, "error writing strings dump file");
else
@@ -541,22 +609,29 @@ reset(int sig)
static SIGNAL_RETURN_TYPE
reap(int sig)
{
- wait waitb;
- int oerrno = errno;
- while (wait3 (&waitb, WNOHANG, (struct rusage*) 0) == 0)
- ;
- errno = oerrno;
- SIG_RETURN;
+#ifdef _POSIX_SOURCE
+ int waitb;
+#else
+ union wait waitb;
+#endif
+ int oerrno;
+
+ oerrno = errno;
+ while (wait3 (&waitb, WNOHANG, (struct rusage*) 0) == 0)
+ ;
+ errno = oerrno;
+ SIG_RETURN;
}
static void
-do_reset(void)
+do_reset()
{
int oerrno = errno;
+ int old_mask;
#if 0
zdbug((LOG_DEBUG,"do_reset()"));
#endif
- SignalBlock no_hups (sigmask (SIGHUP));
+ old_mask = sigblock(sigmask(SIGHUP));
/* reset various things in the server's state */
subscr_reset();
@@ -565,6 +640,7 @@ do_reset(void)
syslog (LOG_INFO, "restart completed");
doreset = 0;
errno = oerrno;
+ sigsetmask(old_mask);
}
#ifndef DEBUG
@@ -573,7 +649,7 @@ do_reset(void)
*/
static void
-detach(void)
+detach()
{
/* detach from terminal and fork. */
register int i, size = getdtablesize();
@@ -596,51 +672,3 @@ detach(void)
(void) close(i);
}
#endif
-
-#if 0 /* Not useful now that strings in string table are sorted by
- hash value rather than entry time. */
-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",
- "testers.athena.mit.edu:x11r4",
-};
-#endif
diff --git a/server/server.c b/server/server.c
index 406a58b..d869bea 100644
--- a/server/server.c
+++ b/server/server.c
@@ -20,11 +20,9 @@ static char rcsid_server_c[] = "$Id$";
#endif
#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.
@@ -67,40 +65,51 @@ extern "C" {
* void server_reset();
*/
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
static void
- server_flush(ZServerDesc_t *),
- hello_respond(sockaddr_in *, int, int),
- srv_responded(sockaddr_in *),
- send_msg(sockaddr_in *, char *, int),
- send_msg_list(sockaddr_in *, char *, char **, int, int),
- srv_nack_cancel(ZNotice_t *, sockaddr_in *),
- srv_nack_release(ZServerDesc_t *),
- srv_nack_renumber (int *),
- server_lost(ZServerDesc_t *),
- send_stats(sockaddr_in *),
- server_queue(ZServerDesc_t *, int, caddr_t, int, sockaddr_in *);
+ server_flush P((ZServerDesc_t *)),
+ hello_respond P((struct sockaddr_in *, int, int)),
+ srv_responded P((struct sockaddr_in *)),
+ send_msg P((struct sockaddr_in *, char *, int)),
+ send_msg_list P((struct sockaddr_in *, char *, char **, int, int)),
+ srv_nack_cancel P((ZNotice_t *, struct sockaddr_in *)),
+ srv_nack_release P((ZServerDesc_t *)),
+ srv_nack_renumber P((int *)),
+ server_lost P((ZServerDesc_t *)),
+ send_stats P((struct sockaddr_in *)),
+ server_queue P((ZServerDesc_t *, int, caddr_t, int, struct sockaddr_in *));
#define STATIC /* should be static, but is friend elsewhere */
STATIC void
- server_hello(ZServerDesc_t *, int),
- setup_server(ZServerDesc_t *, in_addr *),
- srv_rexmit(void *),
- server_forw_reliable(ZServerDesc_t *, caddr_t, int, ZNotice_t *);
+ server_hello P((ZServerDesc_t *, int)),
+ setup_server P((ZServerDesc_t *, struct in_addr *)),
+ srv_rexmit P((void *)),
+ server_forw_reliable P((ZServerDesc_t *, caddr_t, int, ZNotice_t *));
static Code_t
- admin_dispatch(ZNotice_t *, int, sockaddr_in *, ZServerDesc_t *),
- recover_clt(ZNotice_t *, ZServerDesc_t *),
- kill_clt(ZNotice_t *),
- extract_addr (ZNotice_t *, sockaddr_in *);
+ admin_dispatch P((ZNotice_t *, int, struct sockaddr_in *,
+ ZServerDesc_t *)),
+ recover_clt P((ZNotice_t *, ZServerDesc_t *)),
+ kill_clt P((ZNotice_t *, ZServerDesc_t *)),
+ extract_addr P((ZNotice_t *, struct sockaddr_in *));
+
#ifdef notdef
static Code_t server_register();
#endif
-static struct in_addr *get_server_addrs(int *number);
+static struct in_addr *get_server_addrs P((int *number));
#ifndef HESIOD
-static char **get_server_list(char *file);
-static void free_server_list(char **list);
+static char **get_server_list P((char *file));
+static void free_server_list P((char **list));
#endif
+#undef P
+
+
ZNotAcked_t *srv_nacklist; /* not acked list for server-server
packets */
ZServerDesc_t *otherservers; /* points to an array of the known
@@ -130,8 +139,8 @@ int new_compat_count_subscr = 0;
#endif /* NEW_COMPAT */
#ifdef DEBUG
-extern int zalone;
-#endif DEBUG
+int zalone;
+#endif /* DEBUG */
/*
* Initialize the array of servers. The `limbo' server goes in the first
* slot (otherservers[0]).
@@ -141,7 +150,7 @@ extern int zalone;
*/
void
-server_init(void)
+server_init()
{
register int i;
struct in_addr *serv_addr, *server_addrs, limbo_addr;
@@ -159,7 +168,7 @@ server_init(void)
if (zalone)
nservers = 1;
else
-#endif DEBUG
+#endif /* DEBUG */
/* increment servers to make room for 'limbo' */
nservers++;
@@ -180,7 +189,7 @@ server_init(void)
/* is this me? */
if (serv_addr->s_addr == my_addr.s_addr) {
me_server_idx = i;
- otherservers[i].set_state (SERV_UP);
+ otherservers[i].zs_state = SERV_UP;
timer_reset(otherservers[i].zs_timer);
otherservers[i].zs_timer = (timer) NULL;
otherservers[i].zs_update_queue = NULLZSPT;
@@ -203,7 +212,7 @@ server_init(void)
}
setup_server(&otherservers[nservers - 1], &my_addr);
/* we are up. */
- otherservers[nservers - 1].set_state (SERV_UP);
+ otherservers[nservers - 1].zs_state = SERV_UP;
/* I don't send hello's to myself--cancel the timer */
timer_reset(otherservers[nservers - 1].zs_timer);
@@ -215,7 +224,9 @@ server_init(void)
for (i = 1; i < nservers - 1; i++) {
timer_reset(otherservers[i].zs_timer);
/* all the HELLO's are due now */
- otherservers[i].zs_timer = timer_set_rel(0L, server_timo, (caddr_t) &otherservers[i]);
+ otherservers[i].zs_timer =
+ timer_set_rel(0L, server_timo, (void *)
+ &otherservers[i]);
}
me_server_idx = nservers - 1;
}
@@ -243,7 +254,7 @@ server_init(void)
* handle on a particular server other than by indexing on otherservers[].
*/
void
-server_reset(void)
+server_reset()
{
int num_servers;
struct in_addr *server_addrs;
@@ -261,19 +272,19 @@ server_reset(void)
syslog(LOG_INFO, "server_reset while alone, punt");
return;
}
-#endif DEBUG
+#endif /* DEBUG */
/* Find out what servers are supposed to be known. */
if (!(server_addrs = get_server_addrs(&num_servers))) {
syslog(LOG_ERR, "server_reset no servers. nothing done.");
return;
}
- ok_list_new = (int *) LOCAL_ALLOC (num_servers * sizeof (int));
+ ok_list_new = (int *) xmalloc (num_servers * sizeof (int));
if (ok_list_new == (int *) 0) {
syslog(LOG_ERR, "server_reset no mem new");
return;
}
- ok_list_old = (int *) LOCAL_ALLOC (nservers * sizeof (int));
+ ok_list_old = (int *) xmalloc (nservers * sizeof (int));
if (ok_list_old == (int *) 0) {
syslog(LOG_ERR, "server_reset no mem old");
xfree(ok_list_new);
@@ -321,7 +332,7 @@ server_reset(void)
/* since we are never SERV_DEAD, the following
test prevents removing ourself from the list */
if (ok_list_old[j] ||
- (otherservers[j].state() != SERV_DEAD)) {
+ (otherservers[j].zs_state != SERV_DEAD)) {
syslog(LOG_INFO, "keeping server %s",
otherservers[j].addr);
new_num++;
@@ -335,13 +346,13 @@ server_reset(void)
i = 1;
servers[0] = otherservers[0]; /* copy limbo */
- srv = (int*) LOCAL_ALLOC (nservers * sizeof (int));
+ srv = (int*) xmalloc (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].state() != SERV_DEAD) {
+ otherservers[j].zs_state != SERV_DEAD) {
servers[i] = otherservers[j];
srv[j] = i;
i++;
@@ -356,6 +367,7 @@ server_reset(void)
srv_nack_renumber (srv);
hostm_renumber_servers (srv);
+ xfree(srv);
xfree(otherservers);
otherservers = servers;
nservers = new_num;
@@ -368,7 +380,6 @@ server_reset(void)
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");
@@ -408,14 +419,14 @@ server_reset(void)
if (i != me_server_idx && !otherservers[i].zs_timer) {
otherservers[i].zs_timer =
timer_set_rel(0L, server_timo,
- (caddr_t) &otherservers[i]);
+ (void *) &otherservers[i]);
#if 0
zdbug((LOG_DEBUG, "reset timer for %s",
otherservers[i].addr));
#endif
}
- LOCAL_FREE (ok_list_old);
- LOCAL_FREE (ok_list_new);
+ xfree(ok_list_old);
+ xfree(ok_list_new);
#if 0
zdbug((LOG_DEBUG, "server_reset: %d servers now", nservers));
@@ -442,33 +453,38 @@ srv_states[] = {
*/
void
+#ifdef __STDC__
server_timo(void* arg)
+#else
+server_timo(arg)
+ void* arg;
+#endif
{
ZServerDesc_t *which = (ZServerDesc_t *) arg;
- int auth;
+ int auth = 0;
#if 0
zdbug((LOG_DEBUG,"srv_timo: %s", which->addr));
#endif
/* change state and reset if appropriate */
- switch(which->state()) {
+ switch(which->zs_state) {
case SERV_DEAD: /* leave him dead */
server_flush(which);
auth = 1;
break;
case SERV_UP: /* he's now tardy */
- which->set_state (SERV_TARDY);
+ which->zs_state = SERV_TARDY;
which->zs_numsent = 0;
which->zs_timeout = timo_tardy;
auth = 0;
break;
case SERV_TARDY:
case SERV_STARTING:
- if (which->zs_numsent >= ((which->state() == SERV_TARDY) ?
+ if (which->zs_numsent >= ((which->zs_state == SERV_TARDY) ?
H_NUM_TARDY :
H_NUM_STARTING)) {
/* he hasn't answered, assume DEAD */
- which->set_state (SERV_DEAD);
+ which->zs_state = SERV_DEAD;
which->zs_numsent = 0;
which->zs_timeout = timo_dead;
server_lost(which);
@@ -483,43 +499,45 @@ server_timo(void* arg)
We send a "hello," which increments the counter */
#if 0
zdbug((LOG_DEBUG, "srv %s is %s", which->addr,
- srv_states[(int) which->state()]));
+ 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,
- (caddr_t) which);
+ (void *) which);
}
/*
* Dispatch a notice from some other server
*/
-extern statistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
-
/*ARGSUSED*/
Code_t
-server_dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who)
+server_dispatch(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
ZServerDesc_t *server;
struct sockaddr_in newwho;
Code_t status;
- Notice notice = n;
+ ZSTRING *notice_class;
+
#if 1
zdbug((LOG_DEBUG, "server_dispatch"));
#endif
- if (notice.notice->z_kind == SERVACK) {
- srv_nack_cancel(notice.notice, who);
+ if (notice->z_kind == SERVACK) {
+ srv_nack_cancel(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.notice->z_sender_addr.s_addr;
- newwho.sin_port = notice.notice->z_port;
+ newwho.sin_addr.s_addr = notice->z_sender_addr.s_addr;
+ newwho.sin_port = notice->z_port;
server = server_which_server(who);
@@ -528,31 +546,34 @@ server_dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who)
to the caller, and the caller will re-queue the message
for us to process later. */
- if (class_is_admin(notice)) {
+ notice_class = make_zstring(notice->z_class_inst,1);
+
+ if (class_is_admin(notice_class)) {
/* admins don't get acked, else we get a packet loop */
/* will return requeue if bdump request and dumping */
- i_s_admins++;
- return(admin_dispatch(notice.notice, auth, who, server));
- } else if (class_is_control(notice)) {
- status = control_dispatch(notice.notice, auth, &newwho, server);
- i_s_ctls++;
+ i_s_admins.val++;
+ return(admin_dispatch(notice, auth, who, server));
+ } else if (class_is_control(notice_class)) {
+ status = control_dispatch(notice, auth, &newwho, server);
+ i_s_ctls.val++;
}
- else if (class_is_ulogin(notice)) {
- status = ulogin_dispatch(notice.notice, auth, &newwho, server);
- i_s_logins++;
+ else if (class_is_ulogin(notice_class)) {
+ status = ulogin_dispatch(notice, auth, &newwho, server);
+ i_s_logins.val++;
}
- else if (class_is_ulocate(notice)) {
- status = ulocate_dispatch(notice.notice, auth, &newwho, server);
- i_s_locates++;
+ else if (class_is_ulocate(notice_class)) {
+ status = ulocate_dispatch(notice, auth, &newwho, server);
+ i_s_locates.val++;
}
else {
/* shouldn't come from another server */
syslog(LOG_WARNING, "srv_disp: pkt cls %s",
- notice.notice->z_class);
+ notice->z_class);
status = ZERR_NONE; /* XXX */
}
if (status != ZSRV_REQUEUE)
- ack(notice.notice, who); /* acknowledge it if processed */
+ ack(notice, who); /* acknowledge it if processed */
+ free_zstring(notice_class);
return(status);
}
@@ -564,20 +585,23 @@ server_dispatch(ZNotice_t *n, int auth, struct sockaddr_in *who)
/*ARGSUSED*/
static Code_t
server_register(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
ZServerDesc_t *temp;
register int i;
long timerval;
- SignalBlock omask (sigmask(SIGFPE)); /* don't do ascii dumps */
+ int old_mask;
+
+ old_mask = sigblock(sigmask(SIGFPE));
if (who->sin_port != sock_sin.sin_port) {
#if 0
zdbug((LOG_DEBUG, "srv_register wrong port %d",
ntohs(who->sin_port)));
#endif
+ sigsetmask(old_mask);
return 1;
}
/* Not yet... talk to ken about authenticators */
@@ -586,13 +610,15 @@ struct sockaddr_in *who;
#if 0
zdbug((LOG_DEBUG, "srv_register unauth"));
#endif
+ sigsetmask(old_mask);
return 1;
}
#endif notdef
/* OK, go ahead and set him up. */
- temp = (ZServerDesc_t *)malloc((unsigned) ((nservers + 1) * sizeof(ZServerDesc_t)));
+ temp = (ZServerDesc_t *)xmalloc((unsigned) ((nservers + 1) * sizeof(ZServerDesc_t)));
if (!temp) {
syslog(LOG_CRIT, "srv_reg malloc");
+ sigsetmask(old_mask);
return 1;
}
bcopy((caddr_t) otherservers, (caddr_t) temp, nservers * sizeof(ZServerDesc_t));
@@ -608,7 +634,7 @@ struct sockaddr_in *who;
otherservers[i].zs_timer = timer_set_abs(timerval, server_timo, (caddr_t) &otherservers[i]);
}
setup_server(&otherservers[nservers], &who->sin_addr);
- otherservers[nservers].set_state (SERV_STARTING);
+ otherservers[nservers].zs_state = SERV_STARTING;
otherservers[nservers].zs_timeout = timo_tardy;
otherservers[nservers].zs_update_queue = NULLZSPT;
otherservers[nservers].zs_dumping = 0;
@@ -616,8 +642,9 @@ struct sockaddr_in *who;
nservers++;
#if 0
zdbug((LOG_DEBUG, "srv %s is %s", otherservers[nservers].addr,
- srv_states[(int) otherservers[nservers].state()]));
+ srv_states[(int) otherservers[nservers].zs_state]));
#endif
+ sigsetmask(old_mask);
return 0;
}
#endif
@@ -628,7 +655,8 @@ struct sockaddr_in *who;
*/
void
-server_recover(ZClient_t *client)
+server_recover(client)
+ ZClient_t *client;
{
ZServerDesc_t *server;
char *lyst[2];
@@ -666,7 +694,8 @@ server_recover(ZClient_t *client)
*/
void
-server_kill_clt(ZClient_t *client)
+server_kill_clt(client)
+ ZClient_t *client;
{
register int i;
char buf[512], *lyst[2];
@@ -704,7 +733,7 @@ server_kill_clt(ZClient_t *client)
for (i = 1; i < nservers; i++) {
if (i == me_server_idx) /* don't xmit to myself */
continue;
- if (otherservers[i].state() == SERV_DEAD)
+ if (otherservers[i].zs_state == SERV_DEAD)
continue;
if ((retval = ZFormatNoticeList(pnotice, lyst, 2, &pack, &packlen, auth ? ZAUTH : ZNOAUTH)) != ZERR_NONE) {
@@ -721,7 +750,9 @@ server_kill_clt(ZClient_t *client)
*/
static Code_t
-kill_clt(ZNotice_t *notice, ZServerDesc_t *server)
+kill_clt(notice, server)
+ ZNotice_t *notice;
+ ZServerDesc_t *server;
{
struct sockaddr_in who;
ZHostList_t *host;
@@ -762,7 +793,9 @@ kill_clt(ZNotice_t *notice, ZServerDesc_t *server)
* Another server asked us to initiate recovery protocol with the hostmanager
*/
static Code_t
-recover_clt(register ZNotice_t *notice, ZServerDesc_t *server)
+recover_clt(notice, server)
+ register ZNotice_t *notice;
+ ZServerDesc_t *server;
{
struct sockaddr_in who;
ZClient_t *client;
@@ -795,7 +828,9 @@ recover_clt(register ZNotice_t *notice, ZServerDesc_t *server)
*/
static Code_t
-extract_addr(ZNotice_t *notice, struct sockaddr_in *who)
+extract_addr(notice, who)
+ ZNotice_t *notice;
+ struct sockaddr_in *who;
{
register char *cp = notice->z_message;
@@ -824,7 +859,8 @@ extract_addr(ZNotice_t *notice, struct sockaddr_in *who)
*/
static void
-server_flush(register ZServerDesc_t *which)
+server_flush(which)
+ register ZServerDesc_t *which;
{
register ZHostList_t *hst;
@@ -855,7 +891,9 @@ server_flush(register ZServerDesc_t *which)
*/
STATIC void
-server_hello(ZServerDesc_t *which, int auth)
+server_hello(which, auth)
+ ZServerDesc_t *which;
+ int auth;
{
send_msg(&which->zs_addr, ADMIN_HELLO, auth);
(which->zs_numsent)++;
@@ -868,7 +906,11 @@ server_hello(ZServerDesc_t *which, int auth)
/*ARGSUSED*/
static Code_t
-admin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
+admin_dispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
register char *opcode = notice->z_opcode;
Code_t status = ZERR_NONE;
@@ -888,13 +930,13 @@ admin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc
/* we need to transfer all of its hosts to limbo */
if (server) {
server_lost(server);
- server->set_state (SERV_DEAD);
+ server->zs_state = SERV_DEAD;
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", server->addr,
- srv_states[(int) server->state()]));
+ srv_states[(int) server->zs_state]));
#endif
}
} else if (!strcmp(opcode, ADMIN_BDUMP)) {
@@ -926,7 +968,8 @@ admin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc
*/
static void
-server_lost(ZServerDesc_t *server)
+server_lost(server)
+ ZServerDesc_t *server;
{
register ZHostList_t *host, *hishost;
@@ -948,7 +991,11 @@ server_lost(ZServerDesc_t *server)
/*ARGSUSED*/
Code_t
-server_adispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
+server_adispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
/* this had better be a HELLO message--start of acquisition
@@ -977,15 +1024,14 @@ server_adispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDe
}
static void
-send_stats(struct sockaddr_in *who)
+send_stats(who)
+ 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;
@@ -994,38 +1040,12 @@ send_stats(struct sockaddr_in *who)
/* well, not really...but for
backward compatibility, we gotta
do it this way. */
- (void) strcpy(buf,version);
- (void) strcat(buf, "/");
-#ifdef vax
- (void) strcat(buf, "VAX");
-#endif /* vax */
-#ifdef ibm032
- (void) strcat(buf, "IBM 032");
-#endif /* ibm032 */
-#ifdef sun
- (void) strcat(buf, "SUN");
-#ifdef sparc
- (void) strcat (buf, "-4");
-#endif
-#ifdef sun386
- (void) strcat (buf, "-386I");
-#endif
-#endif /* sun */
-#ifdef mips
-#ifdef ultrix /* DECstation */
- (void) strcat (buf, "DEC-");
-#endif
- (void) strcat(buf, "MIPS");
-#endif /* mips */
-#ifdef NeXT
- (void) strcat(buf, "NeXT");
-#endif /* NeXT */
- vers = lstrdup (buf);
+ vers = get_version();
(void) sprintf(buf, "%d pkts", npackets);
- pkts = lstrdup (buf);
+ pkts = strsave(buf);
(void) sprintf(buf, "%d seconds operational",NOW - uptime);
- upt = lstrdup (buf);
+ upt = strsave(buf);
#ifdef OLD_COMPAT
if (old_compat_count_uloc) extrafields++;
@@ -1037,11 +1057,11 @@ send_stats(struct sockaddr_in *who)
if (new_compat_count_subscr) extrafields++;
#endif /* NEW_COMPAT */
#if defined(OLD_COMPAT) || defined(NEW_COMPAT)
- responses = (char **) LOCAL_ALLOC ((NUM_FIXED + nservers +
- extrafields) * sizeof(char **));
+ responses = (char **) xmalloc((NUM_FIXED + nservers + extrafields) *
+ sizeof(char **));
#else
- responses = (char **) LOCAL_ALLOC ((NUM_FIXED + nservers)
- *sizeof(char **));
+ responses = (char **) xmalloc ((NUM_FIXED + nservers) *
+ sizeof(char **));
#endif /* OLD_ or NEW_COMPAT */
responses[0] = vers;
responses[1] = pkts;
@@ -1051,44 +1071,45 @@ send_stats(struct sockaddr_in *who)
/* start at 1 and ignore limbo */
for (i = 1; i < nservers ; i++) {
(void) sprintf(buf, "%s/%s%s", otherservers[i].addr,
- srv_states[(int) otherservers[i].state()],
+ srv_states[(int) otherservers[i].zs_state],
otherservers[i].zs_dumping ? " (DUMPING)" : "");
- responses[num_resp++] = lstrdup (buf);
+ responses[num_resp++] = strsave (buf);
}
#ifdef OLD_COMPAT
if (old_compat_count_uloc) {
(void) sprintf(buf, "%d old old location requests",
old_compat_count_uloc);
- responses[num_resp++] = lstrdup (buf);
+ responses[num_resp++] = strsave (buf);
}
if (old_compat_count_ulocate) {
(void) sprintf(buf, "%d old old loc lookup requests",
old_compat_count_ulocate);
- responses[num_resp++] = lstrdup (buf);
+ responses[num_resp++] = strsave (buf);
}
if (old_compat_count_subscr) {
(void) sprintf(buf, "%d old old subscr requests",
old_compat_count_subscr);
- responses[num_resp++] = lstrdup (buf);
+ responses[num_resp++] = strsave (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++] = lstrdup (buf);
+ responses[num_resp++] = strsave (buf);
}
if (new_compat_count_subscr) {
(void) sprintf(buf, "%d new old subscr requests",
new_compat_count_subscr);
- responses[num_resp++] = lstrdup (buf);
+ responses[num_resp++] = strsave (buf);
}
#endif /* NEW_COMPAT */
send_msg_list(who, ADMIN_STATUS, responses, num_resp, 0);
- for (i = 0; i < num_resp; i++)
- LOCAL_FREE (responses[i]);
- LOCAL_FREE (responses);
+ /* Start at one; don't try to free static version string */
+ for (i = 1; i < num_resp; i++)
+ xfree(responses[i]);
+ xfree(responses);
return;
}
@@ -1104,7 +1125,8 @@ send_stats(struct sockaddr_in *who)
*/
static struct in_addr *
-get_server_addrs(int *number) /* RETURN */
+get_server_addrs(number)
+ int *number; /* RETURN */
{
register int i;
char **server_hosts;
@@ -1154,7 +1176,8 @@ static int nhosts = 0;
*/
static char **
-get_server_list(char *file)
+get_server_list(file)
+ char *file;
{
FILE *fp;
char buf[MAXHOSTNAMELEN];
@@ -1194,7 +1217,8 @@ get_server_list(char *file)
* free storage allocated by get_server_list
*/
static void
-free_server_list(register char **list)
+free_server_list(list)
+ register char **list;
{
char **orig_list = list;
@@ -1213,11 +1237,13 @@ free_server_list(register char **list)
*/
STATIC void
-setup_server(register ZServerDesc_t *server, struct in_addr *addr)
+setup_server(server, addr)
+ register ZServerDesc_t *server;
+ struct in_addr *addr;
{
register ZHostList_t *host;
- server->set_state (SERV_DEAD);
+ server->zs_state = SERV_DEAD;
server->zs_timeout = timo_dead;
server->zs_numsent = 0;
server->zs_addr.sin_family = AF_INET;
@@ -1227,8 +1253,8 @@ setup_server(register ZServerDesc_t *server, struct in_addr *addr)
strcpy (server->addr, inet_ntoa (*addr));
/* set up a timer for this server */
- server->zs_timer = timer_set_rel(0L, server_timo, (caddr_t) server);
- host = new ZHostList_t;
+ server->zs_timer = timer_set_rel(0L, server_timo, (void *) server);
+ host = (ZHostList_t *) xmalloc(sizeof(ZHostList_t));
if (!host) {
/* unrecoverable */
syslog(LOG_CRIT, "zs_host alloc");
@@ -1248,7 +1274,10 @@ setup_server(register ZServerDesc_t *server, struct in_addr *addr)
*/
static void
-hello_respond(struct sockaddr_in *who, int adj, int auth)
+hello_respond(who, adj, auth)
+ struct sockaddr_in *who;
+ int adj;
+ int auth;
{
register ZServerDesc_t *which;
@@ -1265,13 +1294,13 @@ hello_respond(struct sockaddr_in *who, int adj, int auth)
if (!(which = server_which_server(who)))
return;
- switch (which->state()) {
+ switch (which->zs_state) {
case SERV_DEAD:
/* he said hello, we thought he was dead.
reschedule his hello for now. */
timer_reset(which->zs_timer);
which->zs_timer = timer_set_rel(0L, server_timo,
- (caddr_t) which);
+ (void *) which);
break;
case SERV_STARTING:
case SERV_TARDY:
@@ -1287,7 +1316,8 @@ hello_respond(struct sockaddr_in *who, int adj, int auth)
*/
ZServerDesc_t *
-server_which_server(struct sockaddr_in *who)
+server_which_server(who)
+ struct sockaddr_in *who;
{
register ZServerDesc_t *server;
register int i;
@@ -1308,7 +1338,8 @@ server_which_server(struct sockaddr_in *who)
* appropriately.
*/
static void
-srv_responded(struct sockaddr_in *who)
+srv_responded(who)
+ struct sockaddr_in *who;
{
register ZServerDesc_t *which = server_which_server(who);
@@ -1321,15 +1352,15 @@ srv_responded(struct sockaddr_in *who)
return;
}
- switch (which->state()) {
+ switch (which->zs_state) {
case SERV_DEAD:
/* he responded, we thought he was dead. mark as starting
and negotiate */
- which->set_state (SERV_STARTING);
+ which->zs_state = SERV_STARTING;
which->zs_timeout = timo_tardy;
timer_reset(which->zs_timer);
which->zs_timer = timer_set_rel(0L, server_timo,
- (caddr_t) which);
+ (void *) which);
case SERV_STARTING:
/* here we negotiate and set up a braindump */
@@ -1339,19 +1370,19 @@ srv_responded(struct sockaddr_in *who)
}
break;
case SERV_TARDY:
- which->set_state (SERV_UP);
+ which->zs_state = SERV_UP;
case SERV_UP:
/* reset the timer and counts */
which->zs_numsent = 0;
which->zs_timeout = timo_up;
timer_reset(which->zs_timer);
which->zs_timer = timer_set_rel(which->zs_timeout, server_timo,
- (caddr_t) which);
+ (void *) which);
break;
}
#if 0
zdbug((LOG_DEBUG, "srv %s is %s", which->addr,
- srv_states[(int) which->state()]));
+ srv_states[(int) which->zs_state]));
#endif
return;
}
@@ -1361,7 +1392,7 @@ srv_responded(struct sockaddr_in *who)
*/
void
-server_shutdown(void)
+server_shutdown()
{
register int i;
@@ -1378,7 +1409,10 @@ server_shutdown(void)
*/
static void
-send_msg(struct sockaddr_in *who, char *opcode, int auth)
+send_msg(who, opcode, auth)
+ struct sockaddr_in *who;
+ char *opcode;
+ int auth;
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
@@ -1433,18 +1467,23 @@ send_msg(struct sockaddr_in *who, char *opcode, int auth)
*/
static void
-send_msg_list(struct sockaddr_in *who, char *opcode, char **lyst, int num,
- int auth)
+send_msg_list(who, opcode, lyst, num, auth)
+ struct sockaddr_in *who;
+ char *opcode;
+ char **lyst;
+ int num;
+ int auth;
{
ZNotice_t notice;
register ZNotice_t *pnotice; /* speed hack */
char *pack;
int packlen;
Code_t retval;
+ register ZNotAcked_t *nacked;
pnotice = &notice;
- pnotice->z_kind = ACKED;
+ pnotice->z_kind = UNSAFE;
pnotice->z_port = sock_sin.sin_port;
pnotice->z_class = ZEPHYR_ADMIN_CLASS;
@@ -1478,7 +1517,28 @@ send_msg_list(struct sockaddr_in *who, char *opcode, char **lyst, int num,
xfree(pack); /* free allocated storage */
return;
}
- xfree(pack); /* free allocated storage */
+
+ if (!(nacked = (ZNotAcked_t *)xmalloc(sizeof(ZNotAcked_t)))) {
+ /* no space: just punt */
+ syslog(LOG_WARNING, "xmit nack malloc");
+ xfree(pack);
+ return;
+ }
+
+ nacked->na_rexmits = 0;
+ nacked->na_packet = pack;
+ nacked->na_addr = *who;
+ nacked->na_packsz = packlen;
+ nacked->na_uid = pnotice->z_uid;
+ nacked->q_forw = nacked->q_back = nacked;
+ nacked->na_abstimo = NOW + abs_timo;
+
+ /* set a timer to retransmit when done */
+ nacked->na_timer = timer_set_rel(rexmit_secs,
+ rexmit,
+ (void *) nacked);
+ /* chain in */
+ xinsque(nacked, nacklist);
return;
}
@@ -1487,7 +1547,10 @@ send_msg_list(struct sockaddr_in *who, char *opcode, char **lyst, int num,
*/
/*ARGSUSED*/
void
-server_forward(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+server_forward(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
register int i;
caddr_t pack;
@@ -1501,7 +1564,7 @@ server_forward(ZNotice_t *notice, int auth, struct sockaddr_in *who)
for (i = 1; i < nservers; i++) {
if (i == me_server_idx) /* don't xmit to myself */
continue;
- if (otherservers[i].state() == SERV_DEAD &&
+ if (otherservers[i].zs_state == SERV_DEAD &&
otherservers[i].zs_dumping == 0)
/* if we are dumping to him, we want to
queue it, even if he's dead */
@@ -1527,8 +1590,11 @@ server_forward(ZNotice_t *notice, int auth, struct sockaddr_in *who)
}
STATIC void
-server_forw_reliable(ZServerDesc_t *server, caddr_t pack, int packlen,
- ZNotice_t *notice)
+server_forw_reliable(server, pack, packlen, notice)
+ ZServerDesc_t *server;
+ caddr_t pack;
+ int packlen;
+ ZNotice_t *notice;
{
Code_t retval;
register ZNotAcked_t *nacked;
@@ -1564,7 +1630,7 @@ server_forw_reliable(ZServerDesc_t *server, caddr_t pack, int packlen,
/* set a timer to retransmit */
nacked->na_timer = timer_set_rel(srv_rexmit_secs,
srv_rexmit,
- (caddr_t) nacked);
+ (void *) nacked);
/* chain in */
xinsque(nacked, srv_nacklist);
return;
@@ -1576,7 +1642,8 @@ server_forw_reliable(ZServerDesc_t *server, caddr_t pack, int packlen,
*/
void
-server_send_queue(ZServerDesc_t *server)
+server_send_queue(server)
+ ZServerDesc_t *server;
{
register ZSrvPending_t *pending;
ZNotice_t notice;
@@ -1607,7 +1674,9 @@ server_send_queue(ZServerDesc_t *server)
*/
static void
-srv_nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
+srv_nack_cancel(notice, who)
+ register ZNotice_t *notice;
+ struct sockaddr_in *who;
{
register ZServerDesc_t *which = server_which_server(who);
register ZNotAcked_t *nacked;
@@ -1638,7 +1707,12 @@ srv_nack_cancel(register ZNotice_t *notice, struct sockaddr_in *who)
*/
STATIC void
+#ifdef __STDC__
srv_rexmit(void *arg)
+#else
+srv_rexmit(arg)
+ void *arg;
+#endif
{
ZNotAcked_t *nackpacket = (ZNotAcked_t *) arg;
Code_t retval;
@@ -1649,7 +1723,7 @@ srv_rexmit(void *arg)
otherservers[nackpacket->na_srv_idx].addr,
ntohs(otherservers[nackpacket->na_srv_idx].zs_addr.sin_port)));
#endif
- if (otherservers[nackpacket->na_srv_idx].state() == SERV_DEAD) {
+ if (otherservers[nackpacket->na_srv_idx].zs_state == SERV_DEAD) {
#if 0
zdbug((LOG_DEBUG, "cancelling send to dead server"));
#endif
@@ -1675,7 +1749,7 @@ requeue:
/* reset the timer */
nackpacket->na_timer = timer_set_rel(srv_rexmit_secs,
srv_rexmit,
- (caddr_t) nackpacket);
+ (void *) nackpacket);
return;
}
@@ -1685,7 +1759,8 @@ requeue:
*/
static void
-srv_nack_release(ZServerDesc_t *server)
+srv_nack_release(server)
+ ZServerDesc_t *server;
{
/* XXX release any private queue for this server */
@@ -1716,7 +1791,8 @@ srv_nack_release(ZServerDesc_t *server)
*/
static void
-srv_nack_renumber (register int* new_idx)
+srv_nack_renumber (new_idx)
+ register int* new_idx;
{
/* XXX release any private queue for this server */
@@ -1740,8 +1816,12 @@ srv_nack_renumber (register int* new_idx)
* Queue this notice to be transmitted to the server when it is ready.
*/
static void
-server_queue(ZServerDesc_t *server, int len, caddr_t pack, int auth,
- struct sockaddr_in *who)
+server_queue(server, len, pack, auth, who)
+ ZServerDesc_t *server;
+ int len;
+ caddr_t pack;
+ int auth;
+ struct sockaddr_in *who;
{
register ZSrvPending_t *pending;
@@ -1773,7 +1853,8 @@ server_queue(ZServerDesc_t *server, int len, caddr_t pack, int auth,
*/
ZSrvPending_t *
-server_dequeue(register ZServerDesc_t *server)
+server_dequeue(server)
+ register ZServerDesc_t *server;
{
ZSrvPending_t *pending;
@@ -1795,7 +1876,8 @@ server_dequeue(register ZServerDesc_t *server)
*/
void
-server_pending_free(register ZSrvPending_t *pending)
+server_pending_free(pending)
+ register ZSrvPending_t *pending;
{
xfree(pending->pend_packet);
xfree(pending);
@@ -1808,7 +1890,10 @@ server_pending_free(register ZSrvPending_t *pending)
*/
void
-server_self_queue(ZNotice_t* notice, int auth, sockaddr_in * who)
+server_self_queue(notice, auth, who)
+ ZNotice_t* notice;
+ int auth;
+ struct sockaddr_in * who;
{
caddr_t pack;
int packlen;
@@ -1831,14 +1916,15 @@ server_self_queue(ZNotice_t* notice, int auth, sockaddr_in * who)
* (true if called from signal handler)
*/
void
-server_dump_servers(FILE *fp)
+server_dump_servers(fp)
+ FILE *fp;
{
register int i;
for (i = 0; i < nservers ; i++) {
(void) fprintf(fp, "%d:%s/%s%s\n",
i, otherservers[i].addr,
- srv_states[(int) otherservers[i].state()],
+ srv_states[(int) otherservers[i].zs_state],
otherservers[i].zs_dumping ? " (DUMPING)" : "");
}
diff --git a/server/subscr.c b/server/subscr.c
index 0d4308a..a2b6be0 100644
--- a/server/subscr.c
+++ b/server/subscr.c
@@ -65,40 +65,50 @@ static char rcsid_subscr_c[] = "$Id$";
#include <strings.h>
#include <sys/stat.h>
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
/* 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(ZNotice_t *notice, int auth, struct sockaddr_in *who);
+static void old_compat_subscr_sendlist P((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(ZNotice_t *notice, int auth, struct sockaddr_in *who);
+static void new_old_compat_subscr_sendlist P((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();
-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,
+static ZSubscr_t *extract_subscriptions P((register ZNotice_t *notice));
+static int clt_unique P((ZClient_t *clt, ZClientList_t *clist));
+static void free_subscriptions P((register ZSubscr_t *subs));
+static char **subscr_marshal_subs P((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 *);
+ register int *found));
+static Code_t subscr_subscribe_real P((ZClient_t *who, ZSubscr_t *newsubs,
+ ZNotice_t *notice));
+static ZSubscr_t *subscr_copy_def_subs P((char *));
+static int cl_match P((ZSubscr_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 */
-extern const ZString wildcard_class (MATCHALL_CLASS, 1);
-extern const ZString wildcard_instance (WILDCARD_INSTANCE, 1);
+#undef P
-static ZString empty ("");
-static ZSubscr_t matchall_sub (wildcard_class, empty, empty);
+ZSTRING *wildcard_class;
+ZSTRING *wildcard_instance;
+ZSTRING *empty;
+ZSubscr_t matchall_sub;
/* 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, */
@@ -110,16 +120,21 @@ static ZSubscr_t matchall_sub (wildcard_class, empty, empty);
*/
Code_t
-subscr_subscribe(ZClient_t *who, ZNotice_t *notice)
+subscr_subscribe(who, notice)
+ ZClient_t *who;
+ ZNotice_t *notice;
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- subs = new ZSubscr_t;
- if (!subs)
+ if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t))))
return(ENOMEM);
+ subs->q_forw = subs->q_back = subs;
+ subs->zst_dest.classname = subs->zst_dest.inst =
+ subs->zst_dest.recip = NULL;
+ subs->zst_dest.hash_value = 0;
who->zct_subs = subs;
}
@@ -130,14 +145,19 @@ subscr_subscribe(ZClient_t *who, ZNotice_t *notice)
}
static Code_t
-subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *notice)
+subscr_subscribe_real(who, newsubs, notice)
+ ZClient_t *who;
+ register ZSubscr_t *newsubs;
+ ZNotice_t *notice;
{
int omask;
Code_t retval;
ZAcl_t *acl;
- ZString sender (notice->z_sender);
- register ZSubscr_t *subs2, *subs3, *subs;
+ ZSTRING *sender;
+ ZSubscr_t *subs2, *subs3, *subs;
+ int relation;
+ sender = make_zstring(notice->z_sender,0);
omask = sigblock(sigmask(SIGFPE)); /* don't let db dumps start */
for (subs = newsubs->q_forw;
subs != newsubs;
@@ -146,53 +166,56 @@ subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *no
#if 1
zdbug ((LOG_DEBUG, "subscr: %s/%s/%s",
- subs->zst_dest.classname.value (),
- subs->zst_dest.inst.value (),
- subs->zst_dest.recip.value ()));
+ subs->zst_dest.classname->string,
+ subs->zst_dest.inst->string,
+ subs->zst_dest.recip->string));
#endif
if (!bdumping
- && *(subs->zst_dest.recip.value ())
- && subs->zst_dest.recip != sender) {
+ && (subs->zst_dest.recip != NULL)
+ && (subs->zst_dest.recip != sender)) {
syslog(LOG_WARNING, "subscr unauth %s recipient %s",
- sender.value (),
- subs->zst_dest.recip.value ());
+ sender->string,
+ subs->zst_dest.recip->string);
continue;
}
if (!bdumping) {
acl = class_get_acl(subs->zst_dest.classname);
if (acl) {
- if (!acl->ok (sender, SUBSCRIBE)) {
+ if (!(access_check(sender->string, acl, SUBSCRIBE))) {
syslog(LOG_WARNING,
"subscr unauth %s class %s",
- sender.value (),
- subs->zst_dest.classname.value ());
+ sender->string,
+ subs->zst_dest.classname->string);
continue; /* the for loop */
}
if (wildcard_instance == subs->zst_dest.inst) {
- if (!acl->ok (sender, INSTWILD)) {
+ if (!access_check(sender->string, acl, INSTWILD)) {
syslog(LOG_WARNING,
"subscr unauth %s class %s wild inst",
notice->z_sender,
- subs->zst_dest.classname.value ());
+ subs->zst_dest.classname->string);
continue;
}
}
}
}
+ /* subscriptions are stored in ascending order by */
+ /* subscription hash value */
+ /* Scan through list to check for duplicates, and to find */
+ /* where to insert these subs */
+
for (subs2 = who->zct_subs->q_forw;
subs2 != who->zct_subs;
subs2 = subs2->q_forw) {
/* for each existing subscription */
- if (*subs >= *subs2)
- break;
- }
- /*
- * Can't put a goto in place of the break above,
- * because cfront can't cope.
- */
- if (subs2 != who->zct_subs && *subs == *subs2)
+ relation = compare_subs(subs2,subs);
+ if (relation > 0) /* we have passed last possible one */
+ break;
+ if (relation < 0) /* nope... */
continue;
+ goto duplicate;
+ }
/* 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
@@ -201,15 +224,23 @@ subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *no
/* ok, we are a new subscription. register and chain on. */
- subs3 = new ZSubscr_t (*subs);
- if (!subs3) {
+ if (!(subs3 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(ENOMEM);
}
+ subs3->q_forw = subs3->q_back = subs3;
+ subs3->zst_dest.classname = subs->zst_dest.classname;
+ subs3->zst_dest.classname->ref_count++;
+ subs3->zst_dest.inst = subs->zst_dest.inst;
+ subs3->zst_dest.inst->ref_count++;
+ subs3->zst_dest.recip = subs->zst_dest.recip;
+ subs3->zst_dest.recip->ref_count++;
+ set_ZDestination_hash(&subs3->zst_dest);
+
if ((retval = class_register(who, subs)) != ZERR_NONE) {
- delete subs3;
+ xfree(subs3);
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(retval);
@@ -217,6 +248,8 @@ subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *no
/* subs2 was adjusted above */
xinsque(subs3, subs2);
+ duplicate:
+ ;
}
(void) sigsetmask(omask);
@@ -229,37 +262,42 @@ subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *no
*/
Code_t
-subscr_def_subs(ZClient_t *who)
+subscr_def_subs(who)
+ ZClient_t *who;
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- subs = new ZSubscr_t;
- if (!subs) {
+ if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
syslog(LOG_ERR, "no mem subscr_def_subs");
return(ENOMEM);
}
+ subs->q_forw = subs->q_back = subs;
+ subs->zst_dest.classname = subs->zst_dest.inst =
+ subs->zst_dest.recip = (ZSTRING *) NULL;
+ subs->zst_dest.hash_value = 0;
who->zct_subs = subs;
}
- subs = subscr_copy_def_subs(who->zct_principal);
+ subs = subscr_copy_def_subs(who->zct_principal->string);
return(subscr_subscribe_real(who, subs, &default_notice));
}
void
-subscr_reset(void)
+subscr_reset()
{
#if 0
zdbug((LOG_DEBUG, "subscr_reset()"));
#endif
xfree(default_notice.z_message);
- default_notice.z_message = 0;
+ default_notice.z_message = NULL;
defaults_read = 0;
}
static ZSubscr_t *
-subscr_copy_def_subs(const ZString& person)
+subscr_copy_def_subs(person)
+ char *person;
{
int retval;
int fd;
@@ -331,18 +369,20 @@ subscr_copy_def_subs(const ZString& person)
defaults_read = 1;
}
/* needed later for access_check() */
- default_notice.z_sender = (char *) person.value ();
+ default_notice.z_sender = person;
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_dest.recip.value (), "*")) {
- subs2->zst_dest.recip = person;
+ if (strcmp(subs2->zst_dest.recip->string, "*")) {
+ free_zstring(subs2->zst_dest.recip);
+ subs2->zst_dest.recip = make_zstring(person,0);
} else { /* replace with null recipient */
+ free_zstring(subs2->zst_dest.recip);
subs2->zst_dest.recip = empty;
}
- subs2->zst_dest.set_hash ();
+ set_ZDestination_hash(&(subs2->zst_dest));
}
return(subs);
}
@@ -352,13 +392,16 @@ subscr_copy_def_subs(const ZString& person)
*/
Code_t
-subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice)
+subscr_cancel(sin, notice)
+ struct sockaddr_in *sin;
+ ZNotice_t *notice;
{
ZClient_t *who;
register ZSubscr_t *subs, *subs2, *subs3, *subs4;
Code_t retval;
int found = 0;
int omask;
+ int relation;
#if 1
zdbug((LOG_DEBUG,"subscr_cancel"));
@@ -379,51 +422,53 @@ subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice)
subs2 != who->zct_subs;) {
/* for each existing subscription */
/* is this what we are canceling? */
- 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;
- break;
- } else {
-#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;
- }
+ relation = compare_subs(subs4, subs2);
+ if (relation < 0) {
+ subs2 = subs2->q_forw;
+ continue;
+ }
+ if (relation > 0)
+ break;
+ /* go back, since remque will change things */
+ subs3 = subs2->q_back;
+ xremque(subs2);
+ (void) class_deregister(who, subs2);
+ free_zstring(subs2->zst_dest.classname);
+ free_zstring(subs2->zst_dest.inst);
+ free_zstring(subs2->zst_dest.recip);
+ xfree(subs2);
+ found = 1;
+ /* now that the remque adjusted the linked
+ list, we go forward again */
+ subs2 = subs3->q_forw;
+ break;
}
- }
+ }
/* make sure we are still registered for all the classes */
- if (found)
- for (subs2 = who->zct_subs->q_forw;
- subs2 != who->zct_subs;
- subs2 = subs2->q_forw)
- if ((retval = class_register(who, subs2)) != ZERR_NONE) {
- free_subscriptions(subs);
- (void) sigsetmask(omask);
- return(retval);
- }
+ if (found) {
+ for (subs2 = who->zct_subs->q_forw;
+ subs2 != who->zct_subs;
+ subs2 = subs2->q_forw)
+ if ((retval = class_register(who, subs2)) != ZERR_NONE) {
+ free_subscriptions(subs);
+ (void) sigsetmask(omask);
+ return(retval);
+ }
+ }
+
(void) sigsetmask(omask);
free_subscriptions(subs);
if (found) {
#if 0
- zdbug((LOG_DEBUG, "found & removed"));
+ zdbug((LOG_DEBUG, "found & removed"));
#endif
- return(ZERR_NONE);
+ return(ZERR_NONE);
} else {
#if 0
- zdbug((LOG_DEBUG, "not found"));
+ zdbug((LOG_DEBUG, "not found"));
#endif
- return(ZSRV_NOSUB);
+ return(ZSRV_NOSUB);
}
}
@@ -432,7 +477,8 @@ subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice)
*/
void
-subscr_cancel_client(ZClient_t *client)
+subscr_cancel_client(client)
+ ZClient_t *client;
{
register ZSubscr_t *subs;
int omask;
@@ -459,12 +505,18 @@ subscr_cancel_client(ZClient_t *client)
}
xremque(subs);
- delete subs;
+ free_zstring(subs->zst_dest.classname);
+ free_zstring(subs->zst_dest.inst);
+ free_zstring(subs->zst_dest.recip);
+ xfree(subs);
}
/* also flush the head of the queue */
/* subs is now client->zct_subs */
- delete subs;
+ free_zstring(subs->zst_dest.classname);
+ free_zstring(subs->zst_dest.inst);
+ free_zstring(subs->zst_dest.recip);
+ xfree(subs);
client->zct_subs = NULLZST;
(void) sigsetmask(omask);
@@ -507,24 +559,29 @@ struct in_addr *addr;
*/
ZClientList_t *
-subscr_match_list(ZNotice_t *notice)
+subscr_match_list(notice)
+ ZNotice_t *notice;
{
register ZClientList_t *hits, *clients, *majik, *clients2, *hit2;
char *saveclass, *saveclinst;
- /* Use this where we can't use "goto" thanks to cfront... */
- int get_out = 0;
+ ZSTRING *newclass;
+ ZSTRING *newclinst;
+ ZSubscr_t check_sub;
if (!(hits = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
return(NULLZCLT);
hits->q_forw = hits->q_back = hits;
saveclass = notice->z_class;
- ZString newclass (notice->z_class, 1);
+ newclass = make_zstring(notice->z_class, 1);
saveclinst = notice->z_class_inst;
- ZString newclinst (saveclinst, 1);
+ newclinst = make_zstring(notice->z_class_inst, 1);
- ZSubscr_t check_sub (newclass, newclinst, notice->z_recipient);
+ check_sub.zst_dest.classname = newclass;
+ check_sub.zst_dest.inst = newclinst;
+ check_sub.zst_dest.recip = make_zstring(notice->z_recipient, 0);
+ set_ZDestination_hash(&check_sub.zst_dest);
check_sub.q_forw = check_sub.q_back = &check_sub;
clients = class_lookup (&check_sub);
@@ -532,30 +589,33 @@ subscr_match_list(ZNotice_t *notice)
if (!clients && !majik)
return NULLZCLT;
- notice->z_class = (char *) newclass.value ();
- notice->z_class_inst = (char *) newclinst.value ();
+ notice->z_class = (char *) newclass->string;
+ notice->z_class_inst = (char *) newclinst->string;
if (clients) {
for (clients2 = clients->q_forw;
clients2 != clients;
clients2 = clients2->q_forw)
- if (cl_match(notice, clients2->zclt_client)) {
+ if (cl_match(&check_sub, clients2->zclt_client)) {
if (!clt_unique(clients2->zclt_client, hits))
continue;
/* we hit */
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match: punting/no mem");
- get_out = 1;
- break;
+ notice->z_class = saveclass;
+ notice->z_class_inst = saveclinst;
+ free_zstring(newclass);
+ free_zstring(newclinst);
+ free_zstring(check_sub.zst_dest.recip);
+ return(hits);
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- if (!get_out)
- class_free(clients);
+ class_free(clients);
}
- if (!get_out && majik) {
+ if (majik) {
for (clients2 = majik->q_forw;
clients2 != majik;
clients2 = clients2->q_forw) {
@@ -565,20 +625,25 @@ subscr_match_list(ZNotice_t *notice)
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match(majik): punting/no mem");
- get_out = 1;
- break;
+ notice->z_class = saveclass;
+ notice->z_class_inst = saveclinst;
+ free_zstring(newclass);
+ free_zstring(newclinst);
+ free_zstring(check_sub.zst_dest.recip);
+ return(hits);
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- if (!get_out)
- class_free(majik);
+ class_free(majik);
}
-/* out:*/
notice->z_class = saveclass;
notice->z_class_inst = saveclinst;
+ free_zstring(newclass);
+ free_zstring(newclinst);
+ free_zstring(check_sub.zst_dest.recip);
if (hits->q_forw == hits) {
xfree(hits);
return(NULLZCLT);
@@ -591,7 +656,8 @@ subscr_match_list(ZNotice_t *notice)
*/
void
-subscr_free_list(ZClientList_t *list)
+subscr_free_list(list)
+ ZClientList_t *list;
{
register ZClientList_t *lyst;
@@ -608,9 +674,12 @@ subscr_free_list(ZClientList_t *list)
*/
void
-subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+subscr_sendlist(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
- const char **answer;
+ char **answer;
int found;
struct sockaddr_in send_to_who;
Code_t retval;
@@ -661,11 +730,15 @@ subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
return;
}
-static const char **
-subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, register int *found)
+static char **
+subscr_marshal_subs(notice, auth, who, found)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ register int *found;
{
ZNotice_t reply;
- const char **answer = (const char **) NULL;
+ char **answer = (char **) 0;
int temp;
Code_t retval;
ZClient_t *client;
@@ -673,7 +746,7 @@ subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, regist
register int i;
int defsubs = 0;
-#if 0
+#if 1
zdbug((LOG_DEBUG, "subscr_marshal"));
#endif
*found = 0;
@@ -739,14 +812,12 @@ subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, regist
return((char **) 0);
}
if (!defsubs) {
- if (!auth)
- return 0;
- if (client && !strcmp (client->zct_principal.value (),
+ if (client && !strcmp (client->zct_principal->string,
notice->z_sender)) {
zdbug ((LOG_DEBUG,
"subscr_marshal: %s requests subs for %s at %s/%d",
notice->z_sender,
- client->zct_principal.value (),
+ client->zct_principal->string,
inet_ntoa (who->sin_addr),
ntohs (who->sin_port)));
return 0;
@@ -768,9 +839,9 @@ subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, regist
for (i = 0, subs = subs2->q_forw;
i < *found ;
i++, subs = subs->q_forw) {
- 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 ();
+ answer[i*NUM_FIELDS] = subs->zst_dest.classname->string;
+ answer[i*NUM_FIELDS + 1] = subs->zst_dest.inst->string;
+ answer[i*NUM_FIELDS + 2] = subs->zst_dest.recip->string;
}
}
if (defsubs)
@@ -780,14 +851,17 @@ subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, regist
#ifdef NEW_COMPAT
static void
-new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+new_old_compat_subscr_sendlist(notice, auth, who)
+ 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];
- const char **answer;
+ Zconst char **answer;
struct sockaddr_in send_to_who;
register int i;
@@ -861,7 +935,10 @@ new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *
#ifdef OLD_COMPAT
static void
-old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+old_compat_subscr_sendlist(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
ZClient_t *client = client_which_client(who, notice);
register ZSubscr_t *subs;
@@ -963,7 +1040,9 @@ old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
/*ARGSUSED*/
Code_t
-subscr_send_subs(ZClient_t *client, char *vers)
+subscr_send_subs(client, vers)
+ ZClient_t *client;
+ char *vers;
{
register int i = 0;
register ZSubscr_t *sub;
@@ -971,7 +1050,7 @@ subscr_send_subs(ZClient_t *client, char *vers)
char buf[512];
#endif /* KERBEROS */
char buf2[512];
- const char *lyst[7 * NUM_FIELDS];
+ char *lyst[7 * NUM_FIELDS];
int num = 0;
Code_t retval;
@@ -995,12 +1074,12 @@ subscr_send_subs(ZClient_t *client, char *vers)
zdbug((LOG_DEBUG,"cblock %s",buf));
#endif
}
-#endif KERBEROS
+#endif /* KERBEROS */
if ((retval = bdump_send_list_tcp(SERVACK, client->zct_sin.sin_port,
ZEPHYR_ADMIN_CLASS,
num > 1 ? "CBLOCK" : "",
ADMIN_NEWCLT,
- (char*)client->zct_principal.value(),
+ (char*)client->zct_principal->string,
"", lyst, num)) != ZERR_NONE ) {
syslog(LOG_ERR, "subscr_send_subs newclt: %s",
error_message(retval));
@@ -1013,9 +1092,9 @@ subscr_send_subs(ZClient_t *client, char *vers)
sub != client->zct_subs;
sub = sub->q_forw) {
/* for each subscription */
- 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 ();
+ lyst[i * NUM_FIELDS] = sub->zst_dest.classname->string;
+ lyst[i * NUM_FIELDS + 1] = sub->zst_dest.inst->string;
+ lyst[i * NUM_FIELDS + 2] = sub->zst_dest.recip->string;
i++;
if (i >= 7) {
/* we only put 7 in each packet, so we don't
@@ -1054,7 +1133,9 @@ subscr_send_subs(ZClient_t *client, char *vers)
*/
static int
-clt_unique(ZClient_t *clt, ZClientList_t *clist)
+clt_unique(clt, clist)
+ ZClient_t *clt;
+ ZClientList_t *clist;
{
register ZClientList_t *client;
@@ -1071,9 +1152,12 @@ clt_unique(ZClient_t *clt, ZClientList_t *clist)
*/
static int
-cl_match(register ZNotice_t *notice, register ZClient_t *client)
+cl_match(notice_subs, client)
+ register ZSubscr_t *notice_subs;
+ register ZClient_t *client;
{
register ZSubscr_t *subs;
+ int relation;
if (client->zct_subs == NULLZST) {
syslog(LOG_WARNING, "cl_match w/ no subs");
@@ -1083,23 +1167,13 @@ cl_match(register ZNotice_t *notice, register ZClient_t *client)
for (subs = client->zct_subs->q_forw;
subs != client->zct_subs;
subs = subs->q_forw) {
- /* for each subscription, do matching */
-#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 */
-#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);
+ relation = compare_subs(notice_subs, subs);
+ if (relation > 0)
+ return(0);
+ if (relation == 0)
+ return(1);
+ if (relation < 0)
+ continue;
}
/* fall through */
return(0);
@@ -1110,15 +1184,23 @@ cl_match(register ZNotice_t *notice, register ZClient_t *client)
*/
static void
-free_subscriptions(register ZSubscr_t *subs)
+free_subscriptions(subs)
+ register ZSubscr_t *subs;
{
register ZSubscr_t *sub;
for (sub = subs->q_forw; sub != subs; sub = subs->q_forw) {
xremque(sub);
- delete sub;
+ free_zstring(sub->zst_dest.classname);
+ free_zstring(sub->zst_dest.inst);
+ free_zstring(sub->zst_dest.recip);
+ xfree(sub);
}
- delete subs;
+ free_zstring(subs->zst_dest.classname);
+ free_zstring(subs->zst_dest.inst);
+ free_zstring(subs->zst_dest.recip);
+ xfree(subs);
+
return;
}
@@ -1134,7 +1216,8 @@ free_subscriptions(register ZSubscr_t *subs)
*/
static ZSubscr_t *
-extract_subscriptions(register ZNotice_t *notice)
+extract_subscriptions(notice)
+ register ZNotice_t *notice;
{
register ZSubscr_t *subs = NULLZST, *subs2;
register char *recip, *class_name, *classinst;
@@ -1160,20 +1243,26 @@ extract_subscriptions(register ZNotice_t *notice)
return(subs);
}
if (!subs) {
- subs = new ZSubscr_t;
- if (!subs) {
+ if (!(subs = (ZSubscr_t *)
+ xmalloc(sizeof(ZSubscr_t)))) {
syslog(LOG_WARNING, "ex_subs: no mem");
return(NULLZST);
}
+ subs->zst_dest.classname = subs->zst_dest.inst =
+ subs->zst_dest.recip = NULL;
+ subs->zst_dest.hash_value = 0;
}
- subs2 = new ZSubscr_t (ZString (class_name, 1),
- ZString (classinst, 1),
- ZString (recip));
- if (!subs2) {
+ subs->q_forw = subs->q_back = subs;
+ if (!(subs2 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
syslog(LOG_WARNING, "ex_subs: no mem 2");
return(subs);
}
-
+ subs2->q_forw = subs2->q_back = subs2;
+ subs2->zst_dest.classname = make_zstring(class_name,1);
+ subs2->zst_dest.inst = make_zstring(classinst,1);
+ subs2->zst_dest.recip = make_zstring(recip,0);
+ set_ZDestination_hash(&subs2->zst_dest);
+
xinsque(subs2, subs);
}
return(subs);
@@ -1186,7 +1275,9 @@ extract_subscriptions(register ZNotice_t *notice)
*/
void
-subscr_dump_subs(FILE *fp, ZSubscr_t *subs)
+subscr_dump_subs(fp, subs)
+ FILE *fp;
+ ZSubscr_t *subs;
{
register ZSubscr_t *ptr;
@@ -1195,12 +1286,30 @@ subscr_dump_subs(FILE *fp, ZSubscr_t *subs)
for (ptr = subs->q_forw; ptr != subs; ptr = ptr->q_forw) {
fputs("\t\t'", fp);
- fputs(ptr->zst_dest.classname.value (), fp);
+ fputs(ptr->zst_dest.classname->string, fp);
fputs("' '", fp);
- fputs(ptr->zst_dest.inst.value (), fp);
+ fputs(ptr->zst_dest.inst->string, fp);
fputs("' '", fp);
- fputs(ptr->zst_dest.recip.value (), fp);
+ fputs(ptr->zst_dest.recip->string, fp);
fputs("'\n", fp);
}
return;
}
+
+int
+compare_subs(s1,s2)
+ ZSubscr_t *s1, *s2;
+{
+ if (s1->zst_dest.hash_value > s2->zst_dest.hash_value)
+ return 1;
+ if (s1->zst_dest.hash_value < s2->zst_dest.hash_value)
+ return -1;
+
+ if ((s1->zst_dest.classname == s2->zst_dest.classname) &&
+ (s1->zst_dest.inst == s2->zst_dest.inst) &&
+ (s1->zst_dest.recip == s2->zst_dest.recip))
+ return 0;
+
+ return(strcasecmp(s1->zst_dest.classname->string,
+ s2->zst_dest.classname->string));
+}
diff --git a/server/timer.c b/server/timer.c
index 0f152e2..c625e44 100644
--- a/server/timer.c
+++ b/server/timer.c
@@ -9,8 +9,12 @@
*
*/
+#ifndef SABER
+#ifndef lint
static char rcsid[] =
- "$Header$";
+ "$Id$";
+#endif /* lint */
+#endif /* SABER */
/*
* timer_manager_ -- routines for handling timers in login_shell
@@ -65,7 +69,16 @@ long nexttimo = 0L; /* the Unix time of the next
static timer timers = NULL;
static long right_now;
-static void timer_botch(void*), insert_timer(timer), add_timer(timer);
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
+static void timer_botch P((void*)), insert_timer P((timer)),
+ add_timer P((timer));
+
+#undef P
/*
* timer_set_rel(time_rel, proc)
@@ -75,7 +88,11 @@ static void timer_botch(void*), insert_timer(timer), add_timer(timer);
* creates a "timer" and adds it to the current list, returns "timer"
*/
-timer timer_set_rel (long time_rel, void (*proc)(void*), void *arg) {
+timer timer_set_rel (time_rel, proc, arg)
+ long time_rel;
+ void (*proc)(void*);
+ void *arg;
+{
timer new_t;
right_now = NOW;
new_t = (timer) xmalloc(TIMER_SIZE);
@@ -86,7 +103,7 @@ timer timer_set_rel (long time_rel, void (*proc)(void*), void *arg) {
ALARM_PREV(new_t) = NULL;
ALARM_ARG(new_t) = arg;
add_timer(new_t);
- return new_t;
+ return(new_t);
}
#ifdef notdef
@@ -116,9 +133,9 @@ 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
+#endif /* notdef */
/*
* timer_reset
@@ -131,7 +148,9 @@ timer timer_set_abs (time_abs, proc, arg)
*/
void
-timer_reset(timer tmr) {
+timer_reset(tmr)
+ timer tmr;
+{
if (!ALARM_PREV(tmr) || !ALARM_NEXT(tmr)) {
syslog (LOG_ERR, "timer_reset() of unscheduled timer\n");
abort();
@@ -165,7 +184,9 @@ timer_reset(timer tmr) {
*
*/
static void
-add_timer(timer new_t) {
+add_timer(new_t)
+ timer new_t;
+{
if (ALARM_PREV(new_t) || ALARM_NEXT(new_t)) {
syslog (LOG_ERR,"add_timer of enqueued timer\n");
abort();
@@ -181,7 +202,9 @@ add_timer(timer new_t) {
*/
static void
-insert_timer(timer new_t) {
+insert_timer(new_t)
+ timer new_t;
+{
register timer t;
if (timers == NULL) {
@@ -190,6 +213,7 @@ insert_timer(timer new_t) {
ALARM_PREV(timers) = timers;
ALARM_TIME(timers) = 0L;
ALARM_FUNC(timers) = timer_botch;
+ ALARM_ARG(timers) = (void *) NULL;
}
for (t = ALARM_NEXT(timers); t != timers; t = ALARM_NEXT(t)) {
if (ALARM_TIME(t) > ALARM_TIME(new_t)) {
@@ -200,6 +224,7 @@ insert_timer(timer new_t) {
}
xinsque(new_t, ALARM_PREV(timers));
nexttimo = ALARM_TIME(ALARM_NEXT(timers));
+ return;
}
/*
@@ -209,7 +234,8 @@ insert_timer(timer new_t) {
*/
void
-timer_process(void) {
+timer_process()
+{
register timer t;
timer_proc queue;
void * queue_arg;
@@ -240,10 +266,13 @@ timer_process(void) {
if (valid) {
(queue)(queue_arg);
}
+ return;
}
static void
-timer_botch(void *arg) {
+timer_botch(arg)
+ void *arg;
+{
syslog(LOG_CRIT, "Timer botch\n");
abort();
}
diff --git a/server/timer.h b/server/timer.h
index 342340f..1d44de8 100644
--- a/server/timer.h
+++ b/server/timer.h
@@ -35,13 +35,19 @@ without express or implied warranty.
*/
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
+
typedef struct _timer {
struct _timer *next; /* Next one to go off.. */
struct _timer *prev; /* Previous one to go off.. */
/* time for timer to go off, absolute time */
long alarm_time;
/* procedure to call when timer goes off */
- void (*func)(void*);
+ void (*func)P((void*));
/* argument for that procedure */
void * arg;
} *timer;
@@ -56,12 +62,14 @@ typedef struct _timer {
#ifdef mips
#define time_t long /* sigh */
#endif
-extern "C" time_t time(time_t*);
+extern time_t time P((time_t*));
#define NOW (time((time_t *)NULL))
-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);
+typedef void (*timer_proc) P((void *));
+extern timer timer_set_rel P((long, timer_proc, void*));
+extern timer timer_set_abs P((long, timer_proc, void*));
+extern void timer_reset P((timer)), timer_process P((void));
+
+#undef P
#define timer_when(x) ALARM_TIME(x)
diff --git a/server/uloc.c b/server/uloc.c
index 4c33fba..0d115ab 100644
--- a/server/uloc.c
+++ b/server/uloc.c
@@ -14,9 +14,11 @@
#include <zephyr/mit-copyright.h>
#ifndef lint
+#ifndef SABER
static char rcsid_uloc_c[] =
"$Id$";
-#endif
+#endif /* SABER */
+#endif /* lint */
#include "zserver.h"
@@ -62,65 +64,59 @@ static char rcsid_uloc_c[] =
/* else you will lose. See ulogin_locate() and uloc_send_locations() */
#define NUM_FIELDS 3
-enum exposure_type {
+typedef enum _exposure_type {
NONE,
OPSTAFF_VIS,
REALM_VIS,
REALM_ANN,
NET_VIS,
NET_ANN
-};
+} exposure_type;
-struct ZLocation_t {
- ZString zlt_user;
- ZString zlt_machine;
- ZString zlt_time; /* in ctime format */
- ZString zlt_tty;
+typedef struct _ZLocation_t {
+ ZSTRING * zlt_user;
+ ZSTRING * zlt_machine;
+ char * zlt_time; /* in ctime format */
+ ZSTRING * zlt_tty;
struct in_addr zlt_addr; /* IP addr of this loc */
unsigned short zlt_port; /* port of registering client--
for removing old entries */
-#if defined(__GNUC__) || defined(__GNUG__)
- exposure_type zlt_exposure : 16;
-#else
exposure_type zlt_exposure;
-#endif
+} ZLocation_t;
-#if !defined(__GNUG__) || defined(FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZLocation_t)); }
-#endif
-};
+#define NULLZLT ((ZLocation_t *) 0)
+#define NOLOC 1
+#define QUIET -1
+#define UNAUTH -2
-inline int operator == (const ZLocation_t &l1, const ZLocation_t &l2) {
- return (!strcasecmp (l1.zlt_machine.value(), l2.zlt_machine.value())
- && l1.zlt_tty == l2.zlt_tty);
-}
-inline int operator != (const ZLocation_t &l1, const ZLocation_t &l2) {
- return !(l1 == l2);
-}
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
-static ZLocation_t* const NULLZLT = 0;
-static const int NOLOC = 1;
-static const int QUIET = -1;
-static const int UNAUTH = -2;
-
-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),
- ulogin_expose_user(ZNotice_t *notice, exposure_type exposure);
-static exposure_type ulogin_remove_user(ZNotice_t *notice, int auth,
+static void ulogin_locate P((ZNotice_t *notice, struct sockaddr_in *who,
+ int auth)),
+ ulogin_add_user P((ZNotice_t *notice, exposure_type exposure,
+ struct sockaddr_in *who)),
+ ulogin_flush_user P((ZNotice_t *notice));
+static ZLocation_t *ulogin_find P((ZNotice_t *notice, int strict));
+static int ulogin_setup P((ZNotice_t *notice, ZLocation_t *locs,
+ exposure_type exposure, struct sockaddr_in *who)),
+ ulogin_parse P((ZNotice_t *notice, ZLocation_t *locs)),
+ ulogin_expose_user P((ZNotice_t *notice, exposure_type exposure));
+static exposure_type ulogin_remove_user P((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);
-static char **ulogin_marshal_locs(ZNotice_t *notice, int *found, int auth);
+ int *err_return));
+static void login_sendit P((ZNotice_t *notice, int auth, struct sockaddr_in *who)),
+ sense_logout P((ZNotice_t *notice, struct sockaddr_in *who));
+static char **ulogin_marshal_locs P((ZNotice_t *notice, int *found, int auth));
+
+static int ul_equiv P((ZLocation_t *l1, ZLocation_t *l2));
-static ZLocation_t **locations = 0; /* ptr to first in array */
+static void free_loc P((ZLocation_t *loc));
+
+static ZLocation_t *locations = NULLZLT; /* ptr to first in array */
static int num_locs = 0; /* number in array */
/*
@@ -128,8 +124,11 @@ static int num_locs = 0; /* number in array */
*/
Code_t
-ulogin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
- ZServerDesc_t *server)
+ulogin_dispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
exposure_type retval;
int err_ret;
@@ -207,8 +206,7 @@ ulogin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
sense_logout(notice, who);
if (server == me_server)
clt_ack(notice, who, AUTH_FAILED);
- if (!bdumping /* XXX: inter-server and tcp */)
- return(ZERR_NONE);
+ return(ZERR_NONE);
}
if (!strcmp(notice->z_opcode, LOGIN_USER_FLUSH)) {
#if 0
@@ -289,7 +287,10 @@ ulogin_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who,
}
static void
-login_sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
+login_sendit(notice, auth, who)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
{
ZNotice_t log_notice;
@@ -307,10 +308,12 @@ login_sendit(ZNotice_t *notice, int auth, struct sockaddr_in *who)
/*ARGSUSED*/
static void
-sense_logout(ZNotice_t *notice, struct sockaddr_in *who)
+sense_logout(notice, who)
+ ZNotice_t *notice;
+ struct sockaddr_in *who;
{
ZNotice_t sense_notice;
- ZLocation_t *loc, **locptr;
+ ZLocation_t *loc;
struct sockaddr_in owner;
char message[BUFSIZ];
int retval, len;
@@ -325,11 +328,8 @@ sense_logout(ZNotice_t *notice, struct sockaddr_in *who)
will eventually result in a flush of the location.
*/
- locptr = ulogin_find (notice, 1);
- if (!locptr)
+ if (!(loc = ulogin_find (notice, 1)))
return;
- loc = *locptr;
- assert (loc != 0);
/* fabricate an addr descriptor for him */
owner = *who;
@@ -344,7 +344,7 @@ sense_logout(ZNotice_t *notice, struct sockaddr_in *who)
sense_notice.z_class_inst = "URGENT";
sense_notice.z_opcode = "";
sense_notice.z_sender = "Zephyr Server";
- sense_notice.z_recipient = (char *) loc->zlt_user.value ();
+ sense_notice.z_recipient = (char *) loc->zlt_user->string;
sense_notice.z_default_format = "Urgent Message from $sender at $time:\n\n$1";
(void) sprintf(message,
"Someone at host %s tried an unauthorized \nchange to your login information",
@@ -370,7 +370,11 @@ sense_logout(ZNotice_t *notice, struct sockaddr_in *who)
*/
Code_t
-ulocate_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDesc_t *server)
+ulocate_dispatch(notice, auth, who, server)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ ZServerDesc_t *server;
{
#if 0
zdbug((LOG_DEBUG,"ulocate_disp"));
@@ -412,9 +416,10 @@ ulocate_dispatch(ZNotice_t *notice, int auth, struct sockaddr_in *who, ZServerDe
*/
void
-uloc_hflush(struct in_addr *addr)
+uloc_hflush(addr)
+ struct in_addr *addr;
{
- ZLocation_t **loc;
+ ZLocation_t *loc;
register int i = 0, new_num = 0;
int omask;
@@ -424,7 +429,7 @@ uloc_hflush(struct in_addr *addr)
omask = sigblock(sigmask(SIGFPE)); /* don't do ascii dumps */
/* slightly inefficient, assume the worst, and allocate enough space */
- loc = new ZLocation_t* [num_locs];
+ loc = (ZLocation_t *) xmalloc(num_locs *sizeof(ZLocation_t));
if (!loc) {
syslog(LOG_CRIT, "uloc_flush alloc");
abort();
@@ -433,29 +438,30 @@ uloc_hflush(struct in_addr *addr)
/* copy entries which don't match */
while (i < num_locs) {
- if (locations[i]->zlt_addr.s_addr != addr->s_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.value (),
- locations[i]->zlt_machine.value(),
- locations[i]->zlt_tty.value());
+ locations[i].zlt_user->string,
+ locations[i].zlt_machine->string,
+ locations[i].zlt_tty->string);
#endif
- delete locations[i];
+ free_loc(&locations[i]);
}
i++;
}
- delete locations;
+ xfree(locations);
if (!new_num) {
#if 0
zdbug((LOG_DEBUG,"no more locs"));
#endif
- delete loc;
- loc = 0;
+ xfree(loc);
+ loc = NULLZLT;
+ num_locs = new_num;
(void) sigsetmask(omask);
return;
}
@@ -469,8 +475,8 @@ uloc_hflush(struct in_addr *addr)
for (i = 0; i < num_locs; i++)
syslog(LOG_DEBUG, "%s/%d",
- locations[i]->zlt_user.value (),
- (int) locations[i]->zlt_exposure);
+ locations[i].zlt_user->string,
+ (int) locations[i].zlt_exposure);
}
#endif
/* all done */
@@ -478,9 +484,10 @@ uloc_hflush(struct in_addr *addr)
}
void
-uloc_flush_client(struct sockaddr_in *sin)
+uloc_flush_client(sin)
+ struct sockaddr_in *sin;
{
- ZLocation_t **loc;
+ ZLocation_t *loc;
register int i = 0, new_num = 0;
int omask;
@@ -490,7 +497,7 @@ uloc_flush_client(struct sockaddr_in *sin)
omask = sigblock(sigmask(SIGFPE)); /* don't do ascii dumps */
/* slightly inefficient, assume the worst, and allocate enough space */
- loc = new ZLocation_t* [num_locs];
+ loc = (ZLocation_t *) xmalloc(num_locs *sizeof(ZLocation_t));
if (!loc) {
syslog(LOG_CRIT, "uloc_flush_clt alloc");
abort();
@@ -499,30 +506,33 @@ uloc_flush_client(struct sockaddr_in *sin)
/* copy entries which don't match */
while (i < num_locs) {
- if ((locations[i]->zlt_addr.s_addr != sin->sin_addr.s_addr)
- || (locations[i]->zlt_port != sin->sin_port))
+ if ((locations[i].zlt_addr.s_addr != sin->sin_addr.s_addr)
+ || (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.value (),
- locations[i]->zlt_machine.value(),
- locations[i]->zlt_tty.value());
+ locations[i].zlt_user->string,
+ locations[i].zlt_machine->string,
+ locations[i].zlt_tty->string);
#endif
- delete locations[i];
+ free_loc(&locations[i]);
}
i++;
}
- delete locations;
+ xfree(locations);
if (!new_num) {
#if 0
zdbug((LOG_DEBUG,"no more locs"));
#endif
- delete loc;
- loc = 0;
+ xfree(loc);
+ loc = NULLZLT;
+ num_locs = new_num;
+ (void) sigsetmask(omask);
+ return;
}
locations = loc;
num_locs = new_num;
@@ -534,8 +544,8 @@ uloc_flush_client(struct sockaddr_in *sin)
for (i = 0; i < num_locs; i++)
syslog(LOG_DEBUG, "%s/%d",
- locations[i]->zlt_user.value (),
- (int) locations[i]->zlt_exposure);
+ locations[i].zlt_user->string,
+ (int) locations[i].zlt_exposure);
}
#endif
/* all done */
@@ -548,7 +558,9 @@ uloc_flush_client(struct sockaddr_in *sin)
/*ARGSUSED*/
Code_t
-uloc_send_locations(ZHostList_t *host, char *vers)
+uloc_send_locations(host, vers)
+ ZHostList_t *host;
+ char *vers;
{
register ZLocation_t *loc;
register int i;
@@ -557,13 +569,12 @@ uloc_send_locations(ZHostList_t *host, char *vers)
char *exposure_level;
Code_t retval;
- for (i = 0; i < num_locs; i++) {
- loc = locations[i];
+ for (i = 0, loc = locations; i < num_locs; i++, loc++) {
if (loc->zlt_addr.s_addr != haddr->s_addr)
continue;
- lyst[0] = (char *) loc->zlt_machine.value();
- lyst[1] = (char *) loc->zlt_time.value();
- lyst[2] = (char *) loc->zlt_tty.value ();
+ lyst[0] = (char *) loc->zlt_machine->string;
+ lyst[1] = (char *) loc->zlt_time;
+ lyst[2] = (char *) loc->zlt_tty->string;
switch (loc->zlt_exposure) {
case OPSTAFF_VIS:
@@ -583,13 +594,13 @@ uloc_send_locations(ZHostList_t *host, char *vers)
break;
default:
syslog(LOG_ERR,"broken location state %s/%d",
- loc->zlt_user.value (),
+ loc->zlt_user->string,
(int) loc->zlt_exposure);
break;
}
retval = bdump_send_list_tcp(ACKED, loc->zlt_port,
LOGIN_CLASS,
- (char *) loc->zlt_user.value (), /* XXX */
+ (char *) loc->zlt_user->string, /* XXX */
exposure_level,
myname, "", lyst,
NUM_FIELDS);
@@ -607,9 +618,12 @@ uloc_send_locations(ZHostList_t *host, char *vers)
*/
static void
-ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
+ulogin_add_user(notice, exposure, who)
+ ZNotice_t *notice;
+ exposure_type exposure;
+ struct sockaddr_in *who;
{
- ZLocation_t **oldlocs, *newloc;
+ ZLocation_t *oldlocs, *newloc;
register int i = 0;
int omask;
@@ -618,11 +632,7 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
(int) exposure));
#endif
- {
- ZLocation_t **tmp = ulogin_find (notice, 1);
- newloc = tmp ? *tmp : 0;
- }
- if (newloc) {
+ if (newloc = ulogin_find(notice,1)) {
#if 1
zdbug((LOG_DEBUG,"ul_add: already here"));
#endif
@@ -633,7 +643,8 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
oldlocs = locations;
omask = sigblock(sigmask(SIGFPE)); /* don't do ascii dumps */
- locations = new ZLocation_t* [num_locs + 1];
+ locations = (ZLocation_t *) xmalloc((num_locs +1) *
+ sizeof(ZLocation_t));
if (!locations) {
syslog(LOG_ERR, "zloc mem alloc");
locations = oldlocs;
@@ -642,30 +653,32 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
if (num_locs == 0) { /* first one */
if (ulogin_setup(notice, locations, exposure, who)) {
- delete locations;
- locations = 0;
+ xfree(locations);
+ locations = NULLZLT;
+ (void) sigsetmask(omask);
+ return;
}
- else
- num_locs = 1;
+ num_locs = 1;
goto dprnt;
}
/* not the first one, insert him */
- if (ulogin_setup(notice, &newloc, exposure, who)) {
+ if (ulogin_setup(notice, newloc, exposure, who)) {
(void) sigsetmask(omask);
return;
}
num_locs++;
/* copy old locs */
- while ((i < (num_locs - 1)) && oldlocs[i]->zlt_user < newloc->zlt_user) {
+ while ((i < (num_locs - 1)) &&
+ (comp_zstring(oldlocs[i].zlt_user,newloc->zlt_user) < 0)) {
locations[i] = oldlocs[i];
i++;
}
/* add him in here */
- locations[i++] = newloc;
+ locations[i++] = *newloc;
/* copy the rest */
while (i < num_locs) {
@@ -673,7 +686,7 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
i++;
}
if (oldlocs)
- delete oldlocs;
+ xfree(oldlocs);
dprnt:
(void) sigsetmask(omask);
@@ -683,8 +696,8 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
for (i = 0; i < num_locs; i++)
syslog(LOG_DEBUG, "%s/%d",
- locations[i]->zlt_user.value (),
- (int) locations[i]->zlt_exposure);
+ locations[i].zlt_user->string,
+ (int) locations[i].zlt_exposure);
}
#endif
return;
@@ -695,34 +708,40 @@ ulogin_add_user(ZNotice_t *notice, exposure_type exposure, sockaddr_in *who)
*/
static int
-ulogin_setup(ZNotice_t *notice, ZLocation_t **locs, exposure_type exposure, sockaddr_in *who)
+ulogin_setup(notice, locs, exposure, who)
+ ZNotice_t *notice;
+ ZLocation_t *locs;
+ exposure_type exposure;
+ struct sockaddr_in *who;
{
if (ulogin_parse(notice, locs))
return(1);
- ZLocation_t *loc = *locs;
- if (!loc->zlt_user) {
- ret1:
- syslog(LOG_ERR, "zloc bad format");
- return 1;
+
+ if (!locs->zlt_user) {
+ syslog(LOG_ERR, "zloc bad format");
+ return(1);
}
- if (!loc->zlt_machine) {
- ret2:
- loc->zlt_user = 0;
- goto ret1;
+ if (!locs->zlt_machine) {
+ free_zstring(locs->zlt_user);
+ return(1);
+
}
- if (!loc->zlt_tty) {
- ret3:
- loc->zlt_machine = 0;
- goto ret2;
+ if (!locs->zlt_tty) {
+ free_zstring(locs->zlt_user);
+ free_zstring(locs->zlt_machine);
+ return(1);
}
- if (!loc->zlt_time) {
- loc->zlt_tty = 0;
- goto ret3;
+ locs->zlt_time = strsave(locs->zlt_time);
+ if (!locs->zlt_time) {
+ free_zstring(locs->zlt_user);
+ free_zstring(locs->zlt_machine);
+ free_zstring(locs->zlt_tty);
+ return(1);
}
- loc->zlt_exposure = exposure;
- loc->zlt_addr = who->sin_addr;
- loc->zlt_port = notice->z_port;
- return 0;
+ locs->zlt_exposure = exposure;
+ locs->zlt_addr = who->sin_addr;
+ locs->zlt_port = notice->z_port;
+ return(0);
}
/*
@@ -730,25 +749,25 @@ ulogin_setup(ZNotice_t *notice, ZLocation_t **locs, exposure_type exposure, sock
*/
static int
-ulogin_parse(ZNotice_t *notice, ZLocation_t **locs)
+ulogin_parse(notice, locs)
+ ZNotice_t *notice;
+ ZLocation_t *locs;
{
register char *cp, *base;
- ZLocation_t *loc = new ZLocation_t;
- *locs = 0;
if (!notice->z_message_len) {
syslog(LOG_ERR, "short ulogin");
return(1);
}
- loc->zlt_user = notice->z_class_inst;
+ locs->zlt_user = make_zstring(notice->z_class_inst,1);
cp = base = notice->z_message;
#if 0
zdbug((LOG_DEBUG,"user %s",notice->z_class_inst));
#endif
- loc->zlt_machine = cp;
+ locs->zlt_machine = make_zstring(cp,1);
#if 0
zdbug((LOG_DEBUG,"mach %s",cp));
#endif
@@ -758,7 +777,7 @@ ulogin_parse(ZNotice_t *notice, ZLocation_t **locs)
syslog(LOG_ERR, "zloc bad format 1");
return(1);
}
- loc->zlt_time = cp;
+ locs->zlt_time = cp;
#if 0
zdbug((LOG_DEBUG,"time %s",cp));
#endif
@@ -769,17 +788,16 @@ ulogin_parse(ZNotice_t *notice, ZLocation_t **locs)
syslog(LOG_ERR, "zloc bad format 2");
return(1);
} else {
- loc->zlt_tty = cp;
+ locs->zlt_tty = make_zstring(cp,1);
#if 0
zdbug((LOG_DEBUG,"tty %s",cp));
#endif
- cp += loc->zlt_tty.length () + 1;
+ cp += strlen(locs->zlt_tty->string) + 1;
}
if (cp > base + notice->z_message_len) {
syslog(LOG_ERR, "zloc bad format 3");
return(1);
}
- *locs = loc;
return(0);
}
@@ -790,16 +808,20 @@ ulogin_parse(ZNotice_t *notice, ZLocation_t **locs)
* in the table.
*/
-static ZLocation_t **
-ulogin_find(ZNotice_t *notice, int strict)
+static ZLocation_t *
+ulogin_find(notice, strict)
+ ZNotice_t *notice;
+ int strict;
{
register int i, rlo, rhi;
- ZLocation_t *tmploc = 0;
+ ZLocation_t tmploc;
+ int compar;
+ ZSTRING *inst;
if (num_locs == 0)
- return 0;
+ return(NULLZLT);
- ZString inst (notice->z_class_inst);
+ inst = make_zstring(notice->z_class_inst,1);
/* i is the current loc we are checking */
/* rlo is the lowest we will still check, rhi is the highest we will
@@ -809,15 +831,15 @@ ulogin_find(ZNotice_t *notice, int strict)
rlo = 0;
rhi = num_locs - 1; /* first index is 0 */
- while (locations[i]->zlt_user != inst) {
+ while (compar = comp_zstring(locations[i].zlt_user, inst)) {
#if 1
zdbug ((LOG_DEBUG, "ulogin_find: comparing %s %s %s %d %d",
notice->z_class_inst,
- locations[i]->zlt_user.value (),
- locations[i]->zlt_tty.value (),
+ locations[i].zlt_user->string,
+ locations[i].zlt_tty->string,
rlo, rhi));
#endif
- if (locations[i]->zlt_user < inst)
+ if (compar < 0)
rlo = i + 1;
else
rhi = i - 1;
@@ -825,7 +847,7 @@ ulogin_find(ZNotice_t *notice, int strict)
#if 1
zdbug((LOG_DEBUG,"ul_find not found"));
#endif
- return 0;
+ return(NULLZLT);
}
i = (rhi + rlo) >> 1; /* split the diff */
}
@@ -837,53 +859,63 @@ ulogin_find(ZNotice_t *notice, int strict)
}
/* back up to the first of this guy */
if (i) {
- while (i > 0 && locations[--i]->zlt_user == inst) {
+ while (i > 0 && (locations[--i].zlt_user == inst)) {
#if 0
zdbug ((LOG_DEBUG,
"ulogin_find: backing up: %s %d %s %s",
- inst.value (), i,
- locations[i]->zlt_user.value (),
- locations[i]->zlt_tty.value ()));
+ inst->string, i,
+ locations[i].zlt_user->string,
+ locations[i].zlt_tty->string));
#endif
}
- if (i || locations[i]->zlt_user != inst)
+ if (i || (locations[i].zlt_user != inst))
i++;
}
if (strict)
while (i < num_locs
- && *tmploc != *locations[i]
- && locations[i]->zlt_user == inst) {
+ && !ul_equiv(&tmploc, &locations[i])
+ && (locations[i].zlt_user == inst)) {
i++;
}
- if ((i == num_locs) || locations[i]->zlt_user != inst) {
+ if ((i == num_locs) || (locations[i].zlt_user != inst)) {
#if 1
zdbug((LOG_DEBUG,"ul_find final match loss"));
#endif
- if (tmploc)
- delete tmploc;
return 0;
}
- if (tmploc)
- delete tmploc;
return &locations[i];
}
+static int
+ul_equiv(l1, l2)
+register ZLocation_t *l1, *l2;
+{
+ if (l1->zlt_machine != l2->zlt_machine)
+ return(0);
+ if (l1->zlt_tty != l2->zlt_tty)
+ return(0);
+ return(1);
+}
+
/*
* remove the user specified in notice from the internal table
*/
static exposure_type
-ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_return)
+ulogin_remove_user(notice, auth, who, err_return)
+ ZNotice_t *notice;
+ int auth;
+ struct sockaddr_in *who;
+ int *err_return;
{
- ZLocation_t **loc, *loc2;
+ ZLocation_t *loc, *loc2;
register int i = 0;
exposure_type quiet;
int omask;
*err_return = 0;
- loc = ulogin_find (notice, 1);
- if (!loc || !(loc2 = *loc)) {
+ if (!(loc2 = ulogin_find(notice, 1))) {
#if 0
zdbug((LOG_DEBUG,"ul_rem: not here"));
#endif
@@ -905,13 +937,13 @@ ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_retur
#if 0
zdbug((LOG_DEBUG,"last loc"));
#endif
- delete locations;
- locations = 0;
+ xfree(locations);
+ locations = NULLZLT;
(void) sigsetmask(omask);
return(quiet);
}
- loc = new ZLocation_t* [num_locs];
+ loc = (ZLocation_t *) xmalloc(num_locs * sizeof(ZLocation_t));
if (!loc) {
syslog(LOG_CRIT, "ul_rem alloc");
abort();
@@ -919,13 +951,13 @@ ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_retur
}
/* copy old entries */
- while (i < num_locs && locations[i] != loc2) {
+ while (i < num_locs && &locations[i] < loc2) {
loc[i] = locations[i];
i++;
}
/* free up this one */
- delete locations[i];
+ free_loc(&locations[i]);
i++; /* skip over this one */
/* copy the rest */
@@ -934,7 +966,7 @@ ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_retur
i++;
}
- delete locations;
+ xfree(locations);
locations = loc;
@@ -945,8 +977,8 @@ ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_retur
for (i = 0; i < num_locs; i++)
syslog(LOG_DEBUG, "%s/%d",
- locations[i]->zlt_user.value(),
- (int) locations[i]->zlt_exposure);
+ locations[i].zlt_user->string,
+ (int) locations[i].zlt_exposure);
}
#endif
/* all done */
@@ -958,13 +990,14 @@ ulogin_remove_user(ZNotice_t *notice, int auth, sockaddr_in *who, int *err_retur
*/
static void
-ulogin_flush_user(ZNotice_t *notice)
+ulogin_flush_user(notice)
+ ZNotice_t *notice;
{
- register ZLocation_t **loc, **loc2, *loc3;
+ register ZLocation_t *loc, *loc2;
register int i, j, num_match, num_left;
int omask;
- num_match = num_left = 0;
+ i = num_match = num_left = 0;
if (!(loc2 = ulogin_find(notice, 0))) {
#if 0
@@ -974,17 +1007,11 @@ ulogin_flush_user(ZNotice_t *notice)
}
/* compute # locations left in the list, after loc2 (inclusive) */
- {
- int k;
- ZLocation_t *tmp = *loc2;
- for (k = 0; locations[k] != tmp; k++)
- ;
- num_left = num_locs - k;
- }
+ num_left = num_locs - (loc2 - locations);
omask = sigblock(sigmask(SIGFPE)); /* don't let disk db dumps start */
while (num_left &&
- !strcmp(loc2[num_match]->zlt_user.value(),
+ !strcmp(loc2[num_match].zlt_user->string,
notice->z_class_inst)) {
/* as long as we keep matching, march up the list */
num_match++;
@@ -995,15 +1022,16 @@ ulogin_flush_user(ZNotice_t *notice)
zdbug((LOG_DEBUG,"last loc"));
#endif
for (j = 0; j < num_match; j++)
- delete locations[j]; /* free storage */
- delete locations;
- locations = 0;
+ free_loc(&locations[j]); /* free storage */
+ xfree (locations);
+ locations = NULLZLT;
num_locs = 0;
(void) sigsetmask(omask);
return;
}
- loc = new ZLocation_t* [num_locs - num_match];
+ loc = (ZLocation_t *) xmalloc((num_locs - num_match) *
+ sizeof(ZLocation_t));
if (!loc) {
syslog(LOG_CRIT, "ul_rem alloc");
abort();
@@ -1011,24 +1039,16 @@ ulogin_flush_user(ZNotice_t *notice)
}
/* copy old entries */
- loc3 = *loc2;
- i = 0;
- while (1) {
- ZLocation_t *tmp = locations[i];
- if (tmp == loc3)
- break;
-#if 0
- if (i >= num_locs)
- break;
-#endif
- loc[i] = tmp;
- i++;
+ while (i < num_locs && &locations[i] < loc2) {
+ /* XXX should bcopy */
+ loc[i] = locations[i];
+ i++;
+ }
+
+ for(j = 0; j < num_match; j++) {
+ free_loc(&locations[i]);
+ i++;
}
-
- /* skip over (and delete) matches */
- j = i + num_match;
- while (i < j)
- delete locations[i++];
/* copy the rest */
while (i < num_locs) {
@@ -1037,7 +1057,7 @@ ulogin_flush_user(ZNotice_t *notice)
i++;
}
- delete locations;
+ xfree(locations);
locations = loc;
num_locs -= num_match;
@@ -1049,8 +1069,8 @@ ulogin_flush_user(ZNotice_t *notice)
for (i = 0; i < num_locs; i++)
syslog(LOG_DEBUG, "%s/%d",
- locations[i]->zlt_user.value(),
- (int) locations[i]->zlt_exposure);
+ locations[i].zlt_user->string,
+ (int) locations[i].zlt_exposure);
}
#endif
/* all done */
@@ -1062,9 +1082,11 @@ ulogin_flush_user(ZNotice_t *notice)
*/
static int
-ulogin_expose_user(ZNotice_t *notice, exposure_type exposure)
+ulogin_expose_user(notice, exposure)
+ ZNotice_t *notice;
+ exposure_type exposure;
{
- ZLocation_t *loc, *loc2;
+ ZLocation_t *loc, loc2;
int idx, notfound = 1;
#if 0
@@ -1075,42 +1097,40 @@ ulogin_expose_user(ZNotice_t *notice, exposure_type exposure)
if (ulogin_parse(notice, &loc2))
return(1);
- {
- ZLocation_t **tmp = ulogin_find (notice, 0);
- loc = tmp ? *tmp : 0;
- }
- if (!loc) {
+ if (!(loc = ulogin_find(notice, 0))) {
#if 0
zdbug((LOG_DEBUG,"ul_hide: not here"));
#endif
return(1);
}
- for (idx = 0; locations[idx] != loc; idx++)
- ;
+
+ idx = loc -locations;
while ((idx < num_locs) &&
- locations[idx]->zlt_user != loc2->zlt_user) {
+ locations[idx].zlt_user != loc2.zlt_user) {
/* change exposure and owner for each loc on that host */
- if (!strcasecmp(locations[idx]->zlt_machine.value(), loc2->zlt_machine.value())) {
+ if (locations[idx].zlt_machine == loc2.zlt_machine) {
notfound = 0;
- locations[idx]->zlt_exposure = exposure;
- locations[idx]->zlt_port = notice->z_port;
+ locations[idx].zlt_exposure = exposure;
+ locations[idx].zlt_port = notice->z_port;
/* change time for the specific loc */
- if (locations[idx]->zlt_tty == loc2->zlt_tty) {
- locations[idx]->zlt_time = loc2->zlt_time;
+ if (locations[idx].zlt_tty == loc2.zlt_tty) {
+ xfree(locations[idx].zlt_time);
+ locations[idx].zlt_time = loc2.zlt_time;
}
}
idx++;
}
- delete loc2;
-
return(notfound);
}
static void
-ulogin_locate(ZNotice_t *notice, sockaddr_in *who, int auth)
+ulogin_locate(notice, who, auth)
+ ZNotice_t *notice;
+ struct sockaddr_in *who;
+ int auth;
{
char **answer;
int found;
@@ -1151,32 +1171,32 @@ ulogin_locate(ZNotice_t *notice, sockaddr_in *who, int auth)
*/
static char **
-ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
+ulogin_marshal_locs(notice, found, auth)
+ ZNotice_t *notice;
+ register int *found;
+ int auth;
{
ZLocation_t **matches = (ZLocation_t **) 0;
ZLocation_t *loc;
char **answer;
register int i = 0;
+ ZSTRING *inst;
*found = 0; /* # of matches */
- {
- ZLocation_t **tmp = ulogin_find (notice, 0);
- loc = tmp ? *tmp : 0;
- }
- if (!loc)
+ if (!(loc = ulogin_find(notice, 0)))
/* not here anywhere */
return((char **)0);
- for (i = 0; locations[i] != loc; i++)
- ;
- ZString inst (notice->z_class_inst);
- while (i < num_locs && inst == locations[i]->zlt_user) {
+ i = loc - locations;
+
+ inst = make_zstring(notice->z_class_inst,1);
+ while (i < num_locs && (inst == locations[i].zlt_user)) {
/* these locations match */
#if 0
- zdbug((LOG_DEBUG,"match %s", locations[i]->zlt_user.value()));
+ zdbug((LOG_DEBUG,"match %s", locations[i].zlt_user->string));
#endif
- switch (locations[i]->zlt_exposure) {
+ switch (locations[i].zlt_exposure) {
case OPSTAFF_VIS:
i++;
continue;
@@ -1196,7 +1216,7 @@ ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
syslog(LOG_ERR, "ulog_loc: no mem");
break; /* from the while */
}
- matches[0] = locations[i];
+ matches[0] = &locations[i];
(*found)++;
} else {
if ((matches = (ZLocation_t **) realloc((caddr_t) matches, (unsigned) ++(*found) * sizeof(ZLocation_t *))) == (ZLocation_t **) 0) {
@@ -1204,10 +1224,11 @@ ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
*found = 0;
break; /* from the while */
}
- matches[*found - 1] = locations[i];
+ matches[*found - 1] = &locations[i];
}
i++;
}
+ free_zstring(inst);
/* OK, now we have a list of user@host's to return to the client
in matches */
@@ -1217,7 +1238,7 @@ ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
if (zdebug) {
for (i = 0; i < *found ; i++)
zdbug((LOG_DEBUG,"found %s",
- matches[i]->zlt_user.value()));
+ matches[i]->zlt_user->string));
}
#endif
@@ -1227,9 +1248,9 @@ ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
*found = 0;
} else
for (i = 0; i < *found ; i++) {
- answer[i*NUM_FIELDS] = (char *) matches[i]->zlt_machine.value ();
- answer[i*NUM_FIELDS + 1] = (char *) matches[i]->zlt_time.value();
- answer[i*NUM_FIELDS + 2] = (char *) matches[i]->zlt_tty.value();
+ answer[i*NUM_FIELDS] = (char *) matches[i]->zlt_machine->string;
+ answer[i*NUM_FIELDS + 1] = (char *) matches[i]->zlt_time;
+ answer[i*NUM_FIELDS + 2] = (char *) matches[i]->zlt_tty->string;
}
if (matches)
@@ -1238,25 +1259,26 @@ ulogin_marshal_locs(ZNotice_t *notice, register int *found, int auth)
}
void
-uloc_dump_locs(register FILE *fp)
+uloc_dump_locs(fp)
+ register FILE *fp;
{
register int i;
char buf[BUFSIZ*3];
static char *bufp;
- static const char *cp;
+ static Zconst char *cp;
/* delay using stdio so that we can run FAST! */
for (i = 0; i < num_locs; i++) {
bufp = buf;
-#define cpy(str) do{cp=(str);while(*cp){*bufp++=*cp++;}}while(0)
- cpy (locations[i]->zlt_user.value ());
+#define cpy(str) cp=(str);while(*cp){*bufp++ = *cp++;}
+ cpy (locations[i].zlt_user->string);
*bufp++ = '/';
- cpy (locations[i]->zlt_machine.value());
+ cpy (locations[i].zlt_machine->string);
*bufp++ = '/';
- cpy (locations[i]->zlt_time.value());
+ cpy (locations[i].zlt_time);
*bufp++ = '/';
- cpy (locations[i]->zlt_tty.value());
- switch (locations[i]->zlt_exposure) {
+ cpy (locations[i].zlt_tty->string);
+ switch (locations[i].zlt_exposure) {
case OPSTAFF_VIS:
cpy ("/OPSTAFF/");
break;
@@ -1273,17 +1295,28 @@ uloc_dump_locs(register FILE *fp)
cpy ("/NET_ANN/");
break;
default:
- sprintf (bufp, "/? %d ?/", locations[i]->zlt_exposure);
+ sprintf (bufp, "/? %d ?/", locations[i].zlt_exposure);
while (*bufp)
bufp++;
break;
}
- cpy (inet_ntoa (locations[i]->zlt_addr));
+ cpy (inet_ntoa (locations[i].zlt_addr));
*bufp++ = '/';
- sprintf(bufp, "%d", ntohs(locations[i]->zlt_port));
+ sprintf(bufp, "%d", ntohs(locations[i].zlt_port));
fputs(buf, fp);
(void) putc('\n', fp);
#undef cpy
}
return;
}
+
+static void
+free_loc(loc)
+ ZLocation_t *loc;
+{
+ free_zstring(loc->zlt_user);
+ free_zstring(loc->zlt_machine);
+ free_zstring(loc->zlt_tty);
+ xfree(loc->zlt_time);
+ return;
+}
diff --git a/server/unix.h b/server/unix.h
index a7b96f8..858ee71 100644
--- a/server/unix.h
+++ b/server/unix.h
@@ -17,78 +17,63 @@
#ifndef ZSERVER_UNIX_H__
-extern "C" {
- /* found in libc.a */
-#ifndef __GNUG__
- void *malloc(unsigned), *realloc(void *, unsigned), free (void *);
+#include <stdio.h>
+#if defined(__STDC__) && !defined(__HIGHC__) && !defined(SABER)
+/* Brain-dead High-C claims to be ANSI but doesn't have the include files.. */
+#include <stdlib.h>
#endif
- long random(void);
- void srandom (int);
- int getpid (void);
-
- /*
- * Queue-handling functions. This structure is basically a dummy;
- * as long as the start of another structure looks like this,
- * we're okay.
- */
- struct qelem {
- struct qelem *q_forw;
- struct qelem *q_back;
- char *q_data;
- };
- void insque (qelem*, qelem*);
- void remque (qelem *);
-#ifdef __GNUG__
-#if defined (ultrix)
- void openlog (char *, int);
-#undef LOG_DEBUG
-#define LOG_DEBUG LOG_ERR
+
+#ifdef __STDC__
+# define P(s) s
#else
- void openlog (char *, int, int); /* ??? */
-#endif
-#endif /* G++? */
- void syslog (int, const char *, ...);
- int setsockopt (int, int, int, const char *, int);
- extern int strcasecmp (const char*, const char*);
-#ifdef __GNUG__
- extern void setservent (int);
- extern void endservent (void);
+# define P(s) ()
#endif
- extern void moncontrol (int);
- /* From the Error table library */
- char *error_message(long);
+/*
+ * Queue-handling functions. This structure is basically a dummy;
+ * as long as the start of another structure looks like this,
+ * we're okay.
+ */
+struct qelem {
+ struct qelem *q_forw;
+ struct qelem *q_back;
+ char *q_data;
+};
+void insque P((struct qelem*, struct qelem*));
+void remque P((struct qelem *));
+
+/* From the Error table library */
+char *error_message P((long));
#ifdef KERBEROS
- /* Kerberos */
- extern int krb_get_lrealm (char *, int);
- extern int dest_tkt (void);
- extern int krb_get_svc_in_tkt (char *, char *, char *, char *, char *, int,
- char *);
+/* Kerberos */
+extern int krb_get_lrealm P((char *, int));
+extern int dest_tkt P((void));
+extern int krb_get_svc_in_tkt P((char *, char *, char *, char *, char *, int,
+ char *));
#ifdef KRB_DEFS /* have we actually got krb.h? */
- extern int krb_mk_req (KTEXT, char *, char *, char *, unsigned long);
- extern int krb_get_cred (char *, char *, char *, CREDENTIALS *);
+extern int krb_mk_req P((KTEXT, char *, char *, char *, unsigned long));
+extern int krb_get_cred P((char *, char *, char *, CREDENTIALS *));
#endif
- extern int krb_rd_req (...);
- extern int des_quad_cksum (...);
#else
- extern int rresvport (...);
+extern int rresvport P((int *));
#endif
#ifdef HESIOD
/* Hesiod */
- extern char ** hes_resolve (const char *, const char *);
+extern char ** hes_resolve P((Zconst char *, Zconst char *));
#endif
/* hacked acl code */
- extern void acl_cache_reset (void);
-}
+extern void acl_cache_reset P((void));
+
+#undef P
#ifdef vax
#define HAVE_ALLOCA
#endif
-#if defined (__GNUC__) || defined (__GNUG__)
+#if defined (__GNUC__)
/* GCC/G++ has a built-in function for allocating automatic storage. */
#define LOCAL_ALLOC(X) __builtin_alloca(X)
@@ -96,22 +81,11 @@ extern "C" {
#else /* not gcc or g++ */
-#if defined (ibm032)
-/*
- * Unfortunately, there's no way to get cfront to access _Alloca. So
- * we compile with -ma and call alloca. Sigh.
- */
-#define LOCAL_ALLOC(X) alloca(X)
-#define LOCAL_FREE(X)
-extern "C" void * alloca (unsigned int);
-
-#else /* none of above */
#ifdef HAVE_ALLOCA
#define LOCAL_ALLOC(X) alloca(X)
#define LOCAL_FREE(X)
#endif
#endif
-#endif
#ifndef LOCAL_ALLOC
#define LOCAL_ALLOC(X) malloc(X)
diff --git a/server/version.c b/server/version.c
index fe0400c..587028f 100644
--- a/server/version.c
+++ b/server/version.c
@@ -13,20 +13,76 @@
#include <zephyr/mit-copyright.h>
+#include <string.h>
+#include <zephyr/zephyr.h>
+#include "version.h"
+
#ifdef DEBUG
-extern const char version[] = "Zephyr Server (DEBUG) $Revision$";
+Zconst char version[] = "Zephyr Server (DEBUG) $Revision$";
#else
-extern const char version[] = "Zephyr Server $Revision$";
+Zconst char version[] = "Zephyr Server $Revision$";
#endif
#if !defined (lint) && !defined (SABER)
-static const char rcsid_version_c[] =
+Zconst char rcsid_version_c[] =
"$Id$";
-extern const char copyright[] =
+Zconst char copyright[] =
"Copyright (c) 1987,1988,1989,1990 Massachusetts Institute of Technology.\n";
#ifdef CONCURRENT
-extern const char concurrent[] = "Brain-dump concurrency enabled";
+Zconst char concurrent[] = "Brain-dump concurrency enabled";
#else
-extern const char concurrent[] = "no brain-dump concurrency";
+Zconst char concurrent[] = "no brain-dump concurrency";
#endif
#endif
+
+char *
+get_version()
+{
+ static char vers_buf[256];
+
+ if (vers_buf[0] == '\0') {
+#ifdef DEBUG
+ sprintf(vers_buf,"Zephyr Server (DEBUG) $Revision$: %s",
+ ZSERVER_VERSION_STRING);
+#else
+ sprintf(vers_buf,"Zephyr Server $Revision$: %s",
+ ZSERVER_VERSION_STRING);
+#endif /* DEBUG */
+
+ (void) strcat(vers_buf, "/");
+#ifdef vax
+ (void) strcat(vers_buf, "VAX");
+#endif /* vax */
+#ifdef ibm032
+ (void) strcat(vers_buf, "IBM RT");
+#endif /* ibm032 */
+#ifdef _IBMR2
+ (void) strcat(vers_buf, "IBM RS/6000");
+#endif /* _IBMR2 */
+#ifdef sun
+ (void) strcat(vers_buf, "SUN");
+#ifdef sparc
+ (void) strcat (vers_buf, "-4");
+#endif /* sparc */
+#ifdef sun386
+ (void) strcat (vers_buf, "-386I");
+#endif /* sun386 */
+#endif /* sun */
+
+#ifdef mips
+#ifdef ultrix /* DECstation */
+ (void) strcat (vers_buf, "DEC-");
+#endif /* ultrix */
+ (void) strcat(vers_buf, "MIPS");
+#endif /* mips */
+#ifdef NeXT
+ (void) strcat(vers_buf, "NeXT");
+#endif /* NeXT */
+ }
+ return(vers_buf);
+}
+
+
+
+
+
diff --git a/server/zalloc.c b/server/zalloc.c
index 9db5846..f4e5e23 100644
--- a/server/zalloc.c
+++ b/server/zalloc.c
@@ -3,6 +3,8 @@
*/
#include <stdio.h>
+#include <zephyr/zephyr.h>
+#include "unix.h"
#include "zalloc.h"
#ifndef MPROF
@@ -10,63 +12,62 @@
* What's the maximum number of words to expect to allocate through
* this mechanism? (Larger requests will be fed to malloc.)
*/
-const int max_size = 32;
+#define MAX_SIZE 32
static void *free_space;
-static int free_space_size;
-static void *buckets[max_size];
+static unsigned int free_space_size;
+static void *buckets[MAX_SIZE];
#ifdef ZALLOC_STATS
enum zalloc_memtype {
FREE=0, ALLOCATED,
N_zalloc_memtype
};
-static int zalloc_count[max_size][(int) N_zalloc_memtype];
+static int zalloc_count[MAX_SIZE][(int) N_zalloc_memtype];
#endif
-struct dummy {
- int a;
- virtual int i() { return a; }
-};
-
-union misc_types { /* used only for its size */
+/*
+ union misc_types {
void *void_p;
int i;
long l;
double d;
- int (dummy::* member_p) ();
- /* Can't just use a `dummy' object, because it has an invisible
- constructor. */
- char cc[sizeof (dummy)];
-};
-
-const unsigned int sz = sizeof (misc_types);
+ };
+*/
+/* SZ = sizeof(misc_types) */
+#define SZ 32
/*
* Pick some size here that will help keep down the number of calls to
* malloc, but doesn't waste too much space. To avoid waste of space,
* we leave some overhead before the next power of two.
*/
-const int alloc_size = ((16384 - 32) / sz) * sz;
-inline unsigned int round (unsigned int size) {
- size += sz - 1;
- size -= (size % sz);
+
+/* ALLOC_SIZE = ((16384 - 32) / SZ) * SZ */
+#define ALLOC_SIZE 16352
+
+unsigned int round (size)
+ unsigned int size;
+{
+ size += SZ - 1;
+ size -= (size % SZ);
return size;
}
+
#define ROUND(size) (size = round (size))
-inline int BUCKET (unsigned int size) {
+int BUCKET (size)
+ unsigned int size;
+{
ROUND (size);
- return size / sz - 1;
+ return size / SZ - 1;
}
-extern "C" {
- void * malloc (unsigned int);
- void free (void *);
- void abort ();
- void bzero (void *, unsigned int);
-}
-
-static inline void zmemset (void *ptr, int size, int fill) {
+static void
+zmemset (ptr, size, fill)
+ void *ptr;
+ int size;
+ int fill;
+{
#ifdef ZALLOC_DEBUG
char *cptr = (char *) ptr;
while (size--)
@@ -74,15 +75,20 @@ static inline void zmemset (void *ptr, int size, int fill) {
#endif
}
-void *zalloc (unsigned int size) {
- ROUND (size);
+void *
+zalloc (size)
+ unsigned int size;
+{
+ int bucket;
+ void *ret;
+ void **ptr;
- int bucket = BUCKET (size);
- if (bucket < 0 || bucket >= max_size)
- return malloc (size);
+ ROUND (size);
+ bucket = BUCKET (size);
+ if (bucket < 0 || bucket >= MAX_SIZE)
+ return (void *) malloc (size);
- void *ret;
- void **ptr = &buckets[bucket];
+ ptr = &buckets[bucket];
#ifdef ZALLOC_DEBUG_PRINT
fprintf (stderr, "zalloc(%d); looking in bucket %d, found %08X\n",
size, bucket, *ptr);
@@ -107,8 +113,8 @@ void *zalloc (unsigned int size) {
#endif
}
- free_space_size = alloc_size;
- free_space = malloc (free_space_size);
+ free_space_size = ALLOC_SIZE;
+ free_space = (void *) malloc (free_space_size);
if (!free_space)
abort ();
#ifdef ZALLOC_DEBUG_PRINT
@@ -130,16 +136,21 @@ return_it:
return ret;
}
-void zfree (void *ptr, unsigned int size) {
- ROUND (size);
+void zfree (ptr, size)
+ void *ptr;
+ unsigned int size;
+{
+ int bucket;
+ void **b;
- int bucket = BUCKET (size);
- if (bucket < 0 || bucket >= max_size) {
+ ROUND (size);
+ bucket = BUCKET (size);
+ if (bucket < 0 || bucket >= MAX_SIZE) {
free (ptr);
return;
}
- void **b = &buckets[bucket];
+ b = &buckets[bucket];
zmemset (ptr, size, 0xe5);
*(void **) ptr = *b;
*b = ptr;
diff --git a/server/zalloc.h b/server/zalloc.h
index 0b0afbe..a2c60a8 100644
--- a/server/zalloc.h
+++ b/server/zalloc.h
@@ -1,17 +1,22 @@
/*
*/
-#ifndef INCLUDED_zalloc_h
+#ifndef __zalloc_h
+#define __zalloc_h __FILE__
#ifdef MPROF
-inline void * zalloc (unsigned int sz) {
- return malloc (sz);
-}
-inline void zfree (void *ptr, unsigned int sz) {
- free (ptr);
-}
+#define zalloc(sz) malloc(sz)
+#define zfree(p,sz) free(p)
#else
-extern void * zalloc (unsigned int);
-extern void zfree (void *, unsigned int);
-#endif
-#define INCLUDED_zalloc_h
-#endif
+
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif /* STDC */
+
+extern void * zalloc P((unsigned int));
+extern void zfree P((void *, unsigned int));
+
+#undef P
+#endif /* MPROF */
+#endif /* __zalloc_h */
diff --git a/server/zserver.h b/server/zserver.h
index fc00703..eb0a208 100644
--- a/server/zserver.h
+++ b/server/zserver.h
@@ -22,7 +22,6 @@
<sys/time.h>,
<stdio.h>,
<krb.h> */
-extern "C" {
#include <arpa/inet.h>
#include <zephyr/acl.h>
#include <sys/file.h>
@@ -34,15 +33,18 @@ extern "C" {
#ifdef lint
#include <sys/uio.h> /* so it shuts up about struct iovec */
#endif /* lint */
+#ifdef _IBMR2
+#include <sys/select.h>
+#endif
#include "zsrv_err.h"
-}
#include "timer.h"
#include "zsrv_conf.h" /* configuration params */
-#include "ZString.h"
+#include "zstring.h"
#include "access.h"
#include "unix.h"
+#include "zalloc.h"
/* definitions for the Zephyr server */
@@ -53,171 +55,71 @@ extern "C" {
* instance, and recipient at the moment.
*/
-struct ZDestination {
+typedef struct _ZDestination {
unsigned long hash_value;
-public:
- ZString classname;
- ZString inst;
- ZString recip;
- void set_hash () {
- hash_value = classname.hash() ^ inst.hash() ^ recip.hash();
- }
- unsigned long hash () {
- return hash_value;
- }
- 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&);
- ~ZDestination ();
- void print (char *buf);
- static int order_strings (const ZDestination&, const ZDestination&);
-#if !defined(__GNUG__) || defined(FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZDestination)); }
-#endif
-};
-
-const static ZDestination null_destination = 0;
-
-extern int operator== (const ZDestination&, const ZDestination&);
-
-inline int operator != (const ZDestination& z1, const ZDestination& z2) {
- return !(z1 == z2);
-}
+ ZSTRING *classname;
+ ZSTRING *inst;
+ ZSTRING *recip;
+} ZDestination;
-inline int operator< (const ZDestination& z1, const ZDestination& z2) {
- return (z1.hash_value != z2.hash_value
- ? z1.hash_value < z2.hash_value
- : ZDestination::order_strings (z1, z2) < 0);
-}
-
-inline int operator> (const ZDestination& z1, const ZDestination& z2) {
- return (z1 == z2) ? 0 : !(z1 < z2);
-}
-
-inline int operator >= (const ZDestination& z1, const ZDestination& z2) {
- return !(z1 < z2);
-}
-
-struct Notice {
+/* typedef struct _Notice {
ZNotice_t *notice;
- ZDestination dest;
- ZString sender;
+ struct _ZDestination dest;
+ ZSTRING *sender;
int msg_no;
- static int current_msg;
- 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;
- }
-};
-
-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&);
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZSubscr_t)); }
-#endif
-};
-
-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;
-}
-
-struct ZClient_t {
+} Notice;
+*/
+typedef struct _ZSubscr_t {
+ struct _ZSubscr_t *q_forw; /* links in client's subscr. queue */
+ struct _ZSubscr_t *q_back;
+ struct _ZDestination zst_dest; /* destination of messages */
+} 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 */
- ZString zct_principal; /* krb principal of user */
+ 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;
- }
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZClient_t)); }
-#endif
-};
-
-struct ZClientList_t {
- ZClientList_t *q_forw;
- ZClientList_t *q_back;
- ZClient_t *zclt_client;
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZClientList_t)); }
-#endif
-};
+} ZClient_t;
+
+typedef struct _ZClientList_t {
+ struct _ZClientList_t *q_forw;
+ struct _ZClientList_t *q_back;
+ struct _ZClient_t *zclt_client;
+} ZClientList_t;
-struct ZClass_t {
- ZClass_t *q_forw;
- ZClass_t *q_back;
+typedef struct _ZClass_t {
+ struct _ZClass_t *q_forw;
+ struct _ZClass_t *q_back;
ZDestination zct_dest;
ZAcl_t *zct_acl;
ZClientList_t *zct_clientlist;
+} ZClass_t;
- ZClass_t (const ZDestination& dest = null_destination) : zct_dest (dest) {
- q_forw = q_back = this;
- zct_clientlist = 0;
- zct_acl = 0;
- }
- ~ZClass_t () {
- if (zct_clientlist)
- xfree (zct_clientlist);
- }
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZClass_t)); }
-#endif
-};
-
-struct ZHostList_t {
- struct ZHostList_t *q_forw;
- struct ZHostList_t *q_back;
+typedef struct _ZHostList_t {
+ struct _ZHostList_t *q_forw;
+ struct _ZHostList_t *q_back;
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
+ struct sockaddr_in zh_addr; /* IP addr/port of hostmanager */
+ unsigned int zh_locked; /* 1 if this host is locked for
a braindump */
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZHostList_t)); }
-#endif
-};
+} ZHostList_t;
-enum server_state {
+typedef 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;
-struct ZNotAcked_t {
- struct ZNotAcked_t *q_forw; /* link to next */
- struct ZNotAcked_t *q_back; /* link to prev */
+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 */
short na_rexmits; /* number of retransmits */
@@ -230,214 +132,177 @@ struct ZNotAcked_t {
} dest;
#define na_addr dest.na_sin
#define na_srv_idx dest.srv_idx
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZNotAcked_t)); }
-#endif
-#ifndef __GNUG__ /* cfront 2.0 breakage... */
- ZNotAcked_t () { }
-#endif
-};
+} ZNotAcked_t;
-struct ZSrvPending_t {
- struct ZSrvPending_t *q_forw; /* link to next */
- struct ZSrvPending_t *q_back; /* link to prev */
+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) */
short pend_len; /* len of pkt */
- unsigned int pend_auth : 1; /* whether it is authentic */
+ unsigned int pend_auth; /* whether it is authentic */
struct sockaddr_in pend_who; /* the addr of the sender */
-#if !defined (__GNUG__) || defined (FIXED_GXX)
- void *operator new (unsigned int sz) { return zalloc (sz); }
- void operator delete (void *ptr) { zfree (ptr, sizeof (ZSrvPending_t)); }
-#endif
-};
+} ZSrvPending_t;
-class ZServerDesc_t {
+typedef struct _ZServerDesc_t {
+ server_state zs_state; /* server's state */
struct sockaddr_in zs_addr; /* server's address */
- friend void server_reset (void);
- friend void server_recover (ZClient_t *);
- friend void server_hello (ZServerDesc_t *, int);
- friend void setup_server (ZServerDesc_t *, in_addr *);
- friend void server_shutdown (void);
- friend void server_forw_reliable (ZServerDesc_t*, caddr_t, int,
- ZNotice_t *);
- friend void srv_rexmit (void*);
- friend ZServerDesc_t*server_which_server(sockaddr_in*);
- public:
long zs_timeout; /* Length of timeout in sec */
timer zs_timer; /* timer struct for this server */
- ZHostList_t *zs_hosts; /* pointer to list of info from this
+ struct _ZHostList_t *zs_hosts; /* pointer to list of info from this
server */
- ZSrvPending_t *zs_update_queue; /* queue of packets to send
+ struct _ZSrvPending_t *zs_update_queue; /* queue of packets to send
to this server when done dumping */
short zs_numsent; /* number of hello's sent */
- unsigned int zs_dumping : 1; /* 1 if dumping, so we should queue */
+ unsigned int zs_dumping; /* 1 if dumping, so we should queue */
char addr[16]; /* text version of address */
- private:
- server_state zs_state; /* server's state */
- public:
- server_state state () {
- return zs_state;
- }
- void set_state (server_state s) {
- zs_state = s;
- }
-};
-
-enum ZSentType {
+} ZServerDesc_t;
+
+typedef enum ZSentType {
NOT_SENT, /* message was not xmitted */
SENT, /* message was xmitted */
AUTH_FAILED, /* authentication failed */
NOT_FOUND /* user not found for uloc */
-};
-
-class SignalBlock {
- int old_mask;
-public:
- SignalBlock (int mask) {
- old_mask = sigblock (mask);
- }
- ~SignalBlock () {
- (void) sigsetmask (old_mask);
- }
-};
-const int dump_masks = sigmask (SIGFPE) | sigmask (SIGEMT);
-
-/* useful... */
-extern "C" char * inet_ntoa (struct in_addr);
-inline char * inet_ntoa (struct sockaddr_in &s) {
- return inet_ntoa (s.sin_addr);
-}
+} ZSentType;
+
+/* statistics gathering */
+typedef struct _ZStatistic_t {
+ int val;
+ char *str;
+} ZStatistic;
+
+#ifdef __STDC__
+# define P(s) s
+#else
+# define P(s) ()
+#endif
/* Function declarations */
/* 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,
+extern void bdump_get P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
+ ZServerDesc_t *server));
+extern void bdump_send P((void));
+extern void bdump_offer P((struct sockaddr_in *who));
+extern Code_t bdump_send_list_tcp P((ZNotice_Kind_t kind, int port,
+ char *class_name, char *inst, char *opcode,
char *sender, char *recip,
- const char **lyst, int num);
+ char **lyst, int num));
/* found in class.c */
-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;
-}
+extern Code_t class_register P((ZClient_t *client, ZSubscr_t *subs));
+extern Code_t class_deregister P((ZClient_t *client, ZSubscr_t *subs));
+extern Code_t class_restrict P((char *z_class, ZAcl_t *acl));
+extern Code_t class_setup_restricted P((char *z_class, ZAcl_t *acl));
+extern ZClientList_t *class_lookup P((ZSubscr_t *subs));
+extern ZAcl_t *class_get_acl P((ZSTRING *z_class));
+extern void class_free P((ZClientList_t *lyst));
+extern ZSTRING *class_control, *class_admin, *class_hm;
+extern ZSTRING *class_ulogin, *class_ulocate;
+extern void set_ZDestination_hash P((ZDestination *zd));
+extern int ZDest_eq P((ZDestination *zd1, ZDestination *zd2));
+extern int order_dest_strings P((ZDestination *zd1, ZDestination *zd2));
/* found in client.c */
-extern Code_t client_register(ZNotice_t *notice, struct sockaddr_in *who,
+extern Code_t client_register P((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);
+ ZServerDesc_t *server, int wantdefaults));
+extern void client_deregister P((ZClient_t *client, ZHostList_t *host,
+ int flush));
+extern void client_dump_clients P((FILE *fp, ZClientList_t *clist));
+extern ZClient_t *client_which_client P((struct sockaddr_in *who,
+ ZNotice_t *notice));
/* found in common.c */
-extern char *strsave(const char *str);
-extern unsigned long hash (const char *);
+extern char *strsave P((Zconst char *str));
+extern unsigned long hash P((Zconst char *));
/* found in dispatch.c */
-extern void handle_packet(void);
-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;
+extern void handle_packet P((void));
+extern void clt_ack P((ZNotice_t *notice, struct sockaddr_in *who,
+ ZSentType sent));
+extern void nack_release P((ZClient_t *client));
+extern void sendit P((register ZNotice_t *notice, int auth,
+ struct sockaddr_in *who));
+extern void rexmit P((void *));
+extern void xmit P((register ZNotice_t *notice, struct sockaddr_in *dest,
+ int auth, ZClient_t *client));
+extern Code_t control_dispatch P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who,
+ ZServerDesc_t *server));
+extern Code_t xmit_frag P((ZNotice_t *notice, char *buf, int len,
+ int waitforack));
/* found in hostm.c */
-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 *);
+extern void hostm_flush P((ZHostList_t *host, ZServerDesc_t *server));
+extern void hostm_shutdown P((void));
+extern void hostm_losing P((ZClient_t *client, ZHostList_t *host));
+extern ZHostList_t *hostm_find_host P((struct in_addr *addr));
+extern ZServerDesc_t *hostm_find_server P((struct in_addr *addr));
+extern void hostm_transfer P((ZHostList_t *host, ZServerDesc_t *server));
+extern void hostm_deathgram P((struct sockaddr_in *sin,
+ ZServerDesc_t *server));
+extern void hostm_dump_hosts P((FILE *fp));
+extern Code_t hostm_dispatch P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server));
+extern void hostm_lose_ignore P((ZClient_t *client));
+extern void hostm_renumber_servers P((int *));
/* found in kstuff.c */
#ifdef KERBEROS
-extern int GetKerberosData (int, struct in_addr, AUTH_DAT*, char*, char*);
-extern Code_t SendKerberosData (int, KTEXT, char*, char*);
+extern int GetKerberosData P((int, struct in_addr, AUTH_DAT*, char*, char*));
+extern Code_t SendKerberosData P((int, KTEXT, char*, char*));
#endif
/* found in server.c */
-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 void server_timo P((void *which));
+extern void server_recover P((ZClient_t *client)),
+ server_dump_servers P((FILE *fp));
+extern void server_init P((void)),
+ server_shutdown P((void));
+extern void server_forward P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who));
+extern void server_kill_clt P((ZClient_t *client));
+extern void server_pending_free P((register ZSrvPending_t *pending));
+extern void server_self_queue P((ZNotice_t*, int, struct sockaddr_in *)),
+ server_send_queue P((ZServerDesc_t *)),
+ server_reset P((void));
extern int is_server();
-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);
+extern ZServerDesc_t *server_which_server P((struct sockaddr_in *who));
+extern ZSrvPending_t *server_dequeue P((register ZServerDesc_t *server));
+extern Code_t server_dispatch P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who));
+extern Code_t server_adispatch P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who,
+ ZServerDesc_t *server));
/* found in subscr.c */
-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);
+extern Code_t subscr_cancel P((struct sockaddr_in *sin, ZNotice_t *notice));
+extern Code_t subscr_subscribe P((ZClient_t *who, ZNotice_t *notice)),
+ subscr_send_subs P((ZClient_t *client, char *vers));;
+extern ZClientList_t *subscr_match_list P((ZNotice_t *notice));
+extern void subscr_free_list P((ZClientList_t *list)),
+ subscr_cancel_client P((register ZClient_t *client)),
+ subscr_sendlist P((ZNotice_t *notice, int auth, struct sockaddr_in *who));
+extern void subscr_dump_subs P((FILE *fp, ZSubscr_t *subs)),
+ subscr_reset P((void));
+extern Code_t subscr_def_subs P((ZClient_t *who));
/* found in uloc.c */
-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);
+extern void uloc_hflush P((struct in_addr *addr)),
+ uloc_flush_client P((struct sockaddr_in *sin)),
+ uloc_dump_locs P((register FILE *fp));
+extern Code_t ulogin_dispatch P((ZNotice_t *notice, int auth,
+ struct sockaddr_in *who, ZServerDesc_t *server)),
+ ulocate_dispatch P((ZNotice_t *notice, int auth, struct sockaddr_in *who,
+ ZServerDesc_t *server)),
+ uloc_send_locations P((ZHostList_t *host, char *vers));
+
+/* found in version.c */
+extern char *get_version P((void));
+
+#undef P
+
/* global identifiers */
@@ -455,19 +320,37 @@ extern int nfildes; /* number to look at in select() */
extern int zdebug;
extern char myname[]; /* domain name of this host */
extern ZNotAcked_t *nacklist; /* list of not ack'ed packets */
-extern char version[];
+extern Zconst char version[];
extern u_long npackets; /* num of packets processed */
extern long uptime; /* time we started */
+extern struct in_addr my_addr;
/* found in bdump.c */
extern int bdumping; /* are we dumping right now? */
+/* found in dispatch.c */
+extern ZStatistic i_s_ctls, i_s_logins, i_s_admins, i_s_locates;
+extern int num_rexmits;
+extern long rexmit_secs, abs_timo;
+
/* found in server.c */
extern ZServerDesc_t *otherservers; /* array of servers */
extern int me_server_idx; /* me (in the array of servers) */
extern int nservers; /* number of other servers*/
-extern "C" struct in_addr my_addr; /* my inet address */
+/* found in subscr.c */
+extern ZSTRING *empty;
+extern ZSTRING *wildcard_instance;
+extern ZSTRING *wildcard_class;
+extern ZSubscr_t matchall_sub;
+
+extern struct in_addr my_addr; /* my inet address */
+
+#define class_is_control(classname) (classname == class_control)
+#define class_is_admin(classname) (classname == class_admin)
+#define class_is_hm(classname) (classname == class_hm)
+#define class_is_ulogin(classname) (classname == class_ulogin)
+#define class_is_ulocate(classname) (classname == class_ulocate)
#define ADMIN_HELLO "HELLO" /* Opcode: hello, are you there */
#define ADMIN_IMHERE "IHEARDYOU" /* Opcode: yes, I am here */
@@ -484,29 +367,25 @@ extern "C" struct in_addr my_addr; /* my inet address */
#define ADMIN_YOU "YOUR_STATE" /* Class inst: please send your state*/
#define ADMIN_ME "MY_STATE" /* Class inst: please send my info */
-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;
+#define NULLZCT ((ZClass_t *) 0)
+#define NULLZCNT ((ZClient_t *) 0)
+#define NULLZCLT ((ZClientList_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)
/* 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])
-inline int limbo_server_idx () {
- return 0;
-}
+#define limbo_server_idx() (0)
#define limbo_server (&otherservers[limbo_server_idx()])
-inline int msgs_queued () {
- return ZQLength () || otherservers[me_server_idx].zs_update_queue;
-}
+#define msgs_queued() (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)
@@ -515,10 +394,8 @@ inline int msgs_queued () {
/* 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
@@ -530,23 +407,4 @@ extern const ZString wildcard_instance;
#define zdbug(s1)
#endif /* DEBUG */
-/* statistics gathering */
-class statistic {
- int val;
- const char *str;
-public:
- statistic (const char *label) { val = 0; str = label; }
- int value () { return val; }
- void reset () { val = 0; }
- void operator++ () { val++; }
- void log (int do_reset = 0) {
- if (do_reset) {
- syslog (LOG_INFO, "stats: %s: %d since last report", str, val);
- reset ();
- }
- else
- syslog (LOG_INFO, "stats: %s: %d", str, val);
- }
-};
-
#endif /* !__ZSERVER_H__ */
diff --git a/server/zsrv_conf.h b/server/zsrv_conf.h
index 556c268..6723223 100644
--- a/server/zsrv_conf.h
+++ b/server/zsrv_conf.h
@@ -18,27 +18,27 @@
/* Magic path names */
#ifndef HESIOD
-#define SERVER_LIST_FILE Z_LIBDIR "/server.list"
+#define SERVER_LIST_FILE "/usr/athena/lib/zephyr/server.list"
#endif /* !HESIOD */
/* ACL's for pre-registered classes */
/* Directory containing acls and other info */
-#define ZEPHYR_ACL_DIR Z_LIBDIR "/"
+#define ZEPHYR_ACL_DIR "/usr/athena/lib/zephyr/"
/* name of the class registry */
#define ZEPHYR_CLASS_REGISTRY "class-registry.acl"
#ifdef KERBEROS
/* name of file to hold the tickets for keys to exchange with other servers */
-#define ZEPHYR_TKFILE Z_LIBDIR "/ztkts"
+#define ZEPHYR_TKFILE "/usr/athena/lib/zephy/ztkts"
/* Pathname of Kerberos srvtab file.
WARNING: lib/ZCheckAuthentication.c needs to have a corresponding
definition! */
-#define SERVER_SRVTAB Z_LIBDIR "/srvtab"
+#define SERVER_SRVTAB "/usr/athena/lib/zephyr/srvtab"
#endif
/* default subscription file */
-#define DEFAULT_SUBS_FILE Z_LIBDIR "/default.subscriptions"
+#define DEFAULT_SUBS_FILE "/usr/athena/lib/zephyr/default.subscriptions"
/* client defines */
#define REXMIT_SECS ((long) 20) /* rexmit delay on normal notices */
diff --git a/server/zstring.c b/server/zstring.c
index 575adc9..f9377da 100644
--- a/server/zstring.c
+++ b/server/zstring.c
@@ -1,19 +1,34 @@
-/*
- * Copyright (C) 1991 by the Massachusetts Institute of Technology.
- * For copying and distribution information, see the file "mit-copyright.h".
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains the main loop of the Zephyr server
+ *
+ * Created by: Lucien W. Van Elsen
*
* $Source$
- * $Id$
* $Author$
+ *
+ * Copyright (c) 1991 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
*/
+#include <zephyr/mit-copyright.h>
+
+#ifndef lint
+#ifndef SABER
+static char rcsid_zstring_c[] =
+ "$Id$";
+#endif
+#endif
+
#include <mit-copyright.h>
#include <ctype.h>
-#ifdef __STDC__
+#if defined(__STDC__) && !defined(__HIGHC__) && !defined(SABER)
#include <stdlib.h>
#endif
#include <string.h>
+
+#include <zephyr/zephyr.h>
#include "zstring.h"
static ZSTRING *zhash[ZSTRING_HASH_TABLE_SIZE];
@@ -24,8 +39,8 @@ static ZSTRING *zhash[ZSTRING_HASH_TABLE_SIZE];
# define P(s) ()
#endif
-extern unsigned long hash P((const char *s));
-extern char *strsave P((const char *s));
+extern unsigned long hash P((Zconst char *s));
+extern char *strsave P((Zconst char *s));
#undef P
ZSTRING *
@@ -35,7 +50,7 @@ make_zstring(s, downcase)
{
char *new_s,*p;
ZSTRING *new_z,*hp;
- int hash_val;
+ int i;
if (downcase) {
new_s = strsave(s);
@@ -61,19 +76,20 @@ make_zstring(s, downcase)
if (!downcase)
new_s = strsave(s);
- new_z = malloc(sizeof(ZSTRING));
+ new_z = (ZSTRING *) malloc(sizeof(ZSTRING));
new_z->string = new_s;
new_z->len = strlen(new_s);
new_z->ref_count = 1;
/* Add to beginning of hash table */
- hash_val = hash(new_s) % ZSTRING_HASH_TABLE_SIZE;
- hp = zhash[hash_val];
+ new_z->hash_val = hash(new_s);
+ i = new_z->hash_val % ZSTRING_HASH_TABLE_SIZE;
+ hp = zhash[i];
new_z->next = hp;
if (hp != NULL)
hp->prev = new_z;
new_z->prev = NULL;
- zhash[hash_val] = new_z;
+ zhash[i] = new_z;
return(new_z);
}
@@ -82,8 +98,8 @@ void
free_zstring(z)
ZSTRING *z;
{
- ZSTRING *hp;
- int hash_val;
+ if (z == (ZSTRING *) NULL)
+ return;
z->ref_count--;
if (z->ref_count > 0)
@@ -137,8 +153,37 @@ find_zstring(s,downcase)
}
int
-eq_zstring(a,b)
+comp_zstring(a,b)
ZSTRING *a, *b;
{
- return(a == b);
+ if (a->hash_val > b->hash_val)
+ return(1);
+ if (a->hash_val < b->hash_val)
+ return(-1);
+ return(strcmp(a->string,b->string));
+}
+
+void
+print_zstring_table(f)
+ FILE *f;
+{
+ ZSTRING *p;
+ int i;
+
+ for(i=0;i<ZSTRING_HASH_TABLE_SIZE;i++) {
+ p = zhash[i];
+ while (p != (ZSTRING *) NULL) {
+ fprintf(f,"[%d] %s\n",p->ref_count,p->string);
+ p = p->next;
+ }
+ }
+ return;
+}
+
+ZSTRING *
+dup_zstring(z)
+ ZSTRING *z;
+{
+ z->ref_count++;
+ return(z);
}
diff --git a/server/zstring.h b/server/zstring.h
index 7d6fe31..d3fb1a1 100644
--- a/server/zstring.h
+++ b/server/zstring.h
@@ -7,20 +7,23 @@
* $Author$
*/
-#include <mit-copyright.h>
+#include <zephyr/mit-copyright.h>
#ifndef __zstring_h
#define __zstring_h __FILE__
-#define ZSTRING_HASH_TABLE_SIZE 1031
+#define ZSTRING_HASH_TABLE_SIZE 1024
-typedef struct t_zstring
+#include <stdio.h>
+
+typedef struct _zstring
{
char *string; /* the string itself */
int len; /* string length, for speed */
int ref_count; /* for gc */
- struct t_zstring *next; /* for linking in hash table */
- struct t_zstring *prev; /* for linking in hash table */
+ unsigned long hash_val; /* hash value for this string */
+ struct _zstring *next; /* for linking in hash table */
+ struct _zstring *prev; /* for linking in hash table */
} ZSTRING;
#ifdef __STDC__
@@ -32,8 +35,9 @@ typedef struct t_zstring
ZSTRING *make_zstring P((char *s, int downcase));
void free_zstring P((ZSTRING *z));
ZSTRING *find_zstring P((char *s, int downcase));
-int eq_zstring P((ZSTRING *a, ZSTRING *b));
-
+ZSTRING *dup_zstring P((ZSTRING *z));
+int comp_zstring P((ZSTRING *a, ZSTRING *b));
+void print_zstring_table P((FILE *f));
#undef P