diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 15:54:22 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 16:08:35 +0300 |
commit | c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a (patch) | |
tree | bfdaf4003628135622ff7373d8b15cffedc77ff0 | |
parent | 967317a3d5c0ced836d8b6217288cd04819ddc36 (diff) | |
download | acmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.gz acmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.bz2 |
Resolve CNAMES recursively
This complements b2e15909.
-rwxr-xr-x | acmeman | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -1,4 +1,7 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/bin/sh |
2 | #!-*-perl-*- | ||
3 | eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' | ||
4 | if 0; # not running under some shell | ||
2 | # Copyright (C) 2017, 2018 Sergey Poznyakoff <gray@gnu.org> | 5 | # Copyright (C) 2017, 2018 Sergey Poznyakoff <gray@gnu.org> |
3 | # | 6 | # |
4 | # This program is free software; you can redistribute it and/or modify | 7 | # This program is free software; you can redistribute it and/or modify |
@@ -893,7 +896,7 @@ sub resolve { | |||
893 | unless ($res) { | 896 | unless ($res) { |
894 | $res = new Net::DNS::Resolver(); | 897 | $res = new Net::DNS::Resolver(); |
895 | } | 898 | } |
896 | my $q = $res->query($host, 'A'); | 899 | my $q = $res->query($host,'ANY'); |
897 | unless ($q) { | 900 | unless ($q) { |
898 | if ($res->errorstring eq 'NXDOMAIN') { | 901 | if ($res->errorstring eq 'NXDOMAIN') { |
899 | debug(1, "$host: no such host"); | 902 | debug(1, "$host: no such host"); |
@@ -905,7 +908,22 @@ sub resolve { | |||
905 | } | 908 | } |
906 | return (); | 909 | return (); |
907 | } | 910 | } |
908 | return map { $_->rdatastr } grep { $_->type eq 'A' } $q->answer; | 911 | my %res; |
912 | my %cnames; | ||
913 | my @answer = $q->answer(); | ||
914 | while (my $ans = shift @answer) { | ||
915 | if ($ans->type eq 'A') { | ||
916 | $res{$ans->rdatastr} = 1; | ||
917 | } elsif ($ans->type eq 'CNAME') { | ||
918 | unless ($cnames{$ans->owner}) { # Avoid eventual loops | ||
919 | $cnames{$ans->owner} = 1; | ||
920 | if (my $q = $res->query($ans->cname, 'A')) { | ||
921 | push @answer, ($q->answer()); | ||
922 | } | ||
923 | } | ||
924 | } | ||
925 | } | ||
926 | keys %res; | ||
909 | } | 927 | } |
910 | 928 | ||
911 | sub myip { | 929 | sub myip { |