]> jfr.im git - solanum.git/blobdiff - authd/providers/blacklist.c
authd: misc fixes
[solanum.git] / authd / providers / blacklist.c
index c05cb630573b697845753264e173a5cf3f15403b..922d4b2ca7764b1e1f9c72089785b6082d11e04a 100644 (file)
@@ -58,11 +58,12 @@ struct blacklist
 {
        char host[IRCD_RES_HOSTLEN + 1];
        char reason[BUFSIZE];           /* Reason template (ircd fills in the blanks) */
-       unsigned char iptype;           /* IP types supported */
+       uint8_t iptype;                 /* IP types supported */
        rb_dlink_list filters;          /* Filters for queries */
 
        bool delete;                    /* If true delete when no clients */
        int refcount;                   /* When 0 and delete is set, remove this blacklist */
+       unsigned int hits;
 
        time_t lastwarning;             /* Last warning about garbage replies sent */
 };
@@ -81,7 +82,7 @@ struct blacklist_lookup
 struct blacklist_filter
 {
        filter_t type;                  /* Type of filter */
-       char filter[HOSTIPLEN]; /* The filter itself */
+       char filter[HOSTIPLEN];         /* The filter itself */
 
        rb_dlink_node node;
 };
@@ -102,7 +103,7 @@ static void blacklists_cancel(struct auth_client *);
 
 /* private interfaces */
 static void unref_blacklist(struct blacklist *);
-static struct blacklist *new_blacklist(const char *, const char *, unsigned char, rb_dlink_list *);
+static struct blacklist *new_blacklist(const char *, const char *, uint8_t, rb_dlink_list *);
 static struct blacklist *find_blacklist(const char *);
 static bool blacklist_check_reply(struct blacklist_lookup *, const char *);
 static void blacklist_dns_callback(const char *, bool, query_type, void *);
@@ -136,7 +137,7 @@ unref_blacklist(struct blacklist *bl)
 }
 
 static struct blacklist *
-new_blacklist(const char *name, const char *reason, unsigned char iptype, rb_dlink_list *filters)
+new_blacklist(const char *name, const char *reason, uint8_t iptype, rb_dlink_list *filters)
 {
        struct blacklist *bl;
 
@@ -245,8 +246,9 @@ blacklist_dns_callback(const char *result, bool status, query_type type, void *d
        if (result != NULL && status && blacklist_check_reply(bllookup, result))
        {
                /* Match found, so proceed no further */
+               bl->hits++;
                blacklists_cancel(auth);
-               reject_client(auth, PROVIDER_BLACKLIST, bl->reason);
+               reject_client(auth, PROVIDER_BLACKLIST, bl->host, bl->reason);
                return;
        }
 
@@ -442,7 +444,7 @@ add_conf_blacklist(const char *key, int parc, const char **parv)
 {
        rb_dlink_list filters = { NULL, NULL, 0 };
        char *tmp, *elemlist = rb_strdup(parv[2]);
-       unsigned char iptype;
+       uint8_t iptype;
 
        if(*elemlist == '*')
                goto end;
@@ -544,6 +546,24 @@ add_conf_blacklist_timeout(const char *key, int parc, const char **parv)
        blacklist_timeout = timeout;
 }
 
+static void
+blacklist_stats(uint32_t rid, char letter)
+{
+       rb_dlink_node *ptr;
+
+       RB_DLINK_FOREACH(ptr, blacklist_list.head)
+       {
+               struct blacklist *bl = ptr->data;
+
+               if(bl->delete)
+                       continue;
+
+               stats_result(rid, letter, "%s %hhu %u", bl->host, bl->iptype, bl->hits);
+       }
+
+       stats_done(rid, letter);
+}
+
 struct auth_opts_handler blacklist_options[] =
 {
        { "rbl", 4, add_conf_blacklist },
@@ -562,4 +582,5 @@ struct auth_provider blacklist_provider =
        .cancel = blacklists_cancel,
        .completed = blacklists_initiate,
        .opt_handlers = blacklist_options,
+       .stats_handler = { 'B', blacklist_stats },
 };