s/qmail
4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
4.3
sqmail-4.3.20
src
setmaillist.c
Go to the documentation of this file.
1
#include <unistd.h>
2
#include <sys/stat.h>
3
#include "buffer.h"
4
#include "logmsg.h"
5
#include "stralloc.h"
6
#include "getln.h"
7
#include "open.h"
8
#include "byte.h"
9
#include "
qmail.h
"
10
11
#define WHO "setmaillist"
12
13
int
rename
(
const
char
*,
const
char
*);
// stdio.h
14
15
void
usage
()
16
{
17
logmsg(
WHO
,100,USAGE,
"setmaillist list.bin list.tmp"
);
18
}
19
20
stralloc
line
= {0};
21
int
match
;
22
23
char
*
fnbin
;
24
char
*
fntmp
;
25
int
fd
;
26
char
buf
[
BUFSIZE_LINE
];
27
buffer
bo
;
28
29
void
writeerr
()
30
{
31
logmsg(
WHO
,111,FATAL,B(
"unable to write to: "
,
fntmp
));
32
}
33
34
static
void
out
(
char
*s,
int
len)
35
{
36
if
(buffer_put(&
bo
,s,len) == -1)
writeerr
();
37
}
38
39
int
main
(
int
argc,
char
*
const
*argv)
40
{
41
umask(033);
42
43
fnbin
= argv[1];
if
(!
fnbin
)
usage
();
44
fntmp
= argv[2];
if
(!
fntmp
)
usage
();
45
46
fd
= open_trunc(
fntmp
);
47
if
(
fd
== -1)
48
logmsg(
WHO
,111,FATAL,B(
"unable to create: "
,
fntmp
));
49
50
buffer_init(&
bo
,buffer_unixwrite,
fd
,
buf
,
sizeof
(
buf
));
51
52
53
do
{
54
if
(getln(buffer_0small,&
line
,&
match
,
'\n'
) == -1)
55
logmsg(
WHO
,111,FATAL,
"unable to read input: "
);
56
57
while
(
line
.len) {
58
if
(
line
.s[
line
.len - 1] !=
'\n'
)
59
if
(
line
.s[
line
.len - 1] !=
' '
)
60
if
(
line
.s[
line
.len - 1] !=
'\t'
)
61
break
;
62
--
line
.len;
63
}
64
65
if
(byte_chr(
line
.s,
line
.len,
'\0'
) !=
line
.len)
66
logmsg(
WHO
,111,FATAL,
"NUL in input"
);
67
68
if
(
line
.len)
69
if
(
line
.s[0] !=
'#'
) {
70
if
((
line
.s[0] ==
'.'
) || (
line
.s[0] ==
'/'
)) {
71
out
(
line
.s,
line
.len);
72
out
(
""
,1);
73
}
74
else
{
75
if
(
line
.len > 800)
76
logmsg(
WHO
,111,FATAL,
"addresses must be under 800 bytes"
);
77
if
(
line
.s[0] !=
'&'
)
78
out
(
"&"
,1);
79
out
(
line
.s,
line
.len);
80
out
(
""
,1);
81
}
82
}
83
84
}
while
(
match
);
85
86
if
(buffer_flush(&
bo
) == -1)
writeerr
();
87
if
(fsync(
fd
) == -1)
writeerr
();
88
if
(close(
fd
) == -1)
writeerr
();
/* NFS stupidity */
89
90
if
(
rename
(
fntmp
,
fnbin
) == -1)
91
logmsg(
WHO
,111,FATAL,B(
"unable to move "
,
fntmp
,
" to: "
,
fnbin
));
92
93
_exit
(0);
94
}
main
int main()
Definition:
chkshsgr.c:6
out
stralloc out
Definition:
dnscname.c:12
_exit
void _exit(int)
qmail.h
BUFSIZE_LINE
#define BUFSIZE_LINE
Definition:
qmail.h:8
fntmp
char * fntmp
Definition:
setmaillist.c:24
usage
void usage()
Definition:
setmaillist.c:15
fnbin
char * fnbin
Definition:
setmaillist.c:23
rename
int rename(const char *, const char *)
fd
int fd
Definition:
setmaillist.c:25
buf
char buf[BUFSIZE_LINE]
Definition:
setmaillist.c:26
line
stralloc line
Definition:
setmaillist.c:20
writeerr
void writeerr()
Definition:
setmaillist.c:29
match
int match
Definition:
setmaillist.c:21
bo
buffer bo
Definition:
setmaillist.c:27
WHO
#define WHO
Definition:
setmaillist.c:11
Generated on Thu Jan 16 2025 17:42:04 for s/qmail by
1.9.6