Skip to content

Commit

Permalink
#204: Rework utmp check (#213)
Browse files Browse the repository at this point in the history
This reworks the utmp check to not check every element.

Some display managers rely on the legacy property ut_addr, which is mapped to ut_addr_v6[0].

If they use ut_addr and just set it to zero the other fields are kinda "undefined" / not necessary 0
  • Loading branch information
mcdope committed Jan 2, 2024
1 parent c5c336f commit b26dec4
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "log.h"
#include "conf.h"
#include "process.h"
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b26dec4

Please sign in to comment.