diff src/context.h @ 278:368572c57013

add limits on unique ip addresses per hour per authenticated user
author Carl Byington <carl@five-ten-sg.com>
date Tue, 17 Dec 2013 15:35:23 -0800
parents a99b6c1f5f67
children 802e2b779ed1
line wrap: on
line diff
--- a/src/context.h	Wed Dec 11 22:57:06 2013 -0800
+++ b/src/context.h	Tue Dec 17 15:35:23 2013 -0800
@@ -26,6 +26,7 @@
 typedef map<const char *, const char *, ltstr>  string_map;
 typedef set<int>                                int_set;
 typedef set<int32_t>                            int32_t_set;
+typedef int32_t_set *                           int32_t_set_p;
 typedef list<SMTP *>                            smtp_list;
 typedef DNSBL *                                 DNSBLP;
 typedef DNSWL *                                 DNSWLP;
@@ -40,7 +41,8 @@
 typedef list<CONTEXTP>                          context_list;
 typedef map<const char *, CONTEXTP, ltstr>      context_map;
 typedef map<const char *, int32_t, ltstr>       ns_mapper;  // name to ipv4 address
-typedef map<const char *, int, ltstr>           rcpt_rates;
+typedef map<const char *, int, ltstr>           rates;
+typedef map<const char *, int32_t_set_p, ltstr> auth_addresses;
 typedef map<const char *, time_t,  ltstr>       autowhite_sent;
 typedef map<const char *, VERIFYP, ltstr>       verify_map;
 typedef map<const char *, WHITELISTERP, ltstr>  whitelister_map;
@@ -181,9 +183,12 @@
     dnswlp_map      dnswl_names;        // name to dnswl mapping for lists that are available in this context and children
     dnswlp_list     dnswl_list;         // list of dnswls to be used in this context
     bool            dnswl_list_parsed;  // true iff we have actually parsed a dnswl_list
-    int             default_rcpt_rate;  // if not specified per user
-    int             rcpt_daily_multiple;// daily multiplier applied to hourly rate
-    rcpt_rates      rcpt_per_hour;      // per user limits on number of recipients per hour
+    int             default_rate_limit;     // if not specified per user
+    int             default_address_limit;  // if not specified per user
+    int             daily_rate_multiple;    // daily multiplier applied to hourly rate
+    int             daily_address_multiple; // daily multiplier applied to hourly rate
+    rates           rcpt_per_hour;          // per user limits on number of recipients per hour
+    rates           addresses_per_hour;     // per user limits on number of unique ip address connections per hour
 
 
 public:
@@ -207,12 +212,17 @@
     const char* get_autowhite()                             {return autowhite_file;};
     WHITELISTERP find_autowhite(const char *from, const char *to);
 
-    void        set_default_rate(int limit)                 {default_rcpt_rate   = limit;};
-    void        set_daily_multiple(int multiple)            {rcpt_daily_multiple = multiple;};
-    void        add_rate(const char *user, int limit)       {rcpt_per_hour[user] = limit;};
-    int         find_rate(const char *user);
+    void        set_default_rate_limit(int limit)               {default_rate_limit = limit;};
+    void        set_default_address_limit(int limit)            {default_address_limit = limit;};
+    void        set_daily_rate_multiple(int multiple)           {daily_rate_multiple = multiple;};
+    void        set_daily_address_multiple(int multiple)        {daily_address_multiple = multiple;};
+    void        add_rate_limit(const char *user, int limit)     {rcpt_per_hour[user] = limit;};
+    void        add_address_limit(const char *user, int limit)  {addresses_per_hour[user] = limit;};
+    int         find_rate_limit(const char *user);              // recipients per hour/day
+    int         find_address_limit(const char *user);           // unique ip address connections per hour/day
     bool        is_unauthenticated_limited(const char *user);
-    int         get_daily_multiple()                        {return rcpt_daily_multiple;};
+    int         get_daily_rate_multiple()                       {return daily_rate_multiple;};
+    int         get_daily_address_multiple()                    {return daily_address_multiple;};
 
     void        add_to(const char *to)                            {env_to.insert(to);};
     void        add_from(const char *from, const char *status)    {env_from[from] = status;};