summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Karl Ramm <kcr@1ts.org>2013-01-19 19:43:37 -0500
committerGravatar Karl Ramm <kcr@1ts.org>2013-03-16 23:57:54 -0700
commit9e361ec4b0fbf61fc743bae78ab1b6e30c4a2742 (patch)
treef00a4a69a9c942c8c593dbc2049212265be55f2c
parentc88af26f7f05d532ab46ab8b2ff22e20d05fa13d (diff)
rearrange so that most of the server code can be linked without main.c
Move global variables and one function out of main.c so that the rest of the server can be linked with a test harness.
-rw-r--r--server/bdump.c4
-rw-r--r--server/common.c16
-rw-r--r--server/global.c72
-rw-r--r--server/main.c74
-rw-r--r--server/zserver.h7
5 files changed, 98 insertions, 75 deletions
diff --git a/server/bdump.c b/server/bdump.c
index 505e582..344adcf 100644
--- a/server/bdump.c
+++ b/server/bdump.c
@@ -105,8 +105,6 @@ static Z_AuthProc bdump_auth_proc;
int bdumping;
int bdump_concurrent;
-extern char *bdump_version;
-extern int bdump_auth_proto;
/*
* Functions for performing a brain dump between servers.
@@ -201,7 +199,7 @@ bdump_offer(struct sockaddr_in *who)
/* myname is the hostname */
/* the class instance is the version number, here it is */
- /* bdump_version, which is set in main */
+ /* bdump_version, which is set in global.c */
send_list(ACKED, srv_addr.sin_port, ZEPHYR_ADMIN_CLASS, bdump_version,
ADMIN_BDUMP, myname, "", lyst, 2);
diff --git a/server/common.c b/server/common.c
index 4af40c7..1666ec4 100644
--- a/server/common.c
+++ b/server/common.c
@@ -112,3 +112,19 @@ notice_extract_address(ZNotice_t *notice, struct sockaddr_in *addr)
addr->sin_port = notice->z_port;
addr->sin_family = AF_INET;
}
+
+
+int
+packets_waiting(void)
+{
+ fd_set readable, initial;
+ struct timeval tv;
+
+ if (msgs_queued())
+ return 1;
+ FD_ZERO(&initial);
+ FD_SET(srv_socket, &initial);
+ readable = initial;
+ tv.tv_sec = tv.tv_usec = 0;
+ return (select(srv_socket + 1, &readable, NULL, NULL, &tv) > 0);
+}
diff --git a/server/global.c b/server/global.c
new file mode 100644
index 0000000..69aea1f
--- /dev/null
+++ b/server/global.c
@@ -0,0 +1,72 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains the global variables used by the server. (moved from main.c)
+ *
+ * Created by: Karl Ramm
+ *
+ * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+
+#include <zephyr/mit-copyright.h>
+#include "zserver.h"
+#include <sys/socket.h>
+#include <sys/resource.h>
+
+int nfds; /* max file descriptor for select() */
+int srv_socket; /* dgram socket for clients
+ and other servers */
+int bdump_socket = -1; /* brain dump socket fd
+ (closed most of the time) */
+fd_set interesting; /* the file descrips we are listening
+ to right now */
+struct sockaddr_in srv_addr; /* address of the socket */
+
+Unacked *nacklist = NULL; /* list of packets waiting for ack's */
+
+unsigned short hm_port; /* host manager receiver port */
+unsigned short hm_srv_port; /* host manager server sending port */
+
+char myname[NS_MAXDNAME]; /* my host name */
+
+char list_file[128];
+#ifdef HAVE_KRB5
+char keytab_file[128];
+#endif
+#ifdef HAVE_KRB4
+char srvtab_file[128];
+#endif
+char acl_dir[128];
+char subs_file[128];
+
+int zdebug;
+#ifdef DEBUG
+int zalone;
+#endif
+
+struct timeval t_local; /* store current time for other uses */
+
+
+u_long npackets; /* number of packets processed */
+time_t uptime; /* when we started operations */
+struct in_addr my_addr;
+char *bdump_version = "1.2";
+
+#ifdef HAVE_KRB5
+int bdump_auth_proto = 5;
+#else /* HAVE_KRB5 */
+#ifdef HAVE_KRB4
+int bdump_auth_proto = 4;
+#else /* HAVE_KRB4 */
+int bdump_auth_proto = 0;
+#endif /* HAVE_KRB4 */
+#endif /* HAVE_KRB5 */
+
+#ifdef HAVE_KRB5
+krb5_ccache Z_krb5_ccache;
+krb5_keyblock *__Zephyr_keyblock;
+#else
+#ifdef HAVE_KRB4
+C_Block __Zephyr_session;
+#endif
+#endif
diff --git a/server/main.c b/server/main.c
index 7d7a23f..4b2f9b7 100644
--- a/server/main.c
+++ b/server/main.c
@@ -71,71 +71,22 @@ static void detach(void);
static short doreset = 0; /* if it becomes 1, perform
reset functions */
-int nfds; /* max file descriptor for select() */
-int srv_socket; /* dgram socket for clients
- and other servers */
-int bdump_socket = -1; /* brain dump socket fd
- (closed most of the time) */
-fd_set interesting; /* the file descrips we are listening
- to right now */
-struct sockaddr_in srv_addr; /* address of the socket */
+static char *programname; /* set to the basename of argv[0] */
-Unacked *nacklist = NULL; /* list of packets waiting for ack's */
-
-unsigned short hm_port; /* host manager receiver port */
-unsigned short hm_srv_port; /* host manager server sending port */
-
-char *programname; /* set to the basename of argv[0] */
-char myname[NS_MAXDNAME]; /* my host name */
-
-char list_file[128];
#ifdef HAVE_KRB5
-char keytab_file[128];
static char tkt5_file[256];
#endif
#ifdef HAVE_KRB4
-char srvtab_file[128];
static char tkt_file[128];
#endif
-#if defined(HAVE_KRB4) || defined(HAVE_KRB5)
-char my_realm[REALM_SZ];
-#endif
-char acl_dir[128];
-char subs_file[128];
-
-int zdebug;
-#ifdef DEBUG
-int zalone;
-#endif
-
-struct timeval t_local; /* store current time for other uses */
static int dump_db_flag = 0;
static int dump_strings_flag = 0;
-u_long npackets; /* number of packets processed */
-time_t uptime; /* when we started operations */
static int nofork;
-struct in_addr my_addr;
-char *bdump_version = "1.2";
-
-#ifdef HAVE_KRB5
-int bdump_auth_proto = 5;
-#else /* HAVE_KRB5 */
-#ifdef HAVE_KRB4
-int bdump_auth_proto = 4;
-#else /* HAVE_KRB4 */
-int bdump_auth_proto = 0;
-#endif /* HAVE_KRB4 */
-#endif /* HAVE_KRB5 */
-#ifdef HAVE_KRB5
-krb5_ccache Z_krb5_ccache;
-krb5_keyblock *__Zephyr_keyblock;
-#else
-#ifdef HAVE_KRB4
-C_Block __Zephyr_session;
-#endif
+#if defined(HAVE_KRB4) || defined(HAVE_KRB5)
+static char my_realm[REALM_SZ];
#endif
int
@@ -441,10 +392,10 @@ do_net_setup(void)
hp = gethostbyname(hostname);
if (!hp || hp->h_addrtype != AF_INET) {
syslog(LOG_ERR, "no gethostbyname repsonse");
- strncpy(myname, hostname, sizeof(myname));
+ strncpy(myname, hostname, NS_MAXDNAME);
return 1;
}
- strncpy(myname, hp->h_name, sizeof(myname));
+ strncpy(myname, hp->h_name, NS_MAXDNAME);
memcpy(&my_addr, hp->h_addr_list[0], hp->h_length);
setservent(1); /* keep file/connection open */
@@ -502,21 +453,6 @@ usage(void)
exit(2);
}
-int
-packets_waiting(void)
-{
- fd_set readable, initial;
- struct timeval tv;
-
- if (msgs_queued())
- return 1;
- FD_ZERO(&initial);
- FD_SET(srv_socket, &initial);
- readable = initial;
- tv.tv_sec = tv.tv_usec = 0;
- return (select(srv_socket + 1, &readable, NULL, NULL, &tv) > 0);
-}
-
static RETSIGTYPE
bye(int sig)
{
diff --git a/server/zserver.h b/server/zserver.h
index f0f4fda..c694489 100644
--- a/server/zserver.h
+++ b/server/zserver.h
@@ -286,6 +286,7 @@ char *strsave(const char *str);
unsigned long hash (const char *);
void dump_quote(char *p, FILE *fp);
void notice_extract_address(ZNotice_t *notice, struct sockaddr_in *addr);
+int packets_waiting(void);
/* found in dispatch.c */
void handle_packet(void);
@@ -396,8 +397,7 @@ int opstaff_check(char *);
/* global identifiers */
-/* found in main.c */
-int packets_waiting(void);
+/* found in global.c */
extern struct sockaddr_in srv_addr; /* server socket address */
extern unsigned short hm_port; /* host manager receiver port */
extern unsigned short hm_srv_port; /* host manager server sending port */
@@ -418,7 +418,6 @@ extern krb5_ccache Z_krb5_ccache;
#endif
#ifdef HAVE_KRB4
extern char srvtab_file[];
-extern char my_realm[];
#endif
extern char acl_dir[];
extern char subs_file[];
@@ -427,6 +426,8 @@ extern u_long npackets; /* num of packets processed */
extern time_t uptime; /* time we started */
extern struct in_addr my_addr; /* my inet address */
extern struct timeval t_local; /* current time */
+extern char *bdump_version;
+extern int bdump_auth_proto;
/* found in bdump.c */
extern int bdumping; /* are we processing a bdump packet? */