Folder structure reconstruction

This commit is contained in:
Fabian Stamm
2016-12-09 15:41:35 +01:00
parent df48102215
commit c4c32efb04
98 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1,45 @@
using System;
using System.Net;
namespace DnsClient.Protocol.Record
{
/*
3.4.1. A RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ADDRESS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
ADDRESS A 32 bit Internet address.
Hosts that have multiple Internet addresses will have multiple A
records.
*
*/
/// <summary>
/// A DNS resource record represending an IP address.
/// Hosts that have multiple Internet addresses will have multiple A records.
/// </summary>
public class ARecord : DnsResourceRecord
{
public IPAddress Address { get; }
public ARecord(ResourceRecordInfo info, IPAddress address) : base(info)
{
if (address == null)
{
throw new ArgumentNullException(nameof(address));
}
Address = address;
}
public override string RecordToString()
{
return Address.ToString();
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Net;
namespace DnsClient.Protocol.Record
{
/* https://tools.ietf.org/html/rfc3596#section-2.2
2.2 AAAA data format
A 128 bit IPv6 address is encoded in the data portion of an AAAA
resource record in network byte order (high-order byte first).
*/
/// <summary>
/// A 128 bit IPv6 address is encoded in the data portion of an AAAA
/// resource record in network byte order(high-order byte first).
/// </summary>
public class AAAARecord : DnsResourceRecord
{
public IPAddress Address { get; }
public AAAARecord(ResourceRecordInfo info, IPAddress address) : base(info)
{
if (address == null)
{
throw new ArgumentNullException(nameof(address));
}
Address = address;
}
public override string RecordToString()
{
return Address.ToString();
}
}
}

View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace DnsClient.Protocol.Record
{
/* RFC 6844 (https://tools.ietf.org/html/rfc6844#section-5.1)
A CAA RR contains a single property entry consisting of a tag-value
pair. Each tag represents a property of the CAA record. The value
of a CAA property is that specified in the corresponding value field.
A domain name MAY have multiple CAA RRs associated with it and a
given property MAY be specified more than once.
The CAA data field contains one property entry. A property entry
consists of the following data fields:
+0-1-2-3-4-5-6-7-|0-1-2-3-4-5-6-7-|
| Flags | Tag Length = n |
+----------------+----------------+...+---------------+
| Tag char 0 | Tag char 1 |...| Tag char n-1 |
+----------------+----------------+...+---------------+
+----------------+----------------+.....+----------------+
| Value byte 0 | Value byte 1 |.....| Value byte m-1 |
+----------------+----------------+.....+----------------+
Where n is the length specified in the Tag length field and m is the
remaining octets in the Value field (m = d - n - 2) where d is the
length of the RDATA section.
The data fields are defined as follows:
Flags: One octet containing the following fields:
Bit 0, Issuer Critical Flag: If the value is set to '1', the
critical flag is asserted and the property MUST be understood
if the CAA record is to be correctly processed by a certificate
issuer.
A Certification Authority MUST NOT issue certificates for any
Domain that contains a CAA critical property for an unknown or
unsupported property tag that for which the issuer critical
flag is set.
Note that according to the conventions set out in [RFC1035], bit 0
is the Most Significant Bit and bit 7 is the Least Significant
Bit. Thus, the Flags value 1 means that bit 7 is set while a value
of 128 means that bit 0 is set according to this convention.
All other bit positions are reserved for future use.
To ensure compatibility with future extensions to CAA, DNS records
compliant with this version of the CAA specification MUST clear
(set to "0") all reserved flags bits. Applications that interpret
CAA records MUST ignore the value of all reserved flag bits.
Tag Length: A single octet containing an unsigned integer specifying
the tag length in octets. The tag length MUST be at least 1 and
SHOULD be no more than 15.
Tag: The property identifier, a sequence of US-ASCII characters.
Tag values MAY contain US-ASCII characters 'a' through 'z', 'A'
through 'Z', and the numbers 0 through 9. Tag values SHOULD NOT
contain any other characters. Matching of tag values is case
insensitive.
Tag values submitted for registration by IANA MUST NOT contain any
characters other than the (lowercase) US-ASCII characters 'a'
through 'z' and the numbers 0 through 9.
Value: A sequence of octets representing the property value.
Property values are encoded as binary values and MAY employ sub-
formats.
The length of the value field is specified implicitly as the
remaining length of the enclosing Resource Record data field.
* */
/// <summary>
/// Record type 257
/// The Certification Authority Authorization (CAA) DNS Resource Record
/// allows a DNS domain name holder to specify one or more Certification
/// Authorities(CAs) authorized to issue certificates for that domain.
/// CAA Resource Records allow a public Certification Authority to
/// implement additional controls to reduce the risk of unintended
/// certificate mis-issue.This document defines the syntax of the CAA
/// record and rules for processing CAA records by certificate issuers.
/// </summary>
public class CaaRecord
{
}
}

View File

@ -0,0 +1,14 @@
namespace DnsClient.Protocol.Record
{
public class EmptyRecord : DnsResourceRecord
{
public EmptyRecord(ResourceRecordInfo info) : base(info)
{
}
public override string RecordToString()
{
return string.Empty;
}
}
}

View File

@ -0,0 +1,65 @@
using System;
namespace DnsClient.Protocol.Record
{
/*
3.3.9. MX RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ EXCHANGE /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PREFERENCE A 16 bit integer which specifies the preference given to
this RR among others at the same owner. Lower values
are preferred.
EXCHANGE A <domain-name> which specifies a host willing to act as
a mail exchange for the owner name.
MX records cause type A additional section processing for the host
specified by EXCHANGE. The use of MX RRs is explained in detail in
[RFC-974].
*/
/// <summary>
/// MX records cause type A additional section processing for the host
/// specified by EXCHANGE.The use of MX RRs is explained in detail in
/// [RFC-974].
/// </summary>
public class MxRecord : DnsResourceRecord
{
/// <summary>
/// Gets a 16 bit integer which specifies the preference given to
/// this RR among others at the same owner.
/// Lower values are preferred.
/// </summary>
public ushort Preference { get; }
/// <summary>
/// A <domain-name> which specifies a host willing to act as a mail exchange.
/// </summary>
public string Exchange { get; }
public MxRecord(ResourceRecordInfo info, ushort preference, string domainName)
: base(info)
{
if (string.IsNullOrWhiteSpace(domainName))
{
throw new ArgumentNullException(nameof(domainName));
}
Preference = preference;
Exchange = domainName;
}
public override string RecordToString()
{
return string.Format("{0} {1}", Preference, Exchange);
}
}
}

View File

@ -0,0 +1,51 @@
using System;
namespace DnsClient.Protocol.Record
{
/*
https://tools.ietf.org/html/rfc1035#section-3.3.11:
NS RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ NSDNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
NSDNAME A <domain-name> which specifies a host which should be
authoritative for the specified class and domain.
NS records cause both the usual additional section processing to locate
a type A record, and, when used in a referral, a special search of the
zone in which they reside for glue information.
The NS RR states that the named host should be expected to have a zone
starting at owner name of the specified class. Note that the class may
not indicate the protocol family which should be used to communicate
with the host, although it is typically a strong hint. For example,
hosts which are name servers for either Internet (IN) or Hesiod (HS)
class information are normally queried using IN class protocols.
*/
public class NsRecord : DnsResourceRecord
{
public string NSDName { get; }
internal NsRecord(ResourceRecordInfo info, string name)
: base(info)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name));
}
NSDName = name;
}
public override string RecordToString()
{
return NSDName;
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Linq;
namespace DnsClient.Protocol.Record
{
/* RFC 1035 (https://tools.ietf.org/html/rfc1035#section-3.3.12)
3.3.12. PTR RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ PTRDNAME /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
PTRDNAME A <domain-name> which points to some location in the
domain name space.
PTR records cause no additional section processing. These RRs are used
in special domains to point to some other location in the domain space.
These records are simple data, and don't imply any special processing
similar to that performed by CNAME, which identifies aliases. See the
description of the IN-ADDR.ARPA domain for an example.
*/
public class PtrRecord : DnsResourceRecord
{
public string PtrDomainName { get; }
internal PtrRecord(ResourceRecordInfo info, string ptrDName)
: base(info)
{
if (string.IsNullOrWhiteSpace(ptrDName))
{
throw new ArgumentNullException(nameof(ptrDName));
}
PtrDomainName = ptrDName;
}
public override string RecordToString()
{
return PtrDomainName;
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DnsClient.Protocol;
using DnsClient.Protocol.Record;
namespace DnsClient
{
public static class RecordCollectionExtension
{
public static IEnumerable<AAAARecord> AaaaRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<AAAARecord>();
}
public static IEnumerable<ARecord> ARecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<ARecord>();
}
public static IEnumerable<CaaRecord> CaaRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<CaaRecord>();
}
public static IEnumerable<NsRecord> NsRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<NsRecord>();
}
public static IEnumerable<DnsResourceRecord> OfRecordType(this IEnumerable<DnsResourceRecord> records, ResourceRecordType type)
{
return records.Where(p => p.RecordType == type);
}
public static IEnumerable<PtrRecord> PtrRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<PtrRecord>();
}
public static IEnumerable<SoaRecord> SoaRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<SoaRecord>();
}
public static IEnumerable<SrvRecord> SrvRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<SrvRecord>();
}
public static IEnumerable<TxtRecord> TxtRecords(this IEnumerable<DnsResourceRecord> records)
{
return records.OfType<TxtRecord>();
}
}
}

