[hackers] [ubase] login: Write utmp entry || sin
commit d0145aaf1f156606ce1eb1ba32a5e432cd55888a
Author: sin <sin_AT_2f30.org>
Date: Tue Jul 1 15:42:31 2014 +0100
login: Write utmp entry
diff --git a/login.c b/login.c
index aa0ad3c..76d8022 100644
--- a/login.c
+++ b/login.c
_AT_@ -8,7 +8,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
+#include <utmp.h>
#include "config.h"
#include "passwd.h"
_AT_@ -26,7 +28,10 @@ int
main(int argc, char *argv[])
{
struct passwd *pw;
+ struct utmp usr;
+ FILE *fp;
char *pass;
+ char *tty;
uid_t uid;
gid_t gid;
int pflag = 0;
_AT_@ -71,6 +76,24 @@ main(int argc, char *argv[])
if (setuid(uid) < 0)
eprintf("setuid:");
+ /* Write utmp entry */
+ memset(&usr, 0, sizeof(usr));
+
+ tty = ttyname(STDIN_FILENO);
+ if (!tty)
+ tty = "?";
+ usr.ut_type = USER_PROCESS;
+ usr.ut_pid = getpid();
+ strlcpy(usr.ut_user, argv[0], sizeof(usr.ut_user));
+ strlcpy(usr.ut_line, tty, sizeof(usr.ut_line));
+ usr.ut_tv.tv_sec = time(NULL);
+
+ fp = fopen("/var/run/utmp", "a");
+ if (!fp)
+ weprintf("fopen %s:", "/var/run/utmp");
+ fwrite(&usr, sizeof(usr), 1, fp);
+ fclose(fp);
+
return dologin(pw, pflag);
}
Received on Wed Jul 02 2014 - 13:06:02 CEST
This archive was generated by hypermail 2.3.0
: Wed Jul 02 2014 - 13:12:13 CEST