s/qmail
4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
sqmail-4.2.29a
src
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_qmail.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
18
#define WHO "qmail-tcpto"
19
20
void
die
(n)
int
n; { buffer_flush(buffer_1);
_exit
(n); }
21
22
void
warn
(s)
char
*s;
23
{
24
char
*x;
25
x = error_str(errno);
26
buffer_puts(buffer_1,s);
27
buffer_puts(buffer_1,
": "
);
28
buffer_puts(buffer_1,x);
29
buffer_puts(buffer_1,
"\n"
);
30
}
31
32
void
die_chdir
() { logmsg(
WHO
,110,FATAL,
"unable to chdir"
); }
33
void
die_open
() { logmsg(
WHO
,112,FATAL,
"unable to open tcpto"
); }
34
void
die_lock
() { logmsg(
WHO
,112,FATAL,
"unable to lock tcpto"
); }
35
void
die_read
() { logmsg(
WHO
,112,FATAL,
"unable to read tcpto"
); }
36
37
char
tcpto_buf
[1024];
38
39
char
tmp
[FMT_ULONG + IPFMT];
40
41
int
main
(
void
)
42
{
43
int
fdlock;
44
int
fd
;
45
int
r;
46
int
i;
47
char
*record;
48
char
ip4
[4];
49
char
ip6
[16];
50
datetime_sec
when;
51
datetime_sec
start;
52
53
if
(chdir(
auto_qmail
) == -1)
die_chdir
();
54
if
(chdir(
"queue/lock"
) == -1)
die_chdir
();
55
56
fdlock = open_write(
"tcpto"
);
57
if
(fdlock == -1)
die_open
();
58
fd
= open_read(
"tcpto"
);
59
if
(
fd
== -1)
die_open
();
60
if
(lock_ex(fdlock) == -1)
die_lock
();
61
r = read(
fd
,
tcpto_buf
,
sizeof
(
tcpto_buf
));
62
close(
fd
);
63
close(fdlock);
64
65
if
(r == -1)
die_read
();
66
r >>= 5;
/* 32 bit read */
67
68
start =
now
();
69
record =
tcpto_buf
;
70
71
for
(i = 0; i < r; ++i) {
72
if
(record[4] >= 1) {
73
when = (
unsigned
long) (
unsigned
char
) record[11];
74
when = (when << 8) + (
unsigned
long
) (
unsigned
char) record[10];
75
when = (when << 8) + (
unsigned
long
) (
unsigned
char) record[9];
76
when = (when << 8) + (
unsigned
long
) (
unsigned
char) record[8];
77
78
if
(record[0] == AF_INET) {
79
byte_copy(&
ip4
,4,record + 16);
80
buffer_put(buffer_1,
tmp
,ip4_fmt(
tmp
,
ip4
));
81
}
else
{
82
byte_copy(&
ip6
,16,record + 16);
83
buffer_put(buffer_1,
tmp
,ip6_fmt(
tmp
,
ip6
));
84
}
85
buffer_puts(buffer_1,
" timed out "
);
86
buffer_put(buffer_1,
tmp
,fmt_ulong(
tmp
,(
unsigned
long
) (start - when)));
87
buffer_puts(buffer_1,
" seconds ago; # recent timeouts: "
);
88
buffer_put(buffer_1,
tmp
,fmt_ulong(
tmp
,(
unsigned
long
) (
unsigned
char
) record[4]));
89
buffer_puts(buffer_1,
"\n"
);
90
}
91
record += 32;
92
}
93
94
die
(0);
95
}
auto_qmail.h
auto_qmail
char auto_qmail[]
datetime.h
datetime_sec
long datetime_sec
Definition:
datetime.h:15
ip6
char ip6[16]
Definition:
dnsptr.c:15
ip4
char ip4[4]
Definition:
dnsptr.c:14
exit.h
_exit
void _exit()
now.h
now
datetime_sec now()
Definition:
now.c:5
fd
int fd
Definition:
qmail-badloadertypes.c:30
die
void die()
Definition:
qmail-pop3d.c:24
die_open
void die_open()
Definition:
qmail-tcpto.c:33
tmp
char tmp[FMT_ULONG+IPFMT]
Definition:
qmail-tcpto.c:39
main
int main(void)
Definition:
qmail-tcpto.c:41
die_read
void die_read()
Definition:
qmail-tcpto.c:35
die_lock
void die_lock()
Definition:
qmail-tcpto.c:34
warn
void warn(char *s)
Definition:
qmail-tcpto.c:22
die_chdir
void die_chdir()
Definition:
qmail-tcpto.c:32
tcpto_buf
char tcpto_buf[1024]
Definition:
qmail-tcpto.c:37
WHO
#define WHO
Definition:
qmail-tcpto.c:18
Generated on Thu Feb 29 2024 20:44:53 for s/qmail by
1.9.6