visaljs 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +962 -68
  4. package/node/include/js_node.h +11 -1
  5. package/node/prelude/_http_common.js +29 -0
  6. package/node/prelude/async_hooks.js +50 -11
  7. package/node/prelude/child_process.js +31 -4
  8. package/node/prelude/console.js +311 -143
  9. package/node/prelude/crypto.js +6 -4
  10. package/node/prelude/dgram.js +1169 -0
  11. package/node/prelude/diagnostics_channel.js +3 -1
  12. package/node/prelude/dns.js +250 -45
  13. package/node/prelude/dns_promises.js +8 -2
  14. package/node/prelude/fs_promises.js +9 -1
  15. package/node/prelude/http.js +395 -86
  16. package/node/prelude/https.js +13 -4
  17. package/node/prelude/internal/console_class.js +7 -0
  18. package/node/prelude/internal/console_global.js +25 -0
  19. package/node/prelude/internal/crypto/key_encryption.js +217 -0
  20. package/node/prelude/internal/crypto/keys.js +161 -26
  21. package/node/prelude/internal/crypto/random.js +24 -0
  22. package/node/prelude/internal/crypto/util.js +2 -1
  23. package/node/prelude/internal/crypto_x509.js +161 -0
  24. package/node/prelude/internal/dns_classes.js +6 -0
  25. package/node/prelude/internal/dns_resolver.js +371 -0
  26. package/node/prelude/internal/errors.js +9 -0
  27. package/node/prelude/internal/events_on.js +82 -37
  28. package/node/prelude/internal/features.js +8 -4
  29. package/node/prelude/internal/fs_filehandle.js +10 -4
  30. package/node/prelude/internal/perf_histogram.js +1 -1
  31. package/node/prelude/internal/process_more.js +32 -17
  32. package/node/prelude/internal/process_signals.js +8 -2
  33. package/node/prelude/internal/punycode.ts +163 -0
  34. package/node/prelude/internal/readline.js +648 -274
  35. package/node/prelude/internal/readline_editor.js +1240 -0
  36. package/node/prelude/internal/string_width.js +43 -0
  37. package/node/prelude/internal/tls/common.js +145 -33
  38. package/node/prelude/internal/tls/wrap.js +182 -49
  39. package/node/prelude/internal/tls/x509.js +4 -1
  40. package/node/prelude/internal/udp.js +177 -0
  41. package/node/prelude/net.js +13 -1
  42. package/node/prelude/os.js +24 -6
  43. package/node/prelude/perf_hooks.js +37 -2
  44. package/node/prelude/punycode.js +2 -130
  45. package/node/prelude/readline.js +113 -4
  46. package/node/prelude/readline_promises.js +56 -32
  47. package/node/prelude/tls.js +21 -4
  48. package/node/prelude/util.js +3 -16
  49. package/node/src/host_dns.c +623 -0
  50. package/node/src/host_http.c +12 -0
  51. package/node/src/host_net.c +46 -0
  52. package/node/src/host_os.c +1 -6
  53. package/node/src/host_sys.c +70 -0
  54. package/node/src/host_udp.c +418 -0
  55. package/node/third_party/c-ares/LICENSE.md +24 -0
  56. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  57. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  60. package/node/third_party/c-ares/include/ares.h +1237 -0
  61. package/node/third_party/c-ares/include/ares_build.h +202 -0
  62. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  63. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  64. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  65. package/node/third_party/c-ares/include/ares_version.h +47 -0
  66. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  68. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  70. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  71. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  72. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  74. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  75. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  77. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  78. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  80. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  81. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  82. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  84. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  86. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  87. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  88. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  89. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  90. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  91. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  92. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  93. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  94. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  95. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  96. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  97. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  98. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  99. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  100. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  101. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  102. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  103. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  105. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  106. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  107. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  111. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  112. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  113. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  114. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  115. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  116. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  128. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  138. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  149. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  150. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  151. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  167. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  175. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  179. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  180. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  192. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  193. package/package.json +1 -1
  194. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  195. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  197. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  201. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  202. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  203. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  204. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  205. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  206. package/runtime/include/js_builtins.h +5 -0
  207. package/runtime/include/js_crypto.h +11 -0
  208. package/runtime/include/js_gc.h +13 -10
  209. package/runtime/include/js_jobs.h +2 -0
  210. package/runtime/include/js_object.h +58 -0
  211. package/runtime/include/jscontext.h +1 -0
  212. package/runtime/src/crypto_internal.h +1 -0
  213. package/runtime/src/crypto_subtle.c +66 -7
  214. package/runtime/src/crypto_tls.c +265 -19
  215. package/runtime/src/gc.c +73 -92
  216. package/runtime/src/inspect.c +18 -1
  217. package/runtime/src/jobs.c +37 -22
  218. package/runtime/src/object.c +49 -2
  219. package/runtime/src/os.c +16 -6
  220. package/runtime/src/os.h +2 -0
  221. package/runtime/src/process.c +97 -10
