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