Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "cpr_ipc.h" |
michael@0 | 6 | #include "cpr_types.h" |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SIP_OS_WINDOWS |
michael@0 | 9 | #include "netdb.h" |
michael@0 | 10 | #include "arpa/inet.h" |
michael@0 | 11 | #endif |
michael@0 | 12 | |
michael@0 | 13 | #include "dns_utils.h" |
michael@0 | 14 | #include "phone_debug.h" |
michael@0 | 15 | #include "util_string.h" |
michael@0 | 16 | |
michael@0 | 17 | #ifdef SIP_OS_WINDOWS |
michael@0 | 18 | cc_int32_t |
michael@0 | 19 | dnsGetHostByName (const char *hname, |
michael@0 | 20 | cpr_ip_addr_t *ipaddr_ptr, |
michael@0 | 21 | cc_int32_t timeout, |
michael@0 | 22 | cc_int32_t retries) |
michael@0 | 23 | { |
michael@0 | 24 | return DNS_ERR_NOHOST; |
michael@0 | 25 | } |
michael@0 | 26 | #else |
michael@0 | 27 | /* |
michael@0 | 28 | * dnsGetHostByName |
michael@0 | 29 | * |
michael@0 | 30 | * DESCRIPTION: Perform an DNS lookup of the name specified |
michael@0 | 31 | * |
michael@0 | 32 | * RETURNS: returns 0 for success or DNS_ERR_NOHOST |
michael@0 | 33 | * |
michael@0 | 34 | */ |
michael@0 | 35 | cc_int32_t |
michael@0 | 36 | dnsGetHostByName (const char *hname, |
michael@0 | 37 | cpr_ip_addr_t *ipaddr_ptr, |
michael@0 | 38 | cc_int32_t timeout, |
michael@0 | 39 | cc_int32_t retries) |
michael@0 | 40 | { |
michael@0 | 41 | uint32_t ip_address; |
michael@0 | 42 | struct hostent *dns_response; |
michael@0 | 43 | #ifdef IPV6_STACK_ENABLED |
michael@0 | 44 | uint32_t err; |
michael@0 | 45 | uint16_t ip_valid; |
michael@0 | 46 | char ip_addr[MAX_IPADDR_STR_LEN]; |
michael@0 | 47 | struct addrinfo hints, *result; |
michael@0 | 48 | struct sockaddr sa; |
michael@0 | 49 | #endif |
michael@0 | 50 | |
michael@0 | 51 | #ifdef IPV6_STACK_ENABLED |
michael@0 | 52 | /* Check if the IPv6 address */ |
michael@0 | 53 | ip_valid = cpr_inet_pton(AF_INET6, hname, ip_addr); |
michael@0 | 54 | |
michael@0 | 55 | if (ip_valid) { |
michael@0 | 56 | ipaddr_ptr->type = CPR_IP_ADDR_IPV6; |
michael@0 | 57 | cpr_memcopy(ipaddr_ptr->u.ip6.addr.base8, ip_addr, 16); |
michael@0 | 58 | return(0); |
michael@0 | 59 | } |
michael@0 | 60 | #endif |
michael@0 | 61 | |
michael@0 | 62 | ip_address = inet_addr(hname); |
michael@0 | 63 | if (ip_address != INADDR_NONE) { |
michael@0 | 64 | ipaddr_ptr->u.ip4 = ip_address; |
michael@0 | 65 | ipaddr_ptr->type = CPR_IP_ADDR_IPV4; |
michael@0 | 66 | return 0; |
michael@0 | 67 | } else { |
michael@0 | 68 | |
michael@0 | 69 | #ifdef IPV6_STACK_ENABLED |
michael@0 | 70 | memset(&hints, 0, sizeof(hints)); |
michael@0 | 71 | hints.ai_family = PF_INET6; |
michael@0 | 72 | err = getaddrinfo(hname, NULL, &hints, &result); |
michael@0 | 73 | |
michael@0 | 74 | if (err) { |
michael@0 | 75 | return DNS_ERR_NOHOST; |
michael@0 | 76 | |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | while (result) { |
michael@0 | 80 | sa = result->ai_addr; |
michael@0 | 81 | if (sa->family == AF_INET) { |
michael@0 | 82 | ipaddr_ptr->type = CPR_IP_ADDR_IPV4; |
michael@0 | 83 | ip_addr->u.ip4 = ((cpr_sockaddr_in_t *)from)->sin_addr.s_addr; |
michael@0 | 84 | |
michael@0 | 85 | } else if (sa->family == AF_INET6) { |
michael@0 | 86 | |
michael@0 | 87 | //Todo IPv6: Add getaddrinfo() functioncall to get the IPv6 address. |
michael@0 | 88 | ipaddr_ptr->type = CPR_IP_ADDR_IPV6; |
michael@0 | 89 | ip_addr->u.ip6 = ((cpr_sockaddr_in6_t *)sa)->sin6_addr; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | freeaddrinfo(result); |
michael@0 | 94 | #endif |
michael@0 | 95 | |
michael@0 | 96 | dns_response = gethostbyname(hname); |
michael@0 | 97 | if (dns_response) { |
michael@0 | 98 | ipaddr_ptr->u.ip4 = *(uint32_t *) dns_response->h_addr_list[0]; |
michael@0 | 99 | ipaddr_ptr->type = CPR_IP_ADDR_IPV4; |
michael@0 | 100 | return 0; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | } |
michael@0 | 105 | return DNS_ERR_NOHOST; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | #endif |
michael@0 | 109 | |
michael@0 | 110 | #ifdef SIP_OS_WINDOWS |
michael@0 | 111 | |
michael@0 | 112 | cc_int32_t |
michael@0 | 113 | dnsGetHostBySRV (cc_int8_t *service, |
michael@0 | 114 | cc_int8_t *protocol, |
michael@0 | 115 | cc_int8_t *domain, |
michael@0 | 116 | cpr_ip_addr_t *ipaddr_ptr, |
michael@0 | 117 | cc_uint16_t *port, |
michael@0 | 118 | cc_int32_t timeout, |
michael@0 | 119 | cc_int32_t retries, |
michael@0 | 120 | srv_handle_t *psrv_handle) |
michael@0 | 121 | { |
michael@0 | 122 | return DNS_ERR_NOHOST; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | #else |
michael@0 | 126 | /* |
michael@0 | 127 | * dnsGetHostBySRV |
michael@0 | 128 | * |
michael@0 | 129 | * DESCRIPTION: This function calls the dns api to |
michael@0 | 130 | * perform a dns srv query |
michael@0 | 131 | * |
michael@0 | 132 | * RETURNS: returns 0 for success or |
michael@0 | 133 | * DNS_ERR_NOHOST, DNS_ERR_HOST_UNAVAIL |
michael@0 | 134 | * |
michael@0 | 135 | */ |
michael@0 | 136 | cc_int32_t |
michael@0 | 137 | dnsGetHostBySRV (cc_int8_t *service, |
michael@0 | 138 | cc_int8_t *protocol, |
michael@0 | 139 | cc_int8_t *domain, |
michael@0 | 140 | cpr_ip_addr_t *ipaddr_ptr, |
michael@0 | 141 | cc_uint16_t *port, |
michael@0 | 142 | cc_int32_t timeout, |
michael@0 | 143 | cc_int32_t retries, |
michael@0 | 144 | srv_handle_t *psrv_handle) |
michael@0 | 145 | { |
michael@0 | 146 | uint32_t ip_address; |
michael@0 | 147 | |
michael@0 | 148 | |
michael@0 | 149 | ip_address = inet_addr(domain); |
michael@0 | 150 | if (ip_address != INADDR_NONE) { |
michael@0 | 151 | ipaddr_ptr->u.ip4 = ip_address; |
michael@0 | 152 | ipaddr_ptr->type = CPR_IP_ADDR_IPV4; |
michael@0 | 153 | return 0; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | return DNS_ERR_NOBUF; /* not yet implemented */ |
michael@0 | 157 | } |
michael@0 | 158 | #endif |
michael@0 | 159 | |
michael@0 | 160 | void |
michael@0 | 161 | dnsFreeSrvHandle (srv_handle_t srv_handle) |
michael@0 | 162 | { |
michael@0 | 163 | // this function does nothing |
michael@0 | 164 | // srv_handle = NULL; |
michael@0 | 165 | } |