summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMathieu Sauve-Frankel <msf@cvs.openbsd.org>2006-12-24 05:01:09 +0000
committerMathieu Sauve-Frankel <msf@cvs.openbsd.org>2006-12-24 05:01:09 +0000
commit5b3758d3b563d35b683d3f25eb043c7752578d25 (patch)
tree3da796b7dd5a7a1446eafa78ea4c8ae9e349de94 /usr.sbin
parentf9ae506d0111c639aec85b25d95f5d508675f6bd (diff)
first pass cleanup of sasyncd, based on some discussion with deraadt@
inline conf_init into main() and remove it from conf.y. add usage(). small amount of whitespace nits in sasync.h ok deraadt@ mcbride@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sasyncd/conf.y54
-rw-r--r--usr.sbin/sasyncd/sasyncd.c63
-rw-r--r--usr.sbin/sasyncd/sasyncd.h9
3 files changed, 59 insertions, 67 deletions
diff --git a/usr.sbin/sasyncd/conf.y b/usr.sbin/sasyncd/conf.y
index e958d001011..d32a5043865 100644
--- a/usr.sbin/sasyncd/conf.y
+++ b/usr.sbin/sasyncd/conf.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf.y,v 1.11 2006/06/02 20:31:48 moritz Exp $ */
+/* $OpenBSD: conf.y,v 1.12 2006/12/24 05:01:08 msf Exp $ */
/*
* Copyright (c) 2005 Håkan Olsson. All rights reserved.
@@ -269,7 +269,7 @@ yylex(void)
return v;
}
-static int
+int
conf_parse_file(char *cfgfile)
{
struct stat st;
@@ -342,56 +342,6 @@ conf_parse_file(char *cfgfile)
return 1;
}
-int
-conf_init(int argc, char **argv)
-{
- char *cfgfile = 0;
- int ch;
-
- memset(&cfgstate, 0, sizeof cfgstate);
- cfgstate.runstate = INIT;
- LIST_INIT(&cfgstate.peerlist);
-
- cfgstate.listen_port = SASYNCD_DEFAULT_PORT;
-
- while ((ch = getopt(argc, argv, "c:dv")) != -1) {
- switch (ch) {
- case 'c':
- if (cfgfile)
- return 2;
- cfgfile = optarg;
- break;
- case 'd':
- cfgstate.debug++;
- break;
- case 'v':
- cfgstate.verboselevel++;
- break;
- default:
- return 2;
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc > 0)
- return 2;
-
- if (!cfgfile)
- cfgfile = SASYNCD_CFGFILE;
-
- if (conf_parse_file(cfgfile) == 0) {
- if (!cfgstate.sharedkey) {
- fprintf(stderr, "config: "
- "no shared key specified, cannot continue");
- return 1;
- }
- return 0;
- }
-
- return 1;
-}
-
void
yyerror(const char *s)
{
diff --git a/usr.sbin/sasyncd/sasyncd.c b/usr.sbin/sasyncd/sasyncd.c
index 0cca8426af6..2186318d9e4 100644
--- a/usr.sbin/sasyncd/sasyncd.c
+++ b/usr.sbin/sasyncd/sasyncd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sasyncd.c,v 1.13 2006/09/01 01:13:25 mpf Exp $ */
+/* $OpenBSD: sasyncd.c,v 1.14 2006/12/24 05:01:08 msf Exp $ */
/*
* Copyright (c) 2005 Håkan Olsson. All rights reserved.
@@ -130,11 +130,22 @@ sasyncd_run(pid_t ppid)
return 0;
}
+__dead static void
+usage(void)
+{
+ extern char *__progname;
+
+ fprintf(stderr, "Usage: %s [-c config-file] [-d] [-v[v]]\n",
+ __progname);
+ exit(1);
+}
+
int
main(int argc, char **argv)
{
extern char *__progname;
- int r;
+ char *cfgfile = 0;
+ int ch, r;
if (geteuid() != 0) {
/* No point in continuing. */
@@ -154,15 +165,47 @@ main(int argc, char **argv)
log_init(__progname);
timer_init();
- r = conf_init(argc, argv);
- if (r > 1) {
- fprintf(stderr, "Usage: %s [-c config-file] [-d] [-v[v]]\n",
- __progname);
- fprintf(stderr, "Default configuration file is %s\n",
- SASYNCD_CFGFILE);
+ memset(&cfgstate, 0, sizeof cfgstate);
+ cfgstate.runstate = INIT;
+ LIST_INIT(&cfgstate.peerlist);
+
+ cfgstate.listen_port = SASYNCD_DEFAULT_PORT;
+
+ while ((ch = getopt(argc, argv, "c:dv")) != -1) {
+ switch (ch) {
+ case 'c':
+ if (cfgfile)
+ return 2;
+ cfgfile = optarg;
+ break;
+ case 'd':
+ cfgstate.debug++;
+ break;
+ case 'v':
+ cfgstate.verboselevel++;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc > 0)
+ usage();
+
+ if (!cfgfile)
+ cfgfile = SASYNCD_CFGFILE;
+
+ if (conf_parse_file(cfgfile) == 0 ) {
+ if (!cfgstate.sharedkey) {
+ fprintf(stderr, "config: "
+ "no shared key specified, cannot continue");
+ exit(1);
+ }
+ } else {
+ exit(1);
}
- if (r)
- return 1;
carp_demote(CARP_INC, 0);
diff --git a/usr.sbin/sasyncd/sasyncd.h b/usr.sbin/sasyncd/sasyncd.h
index f2564f60c5c..979b97d9089 100644
--- a/usr.sbin/sasyncd/sasyncd.h
+++ b/usr.sbin/sasyncd/sasyncd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sasyncd.h,v 1.11 2006/09/01 01:13:25 mpf Exp $ */
+/* $OpenBSD: sasyncd.h,v 1.12 2006/12/24 05:01:08 msf Exp $ */
/*
* Copyright (c) 2005 Håkan Olsson. All rights reserved.
@@ -102,7 +102,7 @@ extern int carp_demoted;
#define CARP_DEMOTE_MAXTIME 60
/* conf.c */
-int conf_init(int, char **);
+int conf_parse_file(char *);
/* carp.c */
int carp_init(void);
@@ -112,6 +112,8 @@ void carp_update_state(enum RUNSTATE);
void carp_set_rfd(fd_set *);
void carp_read_message(fd_set *);
const char* carp_state_name(enum RUNSTATE);
+void isakmpd_setrun(void);
+
/* log.c */
/*
@@ -162,9 +164,6 @@ void timer_next_event(struct timeval *);
void timer_run(void);
int timer_add(char *, u_int32_t, void (*)(void *), void *);
-/* carp.c */
-void isakmpd_setrun(void);
-
#if defined (GC_DEBUG)
/* Boehms GC */
void *GC_debug_malloc(size_t, char *, int);