Blame
Date:
Sat Aug 1 09:01:52 2020 UTC
Message:
move extended RCODE's out of the RCODE section those are only 0x00 through 0x0F make a section that shows extended RCODE's that are added to a EDNS0 tag.
001
2014-11-14
pjp
/*
002
2019-11-20
pjp
* Copyright (c) 2011-2019 Peter J. Philipp
003
2014-11-14
pjp
* All rights reserved.
004
2014-11-14
pjp
*
005
2014-11-14
pjp
* Redistribution and use in source and binary forms, with or without
006
2014-11-14
pjp
* modification, are permitted provided that the following conditions
007
2014-11-14
pjp
* are met:
008
2014-11-14
pjp
* 1. Redistributions of source code must retain the above copyright
009
2014-11-14
pjp
* notice, this list of conditions and the following disclaimer.
010
2014-11-14
pjp
* 2. Redistributions in binary form must reproduce the above copyright
011
2014-11-14
pjp
* notice, this list of conditions and the following disclaimer in the
012
2014-11-14
pjp
* documentation and/or other materials provided with the distribution.
013
2014-11-14
pjp
* 3. The name of the author may not be used to endorse or promote products
014
2014-11-14
pjp
* derived from this software without specific prior written permission
015
2014-11-14
pjp
*
016
2014-11-14
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017
2014-11-14
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018
2014-11-14
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019
2014-11-14
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020
2014-11-14
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021
2014-11-14
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022
2014-11-14
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023
2014-11-14
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024
2014-11-14
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025
2014-11-14
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
2014-11-14
pjp
*
027
2014-11-14
pjp
*/
028
2014-11-14
pjp
029
2017-10-26
pjp
/*
030
2019-11-25
pjp
* $Id: log.c,v 1.9 2019/11/25 15:14:42 pjp Exp $
031
2017-10-26
pjp
*/
032
2014-11-14
pjp
033
2017-10-26
pjp
034
2019-06-06
pjp
#include <sys/types.h>
035
2019-06-06
pjp
#include <sys/socket.h>
036
2017-10-26
pjp
037
2019-06-06
pjp
#include <netinet/in.h>
038
2019-06-06
pjp
#include <arpa/inet.h>
039
2019-06-06
pjp
#include <netdb.h>
040
2019-06-06
pjp
041
2019-06-06
pjp
#include <stdio.h>
042
2019-06-06
pjp
#include <stdlib.h>
043
2019-06-06
pjp
#include <string.h>
044
2019-11-20
pjp
#include <ctype.h>
045
2019-06-06
pjp
046
2019-06-06
pjp
#include <syslog.h>
047
2019-06-06
pjp
048
2019-06-06
pjp
#ifdef __linux__
049
2019-06-06
pjp
#include <grp.h>
050
2019-06-06
pjp
#define __USE_BSD 1
051
2019-06-06
pjp
#include <endian.h>
052
2019-06-06
pjp
#include <bsd/stdlib.h>
053
2019-06-06
pjp
#include <bsd/string.h>
054
2019-06-06
pjp
#include <bsd/sys/queue.h>
055
2019-06-06
pjp
#define __unused
056
2019-06-06
pjp
#include <bsd/sys/tree.h>
057
2019-06-06
pjp
#include <bsd/sys/endian.h>
058
2019-06-06
pjp
#else /* not linux */
059
2019-06-06
pjp
#include <sys/queue.h>
060
2019-06-06
pjp
#include <sys/tree.h>
061
2019-06-06
pjp
#endif /* __linux__ */
062
2019-06-06
pjp
063
2014-11-14
pjp
#include <openssl/evp.h>
064
2014-11-14
pjp
#include <openssl/hmac.h>
065
2014-11-14
pjp
066
2019-06-06
pjp
#include "ddd-dns.h"
067
2019-06-06
pjp
#include "ddd-db.h"
068
2019-06-06
pjp
069
2014-11-14
pjp
extern int debug;
070
2014-11-14
pjp
extern int verbose;
071
2014-11-14
pjp
072
2014-11-14
pjp
void dolog(int pri, char *fmt, ...);
073
2019-11-20
pjp
char *input_sanitize(char *);
074
2014-11-14
pjp
075
2014-11-14
pjp
076
2014-11-14
pjp
/*
077
2019-11-20
pjp
* INPUT_SANITIZE - syslogd does this sanitization, but in debug mode we want
078
2019-11-20
pjp
* this sanitizer at least.
079
2019-11-20
pjp
*/
080
2019-11-20
pjp
081
2019-11-20
pjp
char *
082
2019-11-20
pjp
input_sanitize(char *fmt)
083
2019-11-20
pjp
{
084
2019-11-20
pjp
char *buf;
085
2019-11-20
pjp
char *p, *q;
086
2019-11-20
pjp
char backslash = '\\';
087
2019-11-20
pjp
088
2019-11-20
pjp
buf = malloc((4 * strlen(fmt)) + 1);
089
2019-11-20
pjp
if (buf == NULL)
090
2019-11-20
pjp
return NULL;
091
2019-11-20
pjp
092
2019-11-20
pjp
q = buf;
093
2019-11-20
pjp
094
2019-11-20
pjp
for (p = fmt; *p; p++) {
095
2019-11-20
pjp
if (*p == backslash) {
096
2019-11-20
pjp
*q++ = *p++;
097
2019-11-20
pjp
if (*p == '\0')
098
2019-11-20
pjp
break;
099
2019-11-20
pjp
switch (*p) {
100
2019-11-20
pjp
case 'n':
101
2019-11-20
pjp
case 't':
102
2019-11-20
pjp
case 'r':
103
2019-11-20
pjp
case '\'':
104
2019-11-20
pjp
case '\\':
105
2019-11-20
pjp
case '"':
106
2019-11-20
pjp
*q++ = *p;
107
2019-11-20
pjp
break;
108
2019-11-20
pjp
default:
109
2019-11-20
pjp
*q++ = '\\';
110
2019-11-20
pjp
*q++ = *p;
111
2019-11-20
pjp
break;
112
2019-11-20
pjp
}
113
2019-11-20
pjp
} else {
114
2019-11-20
pjp
if (isprint(*p) || *p == '\n') {
115
2019-11-20
pjp
*q++ = *p;
116
2019-11-20
pjp
} else {
117
2019-11-20
pjp
*q++ = '\\';
118
2019-11-20
pjp
*q++ = 'x';
119
2019-11-20
pjp
snprintf(q, 3, "%02X", *p & 0xff);
120
2019-11-20
pjp
q += 2;
121
2019-11-20
pjp
}
122
2019-11-20
pjp
}
123
2019-11-20
pjp
}
124
2019-11-20
pjp
125
2019-11-20
pjp
*q = '\0';
126
2019-11-20
pjp
127
2019-11-20
pjp
return (buf);
128
2019-11-20
pjp
}
129
2019-11-20
pjp
130
2019-11-20
pjp
131
2019-11-20
pjp
/*
132
2014-11-14
pjp
* dolog() - is a wrapper to syslog and printf depending on debug flag
133
2014-11-14
pjp
*
134
2014-11-14
pjp
*/
135
2014-11-14
pjp
136
2014-11-14
pjp
void
137
2014-11-14
pjp
dolog(int pri, char *fmt, ...)
138
2014-11-14
pjp
{
139
2014-11-14
pjp
va_list ap;
140
2019-11-20
pjp
char *buf, *sanitize;
141
2014-11-14
pjp
142
2014-11-14
pjp
va_start(ap, fmt);
143
2014-11-14
pjp
144
2014-11-14
pjp
/*
145
2014-11-14
pjp
* if the message is a debug message and verbose (-v) is set
146
2014-11-14
pjp
* then print it, otherwise
147
2014-11-14
pjp
*/
148
2014-11-14
pjp
149
2014-11-14
pjp
if (pri == LOG_DEBUG) {
150
2019-11-20
pjp
if (verbose && debug) {
151
2019-11-20
pjp
buf = malloc(1024);
152
2019-11-20
pjp
if (buf == NULL) {
153
2019-11-20
pjp
printf("-= failed to allocate memory for output buffer =-\n");
154
2019-11-20
pjp
} else {
155
2019-11-20
pjp
vsnprintf(buf, 1024, fmt, ap);
156
2019-11-20
pjp
sanitize = input_sanitize(buf);
157
2019-11-20
pjp
if (sanitize == NULL) {
158
2019-11-20
pjp
printf("-= failed to allocate memory for output buffer =-\n");
159
2019-11-20
pjp
} else {
160
2019-11-20
pjp
printf("%s", sanitize);
161
2019-11-20
pjp
free(sanitize);
162
2019-11-20
pjp
}
163
2019-11-20
pjp
free(buf);
164
2019-11-20
pjp
}
165
2019-11-20
pjp
} else if (verbose)
166
2014-11-14
pjp
vsyslog(pri, fmt, ap);
167
2014-11-14
pjp
} else {
168
2019-11-20
pjp
if (debug) {
169
2019-11-20
pjp
buf = malloc(1024);
170
2019-11-20
pjp
if (buf == NULL) {
171
2019-11-20
pjp
printf("-= failed to allocate memory for output buffer =-\n");
172
2019-11-20
pjp
} else {
173
2019-11-20
pjp
vsnprintf(buf, 1024, fmt, ap);
174
2019-11-20
pjp
sanitize = input_sanitize(buf);
175
2019-11-20
pjp
if (sanitize == NULL) {
176
2019-11-20
pjp
printf("-= failed to allocate memory for output buffer =-\n");
177
2019-11-20
pjp
} else {
178
2019-11-20
pjp
printf("%s", sanitize);
179
2019-11-20
pjp
free(sanitize);
180
2019-11-20
pjp
}
181
2019-11-20
pjp
free(buf);
182
2019-11-20
pjp
}
183
2019-11-20
pjp
} else
184
2014-11-14
pjp
vsyslog(pri, fmt, ap);
185
2014-11-14
pjp
}
186
2014-11-14
pjp
187
2014-11-14
pjp
va_end(ap);
188
2014-11-14
pjp
189
2014-11-14
pjp
}
repomaster@centroid.eu