1
0
mirror of https://frontier.innolan.net/rainlance/c-ares.git synced 2025-10-05 14:49:27 +00:00
Commit Graph

167 Commits

Author SHA1 Message Date
e514088f96 Ignore fopen errors to use default values
After 46bb820be3 `init_by_resolv_conf`
errors are no longer swallowed in `ares_init_options`. This has exposed
a previously unknown bug in `lookups` initialization code.

If there is no lookup configuration in `resolv.conf`,
`init_by_resolv_conf` will attempt to read it from other files available
on the system. However, some of these files may have restricted
permissions (like `600`), which will lead to `EACCESS` errno, which in
turn is handled like a fatal error by `init_by_resolv_conf`.

However, it sounds illogical that this error should be handled as a
fatal. There is a `init_by_defaults` call that overrides `lookups` with
default value, and certainly possible absence of lookup information is
the reason why this function exists in a first place!

I suggest handling any `fopen` errors as non-fatal ones, allowing to
pick up the `lookups` value from different config files, or to pick up
default value.
2016-02-11 08:38:02 +00:00
7972adc5d7 api: Add entrypoints to allow use of per-server ports
Add user-visible entrypoints ares_{get,set}_servers_ports(3), which
take struct ares_addr_port_node rather than struct ares_addr_node.
This structure includes a UDP and TCP port number; if this is set
to zero, the channel-wide port values are used as before.

Similarly, add a new ares_set_servers_ports_csv(3) entrypoint, which
is analogous to ares_set_servers(3) except it doesn't ignore any
specified port information; instead, any per-server specified port
is used as both the UDP and TCP port for that server.

The internal struct ares_addr is extended to hold the UDP/TCP ports,
stored in network order, with the convention that a value of zero
indicates that the channel-wide UDP/TCP port should be used.

For the internal implementation of ares_dup(3), shift to use the
_ports() version of the get/set functions, so port information is
transferred correctly to the new channel.

Update manpages, and add missing ares_set_servers_csv to the lists
while we're at it
2016-02-02 10:13:46 +00:00
06d0f72e54 api: Add ares_set_sortlist(3) entrypoint
Allow explicit configuration of the channel's sortlist, by
specifying a string in the same format as the equivalent
/etc/resolv.conf option.

This allows library users to perform the same configuration
that is available via /etc/resolv.conf, but without needing
to change that file.
2016-02-02 10:05:07 +00:00
f1bcfa1122 api: Allow injection of user-specified malloc/free functions
Add a new ares_library_init_mem() initialization function for the
library which allows the library user to specify their own malloc,
realloc & free equivalents for use library-wide.

Store these function pointers in library-wide global variables,
defaulting to libc's malloc(), realloc() and free().

Change all calls to malloc, realloc and free to use the function pointer
instead.  Also ensure that ares_strdup() is always available
(even if the local environment includes strdup(3)), and change the
library code to always use it.

Convert calls to calloc() to use ares_malloc() + memset
2016-02-02 10:05:07 +00:00
87ff25049c Mark unhittable lines
Add comments for the benefit of the lcov tool, marking
lines that cannot be hit.  Typically these are fall-back
protection arms that are already covered by earlier checks,
and so it's not worth taking out the unhittable code (in case
someone changes the code between the two places in future).
2016-02-02 10:05:07 +00:00
74ba881295 config_sortlist: free any existing sortlist on (re)alloc failure
If we get an allocation failure on 2nd or later entry in the sortlist, the
code would return ENOMEM but still leave the initial entries allocated.
Ensure that *sortlist is set to NULL whenever ENOMEM is returned.
2016-01-24 09:05:40 +00:00
970dea47b7 ares_dup: clear new channel on failure
If the attempt to transfer IPv6 servers from the old to the new channel
fails, the previous code would still return a channel to the user even though
an error return code was generated.  This makes it likely that users would
leak the channel, so explicitly clear the channel in this case.
2016-01-24 09:05:40 +00:00
46bb820be3 ares_init_options: don't lose init failure
If (say) init_by_options() fails, the subsequent call to 
init_by_defaults() was overwriting the return code with
success.  Still call init_by_defaults() regardless, but track
its return value separately
2016-01-24 09:05:40 +00:00
66f40230a0 Don't exit loop early leaving uninitialized entries
Update for commit affc63cba8.