View File

@ -0,0 +1,111 @@
namespace DnsClient.Protocol.Record
{
/*
3.3.13. SOA RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ RNAME /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| SERIAL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| REFRESH |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RETRY |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| EXPIRE |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| MINIMUM |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MNAME The <domain-name> of the name server that was the
original or primary source of data for this zone.
RNAME A <domain-name> which specifies the mailbox of the
person responsible for this zone.
SERIAL The unsigned 32 bit version number of the original copy
of the zone. Zone transfers preserve this value. This
value wraps and should be compared using sequence space
arithmetic.
REFRESH A 32 bit time interval before the zone should be
refreshed.
RETRY A 32 bit time interval that should elapse before a
failed refresh should be retried.
EXPIRE A 32 bit time value that specifies the upper limit on
the time interval that can elapse before the zone is no
longer authoritative.
MINIMUM The unsigned 32 bit minimum TTL field that should be
exported with any RR from this zone.
SOA records cause no additional section processing.
All times are in units of seconds.
Most of these fields are pertinent only for name server maintenance
operations. However, MINIMUM is used in all query operations that
retrieve RRs from a zone. Whenever a RR is sent in a response to a
query, the TTL field is set to the maximum of the TTL field from the RR
and the MINIMUM field in the appropriate SOA. Thus MINIMUM is a lower
bound on the TTL field for all RRs in a zone. Note that this use of
MINIMUM should occur when the RRs are copied into the response and not
when the zone is loaded from a master file or via a zone transfer. The
reason for this provison is to allow future dynamic update facilities to
change the SOA RR with known semantics.
*/
public class SoaRecord : DnsResourceRecord
{
public uint Expire { get; }
public uint Minimum { get; }
public string MName { get; }
public uint Refresh { get; }
public uint Retry { get; }
public string RName { get; }
public uint Serial { get; }
public SoaRecord(ResourceRecordInfo info, string mName, string rName, uint serial, uint refresh, uint retry, uint expire, uint minimum)
: base(info)
{
MName = mName;
RName = rName;
Serial = serial;
Refresh = refresh;
Retry = retry;
Expire = expire;
Minimum = minimum;
}
public override string RecordToString()
{
return string.Format(
"{0} {1} {2} {3} {4} {5} {6}",
MName,
RName,
Serial,
Refresh,
Retry,
Expire,
Minimum);
}
}
}

