s/qmail 4.2.29a
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
13#define WHO "qmail-badloadertypes"
14#define LOADER_LEN 5
15
16int rename(const char *,const char *); // stdio.h
17
19{
20 logmsg(WHO,111,FATAL,"unable to read control/badloadertypes");
21}
23{
24 logmsg(WHO,111,FATAL,"unable to write to control/badloadertypes.tmp");
25}
26
27char inbuf[1024];
28buffer b;
29
30int fd;
32
33struct cdb_make cdb;
34stralloc line = {0};
36
37int 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}
char auto_qmail[]
void _exit()
struct cdb_make cdb
char inbuf[1024]
int rename(const char *, const char *)
buffer b
int fd
void die_write()
void die_read()
stralloc line
int match
#define LOADER_LEN
#define WHO
int fdtemp
int main()