Blame
Date:
Mon Jan 11 09:00:47 2021 UTC
Message:
a usleep makes it unnecessary slow, I guess it forces a context switch...
0001
2018-02-25
pjp
/*
0002
2021-01-06
pjp
* Copyright (c) 2016-2021 Peter J. Philipp
0003
2018-02-25
pjp
* All rights reserved.
0004
2018-02-25
pjp
*
0005
2018-02-25
pjp
* Redistribution and use in source and binary forms, with or without
0006
2018-02-25
pjp
* modification, are permitted provided that the following conditions
0007
2018-02-25
pjp
* are met:
0008
2018-02-25
pjp
* 1. Redistributions of source code must retain the above copyright
0009
2018-02-25
pjp
* notice, this list of conditions and the following disclaimer.
0010
2018-02-25
pjp
* 2. Redistributions in binary form must reproduce the above copyright
0011
2018-02-25
pjp
* notice, this list of conditions and the following disclaimer in the
0012
2018-02-25
pjp
* documentation and/or other materials provided with the distribution.
0013
2018-02-25
pjp
* 3. The name of the author may not be used to endorse or promote products
0014
2018-02-25
pjp
* derived from this software without specific prior written permission
0015
2018-02-25
pjp
*
0016
2018-02-25
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017
2018-02-25
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018
2018-02-25
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019
2018-02-25
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020
2018-02-25
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021
2018-02-25
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022
2018-02-25
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023
2018-02-25
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024
2018-02-25
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025
2018-02-25
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026
2018-02-25
pjp
*
0027
2018-02-25
pjp
*/
0028
2018-02-25
pjp
0029
2020-04-10
pjp
#include <sys/types.h>
0030
2019-06-06
pjp
#include <sys/socket.h>
0031
2019-06-06
pjp
#include <sys/time.h>
0032
2019-06-06
pjp
#include <sys/stat.h>
0033
2019-06-06
pjp
#include <sys/un.h>
0034
2018-02-25
pjp
0035
2019-06-06
pjp
#include <netinet/in.h>
0036
2019-06-06
pjp
#include <arpa/inet.h>
0037
2019-06-06
pjp
#include <netdb.h>
0038
2019-04-26
pjp
0039
2019-06-06
pjp
#include <stdio.h>
0040
2019-06-06
pjp
#include <stdlib.h>
0041
2019-06-06
pjp
#include <stdint.h>
0042
2019-06-06
pjp
#include <stdarg.h>
0043
2019-06-06
pjp
#include <string.h>
0044
2019-06-06
pjp
#include <unistd.h>
0045
2019-06-06
pjp
#include <syslog.h>
0046
2020-04-10
pjp
#include <errno.h>
0047
2019-04-26
pjp
0048
2019-06-06
pjp
#ifdef __linux__
0049
2019-06-06
pjp
#include <grp.h>
0050
2019-06-06
pjp
#define __USE_BSD 1
0051
2019-06-06
pjp
#include <endian.h>
0052
2019-06-06
pjp
#include <bsd/stdlib.h>
0053
2019-06-06
pjp
#include <bsd/string.h>
0054
2019-06-06
pjp
#include <bsd/unistd.h>
0055
2019-06-06
pjp
#include <bsd/sys/queue.h>
0056
2019-06-06
pjp
#define __unused
0057
2019-06-06
pjp
#include <bsd/sys/tree.h>
0058
2019-06-06
pjp
#include <bsd/sys/endian.h>
0059
2019-06-06
pjp
#include "imsg.h"
0060
2019-06-06
pjp
#else /* not linux */
0061
2019-06-06
pjp
#include <sys/queue.h>
0062
2019-06-06
pjp
#include <sys/tree.h>
0063
2019-06-06
pjp
#ifdef __FreeBSD__
0064
2019-06-06
pjp
#include "imsg.h"
0065
2019-06-06
pjp
#else
0066
2019-06-06
pjp
#include <imsg.h>
0067
2019-06-06
pjp
#endif /* __FreeBSD__ */
0068
2019-06-06
pjp
#endif /* __linux__ */
0069
2019-04-26
pjp
0070
2019-06-06
pjp
#ifndef NTOHS
0071
2019-06-06
pjp
#include "endian.h"
0072
2019-06-06
pjp
#endif
0073
2019-04-26
pjp
0074
2019-06-06
pjp
#include "ddd-dns.h"
0075
2019-06-06
pjp
#include "ddd-db.h"
0076
2019-06-06
pjp
#include "ddd-config.h"
0077
2019-06-06
pjp
0078
2018-02-25
pjp
int debug = 0;
0079
2018-02-25
pjp
int verbose = 0;
0080
2020-06-30
pjp
int forward = 0;
0081
2020-07-01
pjp
int forwardtsig = 0;
0082
2020-07-17
pjp
int strictx20i = 1;
0083
2020-07-03
pjp
int zonecount = 0;
0084
2020-07-06
pjp
int cache = 0;
0085
2021-01-07
pjp
int tsigpassname = 0;
0086
2020-04-10
pjp
extern int dnssec;
0087
2019-11-05
pjp
extern int bytes_received;
0088
2018-02-25
pjp
0089
2018-02-25
pjp
/* prototypes */
0090
2018-02-25
pjp
0091
2018-02-25
pjp
void dolog(int pri, char *fmt, ...);
0092
2018-05-10
pjp
int dump_db_bind(ddDB*, FILE *, char *);
0093
2019-02-15
pjp
int print_rbt_bind(FILE *, struct rbtree *);
0094
2018-02-25
pjp
int usage(int argc, char *argv[]);
0095
2018-02-25
pjp
int start(int argc, char *argv[]);
0096
2018-02-25
pjp
int restart(int argc, char *argv[]);
0097
2018-02-25
pjp
int stop(int argc, char *argv[]);
0098
2018-02-25
pjp
int configtest(int argc, char *argv[]);
0099
2018-05-10
pjp
int bindfile(int argc, char *argv[]);
0100
2018-05-04
pjp
int sshfp(int argc, char *argv[]);
0101
2019-02-09
pjp
int count_db(ddDB *);
0102
2018-02-25
pjp
0103
2018-02-25
pjp
0104
2018-02-25
pjp
/* glue */
0105
2018-02-25
pjp
int insert_axfr(char *, char *);
0106
2018-02-25
pjp
int insert_filter(char *, char *);
0107
2020-07-16
pjp
int insert_passlist(char *, char *);
0108
2020-06-25
pjp
int insert_notifyddd(char *, char *);
0109
2020-07-01
pjp
int insert_forward(struct sockaddr_storage *, uint16_t, char *);
0110
2020-08-26
pjp
int insert_zone(char *);
0111
2021-01-07
pjp
int insert_tsigpassname(char *, int);
0112
2018-02-25
pjp
0113
2019-02-19
pjp
int illdestination;
0114
2019-02-19
pjp
int *ptr = &illdestination;
0115
2019-02-19
pjp
0116
2018-02-25
pjp
int notify = 0;
0117
2020-07-16
pjp
int passlist = 0;
0118
2018-02-25
pjp
int bcount = 0;
0119
2018-02-25
pjp
char *bind_list[255];
0120
2018-02-25
pjp
char *interface_list[255];
0121
2018-02-25
pjp
int bflag = 0;
0122
2018-02-25
pjp
int ratelimit_packets_per_second = 0;
0123
2018-02-25
pjp
int ratelimit = 0;
0124
2020-04-10
pjp
extern u_int16_t port;
0125
2018-02-25
pjp
int nflag = 0;
0126
2018-02-25
pjp
int iflag = 0;
0127
2018-02-25
pjp
int lflag = 0;
0128
2018-02-25
pjp
int icount = 0;
0129
2018-02-25
pjp
int vslen = 0;
0130
2018-02-25
pjp
char *versionstring = NULL;
0131
2018-02-25
pjp
u_int64_t expiredon, signedon;
0132
2018-02-25
pjp
0133
2018-02-25
pjp
/* externs */
0134
2018-02-25
pjp
0135
2020-04-10
pjp
extern int dig(int argc, char *argv[]);
0136
2020-04-10
pjp
extern int signmain(int argc, char *argv[]);
0137
2019-12-03
pjp
extern uint32_t unpack32(char *);
0138
2019-12-03
pjp
extern uint16_t unpack16(char *);
0139
2019-12-03
pjp
extern void unpack(char *, char *, int);
0140
2019-12-03
pjp
0141
2019-12-03
pjp
extern void pack(char *, char *, int);
0142
2019-12-03
pjp
extern void pack32(char *, u_int32_t);
0143
2019-12-03
pjp
extern void pack16(char *, u_int16_t);
0144
2019-12-03
pjp
extern void pack8(char *, u_int8_t);
0145
2018-02-25
pjp
extern char * convert_name(char *name, int namelen);
0146
2018-02-25
pjp
0147
2018-02-25
pjp
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
0148
2018-02-25
pjp
extern int mybase64_decode(char const *, u_char *, size_t);
0149
2020-04-10
pjp
0150
2020-04-10
pjp
extern char * bin2hex(char *, int);
0151
2020-04-10
pjp
extern u_int64_t timethuman(time_t);
0152
2020-04-10
pjp
extern char * bitmap2human(char *, int);
0153
2020-04-10
pjp
extern char * dns_label(char *, int *);
0154
2019-11-11
pjp
extern struct rbtree * Lookup_zone(ddDB *, char *, int, int, int);
0155
2019-02-26
pjp
extern struct question *build_fake_question(char *, int, u_int16_t, char *, int);
0156
2020-04-10
pjp
extern int memcasecmp(u_char *, u_char *, int);
0157
2020-04-10
pjp
extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
0158
2019-02-26
pjp
extern char * dns_label(char *, int *);
0159
2018-02-25
pjp
extern int label_count(char *);
0160
2018-02-25
pjp
extern char *get_dns_type(int, int);
0161
2018-02-25
pjp
extern char * hash_name(char *, int, struct nsec3param *);
0162
2018-02-25
pjp
extern char * base32hex_encode(u_char *input, int len);
0163
2018-02-25
pjp
0164
2018-02-25
pjp
0165
2018-02-25
pjp
0166
2020-04-10
pjp
struct _mycmdtab {
0167
2020-04-10
pjp
char *var;
0168
2020-04-10
pjp
int (*cmd)(int, char **);
0169
2020-04-10
pjp
} mycmdtab[] = {
0170
2020-04-10
pjp
{ "bindfile", bindfile },
0171
2020-04-10
pjp
{ "configtest", configtest },
0172
2020-04-10
pjp
{ "query", dig },
0173
2020-04-10
pjp
{ "help", usage },
0174
2020-04-10
pjp
{ "sign", signmain },
0175
2020-04-10
pjp
{ "sshfp", sshfp },
0176
2020-04-10
pjp
{ "start", start },
0177
2020-04-10
pjp
{ "stop", stop},
0178
2020-04-10
pjp
{ "restart", restart },
0179
2020-04-10
pjp
{ NULL, NULL }
0180
2019-02-07
pjp
};
0181
2018-05-11
pjp
0182
2018-02-25
pjp
int
0183
2018-02-25
pjp
main(int argc, char *argv[])
0184
2018-02-25
pjp
{
0185
2018-02-25
pjp
struct _mycmdtab *pctab;
0186
2018-02-25
pjp
0187
2018-02-25
pjp
if (argc == 1) {
0188
2018-02-25
pjp
usage(argc, argv);
0189
2018-02-25
pjp
exit(1);
0190
2018-02-25
pjp
}
0191
2018-02-25
pjp
0192
2018-02-25
pjp
for (pctab = &mycmdtab[0]; pctab->var; pctab++) {
0193
2018-02-25
pjp
if (strcmp((char *)pctab->var, argv[1]) == 0) {
0194
2018-02-25
pjp
argc--; argv++;
0195
2018-02-25
pjp
dnssec = 1;
0196
2018-02-25
pjp
exit(pctab->cmd(argc, argv));
0197
2018-02-25
pjp
}
0198
2018-02-25
pjp
}
0199
2018-02-25
pjp
0200
2018-02-25
pjp
usage(argc, argv);
0201
2018-02-25
pjp
exit(1);
0202
2021-01-07
pjp
}
0203
2021-01-07
pjp
0204
2021-01-07
pjp
int
0205
2021-01-07
pjp
insert_tsigpassname(char *name, int len)
0206
2021-01-07
pjp
{
0207
2021-01-07
pjp
return 0;
0208
2021-01-06
pjp
}
0209
2021-01-06
pjp
0210
2021-01-06
pjp
int
0211
2020-08-26
pjp
insert_zone(char *zonename)
0212
2020-08-26
pjp
{
0213
2020-08-26
pjp
return 0;
0214
2020-08-26
pjp
}
0215
2020-08-26
pjp
0216
2020-08-26
pjp
int
0217
2019-11-04
pjp
insert_axfr(char *address, char *prefixlen)
0218
2018-02-25
pjp
{
0219
2018-02-25
pjp
return 0;
0220
2018-02-25
pjp
}
0221
2018-02-25
pjp
0222
2018-02-25
pjp
int
0223
2019-02-24
pjp
insert_filter(char *address, char *prefixlen)
0224
2018-02-25
pjp
{
0225
2018-02-25
pjp
return 0;
0226
2018-02-25
pjp
}
0227
2018-02-25
pjp
0228
2018-02-25
pjp
int
0229
2020-07-16
pjp
insert_passlist(char *address, char *prefixlen)
0230
2018-02-25
pjp
{
0231
2018-02-25
pjp
return 0;
0232
2018-02-25
pjp
}
0233
2018-02-25
pjp
0234
2018-02-25
pjp
int
0235
2020-06-25
pjp
insert_notifyddd(char *address, char *prefixlen)
0236
2018-02-25
pjp
{
0237
2018-02-25
pjp
return 0;
0238
2018-02-25
pjp
}
0239
2018-02-25
pjp
0240
2020-07-01
pjp
int
0241
2020-07-01
pjp
insert_forward(struct sockaddr_storage *sso, uint16_t port, char *tsigkey)
0242
2020-07-01
pjp
{
0243
2020-07-01
pjp
return 0;
0244
2020-07-01
pjp
}
0245
2018-02-25
pjp
0246
2018-02-25
pjp
/*
0247
2018-02-25
pjp
* dolog() - is a wrapper to syslog and printf depending on debug flag
0248
2018-02-25
pjp
*
0249
2018-02-25
pjp
*/
0250
2018-02-25
pjp
0251
2018-02-25
pjp
void
0252
2018-02-25
pjp
dolog(int pri, char *fmt, ...)
0253
2018-02-25
pjp
{
0254
2018-02-25
pjp
va_list ap;
0255
2018-02-25
pjp
0256
2018-02-25
pjp
va_start(ap, fmt);
0257
2018-02-25
pjp
0258
2018-02-25
pjp
/*
0259
2018-02-25
pjp
* if the message is a debug message and verbose (-v) is set
0260
2018-02-25
pjp
* then print it, otherwise
0261
2018-02-25
pjp
*/
0262
2018-02-25
pjp
0263
2018-02-25
pjp
if (pri <= LOG_INFO) {
0264
2018-02-25
pjp
vprintf(fmt, ap);
0265
2018-02-25
pjp
}
0266
2018-02-25
pjp
0267
2018-02-25
pjp
va_end(ap);
0268
2018-02-25
pjp
0269
2018-02-25
pjp
}
0270
2018-02-25
pjp
0271
2018-02-25
pjp
int
0272
2018-06-23
pjp
usage(int argc, char *argv[])
0273
2018-02-25
pjp
{
0274
2018-06-23
pjp
int retval = 0;
0275
2018-02-25
pjp
0276
2018-06-23
pjp
if (argc == 2 && strcmp(argv[1], "sign") == 0) {
0277
2020-03-06
pjp
fprintf(stderr, "usage: dddctl sign [-KXZ] [-a algorithm] [-B bits] [-e seconds] [-I iterations] [-i inputfile] [-k KSK] [-m mask] [-n zonename] [-o output] [-R keyword] [-S pid] [-s salt] [-t ttl] [-x serial] [-z ZSK]\n");
0278
2018-06-23
pjp
fprintf(stderr, "\t-K\t\tcreate a new KSK key.\n");
0279
2019-10-08
pjp
fprintf(stderr, "\t-X\t\tupdate the serial to YYYYMMDD01.\n");
0280
2018-06-23
pjp
fprintf(stderr, "\t-Z\t\tcreate a new ZSK key.\n");
0281
2018-06-23
pjp
fprintf(stderr, "\t-a algorithm use algorithm (integer)\n");
0282
2018-06-23
pjp
fprintf(stderr, "\t-B bits\t\tuse number of bits (integer)\n");
0283
2018-06-23
pjp
fprintf(stderr, "\t-e seconds\texpiry in seconds\n");
0284
2018-06-23
pjp
fprintf(stderr, "\t-I iterations\tuse (integer) NSEC3 iterations\n");
0285
2018-06-23
pjp
fprintf(stderr, "\t-i inputfile\tuse the inputfile of unsigned zone\n");
0286
2018-06-23
pjp
fprintf(stderr, "\t-k KSK\t\tuse provided KSK key-signing keyname\n");
0287
2018-06-23
pjp
fprintf(stderr, "\t-m mask\t\trun the following masked functions\n");
0288
2018-06-23
pjp
fprintf(stderr, "\t-n zonename\trun for zonename zone\n");
0289
2018-06-23
pjp
fprintf(stderr, "\t-o output\toutput to file, may be '-' for stdout\n");
0290
2020-03-06
pjp
fprintf(stderr, "\t-R keyword\tSpecify key roll-over method (prep or double)\n");
0291
2018-06-23
pjp
fprintf(stderr, "\t-S pid\t\tsign with this pid ('KSK' or 'ZSK' if used in\n\t\t\tconjunction with [-ZK])\n");
0292
2018-06-23
pjp
fprintf(stderr, "\t-s salt\t\tsalt for NSEC3 (in hexadecimal)\n");
0293
2018-06-23
pjp
fprintf(stderr, "\t-t ttl\t\ttime-to-live for dnskey's\n");
0294
2019-10-08
pjp
fprintf(stderr, "\t-x serial\tupdate serial to argument\n");
0295
2018-06-23
pjp
fprintf(stderr, "\t-z ZSK\t\tuse provided ZSK zone-signing keyname\n");
0296
2018-06-23
pjp
return 0;
0297
2019-02-07
pjp
} else if (argc == 2 && strcmp(argv[1], "query") == 0) {
0298
2019-12-27
pjp
fprintf(stderr, "usage: dddctl query [-DITZ] [-@ server] [-P port] [-p file] [-Q server]\n\t\t[-y keyname:password] name command\n");
0299
2019-02-07
pjp
fprintf(stderr, "\t-@ server\t\tUse server ip.\n");
0300
2019-10-10
pjp
fprintf(stderr, "\t-D\t\t\tUse DNSSEC (DO bit) lookup.\n");
0301
2019-10-10
pjp
fprintf(stderr, "\t-I\t\t\tIndent output.\n");
0302
2019-10-10
pjp
fprintf(stderr, "\t-T\t\t\tUse TCP.\n");
0303
2019-10-10
pjp
fprintf(stderr, "\t-Z\t\t\tOutput as a zonefile.\n");
0304
2019-10-10
pjp
fprintf(stderr, "\t-P port\t\t\tUse specified port.\n");
0305
2019-10-10
pjp
fprintf(stderr, "\t-p file\t\t\tOutput to file.\n");
0306
2019-02-19
pjp
fprintf(stderr, "\t-Q server\t\tSynonymous with -@\n");
0307
2019-10-10
pjp
fprintf(stderr, "\t-y keyname:password\tTSIG keyname and password\n");
0308
2019-02-07
pjp
0309
2019-02-07
pjp
return 0;
0310
2018-06-23
pjp
} else if (argc == 2) {
0311
2018-06-23
pjp
retval = 1;
0312
2018-02-25
pjp
} else {
0313
2018-06-23
pjp
fprintf(stderr, "usage: command [arg ...]\n");
0314
2018-06-23
pjp
fprintf(stderr, "\tbindfile zonename zonefile\n");
0315
2019-11-14
pjp
fprintf(stderr, "\tconfigtest [-cn] [configfile]\n");
0316
2019-12-27
pjp
fprintf(stderr, "\tquery [-DITZ] [-@ server] [-P port] [-p file] [-Q server]\n\t\t[-y keyname:password] name command\n");
0317
2018-06-23
pjp
fprintf(stderr, "\thelp [command]\n");
0318
2020-03-06
pjp
fprintf(stderr, "\tsign [-KXZ] [-a algorithm] [-B bits] [-e seconds]\n\t\t[-I iterations] [-i inputfile] [-k KSK] [-m mask]\n\t\t[-n zonename] [-o output] [-R keyword] [-S pid] [-s salt]\n\t\t[-t ttl] [-x serial] [-z ZSK]\n");
0319
2018-06-23
pjp
fprintf(stderr, "\tsshfp hostname [-k keyfile] [-t ttl]\n");
0320
2021-01-06
pjp
fprintf(stderr, "\tstart [-f configfile] [-I ident] [-s socket]\n");
0321
2021-01-06
pjp
fprintf(stderr, "\tstop [-I ident] [-s socket]\n");
0322
2021-01-06
pjp
fprintf(stderr, "\trestart [-I ident] [-s socket]\n");
0323
2018-06-23
pjp
retval = 0;
0324
2018-02-25
pjp
}
0325
2018-02-25
pjp
0326
2018-02-25
pjp
return (retval);
0327
2018-02-25
pjp
}
0328
2018-02-25
pjp
0329
2018-06-23
pjp
int
0330
2018-06-23
pjp
start(int argc, char *argv[])
0331
2018-02-25
pjp
{
0332
2019-01-29
pjp
struct stat sb;
0333
2020-04-10
pjp
char buf[PATH_MAX];
0334
2021-01-06
pjp
char sockpathbuf[PATH_MAX];
0335
2018-06-23
pjp
char *path = NULL;
0336
2019-01-29
pjp
char *socketpath = SOCKPATH;
0337
2019-01-29
pjp
char *configfile = CONFFILE;
0338
2021-01-06
pjp
char *ident = NULL;
0339
2021-01-06
pjp
int ch, usesp = 0;
0340
2018-02-25
pjp
0341
2021-01-06
pjp
while ((ch = getopt(argc, argv, "f:I:s:")) != -1) {
0342
2019-01-29
pjp
switch (ch) {
0343
2019-01-29
pjp
case 'f':
0344
2019-01-29
pjp
configfile = optarg;
0345
2019-01-29
pjp
break;
0346
2021-01-06
pjp
case 'I':
0347
2021-01-06
pjp
ident = optarg;
0348
2021-01-06
pjp
break;
0349
2019-01-29
pjp
case 's':
0350
2019-01-29
pjp
socketpath = optarg;
0351
2021-01-06
pjp
usesp = 1;
0352
2019-01-29
pjp
break;
0353
2019-01-29
pjp
default:
0354
2019-01-29
pjp
usage(argc, argv);
0355
2019-01-29
pjp
exit(1);
0356
2019-01-29
pjp
}
0357
2019-01-29
pjp
}
0358
2019-01-29
pjp
0359
2021-01-06
pjp
if (ident != NULL && usesp) {
0360
2021-01-06
pjp
fprintf(stderr, "cannot specify -I and -s together\n");
0361
2021-01-06
pjp
exit(1);
0362
2021-01-06
pjp
}
0363
2021-01-06
pjp
0364
2021-01-06
pjp
if (ident != NULL) {
0365
2021-01-06
pjp
snprintf(sockpathbuf, sizeof(sockpathbuf),
0366
2021-01-06
pjp
"/var/run/delphinusdnsd-%s.sock", ident);
0367
2021-01-06
pjp
0368
2021-01-06
pjp
socketpath = sockpathbuf;
0369
2021-01-06
pjp
}
0370
2021-01-06
pjp
0371
2019-01-29
pjp
if (lstat(socketpath, &sb) != -1) {
0372
2019-01-29
pjp
fprintf(stderr, "%s exists, not clobbering\n", socketpath);
0373
2019-01-29
pjp
exit(1);
0374
2019-01-29
pjp
}
0375
2019-01-29
pjp
0376
2019-01-29
pjp
0377
2018-06-23
pjp
if (geteuid() != 0) {
0378
2018-06-23
pjp
fprintf(stderr, "must be root\n");
0379
2018-06-23
pjp
exit(1);
0380
2018-02-25
pjp
}
0381
2018-02-25
pjp
0382
2018-06-23
pjp
#if defined __OpenBSD__ || defined __FreeBSD__
0383
2018-06-23
pjp
if (setresuid(0,0,0) < 0) {
0384
2018-06-23
pjp
perror("setuid");
0385
2018-06-23
pjp
exit(1);
0386
2018-02-25
pjp
}
0387
2018-05-10
pjp
#else
0388
2018-06-23
pjp
if (setgid(0) < 0) {
0389
2018-06-23
pjp
perror("setgid");
0390
2018-06-23
pjp
exit(1);
0391
2018-05-10
pjp
}
0392
2018-06-23
pjp
if (setuid(0) < 0) {
0393
2018-06-23
pjp
perror("setuid");
0394
2018-06-23
pjp
exit(1);
0395
2018-05-10
pjp
}
0396
2018-02-25
pjp
#endif
0397
2018-02-25
pjp
0398
2018-02-25
pjp
0399
2018-06-23
pjp
fprintf(stderr, "starting delphinusdnsd\n");
0400
2018-02-25
pjp
0401
2019-01-29
pjp
path = realpath(configfile, buf);
0402
2019-01-29
pjp
if (path == NULL) {
0403
2019-01-29
pjp
perror("realpath");
0404
2019-01-29
pjp
exit(1);
0405
2019-01-29
pjp
}
0406
2018-02-25
pjp
0407
2021-01-06
pjp
if (ident) {
0408
2021-01-06
pjp
if (execl("/usr/local/sbin/delphinusdnsd", "delphinusdnsd", "-f", path,
0409
2021-01-06
pjp
"-I", ident, NULL) < 0) {
0410
2021-01-06
pjp
perror("execl");
0411
2021-01-06
pjp
exit(1);
0412
2021-01-06
pjp
}
0413
2021-01-06
pjp
} else {
0414
2021-01-06
pjp
if (execl("/usr/local/sbin/delphinusdnsd", "delphinusdnsd", "-f", path,
0415
2021-01-06
pjp
"-s", socketpath, NULL) < 0) {
0416
2021-01-06
pjp
perror("execl");
0417
2021-01-06
pjp
exit(1);
0418
2021-01-06
pjp
}
0419
2018-02-25
pjp
}
0420
2018-02-25
pjp
0421
2021-01-06
pjp
return 0;
0422
2018-02-25
pjp
}
0423
2018-02-25
pjp
0424
2019-01-29
pjp
int
0425
2019-01-29
pjp
command_socket(char *sockpath)
0426
2019-01-29
pjp
{
0427
2019-01-29
pjp
int so;
0428
2019-01-29
pjp
struct sockaddr_un sun;
0429
2019-01-29
pjp
0430
2019-01-29
pjp
so = socket(AF_UNIX, SOCK_STREAM, 0);
0431
2019-01-29
pjp
if (so < 0) {
0432
2019-01-29
pjp
return -1;
0433
2019-01-29
pjp
}
0434
2019-01-29
pjp
0435
2019-01-29
pjp
memset(&sun, 0, sizeof(sun));
0436
2019-01-29
pjp
sun.sun_family = AF_UNIX;
0437
2019-01-29
pjp
if (strlcpy(sun.sun_path, sockpath, sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) {
0438
2019-01-29
pjp
close(so);
0439
2019-01-29
pjp
return -1;
0440
2019-01-29
pjp
}
0441
2019-04-25
pjp
#ifndef __linux__
0442
2019-01-29
pjp
sun.sun_len = SUN_LEN(&sun);
0443
2019-04-25
pjp
#endif
0444
2019-01-29
pjp
0445
2019-01-29
pjp
if (connect(so, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
0446
2019-01-29
pjp
close(so);
0447
2019-01-29
pjp
return -1;
0448
2019-01-29
pjp
}
0449
2019-01-29
pjp
0450
2019-01-29
pjp
return (so);
0451
2019-01-29
pjp
}
0452
2019-01-29
pjp
0453
2018-06-23
pjp
int
0454
2018-06-23
pjp
restart(int argc, char *argv[])
0455
2018-02-25
pjp
{
0456
2021-01-06
pjp
char buf[512], sockpathbuf[512];
0457
2019-01-29
pjp
char *socketpath = SOCKPATH;
0458
2021-01-06
pjp
char *ident = NULL;
0459
2019-01-29
pjp
struct dddcomm *dc;
0460
2021-01-06
pjp
int so, usesp = 0;
0461
2019-01-29
pjp
int ch, len;
0462
2018-02-25
pjp
0463
2021-01-06
pjp
while ((ch = getopt(argc, argv, "I:s:")) != -1) {
0464
2019-01-29
pjp
switch (ch) {
0465
2021-01-06
pjp
case 'I':
0466
2021-01-06
pjp
ident = optarg;
0467
2021-01-06
pjp
break;
0468
2019-01-29
pjp
case 's':
0469
2019-01-29
pjp
socketpath = optarg;
0470
2021-01-06
pjp
usesp = 1;
0471
2019-01-29
pjp
break;
0472
2019-01-29
pjp
default:
0473
2019-01-29
pjp
usage(argc, argv);
0474
2019-01-29
pjp
exit(1);
0475
2019-01-29
pjp
}
0476
2019-01-29
pjp
}
0477
2019-01-29
pjp
0478
2021-01-06
pjp
if (ident != NULL && usesp) {
0479
2021-01-06
pjp
fprintf(stderr, "cannot specify -I and -s together\n");
0480
2021-01-06
pjp
exit(1);
0481
2021-01-06
pjp
}
0482
2021-01-06
pjp
0483
2021-01-06
pjp
if (ident != NULL) {
0484
2021-01-06
pjp
snprintf(sockpathbuf, sizeof(sockpathbuf),
0485
2021-01-06
pjp
"/var/run/delphinusdnsd-%s.sock", ident);
0486
2021-01-06
pjp
0487
2021-01-06
pjp
socketpath = sockpathbuf;
0488
2021-01-06
pjp
}
0489
2021-01-06
pjp
0490
2018-06-23
pjp
if (geteuid() != 0) {
0491
2018-06-23
pjp
fprintf(stderr, "must be root\n");
0492
2018-06-23
pjp
exit(1);
0493
2018-02-25
pjp
}
0494
2019-01-29
pjp
0495
2018-06-23
pjp
fprintf(stderr, "restarting delphinusdnsd\n");
0496
2018-02-25
pjp
0497
2019-01-29
pjp
if ((so = command_socket(socketpath)) < 0) {
0498
2019-01-29
pjp
perror(socketpath);
0499
2018-06-23
pjp
exit(1);
0500
2019-01-29
pjp
}
0501
2019-01-29
pjp
0502
2019-01-29
pjp
memset(&buf, 0, sizeof(buf));
0503
2019-01-29
pjp
dc = (struct dddcomm *)&buf[0];
0504
2019-01-29
pjp
dc->command = IMSG_RELOAD_MESSAGE;
0505
2019-01-29
pjp
if (send(so, buf, sizeof(struct dddcomm), 0) < 0) {
0506
2019-01-29
pjp
perror("send");
0507
2019-01-29
pjp
close(so);
0508
2019-01-29
pjp
exit(1);
0509
2018-02-25
pjp
}
0510
2019-01-29
pjp
if ((len = recv(so, buf, sizeof(struct dddcomm), 0)) < 0) {
0511
2019-01-29
pjp
perror("recv");
0512
2019-01-29
pjp
close(so);
0513
2019-01-29
pjp
exit(1);
0514
2019-01-29
pjp
}
0515
2019-01-29
pjp
close(so);
0516
2019-01-29
pjp
0517
2019-01-29
pjp
return (0);
0518
2018-02-25
pjp
}
0519
2018-02-25
pjp
0520
2018-06-23
pjp
int
0521
2018-06-23
pjp
stop(int argc, char *argv[])
0522
2018-02-25
pjp
{
0523
2021-01-06
pjp
char buf[PATH_MAX];
0524
2021-01-06
pjp
char sockpathbuf[PATH_MAX];
0525
2019-01-29
pjp
char *socketpath = SOCKPATH;
0526
2021-01-06
pjp
char *ident = NULL;
0527
2019-01-29
pjp
struct dddcomm *dc;
0528
2021-01-06
pjp
int so, usesp = 0;
0529
2019-01-29
pjp
int ch, len;
0530
2018-02-25
pjp
0531
2021-01-06
pjp
while ((ch = getopt(argc, argv, "I:s:")) != -1) {
0532
2019-01-29
pjp
switch (ch) {
0533
2021-01-06
pjp
case 'I':
0534
2021-01-06
pjp
ident = optarg;
0535
2021-01-06
pjp
break;
0536
2019-01-29
pjp
case 's':
0537
2019-01-29
pjp
socketpath = optarg;
0538
2021-01-06
pjp
usesp = 1;
0539
2019-01-29
pjp
break;
0540
2019-01-29
pjp
default:
0541
2019-01-29
pjp
usage(argc, argv);
0542
2019-01-29
pjp
exit(1);
0543
2019-01-29
pjp
}
0544
2021-01-06
pjp
}
0545
2021-01-06
pjp
0546
2021-01-06
pjp
if (ident != NULL && usesp) {
0547
2021-01-06
pjp
fprintf(stderr, "cannot specify -I and -s together\n");
0548
2021-01-06
pjp
exit(1);
0549
2021-01-06
pjp
}
0550
2021-01-06
pjp
0551
2021-01-06
pjp
if (ident != NULL) {
0552
2021-01-06
pjp
snprintf(sockpathbuf, sizeof(sockpathbuf),
0553
2021-01-06
pjp
"/var/run/delphinusdnsd-%s.sock", ident);
0554
2021-01-06
pjp
0555
2021-01-06
pjp
socketpath = sockpathbuf;
0556
2020-07-26
pjp
}
0557
2020-07-26
pjp
0558
2018-05-10
pjp
if (geteuid() != 0) {
0559
2018-05-10
pjp
fprintf(stderr, "must be root\n");
0560
2018-05-10
pjp
exit(1);
0561
2018-02-25
pjp
}
0562
2019-01-29
pjp
0563
2018-06-23
pjp
fprintf(stderr, "stopping delphinusdnsd\n");
0564
2019-01-29
pjp
0565
2019-01-29
pjp
if ((so = command_socket(socketpath)) < 0) {
0566
2019-01-29
pjp
perror(socketpath);
0567
2018-05-10
pjp
exit(1);
0568
2019-01-29
pjp
}
0569
2019-01-29
pjp
0570
2019-01-29
pjp
memset(&buf, 0, sizeof(buf));
0571
2019-01-29
pjp
dc = (struct dddcomm *)&buf[0];
0572
2019-01-29
pjp
dc->command = IMSG_SHUTDOWN_MESSAGE;
0573
2019-01-29
pjp
if (send(so, buf, sizeof(struct dddcomm), 0) < 0) {
0574
2019-01-29
pjp
perror("send");
0575
2019-01-29
pjp
close(so);
0576
2019-01-29
pjp
exit(1);
0577
2018-02-25
pjp
}
0578
2019-01-29
pjp
if ((len = recv(so, buf, sizeof(struct dddcomm), 0)) < 0) {
0579
2019-01-29
pjp
perror("recv");
0580
2019-01-29
pjp
close(so);
0581
2019-01-29
pjp
exit(1);
0582
2019-01-29
pjp
}
0583
2019-01-29
pjp
close(so);
0584
2019-01-29
pjp
0585
2019-01-29
pjp
return (0);
0586
2018-02-25
pjp
}
0587
2018-02-25
pjp
0588
2018-05-10
pjp
int
0589
2018-05-10
pjp
configtest(int argc, char *argv[])
0590
2018-02-25
pjp
{
0591
2018-05-10
pjp
ddDB *db;
0592
2019-09-20
pjp
char *zonefile = CONFFILE;
0593
2019-02-09
pjp
int ch, count = 0;
0594
2019-11-14
pjp
uint32_t flags = 0;
0595
2018-02-25
pjp
0596
2019-02-09
pjp
0597
2019-11-14
pjp
while ((ch = getopt(argc, argv, "cn")) != -1) {
0598
2019-02-09
pjp
switch (ch) {
0599
2019-02-09
pjp
case 'c':
0600
2019-02-09
pjp
count = 1;
0601
2019-02-09
pjp
break;
0602
2019-11-14
pjp
case 'n':
0603
2019-11-14
pjp
flags = PARSEFILE_FLAG_NOSOCKET;
0604
2019-11-14
pjp
break;
0605
2019-02-09
pjp
default:
0606
2019-02-09
pjp
fprintf(stderr, "usage: dddctl configtest [-c] [input]\n");
0607
2019-02-09
pjp
exit(1);
0608
2019-02-09
pjp
}
0609
2018-02-25
pjp
}
0610
2018-02-25
pjp
0611
2019-02-09
pjp
argc -= optind;
0612
2019-02-09
pjp
argv += optind;
0613
2018-02-25
pjp
0614
2019-02-09
pjp
if (argc)
0615
2019-02-09
pjp
zonefile = argv[0];
0616
2018-02-25
pjp
0617
2018-02-25
pjp
0618
2019-02-09
pjp
0619
2019-02-09
pjp
0620
2018-05-10
pjp
/* open the database(s) */
0621
2018-05-10
pjp
db = dddbopen();
0622
2018-05-10
pjp
if (db == NULL) {
0623
2018-05-10
pjp
dolog(LOG_INFO, "dddbopen() failed\n");
0624
2018-05-10
pjp
return 1;
0625
2018-02-25
pjp
}
0626
2018-02-25
pjp
0627
2018-05-10
pjp
/* now we start reading our configfile */
0628
2018-02-25
pjp
0629
2019-11-14
pjp
if (parse_file(db, zonefile, flags) < 0) {
0630
2018-05-10
pjp
dolog(LOG_INFO, "parsing config file failed\n");
0631
2018-05-10
pjp
return 1;
0632
2018-02-25
pjp
}
0633
2018-02-25
pjp
0634
2019-11-06
pjp
#if __OpenBSD__
0635
2019-11-06
pjp
/* better late than never */
0636
2019-11-06
pjp
if (pledge("stdio", NULL) < 0) {
0637
2019-11-06
pjp
perror("pledge");
0638
2019-11-06
pjp
exit(1);
0639
2019-11-06
pjp
}
0640
2019-11-06
pjp
#endif
0641
2019-11-06
pjp
0642
2019-02-09
pjp
if (count)
0643
2019-02-09
pjp
count_db(db);
0644
2019-02-09
pjp
0645
2018-05-10
pjp
dddbclose(db);
0646
2018-02-25
pjp
0647
2018-05-10
pjp
printf("OK\n");
0648
2018-02-25
pjp
0649
2018-02-25
pjp
return 0;
0650
2018-02-25
pjp
}
0651
2018-02-25
pjp
0652
2018-05-10
pjp
int
0653
2018-05-10
pjp
sshfp(int argc, char *argv[])
0654
2018-02-25
pjp
{
0655
2018-02-25
pjp
char buf[512];
0656
2018-05-10
pjp
char *hostname = NULL;
0657
2018-05-10
pjp
char *keyfile = NULL;
0658
2018-05-10
pjp
FILE *po;
0659
2018-02-25
pjp
char *p, *q;
0660
2018-05-10
pjp
char *tmp;
0661
2018-05-10
pjp
int len, ttl = 3600;
0662
2018-05-10
pjp
int ch;
0663
2018-02-25
pjp
0664
2018-05-10
pjp
if (argc < 2) {
0665
2018-05-10
pjp
usage(argc, argv);
0666
2018-05-10
pjp
exit(1);
0667
2018-02-25
pjp
}
0668
2018-02-25
pjp
0669
2018-05-10
pjp
hostname = argv[1];
0670
2018-02-25
pjp
0671
2018-05-10
pjp
while ((ch = getopt(argc, argv, "f:k:t:")) != -1) {
0672
2018-05-10
pjp
switch (ch) {
0673
2018-05-10
pjp
case 'f':
0674
2018-05-10
pjp
/* fallthrough */
0675
2018-05-10
pjp
case 'k':
0676
2018-05-10
pjp
keyfile = optarg;
0677
2018-05-10
pjp
break;
0678
2018-05-10
pjp
case 't':
0679
2018-05-10
pjp
ttl = atoi(optarg);
0680
2018-05-10
pjp
break;
0681
2018-02-25
pjp
0682
2018-02-25
pjp
}
0683
2018-02-25
pjp
}
0684
2018-02-25
pjp
0685
2018-05-10
pjp
if (keyfile)
0686
2018-05-10
pjp
snprintf(buf, sizeof(buf), "/usr/bin/ssh-keygen -r %s -f %s", hostname, keyfile);
0687
2018-05-10
pjp
else
0688
2018-05-10
pjp
snprintf(buf, sizeof(buf), "/usr/bin/ssh-keygen -r %s", hostname);
0689
2018-02-25
pjp
0690
2018-05-10
pjp
po = popen(buf, "r");
0691
2018-05-10
pjp
if (po == NULL) {
0692
2018-05-10
pjp
perror("popen");
0693
2018-05-10
pjp
exit(1);
0694
2018-02-25
pjp
}
0695
2018-02-25
pjp
0696
2018-05-10
pjp
while (fgets(buf, sizeof(buf), po) != NULL) {
0697
2018-05-10
pjp
len = strlen(buf);
0698
2018-05-10
pjp
if (buf[len - 1] == '\n')
0699
2018-05-10
pjp
len--;
0700
2018-05-10
pjp
buf[len] = '\0';
0701
2018-02-25
pjp
0702
2018-05-10
pjp
while ((p = strchr(buf, ' ')) != NULL) {
0703
2018-05-10
pjp
*p = ',';
0704
2018-02-25
pjp
}
0705
2018-02-25
pjp
0706
2018-05-10
pjp
q = strrchr(buf, ',');
0707
2018-05-10
pjp
if (q == NULL) {
0708
2018-05-10
pjp
continue;
0709
2018-02-25
pjp
}
0710
2018-02-25
pjp
0711
2018-02-25
pjp
q++;
0712
2018-05-10
pjp
if (*q == '\0') {
0713
2018-05-10
pjp
continue;
0714
2018-02-25
pjp
}
0715
2018-02-25
pjp
0716
2018-05-10
pjp
tmp = strdup(q);
0717
2018-05-10
pjp
if (tmp == NULL) {
0718
2018-05-10
pjp
perror("strdup");
0719
2018-05-10
pjp
exit(1);
0720
2018-02-25
pjp
}
0721
2018-05-10
pjp
*q = '\0';
0722
2018-02-25
pjp
0723
2018-05-10
pjp
p = strchr(buf, ',');
0724
2018-05-10
pjp
if (p == NULL) {
0725
2018-05-10
pjp
continue;
0726
2018-02-25
pjp
}
0727
2018-02-25
pjp
0728
2018-05-10
pjp
q = strchr(p, ',');
0729
2018-05-10
pjp
if (q == NULL) {
0730
2018-05-10
pjp
continue;
0731
2018-02-25
pjp
}
0732
2018-02-25
pjp
0733
2018-05-10
pjp
q += 10;
0734
2018-02-25
pjp
0735
2018-05-10
pjp
printf(" %s.,sshfp,%d,%s\"%s\"\n", hostname, ttl, q, tmp);
0736
2018-05-10
pjp
free(tmp);
0737
2018-02-25
pjp
}
0738
2018-02-25
pjp
0739
2018-05-10
pjp
pclose(po);
0740
2018-02-25
pjp
0741
2018-05-10
pjp
exit(0);
0742
2018-02-25
pjp
}
0743
2018-02-25
pjp
0744
2018-02-25
pjp
int
0745
2018-05-10
pjp
dump_db_bind(ddDB *db, FILE *of, char *zonename)
0746
2018-02-25
pjp
{
0747
2018-05-10
pjp
int j, rs;
0748
2018-02-25
pjp
0749
2018-05-10
pjp
ddDBT key, data;
0750
2018-02-25
pjp
0751
2018-05-10
pjp
struct node *n, *nx;
0752
2019-02-15
pjp
struct rbtree *rbt = NULL, *rbt0 = NULL;
0753
2018-02-25
pjp
0754
2019-02-15
pjp
0755
2018-02-25
pjp
char *dnsname;
0756
2018-02-27
pjp
int labellen;
0757
2018-02-25
pjp
0758
2018-05-10
pjp
fprintf(of, ";; This file was generated by dddctl.c of delphinusdnsd\n");
0759
2018-02-25
pjp
0760
2018-02-25
pjp
dnsname = dns_label(zonename, &labellen);
0761
2018-02-25
pjp
if (dnsname == NULL)
0762
2018-02-25
pjp
return -1;
0763
2018-02-25
pjp
0764
2019-11-11
pjp
if ((rbt = Lookup_zone(db, dnsname, labellen, DNS_TYPE_SOA, 0)) == NULL) {
0765
2018-02-25
pjp
return -1;
0766
2018-02-25
pjp
}
0767
2018-02-25
pjp
0768
2019-02-15
pjp
if (print_rbt_bind(of, rbt) < 0) {
0769
2019-02-15
pjp
fprintf(stderr, "print_rbt_bind error\n");
0770
2018-02-25
pjp
return -1;
0771
2018-02-25
pjp
}
0772
2018-02-25
pjp
0773
2018-05-10
pjp
memset(&key, 0, sizeof(key));
0774
2018-05-10
pjp
memset(&data, 0, sizeof(data));
0775
2018-02-25
pjp
0776
2018-02-25
pjp
j = 0;
0777
2019-02-19
pjp
RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
0778
2018-02-25
pjp
rs = n->datalen;
0779
2019-02-15
pjp
if ((rbt0 = calloc(1, rs)) == NULL) {
0780
2018-02-25
pjp
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
0781
2018-02-25
pjp
exit(1);
0782
2018-02-25
pjp
}
0783
2018-02-25
pjp
0784
2019-02-15
pjp
memcpy((char *)rbt0, (char *)n->data, n->datalen);
0785
2018-02-25
pjp
0786
2019-02-15
pjp
if (rbt->zonelen == rbt0->zonelen &&
0787
2019-02-15
pjp
memcasecmp(rbt->zone, rbt0->zone, rbt->zonelen) == 0) {
0788
2018-05-10
pjp
continue;
0789
2019-02-09
pjp
}
0790
2018-02-25
pjp
0791
2019-02-15
pjp
if (print_rbt_bind(of, rbt0) < 0) {
0792
2019-02-15
pjp
fprintf(stderr, "print_rbt_bind error\n");
0793
2018-02-25
pjp
return -1;
0794
2018-02-25
pjp
}
0795
2018-02-25
pjp
0796
2018-02-25
pjp
0797
2018-05-10
pjp
j++;
0798
2018-05-10
pjp
}
0799
2018-02-25
pjp
0800
2018-05-10
pjp
#if DEBUG
0801
2018-02-25
pjp
printf("%d records\n", j);
0802
2018-02-25
pjp
#endif
0803
2019-10-08
pjp
0804
2018-05-10
pjp
return (0);
0805
2018-02-25
pjp
}
0806
2018-02-25
pjp
0807
2018-05-10
pjp
/*
0808
2018-05-10
pjp
* dump the RR's in BIND format
0809
2018-05-10
pjp
*/
0810
2018-02-25
pjp
0811
2018-02-25
pjp
int
0812
2019-02-15
pjp
print_rbt_bind(FILE *of, struct rbtree *rbt)
0813
2018-02-25
pjp
{
0814
2018-02-25
pjp
int i, x, len;
0815
2018-02-25
pjp
0816
2019-02-15
pjp
struct rrset *rrset = NULL;
0817
2019-02-15
pjp
struct rr *rrp = NULL;
0818
2019-02-15
pjp
struct rr *rrp2 = NULL;
0819
2019-02-15
pjp
0820
2018-02-25
pjp
char buf[4096];
0821
2018-02-25
pjp
0822
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
0823
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0824
2019-02-15
pjp
dolog(LOG_INFO, "no soa in zone!\n");
0825
2018-02-25
pjp
return -1;
0826
2018-02-25
pjp
}
0827
2018-05-10
pjp
fprintf(of, "%s %d IN SOA %s %s (\n\t\t\t\t%u\t; Serial\n\t\t\t\t%d\t; Refresh\n\t\t\t\t%d\t; Retry\n\t\t\t\t%d\t; Expire\n\t\t\t\t%d )\t; Minimum TTL\n\n",
0828
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0829
2020-05-07
pjp
rrset->ttl,
0830
2019-02-15
pjp
convert_name(((struct soa *)rrp->rdata)->nsserver, ((struct soa *)rrp->rdata)->nsserver_len),
0831
2019-02-15
pjp
convert_name(((struct soa *)rrp->rdata)->responsible_person, ((struct soa *)rrp->rdata)->rp_len),
0832
2019-02-15
pjp
((struct soa *)rrp->rdata)->serial,
0833
2019-02-15
pjp
((struct soa *)rrp->rdata)->refresh,
0834
2019-02-15
pjp
((struct soa *)rrp->rdata)->retry,
0835
2019-02-15
pjp
((struct soa *)rrp->rdata)->expire,
0836
2019-02-15
pjp
((struct soa *)rrp->rdata)->minttl);
0837
2018-02-25
pjp
}
0838
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NS)) != NULL) {
0839
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0840
2019-02-15
pjp
dolog(LOG_INFO, "no soa in zone!\n");
0841
2018-02-25
pjp
return -1;
0842
2018-02-25
pjp
}
0843
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0844
2018-05-10
pjp
fprintf(of, "%s %d IN NS %s\n",
0845
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0846
2020-05-07
pjp
rrset->ttl,
0847
2019-02-15
pjp
convert_name(((struct ns *)rrp2->rdata)->nsserver, ((struct ns *)rrp2->rdata)->nslen));
0848
2018-02-25
pjp
}
0849
2018-02-25
pjp
}
0850
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_MX)) != NULL) {
0851
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0852
2019-02-15
pjp
dolog(LOG_INFO, "no mx in zone!\n");
0853
2018-02-25
pjp
return -1;
0854
2018-02-25
pjp
}
0855
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0856
2018-05-10
pjp
fprintf(of, "%s %d IN MX %d %s\n",
0857
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0858
2020-05-07
pjp
rrset->ttl,
0859
2019-02-15
pjp
((struct smx *)rrp2->rdata)->preference,
0860
2019-02-15
pjp
convert_name(((struct smx *)rrp2->rdata)->exchange, ((struct smx *)rrp2->rdata)->exchangelen));
0861
2018-02-25
pjp
}
0862
2018-02-25
pjp
}
0863
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_DS)) != NULL) {
0864
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0865
2019-02-15
pjp
dolog(LOG_INFO, "no ds in zone!\n");
0866
2018-02-25
pjp
return -1;
0867
2018-02-25
pjp
}
0868
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0869
2018-05-10
pjp
fprintf(of, "%s %d IN DS %d %d %d (%s)\n",
0870
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0871
2020-05-07
pjp
rrset->ttl,
0872
2019-02-15
pjp
((struct ds *)rrp2->rdata)->key_tag,
0873
2019-02-15
pjp
((struct ds *)rrp2->rdata)->algorithm,
0874
2019-02-15
pjp
((struct ds *)rrp2->rdata)->digest_type,
0875
2019-02-15
pjp
bin2hex(((struct ds *)rrp2->rdata)->digest, ((struct ds *)rrp2->rdata)->digestlen));
0876
2018-02-25
pjp
}
0877
2018-02-25
pjp
}
0878
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_CNAME)) != NULL) {
0879
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0880
2019-02-15
pjp
dolog(LOG_INFO, "no soa in zone!\n");
0881
2018-02-25
pjp
return -1;
0882
2018-02-25
pjp
}
0883
2018-05-10
pjp
fprintf(of, "%s %d IN CNAME %s\n",
0884
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0885
2020-05-07
pjp
rrset->ttl,
0886
2019-02-15
pjp
convert_name(((struct cname *)rrp->rdata)->cname, ((struct cname *)rrp->rdata)->cnamelen));
0887
2018-02-25
pjp
}
0888
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NAPTR)) != NULL) {
0889
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0890
2019-02-15
pjp
dolog(LOG_INFO, "no ds in zone!\n");
0891
2018-02-25
pjp
return -1;
0892
2018-02-25
pjp
}
0893
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0894
2018-05-12
pjp
fprintf(of, "%s %d IN NAPTR %d\t%d\t\"",
0895
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0896
2020-05-07
pjp
rrset->ttl,
0897
2019-02-15
pjp
((struct naptr *)rrp2->rdata)->order,
0898
2019-02-15
pjp
((struct naptr *)rrp2->rdata)->preference);
0899
2018-02-25
pjp
0900
2019-02-15
pjp
for (x = 0; x < ((struct naptr *)rrp2->rdata)->flagslen; x++) {
0901
2019-02-15
pjp
fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->flags[x]);
0902
2018-02-25
pjp
}
0903
2018-05-12
pjp
fprintf(of, "\"\t\"");
0904
2019-02-15
pjp
for (x = 0; x < ((struct naptr *)rrp2->rdata)->serviceslen; x++) {
0905
2019-02-15
pjp
fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->services[x]);
0906
2018-02-25
pjp
}
0907
2018-05-12
pjp
fprintf(of, "\"\t\"");
0908
2019-02-15
pjp
for (x = 0; x < ((struct naptr *)rrp2->rdata)->regexplen; x++) {
0909
2019-02-15
pjp
fprintf(of, "%c", ((struct naptr *)rrp2->rdata)->regexp[x]);
0910
2018-02-25
pjp
}
0911
2019-02-15
pjp
fprintf(of, "\"\t%s\n", (((struct naptr *)rrp2->rdata)->replacement[0] == '\0') ? "." : convert_name(((struct naptr *)rrp2->rdata)->replacement, ((struct naptr *)rrp2->rdata)->replacementlen));
0912
2018-02-25
pjp
}
0913
2018-02-25
pjp
}
0914
2020-07-23
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_CAA)) != NULL) {
0915
2020-07-23
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0916
2020-07-23
pjp
dolog(LOG_INFO, "no caa in zone!\n");
0917
2020-07-23
pjp
return -1;
0918
2020-07-23
pjp
}
0919
2020-07-23
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0920
2020-07-23
pjp
fprintf(of, "%s %d IN CAA %d ",
0921
2020-07-23
pjp
convert_name(rbt->zone, rbt->zonelen),
0922
2020-07-23
pjp
rrset->ttl,
0923
2020-07-23
pjp
((struct caa *)rrp2->rdata)->flags);
0924
2020-07-23
pjp
0925
2020-07-23
pjp
for (i = 0; i < ((struct caa *)rrp2->rdata)->taglen; i++) {
0926
2020-07-23
pjp
fprintf(of, "%c", ((struct caa *)rrp2->rdata)->tag[i]);
0927
2020-07-23
pjp
}
0928
2020-07-23
pjp
fprintf(of, " \"");
0929
2020-07-23
pjp
for (i = 0; i < ((struct caa *)rrp2->rdata)->valuelen; i++) {
0930
2020-07-23
pjp
fprintf(of, "%c", ((struct caa *)rrp2->rdata)->value[i]);
0931
2020-07-23
pjp
}
0932
2020-07-23
pjp
fprintf(of, "\"\n");
0933
2020-07-23
pjp
}
0934
2020-07-23
pjp
}
0935
2020-07-23
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_HINFO)) != NULL) {
0936
2020-07-23
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0937
2020-07-23
pjp
dolog(LOG_INFO, "no hinfo in zone!\n");
0938
2020-07-23
pjp
return -1;
0939
2020-07-23
pjp
}
0940
2020-07-23
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0941
2020-07-26
pjp
fprintf(of, "%s %d IN HINFO \"",
0942
2020-07-23
pjp
convert_name(rbt->zone, rbt->zonelen),
0943
2020-07-23
pjp
rrset->ttl);
0944
2020-07-23
pjp
0945
2020-07-23
pjp
for (i = 0; i < ((struct hinfo *)rrp2->rdata)->cpulen; i++) {
0946
2020-07-23
pjp
fprintf(of, "%c", ((struct hinfo *)rrp2->rdata)->cpu[i]);
0947
2020-07-23
pjp
}
0948
2020-07-26
pjp
fprintf(of, "\" \"");
0949
2020-07-23
pjp
for (i = 0; i < ((struct hinfo *)rrp2->rdata)->oslen; i++) {
0950
2020-07-23
pjp
fprintf(of, "%c", ((struct hinfo *)rrp2->rdata)->os[i]);
0951
2020-07-23
pjp
}
0952
2020-07-26
pjp
fprintf(of, "\"\n");
0953
2020-07-23
pjp
}
0954
2020-07-23
pjp
}
0955
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_TXT)) != NULL) {
0956
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0957
2019-11-27
pjp
dolog(LOG_INFO, "no txt in zone!\n");
0958
2019-02-15
pjp
return -1;
0959
2019-02-15
pjp
}
0960
2019-11-27
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0961
2019-11-27
pjp
fprintf(of, "%s %d IN TXT \"",
0962
2019-11-27
pjp
convert_name(rbt->zone, rbt->zonelen),
0963
2020-05-07
pjp
rrset->ttl);
0964
2019-11-27
pjp
0965
2019-11-27
pjp
for (i = 0; i < ((struct txt *)rrp2->rdata)->txtlen; i++) {
0966
2019-11-27
pjp
if (i % 256 == 0)
0967
2019-11-27
pjp
continue;
0968
2019-04-30
pjp
0969
2019-11-27
pjp
fprintf(of, "%c", ((struct txt *)rrp2->rdata)->txt[i]);
0970
2019-11-27
pjp
}
0971
2019-11-27
pjp
fprintf(of, "\"\n");
0972
2019-02-15
pjp
}
0973
2019-02-15
pjp
}
0974
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_PTR)) != NULL) {
0975
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0976
2019-02-15
pjp
dolog(LOG_INFO, "no ds in zone!\n");
0977
2019-02-15
pjp
return -1;
0978
2019-02-15
pjp
}
0979
2018-05-10
pjp
fprintf(of, "%s %d IN PTR %s\n",
0980
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0981
2020-05-07
pjp
rrset->ttl,
0982
2019-02-15
pjp
convert_name(((struct ptr *)rrp->rdata)->ptr, ((struct ptr *)rrp->rdata)->ptrlen));
0983
2018-05-10
pjp
}
0984
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_SRV)) != NULL) {
0985
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0986
2019-02-15
pjp
dolog(LOG_INFO, "no srv in zone!\n");
0987
2018-05-10
pjp
return -1;
0988
2018-02-25
pjp
}
0989
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
0990
2018-05-10
pjp
fprintf(of, "%s %d IN SRV %d %d %d %s\n",
0991
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
0992
2020-05-07
pjp
rrset->ttl,
0993
2019-02-15
pjp
((struct srv *)rrp2->rdata)->priority,
0994
2019-02-15
pjp
((struct srv *)rrp2->rdata)->weight,
0995
2019-02-15
pjp
((struct srv *)rrp2->rdata)->port,
0996
2019-02-15
pjp
convert_name(((struct srv *)rrp2->rdata)->target,((struct srv *)rrp2->rdata)->targetlen));
0997
2018-05-10
pjp
}
0998
2018-02-25
pjp
}
0999
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_TLSA)) != NULL) {
1000
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1001
2019-02-15
pjp
dolog(LOG_INFO, "no tlsa in zone!\n");
1002
2018-02-25
pjp
return -1;
1003
2018-02-25
pjp
}
1004
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1005
2018-05-10
pjp
fprintf(of, "%s %d IN TLSA %d %d %d (%s)\n",
1006
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1007
2020-05-07
pjp
rrset->ttl,
1008
2019-02-15
pjp
((struct tlsa *)rrp2->rdata)->usage,
1009
2019-02-15
pjp
((struct tlsa *)rrp2->rdata)->selector,
1010
2019-02-15
pjp
((struct tlsa *)rrp2->rdata)->matchtype,
1011
2019-02-15
pjp
bin2hex(((struct tlsa *)rrp2->rdata)->data, ((struct tlsa *)rrp2->rdata)->datalen));
1012
2018-02-25
pjp
}
1013
2018-02-25
pjp
}
1014
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_SSHFP)) != NULL) {
1015
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1016
2019-02-15
pjp
dolog(LOG_INFO, "no sshfp in zone!\n");
1017
2018-02-25
pjp
return -1;
1018
2018-02-25
pjp
}
1019
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1020
2018-05-10
pjp
fprintf(of, "%s %d IN SSHFP %d %d (%s)\n",
1021
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1022
2020-05-07
pjp
rrset->ttl,
1023
2019-02-15
pjp
((struct sshfp *)rrp2->rdata)->algorithm,
1024
2019-02-15
pjp
((struct sshfp *)rrp2->rdata)->fptype,
1025
2019-02-15
pjp
bin2hex(((struct sshfp *)rrp2->rdata)->fingerprint, ((struct sshfp *)rrp2->rdata)->fplen));
1026
2018-05-10
pjp
}
1027
2018-05-10
pjp
}
1028
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_A)) != NULL) {
1029
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1030
2019-02-15
pjp
dolog(LOG_INFO, "no a RR in zone!\n");
1031
2018-05-10
pjp
return -1;
1032
2018-05-10
pjp
}
1033
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1034
2019-02-15
pjp
inet_ntop(AF_INET, &((struct a *)rrp2->rdata)->a, buf, sizeof(buf));
1035
2018-05-10
pjp
fprintf(of, "%s %d IN A %s\n",
1036
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1037
2020-05-07
pjp
rrset->ttl,
1038
2018-02-25
pjp
buf);
1039
2018-02-25
pjp
}
1040
2018-02-25
pjp
}
1041
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_AAAA)) != NULL) {
1042
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1043
2019-02-15
pjp
dolog(LOG_INFO, "no a RR in zone!\n");
1044
2018-02-25
pjp
return -1;
1045
2018-02-25
pjp
}
1046
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1047
2019-02-15
pjp
inet_ntop(AF_INET6, &((struct aaaa *)rrp2->rdata)->aaaa , buf, sizeof(buf));
1048
2018-05-10
pjp
fprintf(of, "%s %d IN AAAA %s\n",
1049
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1050
2020-05-07
pjp
rrset->ttl,
1051
2018-02-25
pjp
buf);
1052
2018-02-25
pjp
}
1053
2018-02-25
pjp
}
1054
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_DNSKEY)) != NULL) {
1055
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1056
2019-02-15
pjp
dolog(LOG_INFO, "no a RR in zone!\n");
1057
2018-02-25
pjp
return -1;
1058
2018-02-25
pjp
}
1059
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1060
2019-02-15
pjp
len = mybase64_encode(((struct dnskey *)rrp2->rdata)->public_key, ((struct dnskey *)rrp2->rdata)->publickey_len, buf, sizeof(buf));
1061
2018-02-25
pjp
buf[len] = '\0';
1062
2018-05-10
pjp
fprintf(of, "%s %d IN DNSKEY %d %d %d (%s)\n",
1063
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1064
2020-05-07
pjp
rrset->ttl,
1065
2019-02-15
pjp
((struct dnskey *)rrp2->rdata)->flags,
1066
2019-02-15
pjp
((struct dnskey *)rrp2->rdata)->protocol,
1067
2019-02-15
pjp
((struct dnskey *)rrp2->rdata)->algorithm,
1068
2018-02-25
pjp
buf);
1069
2020-07-23
pjp
}
1070
2020-07-23
pjp
}
1071
2020-07-23
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_RP)) != NULL) {
1072
2020-07-23
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1073
2020-07-23
pjp
dolog(LOG_INFO, "no RP RR in zone!\n");
1074
2020-07-23
pjp
return -1;
1075
2020-07-23
pjp
}
1076
2020-07-23
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1077
2020-07-23
pjp
1078
2020-07-23
pjp
fprintf(of, "%s %d IN RP %s %s\n",
1079
2020-07-23
pjp
convert_name(rbt->zone, rbt->zonelen),
1080
2020-07-23
pjp
rrset->ttl,
1081
2020-07-23
pjp
convert_name(((struct rp *)rrp2->rdata)->mbox, ((struct rp *)rrp2->rdata)->mboxlen),
1082
2020-07-23
pjp
convert_name(((struct rp *)rrp2->rdata)->txt, ((struct rp *)rrp2->rdata)->txtlen));
1083
2020-07-08
pjp
}
1084
2020-07-08
pjp
}
1085
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) != NULL) {
1086
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1087
2019-02-15
pjp
dolog(LOG_INFO, "no NSEC3PARAM RR in zone!\n");
1088
2019-02-15
pjp
return -1;
1089
2019-02-15
pjp
}
1090
2019-02-15
pjp
1091
2018-05-10
pjp
fprintf(of, "%s 0 IN NSEC3PARAM %d %d %d (%s)\n",
1092
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1093
2019-02-15
pjp
((struct nsec3param *)rrp->rdata)->algorithm,
1094
2019-02-15
pjp
((struct nsec3param *)rrp->rdata)->flags,
1095
2019-02-15
pjp
((struct nsec3param *)rrp->rdata)->iterations,
1096
2019-02-15
pjp
(((struct nsec3param *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3param *)rrp->rdata)->salt, ((struct nsec3param *)rrp->rdata)->saltlen));
1097
2018-02-25
pjp
}
1098
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
1099
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1100
2019-02-15
pjp
dolog(LOG_INFO, "no NSEC3PARAM RR in zone!\n");
1101
2018-02-25
pjp
return -1;
1102
2018-02-25
pjp
}
1103
2018-05-10
pjp
1104
2018-05-10
pjp
fprintf(of, "%s %d IN NSEC3 %d %d %d %s %s %s\n",
1105
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1106
2020-05-07
pjp
rrset->ttl,
1107
2019-02-15
pjp
((struct nsec3 *)rrp->rdata)->algorithm,
1108
2019-02-15
pjp
((struct nsec3 *)rrp->rdata)->flags,
1109
2019-02-15
pjp
((struct nsec3 *)rrp->rdata)->iterations,
1110
2019-02-15
pjp
(((struct nsec3 *)rrp->rdata)->saltlen == 0) ? "-" : bin2hex(((struct nsec3 *)rrp->rdata)->salt, ((struct nsec3 *)rrp->rdata)->saltlen),
1111
2019-02-15
pjp
base32hex_encode(((struct nsec3 *)rrp->rdata)->next, ((struct nsec3 *)rrp->rdata)->nextlen),
1112
2019-02-15
pjp
bitmap2human(((struct nsec3 *)rrp->rdata)->bitmap, ((struct nsec3 *)rrp->rdata)->bitmap_len));
1113
2018-02-25
pjp
1114
2018-05-10
pjp
}
1115
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_RRSIG)) != NULL) {
1116
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1117
2019-02-15
pjp
dolog(LOG_INFO, "no a RR in zone!\n");
1118
2018-05-10
pjp
return -1;
1119
2018-02-25
pjp
}
1120
2019-02-15
pjp
TAILQ_FOREACH(rrp2, &rrset->rr_head, entries) {
1121
2019-02-15
pjp
len = mybase64_encode(((struct rrsig *)rrp2->rdata)->signature, ((struct rrsig *)rrp2->rdata)->signature_len, buf, sizeof(buf));
1122
2018-02-25
pjp
buf[len] = '\0';
1123
2018-02-25
pjp
1124
2018-05-10
pjp
fprintf(of, "%s %d IN RRSIG (%s %d %d %d %llu %llu %d %s %s)\n",
1125
2019-02-15
pjp
convert_name(rbt->zone, rbt->zonelen),
1126
2020-05-07
pjp
rrset->ttl,
1127
2019-02-15
pjp
get_dns_type(((struct rrsig *)rrp2->rdata)->type_covered, 0),
1128
2019-02-15
pjp
((struct rrsig *)rrp2->rdata)->algorithm,
1129
2019-02-15
pjp
((struct rrsig *)rrp2->rdata)->labels,
1130
2019-02-15
pjp
((struct rrsig *)rrp2->rdata)->original_ttl,
1131
2019-02-15
pjp
timethuman(((struct rrsig *)rrp2->rdata)->signature_expiration),
1132
2019-02-15
pjp
timethuman(((struct rrsig *)rrp2->rdata)->signature_inception),
1133
2019-02-15
pjp
((struct rrsig *)rrp2->rdata)->key_tag,
1134
2019-02-15
pjp
convert_name(((struct rrsig *)rrp2->rdata)->signers_name, ((struct rrsig *)rrp2->rdata)->signame_len),
1135
2018-02-25
pjp
buf);
1136
2018-02-25
pjp
}
1137
2018-02-25
pjp
}
1138
2018-02-25
pjp
1139
2018-02-25
pjp
return 0;
1140
2018-02-25
pjp
}
1141
2018-02-25
pjp
1142
2019-02-15
pjp
1143
2018-02-25
pjp
int
1144
2018-05-10
pjp
bindfile(int argc, char *argv[])
1145
2018-02-25
pjp
{
1146
2018-05-10
pjp
ddDB *db;
1147
2018-05-10
pjp
char *zonefile;
1148
2018-05-10
pjp
char *zonename;
1149
2018-05-10
pjp
FILE *of = stdout;
1150
2018-05-11
pjp
int len;
1151
2019-11-14
pjp
uint32_t flags = PARSEFILE_FLAG_NOSOCKET;
1152
2018-02-25
pjp
1153
2018-05-10
pjp
if (argc != 3) {
1154
2018-05-10
pjp
usage(argc, argv);
1155
2018-02-25
pjp
exit(1);
1156
2018-02-25
pjp
}
1157
2018-02-25
pjp
1158
2018-05-10
pjp
zonename = argv[1];
1159
2018-05-10
pjp
zonefile = argv[2];
1160
2018-02-25
pjp
1161
2018-05-11
pjp
len = strlen(zonename);
1162
2018-05-11
pjp
if (zonename[len - 1] != '.') {
1163
2018-05-11
pjp
len += 2;
1164
2018-05-11
pjp
zonename = malloc(len);
1165
2018-05-11
pjp
if (zonename == NULL) {
1166
2018-05-11
pjp
perror("malloc");
1167
2018-05-11
pjp
return 1;
1168
2018-05-11
pjp
}
1169
2018-05-11
pjp
1170
2018-05-11
pjp
strlcpy(zonename, argv[1], len);
1171
2018-05-11
pjp
strlcat(zonename, ".", len);
1172
2018-05-11
pjp
}
1173
2018-05-11
pjp
1174
2018-05-11
pjp
1175
2018-02-25
pjp
#if __OpenBSD__
1176
2018-05-10
pjp
if (pledge("stdio rpath cpath", NULL) < 0) {
1177
2018-02-25
pjp
perror("pledge");
1178
2018-02-25
pjp
exit(1);
1179
2018-02-25
pjp
}
1180
2018-02-25
pjp
#endif
1181
2018-02-25
pjp
1182
2018-02-25
pjp
1183
2018-02-25
pjp
1184
2018-02-25
pjp
/* open the database(s) */
1185
2018-02-25
pjp
db = dddbopen();
1186
2018-02-25
pjp
if (db == NULL) {
1187
2018-02-25
pjp
dolog(LOG_INFO, "dddbopen() failed\n");
1188
2018-02-25
pjp
return 1;
1189
2018-02-25
pjp
}
1190
2018-02-25
pjp
1191
2018-02-25
pjp
/* now we start reading our configfile */
1192
2018-02-25
pjp
1193
2019-11-14
pjp
if (parse_file(db, zonefile, flags) < 0) {
1194
2018-02-25
pjp
dolog(LOG_INFO, "parsing config file failed\n");
1195
2018-02-25
pjp
return 1;
1196
2018-02-25
pjp
}
1197
2018-02-25
pjp
1198
2018-05-10
pjp
if (dump_db_bind(db, of, zonename) < 0) {
1199
2018-05-10
pjp
dddbclose(db);
1200
2018-05-10
pjp
return 1;
1201
2018-05-10
pjp
}
1202
2018-05-10
pjp
1203
2018-02-25
pjp
dddbclose(db);
1204
2018-02-25
pjp
1205
2018-02-25
pjp
1206
2018-02-25
pjp
return 0;
1207
2018-06-27
pjp
}
1208
2018-06-27
pjp
1209
2019-02-09
pjp
1210
2019-02-09
pjp
int
1211
2019-02-09
pjp
count_db(ddDB *db)
1212
2018-06-27
pjp
{
1213
2019-02-15
pjp
struct rbtree *rbt;
1214
2019-02-15
pjp
struct rrset *rrset = NULL;
1215
2019-02-15
pjp
struct rr *rrp = NULL;
1216
2019-02-09
pjp
struct node *n, *nx;
1217
2019-02-09
pjp
int count = 0;
1218
2019-02-09
pjp
int rs;
1219
2019-01-07
pjp
1220
2019-02-19
pjp
RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
1221
2019-02-09
pjp
rs = n->datalen;
1222
2019-02-15
pjp
if ((rbt = calloc(1, rs)) == NULL) {
1223
2019-02-09
pjp
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
1224
2019-02-09
pjp
exit(1);
1225
2019-02-09
pjp
}
1226
2018-06-27
pjp
1227
2018-06-27
pjp
1228
2019-02-15
pjp
memcpy((char *)rbt, (char *)n->data, n->datalen);
1229
2018-06-27
pjp
1230
2019-01-09
pjp
1231
2019-02-15
pjp
TAILQ_FOREACH(rrset, &rbt->rrset_head, entries) {
1232
2019-02-15
pjp
TAILQ_FOREACH(rrp, &rrset->rr_head, entries) {
1233
2019-02-15
pjp
count++;
1234
2019-02-09
pjp
}
1235
2019-02-09
pjp
}
1236
2019-01-07
pjp
}
1237
2018-06-27
pjp
1238
2019-02-09
pjp
printf("Records = %d , ", count);
1239
2018-06-27
pjp
1240
2019-02-09
pjp
return count;
1241
2018-02-25
pjp
}
repomaster@centroid.eu