Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/blacklist/bin/blacklistd.c
/* $NetBSD: blacklistd.c,v 1.37 2017/02/18 00:26:16 christos Exp $ */ | /* $NetBSD: blacklistd.c,v 1.38 2019/02/27 02:20:18 christos Exp $ */ | ||||
/*- | /*- | ||||
* Copyright (c) 2015 The NetBSD Foundation, Inc. | * Copyright (c) 2015 The NetBSD Foundation, Inc. | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* This code is derived from software contributed to The NetBSD Foundation | * This code is derived from software contributed to The NetBSD Foundation | ||||
* by Christos Zoulas. | * by Christos Zoulas. | ||||
* | * | ||||
Show All 17 Lines | |||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | * 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 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
* POSSIBILITY OF SUCH DAMAGE. | * POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | ||||
#include "config.h" | #include "config.h" | ||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__RCSID("$NetBSD: blacklistd.c,v 1.37 2017/02/18 00:26:16 christos Exp $"); | __RCSID("$NetBSD: blacklistd.c,v 1.38 2019/02/27 02:20:18 christos Exp $"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#ifdef HAVE_LIBUTIL_H | #ifdef HAVE_LIBUTIL_H | ||||
#include <libutil.h> | #include <libutil.h> | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct conf c; | struct conf c; | ||||
struct dbinfo dbi; | struct dbinfo dbi; | ||||
unsigned int f; | unsigned int f; | ||||
for (f = 1; state_iterate(state, &c, &dbi, f) == 1; f = 0) { | for (f = 1; state_iterate(state, &c, &dbi, f) == 1; f = 0) { | ||||
if (dbi.id[0] == '\0') | if (dbi.id[0] == '\0') | ||||
continue; | continue; | ||||
(void)run_change("rem", &c, dbi.id, 0); | |||||
(void)run_change("add", &c, dbi.id, sizeof(dbi.id)); | (void)run_change("add", &c, dbi.id, sizeof(dbi.id)); | ||||
} | } | ||||
} | } | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int c, tout, flags, flush, restore, ret; | int c, tout, flags, flush, restore, ret; | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (debug) { | ||||
if (tout == 0) | if (tout == 0) | ||||
tout = 15000; | tout = 15000; | ||||
} | } | ||||
update_interfaces(); | update_interfaces(); | ||||
conf_parse(configfile); | conf_parse(configfile); | ||||
if (flush) { | if (flush) { | ||||
rules_flush(); | rules_flush(); | ||||
if (!restore) | |||||
flags |= O_TRUNC; | flags |= O_TRUNC; | ||||
} | } | ||||
struct pollfd *pfd = NULL; | struct pollfd *pfd = NULL; | ||||
bl_t *bl = NULL; | bl_t *bl = NULL; | ||||
size_t nfd = 0; | size_t nfd = 0; | ||||
size_t maxfd = 0; | size_t maxfd = 0; | ||||
for (size_t i = 0; i < nblsock; i++) | for (size_t i = 0; i < nblsock; i++) | ||||
Show All 14 Lines | if (nfd == 0) | ||||
addfd(&pfd, &bl, &nfd, &maxfd, _PATH_BLSOCK); | addfd(&pfd, &bl, &nfd, &maxfd, _PATH_BLSOCK); | ||||
state = state_open(dbfile, flags, 0600); | state = state_open(dbfile, flags, 0600); | ||||
if (state == NULL) | if (state == NULL) | ||||
state = state_open(dbfile, flags | O_CREAT, 0600); | state = state_open(dbfile, flags | O_CREAT, 0600); | ||||
if (state == NULL) | if (state == NULL) | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
if (restore) | if (restore) { | ||||
if (!flush) | |||||
rules_flush(); | |||||
rules_restore(); | rules_restore(); | ||||
} | |||||
if (!debug) { | if (!debug) { | ||||
if (daemon(0, 0) == -1) | if (daemon(0, 0) == -1) | ||||
err(EXIT_FAILURE, "daemon failed"); | err(EXIT_FAILURE, "daemon failed"); | ||||
if (pidfile(NULL) == -1) | if (pidfile(NULL) == -1) | ||||
err(EXIT_FAILURE, "Can't create pidfile"); | err(EXIT_FAILURE, "Can't create pidfile"); | ||||
} | } | ||||
Show All 31 Lines |