The original patch from Gregor Jasny did not have the break
statement; I incorrectly added it to prevent continuing the loop.
However, the later entries in the array would then be left
uninitialized, causing problems for later cleanup.

So fix to match Gregor's original patch, with apologies.
2016-01-18 10:00:59 +00:00
affc63cba8 Use libresolv to initialize cares on iPhone targets
On iPhone targets like iOS, watchOS or tvOS the file
/etc/resolv.conf cannot be used to configure cares.

Instead the resolver library is queried for configuration
values.

CC: Yury Kirpichev <ykirpichev@yandex-team.ru>
2016-01-17 16:45:04 +00:00
52ecef76df Fixing slow DNS lookup issue
This patch is fixing the dns lookup issue due to dummy dns information
of a disconnected adapter(in my case is a bluetooth adapter). I changed
the dns lookup policy to try GetNetworkParams first because the
GetNetworkParams provides the most reliable dns information (lots of
checks were done by system). I also filter out inoperable adapter in
DNS_AdaptersAddresses in case GetNetworkParams fail.
2016-01-14 11:32:18 +00:00
453578354f Destroy options if ares_save_options fails
It's possible that, if ares_save_options failed, the opts structure
would contain some allocated memory. Calling ares_destroy_options in
this case is safe, because ares_save_options zeroes out the memory
initially.
2014-11-06 10:21:54 +01:00
a0b24beb95 Continue loop if space for hostname not large enough
When attempting to build a search domain from the local hostname
(used as a fallback when no other methods have given a search
domain), the code doubles the buffer size on each loop iteration.

However, the loop previously had a WHILE_FALSE terminator so the continue
statement exited the loop rather than going round again.
2014-11-06 10:14:08 +01:00
7df69c0f79 Don't override explicitly specified search domains
Only set search domains from /etc/resolv.conf if there isn't a value
already present in the channel.
2014-05-22 16:24:24 +02:00
cf7ad9758d ares_inet_pton/ntop: cleanup
Make sure that the symbols are always exported and present in c-ares.

Make the headers prefixed with 'ares'.

Removed the inet_ntop.h version as it no longer features any content.
2013-02-17 17:44:02 +01:00
9c03cc118c ares__generate_new_id: moved to ares_query.c
... and ares__rc4 is turned into a local static function.
2013-02-13 14:58:04 +01:00
0c677f578e setup_once.h: refactor inclusion of <unistd.h> and <sys/socket.h>
Inclusion of these two header files now done in setup_once.h
2012-12-14 18:36:59 +01:00
a1035276c1 Header inclusion clean-up
Remove header inclusions already done in setup_once.h
2012-12-14 18:25:56 +01:00
65ac7e706d get_DNS_AdaptersAddresses: fix IPv6 parsing
Use of the wrong define made the function not parse IPv6 addresses
properly.

Bug: http://c-ares.haxx.se/mail/c-ares-archive-2012-06/0028.shtml
Reported by: Saúl Ibarra Corretgé
2012-08-23 00:11:30 +02:00
90364defb0 Added new feature (rfc2671) 2012-08-17 00:54:47 +02:00
38b69b7269 Kill compiler warning 2012-06-14 21:19:48 +02:00
9bd38a4a6e Fix UDP and TCP port byte order in saved options.
The UDP and TCP port are stored in network byte order in the
ares_channeldata, but are passed in to ares_init_options() in host byte
order.  Thus we must return them from ares_save_options() in host byte
order too, or a duplicated channel will convert them again, leading to a
nonfunctional channel and a mysterious connection refused error from
ares_gethostbyname().  This breaks ares_dup(), thus the curl easy API
when c-ares is used by curl, and thus all the curl easy API's users.
2012-05-21 22:40:45 +02:00
7ce8fe781a ares_init.c: Further refactoring of Windows system's DNS fetching code 2012-04-21 14:17:44 +02:00
05346c25cb Android: small changes to dns property part.
Prefix prop vars; kill var; use DNS_PROP_NAME_PREFIX macro.
2012-04-20 20:42:41 +02:00
2c67ce6459 Add support for multiple DNS servers on Android.
Before, c-ares always used the first DNS server on Android, causing
network problems if this DNS server was not available.

Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
2012-04-19 19:16:27 +02:00
5e80852e4c Added some more ifdefs to silent compiler warnings. 2012-04-17 16:57:40 +02:00
4980cc99e2 ares_init.c: get_iphlpapi_dns_info() refactoring 2012-04-16 22:10:23 +02:00
8b79584e01 Kill some more compiler warnings. 2012-04-16 15:33:14 +02:00
27a478c7a3 Kill compiler warning about unused var. 2012-04-16 15:24:14 +02:00
58e62c5879 Fixed my last commit: wrong preprocessor directive. 2012-04-16 11:27:16 +02:00
995fa144d9 Check for __ANDROID__ in addition to ANDROID macro.
Posted to c-ares list by Wayne.
2012-04-16 10:19:07 +02:00
506d586276 port numbers: convert them to network order!
When the config options ARES_OPT_UDP_PORT or ARES_OPT_TCP_PORT are used,
make sure to convert them to network byte order!

