summaryrefslogtreecommitdiff
path: root/user/libutempter/port-to-utmpx.patch
blob: d715c42abf9c0a5d18c9d63dd4c84ef0a65f5a2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
--- libutempter-1.1.6/utempter.c.old	2010-11-04 17:14:53.000000000 +0000
+++ libutempter-1.1.6/utempter.c	2018-07-15 07:52:35.620000000 +0000
@@ -32,15 +32,8 @@
 #include <pwd.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#include <utmp.h>
-
-#ifdef __GLIBC__
-# include <pty.h>
-#elif defined(__FreeBSD__)
-# include <libutil.h>
-#else
-# error Unsupported platform
-#endif /* __GLIBC__ || __FreeBSD__ */
+#include <paths.h>  /* _PATH_WTMP */
+#include <utmpx.h>
 
 #define	DEV_PREFIX	"/dev/"
 #define	DEV_PREFIX_LEN	(sizeof(DEV_PREFIX)-1)
@@ -106,17 +99,12 @@
 
 static int
 write_uwtmp_record(const char *user, const char *term, const char *host,
-#ifdef __GLIBC__
 		   pid_t pid,
-#endif
 		   int add)
 {
-	struct utmp ut;
+	struct utmpx ut;
 	struct timeval tv;
-
-#ifdef __GLIBC__
 	size_t offset;
-#endif
 
 	memset(&ut, 0, sizeof(ut));
 
@@ -128,8 +116,6 @@
 	if (host)
 		strncpy(ut.ut_host, host, sizeof(ut.ut_host));
 
-#ifdef __GLIBC__
-
 	offset = (strlen(term) <= sizeof(ut.ut_id)) ? 0 :
 			strlen(term) - sizeof(ut.ut_id);
 	strncpy(ut.ut_id, term + offset, sizeof(ut.ut_id));
@@ -144,38 +130,17 @@
 	ut.ut_tv.tv_sec = tv.tv_sec;
 	ut.ut_tv.tv_usec = tv.tv_usec;
 
-	setutent();
-	if (!pututline(&ut))
+	setutxent();
+	if (!pututxline(&ut))
 	{
 #ifdef	UTEMPTER_DEBUG
 		fprintf(stderr, "utempter: pututline: %s\n", strerror(errno));
 #endif
 		exit(EXIT_FAILURE);
 	}
-	endutent();
-
-	(void) updwtmp(_PATH_WTMP, &ut);
-
-#elif defined(__FreeBSD__)
-
-	ut.ut_time = tv.tv_sec;
-
-	if (add)
-	{
-		login(&ut);
-	} else
-	{
-		if (logout(term) != 1)
-		{
-#ifdef	UTEMPTER_DEBUG
-			fprintf(stderr, "utempter: logout: %s\n",
-				strerror(errno));
-#endif
-			exit(EXIT_FAILURE);
-		}
-	}
+	endutxent();
 
-#endif /* __GLIBC__ || __FreeBSD__ */
+	(void) updwtmpx(_PATH_WTMP, &ut);
 
 #ifdef	UTEMPTER_DEBUG
 	fprintf(stderr,
@@ -255,8 +220,6 @@
 	validate_device(device);
 
 	return write_uwtmp_record(pw->pw_name, device + DEV_PREFIX_LEN, host,
-#ifdef __GLIBC__
 				  pid,
-#endif
 				  add);
 }