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