@@ -0,0 +1,851 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 Massachusetts Institute of Technology
4
+ * Copyright (c) 2007 Daniel Stenberg
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice (including the next
14
+ * paragraph) shall be included in all copies or substantial portions of the
15
+ * Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ *
25
+ * SPDX-License-Identifier: MIT
26
+ */
27
+
28
+ #include "ares_private.h"
29
+
30
+ #include <limits.h>
31
+
32
+ #ifdef HAVE_SYS_PARAM_H
33
+ # include <sys/param.h>
34
+ #endif
35
+
36
+ #ifdef HAVE_NETINET_IN_H
37
+ # include <netinet/in.h>
38
+ #endif
39
+
40
+ #ifdef HAVE_NETDB_H
41
+ # include <netdb.h>
42
+ #endif
43
+
44
+ #ifdef HAVE_ARPA_INET_H
45
+ # include <arpa/inet.h>
46
+ #endif
47
+
48
+ #if defined(ANDROID) || defined(__ANDROID__)
49
+ # include <sys/system_properties.h>
50
+ # include "ares_android.h"
51
+ /* From the Bionic sources */
52
+ # define DNS_PROP_NAME_PREFIX "net.dns"
53
+ # define MAX_DNS_PROPERTIES 8
54
+ #endif
55
+
56
+ #if defined(CARES_USE_LIBRESOLV)
57
+ # include <resolv.h>
58
+ #endif
59
+
60
+ #if defined(USE_WINSOCK) && defined(HAVE_IPHLPAPI_H)
61
+ # include <iphlpapi.h>
62
+ #endif
63
+
64
+ #include "ares_inet_net_pton.h"
65
+
66
+ static unsigned char ip_natural_mask(const struct ares_addr *addr)
67
+ {
68
+ const unsigned char *ptr = NULL;
69
+ /* This is an odd one. If a raw ipv4 address is specified, then we take
70
+ * what is called a natural mask, which means we look at the first octet
71
+ * of the ip address and for values 0-127 we assume it is a class A (/8),
72
+ * for values 128-191 we assume it is a class B (/16), and for 192-223
73
+ * we assume it is a class C (/24). 223-239 is Class D which and 240-255 is
74
+ * Class E, however, there is no pre-defined mask for this, so we'll use
75
+ * /24 as well as that's what the old code did.
76
+ *
77
+ * For IPv6, we'll use /64.
78
+ */
79
+
80
+ if (addr->family == AF_INET6) {
81
+ return 64;
82
+ }
83
+
84
+ ptr = (const unsigned char *)&addr->addr.addr4;
85
+ if (*ptr < 128) {
86
+ return 8;
87
+ }
88
+
89
+ if (*ptr < 192) {
90
+ return 16;
91
+ }
92
+
93
+ return 24;
94
+ }
95
+
96
+ static ares_bool_t sortlist_append(struct apattern **sortlist, size_t *nsort,
97
+ const struct apattern *pat)
98
+ {
99
+ struct apattern *newsort;
100
+
101
+ newsort = ares_realloc(*sortlist, (*nsort + 1) * sizeof(*newsort));
102
+ if (newsort == NULL) {
103
+ return ARES_FALSE; /* LCOV_EXCL_LINE: OutOfMemory */
104
+ }
105
+
106
+ *sortlist = newsort;
107
+
108
+ memcpy(&(*sortlist)[*nsort], pat, sizeof(**sortlist));
109
+ (*nsort)++;
110
+
111
+ return ARES_TRUE;
112
+ }
113
+
114
+ static ares_status_t parse_sort(ares_buf_t *buf, struct apattern *pat)
115
+ {
116
+ ares_status_t status;
117
+ const unsigned char ip_charset[] = "ABCDEFabcdef0123456789.:";
118
+ char ipaddr[INET6_ADDRSTRLEN] = "";
119
+ size_t addrlen;
120
+
121
+ memset(pat, 0, sizeof(*pat));
122
+
123
+ /* Consume any leading whitespace */
124
+ ares_buf_consume_whitespace(buf, ARES_TRUE);
125
+
126
+ /* If no length, just ignore, return ENOTFOUND as an indicator */
127
+ if (ares_buf_len(buf) == 0) {
128
+ return ARES_ENOTFOUND;
129
+ }
130
+
131
+ ares_buf_tag(buf);
132
+
133
+ /* Consume ip address */
134
+ if (ares_buf_consume_charset(buf, ip_charset, sizeof(ip_charset) - 1) == 0) {
135
+ return ARES_EBADSTR;
136
+ }
137
+
138
+ /* Fetch ip address */
139
+ status = ares_buf_tag_fetch_string(buf, ipaddr, sizeof(ipaddr));
140
+ if (status != ARES_SUCCESS) {
141
+ return status;
142
+ }
143
+
144
+ /* Parse it to make sure its valid */
145
+ pat->addr.family = AF_UNSPEC;
146
+ if (ares_dns_pton(ipaddr, &pat->addr, &addrlen) == NULL) {
147
+ return ARES_EBADSTR;
148
+ }
149
+
150
+ /* See if there is a subnet mask */
151
+ if (ares_buf_begins_with(buf, (const unsigned char *)"/", 1)) {
152
+ char maskstr[16];
153
+ const unsigned char ipv4_charset[] = "0123456789.";
154
+
155
+
156
+ /* Consume / */
157
+ ares_buf_consume(buf, 1);
158
+
159
+ ares_buf_tag(buf);
160
+
161
+ /* Consume mask */
162
+ if (ares_buf_consume_charset(buf, ipv4_charset, sizeof(ipv4_charset) - 1) ==
163
+ 0) {
164
+ return ARES_EBADSTR;
165
+ }
166
+
167
+ /* Fetch mask */
168
+ status = ares_buf_tag_fetch_string(buf, maskstr, sizeof(maskstr));
169
+ if (status != ARES_SUCCESS) {
170
+ return status;
171
+ }
172
+
173
+ if (ares_str_isnum(maskstr)) {
174
+ /* Numeric mask */
175
+ unsigned int mask;
176
+ if (!ares_str_parse_uint(maskstr, 128, &mask)) {
177
+ return ARES_EBADSTR;
178
+ }
179
+ if (pat->addr.family == AF_INET && mask > 32) {
180
+ return ARES_EBADSTR;
181
+ }
182
+ pat->mask = (unsigned char)mask;
183
+ } else {
184
+ /* Ipv4 subnet style mask */
185
+ struct ares_addr maskaddr;
186
+ const unsigned char *ptr;
187
+
188
+ memset(&maskaddr, 0, sizeof(maskaddr));
189
+ maskaddr.family = AF_INET;
190
+ if (ares_dns_pton(maskstr, &maskaddr, &addrlen) == NULL) {
191
+ return ARES_EBADSTR;
192
+ }
193
+ ptr = (const unsigned char *)&maskaddr.addr.addr4;
194
+ pat->mask = (unsigned char)(ares_count_bits_u8(ptr[0]) +
195
+ ares_count_bits_u8(ptr[1]) +
196
+ ares_count_bits_u8(ptr[2]) +
197
+ ares_count_bits_u8(ptr[3]));
198
+ }
199
+ } else {
200
+ pat->mask = ip_natural_mask(&pat->addr);
201
+ }
202
+
203
+ /* Consume any trailing whitespace */
204
+ ares_buf_consume_whitespace(buf, ARES_TRUE);
205
+
206
+ /* If we have any trailing bytes other than whitespace, its a parse failure */
207
+ if (ares_buf_len(buf) != 0) {
208
+ return ARES_EBADSTR;
209
+ }
210
+
211
+ return ARES_SUCCESS;
212
+ }
213
+
214
+ ares_status_t ares_parse_sortlist(struct apattern **sortlist, size_t *nsort,
215
+ const char *str)
216
+ {
217
+ ares_buf_t *buf = NULL;
218
+ ares_status_t status = ARES_SUCCESS;
219
+ ares_array_t *arr = NULL;
220
+ size_t num = 0;
221
+ size_t i;
222
+
223
+ if (sortlist == NULL || nsort == NULL || str == NULL) {
224
+ return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
225
+ }
226
+
227
+ if (*sortlist != NULL) {
228
+ ares_free(*sortlist);
229
+ }
230
+
231
+ *sortlist = NULL;
232
+ *nsort = 0;
233
+
234
+ buf = ares_buf_create_const((const unsigned char *)str, ares_strlen(str));
235
+ if (buf == NULL) {
236
+ status = ARES_ENOMEM;
237
+ goto done;
238
+ }
239
+
240
+ /* Split on space or semicolon */
241
+ status = ares_buf_split(buf, (const unsigned char *)" ;", 2,
242
+ ARES_BUF_SPLIT_NONE, 0, &arr);
243
+ if (status != ARES_SUCCESS) {
244
+ goto done;
245
+ }
246
+
247
+ num = ares_array_len(arr);
248
+ for (i = 0; i < num; i++) {
249
+ ares_buf_t **bufptr = ares_array_at(arr, i);
250
+ ares_buf_t *entry = *bufptr;
251
+
252
+ struct apattern pat;
253
+
254
+ status = parse_sort(entry, &pat);
255
+ if (status != ARES_SUCCESS && status != ARES_ENOTFOUND) {
256
+ goto done;
257
+ }
258
+
259
+ if (status != ARES_SUCCESS) {
260
+ continue;
261
+ }
262
+
263
+ if (!sortlist_append(sortlist, nsort, &pat)) {
264
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
265
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
266
+ }
267
+ }
268
+
269
+ status = ARES_SUCCESS;
270
+
271
+ done:
272
+ ares_buf_destroy(buf);
273
+ ares_array_destroy(arr);
274
+
275
+ if (status != ARES_SUCCESS) {
276
+ ares_free(*sortlist);
277
+ *sortlist = NULL;
278
+ *nsort = 0;
279
+ }
280
+
281
+ return status;
282
+ }
283
+
284
+ static ares_status_t config_search(ares_sysconfig_t *sysconfig, const char *str,
285
+ size_t max_domains)
286
+ {
287
+ if (sysconfig->domains && sysconfig->ndomains > 0) {
288
+ /* if we already have some domains present, free them first */
289
+ ares_strsplit_free(sysconfig->domains, sysconfig->ndomains);
290
+ sysconfig->domains = NULL;
291
+ sysconfig->ndomains = 0;
292
+ }
293
+
294
+ sysconfig->domains = ares_strsplit(str, ", ", &sysconfig->ndomains);
295
+ if (sysconfig->domains == NULL) {
296
+ return ARES_ENOMEM;
297
+ }
298
+
299
+ /* Truncate if necessary */
300
+ if (max_domains && sysconfig->ndomains > max_domains) {
301
+ size_t i;
302
+ for (i = max_domains; i < sysconfig->ndomains; i++) {
303
+ ares_free(sysconfig->domains[i]);
304
+ sysconfig->domains[i] = NULL;
305
+ }
306
+ sysconfig->ndomains = max_domains;
307
+ }
308
+
309
+ return ARES_SUCCESS;
310
+ }
311
+
312
+ static ares_status_t buf_fetch_string(ares_buf_t *buf, char *str,
313
+ size_t str_len)
314
+ {
315
+ ares_status_t status;
316
+ ares_buf_tag(buf);
317
+ ares_buf_consume(buf, ares_buf_len(buf));
318
+
319
+ status = ares_buf_tag_fetch_string(buf, str, str_len);
320
+ return status;
321
+ }
322
+
323
+ static ares_status_t config_lookup(ares_sysconfig_t *sysconfig, ares_buf_t *buf,
324
+ const char *separators)
325
+ {
326
+ ares_status_t status;
327
+ char lookupstr[32];
328
+ size_t lookupstr_cnt = 0;
329
+ char **lookups = NULL;
330
+ size_t num = 0;
331
+ size_t i;
332
+ size_t separators_len = ares_strlen(separators);
333
+
334
+ status =
335
+ ares_buf_split_str(buf, (const unsigned char *)separators, separators_len,
336
+ ARES_BUF_SPLIT_TRIM, 0, &lookups, &num);
337
+ if (status != ARES_SUCCESS) {
338
+ goto done;
339
+ }
340
+
341
+ for (i = 0; i < num; i++) {
342
+ const char *value = lookups[i];
343
+ char ch;
344
+
345
+ /* AIX /etc/netsvc.conf uses address-family-suffixed tokens such as
346
+ * "bind4"/"bind6" and "local4"/"local6" in addition to the bare forms. */
347
+ if (ares_strcaseeq(value, "dns") || ares_strcaseeq(value, "bind") ||
348
+ ares_strcaseeq(value, "bind4") || ares_strcaseeq(value, "bind6") ||
349
+ ares_strcaseeq(value, "resolv") || ares_strcaseeq(value, "resolve")) {
350
+ ch = 'b';
351
+ } else if (ares_strcaseeq(value, "files") ||
352
+ ares_strcaseeq(value, "file") ||
353
+ ares_strcaseeq(value, "local") ||
354
+ ares_strcaseeq(value, "local4") ||
355
+ ares_strcaseeq(value, "local6")) {
356
+ ch = 'f';
357
+ } else {
358
+ continue;
359
+ }
360
+
361
+ /* Look for a duplicate and ignore */
362
+ if (memchr(lookupstr, ch, lookupstr_cnt) == NULL) {
363
+ lookupstr[lookupstr_cnt++] = ch;
364
+ }
365
+ }
366
+
367
+ if (lookupstr_cnt) {
368
+ lookupstr[lookupstr_cnt] = 0;
369
+ ares_free(sysconfig->lookups);
370
+ sysconfig->lookups = ares_strdup(lookupstr);
371
+ if (sysconfig->lookups == NULL) {
372
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
373
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
374
+ }
375
+ }
376
+
377
+ status = ARES_SUCCESS;
378
+
379
+ done:
380
+ if (status != ARES_ENOMEM) {
381
+ status = ARES_SUCCESS;
382
+ }
383
+ ares_free_array(lookups, num, ares_free);
384
+ return status;
385
+ }
386
+
387
+ static ares_status_t process_option(ares_sysconfig_t *sysconfig,
388
+ ares_buf_t *option)
389
+ {
390
+ char **kv = NULL;
391
+ size_t num = 0;
392
+ const char *key;
393
+ const char *val;
394
+ unsigned int valint = 0;
395
+ ares_status_t status;
396
+
397
+ /* Split on : */
398
+ status = ares_buf_split_str(option, (const unsigned char *)":", 1,
399
+ ARES_BUF_SPLIT_TRIM, 2, &kv, &num);
400
+ if (status != ARES_SUCCESS) {
401
+ goto done;
402
+ }
403
+
404
+ if (num < 1) {
405
+ status = ARES_EBADSTR;
406
+ goto done;
407
+ }
408
+
409
+ key = kv[0];
410
+ if (num == 2) {
411
+ val = kv[1];
412
+ if (!ares_str_parse_uint(val, UINT_MAX, &valint)) {
413
+ status = ARES_EBADSTR;
414
+ goto done;
415
+ }
416
+ }
417
+
418
+ if (ares_streq(key, "ndots")) {
419
+ sysconfig->ndots = valint;
420
+ } else if (ares_streq(key, "retrans") || ares_streq(key, "timeout")) {
421
+ if (valint == 0) {
422
+ status = ARES_EFORMERR;
423
+ goto done;
424
+ }
425
+ sysconfig->timeout_ms = valint * 1000;
426
+ } else if (ares_streq(key, "retry") || ares_streq(key, "attempts")) {
427
+ if (valint == 0) {
428
+ status = ARES_EFORMERR;
429
+ goto done;
430
+ }
431
+ sysconfig->tries = valint;
432
+ } else if (ares_streq(key, "rotate")) {
433
+ sysconfig->rotate = ARES_TRUE;
434
+ } else if (ares_streq(key, "use-vc") || ares_streq(key, "usevc")) {
435
+ sysconfig->usevc = ARES_TRUE;
436
+ }
437
+
438
+ done:
439
+ ares_free_array(kv, num, ares_free);
440
+ return status;
441
+ }
442
+
443
+ ares_status_t ares_sysconfig_set_options(ares_sysconfig_t *sysconfig,
444
+ const char *str)
445
+ {
446
+ ares_buf_t *buf = NULL;
447
+ ares_array_t *options = NULL;
448
+ size_t num;
449
+ size_t i;
450
+ ares_status_t status;
451
+
452
+ buf = ares_buf_create_const((const unsigned char *)str, ares_strlen(str));
453
+ if (buf == NULL) {
454
+ return ARES_ENOMEM;
455
+ }
456
+
457
+ status = ares_buf_split(buf, (const unsigned char *)" \t", 2,
458
+ ARES_BUF_SPLIT_TRIM, 0, &options);
459
+ if (status != ARES_SUCCESS) {
460
+ goto done;
461
+ }
462
+
463
+ num = ares_array_len(options);
464
+ for (i = 0; i < num; i++) {
465
+ ares_buf_t **bufptr = ares_array_at(options, i);
466
+ ares_buf_t *valbuf = *bufptr;
467
+
468
+ status = process_option(sysconfig, valbuf);
469
+ /* Out of memory is the only fatal condition */
470
+ if (status == ARES_ENOMEM) {
471
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
472
+ }
473
+ }
474
+
475
+ status = ARES_SUCCESS;
476
+
477
+ done:
478
+ ares_array_destroy(options);
479
+ ares_buf_destroy(buf);
480
+ return status;
481
+ }
482
+
483
+ ares_status_t ares_init_by_environment(ares_sysconfig_t *sysconfig)
484
+ {
485
+ const char *localdomain;
486
+ const char *res_options;
487
+ ares_status_t status;
488
+
489
+ localdomain = getenv("LOCALDOMAIN");
490
+ if (localdomain) {
491
+ char *temp = ares_strdup(localdomain);
492
+ if (temp == NULL) {
493
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
494
+ }
495
+ status = config_search(sysconfig, temp, 1);
496
+ ares_free(temp);
497
+ if (status != ARES_SUCCESS) {
498
+ return status;
499
+ }
500
+ }
501
+
502
+ res_options = getenv("RES_OPTIONS");
503
+ if (res_options) {
504
+ status = ares_sysconfig_set_options(sysconfig, res_options);
505
+ if (status != ARES_SUCCESS) {
506
+ return status;
507
+ }
508
+ }
509
+
510
+ return ARES_SUCCESS;
511
+ }
512
+
513
+ /* Configuration Files:
514
+ * /etc/resolv.conf
515
+ * - All Unix-like systems
516
+ * - Comments start with ; or #
517
+ * - Lines have a keyword followed by a value that is interpreted specific
518
+ * to the keyword:
519
+ * - Keywords:
520
+ * - nameserver - IP address of nameserver with optional port (using a :
521
+ * prefix). If using an ipv6 address and specifying a port, the ipv6
522
+ * address must be encapsulated in brackets. For link-local ipv6
523
+ * addresses, the interface can also be specified with a % prefix. e.g.:
524
+ * "nameserver [fe80::1]:1234%iface"
525
+ * This keyword may be specified multiple times.
526
+ * - search - whitespace separated list of domains
527
+ * - domain - obsolete, same as search except only a single domain
528
+ * - lookup / hostresorder - local, bind, file, files
529
+ * - sortlist - whitespace separated ip-address/netmask pairs
530
+ * - options - options controlling resolver variables
531
+ * - ndots:n - set ndots option
532
+ * - timeout:n (retrans:n) - timeout per query attempt in seconds
533
+ * - attempts:n (retry:n) - number of times resolver will send query
534
+ * - rotate - round-robin selection of name servers
535
+ * - use-vc / usevc - force tcp
536
+ * /etc/nsswitch.conf
537
+ * - Modern Linux, FreeBSD, HP-UX, Solaris
538
+ * - Search order set via:
539
+ * "hosts: files dns mdns4_minimal mdns4"
540
+ * - files is /etc/hosts
541
+ * - dns is dns
542
+ * - mdns4_minimal does mdns only if ending in .local
543
+ * - mdns4 does not limit to domains ending in .local
544
+ * /etc/netsvc.conf
545
+ * - AIX
546
+ * - Search order set via:
547
+ * "hosts = local , bind"
548
+ * - bind is dns
549
+ * - local is /etc/hosts
550
+ * /etc/svc.conf
551
+ * - Tru64
552
+ * - Same format as /etc/netsvc.conf
553
+ * /etc/host.conf
554
+ * - Early FreeBSD, Early Linux
555
+ * - Not worth supporting, format varied based on system, FreeBSD used
556
+ * just a line per search order, Linux used "order " and a comma
557
+ * delimited list of "bind" and "hosts"
558
+ */
559
+
560
+
561
+ /* This function will only return ARES_SUCCESS or ARES_ENOMEM. Any other
562
+ * conditions are ignored. Users may mess up config files, but we want to
563
+ * process anything we can. */
564
+ ares_status_t ares_sysconfig_parse_resolv_line(const ares_channel_t *channel,
565
+ ares_sysconfig_t *sysconfig,
566
+ ares_buf_t *line)
567
+ {
568
+ char option[32];
569
+ char value[512];
570
+ ares_status_t status = ARES_SUCCESS;
571
+
572
+ /* Ignore lines beginning with a comment */
573
+ if (ares_buf_begins_with(line, (const unsigned char *)"#", 1) ||
574
+ ares_buf_begins_with(line, (const unsigned char *)";", 1)) {
575
+ return ARES_SUCCESS;
576
+ }
577
+
578
+ ares_buf_tag(line);
579
+
580
+ /* Shouldn't be possible, but if it happens, ignore the line. */
581
+ if (ares_buf_consume_nonwhitespace(line) == 0) {
582
+ return ARES_SUCCESS;
583
+ }
584
+
585
+ status = ares_buf_tag_fetch_string(line, option, sizeof(option));
586
+ if (status != ARES_SUCCESS) {
587
+ return ARES_SUCCESS;
588
+ }
589
+
590
+ ares_buf_consume_whitespace(line, ARES_TRUE);
591
+
592
+ status = buf_fetch_string(line, value, sizeof(value));
593
+ if (status != ARES_SUCCESS) {
594
+ return ARES_SUCCESS;
595
+ }
596
+
597
+ ares_str_trim(value);
598
+ if (*value == 0) {
599
+ return ARES_SUCCESS;
600
+ }
601
+
602
+ /* At this point we have a string option and a string value, both trimmed
603
+ * of leading and trailing whitespace. Lets try to evaluate them */
604
+ if (ares_streq(option, "domain")) {
605
+ /* Domain is legacy, don't overwrite an existing config set by search */
606
+ if (sysconfig->domains == NULL) {
607
+ status = config_search(sysconfig, value, 1);
608
+ }
609
+ } else if (ares_streq(option, "lookup") ||
610
+ ares_streq(option, "hostresorder")) {
611
+ ares_buf_tag_rollback(line);
612
+ status = config_lookup(sysconfig, line, " \t");
613
+ } else if (ares_streq(option, "search")) {
614
+ status = config_search(sysconfig, value, 0);
615
+ } else if (ares_streq(option, "nameserver")) {
616
+ status = ares_sconfig_append_fromstr(channel, &sysconfig->sconfig, value,
617
+ ARES_TRUE);
618
+ } else if (ares_streq(option, "sortlist")) {
619
+ /* Ignore all failures except ENOMEM. If the sysadmin set a bad
620
+ * sortlist, just ignore the sortlist, don't cause an inoperable
621
+ * channel */
622
+ status =
623
+ ares_parse_sortlist(&sysconfig->sortlist, &sysconfig->nsortlist, value);
624
+ if (status != ARES_ENOMEM) {
625
+ status = ARES_SUCCESS;
626
+ }
627
+ } else if (ares_streq(option, "options")) {
628
+ status = ares_sysconfig_set_options(sysconfig, value);
629
+ }
630
+
631
+ return status;
632
+ }
633
+
634
+ /* This function will only return ARES_SUCCESS or ARES_ENOMEM. Any other
635
+ * conditions are ignored. Users may mess up config files, but we want to
636
+ * process anything we can. */
637
+ static ares_status_t parse_nsswitch_line(const ares_channel_t *channel,
638
+ ares_sysconfig_t *sysconfig,
639
+ ares_buf_t *line)
640
+ {
641
+ char option[32];
642
+ ares_status_t status = ARES_SUCCESS;
643
+ ares_array_t *sects = NULL;
644
+ ares_buf_t **bufptr;
645
+ ares_buf_t *buf;
646
+
647
+ (void)channel;
648
+
649
+ /* Ignore lines beginning with a comment */
650
+ if (ares_buf_begins_with(line, (const unsigned char *)"#", 1)) {
651
+ return ARES_SUCCESS;
652
+ }
653
+
654
+ /* database : values (space delimited) */
655
+ status = ares_buf_split(line, (const unsigned char *)":", 1,
656
+ ARES_BUF_SPLIT_TRIM, 2, &sects);
657
+
658
+ if (status != ARES_SUCCESS || ares_array_len(sects) != 2) {
659
+ goto done;
660
+ }
661
+
662
+ bufptr = ares_array_at(sects, 0);
663
+ buf = *bufptr;
664
+
665
+ status = buf_fetch_string(buf, option, sizeof(option));
666
+ if (status != ARES_SUCCESS) {
667
+ goto done;
668
+ }
669
+
670
+ /* Only support "hosts:" */
671
+ if (!ares_streq(option, "hosts")) {
672
+ goto done;
673
+ }
674
+
675
+ /* Values are space separated */
676
+ bufptr = ares_array_at(sects, 1);
677
+ buf = *bufptr;
678
+ status = config_lookup(sysconfig, buf, " \t");
679
+
680
+ done:
681
+ ares_array_destroy(sects);
682
+ if (status != ARES_ENOMEM) {
683
+ status = ARES_SUCCESS;
684
+ }
685
+ return status;
686
+ }
687
+
688
+ /* This function will only return ARES_SUCCESS or ARES_ENOMEM. Any other
689
+ * conditions are ignored. Users may mess up config files, but we want to
690
+ * process anything we can. */
691
+ static ares_status_t parse_svcconf_line(const ares_channel_t *channel,
692
+ ares_sysconfig_t *sysconfig,
693
+ ares_buf_t *line)
694
+ {
695
+ char option[32];
696
+ ares_buf_t **bufptr;
697
+ ares_buf_t *buf;
698
+ ares_status_t status = ARES_SUCCESS;
699
+ ares_array_t *sects = NULL;
700
+
701
+ (void)channel;
702
+
703
+ /* Ignore lines beginning with a comment */
704
+ if (ares_buf_begins_with(line, (const unsigned char *)"#", 1)) {
705
+ return ARES_SUCCESS;
706
+ }
707
+
708
+ /* database = values (comma delimited)*/
709
+ status = ares_buf_split(line, (const unsigned char *)"=", 1,
710
+ ARES_BUF_SPLIT_TRIM, 2, &sects);
711
+
712
+ if (status != ARES_SUCCESS || ares_array_len(sects) != 2) {
713
+ goto done;
714
+ }
715
+
716
+ bufptr = ares_array_at(sects, 0);
717
+ buf = *bufptr;
718
+ status = buf_fetch_string(buf, option, sizeof(option));
719
+ if (status != ARES_SUCCESS) {
720
+ goto done;
721
+ }
722
+
723
+ /* Only support "hosts=" */
724
+ if (!ares_streq(option, "hosts")) {
725
+ goto done;
726
+ }
727
+
728
+ /* Values are comma separated */
729
+ bufptr = ares_array_at(sects, 1);
730
+ buf = *bufptr;
731
+ status = config_lookup(sysconfig, buf, ",");
732
+
733
+ done:
734
+ ares_array_destroy(sects);
735
+ if (status != ARES_ENOMEM) {
736
+ status = ARES_SUCCESS;
737
+ }
738
+ return status;
739
+ }
740
+
741
+
742
+ ares_status_t ares_sysconfig_process_buf(const ares_channel_t *channel,
743
+ ares_sysconfig_t *sysconfig,
744
+ ares_buf_t *buf,
745
+ ares_sysconfig_line_cb_t cb)
746
+ {
747
+ ares_array_t *lines = NULL;
748
+ size_t num;
749
+ size_t i;
750
+ ares_status_t status;
751
+
752
+ status = ares_buf_split(buf, (const unsigned char *)"\n", 1,
753
+ ARES_BUF_SPLIT_TRIM, 0, &lines);
754
+ if (status != ARES_SUCCESS) {
755
+ goto done;
756
+ }
757
+
758
+ num = ares_array_len(lines);
759
+ for (i = 0; i < num; i++) {
760
+ ares_buf_t **bufptr = ares_array_at(lines, i);
761
+ ares_buf_t *line = *bufptr;
762
+
763
+ status = cb(channel, sysconfig, line);
764
+ if (status != ARES_SUCCESS) {
765
+ goto done;
766
+ }
767
+ }
768
+
769
+ done:
770
+ ares_array_destroy(lines);
771
+ return status;
772
+ }
773
+
774
+ /* Should only return:
775
+ * ARES_ENOTFOUND - file not found
776
+ * ARES_EFILE - error reading file (perms)
777
+ * ARES_ENOMEM - out of memory
778
+ * ARES_SUCCESS - file processed, doesn't necessarily mean it was a good
779
+ * file, but we're not erroring out if we can't parse
780
+ * something (or anything at all) */
781
+ static ares_status_t process_config_lines(const ares_channel_t *channel,
782
+ const char *filename,
783
+ ares_sysconfig_t *sysconfig,
784
+ ares_sysconfig_line_cb_t cb)
785
+ {
786
+ ares_status_t status = ARES_SUCCESS;
787
+ ares_buf_t *buf = NULL;
788
+
789
+ buf = ares_buf_create();
790
+ if (buf == NULL) {
791
+ status = ARES_ENOMEM;
792
+ goto done;
793
+ }
794
+
795
+ status = ares_buf_load_file(filename, buf);
796
+ if (status != ARES_SUCCESS) {
797
+ goto done;
798
+ }
799
+
800
+ status = ares_sysconfig_process_buf(channel, sysconfig, buf, cb);
801
+
802
+ done:
803
+ ares_buf_destroy(buf);
804
+
805
+ return status;
806
+ }
807
+
808
+ ares_status_t ares_init_sysconfig_files(const ares_channel_t *channel,
809
+ ares_sysconfig_t *sysconfig,
810
+ ares_bool_t process_resolvconf)
811
+ {
812
+ ares_status_t status = ARES_SUCCESS;
813
+
814
+ /* Resolv.conf */
815
+ if (process_resolvconf) {
816
+ status = process_config_lines(channel,
817
+ (channel->resolvconf_path != NULL)
818
+ ? channel->resolvconf_path
819
+ : PATH_RESOLV_CONF,
820
+ sysconfig, ares_sysconfig_parse_resolv_line);
821
+ if (status != ARES_SUCCESS && status != ARES_ENOTFOUND) {
822
+ goto done;
823
+ }
824
+ }
825
+
826
+ /* Nsswitch.conf */
827
+ status = process_config_lines(channel, "/etc/nsswitch.conf", sysconfig,
828
+ parse_nsswitch_line);
829
+ if (status != ARES_SUCCESS && status != ARES_ENOTFOUND) {
830
+ goto done;
831
+ }
832
+
833
+ /* netsvc.conf */
834
+ status = process_config_lines(channel, "/etc/netsvc.conf", sysconfig,
835
+ parse_svcconf_line);
836
+ if (status != ARES_SUCCESS && status != ARES_ENOTFOUND) {
837
+ goto done;
838
+ }
839
+
840
+ /* svc.conf */
841
+ status = process_config_lines(channel, "/etc/svc.conf", sysconfig,
842
+ parse_svcconf_line);
843
+ if (status != ARES_SUCCESS && status != ARES_ENOTFOUND) {
844
+ goto done;
845
+ }
846
+
847
+ status = ARES_SUCCESS;
848
+
849
+ done:
850
+ return status;
851
+ }