View File

@ -0,0 +1,147 @@
namespace DnsClient.Protocol.Record
{
/* RFC 2782 (https://tools.ietf.org/html/rfc2782)
The format of the SRV RR
Here is the format of the SRV RR, whose DNS type code is 33:
_Service._Proto.Name TTL Class SRV Priority Weight Port Target
(There is an example near the end of this document.)
Service
The symbolic name of the desired service, as defined in Assigned
Numbers [STD 2] or locally. An underscore (_) is prepended to
the service identifier to avoid collisions with DNS labels that
occur in nature.
Some widely used services, notably POP, don't have a single
universal name. If Assigned Numbers names the service
indicated, that name is the only name which is legal for SRV
lookups. The Service is case insensitive.
Proto
The symbolic name of the desired protocol, with an underscore
(_) prepended to prevent collisions with DNS labels that occur
in nature. _TCP and _UDP are at present the most useful values
for this field, though any name defined by Assigned Numbers or
locally may be used (as for Service). The Proto is case
insensitive.
Name
The domain this RR refers to. The SRV RR is unique in that the
name one searches for is not this name; the example near the end
shows this clearly.
TTL
Standard DNS meaning [RFC 1035].
Class
Standard DNS meaning [RFC 1035]. SRV records occur in the IN
Class.
Priority
The priority of this target host. A client MUST attempt to
contact the target host with the lowest-numbered priority it can
reach; target hosts with the same priority SHOULD be tried in an
order defined by the weight field. The range is 0-65535. This
is a 16 bit unsigned integer in network byte order.
Weight
A server selection mechanism. The weight field specifies a
relative weight for entries with the same priority. Larger
weights SHOULD be given a proportionately higher probability of
being selected. The range of this number is 0-65535. This is a
16 bit unsigned integer in network byte order. Domain
administrators SHOULD use Weight 0 when there isn't any server
selection to do, to make the RR easier to read for humans (less
noisy). In the presence of records containing weights greater
than 0, records with weight 0 should have a very small chance of
being selected.
In the absence of a protocol whose specification calls for the
use of other weighting information, a client arranges the SRV
RRs of the same Priority in the order in which target hosts,
specified by the SRV RRs, will be contacted. The following
algorithm SHOULD be used to order the SRV RRs of the same
priority:
To select a target to be contacted next, arrange all SRV RRs
(that have not been ordered yet) in any order, except that all
those with weight 0 are placed at the beginning of the list.
Compute the sum of the weights of those RRs, and with each RR
associate the running sum in the selected order. Then choose a
uniform random number between 0 and the sum computed
(inclusive), and select the RR whose running sum value is the
first in the selected order which is greater than or equal to
the random number selected. The target host specified in the
selected SRV RR is the next one to be contacted by the client.
Remove this SRV RR from the set of the unordered SRV RRs and
apply the described algorithm to the unordered SRV RRs to select
the next target host. Continue the ordering process until there
are no unordered SRV RRs. This process is repeated for each
Priority.
Port
The port on this target host of this service. The range is 0-
65535. This is a 16 bit unsigned integer in network byte order.
This is often as specified in Assigned Numbers but need not be.
Target
The domain name of the target host. There MUST be one or more
address records for this name, the name MUST NOT be an alias (in
the sense of RFC 1034 or RFC 2181). Implementors are urged, but
not required, to return the address record(s) in the Additional
Data section. Unless and until permitted by future standards
action, name compression is not to be used for this field.
A Target of "." means that the service is decidedly not
available at this domain.
*/
/// <summary>
/// The SRV RR allows administrators to use several servers for a single
/// domain, to move services from host to host with little fuss, and to
/// designate some hosts as primary servers for a service and others as
/// backups.
///
/// Clients ask for a specific service/protocol for a specific domain
/// (the word domain is used here in the strict RFC 1034 sense), and get
/// back the names of any available servers.
///
/// Note that where this document refers to "address records", it means A
/// RR's, AAAA RR's, or their most modern equivalent.
/// </summary>
public class SrvRecord : DnsResourceRecord
{
public ushort Port { get; }
public ushort Priority { get; }
public string Target { get; }
public ushort Weight { get; }
public SrvRecord(ResourceRecordInfo info, ushort priority, ushort weigth, ushort port, string target)
: base(info)
{
Priority = priority;
Weight = weigth;
Port = port;
Target = target;
}
public override string RecordToString()
{
return string.Format(
"{0} {1} {2} {3}",
Priority,
Weight,
Port,
Target);
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
namespace DnsClient.Protocol.Record
{
/*
* RFC 1464 https://tools.ietf.org/html/rfc1464
https://tools.ietf.org/html/rfc1035#section-3.3:
<character-string> is a single
length octet followed by that number of characters. <character-string>
is treated as binary information, and can be up to 256 characters in
length (including the length octet).
https://tools.ietf.org/html/rfc1035#section-3.3.14:
TXT RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ TXT-DATA /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
TXT-DATA One or more <character-string>s.
TXT RRs are used to hold descriptive text. The semantics of the text
depends on the domain where it is found.
*/
/// <summary>
/// TXT RRs are used to hold descriptive text. The semantics of the text
/// depends on the domain where it is found.
/// </summary>
public class TxtRecord : DnsResourceRecord
{
/// <summary>
/// The list of TXT values of this TXT RR.
/// </summary>
public IReadOnlyCollection<string> Text { get; }
public TxtRecord(ResourceRecordInfo info, string[] values)
: base(info)
{
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
Text = values;
}
public override string RecordToString()
{
return string.Join(" ", Text).Trim();
}
}
}