s/qmail 4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
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
17int rename(const char *,const char *); // stdio.h
18
19static void die_read()
20{
21 logmsg(WHO,111,FATAL,"unable to read control/badloadertypes");
22}
23static void die_write()
24{
25 logmsg(WHO,111,FATAL,"unable to write to control/badloadertypes.tmp");
26}
27
29buffer b;
30
31int fd;
33
34struct cdb_make cdb;
35stralloc line = {0};
37
38int 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}
char auto_qmail[]
void die_write()
Definition: columnt.c:17
void die_read()
Definition: columnt.c:16
void _exit(int)
struct cdb_make cdb
int rename(const char *, const char *)
buffer b
int fd
stralloc line
int match
#define LOADER_LEN
#define WHO
int fdtemp
int main()
char inbuf[BUFSIZE_LINE]
#define BUFSIZE_LINE
Definition: qmail.h:8