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