mess822x 1.23
mess822x
Loading...
Searching...
No Matches
rwhconfig.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "rewritehost.h"
3#include "stralloc.h"
4#include "config.h"
5#include "logmsg.h"
6#include "rwhconfig.h"
7#include "auto_qmail.h"
8
9#define WHO "rwhconfig"
10
11// struct strerr rwhconfig_err;
12
13static stralloc tmp = {0};
14static config_str me = CONFIG_STR;
15static config_str defaultdomain = CONFIG_STR;
16static config_str defaulthost = CONFIG_STR;
17static config_str plusdomain = CONFIG_STR;
18static config_str idhost = CONFIG_STR;
19
20static void nomem()
21{
22 logmsg(WHO,111,FATAL,"out of memory");
23}
24
26{
27 if (config_readline(&me,"control/me") == -1)
28 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/me"));
29
30 if (!config(rewrite))
31 if (config_readfile(rewrite,"control/rewrite") == -1)
32 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/rewrite"));
33
34 if (!config(rewrite)) {
35 if (config_env(&defaulthost,"QMAILDEFAULTHOST") == -1) nomem();
36 if (config_readline(&defaulthost,"control/defaulthost") == -1)
37 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/defaulthost"));
38 if (config_copy(&defaulthost,&me) == -1) nomem();
39 if (config_default(&defaulthost,"DEFAULTHOST") == -1) nomem();
40
41 if (config_env(&defaultdomain,"QMAILDEFAULTDOMAIN") == -1) nomem();
42 if (config_readline(&defaultdomain,"control/defaultdomain") == -1)
43 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/defaultdomain"));
44 if (config_copy(&defaultdomain,&me) == -1) nomem();
45 if (config_default(&defaultdomain,"DEFAULTDOMAIN") == -1) nomem();
46
47 if (config_env(&plusdomain,"QMAILPLUSDOMAIN") == -1) nomem();
48 if (config_readline(&plusdomain,"control/plusdomain") == -1)
49 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/plusdomain"));
50 if (config_copy(&plusdomain,&me) == -1) nomem();
51 if (config_default(&plusdomain,"PLUSDOMAIN") == -1) nomem();
52
53 if (!stralloc_copys(config_data(rewrite),"*.:")) nomem();
54 if (!stralloc_0(config_data(rewrite))) nomem();
55 if (!stralloc_cats(config_data(rewrite),"=:")) nomem();
56 if (!stralloc_cat(config_data(rewrite),config_data(&defaulthost))) nomem();
57 if (!stralloc_0(config_data(rewrite))) nomem();
58 if (!stralloc_cats(config_data(rewrite),"*+:.")) nomem();
59 if (!stralloc_cat(config_data(rewrite),config_data(&plusdomain))) nomem();
60 if (!stralloc_0(config_data(rewrite))) nomem();
61 if (!stralloc_cats(config_data(rewrite),"?:.")) nomem();
62 if (!stralloc_cat(config_data(rewrite),config_data(&defaultdomain))) nomem();
63 if (!stralloc_0(config_data(rewrite))) nomem();
64 }
65
66 if (config_env(&idhost,"QMAILIDHOST") == -1) nomem();
67 if (config_readline(&idhost,"control/idhost") == -1)
68 logmsg(WHO,-1,FATAL,B("unable to read ",auto_qmail,"/control/idhost"));
69 if (config_copy(&idhost,&me) == -1) nomem();
70 if (config_default(&idhost,"IDHOST") == -1) nomem();
71
72 if (!rewritehost(&tmp,config_data(&idhost)->s,config_data(&idhost)->len,config_data(rewrite))) nomem();
73
74 if (!stralloc_copys(idappend,".")) nomem();
75 if (!stralloc_catint(idappend,(int) getpid())) nomem();
76 if (!stralloc_cats(idappend,".qmail@")) nomem();
77 if (!stralloc_cat(idappend,&tmp)) nomem();
78
79 return 0;
80}
int config_readline(config_str *c, char *fn)
Definition: config.c:57
int config_copy(config_str *c, config_str *d)
Definition: config.c:19
int config_env(config_str *c, char *s)
Definition: config.c:28
int config_default(config_str *c, char *s)
Definition: config.c:10
int config_readfile(config_str *c, char *fn)
Definition: config.c:84
void nomem()
Definition: quote.c:8
stralloc tmp
Definition: 822print.c:78
#define config(c)
Definition: config.h:13
#define CONFIG_STR
Definition: config.h:11
#define config_data(c)
Definition: config.h:14
int rewritehost(stralloc *, char *, unsigned int, stralloc *)
Definition: rewritehost.c:63
char auto_qmail[]
int rwhconfig(config_str *rewrite, stralloc *idappend)
Definition: rwhconfig.c:25
#define WHO
Definition: rwhconfig.c:9
stralloc idappend
Definition: new-inject.c:44
config_str rewrite
Definition: new-inject.c:43