s/qmail 4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
qmail-badmimetypes.c
Go to the documentation of this file.
1#include <unistd.h>
2#include <sys/stat.h>
3#include "logmsg.h"
4#include "stralloc.h"
5#include "buffer.h"
6#include "getln.h"
7#include "exit.h"
8#include "open.h"
9#include "auto_qmail.h"
10#include "cdbmake.h"
11#include "qmail.h"
12
13#define WHO "qmail-badmimetypes"
14#define MIMETYPE_LEN 9
15
16int rename(const char *,const char *); // stdio.h
17
18static void die_read()
19{
20 logmsg(WHO,111,FATAL,"unable to read control/badmimetypes");
21}
22static void die_write()
23{
24 logmsg(WHO,111,FATAL,"unable to write to control/badmimetypes.tmp");
25}
26
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/badmimetypes");
44 if (fd == -1) die_read();
45
46 buffer_init(&b,read,fd,inbuf,sizeof(inbuf));
47
48 fdtemp = open_trunc("control/badmimetypes.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 > MIMETYPE_LEN)
56 if (cdb_make_add(&cdb,line.s,MIMETYPE_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/badmimetypes.tmp","control/badmimetypes.cdb") == -1)
65 logmsg(WHO,111,FATAL,"unable to move control/badmimetypes.tmp to control/badmimetypes.cdb");
66
67 _exit(0);
68}
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
#define MIMETYPE_LEN
stralloc line
int match
#define WHO
int fdtemp
int main()
char inbuf[BUFSIZE_LINE]
#define BUFSIZE_LINE
Definition: qmail.h:8