diff options
Diffstat (limited to 'qbiff.c')
| -rw-r--r-- | qbiff.c | 33 |
1 files changed, 9 insertions, 24 deletions
| @@ -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 | ||
| 23 | substdio ssutmp; | ||
| 24 | char bufutmp[sizeof(struct utmp) * 16]; | ||
| 25 | int fdutmp; | ||
| 26 | substdio sstty; | 15 | substdio sstty; |
| 27 | char buftty[1024]; | 16 | char buftty[1024]; |
| 28 | int fdtty; | 17 | int fdtty; |
| 29 | 18 | ||
| 30 | struct utmp ut; | 19 | struct utmpx *ut; |
| 31 | char line[sizeof(ut.ut_line) + 1]; | 20 | char line[sizeof(ut->ut_line) + 1]; |
| 32 | stralloc woof = {0}; | 21 | stralloc woof = {0}; |
| 33 | stralloc tofrom = {0}; | 22 | stralloc tofrom = {0}; |
| 34 | stralloc text = {0}; | 23 | stralloc text = {0}; |
| @@ -50,7 +39,7 @@ void doheader(h) stralloc *h; | |||
| 50 | } | 39 | } |
| 51 | void finishheader() { ; } | 40 | void finishheader() { ; } |
| 52 | 41 | ||
| 53 | void main() | 42 | int 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; |
