s/qmail 4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
qmail-tcpto.c
Go to the documentation of this file.
1/* XXX: this program knows quite a bit about tcpto's internals */
2
3#include <sys/socket.h>
4#include <unistd.h>
5#include "buffer.h"
6#include "auto_queue.h"
7#include "fmt.h"
8#include "ip.h"
9#include "lock.h"
10#include "error.h"
11#include "exit.h"
12#include "datetime.h"
13#include "now.h"
14#include "stralloc.h"
15#include "open.h"
16#include "logmsg.h"
17#include "qmail.h"
18
19#define WHO "qmail-tcpto"
20
21void die(n) int n; { buffer_flush(buffer_1); _exit(n); }
22
23void warn(s) char *s;
24{
25 char *x;
26 x = error_str(errno);
27 buffer_puts(buffer_1,s);
28 buffer_puts(buffer_1,": ");
29 buffer_puts(buffer_1,x);
30 buffer_puts(buffer_1,"\n");
31}
32
33void die_chdir() { logmsg(WHO,110,FATAL,"unable to chdir"); }
34void die_open() { logmsg(WHO,112,FATAL,"unable to open tcpto"); }
35void die_lock() { logmsg(WHO,112,FATAL,"unable to lock tcpto"); }
36void die_read() { logmsg(WHO,112,FATAL,"unable to read tcpto"); }
37
39
40char tmp[FMT_ULONG + IPFMT];
41
42int main(void)
43{
44 int fdlock;
45 int fd;
46 int r;
47 int i;
48 char *record;
49 char ip4[4];
50 char ip6[16];
51 datetime_sec when;
52 datetime_sec start;
53
54 if (chdir(auto_queue) == -1) die_chdir();
55 if (chdir("queue/lock") == -1) die_chdir();
56
57 fdlock = open_write("tcpto");
58 if (fdlock == -1) die_open();
59 fd = open_read("tcpto");
60 if (fd == -1) die_open();
61 if (lock_ex(fdlock) == -1) die_lock();
62 r = read(fd,tcpto_buf,sizeof(tcpto_buf));
63 close(fd);
64 close(fdlock);
65
66 if (r == -1) die_read();
67 r >>= 5; /* 32 bit read */
68
69 start = now();
70 record = tcpto_buf;
71
72 for (i = 0; i < r; ++i) {
73 if (record[4] >= 1) {
74 when = (unsigned long) (unsigned char) record[11];
75 when = (when << 8) + (unsigned long) (unsigned char) record[10];
76 when = (when << 8) + (unsigned long) (unsigned char) record[9];
77 when = (when << 8) + (unsigned long) (unsigned char) record[8];
78
79 if (record[0] == AF_INET) {
80 byte_copy(&ip4,4,record + 16);
81 buffer_put(buffer_1,tmp,ip4_fmt(tmp,ip4));
82 } else {
83 byte_copy(&ip6,16,record + 16);
84 buffer_put(buffer_1,tmp,ip6_fmt(tmp,ip6));
85 }
86 buffer_puts(buffer_1," timed out ");
87 buffer_put(buffer_1,tmp,fmt_ulong(tmp,(unsigned long) (start - when)));
88 buffer_puts(buffer_1," seconds ago; # recent timeouts: ");
89 buffer_put(buffer_1,tmp,fmt_ulong(tmp,(unsigned long) (unsigned char) record[4]));
90 buffer_puts(buffer_1,"\n");
91 }
92 record += 32;
93 }
94
95 die(0);
96}
char auto_queue[]
long datetime_sec
Definition: datetime.h:15
char ip6[16]
Definition: dnsptr.c:15
char ip4[4]
Definition: dnsptr.c:14
void _exit(int)
datetime_sec now()
Definition: now.c:5
int fd
void die()
Definition: qmail-start.c:14
char tcpto_buf[BUFSIZE_LINE]
Definition: qmail-tcpto.c:38
void die_open()
Definition: qmail-tcpto.c:34
char tmp[FMT_ULONG+IPFMT]
Definition: qmail-tcpto.c:40
int main(void)
Definition: qmail-tcpto.c:42
void die_read()
Definition: qmail-tcpto.c:36
void die_lock()
Definition: qmail-tcpto.c:35
void warn(char *s)
Definition: qmail-tcpto.c:23
void die_chdir()
Definition: qmail-tcpto.c:33
#define WHO
Definition: qmail-tcpto.c:19
#define BUFSIZE_LINE
Definition: qmail.h:8