comparison src/context.cpp @ 136:f4746d8a12a3

add smtp auth rate limits
author carl
date Tue, 26 Sep 2006 13:59:14 -0700
parents c5cd1261394d
children 4028de9b46dd
comparison
equal deleted inserted replaced
135:8e813497582e 136:f4746d8a12a3
43 char *token_many; 43 char *token_many;
44 char *token_off; 44 char *token_off;
45 char *token_ok2; 45 char *token_ok2;
46 char *token_ok; 46 char *token_ok;
47 char *token_on; 47 char *token_on;
48 char *token_rate;
48 char *token_rbrace; 49 char *token_rbrace;
49 char *token_semi; 50 char *token_semi;
50 char *token_soft; 51 char *token_soft;
51 char *token_substitute; 52 char *token_substitute;
52 char *token_tld; 53 char *token_tld;
551 else if (parent) return parent->find_verify(to); 552 else if (parent) return parent->find_verify(to);
552 else return NULL; 553 else return NULL;
553 } 554 }
554 555
555 556
557 int CONTEXT::find_rate(char *user) {
558 if (rcpt_per_hour.empty()) return INT_MAX;
559 rcpt_rates::iterator i = rcpt_per_hour.find(user);
560 if (i == rcpt_per_hour.end()) i = rcpt_per_hour.find(" ");
561 return (i == rcpt_per_hour.end()) ? INT_MAX : (*i).second;
562 }
563
564
556 char *CONTEXT::find_from(char *from) { 565 char *CONTEXT::find_from(char *from) {
557 char *rc = token_inherit; 566 char *rc = token_inherit;
558 string_map::iterator i = env_from.find(from); 567 string_map::iterator i = env_from.find(from);
559 if (i != env_from.end()) rc = (*i).second; // found user@domain key 568 if (i != env_from.end()) rc = (*i).second; // found user@domain key
560 else { 569 else {
793 printf("%s %s \t%s; \n", indent, f, t->name); 802 printf("%s %s \t%s; \n", indent, f, t->name);
794 } 803 }
795 } 804 }
796 printf("%s }; \n", indent); 805 printf("%s }; \n", indent);
797 806
807 if (!rcpt_per_hour.empty()) {
808 printf("%s rate_limit { \n", indent);
809 for (rcpt_rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) {
810 char *u = (*j).first;
811 int l = (*j).second;
812 printf("%s \"%s\" \t%d; \n", indent, u, l);
813 }
814 printf("%s }; \n", indent);
815 }
816
798 printf("%s }; \n", indent); 817 printf("%s }; \n", indent);
799 } 818 }
800 819
801 820
802 //////////////////////////////////////////////// 821 ////////////////////////////////////////////////
1169 } 1188 }
1170 1189
1171 1190
1172 //////////////////////////////////////////////// 1191 ////////////////////////////////////////////////
1173 // 1192 //
1193 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1194 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1195 if (!tsa(tok, token_lbrace)) return false;
1196 while (true) {
1197 char *have = tok.next();
1198 if (!have) break;
1199 if (have == token_rbrace) break;
1200 if (have == token_semi) {
1201 // optional separators
1202 }
1203 else {
1204 char *limit = tok.next();
1205 int lim = (limit) ? atoi(limit) : 0;
1206 me.add_rate(have, lim);
1207 }
1208 }
1209 return tsa(tok, token_semi);
1210 }
1211
1212
1213 ////////////////////////////////////////////////
1214 //
1174 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent); 1215 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
1175 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) { 1216 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
1176 char *name = tok.next(); 1217 char *name = tok.next();
1177 if (!tsa(tok, token_lbrace)) return false; 1218 if (!tsa(tok, token_lbrace)) return false;
1178 CONTEXTP con = new CONTEXT(parent, name); 1219 CONTEXTP con = new CONTEXT(parent, name);
1196 else if (have == token_verify) { 1237 else if (have == token_verify) {
1197 if (!parse_verify(tok, dc, *con)) return false; 1238 if (!parse_verify(tok, dc, *con)) return false;
1198 } 1239 }
1199 else if (have == token_envfrom) { 1240 else if (have == token_envfrom) {
1200 if (!parse_envfrom(tok, dc, *con)) return false; 1241 if (!parse_envfrom(tok, dc, *con)) return false;
1242 }
1243 else if ((have == token_rate) && (!parent) && (!dc.default_context)) {
1244 if (!parse_rate(tok, dc, *con)) return false;
1201 } 1245 }
1202 else if (have == token_context) { 1246 else if (have == token_context) {
1203 if (!parse_context(tok, dc, con)) return false; 1247 if (!parse_context(tok, dc, con)) return false;
1204 } 1248 }
1205 else { 1249 else {
1298 token_many = register_string("many"); 1342 token_many = register_string("many");
1299 token_off = register_string("off"); 1343 token_off = register_string("off");
1300 token_ok = register_string("ok"); 1344 token_ok = register_string("ok");
1301 token_ok2 = register_string("ok2"); 1345 token_ok2 = register_string("ok2");
1302 token_on = register_string("on"); 1346 token_on = register_string("on");
1347 token_rate = register_string("rate_limit");
1303 token_rbrace = register_string("}"); 1348 token_rbrace = register_string("}");
1304 token_semi = register_string(";"); 1349 token_semi = register_string(";");
1305 token_soft = register_string("soft"); 1350 token_soft = register_string("soft");
1306 token_substitute = register_string("substitute"); 1351 token_substitute = register_string("substitute");
1307 token_tld = register_string("tld"); 1352 token_tld = register_string("tld");