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