diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-09-10 15:01:21 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-09-10 15:04:06 +0300 |
commit | 5d4deb7c304b860d7501b04cdf1185df274ab83c (patch) | |
tree | 94a09630980d24374b32b0c87e6796709ede841b | |
parent | ccdc549cd2540a19f4bff908555aebb2dc3b7bd5 (diff) | |
download | squark-5d4deb7c304b860d7501b04cdf1185df274ab83c.tar.bz2 squark-5d4deb7c304b860d7501b04cdf1185df274ab83c.tar.xz |
auth-snmp: record logins to authdb
with additional info.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | squark-auth-snmp.c | 23 |
2 files changed, 23 insertions, 2 deletions
@@ -13,7 +13,7 @@ LIBS+=-lrt all: $(TARGETS) -squark-auth-snmp: squark-auth-snmp.o blob.o addr.o +squark-auth-snmp: squark-auth-snmp.o authdb.o blob.o addr.o $(CC) -o $@ $^ $(NETSNMP_LIBS) $(LIBS) squark-auth-ip: squark-auth-ip.o authdb.o blob.o addr.o diff --git a/squark-auth-snmp.c b/squark-auth-snmp.c index 3fd253c..bcf1858 100644 --- a/squark-auth-snmp.c +++ b/squark-auth-snmp.c @@ -28,6 +28,7 @@ #include "blob.h" #include "addr.h" +#include "authdb.h" /* Compile time configurables */ #define SWITCH_HASH_SIZE 128 @@ -96,6 +97,7 @@ static int num_queries = 0; static int running = TRUE; static int kick_out = FALSE; +static struct authdb adb; static const char *snmp_community = NULL; static const char *username_format = "%w"; static struct switch_info *all_switches[SWITCH_HASH_SIZE]; @@ -545,14 +547,30 @@ static int auth_ok(struct auth_context *auth) static void auth_completed(struct auth_context *auth) { char tmp[256]; - blob_t b = BLOB_BUF(tmp); + void *token; + struct authdb_entry entry; + blob_t b = BLOB_BUF(tmp), un; + + token = authdb_get(&adb, &auth->addr, &entry, 1); + authdb_clear_entry(&entry); blob_push(&b, BLOB_STRLEN(auth->token)); if (auth_ok(auth)) { + if (token != NULL) { + un = BLOB_BUF(entry.p.login_name); + blob_push_formatted_username(&un, username_format, auth); + memcpy(entry.p.mac_address, auth->mac, MAC_LEN); + entry.p.switch_ip = auth->current_switch->addr; + entry.p.switch_port = auth->local_port; + authdb_commit_login(token, &entry, current_time); + } + blob_push(&b, BLOB_STR(" OK user=")); blob_push_formatted_username(&b, username_format, auth); blob_push(&b, BLOB_PTR_LEN("\n", 1)); } else { + if (token != NULL) + authdb_commit_logout(token); blob_push(&b, BLOB_STR(" ERR\n")); } b = blob_pushed(BLOB_BUF(tmp), b); @@ -1074,6 +1092,8 @@ int main(int argc, char **argv) return 1; } + authdb_open(&adb); + if (l2_root == NULL) l2_root = l3_root; @@ -1112,6 +1132,7 @@ int main(int argc, char **argv) } else snmp_timeout(); } + authdb_close(&adb); return 0; } |