--- mdap-server.pl 2007/04/23 17:41:34 16 +++ mdap-server.pl 2007/04/23 17:42:42 17 @@ -12,8 +12,25 @@ my $resend_search_delay = 3; my $tftp_path = '/srv/tftp/'; -my $user_id = 'Administrator'; -my $user_pwd = ''; +# tab-delimited list of user id/passwd to try on ants +my @try_accounts = ( "Administrator\t" ); + +my $passwd_path = $0; +$passwd_path =~ s/[^\/]+$/passwd/; + +if (-e $passwd_path) { + open(my $fh, $passwd_path) || die "can't open $passwd_path: $!"; + while(<$fh>) { + chomp; + next if /^#/ || /^$/ || /^\s+$/; + if (/^\S+\t\S+$/) { + push @try_accounts, $_; + } else { + warn "invalid $passwd_path entry: $_\n"; + } + } + print "found ", $#try_accounts, " accounts to try on password protected ants\n"; +} warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; @@ -71,6 +88,22 @@ } } +my $ant_passwd_try; + +sub ant_credentials { + my $ant = shift || die "no ant?"; + my $i = $ant_passwd_try->{$ant} || 0; + my ($user_id,$user_pwd) = split(/\t/, $try_accounts[$i]); + #warn "ant $ant as [$i] $user_id / $user_pwd\n"; + return ($user_id,$user_pwd); +} + +sub ant_another_passwd { + my $ant = shift || die "no ant?"; + $ant_passwd_try->{$ant}++; + $ant_passwd_try->{$ant} = 0 if ( $ant_passwd_try->{$ant} > $#try_accounts ); +} + local $SIG{ALRM} = sub { mdap_send("ANT-SEARCH MDAP/1.1\r\n"); alarm( $resend_search_delay ); @@ -97,17 +130,21 @@ warn dump($h),$/ if ($debug); - # we are getting our own INFO messages + # we are getting our own messages (since our source port + # is same as destination) next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); + my ($user_id,$user_pwd) = ant_credentials( $ant ); + if ($type eq 'REPLY-ANT-SEARCH') { mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); } elsif ($type eq 'REPLY-INFO') { if ($h->{'SEQ-NR'} < 0) { warn "!! password protected ant $ant, skipping\n"; + ant_another_passwd( $ant ); next; }