From e3695042ebbb42b0528b378b9033df92b5ab7d17 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 5 Feb 2008 09:41:18 +0000 Subject: [PATCH] switch function get_server_address from shell to Net::DNS git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8744 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-client | 84 ++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 1f0ae9b9b..e483eb326 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -34,14 +34,7 @@ use GOSA::GosaSupportDaemon; use Digest::MD5 qw(md5_hex md5 md5_base64); use MIME::Base64; use XML::Simple; - - -#use Fcntl; -#use Sys::Syslog qw( :DEFAULT setlogsock); -#use File::Spec; -#use Cwd; - - +use Net::DNS; my $event_dir = "/usr/lib/gosa-si/client/events"; use lib "/usr/lib/gosa-si/client/events"; @@ -583,33 +576,62 @@ sub create_passwd { sub get_server_addresses { my $domain= shift; my @result; - my $dig_cmd= 'dig +nocomments srv _gosad._tcp.'.$domain; - - my $output= `$dig_cmd 2>&1`; - open (PIPE, "$dig_cmd 2>&1 |"); - while() { - chomp $_; - # If it's not a comment - if($_ =~ m/^[^;]/) { - my @matches= split /\s+/; - - # Push hostname with port - if($matches[3] eq 'SRV') { - push @result, $matches[7].':'.$matches[6]; - } elsif ($matches[3] eq 'A') { - my $i=0; - - # Substitute the hostname with the ip address of the matching A record - foreach my $host (@result) { - if ((split /\:/, $host)[0] eq $matches[0]) { - $result[$i]= $matches[4].':'.(split /\:/, $host)[1]; - } - $i++; + + my $error = 0; + my $res = Net::DNS::Resolver->new; + my $query = $res->send("_gosad._tcp.".$domain, "SRV"); + my @hits; + + if ($query) { + foreach my $rr ($query->answer) { + push(@hits, $rr->target.":".$rr->port); + } + } + else { + #warn "query failed: ", $res->errorstring, "\n"; + $error++; + } + + if( $error == 0 ) { + foreach my $hit (@hits) { + my ($hit_name, $hit_port) = split(/:/, $hit); + + my $address_query = $res->send($hit_name); + if( 1 == length($address_query->answer) ) { + foreach my $rr ($address_query->answer) { + push(@result, $rr->address.":".$hit_port); } } } } - close(PIPE); + +# my $dig_cmd= 'dig +nocomments srv _gosad._tcp.'.$domain; +# +# my $output= `$dig_cmd 2>&1`; +# open (PIPE, "$dig_cmd 2>&1 |"); +# while() { +# chomp $_; +# # If it's not a comment +# if($_ =~ m/^[^;]/) { +# my @matches= split /\s+/; +# +# # Push hostname with port +# if($matches[3] eq 'SRV') { +# push @result, $matches[7].':'.$matches[6]; +# } elsif ($matches[3] eq 'A') { +# my $i=0; +# +# # Substitute the hostname with the ip address of the matching A record +# foreach my $host (@result) { +# if ((split /\:/, $host)[0] eq $matches[0]) { +# $result[$i]= $matches[4].':'.(split /\:/, $host)[1]; +# } +# $i++; +# } +# } +# } +# } +# close(PIPE); return @result; } -- 2.30.2