Ignore:
Timestamp:
Nov 27, 2012, 4:56:06 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated vendor to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/libsmb/namequery.c

    r740 r746  
    10791079                        "looking for duplicate address/port pairs\n"));
    10801080
    1081         /* one loop to remove duplicates */
     1081        /* One loop to set duplicates to a zero addr. */
    10821082        for ( i=0; i<count; i++ ) {
    10831083                if ( is_zero_addr(&iplist[i].ss)) {
     
    10931093        }
    10941094
    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));
    11021103                        }
    11031104                        count--;
    1104                         continue;
    1105                 }
    1106                 i++;
     1105                }
    11071106        }
    11081107
     
    13401339                in_addr_to_sockaddr_storage(&addr, ip);
    13411340
     1341                if (is_zero_addr(&addr)) {
     1342                        continue;
     1343                }
     1344
    13421345                for (j=0; j<state->num_addrs; j++) {
    13431346                        if (sockaddr_equal(
     
    14771480
    14781481/********************************************************
    1479  convert an array if struct sockaddr_storage to struct ip_service
     1482 Convert an array if struct sockaddr_storage to struct ip_service
    14801483 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.
    14811487*********************************************************/
    14821488
    14831489static bool convert_ss2service(struct ip_service **return_iplist,
    14841490                const struct sockaddr_storage *ss_list,
    1485                 int count)
     1491                int *pcount)
    14861492{
    14871493        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 )
    14901498                return False;
    14911499
     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
    14921511        /* 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)) ==
    14941513                        NULL) {
    14951514                DEBUG(0,("convert_ip2service: malloc failed "
    1496                         "for %d enetries!\n", count ));
     1515                        "for %d enetries!\n", real_count ));
    14971516                return False;
    14981517        }
    14991518
    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;
    15051529        return true;
    15061530}
     
    16861710
    16871711        status = NT_STATUS_OK;
    1688         if (!convert_ss2service(return_iplist, ss_list, *return_count))
     1712        if (!convert_ss2service(return_iplist, ss_list, return_count))
    16891713                status = NT_STATUS_INVALID_PARAMETER;
    16901714
     
    17301754                if (convert_ss2service(return_iplist,
    17311755                                       ss_list,
    1732                                        *return_count)) {
     1756                                       return_count)) {
    17331757                        talloc_free(ctx);
    17341758                        return NT_STATUS_OK;
     
    18031827                memcpy(&ss, res->ai_addr, res->ai_addrlen);
    18041828
     1829                if (is_zero_addr(&ss)) {
     1830                        continue;
     1831                }
     1832
    18051833                *return_count += 1;
    18061834
     
    18391867                            int *return_count)
    18401868{
    1841         int                     i, j;
     1869        int                     i;
    18421870        NTSTATUS                status;
    18431871        TALLOC_CTX              *ctx;
     
    18881916
    18891917        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        }
    18921924
    18931925        if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, numaddrs)) ==
     
    19021934
    19031935        *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++ ) {
    19111938                /* If we don't have an IP list for a name, lookup it up */
    1912 
    19131939                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)) {
    19231948                                continue;
    19241949                        }
    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                        }
    19402007                }
    19412008        }
     
    19942061                        return NT_STATUS_INVALID_PARAMETER;
    19952062                }
     2063                if (is_zero_addr(&(*return_iplist)->ss)) {
     2064                        SAFE_FREE(*return_iplist);
     2065                        return NT_STATUS_UNSUCCESSFUL;
     2066                }
    19962067                *return_count = 1;
    19972068                return NT_STATUS_OK;
     
    20012072
    20022073        if (namecache_fetch(name, name_type, return_iplist, return_count)) {
     2074                *return_count = remove_duplicate_addrs2(*return_iplist,
     2075                                        *return_count );
    20032076                /* This could be a negative response */
    20042077                if (*return_count > 0) {
     
    20752148                                if (!convert_ss2service(return_iplist,
    20762149                                                        ss_list,
    2077                                                         *return_count)) {
     2150                                                        return_count)) {
    20782151                                        status = NT_STATUS_NO_MEMORY;
    20792152                                }
     
    21012174        the iplist when the PDC is down will cause two sets of timeouts. */
    21022175
    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 );
    21072177
    21082178        /* Save in name cache */
     
    21202190        }
    21212191
    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        }
    21232195
    21242196        /* Display some debugging info */
     
    25832655           explicit password servers */
    25842656
    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 );
    25892658
    25902659        /* For DC's we always prioritize IPv4 due to W2K3 not
Note: See TracChangeset for help on using the changeset viewer.