Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f33a63fe authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

resolv: First pass of un-ifdef

Removed #ifdefs for symbols which are always defined (ANDROID_CHANGES)
and symbols which are never defined (COMPAT__RES, _LIBRESOLV, sun,
ultrix, lint).

Leaving in DEBUG for now because we might want to toggle it in the
future. It's currently defined on a module-by-module basis.

Test: atest netd_integration_test
Change-Id: Iaeaf096266e6ed10895a16253c5f1bdb05760dce
parent afaacf72
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ cc_library_shared {
    // TODO: un-ifdef resolver code
    // TODO: un-ifdef resolver code
    // TODO: fix unused parameter warnings
    // TODO: fix unused parameter warnings
    cflags: [
    cflags: [
        "-DANDROID_CHANGES",
        "-DINET6",
        "-DINET6",
        "-Wno-unused-parameter",
        "-Wno-unused-parameter",
    ],
    ],
+0 −13
Original line number Original line Diff line number Diff line
@@ -881,11 +881,7 @@ static int get_port(const struct addrinfo* ai, const char* servname, int matchon
            allownumeric = 1;
            allownumeric = 1;
            break;
            break;
        case ANY:
        case ANY:
#if 1 /* ANDROID-SPECIFIC CHANGE TO MATCH GLIBC */
            allownumeric = 1;
            allownumeric = 1;
#else
            allownumeric = 0;
#endif
            break;
            break;
        default:
        default:
            return EAI_SOCKTYPE;
            return EAI_SOCKTYPE;
@@ -1198,7 +1194,6 @@ struct addrinfo_sort_elem {
    int original_order;
    int original_order;
};
};


/*ARGSUSED*/
static int _get_scope(const struct sockaddr* addr) {
static int _get_scope(const struct sockaddr* addr) {
    if (addr->sa_family == AF_INET6) {
    if (addr->sa_family == AF_INET6) {
        const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*) addr;
        const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*) addr;
@@ -1256,7 +1251,6 @@ static int _get_scope(const struct sockaddr* addr) {
 * RFC 6724, section 2.1.
 * RFC 6724, section 2.1.
 */
 */


/*ARGSUSED*/
static int _get_label(const struct sockaddr* addr) {
static int _get_label(const struct sockaddr* addr) {
    if (addr->sa_family == AF_INET) {
    if (addr->sa_family == AF_INET) {
        return 4;
        return 4;
@@ -1296,7 +1290,6 @@ static int _get_label(const struct sockaddr* addr) {
 * RFC 6724, section 2.1.
 * RFC 6724, section 2.1.
 */
 */


/*ARGSUSED*/
static int _get_precedence(const struct sockaddr* addr) {
static int _get_precedence(const struct sockaddr* addr) {
    if (addr->sa_family == AF_INET) {
    if (addr->sa_family == AF_INET) {
        return 35;
        return 35;
@@ -1329,7 +1322,6 @@ static int _get_precedence(const struct sockaddr* addr) {
 * Find number of matching initial bits between the two addresses a1 and a2.
 * Find number of matching initial bits between the two addresses a1 and a2.
 */
 */


/*ARGSUSED*/
static int _common_prefix_len(const struct in6_addr* a1, const struct in6_addr* a2) {
static int _common_prefix_len(const struct in6_addr* a1, const struct in6_addr* a2) {
    const char* p1 = (const char*) a1;
    const char* p1 = (const char*) a1;
    const char* p2 = (const char*) a2;
    const char* p2 = (const char*) a2;
@@ -1357,7 +1349,6 @@ static int _common_prefix_len(const struct in6_addr* a1, const struct in6_addr*
 * RFC 6724, section 6.
 * RFC 6724, section 6.
 */
 */


/*ARGSUSED*/
static int _rfc6724_compare(const void* ptr1, const void* ptr2) {
static int _rfc6724_compare(const void* ptr1, const void* ptr2) {
    const struct addrinfo_sort_elem* a1 = (const struct addrinfo_sort_elem*) ptr1;
    const struct addrinfo_sort_elem* a1 = (const struct addrinfo_sort_elem*) ptr1;
    const struct addrinfo_sort_elem* a2 = (const struct addrinfo_sort_elem*) ptr2;
    const struct addrinfo_sort_elem* a2 = (const struct addrinfo_sort_elem*) ptr2;
@@ -1461,7 +1452,6 @@ static int _rfc6724_compare(const void* ptr1, const void* ptr2) {
 * undefined.
 * undefined.
 */
 */


/*ARGSUSED*/
static int _find_src_addr(const struct sockaddr* addr, struct sockaddr* src_addr, unsigned mark,
static int _find_src_addr(const struct sockaddr* addr, struct sockaddr* src_addr, unsigned mark,
                          uid_t uid) {
                          uid_t uid) {
    int sock;
    int sock;
@@ -1518,7 +1508,6 @@ static int _find_src_addr(const struct sockaddr* addr, struct sockaddr* src_addr
 * Will leave the list unchanged if an error occurs.
 * Will leave the list unchanged if an error occurs.
 */
 */


/*ARGSUSED*/
static void _rfc6724_sort(struct addrinfo* list_sentinel, unsigned mark, uid_t uid) {
static void _rfc6724_sort(struct addrinfo* list_sentinel, unsigned mark, uid_t uid) {
    struct addrinfo* cur;
    struct addrinfo* cur;
    int nelem = 0, i;
    int nelem = 0, i;
@@ -1565,7 +1554,6 @@ error:
    free(elems);
    free(elems);
}
}


/*ARGSUSED*/
static int _dns_getaddrinfo(void* rv, void* cb_data, va_list ap) {
static int _dns_getaddrinfo(void* rv, void* cb_data, va_list ap) {
    struct addrinfo* ai;
    struct addrinfo* ai;
    querybuf *buf, *buf2;
    querybuf *buf, *buf2;
@@ -1767,7 +1755,6 @@ found:
    return res0;
    return res0;
}
}


/*ARGSUSED*/
static int _files_getaddrinfo(void* rv, void* cb_data, va_list ap) {
static int _files_getaddrinfo(void* rv, void* cb_data, va_list ap) {
    const char* name;
    const char* name;
    const struct addrinfo* pai;
    const struct addrinfo* pai;
+0 −5
Original line number Original line Diff line number Diff line
@@ -932,7 +932,6 @@ static void addrsort(char** ap, int num, res_state res) {
    }
    }
}
}


/*ARGSUSED*/
static int _dns_gethtbyname(void* rv, void* cb_data, va_list ap) {
static int _dns_gethtbyname(void* rv, void* cb_data, va_list ap) {
    querybuf* buf;
    querybuf* buf;
    int n, type;
    int n, type;
@@ -990,7 +989,6 @@ static int _dns_gethtbyname(void* rv, void* cb_data, va_list ap) {
    return NS_SUCCESS;
    return NS_SUCCESS;
}
}


/*ARGSUSED*/
static int _dns_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
static int _dns_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
    char qbuf[MAXDNAME + 1], *qp, *ep;
    char qbuf[MAXDNAME + 1], *qp, *ep;
    int n;
    int n;
@@ -1094,7 +1092,6 @@ nospc:
}
}


#ifdef YP
#ifdef YP
/*ARGSUSED*/
static struct hostent* _yp_hostent(char* line, int af, struct getnamaddr* info) {
static struct hostent* _yp_hostent(char* line, int af, struct getnamaddr* info) {
    struct in6_addr host_addrs[MAXADDRS];
    struct in6_addr host_addrs[MAXADDRS];
    char** aliases;
    char** aliases;
@@ -1210,7 +1207,6 @@ nospc:
    return NULL;
    return NULL;
}
}


/*ARGSUSED*/
int _yp_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
int _yp_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
    struct hostent* hp = NULL;
    struct hostent* hp = NULL;
    char* ypcurrent;
    char* ypcurrent;
@@ -1257,7 +1253,6 @@ int _yp_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
    return NS_SUCCESS;
    return NS_SUCCESS;
}
}


/*ARGSUSED*/
int _yp_gethtbyname(void* rv, void* cb_data, va_list ap) {
int _yp_gethtbyname(void* rv, void* cb_data, va_list ap) {
    struct hostent* hp;
    struct hostent* hp;
    char* ypcurrent;
    char* ypcurrent;
+0 −77
Original line number Original line Diff line number Diff line
@@ -42,16 +42,6 @@ const char* const _res_opcodes[] = {
        "11",     "12",     "13",      "ZONEINIT", "ZONEREF",
        "11",     "12",     "13",      "ZONEINIT", "ZONEREF",
};
};


#ifdef BIND_UPDATE
const char* const _res_sectioncodes[] = {
        "ZONE",
        "PREREQUISITES",
        "UPDATE",
        "ADDITIONAL",
};
#endif

#ifndef __BIND_NOSTATIC
extern struct __res_state _nres;
extern struct __res_state _nres;


/* Proto. */
/* Proto. */
@@ -63,21 +53,6 @@ int res_ourserver_p(const res_state, const struct sockaddr*);
int res_init(void) {
int res_init(void) {
    int rv;
    int rv;
    extern int __res_vinit(res_state, int);
    extern int __res_vinit(res_state, int);
#ifdef COMPAT__RES
    /*
     * Compatibility with program that were accessing _res directly
     * to set options. We keep another struct res that is the same
     * size as the original res structure, and then copy fields to
     * it so that we achieve the same initialization
     */
    extern void* __res_get_old_state(void);
    extern void __res_put_old_state(void*);
    res_state ores = __res_get_old_state();

    if (ores->options != 0) _nres.options = ores->options;
    if (ores->retrans != 0) _nres.retrans = ores->retrans;
    if (ores->retry != 0) _nres.retry = ores->retry;
#endif


    /*
    /*
     * These three fields used to be statically initialized.  This made
     * These three fields used to be statically initialized.  This made
@@ -109,9 +84,6 @@ int res_init(void) {
    if (!_nres.id) _nres.id = res_randomid();
    if (!_nres.id) _nres.id = res_randomid();


    rv = __res_vinit(&_nres, 1);
    rv = __res_vinit(&_nres, 1);
#ifdef COMPAT__RES
    __res_put_old_state(&_nres);
#endif
    return rv;
    return rv;
}
}


@@ -145,17 +117,6 @@ int res_mkquery(int op, /* opcode of query */
    return (res_nmkquery(&_nres, op, dname, class, type, data, datalen, newrr_in, buf, buflen));
    return (res_nmkquery(&_nres, op, dname, class, type, data, datalen, newrr_in, buf, buflen));
}
}


#ifdef _LIBRESOLV
int res_mkupdate(ns_updrec* rrecp_in, u_char* buf, int buflen) {
    if (res_need_init() && res_init() == -1) {
        RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
        return (-1);
    }

    return (res_nmkupdate(&_nres, rrecp_in, buf, buflen));
}
#endif

int res_query(const char* name,    /* domain name */
int res_query(const char* name,    /* domain name */
              int class, int type, /* class and type of query */
              int class, int type, /* class and type of query */
              u_char* answer,      /* buffer to put answer */
              u_char* answer,      /* buffer to put answer */
@@ -189,32 +150,10 @@ int res_send(const u_char* buf, int buflen, u_char* ans, int anssiz) {
    return (res_nsend(&_nres, buf, buflen, ans, anssiz));
    return (res_nsend(&_nres, buf, buflen, ans, anssiz));
}
}


#ifdef _LIBRESOLV
int res_sendsigned(const u_char* buf, int buflen, ns_tsig_key* key, u_char* ans, int anssiz) {
    if (res_need_init() && res_init() == -1) {
        /* errno should have been set by res_init() in this case. */
        return (-1);
    }

    return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz));
}
#endif

void res_close(void) {
void res_close(void) {
    res_nclose(&_nres);
    res_nclose(&_nres);
}
}


#ifdef _LIBRESOLV
int res_update(ns_updrec* rrecp_in) {
    if (res_need_init() && res_init() == -1) {
        RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
        return (-1);
    }

    return (res_nupdate(&_nres, rrecp_in, NULL));
}
#endif

int res_search(const char* name,    /* domain name */
int res_search(const char* name,    /* domain name */
               int class, int type, /* class and type of query */
               int class, int type, /* class and type of query */
               u_char* answer,      /* buffer to put answer */
               u_char* answer,      /* buffer to put answer */
@@ -248,19 +187,3 @@ int res_opt(int a, u_char* b, int c, int d) {
const char* hostalias(const char* name) {
const char* hostalias(const char* name) {
    return NULL;
    return NULL;
}
}

#ifdef ultrix
int local_hostname_length(const char* hostname) {
    int len_host, len_domain;

    if (!*_nres.defdname) res_init();
    len_host = strlen(hostname);
    len_domain = strlen(_nres.defdname);
    if (len_host > len_domain && !strcasecmp(hostname + len_host - len_domain, _nres.defdname) &&
        hostname[len_host - len_domain - 1] == '.')
        return (len_host - len_domain - 1);
    return (0);
}
#endif /*ultrix*/

#endif
+4 −176
Original line number Original line Diff line number Diff line
@@ -80,24 +80,17 @@
#include <netinet/in.h>
#include <netinet/in.h>


#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netdb.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>


#ifdef ANDROID_CHANGES
#include <errno.h>
#include <fcntl.h>
#endif /* ANDROID_CHANGES */

/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
#ifdef ANDROID_CHANGES
#include "resolv_netid.h"
#include "resolv_netid.h"
#include "resolv_private.h"
#include "resolv_private.h"
#else
#include <resolv.h>
#endif


#include "res_private.h"
#include "res_private.h"


@@ -106,17 +99,7 @@
#define DEBUG
#define DEBUG
#endif
#endif


static void res_setoptions __P((res_state, const char*, const char*) );
static void res_setoptions(res_state, const char*, const char*);

#ifdef RESOLVSORT
static const char sort_mask[] = "/&";
#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
static uint32_t net_mask(struct in_addr);
#endif

#if !defined(isascii) /* XXX - could be a function */
#define isascii(c) (!(c & 0200))
#endif


/*
/*
 * Resolver state default settings.
 * Resolver state default settings.
@@ -164,9 +147,6 @@ int __res_vinit(res_state statp, int preinit) {
    int haveenv = 0;
    int haveenv = 0;
#endif
#endif
    int havesearch = 0;
    int havesearch = 0;
#ifdef RESOLVSORT
    int nsort = 0;
#endif
#if !defined(__BIONIC__)
#if !defined(__BIONIC__)
    char* net;
    char* net;
#endif
#endif
@@ -266,141 +246,6 @@ int __res_vinit(res_state statp, int preinit) {
    if (nserv > 0) statp->nscount = nserv;
    if (nserv > 0) statp->nscount = nserv;
#endif
#endif


#ifndef ANDROID_CHANGES /* !ANDROID_CHANGES - IGNORE resolv.conf in Android */
#define MATCH(line, name)                      \
    (!strncmp(line, name, sizeof(name) - 1) && \
     (line[sizeof(name) - 1] == ' ' || line[sizeof(name) - 1] == '\t'))

    nserv = 0;
    if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) {
        /* read the config file */
        while (fgets(buf, sizeof(buf), fp) != NULL) {
            /* skip comments */
            if (*buf == ';' || *buf == '#') continue;
            /* read default domain name */
            if (MATCH(buf, "domain")) {
                if (haveenv) /* skip if have from environ */
                    continue;
                cp = buf + sizeof("domain") - 1;
                while (*cp == ' ' || *cp == '\t') cp++;
                if ((*cp == '\0') || (*cp == '\n')) continue;
                strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL) *cp = '\0';
                havesearch = 0;
                continue;
            }
            /* set search list */
            if (MATCH(buf, "search")) {
                if (haveenv) /* skip if have from environ */
                    continue;
                cp = buf + sizeof("search") - 1;
                while (*cp == ' ' || *cp == '\t') cp++;
                if ((*cp == '\0') || (*cp == '\n')) continue;
                strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                if ((cp = strchr(statp->defdname, '\n')) != NULL) *cp = '\0';
                /*
                 * Set search list to be blank-separated strings
                 * on rest of line.
                 */
                cp = statp->defdname;
                pp = statp->dnsrch;
                *pp++ = cp;
                for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
                    if (*cp == ' ' || *cp == '\t') {
                        *cp = 0;
                        n = 1;
                    } else if (n) {
                        *pp++ = cp;
                        n = 0;
                    }
                }
                /* null terminate last domain if there are excess */
                while (*cp != '\0' && *cp != ' ' && *cp != '\t') cp++;
                *cp = '\0';
                *pp++ = 0;
                havesearch = 1;
                continue;
            }
            /* read nameservers to query */
            if (MATCH(buf, "nameserver") && nserv < MAXNS) {
                struct addrinfo hints, *ai;
                char sbuf[NI_MAXSERV];
                const size_t minsiz = sizeof(statp->_u._ext.ext->nsaddrs[0]);

                cp = buf + sizeof("nameserver") - 1;
                while (*cp == ' ' || *cp == '\t') cp++;
                cp[strcspn(cp, ";# \t\n")] = '\0';
                if ((*cp != '\0') && (*cp != '\n')) {
                    memset(&hints, 0, sizeof(hints));
                    hints.ai_family = PF_UNSPEC;
                    hints.ai_socktype = SOCK_DGRAM; /*dummy*/
                    hints.ai_flags = AI_NUMERICHOST;
                    sprintf(sbuf, "%u", NAMESERVER_PORT);
                    if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 && ai->ai_addrlen <= minsiz) {
                        if (statp->_u._ext.ext != NULL) {
                            memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr,
                                   ai->ai_addrlen);
                        }
                        if (ai->ai_addrlen <= sizeof(statp->nsaddr_list[nserv])) {
                            memcpy(&statp->nsaddr_list[nserv], ai->ai_addr, ai->ai_addrlen);
                        } else
                            statp->nsaddr_list[nserv].sin_family = 0;
                        freeaddrinfo(ai);
                        nserv++;
                    }
                }
                continue;
            }
            if (MATCH(buf, "sortlist")) {
                struct in_addr a;

                cp = buf + sizeof("sortlist") - 1;
                while (nsort < MAXRESOLVSORT) {
                    while (*cp == ' ' || *cp == '\t') cp++;
                    if (*cp == '\0' || *cp == '\n' || *cp == ';') break;
                    net = cp;
                    while (*cp && !ISSORTMASK(*cp) && *cp != ';' && isascii(*cp) &&
                           !isspace((unsigned char) *cp))
                        cp++;
                    n = *cp;
                    *cp = 0;
                    if (inet_aton(net, &a)) {
                        statp->sort_list[nsort].addr = a;
                        if (ISSORTMASK(n)) {
                            *cp++ = n;
                            net = cp;
                            while (*cp && *cp != ';' && isascii(*cp) &&
                                   !isspace((unsigned char) *cp))
                                cp++;
                            n = *cp;
                            *cp = 0;
                            if (inet_aton(net, &a)) {
                                statp->sort_list[nsort].mask = a.s_addr;
                            } else {
                                statp->sort_list[nsort].mask =
                                        net_mask(statp->sort_list[nsort].addr);
                            }
                        } else {
                            statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr);
                        }
                        nsort++;
                    }
                    *cp = n;
                }
                continue;
            }
            if (MATCH(buf, "options")) {
                res_setoptions(statp, buf + sizeof("options") - 1, "conf");
                continue;
            }
        }
        if (nserv > 0) statp->nscount = nserv;
        statp->nsort = nsort;
        (void) fclose(fp);
    }
#endif /* !ANDROID_CHANGES */
/*
/*
 * Last chance to get a nameserver.  This should not normally
 * Last chance to get a nameserver.  This should not normally
 * be necessary
 * be necessary
@@ -541,21 +386,7 @@ static void res_setoptions(res_state statp, const char* options, const char* sou
    }
    }
}
}


#ifdef RESOLVSORT
/*
/* XXX - should really support CIDR which means explicit masks always. */
static uint32_t net_mask(struct in_addr in) /*!< XXX - should really use system's version of this */
{
    register uint32_t i = ntohl(in.s_addr);

    if (IN_CLASSA(i))
        return (htonl(IN_CLASSA_NET));
    else if (IN_CLASSB(i))
        return (htonl(IN_CLASSB_NET));
    return (htonl(IN_CLASSC_NET));
}
#endif

/*%
 * This routine is for closing the socket if a virtual circuit is used and
 * This routine is for closing the socket if a virtual circuit is used and
 * the program wants to close it.  This provides support for endhostent()
 * the program wants to close it.  This provides support for endhostent()
 * which expects to close the socket.
 * which expects to close the socket.
@@ -679,7 +510,6 @@ int res_getservers(res_state statp, union res_sockaddr_union* set, int cnt) {
    return (statp->nscount);
    return (statp->nscount);
}
}


#ifdef ANDROID_CHANGES
void res_setnetcontext(res_state statp, const struct android_net_context* netcontext) {
void res_setnetcontext(res_state statp, const struct android_net_context* netcontext) {
    if (statp != NULL) {
    if (statp != NULL) {
        statp->netid = netcontext->dns_netid;
        statp->netid = netcontext->dns_netid;
@@ -690,5 +520,3 @@ void res_setnetcontext(res_state statp, const struct android_net_context* netcon
        }
        }
    }
    }
}
}

#endif /* ANDROID_CHANGES */
Loading