summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 48b84af)
raw | patch | inline | side by side (parent: 48b84af)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 20 Jul 2013 00:11:44 +0000 (17:11 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 20 Jul 2013 00:11:44 +0000 (17:11 -0700) |
configure.ac | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/plugins/cname/dns.c | [new file with mode: 0644] | patch | blob |
diff --git a/configure.ac b/configure.ac
index 6847c08c9da269681eddfcc3c269bb110314e10d..937750160ff55651a3d1aef99be6a64015be9ad5 100644 (file)
--- a/configure.ac
+++ b/configure.ac
[backend accessing the Puppet stored configuration database])
AC_SDB_PLUGIN([syslog], [yes],
[plugin logging to syslog])
+AC_SDB_PLUGIN([cname-dns], [yes],
+ [canonicalize hostnames by querying DNS])
AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
diff --git a/src/Makefile.am b/src/Makefile.am
index 09b81b72727d33e625dad9cd65fc4ed30cb7dfbb..3ab6bc616da82c88e4b38ebea79a5093c44b6712 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
pkgbackendlibdir = $(pkglibdir)/backend
pkgbackendcollectdlibdir = $(pkgbackendlibdir)/collectd
pkgbackendpuppetlibdir = $(pkgbackendlibdir)/puppet
+pkgcnamelibdir = $(pkglibdir)/cname
pkglib_LTLIBRARIES =
pkgbackendlib_LTLIBRARIES =
pkgbackendcollectdlib_LTLIBRARIES =
pkgbackendpuppetlib_LTLIBRARIES =
+pkgcnamelib_LTLIBRARIES =
if BUILD_PLUGIN_COLLECTD
pkgbackendcollectdlib_LTLIBRARIES += backend/collectd/unixsock.la
libsysdb_la_DEPENDENCIES += plugins/syslog.la
endif
+if BUILD_PLUGIN_CNAMEDNS
+pkgcnamelib_LTLIBRARIES += plugins/cname/dns.la
+plugins_cname_dns_la_SOURCE = plugins/cname/dns.c
+plugins_cname_dns_la_LDFLAGS = -module -avoid-version
+libsysdb_la_LIBADD += -dlopen plugins/cname/dns.la
+libsysdb_la_DEPENDENCIES += plugins/cname/dns.la
+endif
+
include/sysdb.h: include/sysdb.h.in ../version
source ../version; sed \
-e "s/@SDB_VERSION_MAJOR@/$$VERSION_MAJOR/g" \
diff --git a/src/plugins/cname/dns.c b/src/plugins/cname/dns.c
--- /dev/null
+++ b/src/plugins/cname/dns.c
@@ -0,0 +1,97 @@
+/*
+ * SysDB - src/plugins/cname/dns.c
+ * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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 "sysdb.h"
+#include "core/plugin.h"
+#include "core/error.h"
+
+#include <assert.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+/* make it a no-op if necessary */
+#ifndef AI_IDN
+# define AI_IDN 0
+#endif
+
+SDB_PLUGIN_MAGIC;
+
+/*
+ * plugin API
+ */
+
+static char *
+sdb_dns_cname(const char *name,
+ sdb_object_t __attribute__((unused)) *user_data)
+{
+ struct addrinfo hints;
+ struct addrinfo *ret = NULL;
+ char *cname;
+ int err;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_CANONNAME | AI_IDN;
+
+ err = getaddrinfo(name, /* service = */ NULL, &hints, &ret);
+ if (err) {
+ /* XXX: what to do about EAI_AGAIN? */
+ sdb_plugin_logf(SDB_LOG_ERR, "cname::dns: Failed to resolve '%s': %s",
+ name, gai_strerror(err));
+ return NULL;
+ }
+
+ if ((! ret) || (! ret->ai_canonname))
+ return NULL;
+
+ cname = strdup(ret->ai_canonname);
+ freeaddrinfo(ret);
+ return cname;
+} /* sdb_dns_cname */
+
+int
+sdb_module_init(sdb_plugin_info_t *info)
+{
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "cname::dns");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC,
+ "canonicalize hostnames by querying DNS");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT,
+ "Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
+
+ sdb_plugin_register_cname("cname::dns", sdb_dns_cname, NULL);
+ return 0;
+} /* sdb_module_init */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+