mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 13:29:14 +02:00
* Support the ndots and search resolve options
git-svn-id: trunk@44088 -
This commit is contained in:
parent
0af71da9cc
commit
2e17c67a61
@ -126,6 +126,7 @@ Type
|
|||||||
|
|
||||||
Var
|
Var
|
||||||
DNSServers : TDNSServerArray;
|
DNSServers : TDNSServerArray;
|
||||||
|
DNSOptions : String;
|
||||||
DefaultDomainList : String;
|
DefaultDomainList : String;
|
||||||
CheckResolveFileAge : Boolean;
|
CheckResolveFileAge : Boolean;
|
||||||
CheckHostsFileAge : Boolean;
|
CheckHostsFileAge : Boolean;
|
||||||
@ -176,6 +177,9 @@ uses
|
|||||||
BaseUnix,
|
BaseUnix,
|
||||||
sysutils;
|
sysutils;
|
||||||
|
|
||||||
|
var
|
||||||
|
DefaultDomainListArr : array of string;
|
||||||
|
NDots: Integer;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ from http://www.iana.org/assignments/dns-parameters }
|
{ from http://www.iana.org/assignments/dns-parameters }
|
||||||
@ -568,6 +572,8 @@ begin
|
|||||||
Result:=0;
|
Result:=0;
|
||||||
ResolveFileName:=Fn;
|
ResolveFileName:=Fn;
|
||||||
ResolveFileAge:=FileAge(FN);
|
ResolveFileAge:=FileAge(FN);
|
||||||
|
DefaultDomainListArr:=[];
|
||||||
|
NDots:=1;
|
||||||
{$push}{$i-}
|
{$push}{$i-}
|
||||||
Assign(R,FN);
|
Assign(R,FN);
|
||||||
Reset(R);
|
Reset(R);
|
||||||
@ -598,11 +604,16 @@ begin
|
|||||||
else if CheckDirective('domain') then
|
else if CheckDirective('domain') then
|
||||||
DefaultDomainList:=L
|
DefaultDomainList:=L
|
||||||
else if CheckDirective('search') then
|
else if CheckDirective('search') then
|
||||||
DefaultDomainList:=L;
|
DefaultDomainList:=L
|
||||||
|
else if CheckDirective('options') then
|
||||||
|
DNSOptions:=L;
|
||||||
end;
|
end;
|
||||||
Finally
|
Finally
|
||||||
Close(R);
|
Close(R);
|
||||||
end;
|
end;
|
||||||
|
L := GetEnvironmentVariable('LOCALDOMAIN');
|
||||||
|
if L <> '' then
|
||||||
|
DefaultDomainList := L;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure CheckResolveFile;
|
Procedure CheckResolveFile;
|
||||||
@ -1143,14 +1154,70 @@ begin
|
|||||||
(HostAddr.u6_addr16[5] = $FFFF);
|
(HostAddr.u6_addr16[5] = $FFFF);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function HandleAsFullyQualifiedName(const HostName: String) : Boolean;
|
||||||
|
var
|
||||||
|
I,J : Integer;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
J := 0;
|
||||||
|
for I := 1 to Length(HostName) do
|
||||||
|
if HostName[I] = '.' then
|
||||||
|
begin
|
||||||
|
Inc(J);
|
||||||
|
if J >= NDots then
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean;
|
Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
Address : Array[1..MaxResolveAddr] of THostAddr;
|
Address : Array[1..MaxResolveAddr] of THostAddr;
|
||||||
|
AbsoluteQueryFirst : Boolean;
|
||||||
L : Integer;
|
L : Integer;
|
||||||
|
K : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
L:=ResolveName(HostName,Address);
|
// Use domain or search-list to append to the searched hostname.
|
||||||
|
// When the amount of dots in hostname is higher or equal to ndots,
|
||||||
|
// do the query without adding any search-domain first.
|
||||||
|
// See the resolv.conf manual for more info.
|
||||||
|
if (DefaultDomainList<>'') then
|
||||||
|
begin
|
||||||
|
// Fill the cached DefaultDomainListArr and NDots
|
||||||
|
if (Length(DefaultDomainListArr) = 0) then
|
||||||
|
begin
|
||||||
|
DefaultDomainListArr := DefaultDomainList.Split(' ',Char(9));
|
||||||
|
L := Pos('ndots:', DNSOptions);
|
||||||
|
if L > 0 then
|
||||||
|
NDots := StrToIntDef(Trim(Copy(DNSOptions, L+6, 2)), 1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
AbsoluteQueryFirst := HandleAsFullyQualifiedName(HostName);
|
||||||
|
if AbsoluteQueryFirst then
|
||||||
|
L:=ResolveName(HostName,Address)
|
||||||
|
else
|
||||||
|
L := -1;
|
||||||
|
|
||||||
|
K := 0;
|
||||||
|
while (L < 1) and (K < Length(DefaultDomainListArr)) do
|
||||||
|
begin
|
||||||
|
L:=ResolveName(HostName + '.' + DefaultDomainListArr[K],Address);
|
||||||
|
Inc(K);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
AbsoluteQueryFirst := False;
|
||||||
|
L := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (L<1) and not AbsoluteQueryFirst then
|
||||||
|
L:=ResolveName(HostName,Address);
|
||||||
|
|
||||||
Result:=(L>0);
|
Result:=(L>0);
|
||||||
If Result then
|
If Result then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user