|
@@ -5,21 +5,56 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <utmp.h>
|
|
|
|
|
|
-
|
|
|
-void login (const struct utmp *entry)
|
|
|
+
|
|
|
+ * Note: the match in utmp is done against ut_id field,
|
|
|
+ * which is NOT set by this function - caller must set it.
|
|
|
+ */
|
|
|
+void login(const struct utmp *entry)
|
|
|
{
|
|
|
- struct utmp copy = *entry;
|
|
|
+ struct utmp copy;
|
|
|
+ char tty_name[sizeof(copy.ut_line) + 6];
|
|
|
+ int fd;
|
|
|
|
|
|
- utmpname(_PATH_UTMP);
|
|
|
- setutent();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ copy = *entry;
|
|
|
#if _HAVE_UT_TYPE - 0
|
|
|
- copy.ut_type = USER_PROCESS;
|
|
|
+ copy.ut_type = USER_PROCESS;
|
|
|
#endif
|
|
|
#if _HAVE_UT_PID - 0
|
|
|
- copy.ut_pid = getpid();
|
|
|
+ copy.ut_pid = getpid();
|
|
|
#endif
|
|
|
- strncpy (copy.ut_line, entry->ut_line, UT_LINESIZE);
|
|
|
- pututline(entry);
|
|
|
- endutent();
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ fd = 0;
|
|
|
+ while (fd != 3 && ttyname_r(fd, tty_name, sizeof(tty_name)) != 0)
|
|
|
+ fd++;
|
|
|
+ if (fd != 3) {
|
|
|
+ if (strncmp(tty_name, "/dev/", 5) == 0)
|
|
|
+ strncpy(copy.ut_line, tty_name + 5, sizeof(copy.ut_line)-1);
|
|
|
+ else
|
|
|
+ strncpy(copy.ut_line, tty_name, sizeof(copy.ut_line)-1);
|
|
|
+ copy.ut_line[sizeof(copy.ut_line)-1] = '\0';
|
|
|
+
|
|
|
+
|
|
|
+ * this makes it impossible for caller to use other file!
|
|
|
+ * Does any standard or historical precedent says this must be done? */
|
|
|
+ setutent();
|
|
|
+
|
|
|
+ pututline(©);
|
|
|
+ endutent();
|
|
|
+ } else {
|
|
|
+ strncpy(copy.ut_line, "???", sizeof(copy.ut_line));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ updwtmp(_PATH_WTMP, ©);
|
|
|
+}
|