summaryrefslogtreecommitdiffstats
path: root/squark-auth-ip.c
diff options
context:
space:
mode:
Diffstat (limited to 'squark-auth-ip.c')
-rw-r--r--squark-auth-ip.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/squark-auth-ip.c b/squark-auth-ip.c
index 602969b..1346a2e 100644
--- a/squark-auth-ip.c
+++ b/squark-auth-ip.c
@@ -101,6 +101,13 @@ static void read_input(void)
} while (b.len);
}
+#define DUMPPAR(b, name, fn) \
+ do { \
+ blob_push(b, BLOB_STR("squark_" name "='")); \
+ fn; \
+ blob_push(b, BLOB_STR("'; ")); \
+ } while (0)
+
int main(int argc, char **argv)
{
int opt;
@@ -141,7 +148,6 @@ int main(int argc, char **argv)
if (running < 0) {
struct authdb_entry entry;
void *token;
- char buf1[64], buf2[64], buf3[64];
if (ipaddr.any.sa_family == AF_UNSPEC) {
fprintf(stderr, "IP-address not specified\n");
@@ -168,30 +174,27 @@ int main(int argc, char **argv)
if (authdb_check_login(token, &entry, username, now))
authdb_commit_override(token, &entry, now);
break;
- case DO_PRINT:
- fprintf(stdout,
- "IP-address: %s\n"
- "Username: %s\n"
- "MAC-address: %02x:%02x:%02x:%02x:%02x:%02x\n"
- "Soft block mask: %016llx\n"
- "Hard block mask: %016llx\n"
- "Login time: %s"
- "Last activity time: %s"
- "Override time: %s",
- ip.ptr,
- entry.p.login_name,
- entry.p.mac_address[0],
- entry.p.mac_address[1],
- entry.p.mac_address[2],
- entry.p.mac_address[3],
- entry.p.mac_address[4],
- entry.p.mac_address[5],
- entry.p.block_categories,
- entry.p.hard_block_categories,
- entry.p.login_time ? ctime_r(&entry.p.login_time, buf1) : "<none>\n",
- entry.last_activity_time ? ctime_r(&entry.last_activity_time, buf2) : "<none>\n",
- entry.override_time ? ctime_r(&entry.override_time, buf3) : "<none>\n");
+ case DO_PRINT: {
+ char buf[512];
+ blob_t b = BLOB_BUF(buf);
+
+ DUMPPAR(&b, "ip_address",
+ addr_push_hostaddr(&b, &ipaddr));
+ DUMPPAR(&b, "username",
+ blob_push(&b, BLOB_BUF(entry.p.login_name)));
+ DUMPPAR(&b, "mac_address",
+ blob_push_hexdump(&b, BLOB_BUF(entry.p.mac_address)));
+ DUMPPAR(&b, "login_time",
+ blob_push_ctime(&b, entry.p.login_time));
+ DUMPPAR(&b, "activity_time",
+ blob_push_ctime(&b, entry.last_activity_time));
+ DUMPPAR(&b, "override_time",
+ blob_push_ctime(&b, entry.override_time));
+ blob_push(&b, BLOB_STR("\n"));
+ b = blob_pushed(BLOB_BUF(buf), b);
+ fwrite(b.ptr, b.len, 1, stdout);
break;
+ }
case DO_LOGOUT:
if (authdb_check_login(token, &entry, username, now))
authdb_commit_logout(token);