s/qmail
4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
4.3
sqmail-4.3.20
src
qmail-badloadertypes.c
Go to the documentation of this file.
1
#include <unistd.h>
2
#include <stdlib.h>
3
#include <sys/stat.h>
4
#include "logmsg.h"
5
#include "stralloc.h"
6
#include "buffer.h"
7
#include "getln.h"
8
#include "
exit.h
"
9
#include "open.h"
10
#include "
auto_qmail.h
"
11
#include "cdbmake.h"
12
#include "
qmail.h
"
13
14
#define WHO "qmail-badloadertypes"
15
#define LOADER_LEN 5
16
17
int
rename
(
const
char
*,
const
char
*);
// stdio.h
18
19
static
void
die_read
()
20
{
21
logmsg(
WHO
,111,FATAL,
"unable to read control/badloadertypes"
);
22
}
23
static
void
die_write
()
24
{
25
logmsg(
WHO
,111,FATAL,
"unable to write to control/badloadertypes.tmp"
);
26
}
27
28
char
inbuf
[
BUFSIZE_LINE
];
29
buffer
b
;
30
31
int
fd
;
32
int
fdtemp
;
33
34
struct
cdb_make
cdb
;
35
stralloc
line
= {0};
36
int
match
;
37
38
int
main
()
39
{
40
umask(033);
41
if
(chdir(
auto_qmail
) == -1)
42
logmsg(
WHO
,111,FATAL,B(
"unable to chdir to: "
,
auto_qmail
));
43
44
fd
= open_read(
"control/badloadertypes"
);
45
if
(
fd
== -1)
die_read
();
46
47
buffer_init(&
b
,read,
fd
,
inbuf
,
sizeof
(
inbuf
));
48
49
fdtemp
= open_trunc(
"control/badloadertypes.tmp"
);
50
if
(
fdtemp
== -1)
die_write
();
51
52
if
(cdb_make_start(&
cdb
,
fdtemp
) == -1)
die_write
();
53
54
for
(;;) {
55
if
(getln(&
b
,&
line
,&
match
,
'\n'
) != 0)
die_read
();
56
if
(
line
.s[0] !=
'#'
&&
line
.len >
LOADER_LEN
)
57
if
(cdb_make_add(&
cdb
,
line
.s,
LOADER_LEN
,
""
,0) == -1)
58
die_write
();
59
if
(!
match
)
break
;
60
}
61
62
if
(cdb_make_finish(&
cdb
) == -1)
die_write
();
63
if
(fsync(
fdtemp
) == -1)
die_write
();
64
if
(close(
fdtemp
) == -1)
die_write
();
/* NFS stupidity */
65
if
(
rename
(
"control/badloadertypes.tmp"
,
"control/badloadertypes.cdb"
) == -1)
66
logmsg(
WHO
,111,FATAL,
"unable to move control/badloadertypes.tmp to control/badloadertypes.cdb"
);
67
68
_exit
(0);
69
}
auto_qmail.h
auto_qmail
char auto_qmail[]
die_write
void die_write()
Definition:
columnt.c:17
die_read
void die_read()
Definition:
columnt.c:16
exit.h
_exit
void _exit(int)
cdb
struct cdb_make cdb
Definition:
qmail-badloadertypes.c:34
rename
int rename(const char *, const char *)
b
buffer b
Definition:
qmail-badloadertypes.c:29
fd
int fd
Definition:
qmail-badloadertypes.c:31
line
stralloc line
Definition:
qmail-badloadertypes.c:35
match
int match
Definition:
qmail-badloadertypes.c:36
LOADER_LEN
#define LOADER_LEN
Definition:
qmail-badloadertypes.c:15
WHO
#define WHO
Definition:
qmail-badloadertypes.c:14
fdtemp
int fdtemp
Definition:
qmail-badloadertypes.c:32
main
int main()
Definition:
qmail-badloadertypes.c:38
inbuf
char inbuf[BUFSIZE_LINE]
Definition:
qmail-badloadertypes.c:28
qmail.h
BUFSIZE_LINE
#define BUFSIZE_LINE
Definition:
qmail.h:8
Generated on Thu Jan 16 2025 17:42:04 for s/qmail by
1.9.6