Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/blacklist/bin handle '*' entries in rules.



details:   https://anonhg.NetBSD.org/src/rev/2f7eec393ff4
branches:  trunk
changeset: 319298:2f7eec393ff4
user:      christos <christos%NetBSD.org@localhost>
date:      Thu May 24 19:19:37 2018 +0000

description:
handle '*' entries in rules.

diffstat:

 external/bsd/blacklist/bin/blacklistctl.c |  34 ++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 9 deletions(-)

diffs (71 lines):

diff -r c243138a9d37 -r 2f7eec393ff4 external/bsd/blacklist/bin/blacklistctl.c
--- a/external/bsd/blacklist/bin/blacklistctl.c Thu May 24 19:03:47 2018 +0000
+++ b/external/bsd/blacklist/bin/blacklistctl.c Thu May 24 19:19:37 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: blacklistctl.c,v 1.21 2016/11/02 03:15:07 jnemeth Exp $        */
+/*     $NetBSD: blacklistctl.c,v 1.22 2018/05/24 19:19:37 christos Exp $       */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.21 2016/11/02 03:15:07 jnemeth Exp $");
+__RCSID("$NetBSD: blacklistctl.c,v 1.22 2018/05/24 19:19:37 christos Exp $");
 
 #include <stdio.h>
 #include <time.h>
@@ -67,6 +67,15 @@
        exit(EXIT_FAILURE);
 }
 
+static const char *
+star(char *buf, size_t len, int val)
+{
+       if (val == -1)
+               return "*";
+       snprintf(buf, len, "%d", val);
+       return buf;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -128,9 +137,10 @@
                    "address", remain ? "remaining time" : "last access");
        for (i = 1; state_iterate(db, &c, &dbi, i) != 0; i = 0) {
                char buf[BUFSIZ];
+               char mbuf[64], pbuf[64];
                if (!all) {
                        if (blocked) {
-                               if (dbi.count < c.c_nfail)
+                               if (c.c_nfail == -1 || dbi.count < c.c_nfail)
                                        continue;
                        } else {
                                if (dbi.count >= c.c_nfail)
@@ -138,12 +148,18 @@
                        }
                }
                sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&c.c_ss);
-               printf("%*.*s/%d:%d\t", wide, wide, buf, c.c_lmask, c.c_port);
-               if (remain)
-                       fmtydhms(buf, sizeof(buf),
-                           c.c_duration - (ts.tv_sec - dbi.last));
-               else
-                       fmttime(buf, sizeof(buf), dbi.last);
+               printf("%*.*s/%s:%s\t", wide, wide, buf,
+                   star(mbuf, sizeof(mbuf), c.c_lmask),
+                   star(pbuf, sizeof(pbuf), c.c_port));
+               if (c.c_duration == -1) {
+                       strlcpy(buf, "never", sizeof(buf));
+               } else {
+                       if (remain)
+                               fmtydhms(buf, sizeof(buf),
+                                   c.c_duration - (ts.tv_sec - dbi.last));
+                       else
+                               fmttime(buf, sizeof(buf), dbi.last);
+               }
                printf("%s\t%d/%d\t%-s\n", dbi.id, dbi.count, c.c_nfail, buf);
        }
        state_close(db);



Home | Main Index | Thread Index | Old Index