Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from obsolete utmp interface to utmpx #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions toys/pending/getty.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ config GETTY
*/
#define FOR_getty
#include "toys.h"
#include <utmp.h>
#include <utmpx.h>

GLOBALS(
char *issue_str;
Expand Down Expand Up @@ -262,35 +262,35 @@ static int read_login_name(void)
// Put hostname entry in utmp file
static void utmp_entry(void)
{
struct utmp entry;
struct utmp *utp_ptr;
struct utmpx entry;
struct utmpx *utp_ptr;
pid_t pid = getpid();
char *utmperr = "can't make utmp entry, host length greater than UT_HOSTSIZE(256)";

utmpname(_PATH_UTMP);
setutent(); // Starts from start
while ((utp_ptr = getutent()))
setutxent(); // Starts from start
while ((utp_ptr = getutxent()))
if (utp_ptr->ut_pid == pid && utp_ptr->ut_type >= INIT_PROCESS) break;
if (!utp_ptr) {
if (!utp_ptr) {
entry.ut_type = LOGIN_PROCESS;
entry.ut_pid = getpid();
xstrncpy(entry.ut_line, ttyname(STDIN_FILENO) +
strlen("/dev/"), UT_LINESIZE);
time((time_t *)&entry.ut_time);
xstrncpy(entry.ut_user, "LOGIN", UT_NAMESIZE);
if (strlen(TT.host_str) > UT_HOSTSIZE) perror_msg_raw(utmperr);
else xstrncpy(entry.ut_host, TT.host_str, UT_HOSTSIZE);
setutent();
pututline(&entry);
xstrncpy(entry.ut_line, ttyname(STDIN_FILENO) +
strlen("/dev/"), sizeof(entry.ut_line));
time((time_t *)&entry.ut_tv.tv_sec);
xstrncpy(entry.ut_user, "LOGIN", sizeof(entry.ut_user));
if (strlen(TT.host_str) > sizeof(entry.ut_host)) perror_msg_raw(utmperr);
else xstrncpy(entry.ut_host, TT.host_str, sizeof(entry.ut_host));
setutxent();
pututxline(&entry);
return;
}
xstrncpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"), UT_LINESIZE);
xstrncpy(entry.ut_user, "LOGIN", UT_NAMESIZE);
if (strlen(TT.host_str) > UT_HOSTSIZE) perror_msg_raw(utmperr);
else xstrncpy(entry.ut_host, TT.host_str, UT_HOSTSIZE);
time((time_t *)&entry.ut_time);
setutent();
pututline(&entry);
xstrncpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"),
sizeof(entry.ut_line));
xstrncpy(entry.ut_user, "LOGIN", sizeof(entry.ut_user));
if (strlen(TT.host_str) > sizeof(entry.ut_host)) perror_msg_raw(utmperr);
else xstrncpy(entry.ut_host, TT.host_str, sizeof(entry.ut_host));
time((time_t *)&entry.ut_tv.tv_sec);
setutxent();
pututxline(&entry);
}

void getty_main(void)
Expand Down
17 changes: 8 additions & 9 deletions toys/pending/telnetd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ config TELNETD

#define FOR_telnetd
#include "toys.h"
#include <utmp.h>
#include <utmpx.h>
GLOBALS(
char *login_path;
char *issue_path;
Expand Down Expand Up @@ -111,19 +111,18 @@ static void get_sockaddr(char *host, void *buf)

static void utmp_entry(void)
{
struct utmp entry;
struct utmp *utp_ptr;
struct utmpx entry;
struct utmpx *utp_ptr;
pid_t pid = getpid();

utmpname(_PATH_UTMP);
setutent(); //start from start
while ((utp_ptr = getutent()) != NULL) {
setutxent(); //start from start
while ((utp_ptr = getutxent()) != NULL) {
if (utp_ptr->ut_pid == pid && utp_ptr->ut_type >= INIT_PROCESS) break;
}
if (!utp_ptr) entry.ut_type = DEAD_PROCESS;
entry.ut_time = time(0);
setutent();
pututline(&entry);
entry.ut_tv.tv_sec = time(0);
setutxent();
pututxline(&entry);
}

static int listen_socket(void)
Expand Down