diff --git a/src/local.c b/src/local.c index 7cf4db23..3f647714 100644 --- a/src/local.c +++ b/src/local.c @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include "log.h" #include "conf.h" #include "process.h" @@ -55,21 +58,16 @@ int pusb_is_tty_local(char *tty) log_debug(" utmp->ut_user: %s\n", utent->ut_user); } - for (int i = 0; i < 4; ++i) - { - /** - * Note: despite the property name this also works for IPv4, v4 addr would be in ut_addr_v6[0] solely. - * See utmp man (http://manpages.ubuntu.com/manpages/bionic/de/man5/utmp.5.html) - **/ - if (utent->ut_addr_v6[i] != 0) - { - log_error("Remote authentication request: %s\n", utent->ut_host); - return (-1); - } - else - { - log_debug(" Checking utmp->ut_addr_v6[%d]\n", i); - } + /** + * Note: despite the property name this also works for IPv4, v4 addr would be in ut_addr_v6[0] solely while for v6 it will have just a part of the ip. Anyway: if first element is set -> remote + **/ + if (utent->ut_addr_v6[0] != 0) { + struct in_addr ipnetw; + ipnetw.s_addr = utent->ut_addr_v6[0]; + char* ipaddr = inet_ntoa(ipnetw); + + log_error("Remote authentication request, host: %s, ip: %s\n", utent->ut_host, ipaddr); + return (-1); } log_debug(" utmp check successful, request originates from a local source!\n");