Bug: http://c-ares.haxx.se/mail/c-ares-archive-2012-02/0004.shtml
2012-03-16 16:06:03 +01:00
1c26242c52 white space cleanup
- Keep code within 80 columns

- Removed funny spaces after open paren and before closing paren
2012-02-25 22:36:50 +01:00
73dc26a9fc get_iphlpapi_dns_info: fix buffer overrun
I experienced a buffer overrun exception in c-ares on Windows and
tracked it down to be an error in the calculation of the 'left' variable
in get_iphlpapi_dns_info().

I changed the variable type of 'left' to a _signed_ type because of the
subtraction arithmetic; not sure if a long is the best choice
2012-02-25 22:32:24 +01:00
4ab65461b6 ares_init.c: fix compiler warning on winsock builds 2012-01-19 20:20:56 +01:00
3d84eb3bbc ares_init.c: fix segfault triggered in ares_init_options() upon previous
failure of init_by_defaults() and incomplete cleanup there.
2011-09-07 00:30:53 +02:00
a831da792d fix MSVC compiler warning 'conditional expression is constant' 2011-09-04 17:23:39 +02:00
8e457f2c41 Fix incorrect sizeof() in ares_save_options 2011-06-14 16:41:29 +02:00
3cb1afe054 strlen: use size_t to receive the return 2011-06-04 20:14:38 +02:00
22a52102d6 ares_init: make ares_private.h last included header again 2011-05-26 17:32:43 +02:00
ef5390e6bb winsock: compilation fixes
Provide winsock iphlpapi alternative definitions to prevent compilation
failures when using a variety of winsock header implementations.
2011-05-20 16:43:25 +02:00
6518b56a5e IPv6-on-windows: find DNS servers correctly 2011-05-17 11:53:13 +02:00
5e5c0132e6 renamed getplatform() to ares__getplatform() to avoid namespace pollution 2011-03-25 17:57:02 +01:00
5b6a188909 build: move platform stuff to ares_platform.c and ares_platform.h 2011-03-24 11:31:50 +01:00
bd066ab8ef build: find out windows platform using GetVersionEx() 2011-03-23 20:53:28 +01:00
8c503ddf79 System's errno.h inclusion cleanup.
System's errno.h is conditionally included from setup_once.h
2011-03-22 14:02:23 +01:00
ef8e2ad601 ares_init: fix gethostname error detection on winsock platforms 2011-03-22 13:43:34 +01:00
9a11973403 Watt32: fix server init
Somewhere in the process, programs using the Watt-32 tcp/ip stack
stopped working.
2011-02-18 13:59:00 +01:00
e14f136aa3 config_sortlist: (win32) missing else
Without an else there, contents of "pat" that could have been
successfully set just above, may be clobbered by successive unsuccessful
calls to "xxx_pton" or "ip_addr".
2011-02-16 23:44:36 +01:00
bd6636c138 init_by_resolv_conf: fix compiler warnings
The code received the return codes in the 'status' variable without
using it. Instead we just ignore those particular errors.
2010-12-27 13:18:54 +01:00