12 |
#include "log.h" |
#include "log.h" |
13 |
|
|
14 |
|
|
15 |
account_data account; |
extern char logfile[PATH_MAX]; |
16 |
|
account_data **accounts; |
17 |
|
int acccnt = -1; /* Accounts declared. */ |
18 |
filter_entry **dfilters; /* Filters of DENY type. */ |
filter_entry **dfilters; /* Filters of DENY type. */ |
19 |
filter_entry **afilters; /* Filters of ALLOW type. */ |
filter_entry **afilters; /* Filters of ALLOW type. */ |
20 |
int dfcnt = 0; |
int dfilcnt = 0; |
21 |
int afcnt = 0; /* DENY and ALLOW type filters found |
int afilcnt = 0; /* DENY and ALLOW type filters found |
22 |
in the configuration file. */ |
in the configuration file. */ |
23 |
unsigned int dlimit = 0; |
unsigned int dlimit = 0; |
24 |
unsigned int alimit = 0; /* DENY and ALLOW message size limits. */ |
unsigned int alimit = 0; /* DENY and ALLOW message size limits. */ |
59 |
return r; |
return r; |
60 |
} |
} |
61 |
|
|
62 |
|
|
63 |
/* |
/* |
64 |
* Parses configuration file. |
* Parses configuration file. |
65 |
*/ |
*/ |
105 |
} |
} |
106 |
} |
} |
107 |
|
|
108 |
/* Fail if no filters were defined. */ |
/* Fail if no accounts were defined. */ |
109 |
if (!dfcnt && !afcnt) { |
if (acccnt == -1) { |
110 |
|
fprintf(stderr, |
111 |
|
"imapfilter: no accounts defined in config file\n"); |
112 |
|
return FAILURE; |
113 |
|
} |
114 |
|
|
115 |
|
/* Fail if no fitlers were defined. */ |
116 |
|
if (!dfilcnt && !afilcnt) { |
117 |
fprintf(stderr, "imapfilter: no filters defined in config file\n"); |
fprintf(stderr, "imapfilter: no filters defined in config file\n"); |
118 |
return FAILURE; |
return FAILURE; |
119 |
} |
} |
120 |
#ifdef DEBUG |
|
|
printf("debug: account setting SERVER: '%s'\n" |
|
|
"debug: account setting PORT: %d\n" |
|
|
"debug: account setting USERNAME: '%s'\n" |
|
|
"debug: account setting PASSWORD: '%s'\n" |
|
|
"debug: account setting LOGFILE: '%s'\n" |
|
|
"debug: setting DENY_LIMIT: %d\n" |
|
|
"debug: setting ALLOW_LIMIT: %d\n", |
|
|
account.server, account.port, account.username, |
|
|
account.password, account.logfile, dlimit, alimit); |
|
|
#endif |
|
121 |
return SUCCESS; |
return SUCCESS; |
122 |
} |
} |
123 |
|
|
124 |
|
|
125 |
/* |
/* |
126 |
* NULL terminate account settings. |
* Allocate memory for accounts and NULL terminate account settings. |
127 |
*/ |
*/ |
128 |
void prepare_account(void) |
void prepare_account(void) |
129 |
{ |
{ |
130 |
account.server[0] = 0; |
acccnt++; |
131 |
account.port = 143; |
|
132 |
account.username[0] = 0; |
if (!acccnt) |
133 |
account.password[0] = 0; |
accounts = (account_data **) malloc(sizeof(account_data *)); |
134 |
account.logfile[0] = 0; |
else |
135 |
|
accounts = (account_data **) realloc(accounts, (acccnt + 1) * |
136 |
|
sizeof(account_data *)); |
137 |
|
|
138 |
|
accounts[acccnt] = (account_data *) malloc(sizeof(account_data)); |
139 |
|
|
140 |
|
accounts[acccnt]->server[0] = 0; |
141 |
|
accounts[acccnt]->port = 143; |
142 |
|
accounts[acccnt]->username[0] = 0; |
143 |
|
accounts[acccnt]->password[0] = 0; |
144 |
} |
} |
145 |
|
|
146 |
|
|
154 |
char port[6]; |
char port[6]; |
155 |
|
|
156 |
if (!strncmp(line + match[1].rm_so, "SERVER", 6)) { |
if (!strncmp(line + match[1].rm_so, "SERVER", 6)) { |
157 |
|
prepare_account(); |
158 |
s = min((match[2].rm_eo - match[2].rm_so), SERVER_MAX - 1); |
s = min((match[2].rm_eo - match[2].rm_so), SERVER_MAX - 1); |
159 |
strncpy(account.server, line + match[2].rm_so, s); |
strncpy(accounts[acccnt]->server, line + match[2].rm_so, s); |
160 |
account.server[s] = 0; |
accounts[acccnt]->server[s] = 0; |
161 |
} else if (!strncmp(line + match[1].rm_so, "PORT", 4)) { |
#ifdef DEBUG |
162 |
s = min((match[2].rm_eo - match[2].rm_so), sizeof(port)); |
printf("debug: account setting SERVER: '%s'\n", accounts[acccnt]->server); |
163 |
strncpy(port, line + match[2].rm_so, s); |
#endif |
164 |
port[s] = 0; |
} else if (acccnt >= 0) { |
165 |
account.port = strtoul(port, NULL, 0); |
if (!strncmp(line + match[1].rm_so, "PORT", 4)) { |
166 |
} else if (!strncmp(line + match[1].rm_so, "USERNAME", 8)) { |
s = min((match[2].rm_eo - match[2].rm_so), sizeof(port)); |
167 |
s = min((match[2].rm_eo - match[2].rm_so), USERNAME_MAX - 1); |
strncpy(port, line + match[2].rm_so, s); |
168 |
strncpy(account.username, line + match[2].rm_so, s); |
port[s] = 0; |
169 |
account.username[s] = 0; |
accounts[acccnt]->port = strtoul(port, NULL, 0); |
170 |
} else if (!strncmp(line + match[1].rm_so, "PASSWORD", 8)) { |
#ifdef DEBUG |
171 |
s = min((match[2].rm_eo - match[2].rm_so), PASSWORD_MAX - 1); |
printf("debug: account setting PORT: '%d'\n", accounts[acccnt]->port); |
172 |
strncpy(account.password, line + match[2].rm_so, s); |
#endif |
173 |
account.password[s] = 0; |
} else if (!strncmp(line + match[1].rm_so, "USERNAME", 8)) { |
174 |
} else if (!strncmp(line + match[1].rm_so, "LOGFILE", 7)) { |
s = min((match[2].rm_eo - match[2].rm_so), USERNAME_MAX - 1); |
175 |
s = min((match[2].rm_eo - match[2].rm_so), PATH_MAX - 1); |
strncpy(accounts[acccnt]->username, line + match[2].rm_so, s); |
176 |
strncpy(account.logfile, line + match[2].rm_so, s); |
accounts[acccnt]->username[s] = 0; |
177 |
account.logfile[s] = 0; |
#ifdef DEBUG |
178 |
|
printf("debug: account setting USERNAME: '%s'\n", accounts[acccnt]->username); |
179 |
|
#endif |
180 |
|
} else if (!strncmp(line + match[1].rm_so, "PASSWORD", 8)) { |
181 |
|
s = min((match[2].rm_eo - match[2].rm_so), PASSWORD_MAX - 1); |
182 |
|
strncpy(accounts[acccnt]->password, line + match[2].rm_so, s); |
183 |
|
accounts[acccnt]->password[s] = 0; |
184 |
|
#ifdef DEBUG |
185 |
|
printf("debug: account setting PASSWORD: '%s'\n", accounts[acccnt]->password); |
186 |
|
#endif |
187 |
|
} else if (!strncmp(line + match[1].rm_so, "LOGFILE", 7)) { |
188 |
|
s = min((match[2].rm_eo - match[2].rm_so), PATH_MAX - 1); |
189 |
|
strncpy(logfile, line + match[2].rm_so, s); |
190 |
|
logfile[s] = 0; |
191 |
|
} |
192 |
} |
} |
193 |
} |
} |
194 |
|
|
206 |
#ifdef DEBUG |
#ifdef DEBUG |
207 |
printf("debug: filter entry: DENY"); |
printf("debug: filter entry: DENY"); |
208 |
#endif |
#endif |
209 |
fcnt = &dfcnt; |
fcnt = &dfilcnt; |
210 |
filters = &dfilters; |
filters = &dfilters; |
211 |
} else { |
} else { |
212 |
#ifdef DEBUG |
#ifdef DEBUG |
213 |
printf("debug: filter entry: ALLOW"); |
printf("debug: filter entry: ALLOW"); |
214 |
#endif |
#endif |
215 |
fcnt = &afcnt; |
fcnt = &afilcnt; |
216 |
filters = &afilters; |
filters = &afilters; |
217 |
} |
} |
218 |
|
|