Commit Diff
Diff:
c25e4088bd7943eacc409e3d66848fbea777a257
02c349d24d1f505cd60a8780fdbdb4234c8e0d34
Commit:
02c349d24d1f505cd60a8780fdbdb4234c8e0d34
Tree:
3bfe384f23e9b3753d914ca530dce59e1123a5ae
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Tue Jun 28 18:40:18 2011 UTC
Message:
* make Linux happy, make NetBSD happy * forgot to add log.c which is needed for this last commit tested on Linux Debian 6.0, NetBSD (compiles), FreeBSD 8.2 (compiles), OpenBSD
blob - d80efa9fa2cb5b61917a4422149e1e62d55a22b6
blob + c6fbfc09b53a8f1b26235f79e81421e07bf069dd
--- main.c
+++ main.c
@@ -129,7 +129,7 @@ struct tcps {
} *tn1, *tn2, *tnp;
-static const char rcsid[] = "$Id: main.c,v 1.65 2011/06/28 17:04:33 pbug Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.66 2011/06/28 18:40:19 pbug Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -565,21 +565,28 @@ main(int argc, char *argv[])
if (logging.bind == 1) {
if (bind(lfd, (struct sockaddr *)&logging.loghost2,
- logging.loghost2.ss_len) < 0) {
+ ((logging.loghost2.ss_family == AF_INET6) ?
+ sizeof(struct sockaddr_in6) :
+ sizeof(struct sockaddr_in))
+ ) < 0) {
syslog(LOG_INFO, "binding log socket: %m");
slave_shutdown();
exit(1);
}
+#ifndef __linux__
if (shutdown(lfd, SHUT_WR) < 0) {
syslog(LOG_INFO, "shutdown log socket: %m");
slave_shutdown();
exit(1);
}
+#endif
} else {
if (connect(lfd, (struct sockaddr *)&logging.loghost2,
- logging.loghost2.ss_len) < 0) {
+ ((logging.loghost2.ss_family == AF_INET6) ?
+ sizeof(struct sockaddr_in6) :
+ sizeof(struct sockaddr_in))) < 0) {
syslog(LOG_INFO, "connecting log socket: %m");
slave_shutdown();
exit(1);
blob - /dev/null
blob + 9729cc50f46076b4aa0b2295dfc4291143eb9b12 (mode 644)
--- /dev/null
+++ log.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2011 Peter J. Philipp
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 "include.h"
+#include "dns.h"
+#include "db.h"
+
+#include <openssl/evp.h>
+#include <openssl/hmac.h>
+
+extern struct logging logging;
+int remotelog(int fd, char *fmt, ...);
+void receivelog(char *buf, int len);
+
+/*
+ * remotelog() - is like syslog() only the first argument is a filedescriptor
+ * instead of severity, it will send a packet to the loghost
+ * signed.
+ */
+
+int
+remotelog(int fd, char *fmt, ...)
+{
+ va_list ap;
+ static char buf[1500];
+ static char outbuf[1500];
+ char sign[20];
+ char *p;
+ u_int rlen;
+ static u_int64_t sequence = 0;
+
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
+#ifdef __NetBSD__
+ snprintf(outbuf, sizeof(outbuf), "XXXXXXXXXXXXXXXXXXXX%lu %s %s",
+#else
+ snprintf(outbuf, sizeof(outbuf), "XXXXXXXXXXXXXXXXXXXX%llu %s %s",
+#endif
+ sequence++, logging.hostname, buf);
+
+ p = &outbuf[20];
+
+
+ HMAC(EVP_sha1(), logging.logpasswd, strlen(logging.logpasswd),
+ (unsigned char *)p, strlen(p), (unsigned char *)&sign,
+ &rlen);
+
+ memcpy(outbuf, sign, 20);
+
+ return (send(fd, outbuf, strlen(outbuf), 0));
+}
+
+
+void
+receivelog(char *buf, int len)
+{
+ static char inbuf[1500];
+ char sign[20];
+ char *p;
+ int rlen;
+
+ if (len < 21 || len > 1450)
+ return;
+
+ memcpy(&inbuf, buf, len);
+ inbuf[len] = '\0';
+
+ p = &inbuf[20];
+
+ HMAC(EVP_sha1(), logging.logpasswd, strlen(logging.logpasswd),
+ (unsigned char *)p, strlen(p), (unsigned char *)&sign,
+ (unsigned int *)&rlen);
+
+ if (memcmp(inbuf, sign, 20) != 0)
+ return;
+
+ /* skip sequence number */
+ p = strchr(p, ' ');
+ if (p == NULL)
+ return;
+
+ p++;
+
+ syslog(LOG_INFO, "%s", p);
+
+ return;
+}
repomaster@centroid.eu