diff options
Diffstat (limited to 'src/squark-auth-ip.c')
-rw-r--r-- | src/squark-auth-ip.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/squark-auth-ip.c b/src/squark-auth-ip.c index 9b6ab15..677c008 100644 --- a/src/squark-auth-ip.c +++ b/src/squark-auth-ip.c @@ -18,6 +18,7 @@ #include "blob.h" #include "authdb.h" #include "filterdb.h" +#include "reporting.h" #define DO_LOGIN -1 #define DO_OVERRIDE -2 @@ -120,7 +121,9 @@ int main(int argc, char **argv) sockaddr_any ipaddr = { .any.sa_family = AF_UNSPEC }; blob_t ip = BLOB_NULL, username = BLOB_NULL; - while ((opt = getopt(argc, argv, "Vi:u:olpLr")) != -1) { + reporting_init("squark-auth-ip"); + + while ((opt = getopt(argc, argv, "Vi:u:olpLrsqv::")) != -1) { switch (opt) { case 'V': fprintf(stderr, "squark-auth-ip %s\n", squark_version); @@ -128,8 +131,7 @@ int main(int argc, char **argv) case 'i': ip = BLOB_STRLEN(optarg); if (!addr_parse(ip, &ipaddr)) { - fprintf(stderr, "'%s' does not look like IP-address\n", - optarg); + report_error("'%s' does not look like IP-address\n", optarg); return 1; } break; @@ -151,17 +153,28 @@ int main(int argc, char **argv) case 'r': running = DO_REFRESH; break; + case 's': + reporting_use_syslog(1); + break; + case 'q': + reporting_verbosity(REPORT_ALERT); + break; + case 'v': + if (optarg == 0) + reporting_verbosity(REPORT_INFO); + else if (*optarg == 'v') + reporting_verbosity(REPORT_DEBUG); + break; } } now = time(NULL); if (sqdb_open(&db, squark_dbname) < 0) { - fprintf(stderr, "%s: failed to open squarkdb\n", - squark_dbname); + report_error("%s: failed to open squarkdb\n", squark_dbname); goto err_sqdb; } if (authdb_open(&adb, &adbc, &db) < 0) { - fprintf(stderr, "Failed to initialize authdb\n"); + report_error("Failed to initialize authdb\n"); goto err_adb; } @@ -171,20 +184,20 @@ int main(int argc, char **argv) void *token; if (ipaddr.any.sa_family == AF_UNSPEC) { - fprintf(stderr, "IP-address not specified\n"); + report_error("IP-address not specified\n"); return 2; } token = authdb_get(&adb, &ipaddr, &entry, 1); if (token == NULL) { - fprintf(stderr, "Failed to get authdb record\n"); + report_error("Failed to get authdb record\n"); return 3; } switch (running) { case DO_LOGIN: if (blob_is_null(username)) { - fprintf(stderr, "Username not specified\n"); + report_error("Username not specified\n"); return 2; } authdb_clear_entry(&entry); |