1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* NAME
* getsoa - retrieve soa record of an NS zone.
*
* SYNOPSIS
* LD_PRELOAD=/path/to/libfakedns.so getsoa [-d] ZONE NS
*
* DESCRIPTION
* Queries NS for the SOA record of an NS zone and displays it as
* a series of space-delimited values. Used as a helper for the
* self-test mode in poundharness.pl.
*
* OPTIONS
* -d Enables adns debugging output.
*
* SEE ALSO
* fakedns.c
*
* LICENSE
* This library is part of pound testsuite.
* Copyright (C) 2024-2025 Sergey Poznyakoff
*
* Pound is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Pound is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pound. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <adns.h>
#include <assert.h>
#include <string.h>
char *progname;
static void
usage (FILE *fp)
{
fprintf (stderr, "%s ZONE NS\n", progname);
}
#define NSSTR "nameserver "
#define DEFAULT_QFLAGS \
(adns_qf_cname_loose | \
adns_qf_quoteok_query | \
adns_qf_quoteok_cname | \
adns_qf_quoteok_anshost)
/*
getsoa ZONE NS
*/
int
main (int argc, char **argv)
{
char *zone;
char *nameserver = NULL;
adns_state state;
adns_initflags flags = adns_if_none;
int rc, i;
char *config_text = NULL;
adns_answer *ans = NULL;
progname = argv[0];
while ((rc = getopt (argc, argv, "dh")) != EOF)
{
switch (rc)
{
case 'd':
flags |= adns_if_debug;
break;
case 'h':
usage (stdout);
return 0;
default:
return 1;
}
}
argc -= optind;
argv += optind;
switch (argc)
{
case 2:
nameserver = argv[1];
zone = argv[0];
break;
default:
fprintf (stderr, "%s: bad number of arguments\n", progname);
usage (stderr);
return 1;
}
config_text = malloc (sizeof (NSSTR) + 1 + strlen (nameserver));
assert (config_text != NULL);
strcat (strcpy (config_text, NSSTR), nameserver);
rc = adns_init_strcfg (&state, flags, stderr, config_text);
if (rc)
{
fprintf (stderr, "%s: can't initialize DNS state: %s",
progname, strerror (rc));
return 1;
}
rc = adns_synchronous (state, zone, adns_r_soa, DEFAULT_QFLAGS, &ans);
if (rc != adns_s_ok)
{
fprintf (stderr, "%s: %s\n", progname, adns_strerror (rc));
return 1;
}
for (i = 0; i < ans->nrrs; i++)
{
printf ("%s. %s. %ld %ld %ld %ld %ld\n",
ans->rrs.soa[i].mname,
ans->rrs.soa[i].rname,
ans->rrs.soa[i].serial,
ans->rrs.soa[i].refresh,
ans->rrs.soa[i].retry,
ans->rrs.soa[i].expire,
ans->rrs.soa[i].minimum);
}
free (ans);
return 0;
}
|