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