summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qbiff.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/qbiff.c b/qbiff.c
index a068ad9..c2d474f 100644
--- a/qbiff.c
+++ b/qbiff.c
@@ -1,14 +1,6 @@
1#include <sys/types.h> 1#include <sys/types.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <unistd.h> 3#include <utmpx.h>
4#include <utmp.h>
5#ifndef UTMP_FILE
6#ifdef _PATH_UTMP
7#define UTMP_FILE _PATH_UTMP
8#else
9#define UTMP_FILE "/etc/utmp"
10#endif
11#endif
12#include "stralloc.h" 4#include "stralloc.h"
13#include "substdio.h" 5#include "substdio.h"
14#include "subfd.h" 6#include "subfd.h"
@@ -20,15 +12,12 @@
20#include "env.h" 12#include "env.h"
21#include "exit.h" 13#include "exit.h"
22 14
23substdio ssutmp;
24char bufutmp[sizeof(struct utmp) * 16];
25int fdutmp;
26substdio sstty; 15substdio sstty;
27char buftty[1024]; 16char buftty[1024];
28int fdtty; 17int fdtty;
29 18
30struct utmp ut; 19struct utmpx *ut;
31char line[sizeof(ut.ut_line) + 1]; 20char line[sizeof(ut->ut_line) + 1];
32stralloc woof = {0}; 21stralloc woof = {0};
33stralloc tofrom = {0}; 22stralloc tofrom = {0};
34stralloc text = {0}; 23stralloc text = {0};
@@ -50,7 +39,7 @@ void doheader(h) stralloc *h;
50} 39}
51void finishheader() { ; } 40void finishheader() { ; }
52 41
53void main() 42int main()
54{ 43{
55 char *user; 44 char *user;
56 char *sender; 45 char *sender;
@@ -63,7 +52,7 @@ void main()
63 if (!(user = env_get("USER"))) _exit(0); 52 if (!(user = env_get("USER"))) _exit(0);
64 if (!(sender = env_get("SENDER"))) _exit(0); 53 if (!(sender = env_get("SENDER"))) _exit(0);
65 if (!(userext = env_get("LOCAL"))) _exit(0); 54 if (!(userext = env_get("LOCAL"))) _exit(0);
66 if (str_len(user) > sizeof(ut.ut_name)) _exit(0); 55 if (str_len(user) > sizeof(ut->ut_user)) _exit(0);
67 56
68 if (!stralloc_copys(&tofrom,"*** TO <")) _exit(0); 57 if (!stralloc_copys(&tofrom,"*** TO <")) _exit(0);
69 if (!stralloc_cats(&tofrom,userext)) _exit(0); 58 if (!stralloc_cats(&tofrom,userext)) _exit(0);
@@ -88,15 +77,11 @@ void main()
88 if (!stralloc_cat(&woof,&text)) _exit(0); 77 if (!stralloc_cat(&woof,&text)) _exit(0);
89 if (!stralloc_cats(&woof,"\015\n")) _exit(0); 78 if (!stralloc_cats(&woof,"\015\n")) _exit(0);
90 79
91 fdutmp = open_read(UTMP_FILE); 80 while ((ut = getutxent()) != NULL)
92 if (fdutmp == -1) _exit(0); 81 if (ut->ut_type == USER_PROCESS && !str_diffn(ut->ut_user,user,sizeof(ut->ut_user)))
93 substdio_fdbuf(&ssutmp,read,fdutmp,bufutmp,sizeof(bufutmp));
94
95 while (substdio_get(&ssutmp,&ut,sizeof(ut)) == sizeof(ut))
96 if (!str_diffn(ut.ut_name,user,sizeof(ut.ut_name)))
97 { 82 {
98 byte_copy(line,sizeof(ut.ut_line),ut.ut_line); 83 byte_copy(line,sizeof(ut->ut_line),ut->ut_line);
99 line[sizeof(ut.ut_line)] = 0; 84 line[sizeof(ut->ut_line)] = 0;
100 if (line[0] == '/') continue; 85 if (line[0] == '/') continue;
101 if (!line[0]) continue; 86 if (!line[0]) continue;
102 if (line[str_chr(line,'.')]) continue; 87 if (line[str_chr(line,'.')]) continue;