summaryrefslogtreecommitdiffstats
path: root/src/aeswepd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/aeswepd.c')
-rw-r--r--src/aeswepd.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/aeswepd.c b/src/aeswepd.c
index 11e77c8..2975647 100644
--- a/src/aeswepd.c
+++ b/src/aeswepd.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <limits.h>
#include <libdaemon/dlog.h>
#include <libdaemon/dpid.h>
@@ -40,9 +41,8 @@
#include "aes.h"
#include "aeswepd.h"
-#include "iwkey.h"
-#include "interface.h"
#include "util.h"
+#include "keyapi.h"
uint8_t aes_key[AES_KEY_LEN];
int rekey_time = 15*60;
@@ -115,11 +115,11 @@ int print_wep_key(FILE *f, int t, uint8_t wep[WEP_KEY_LEN]) {
}
-int rekey(struct interface *i, time_t now, time_t *next_rekey) {
+int rekey(const struct key_api *ka, void *c, time_t now, time_t *next_rekey) {
uint8_t w[WEP_KEY_LEN];
uint32_t t;
- assert(i && n_max_keys >= 1 && next_rekey);
+ assert(n_max_keys >= 1 && next_rekey && ka);
t = now/rekey_time;
@@ -133,7 +133,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -143,7 +143,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t-1, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -152,7 +152,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t+1, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -162,7 +162,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (status_file)
fflush(status_file);
- if (wep_key_finish(i) < 0)
+ if (ka->finish(c) < 0)
return -1;
*next_rekey = (t+1)*rekey_time;
@@ -170,12 +170,14 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
return 0;
}
-int go(struct interface *i) {
+int go(void) {
time_t next_rekey = 0;
int send_retval = 1;
fd_set fds;
time_t now = time(NULL);
int sigfd, r = -1;
+ void *c = NULL;
+ const struct key_api *ka = NULL;
daemon_log(LOG_INFO, "aeswepd "VERSION" initializing. (rekey_time=%i)", rekey_time);
@@ -201,8 +203,16 @@ int go(struct interface *i) {
use_status_file = 0;
}
}
+
+ if (!(ka = key_api_get(interface_name))) {
+ daemon_log(LOG_ERR, "Failed to find key API for specified interface %s", interface_name);
+ goto finish;
+ }
+
+ if (!(c = ka->open(interface_name)))
+ goto finish;
- if (rekey(i, now, &next_rekey) < 0)
+ if (rekey(ka, c, now, &next_rekey) < 0)
goto finish;
daemon_log(LOG_INFO, "aeswepd successfully initialized.");
@@ -221,7 +231,7 @@ int go(struct interface *i) {
now = time(NULL);
if (next_rekey < now) {
- if (rekey(i, now, &next_rekey) < 0)
+ if (rekey(ka, c, now, &next_rekey) < 0)
return -1;
}
@@ -273,6 +283,12 @@ int go(struct interface *i) {
finish:
+ if (c && ka) {
+ ka->close(c);
+ c = NULL;
+ }
+
+
if (status_file) {
fclose(status_file);
unlink(get_status_file_name());
@@ -293,7 +309,7 @@ void usage(char *p) {
if (strrchr(p, '/'))
p = strchr(p, '/')+1;
- printf("%s -- AES Rekeying Daemon for IEEE 802.11b WEP\n\n"
+ printf("%s -- AES Rekeying Daemon for IEEE 802.11 WEP\n\n"
"Usage: %s [options]\n\n"
"Options:\n"
" -n --no-daemon Do not daemonize (for debugging) (%s)\n"
@@ -407,7 +423,7 @@ void parse_args(int argc, char *argv[]) {
break;
case 'K':
- daemon_log(LOG_WARNING, "WARNING: Don't use the --key option, other local users might peek on 'ps'. Proceeding");
+ daemon_log(LOG_WARNING, "WARNING: Don't use the --key option, other local users might peek on 'ps'. Proceeding anyway.");
strncpy(ln, optarg, sizeof(ln)-1);
ln[sizeof(ln)-1] = 0;
_key_set = 1;
@@ -528,7 +544,6 @@ void parse_args(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- struct interface *i = NULL;
int r = 1, j;
pid_t pid;
@@ -560,17 +575,17 @@ int main(int argc, char *argv[]) {
goto finish;
if (pid) {
- int c = 0;
-
// Parent process
- if (wait_on_fork)
- if ((c = daemon_retval_wait(60)) < 0) {
+ if (wait_on_fork) {
+ if ((r = daemon_retval_wait(60)) < 0) {
daemon_log(LOG_WARNING, "Killing background process.");
kill(pid, SIGTERM);
+ r = 1;
}
+ } else
+ r = 0;
- r = c;
goto finish;
}
}
@@ -579,19 +594,13 @@ int main(int argc, char *argv[]) {
for (j = 0; j < MAX_WEP_KEYS; j++)
key_map[j] = j;
- if (!(i = interface_open(interface_name)) < 0)
- goto finish;
-
- if (go(i) < 0)
+ if (go() < 0)
goto finish;
r = 0;
finish:
- if (i)
- interface_close(i);
-
if (interface_name)
free(interface_name);