summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-04-19 12:54:22 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-04-19 13:08:35 (GMT)
commitc7c75b0cca25ecacad0ba2dfe7c41db836a0b17a (patch) (side-by-side diff)
treebfdaf4003628135622ff7373d8b15cffedc77ff0
parent967317a3d5c0ced836d8b6217288cd04819ddc36 (diff)
downloadacmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.gz
acmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.bz2
Resolve CNAMES recursively
This complements b2e15909.
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xacmeman24
1 files changed, 21 insertions, 3 deletions
diff --git a/acmeman b/acmeman
index e6fee16..37ed4dd 100755
--- a/acmeman
+++ b/acmeman
@@ -1,4 +1,7 @@
-#!/usr/bin/perl
+#!/bin/sh
+#!-*-perl-*-
+eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
+ if 0; # not running under some shell
# Copyright (C) 2017, 2018 Sergey Poznyakoff <gray@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
@@ -893,7 +896,7 @@ sub resolve {
unless ($res) {
$res = new Net::DNS::Resolver();
}
- my $q = $res->query($host, 'A');
+ my $q = $res->query($host,'ANY');
unless ($q) {
if ($res->errorstring eq 'NXDOMAIN') {
debug(1, "$host: no such host");
@@ -905,7 +908,22 @@ sub resolve {
}
return ();
}
- return map { $_->rdatastr } grep { $_->type eq 'A' } $q->answer;
+ my %res;
+ my %cnames;
+ my @answer = $q->answer();
+ while (my $ans = shift @answer) {
+ if ($ans->type eq 'A') {
+ $res{$ans->rdatastr} = 1;
+ } elsif ($ans->type eq 'CNAME') {
+ unless ($cnames{$ans->owner}) { # Avoid eventual loops
+ $cnames{$ans->owner} = 1;
+ if (my $q = $res->query($ans->cname, 'A')) {
+ push @answer, ($q->answer());
+ }
+ }
+ }
+ }
+ keys %res;
}
sub myip {

Return to:

Send suggestions and report system problems to the System administrator.