s/qmail
4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
sqmail-4.2.29a
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
13
#define WHO "qmail-badloadertypes"
14
#define LOADER_LEN 5
15
16
int
rename
(
const
char
*,
const
char
*);
// stdio.h
17
18
void
die_read
()
19
{
20
logmsg(
WHO
,111,FATAL,
"unable to read control/badloadertypes"
);
21
}
22
void
die_write
()
23
{
24
logmsg(
WHO
,111,FATAL,
"unable to write to control/badloadertypes.tmp"
);
25
}
26
27
char
inbuf
[1024];
28
buffer
b
;
29
30
int
fd
;
31
int
fdtemp
;
32
33
struct
cdb_make
cdb
;
34
stralloc
line
= {0};
35
int
match
;
36
37
int
main
()
38
{
39
umask(033);
40
if
(chdir(
auto_qmail
) == -1)
41
logmsg(
WHO
,111,FATAL,B(
"unable to chdir to: "
,
auto_qmail
));
42
43
fd
= open_read(
"control/badloadertypes"
);
44
if
(
fd
== -1)
die_read
();
45
46
buffer_init(&
b
,read,
fd
,
inbuf
,
sizeof
(
inbuf
));
47
48
fdtemp
= open_trunc(
"control/badloadertypes.tmp"
);
49
if
(
fdtemp
== -1)
die_write
();
50
51
if
(cdb_make_start(&
cdb
,
fdtemp
) == -1)
die_write
();
52
53
for
(;;) {
54
if
(getln(&
b
,&
line
,&
match
,
'\n'
) != 0)
die_read
();
55
if
(
line
.s[0] !=
'#'
&&
line
.len >
LOADER_LEN
)
56
if
(cdb_make_add(&
cdb
,
line
.s,
LOADER_LEN
,
""
,0) == -1)
57
die_write
();
58
if
(!
match
)
break
;
59
}
60
61
if
(cdb_make_finish(&
cdb
) == -1)
die_write
();
62
if
(fsync(
fdtemp
) == -1)
die_write
();
63
if
(close(
fdtemp
) == -1)
die_write
();
/* NFS stupidity */
64
if
(
rename
(
"control/badloadertypes.tmp"
,
"control/badloadertypes.cdb"
) == -1)
65
logmsg(
WHO
,111,FATAL,
"unable to move control/badloadertypes.tmp to control/badloadertypes.cdb"
);
66
67
_exit
(0);
68
}
auto_qmail.h
auto_qmail
char auto_qmail[]
exit.h
_exit
void _exit()
cdb
struct cdb_make cdb
Definition:
qmail-badloadertypes.c:33
inbuf
char inbuf[1024]
Definition:
qmail-badloadertypes.c:27
rename
int rename(const char *, const char *)
b
buffer b
Definition:
qmail-badloadertypes.c:28
fd
int fd
Definition:
qmail-badloadertypes.c:30
die_write
void die_write()
Definition:
qmail-badloadertypes.c:22
die_read
void die_read()
Definition:
qmail-badloadertypes.c:18
line
stralloc line
Definition:
qmail-badloadertypes.c:34
match
int match
Definition:
qmail-badloadertypes.c:35
LOADER_LEN
#define LOADER_LEN
Definition:
qmail-badloadertypes.c:14
WHO
#define WHO
Definition:
qmail-badloadertypes.c:13
fdtemp
int fdtemp
Definition:
qmail-badloadertypes.c:31
main
int main()
Definition:
qmail-badloadertypes.c:37
Generated on Thu Feb 29 2024 20:44:52 for s/qmail by
1.9.6