home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / TKEY.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-04  |  4.7 KB  |  207 lines

  1. package Net::DNS::RR::TKEY;
  2. #
  3. # $Id: TKEY.pm,v 2.101 2004/01/04 04:31:11 ctriv Exp $
  4. #
  5. use strict;
  6. use vars qw(@ISA $VERSION);
  7.  
  8. use Net::DNS::Packet;
  9. use Digest::HMAC_MD5;
  10. use MIME::Base64;
  11.  
  12. @ISA     = qw(Net::DNS::RR);
  13. $VERSION = (qw$Revision: 2.101 $)[1];
  14.  
  15. sub new {
  16.     my ($class, $self, $data, $offset) = @_;
  17.  
  18.     # if we have some data then we are parsing an incoming TKEY packet
  19.     # see RFC2930 for the packet format
  20.     if ($self->{"rdlength"} > 0) {
  21.         ($self->{"algorithm"}, $offset) = Net::DNS::Packet::dn_expand($data, $offset);
  22.  
  23.         @{$self}{qw(inception expiration)} = unpack("\@$offset NN", $$data);
  24.         $offset += &Net::DNS::INT32SZ + &Net::DNS::INT32SZ;
  25.  
  26.         @{$self}{qw(inception expiration)} = unpack("\@$offset nn", $$data);
  27.         $offset += &Net::DNS::INT16SZ + &Net::DNS::INT16SZ;
  28.  
  29.         my ($key_len) = unpack("\@$offset n", $$data);
  30.         $offset += &Net::DNS::INT16SZ;
  31.         $self->{"key"} = substr($$data, $offset, $key_len);
  32.         $offset += $key_len;
  33.  
  34.         my ($other_len) = unpack("\@$offset n", $$data);
  35.         $offset += &Net::DNS::INT16SZ;
  36.         $self->{"other_data"} = substr($$data, $offset, $other_len);
  37.         $offset += $other_len;
  38.     }
  39.  
  40.     return bless $self, $class;
  41. }
  42.  
  43. sub new_from_string {
  44.     my ($class, $self, $string) = @_;
  45.  
  46.     if ($string && ($string =~ /^(.*)$/)) {
  47.         $self->{"key"}     = $1;
  48.     }
  49.  
  50.     $self->{"algorithm"}   = "gss.microsoft.com";
  51.     $self->{"inception"}   = time;
  52.     $self->{"expiration"}  = time + 24*60*60;
  53.     $self->{"mode"}        = 3; # GSSAPI
  54.     $self->{"error"}       = 0;
  55.     $self->{"other_len"}   = 0;
  56.     $self->{"other_data"}  = "";
  57.  
  58.     return bless $self, $class;
  59. }
  60.  
  61. sub error {
  62.     my $self = shift;
  63.  
  64.     my $rcode;
  65.     my $error = $self->{"error"};
  66.  
  67.     if (defined($error)) {
  68.         $rcode = $Net::DNS::rcodesbyval{$error} || $error;
  69.     }
  70.  
  71.     return $rcode;
  72. }
  73.  
  74. sub rdatastr {
  75.     my $self = shift;
  76.  
  77.     my $error = $self->error;
  78.     $error = "UNDEFINED" unless defined $error;
  79.  
  80.     my $rdatastr;
  81.  
  82.     if (exists $self->{"algorithm"}) {
  83.         $rdatastr = "$self->{algorithm}. $error";
  84.         if ($self->{"other_len"} && defined($self->{"other_data"})) {
  85.             $rdatastr .= " $self->{other_data}";
  86.         }
  87.     } else {
  88.         $rdatastr = '';
  89.     }
  90.  
  91.     return $rdatastr;
  92. }
  93.  
  94. sub rr_rdata {
  95.     my ($self, $packet, $offset) = @_;
  96.     my $rdata = "";
  97.  
  98.     $packet->{"compnames"} = {};
  99.     $rdata .= $packet->dn_comp($self->{"algorithm"}, 0);
  100.     $rdata .= pack("N", $self->{"inception"});
  101.     $rdata .= pack("N", $self->{"expiration"});
  102.     $rdata .= pack("n", $self->{"mode"});
  103.     $rdata .= pack("n", 0); # error
  104.     $rdata .= pack("n", length($self->{"key"}));
  105.     $rdata .= $self->{"key"};
  106.     $rdata .= pack("n", length($self->{"other_data"}));
  107.     $rdata .= $self->{"other_data"};
  108.  
  109.     return $rdata;
  110. }
  111.  
  112. 1;
  113. __END__
  114.  
  115. =head1 NAME
  116.  
  117. Net::DNS::RR::TKEY - DNS TKEY resource record
  118.  
  119. =head1 SYNOPSIS
  120.  
  121. C<use Net::DNS::RR>;
  122.  
  123. =head1 DESCRIPTION
  124.  
  125. Class for DNS TKEY resource records.
  126.  
  127. =head1 METHODS
  128.  
  129. =head2 algorithm
  130.  
  131.     $rr->algorithm($algorithm_name);
  132.     print "algorithm = ", $rr->algorithm, "\n";
  133.  
  134. Gets or sets the domain name that specifies the name of the algorithm.
  135. The default algorithm is gss.microsoft.com
  136.  
  137. =head2 inception
  138.  
  139.     $rr->inception(time);
  140.     print "inception = ", $rr->inception, "\n";
  141.  
  142. Gets or sets the inception time as the number of seconds since 1 Jan 1970
  143. 00:00:00 UTC.
  144.  
  145. The default inception time is the current time.
  146.  
  147. =head2 expiration
  148.  
  149.     $rr->expiration(time);
  150.     print "expiration = ", $rr->expiration, "\n";
  151.  
  152. Gets or sets the expiration time as the number of seconds since 1 Jan 1970
  153. 00:00:00 UTC.
  154.  
  155. The default expiration time is the current time plus 1 day.
  156.  
  157. =head2 mode
  158.  
  159.     $rr->mode(3);
  160.     print "mode = ", $rr->mode, "\n";
  161.  
  162. Sets the key mode (see rfc2930). The default is 3 which corresponds to GSSAPI
  163.  
  164. =head2 error
  165.  
  166.     print "error = ", $rr->error, "\n";
  167.  
  168. Returns the RCODE covering TKEY processing.  See RFC 2930 for details.
  169.  
  170. =head2 other_len
  171.  
  172.     print "other len = ", $rr->other_len, "\n";
  173.  
  174. Returns the length of the Other Data.  Should be zero.
  175.  
  176. =head2 other_data
  177.  
  178.     print "other data = ", $rr->other_data, "\n";
  179.  
  180. Returns the Other Data.  This field should be empty.
  181.  
  182. =head1 BUGS
  183.  
  184. This code has not been extensively tested.  Use with caution on
  185. production systems. See http://samba.org/ftp/samba/tsig-gss/ for an
  186. example usage.
  187.  
  188. =head1 COPYRIGHT
  189.  
  190. Copyright (c) 2000 Andrew Tridgell.  All rights reserved.  This program
  191. is free software; you can redistribute it and/or modify it under
  192. the same terms as Perl itself.
  193.  
  194. =head1 ACKNOWLEDGMENT
  195.  
  196. The Net::DNS::RR::TKEY module is based on the TSIG module by Michael
  197. Fuhr and Chris Turbeville.
  198.  
  199. =head1 SEE ALSO
  200.  
  201. L<perl(1)>, L<Net::DNS>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>,
  202. L<Net::DNS::Header>, L<Net::DNS::Question>, L<Net::DNS::RR>,
  203. RFC 2845
  204.  
  205. =cut
  206.  
  207.