summaryrefslogtreecommitdiff
path: root/user/netqmail/0002-qbiffutmpx-20170820.patch
blob: a55044f6e46ef78e0b4d7e08ccf11b6f0f27e5cb (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<https://schmonz.com/qmail/qbiffutmpx>

diff --git a/Makefile b/Makefile
index 0f0e31a..ae8d229 100644
--- a/Makefile
+++ b/Makefile
@@ -685,6 +685,13 @@ chkshsgr warn-shsgr tryshsgr.c compile load
 	hasshsgr.h
 	rm -f tryshsgr.o tryshsgr
 
+hasutmpx.h: \
+tryutmpx.c compile load
+	( ( ./compile tryutmpx.c && ./load tryutmpx ) >/dev/null \
+	2>&1 \
+	&& echo \#define HASUTMPX 1 || exit 0 ) > hasutmpx.h
+	rm -f tryutmpx.o tryutmpx
+
 haswaitp.h: \
 trywaitp.c compile load
 	( ( ./compile trywaitp.c && ./load trywaitp ) >/dev/null \
@@ -1071,7 +1078,8 @@ qbiff.1
 
 qbiff.o: \
 compile qbiff.c readwrite.h stralloc.h gen_alloc.h substdio.h subfd.h \
-substdio.h open.h byte.h str.h headerbody.h hfield.h env.h exit.h
+substdio.h open.h byte.h str.h headerbody.h hfield.h env.h exit.h \
+hasutmpx.h
 	./compile qbiff.c
 
 qmail-clean: \
diff --git a/TARGETS b/TARGETS
index facdad7..c37a453 100644
--- a/TARGETS
+++ b/TARGETS
@@ -388,3 +388,4 @@
 man
 setup
 check
+hasutmpx.h
diff --git a/qbiff.c b/qbiff.c
index 4e9f1d8..f21b6bf 100644
--- a/qbiff.c
+++ b/qbiff.c
@@ -1,5 +1,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include "hasutmpx.h"
+#ifdef HASUTMPX
+#include <utmpx.h>
+#else
 #include <utmp.h>
 #ifndef UTMP_FILE
 #ifdef _PATH_UTMP
@@ -8,6 +12,7 @@
 #define UTMP_FILE "/etc/utmp"
 #endif
 #endif
+#endif
 #include "readwrite.h"
 #include "stralloc.h"
 #include "substdio.h"
@@ -20,15 +25,22 @@
 #include "env.h"
 #include "exit.h"
 
+#ifndef HASUTMPX
 substdio ssutmp;
 char bufutmp[sizeof(struct utmp) * 16];
 int fdutmp;
+#endif
 substdio sstty;
 char buftty[1024];
 int fdtty;
 
+#ifdef HASUTMPX
+struct utmpx *ut;
+char line[sizeof(ut->ut_line) + 1];
+#else
 struct utmp ut;
 char line[sizeof(ut.ut_line) + 1];
+#endif
 stralloc woof = {0};
 stralloc tofrom = {0};
 stralloc text = {0};
@@ -63,7 +75,11 @@ void main()
  if (!(user = env_get("USER"))) _exit(0);
  if (!(sender = env_get("SENDER"))) _exit(0);
  if (!(userext = env_get("LOCAL"))) _exit(0);
+#ifdef HASUTMPX
+ if (str_len(user) > sizeof(ut->ut_user)) _exit(0);
+#else
  if (str_len(user) > sizeof(ut.ut_name)) _exit(0);
+#endif
 
  if (!stralloc_copys(&tofrom,"*** TO <")) _exit(0);
  if (!stralloc_cats(&tofrom,userext)) _exit(0);
@@ -88,6 +104,7 @@ void main()
  if (!stralloc_cat(&woof,&text)) _exit(0);
  if (!stralloc_cats(&woof,"\015\n")) _exit(0);
 
+#ifndef HASUTMPX
  fdutmp = open_read(UTMP_FILE);
  if (fdutmp == -1) _exit(0);
  substdio_fdbuf(&ssutmp,read,fdutmp,bufutmp,sizeof(bufutmp));
@@ -97,6 +114,13 @@ void main()
     {
      byte_copy(line,sizeof(ut.ut_line),ut.ut_line);
      line[sizeof(ut.ut_line)] = 0;
+#else
+ while ((ut = getutxent()))
+   if (ut->ut_type == USER_PROCESS && !str_diffn(ut->ut_user,user,sizeof(ut->ut_user)))
+    {
+     byte_copy(line,sizeof(ut->ut_line),ut->ut_line);
+     line[sizeof(ut->ut_line)] = 0;
+#endif
      if (line[0] == '/') continue;
      if (!line[0]) continue;
      if (line[str_chr(line,'.')]) continue;
diff --git a/tryutmpx.c b/tryutmpx.c
new file mode 100644
index 0000000..551b597
--- /dev/null
+++ b/tryutmpx.c
@@ -0,0 +1,6 @@
+#include <utmpx.h>
+
+void main()
+{
+  ;
+}