Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/blacklist *** empty log message ***



details:   https://anonhg.NetBSD.org/src/rev/f1270817a3a1
branches:  trunk
changeset: 335662:f1270817a3a1
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jan 19 18:52:55 2015 +0000

description:
*** empty log message ***

diffstat:

 external/bsd/blacklist/bin/blacklist.h  |    3 +-
 external/bsd/blacklist/bin/blacklistd.c |   11 +-
 external/bsd/blacklist/bin/conf.h       |   36 ++++
 external/bsd/blacklist/bin/internal.h   |   18 +-
 external/bsd/blacklist/include/bl.h     |   75 ++++++++-
 external/bsd/blacklist/lib/bl.c         |  231 +++++++++++++++++++++----------
 external/bsd/blacklist/test/cltest.c    |   66 +++++++--
 external/bsd/blacklist/test/srvtest.c   |  104 +++++++++----
 8 files changed, 387 insertions(+), 157 deletions(-)

diffs (truncated from 817 to 300 lines):

diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/bin/blacklist.h
--- a/external/bsd/blacklist/bin/blacklist.h    Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklist.h    Mon Jan 19 18:52:55 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: blacklist.h,v 1.1 2015/01/19 18:52:55 christos Exp $   */
+/*     $NetBSD: blacklist.h,v 1.2 2015/01/19 19:02:35 christos Exp $   */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -43,6 +43,7 @@
 __BEGIN_DECLS
 
 bl_t bl_create(void);
+int bl_getfd(bl_t);
 int bl_send(bl_t, bl_type_t, int, int, const char *);
 void bl_destroy(bl_t);
 
diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/bin/blacklistd.c
--- a/external/bsd/blacklist/bin/blacklistd.c   Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistd.c   Mon Jan 19 18:52:55 2015 +0000
@@ -1,6 +1,6 @@
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistd.c,v 1.2 2015/01/19 18:52:55 christos Exp $");
+__RCSID("$NetBSD: blacklistd.c,v 1.3 2015/01/19 19:02:35 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -47,7 +47,8 @@
 static __dead void
 usage(void)
 {
-       fprintf(stderr, "Usage: %s -d [-c <config>]\n", getprogname());
+       fprintf(stderr, "Usage: %s -d [-c <config>] [-s <sockpath>]\n",
+           getprogname());
        exit(EXIT_FAILURE);
 }
 
@@ -111,7 +112,7 @@
        rfd = bi->bi_fd[1];
        rsl = sizeof(rss);
        if (getpeername(rfd, (void *)&rss, &rsl) == -1) {
-               (*bl->b_fun)(LOG_ERR, "getsockname failed (%m)"); 
+               (*lfun)(LOG_ERR, "getsockname failed (%m)"); 
                goto out;
        }
        sockaddr_snprintf(rbuf, sizeof(rbuf), "%a:%p", (void *)&rss);
@@ -163,11 +164,11 @@
        }
 
        bl = bl_create2(true, spath, lfun);
-       if (bl == NULL || !bl->b_connected)
+       if (bl == NULL || !bl_isconnected(bl))
                return EXIT_FAILURE;
 
        struct pollfd pfd;
