s/qmail
4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
sqmail-4.2.29a
src
rcpthosts.c
Go to the documentation of this file.
1
#include "cdbread.h"
2
#include "byte.h"
3
#include "open.h"
4
#include "error.h"
5
#include "
exit.h
"
6
#include "
control.h
"
7
#include "
constmap.h
"
8
#include "stralloc.h"
9
#include "case.h"
10
#include "close.h"
11
#include "fd.h"
12
#include "
rcpthosts.h
"
13
14
static
int
flagrh
= 0;
15
static
int
flagmrh = 0;
16
static
stralloc rh = {0};
17
static
struct
constmap
maprh;
18
static
int
fdmrh;
19
20
static
struct
cdb
cdb
;
21
22
int
rcpthosts_init
()
23
{
24
flagrh
=
control_readfile
(&rh,
"control/rcpthosts"
,0);
25
if
(
flagrh
!= 1)
return
flagrh
;
26
if
(!
constmap_init
(&maprh,rh.s,rh.len,0))
return
flagrh
= -1;
27
fdmrh = open_read(
"control/morercpthosts.cdb"
);
28
if
(fdmrh == -1)
if
(errno != ENOENT)
return
flagmrh = -1;
29
if
(fdmrh > 0) flagmrh = 1;
30
return
0;
31
}
32
33
static
stralloc
host
= {0};
34
35
int
rcpthosts
(
char
*
buf
,
int
len)
36
{
37
int
j
;
38
int
r;
39
40
if
(
flagrh
!= 1)
return
1;
41
42
j
= byte_rchr(
buf
,len,
'@'
);
43
if
(
j
>= len)
return
1;
/* presumably envnoathost is acceptable */
44
45
++
j
;
buf
+=
j
; len -=
j
;
46
47
if
(!stralloc_copyb(&
host
,
buf
,len))
return
-1;
48
buf
=
host
.s;
49
case_lowerb(
buf
,len);
50
51
for
(
j
= 0;
j
< len; ++
j
)
52
if
(!
j
|| (
buf
[
j
] ==
'.'
))
53
if
(
constmap
(&maprh,
buf
+
j
,len -
j
))
return
1;
54
55
if
(flagmrh == 1) {
56
fdmrh = open_read(
"control/morercpthosts.cdb"
);
57
if
(fdmrh == -1)
if
(errno == ENOENT)
return
0;
58
cdb_init(&
cdb
,fdmrh);
59
60
for
(
j
= 0;
j
< len ;++
j
)
61
if
(!
j
|| (
buf
[
j
] ==
'.'
)) {
62
r = cdb_find(&
cdb
,
buf
+
j
,len -
j
);
63
if
(r) { cdb_free(&
cdb
); close(fdmrh);
return
r; }
64
}
65
cdb_free(&
cdb
);
66
close(fdmrh);
67
}
68
69
return
0;
70
}
constmap_init
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
Definition:
constmap.c:35
constmap.h
control_readfile
int control_readfile(stralloc *sa, char *fn, int flagme)
Definition:
control.c:86
control.h
exit.h
cdb
struct cdb cdb
Definition:
fastforward.c:119
buf
char buf[100+FMT_ULONG]
Definition:
hier.c:10
host
char host[256]
Definition:
hostname.c:5
flagrh
int flagrh
Definition:
qmail-inject.c:50
j
int j
Definition:
qmail-send.c:920
rcpthosts_init
int rcpthosts_init()
Definition:
rcpthosts.c:22
rcpthosts.h
rcpthosts
int rcpthosts()
constmap
Definition:
constmap.h:6
Generated on Thu Feb 29 2024 20:44:53 for s/qmail by
1.9.6