︙ | | | ︙ | |
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
* RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how
* many. Since it's unspecified, we have to assume that it might happen, but we
* also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and
* immediately rejecting pointers to itself seems like a fair balance.
*/
#define MAX_ALLOWED_POINTERS 16
#define TIMEOUT 2
#define ATTEMPTS 3
#if defined(OF_HAIKU)
# define HOSTS_PATH @"/system/settings/network/hosts"
# define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf"
#elif defined(OF_MORPHOS)
# define HOSTS_PATH @"ENV:sys/net/hosts"
# define RESOLV_CONF_PATH @"ENV:sys/net/resolv.conf"
#elif defined(OF_AMIGAOS4)
|
<
<
<
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
* RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how
* many. Since it's unspecified, we have to assume that it might happen, but we
* also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and
* immediately rejecting pointers to itself seems like a fair balance.
*/
#define MAX_ALLOWED_POINTERS 16
#if defined(OF_HAIKU)
# define HOSTS_PATH @"/system/settings/network/hosts"
# define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf"
#elif defined(OF_MORPHOS)
# define HOSTS_PATH @"ENV:sys/net/hosts"
# define RESOLV_CONF_PATH @"ENV:sys/net/resolv.conf"
#elif defined(OF_AMIGAOS4)
|
︙ | | | ︙ | |
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
@public
OFString *_host, *_domainName;
of_dns_resource_record_class_t _recordClass;
of_dns_resource_record_type_t _recordType;
OFNumber *_ID;
OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
size_t _nameServersIndex, _searchDomainsIndex;
size_t _attempt;
id _target;
SEL _selector;
id _context;
OFData *_queryData;
OFTimer *_cancelTimer;
}
- (instancetype)initWithHost: (OFString *)host
domainName: (OFString *)domainName
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
target: (id)target
selector: (SEL)selector
context: (id)context;
@end
@interface OFDNSResolver ()
- (void)of_parseConfig;
#ifdef OF_HAVE_FILES
- (void)of_parseHosts: (OFString *)path;
# ifndef OF_WINDOWS
- (void)of_parseResolvConf: (OFString *)path;
- (void)of_parseResolvConfOption: (OFString *)option;
# endif
|
>
>
>
>
>
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
@public
OFString *_host, *_domainName;
of_dns_resource_record_class_t _recordClass;
of_dns_resource_record_type_t _recordType;
OFNumber *_ID;
OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains;
size_t _nameServersIndex, _searchDomainsIndex;
of_time_interval_t _timeout;
unsigned int _maxRetries;
size_t _attempt;
id _target;
SEL _selector;
id _context;
OFData *_queryData;
OFTimer *_cancelTimer;
}
- (instancetype)initWithHost: (OFString *)host
domainName: (OFString *)domainName
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
timeout: (of_time_interval_t)timeout
maxRetries: (unsigned int)maxRetries
target: (id)target
selector: (SEL)selector
context: (id)context;
@end
@interface OFDNSResolver ()
- (void)of_setDefaults;
- (void)of_parseConfig;
#ifdef OF_HAVE_FILES
- (void)of_parseHosts: (OFString *)path;
# ifndef OF_WINDOWS
- (void)of_parseResolvConf: (OFString *)path;
- (void)of_parseResolvConfOption: (OFString *)option;
# endif
|
︙ | | | ︙ | |
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
- (instancetype)initWithHost: (OFString *)host
domainName: (OFString *)domainName
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
target: (id)target
selector: (SEL)selector
context: (id)context
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
OFMutableData *queryData;
uint16_t tmp;
_host = [host copy];
_domainName = [domainName copy];
_recordClass = recordClass;
_recordType = recordType;
_ID = [ID retain];
_nameServers = [nameServers copy];
_searchDomains = [searchDomains copy];
_target = [target retain];
_selector = selector;
_context = [context retain];
queryData = [OFMutableData dataWithCapacity: 512];
/* Header */
|
>
>
>
>
|
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
- (instancetype)initWithHost: (OFString *)host
domainName: (OFString *)domainName
recordClass: (of_dns_resource_record_class_t)recordClass
recordType: (of_dns_resource_record_type_t)recordType
ID: (OFNumber *)ID
nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers
searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains
timeout: (of_time_interval_t)timeout
maxRetries: (unsigned int)maxRetries
target: (id)target
selector: (SEL)selector
context: (id)context
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
OFMutableData *queryData;
uint16_t tmp;
_host = [host copy];
_domainName = [domainName copy];
_recordClass = recordClass;
_recordType = recordType;
_ID = [ID retain];
_nameServers = [nameServers copy];
_searchDomains = [searchDomains copy];
_timeout = timeout;
_maxRetries = maxRetries;
_target = [target retain];
_selector = selector;
_context = [context retain];
queryData = [OFMutableData dataWithCapacity: 512];
/* Header */
|
︙ | | | ︙ | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
|
[super dealloc];
}
@end
@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval;
+ (instancetype)resolver
{
return [[[self alloc] init] autorelease];
}
|
>
|
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
[super dealloc];
}
@end
@implementation OFDNSResolver
@synthesize staticHosts = _staticHosts, nameServers = _nameServers;
@synthesize localDomain = _localDomain, searchDomains = _searchDomains;
@synthesize timeout = _timeout, maxRetries = _maxRetries;
@synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName;
@synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval;
+ (instancetype)resolver
{
return [[[self alloc] init] autorelease];
}
|
︙ | | | ︙ | |
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)of_parseConfig
{
void *pool = objc_autoreleasePoolPush();
#ifdef OF_WINDOWS
OFString *path;
#endif
_minNumberOfDotsInAbsoluteName = 1;
_usesTCP = false;
_configReloadInterval = 2;
#if defined(OF_WINDOWS)
# ifdef OF_HAVE_FILES
path = [[OFWindowsRegistryKey localMachineKey]
stringForValue: @"DataBasePath"
subKeyPath: @"SYSTEM\\CurrentControlSet\\Services\\"
@"Tcpip\\Parameters"];
path = [path stringByAppendingPathComponent: @"hosts"];
|
>
>
>
>
>
>
>
>
>
<
<
<
<
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)of_setDefaults
{
_timeout = 2;
_maxRetries = 3;
_minNumberOfDotsInAbsoluteName = 1;
_usesTCP = false;
_configReloadInterval = 2;
}
- (void)of_parseConfig
{
void *pool = objc_autoreleasePoolPush();
#ifdef OF_WINDOWS
OFString *path;
#endif
#if defined(OF_WINDOWS)
# ifdef OF_HAVE_FILES
path = [[OFWindowsRegistryKey localMachineKey]
stringForValue: @"DataBasePath"
subKeyPath: @"SYSTEM\\CurrentControlSet\\Services\\"
@"Tcpip\\Parameters"];
path = [path stringByAppendingPathComponent: @"hosts"];
|
︙ | | | ︙ | |
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
|
[_localDomain release];
_localDomain = nil;
[_searchDomains release];
_searchDomains = nil;
_minNumberOfDotsInAbsoluteName = 1;
_usesTCP = false;
_configReloadInterval = 2;
[_lastConfigReload release];
_lastConfigReload = nil;
[self of_parseConfig];
}
|
<
|
<
|
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
|
[_localDomain release];
_localDomain = nil;
[_searchDomains release];
_searchDomains = nil;
[self of_setDefaults];
[_lastConfigReload release];
_lastConfigReload = nil;
[self of_parseConfig];
}
|
︙ | | | ︙ | |
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
initWithHost: host
domainName: domainName
recordClass: recordClass
recordType: recordType
ID: ID
nameServers: _nameServers
searchDomains: _searchDomains
target: target
selector: selector
context: context] autorelease];
[_queries setObject: query
forKey: ID];
[self of_sendQuery: query];
objc_autoreleasePoolPop(pool);
}
- (void)of_sendQuery: (OFDNSResolverQuery *)query
{
of_socket_address_t address;
OFUDPSocket *sock;
[query->_cancelTimer invalidate];
[query->_cancelTimer release];
query->_cancelTimer = nil;
query->_cancelTimer = [[OFTimer
scheduledTimerWithTimeInterval: TIMEOUT
target: self
selector: @selector(of_queryWithIDTimedOut:)
object: query
repeats: false] retain];
address = of_socket_address_parse_ip(
[query->_nameServers objectAtIndex: query->_nameServersIndex], 53);
|
>
>
|
|
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
initWithHost: host
domainName: domainName
recordClass: recordClass
recordType: recordType
ID: ID
nameServers: _nameServers
searchDomains: _searchDomains
timeout: _timeout
maxRetries: _maxRetries
target: target
selector: selector
context: context] autorelease];
[_queries setObject: query
forKey: ID];
[self of_sendQuery: query];
objc_autoreleasePoolPop(pool);
}
- (void)of_sendQuery: (OFDNSResolverQuery *)query
{
of_socket_address_t address;
OFUDPSocket *sock;
[query->_cancelTimer invalidate];
[query->_cancelTimer release];
query->_cancelTimer = nil;
query->_cancelTimer = [[OFTimer
scheduledTimerWithTimeInterval: query->_timeout
target: self
selector: @selector(of_queryWithIDTimedOut:)
object: query
repeats: false] retain];
address = of_socket_address_parse_ip(
[query->_nameServers objectAtIndex: query->_nameServersIndex], 53);
|
︙ | | | ︙ | |
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
|
if (query->_nameServersIndex + 1 < [query->_nameServers count]) {
query->_nameServersIndex++;
[self of_sendQuery: query];
return;
}
if (query->_attempt < ATTEMPTS) {
query->_attempt++;
query->_nameServersIndex = 0;
[self of_sendQuery: query];
return;
}
query = [[query retain] autorelease];
|
|
|
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
|
if (query->_nameServersIndex + 1 < [query->_nameServers count]) {
query->_nameServersIndex++;
[self of_sendQuery: query];
return;
}
if (query->_attempt < query->_maxRetries) {
query->_attempt++;
query->_nameServersIndex = 0;
[self of_sendQuery: query];
return;
}
query = [[query retain] autorelease];
|
︙ | | | ︙ | |