s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
qmail-recipients.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 "case.h"
10#include "auto_qmail.h"
11#include "cdbmake.h"
12
13#define WHO "qmail-recipients"
14
15int rename(const char *,const char *); // stdio.h
16
18{
19 logmsg(WHO,111,ERROR,"unable to read users/recipients");
20}
22{
23 logmsg(WHO,111,ERROR,"unable to write to users/recipients.tmp");
24}
25
26char inbuf[1024];
27buffer b;
28
29int fd;
31
32struct cdb_make cdb;
33stralloc line = {0};
34stralloc key = {0};
36
37int main()
38{
39 umask(033);
40 if (chdir(auto_qmail) == -1)
41 logmsg(WHO,110,ERROR,B("unable to chdir to: ",auto_qmail));
42
43 fd = open_read("users/recipients");
44 if (fd == -1) die_read();
45
46 buffer_init(&b,read,fd,inbuf,sizeof(inbuf));
47
48 fdtemp = open_trunc("users/recipients.tmp");
49 if (fdtemp == -1) die_write();
50
51 if (cdb_make_start(&cdb,fdtemp) == -1) die_write();
52
53 for (;;) {
54 stralloc_copys(&key,":");
55 if (getln(&b,&line,&match,'\n') != 0) die_read();
56 while (line.len) {
57 if (line.s[line.len - 1] == ' ') { --line.len; continue; }
58 if (line.s[line.len - 1] == '\n') { --line.len; continue; }
59 if (line.s[line.len - 1] == '\t') { --line.len; continue; }
60 if (line.s[0] != '#' && stralloc_cat(&key,&line)) {
61 case_lowerb(key.s,key.len);
62 if (cdb_make_add(&cdb,key.s,key.len,"",0) == -1)
63 die_write();
64 }
65 break;
66 }
67 if (!match) break;
68 }
69
70 if (cdb_make_finish(&cdb) == -1) die_write();
71 if (fsync(fdtemp) == -1) die_write();
72 if (close(fdtemp) == -1) die_write(); /* NFS stupidity */
73 if (rename("users/recipients.tmp","users/recipients.cdb") == -1)
74 logmsg(WHO,111,ERROR,"unable to move users/recipients.tmp to users/recipients.cdb");
75
76 _exit(0);
77}
char auto_qmail[]
int stralloc_copys(stralloc *, char const *)
void _exit()
stralloc key
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 WHO
int fdtemp
int main()