Blame
Date:
Sat Nov 8 20:28:31 2014 UTC
Message:
0.9.0 is the last version of Wildcarddnsd, the succeeding project is called Delphinusdnsd and will have its first release around November 15th, 2015. The new project page is at http://delphinusdns.centroid.eu.
001
2011-06-28
pbug
/*
002
2014-04-13
pjp
* Copyright (c) 2011-2014 Peter J. Philipp
003
2011-06-28
pbug
* All rights reserved.
004
2011-06-28
pbug
*
005
2011-06-28
pbug
* Redistribution and use in source and binary forms, with or without
006
2011-06-28
pbug
* modification, are permitted provided that the following conditions
007
2011-06-28
pbug
* are met:
008
2011-06-28
pbug
* 1. Redistributions of source code must retain the above copyright
009
2011-06-28
pbug
* notice, this list of conditions and the following disclaimer.
010
2011-06-28
pbug
* 2. Redistributions in binary form must reproduce the above copyright
011
2011-06-28
pbug
* notice, this list of conditions and the following disclaimer in the
012
2011-06-28
pbug
* documentation and/or other materials provided with the distribution.
013
2011-06-28
pbug
* 3. The name of the author may not be used to endorse or promote products
014
2011-06-28
pbug
* derived from this software without specific prior written permission
015
2011-06-28
pbug
*
016
2011-06-28
pbug
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017
2011-06-28
pbug
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018
2011-06-28
pbug
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019
2011-06-28
pbug
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020
2011-06-28
pbug
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021
2011-06-28
pbug
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022
2011-06-28
pbug
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023
2011-06-28
pbug
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024
2011-06-28
pbug
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025
2011-06-28
pbug
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
2011-06-28
pbug
*
027
2011-06-28
pbug
*/
028
2011-06-28
pbug
029
2011-06-28
pbug
#include "include.h"
030
2011-06-28
pbug
#include "dns.h"
031
2011-06-28
pbug
#include "db.h"
032
2011-06-28
pbug
033
2011-06-28
pbug
#include <openssl/evp.h>
034
2011-06-28
pbug
#include <openssl/hmac.h>
035
2011-06-28
pbug
036
2011-06-28
pbug
extern struct logging logging;
037
2013-02-16
pjp
extern int debug;
038
2013-02-16
pjp
extern int verbose;
039
2013-02-16
pjp
040
2014-05-18
pjp
void dolog(int pri, char *fmt, ...);
041
2014-05-18
pjp
void receivelog(char *buf, int len);
042
2014-05-18
pjp
int remotelog(int fd, char *fmt, ...);
043
2013-02-16
pjp
044
2013-02-16
pjp
045
2013-02-16
pjp
/*
046
2013-02-16
pjp
* dolog() - is a wrapper to syslog and printf depending on debug flag
047
2013-02-16
pjp
*
048
2013-02-16
pjp
*/
049
2013-02-16
pjp
050
2013-02-16
pjp
void
051
2013-02-16
pjp
dolog(int pri, char *fmt, ...)
052
2013-02-16
pjp
{
053
2013-02-16
pjp
va_list ap;
054
2013-02-16
pjp
055
2013-02-16
pjp
va_start(ap, fmt);
056
2013-02-16
pjp
057
2013-02-16
pjp
/*
058
2013-02-16
pjp
* if the message is a debug message and verbose (-v) is set
059
2013-02-16
pjp
* then print it, otherwise
060
2013-02-16
pjp
*/
061
2013-02-16
pjp
062
2013-02-16
pjp
if (pri == LOG_DEBUG) {
063
2013-02-16
pjp
if (verbose && debug)
064
2013-02-16
pjp
vprintf(fmt, ap);
065
2013-02-16
pjp
else if (verbose)
066
2013-02-16
pjp
vsyslog(pri, fmt, ap);
067
2013-02-16
pjp
} else {
068
2013-02-16
pjp
if (debug)
069
2013-02-16
pjp
vprintf(fmt, ap);
070
2013-02-16
pjp
else
071
2013-02-16
pjp
vsyslog(pri, fmt, ap);
072
2013-02-16
pjp
}
073
2013-02-16
pjp
074
2013-02-16
pjp
va_end(ap);
075
2013-02-16
pjp
076
2013-02-16
pjp
}
077
2011-06-28
pbug
078
2011-06-28
pbug
/*
079
2011-06-28
pbug
* remotelog() - is like syslog() only the first argument is a filedescriptor
080
2011-06-28
pbug
* instead of severity, it will send a packet to the loghost
081
2011-06-28
pbug
* signed.
082
2011-06-28
pbug
*/
083
2011-06-28
pbug
084
2011-06-28
pbug
int
085
2011-06-28
pbug
remotelog(int fd, char *fmt, ...)
086
2011-06-28
pbug
{
087
2011-06-28
pbug
va_list ap;
088
2011-06-28
pbug
static char buf[1500];
089
2011-06-28
pbug
static char outbuf[1500];
090
2011-06-28
pbug
char sign[20];
091
2011-06-28
pbug
char *p;
092
2011-06-28
pbug
u_int rlen;
093
2011-06-28
pbug
static u_int64_t sequence = 0;
094
2011-06-28
pbug
095
2011-06-28
pbug
096
2011-06-28
pbug
va_start(ap, fmt);
097
2011-06-28
pbug
vsnprintf(buf, sizeof(buf), fmt, ap);
098
2011-06-28
pbug
va_end(ap);
099
2011-06-28
pbug
100
2011-06-28
pbug
#ifdef __NetBSD__
101
2011-06-28
pbug
snprintf(outbuf, sizeof(outbuf), "XXXXXXXXXXXXXXXXXXXX%lu %s %s",
102
2011-06-28
pbug
#else
103
2011-06-28
pbug
snprintf(outbuf, sizeof(outbuf), "XXXXXXXXXXXXXXXXXXXX%llu %s %s",
104
2011-06-28
pbug
#endif
105
2011-06-28
pbug
sequence++, logging.hostname, buf);
106
2011-06-28
pbug
107
2011-06-28
pbug
p = &outbuf[20];
108
2011-06-28
pbug
109
2011-06-28
pbug
110
2011-06-28
pbug
HMAC(EVP_sha1(), logging.logpasswd, strlen(logging.logpasswd),
111
2011-06-28
pbug
(unsigned char *)p, strlen(p), (unsigned char *)&sign,
112
2011-06-28
pbug
&rlen);
113
2011-06-28
pbug
114
2011-06-28
pbug
memcpy(outbuf, sign, 20);
115
2011-06-28
pbug
116
2011-06-28
pbug
return (send(fd, outbuf, strlen(outbuf), 0));
117
2011-06-28
pbug
}
118
2011-06-28
pbug
119
2011-06-28
pbug
120
2011-06-28
pbug
void
121
2011-06-28
pbug
receivelog(char *buf, int len)
122
2011-06-28
pbug
{
123
2011-06-28
pbug
static char inbuf[1500];
124
2011-06-28
pbug
char sign[20];
125
2011-06-28
pbug
char *p;
126
2011-06-28
pbug
int rlen;
127
2011-06-28
pbug
128
2011-06-28
pbug
if (len < 21 || len > 1450)
129
2011-06-28
pbug
return;
130
2011-06-28
pbug
131
2011-06-28
pbug
memcpy(&inbuf, buf, len);
132
2011-06-28
pbug
inbuf[len] = '\0';
133
2011-06-28
pbug
134
2011-06-28
pbug
p = &inbuf[20];
135
2011-06-28
pbug
136
2011-06-28
pbug
HMAC(EVP_sha1(), logging.logpasswd, strlen(logging.logpasswd),
137
2011-06-28
pbug
(unsigned char *)p, strlen(p), (unsigned char *)&sign,
138
2011-06-28
pbug
(unsigned int *)&rlen);
139
2011-06-28
pbug
140
2011-06-28
pbug
if (memcmp(inbuf, sign, 20) != 0)
141
2011-06-28
pbug
return;
142
2011-06-28
pbug
143
2011-06-28
pbug
/* skip sequence number */
144
2011-06-28
pbug
p = strchr(p, ' ');
145
2011-06-28
pbug
if (p == NULL)
146
2011-06-28
pbug
return;
147
2011-06-28
pbug
148
2011-06-28
pbug
p++;
149
2011-06-28
pbug
150
2011-06-28
pbug
syslog(LOG_INFO, "%s", p);
151
2011-06-28
pbug
152
2011-06-28
pbug
return;
153
2011-06-28
pbug
}
repomaster@centroid.eu