Changeset 746 for vendor/current/source3/libsmb/namequery.c
- Timestamp:
- Nov 27, 2012, 4:56:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/namequery.c
r740 r746 1079 1079 "looking for duplicate address/port pairs\n")); 1080 1080 1081 /* one loop to remove duplicates*/1081 /* One loop to set duplicates to a zero addr. */ 1082 1082 for ( i=0; i<count; i++ ) { 1083 1083 if ( is_zero_addr(&iplist[i].ss)) { … … 1093 1093 } 1094 1094 1095 /* one loop to clean up any holes we left */ 1096 /* first ip should never be a zero_ip() */ 1097 for (i = 0; i<count; ) { 1098 if (is_zero_addr(&iplist[i].ss) ) { 1099 if (i != count-1) { 1100 memmove(&iplist[i], &iplist[i+1], 1101 (count - i - 1)*sizeof(iplist[i])); 1095 /* Now remove any addresses set to zero above. */ 1096 for (i = 0; i < count; i++) { 1097 while (i < count && 1098 is_zero_addr(&iplist[i].ss)) { 1099 if (count-i-1>0) { 1100 memmove(&iplist[i], 1101 &iplist[i+1], 1102 (count-i-1)*sizeof(struct ip_service)); 1102 1103 } 1103 1104 count--; 1104 continue; 1105 } 1106 i++; 1105 } 1107 1106 } 1108 1107 … … 1340 1339 in_addr_to_sockaddr_storage(&addr, ip); 1341 1340 1341 if (is_zero_addr(&addr)) { 1342 continue; 1343 } 1344 1342 1345 for (j=0; j<state->num_addrs; j++) { 1343 1346 if (sockaddr_equal( … … 1477 1480 1478 1481 /******************************************************** 1479 convert an array if struct sockaddr_storage to struct ip_service1482 Convert an array if struct sockaddr_storage to struct ip_service 1480 1483 return false on failure. Port is set to PORT_NONE; 1484 pcount is [in/out] - it is the length of ss_list on input, 1485 and the length of return_iplist on output as we remove any 1486 zero addresses from ss_list. 1481 1487 *********************************************************/ 1482 1488 1483 1489 static bool convert_ss2service(struct ip_service **return_iplist, 1484 1490 const struct sockaddr_storage *ss_list, 1485 int count)1491 int *pcount) 1486 1492 { 1487 1493 int i; 1488 1489 if ( count==0 || !ss_list ) 1494 int orig_count = *pcount; 1495 int real_count = 0; 1496 1497 if (orig_count==0 || !ss_list ) 1490 1498 return False; 1491 1499 1500 /* Filter out zero addrs. */ 1501 for ( i=0; i<orig_count; i++ ) { 1502 if (is_zero_addr(&ss_list[i])) { 1503 continue; 1504 } 1505 real_count++; 1506 } 1507 if (real_count==0) { 1508 return false; 1509 } 1510 1492 1511 /* copy the ip address; port will be PORT_NONE */ 1493 if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) ==1512 if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, real_count)) == 1494 1513 NULL) { 1495 1514 DEBUG(0,("convert_ip2service: malloc failed " 1496 "for %d enetries!\n", count ));1515 "for %d enetries!\n", real_count )); 1497 1516 return False; 1498 1517 } 1499 1518 1500 for ( i=0; i<count; i++ ) { 1501 (*return_iplist)[i].ss = ss_list[i]; 1502 (*return_iplist)[i].port = PORT_NONE; 1503 } 1504 1519 for ( i=0, real_count = 0; i<orig_count; i++ ) { 1520 if (is_zero_addr(&ss_list[i])) { 1521 continue; 1522 } 1523 (*return_iplist)[real_count].ss = ss_list[i]; 1524 (*return_iplist)[real_count].port = PORT_NONE; 1525 real_count++; 1526 } 1527 1528 *pcount = real_count; 1505 1529 return true; 1506 1530 } … … 1686 1710 1687 1711 status = NT_STATUS_OK; 1688 if (!convert_ss2service(return_iplist, ss_list, *return_count))1712 if (!convert_ss2service(return_iplist, ss_list, return_count)) 1689 1713 status = NT_STATUS_INVALID_PARAMETER; 1690 1714 … … 1730 1754 if (convert_ss2service(return_iplist, 1731 1755 ss_list, 1732 *return_count)) {1756 return_count)) { 1733 1757 talloc_free(ctx); 1734 1758 return NT_STATUS_OK; … … 1803 1827 memcpy(&ss, res->ai_addr, res->ai_addrlen); 1804 1828 1829 if (is_zero_addr(&ss)) { 1830 continue; 1831 } 1832 1805 1833 *return_count += 1; 1806 1834 … … 1839 1867 int *return_count) 1840 1868 { 1841 int i , j;1869 int i; 1842 1870 NTSTATUS status; 1843 1871 TALLOC_CTX *ctx; … … 1888 1916 1889 1917 for (i=0;i<numdcs;i++) { 1890 numaddrs += MAX(dcs[i].num_ips,1); 1891 } 1918 if (!dcs[i].ss_s) { 1919 numaddrs += 1; 1920 } else { 1921 numaddrs += dcs[i].num_ips; 1922 } 1923 } 1892 1924 1893 1925 if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, numaddrs)) == … … 1902 1934 1903 1935 *return_count = 0; 1904 i = 0; 1905 j = 0; 1906 while ( i < numdcs && (*return_count<numaddrs) ) { 1907 struct ip_service *r = &(*return_iplist)[*return_count]; 1908 1909 r->port = dcs[i].port; 1910 1936 1937 for (i = 0; i < numdcs && (*return_count<numaddrs); i++ ) { 1911 1938 /* If we don't have an IP list for a name, lookup it up */ 1912 1913 1939 if (!dcs[i].ss_s) { 1914 interpret_string_addr(&r->ss, dcs[i].hostname, 0); 1915 i++; 1916 j = 0; 1917 } else { 1918 /* use the IP addresses from the SRV sresponse */ 1919 1920 if ( j >= dcs[i].num_ips ) { 1921 i++; 1922 j = 0; 1940 /* We need to get all IP addresses here. */ 1941 struct addrinfo *res = NULL; 1942 struct addrinfo *p; 1943 int extra_addrs = 0; 1944 1945 if (!interpret_string_addr_internal(&res, 1946 dcs[i].hostname, 1947 0)) { 1923 1948 continue; 1924 1949 } 1925 1926 r->ss = dcs[i].ss_s[j]; 1927 j++; 1928 } 1929 1930 /* make sure it is a valid IP. I considered checking the 1931 * negative connection cache, but this is the wrong place 1932 * for it. Maybe only as a hack. After think about it, if 1933 * all of the IP addresses returned from DNS are dead, what 1934 * hope does a netbios name lookup have ? The standard reason 1935 * for falling back to netbios lookups is that our DNS server 1936 * doesn't know anything about the DC's -- jerry */ 1937 1938 if (!is_zero_addr(&r->ss)) { 1939 (*return_count)++; 1950 /* Add in every IP from the lookup. How 1951 many is that ? */ 1952 for (p = res; p; p = p->ai_next) { 1953 struct sockaddr_storage ss; 1954 memcpy(&ss, p->ai_addr, p->ai_addrlen); 1955 if (is_zero_addr(&ss)) { 1956 continue; 1957 } 1958 extra_addrs++; 1959 } 1960 if (extra_addrs > 1) { 1961 /* We need to expand the return_iplist array 1962 as we only budgeted for one address. */ 1963 numaddrs += (extra_addrs-1); 1964 *return_iplist = SMB_REALLOC_ARRAY(*return_iplist, 1965 struct ip_service, 1966 numaddrs); 1967 if (*return_iplist == NULL) { 1968 if (res) { 1969 freeaddrinfo(res); 1970 } 1971 talloc_destroy(ctx); 1972 return NT_STATUS_NO_MEMORY; 1973 } 1974 } 1975 for (p = res; p; p = p->ai_next) { 1976 (*return_iplist)[*return_count].port = dcs[i].port; 1977 memcpy(&(*return_iplist)[*return_count].ss, 1978 p->ai_addr, 1979 p->ai_addrlen); 1980 if (is_zero_addr(&(*return_iplist)[*return_count].ss)) { 1981 continue; 1982 } 1983 (*return_count)++; 1984 /* Should never happen, but still... */ 1985 if (*return_count>=numaddrs) { 1986 break; 1987 } 1988 } 1989 if (res) { 1990 freeaddrinfo(res); 1991 } 1992 } else { 1993 /* use all the IP addresses from the SRV sresponse */ 1994 int j; 1995 for (j = 0; j < dcs[i].num_ips; j++) { 1996 (*return_iplist)[*return_count].port = dcs[i].port; 1997 (*return_iplist)[*return_count].ss = dcs[i].ss_s[j]; 1998 if (is_zero_addr(&(*return_iplist)[*return_count].ss)) { 1999 continue; 2000 } 2001 (*return_count)++; 2002 /* Should never happen, but still... */ 2003 if (*return_count>=numaddrs) { 2004 break; 2005 } 2006 } 1940 2007 } 1941 2008 } … … 1994 2061 return NT_STATUS_INVALID_PARAMETER; 1995 2062 } 2063 if (is_zero_addr(&(*return_iplist)->ss)) { 2064 SAFE_FREE(*return_iplist); 2065 return NT_STATUS_UNSUCCESSFUL; 2066 } 1996 2067 *return_count = 1; 1997 2068 return NT_STATUS_OK; … … 2001 2072 2002 2073 if (namecache_fetch(name, name_type, return_iplist, return_count)) { 2074 *return_count = remove_duplicate_addrs2(*return_iplist, 2075 *return_count ); 2003 2076 /* This could be a negative response */ 2004 2077 if (*return_count > 0) { … … 2075 2148 if (!convert_ss2service(return_iplist, 2076 2149 ss_list, 2077 *return_count)) {2150 return_count)) { 2078 2151 status = NT_STATUS_NO_MEMORY; 2079 2152 } … … 2101 2174 the iplist when the PDC is down will cause two sets of timeouts. */ 2102 2175 2103 if ( *return_count ) { 2104 *return_count = remove_duplicate_addrs2(*return_iplist, 2105 *return_count ); 2106 } 2176 *return_count = remove_duplicate_addrs2(*return_iplist, *return_count ); 2107 2177 2108 2178 /* Save in name cache */ … … 2120 2190 } 2121 2191 2122 namecache_store(name, name_type, *return_count, *return_iplist); 2192 if (*return_count) { 2193 namecache_store(name, name_type, *return_count, *return_iplist); 2194 } 2123 2195 2124 2196 /* Display some debugging info */ … … 2583 2655 explicit password servers */ 2584 2656 2585 if (local_count) { 2586 local_count = remove_duplicate_addrs2(return_iplist, 2587 local_count ); 2588 } 2657 local_count = remove_duplicate_addrs2(return_iplist, local_count ); 2589 2658 2590 2659 /* For DC's we always prioritize IPv4 due to W2K3 not
Note:
See TracChangeset
for help on using the changeset viewer.