-       pfd.fd = bl->b_fd;
+       pfd.fd = bl_getfd(bl);
        pfd.events = POLLIN;
        for (;;) {
                if (rconf) {
diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/bin/conf.h
--- a/external/bsd/blacklist/bin/conf.h Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/bin/conf.h Mon Jan 19 18:52:55 2015 +0000
@@ -1,3 +1,35 @@
+/*     $NetBSD: conf.h,v 1.2 2015/01/19 19:02:35 christos Exp $        */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _CONF_H
+#define _CONF_H
 
 struct conf {
        int                     c_port;
@@ -8,5 +40,9 @@
        int                     c_duration;
 };
 
+__BEGIN_DECLS
 void parseconf(const char *);
 const struct conf *findconf(bl_info_t *);
+__END_DECLS
+
+#endif /* _CONF_H */
diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/bin/internal.h
--- a/external/bsd/blacklist/bin/internal.h     Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/bin/internal.h     Mon Jan 19 18:52:55 2015 +0000
@@ -1,16 +1,6 @@
-
 
-typedef struct {
-       uint32_t bl_len;
-       uint32_t bl_version;
-       uint32_t bl_type;
-       char bl_data[];
-} bl_message_t;
+struct conf *conf;
+size_t nconf;
+int debug;
 
-struct blacklist {
-       int b_fd;
-       int b_connected;
-};
-
-
-#define BL_VERSION     1
+void (*lfun)(int, const char *, ...);
diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/include/bl.h
--- a/external/bsd/blacklist/include/bl.h       Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/include/bl.h       Mon Jan 19 18:52:55 2015 +0000
@@ -1,17 +1,70 @@
-
-#include <stdbool.h>
+/*     $NetBSD: bl.h,v 1.4 2015/01/19 18:52:55 christos Exp $  */
 
-typedef enum {
-       BL_INVALID,
-       BL_ADD,
-} bl_type_t;
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _BL_H
+#define _BL_H
+
+#include "blacklist.h"
+
+struct sockcred;
+
+typedef struct {
+       bl_type_t bi_type;
+       int *bi_fd;
+       struct sockcred *bi_cred;
+       char bi_msg[1024];
+} bl_info_t;
 
 typedef struct blacklist *bl_t;
 
-bl_t bl_create(bool);
-void bl_destroy(bl_t);
-int bl_send(bl_t, bl_type_t, int, int, const char *);
-int bl_recv(bl_t, bl_type_t *, int *, int *, char *, size_t);
+__BEGIN_DECLS
+bl_t bl_create2(bool, const char *, void (*)(int, const char *, ...));
+bl_info_t *bl_recv(bl_t);
+__END_DECLS
 
 #define _PATH_BLSOCK "/tmp/blsock"
-#define _PATH_BLCONF "/etc/blacklist.conf"
+#define _PATH_BLCONF "/etc/blacklistd/conf"
+
+#endif /* _BL_H */
+typedef struct {
+       uint32_t bl_len;
+       uint32_t bl_version;
+       uint32_t bl_type;
+       char bl_data[];
+} bl_message_t;
+
+struct blacklist {
+       int b_fd;
+       int b_connected;
+       const char *b_path;
+       void (*b_fun)(int, const char *, ...);
+       bl_info_t b_info;
+};
+#define BL_VERSION     1
diff -r 5b6978e8a3d4 -r f1270817a3a1 external/bsd/blacklist/lib/bl.c
--- a/external/bsd/blacklist/lib/bl.c   Mon Jan 19 18:52:54 2015 +0000
+++ b/external/bsd/blacklist/lib/bl.c   Mon Jan 19 18:52:55 2015 +0000
@@ -1,8 +1,42 @@
+/*     $NetBSD: bl.c,v 1.4 2015/01/19 18:52:55 christos Exp $  */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: bl.c,v 1.4 2015/01/19 18:52:55 christos Exp $");
+
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include <stdio.h>
 #include <string.h>
 #include <syslog.h>
 #include <fcntl.h>
@@ -11,23 +45,34 @@
 #include <stdbool.h>
 
 #include "bl.h"
-#include "internal.h"
+
+static void
+bl_reset(bl_t b)
+{
+       close(b->b_fd);
+       b->b_fd = -1;
+       b->b_connected = false;
+}
 
 static int
 bl_init(bl_t b, bool srv)
 {
+       static int one = 1;
        /* AF_UNIX address of local logger */
-       static const struct sockaddr_un sun = {
+       struct sockaddr_un sun = {
                .sun_family = AF_LOCAL,
                .sun_len = sizeof(sun),
-               .sun_path = _PATH_BLSOCK,
        };
+       strlcpy(sun.sun_path, b->b_path, sizeof(sun.sun_path));
+       if (srv)
+               (void)unlink(b->b_path);
 
        if (b->b_fd == -1) {
                b->b_fd = socket(PF_LOCAL,
                    SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK|SOCK_NOSIGPIPE, 0);
                if (b->b_fd == -1) {
-                       syslog(LOG_ERR, "%s: socket failed (%m)", __func__);
+                       (*b->b_fun)(LOG_ERR, "%s: socket failed (%m)",



Home | Main Index | Thread Index | Old Index