diff --git a/authd.c b/authd.c index 6d9f83e..c2d6c6f 100644 --- a/authd.c +++ b/authd.c @@ -478,7 +478,7 @@ static request_t created_request(int argc, char *argv[]) { static char *created_hostname(const char *node) { char *s; - struct addrinfo *res, hints = { ai_flags: AI_CANONNAME }; + struct addrinfo *res, hints = { .ai_flags = AI_CANONNAME }; assert(node != NULL && *node != '\0'); if (opt.resolve && getaddrinfo(node, NULL, &hints, &res) == 0) { @@ -620,6 +620,25 @@ typedef struct { static const size_t USERID_MAX_LEN = 512; // as per RFC1413 static const char *const TEXT_READ_MODE = "r"; // passphrase, /proc plaintext + +static char *created_verbose(const char *name, unsigned long id, + const char *laddr, unsigned long lport, + const char *raddr, unsigned long rport) { + size_t n; time_t tod; + char *s, when[USERID_MAX_LEN], *host1, *port1, *host2, *port2; + const char *const UTC_FMT = "%FT%TZ", *const TZ_FMT = "(%a %EX %z/%Z)"; + const char *const VERBOSE_FMT = "%s:%lu,%s,%s|%s,%s|%s"; + + if (time(&tod) == (time_t) -1) handle_error(NULL); + n = strftime(when, sizeof(when), UTC_FMT, gmtime(&tod)); + strftime(when + n, sizeof(when) - n, TZ_FMT, localtime(&tod)); + host1 = created_hostname(laddr); port1 = created_servicename(lport); + host2 = created_hostname(raddr); port2 = created_servicename(rport); + asprintf(&s, VERBOSE_FMT, name, id, when, host1, port1, host2, port2); + free(host1); free(port1); free(host2); free(port2); + return s; +} + static bool get_info(reply_t *out, request_t in, const char *tcpname) { //unsigned long lport, rport, uid, status; FILE *stream; unsigned long lport, rport, status; FILE *stream; @@ -629,22 +648,6 @@ static bool get_info(reply_t *out, request_t in, const char *tcpname) { char *laddr = NULL, *raddr = NULL; bool is_port_pair_found = false; - char *created_verbose(const char *name, unsigned long id) { - size_t n; time_t tod; - char *s, when[USERID_MAX_LEN], *host1, *port1, *host2, *port2; - const char *const UTC_FMT = "%FT%TZ", *const TZ_FMT = "(%a %EX %z/%Z)"; - const char *const VERBOSE_FMT = "%s:%lu,%s,%s|%s,%s|%s"; - - if (time(&tod) == (time_t) -1) handle_error(NULL); - n = strftime(when, sizeof(when), UTC_FMT, gmtime(&tod)); - strftime(when + n, sizeof(when) - n, TZ_FMT, localtime(&tod)); - host1 = created_hostname(laddr); port1 = created_servicename(lport); - host2 = created_hostname(raddr); port2 = created_servicename(rport); - asprintf(&s, VERBOSE_FMT, name, id, when, host1, port1, host2, port2); - free(host1); free(port1); free(host2); free(port2); - return s; - } - assert(out != NULL); if (tcpname == NULL) return false; if ((stream = fopen(tcpname, TEXT_READ_MODE)) == NULL) { @@ -779,7 +782,7 @@ static bool get_info(reply_t *out, request_t in, const char *tcpname) { if (opt.verbose && !out->error) { char *brief = out->s; - if ((out->s = created_verbose(brief, uid)) == NULL) + if ((out->s = created_verbose(brief, uid, laddr, lport, raddr, rport)) == NULL) out->error = true; else free(brief); } @@ -863,7 +866,7 @@ static char *created_ciphertext_b64(const char *s) { BIO *encoder; char *b64; const char *const MAGIC = "Salted__"; // openssl compat: enc -salt const char *const NL = "\n"; // is strcat()ed to plaintext - crypto_t x = { cipher: NULL }; + crypto_t x = { .cipher = NULL }; assert(s != NULL); OpenSSL_add_all_ciphers(); @@ -908,7 +911,7 @@ static char *created_ciphertext_b64(const char *s) { } static reply_t created_reply(request_t in) { - reply_t out = { lport: 0, rport: 0 }; + reply_t out = { .lport = 0, .rport = 0 }; bool is_invalid_port = false; unsigned attempts = 0;