From owner-svn-src-all@FreeBSD.ORG Fri Aug 13 06:39:54 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8D32D106566C; Fri, 13 Aug 2010 06:39:54 +0000 (UTC) (envelope-from ume@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7919F8FC08; Fri, 13 Aug 2010 06:39:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7D6dsYr022791; Fri, 13 Aug 2010 06:39:54 GMT (envelope-from ume@svn.freebsd.org) Received: (from ume@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7D6dsk1022779; Fri, 13 Aug 2010 06:39:54 GMT (envelope-from ume@svn.freebsd.org) Message-Id: <201008130639.o7D6dsk1022779@svn.freebsd.org> From: Hajimu UMEMOTO Date: Fri, 13 Aug 2010 06:39:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211276 - head/lib/libc/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2010 06:39:54 -0000 Author: ume Date: Fri Aug 13 06:39:54 2010 New Revision: 211276 URL: http://svn.freebsd.org/changeset/base/211276 Log: - When there is no room for returning the result, nss backend have to return ERANGE and terminate with NS_RETURN. - When gethostbyname_r(3) and the friends end with an error, set errno to the value nss backend returns, and return errno value. PR: kern/131623 MFC after: 2 weeks Modified: head/lib/libc/net/gethostbydns.c head/lib/libc/net/gethostbyht.c head/lib/libc/net/gethostbynis.c head/lib/libc/net/gethostnamadr.c head/lib/libc/net/getnetbydns.c head/lib/libc/net/getnetbyht.c head/lib/libc/net/getnetbynis.c head/lib/libc/net/getnetnamadr.c head/lib/libc/net/getproto.c head/lib/libc/net/getprotoent.c head/lib/libc/net/getprotoname.c Modified: head/lib/libc/net/gethostbydns.c ============================================================================== --- head/lib/libc/net/gethostbydns.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/gethostbydns.c Fri Aug 13 06:39:54 2010 (r211276) @@ -536,9 +536,12 @@ _dns_gethostbyname(void *rval, void *cb_ return (NS_NOTFOUND); } if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } + RES_SET_H_ERRNO(statp, NETDB_SUCCESS); *((struct hostent **)rval) = hptr; return (NS_SUCCESS); } @@ -683,11 +686,13 @@ _dns_gethostbyaddr(void *rval, void *cb_ he.h_addrtype = AF_INET6; he.h_length = NS_IN6ADDRSZ; } - RES_SET_H_ERRNO(statp, NETDB_SUCCESS); if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } + RES_SET_H_ERRNO(statp, NETDB_SUCCESS); *((struct hostent **)rval) = hptr; return (NS_SUCCESS); } Modified: head/lib/libc/net/gethostbyht.c ============================================================================== --- head/lib/libc/net/gethostbyht.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/gethostbyht.c Fri Aug 13 06:39:54 2010 (r211276) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -192,8 +193,11 @@ gethostent_r(struct hostent *hptr, char } if (gethostent_p(&he, hed, statp->options & RES_USE_INET6, statp) != 0) return (-1); - if (__copy_hostent(&he, hptr, buffer, buflen) != 0) - return (-1); + if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + *h_errnop = statp->res_h_errno; + return ((errno != 0) ? errno : -1); + } *result = hptr; return (0); } @@ -268,8 +272,10 @@ found: return (NS_NOTFOUND); } if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); @@ -323,8 +329,10 @@ _ht_gethostbyaddr(void *rval, void *cb_d if (error != 0) return (NS_NOTFOUND); if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); Modified: head/lib/libc/net/gethostbynis.c ============================================================================== --- head/lib/libc/net/gethostbynis.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/gethostbynis.c Fri Aug 13 06:39:54 2010 (r211276) @@ -288,8 +288,10 @@ _nis_gethostbyname(void *rval, void *cb_ return (NS_NOTFOUND); } if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); @@ -336,8 +338,10 @@ _nis_gethostbyaddr(void *rval, void *cb_ return (NS_NOTFOUND); } if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); Modified: head/lib/libc/net/gethostnamadr.c ============================================================================== --- head/lib/libc/net/gethostnamadr.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/gethostnamadr.c Fri Aug 13 06:39:54 2010 (r211276) @@ -480,8 +480,12 @@ fakeaddr(const char *name, int af, struc hed->h_addr_ptrs[0] = (char *)hed->host_addr; hed->h_addr_ptrs[1] = NULL; he.h_addr_list = hed->h_addr_ptrs; + if (__copy_hostent(&he, hp, buf, buflen) != 0) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + return (-1); + } RES_SET_H_ERRNO(statp, NETDB_SUCCESS); - return (__copy_hostent(&he, hp, buf, buflen)); + return (0); } int @@ -528,7 +532,7 @@ gethostbyname_internal(const char *name, size_t buflen, struct hostent **result, int *h_errnop, res_state statp) { const char *cp; - int rval, ret_errno; + int rval, ret_errno = 0; char abuf[MAXDNAME]; #ifdef NS_CACHING @@ -576,7 +580,11 @@ gethostbyname_internal(const char *name, "gethostbyname2_r", default_src, name, af, hp, buf, buflen, &ret_errno, h_errnop); - return ((rval == NS_SUCCESS) ? 0 : -1); + if (rval != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } int @@ -586,7 +594,7 @@ gethostbyaddr_r(const void *addr, sockle const u_char *uaddr = (const u_char *)addr; const struct in6_addr *addr6; socklen_t size; - int rval, ret_errno; + int rval, ret_errno = 0; res_state statp; #ifdef NS_CACHING @@ -651,7 +659,11 @@ gethostbyaddr_r(const void *addr, sockle "gethostbyaddr_r", default_src, uaddr, len, af, hp, buf, buflen, &ret_errno, h_errnop); - return ((rval == NS_SUCCESS) ? 0 : -1); + if (rval != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } struct hostent * Modified: head/lib/libc/net/getnetbydns.c ============================================================================== --- head/lib/libc/net/getnetbydns.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getnetbydns.c Fri Aug 13 06:39:54 2010 (r211276) @@ -355,8 +355,10 @@ _dns_getnetbyaddr(void *rval, void *cb_d net >>= 8; ne.n_net = net; if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); @@ -431,8 +433,10 @@ _dns_getnetbyname(void *rval, void *cb_d return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); Modified: head/lib/libc/net/getnetbyht.c ============================================================================== --- head/lib/libc/net/getnetbyht.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getnetbyht.c Fri Aug 13 06:39:54 2010 (r211276) @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -162,8 +163,11 @@ getnetent_r(struct netent *nptr, char *b } if (getnetent_p(&ne, ned) != 0) return (-1); - if (__copy_netent(&ne, nptr, buffer, buflen) != 0) - return (-1); + if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + *h_errnop = statp->res_h_errno; + return ((errno != 0) ? errno : -1); + } *result = nptr; return (0); } @@ -226,8 +230,10 @@ found: return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); @@ -272,8 +278,10 @@ _ht_getnetbyaddr(void *rval, void *cb_da return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); Modified: head/lib/libc/net/getnetbynis.c ============================================================================== --- head/lib/libc/net/getnetbynis.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getnetbynis.c Fri Aug 13 06:39:54 2010 (r211276) @@ -160,8 +160,10 @@ _nis_getnetbyname(void *rval, void *cb_d return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); @@ -244,8 +246,10 @@ _nis_getnetbyaddr(void *rval, void *cb_d return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { + *errnop = errno; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); Modified: head/lib/libc/net/getnetnamadr.c ============================================================================== --- head/lib/libc/net/getnetnamadr.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getnetnamadr.c Fri Aug 13 06:39:54 2010 (r211276) @@ -360,13 +360,17 @@ getnetbyname_r(const char *name, struct #endif { 0 } }; - int rval, ret_errno; + int rval, ret_errno = 0; rval = _nsdispatch((void *)result, dtab, NSDB_NETWORKS, "getnetbyname_r", default_src, name, ne, buffer, buflen, &ret_errno, h_errorp); - return ((rval == NS_SUCCESS) ? 0 : -1); + if (rval != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } int @@ -388,13 +392,17 @@ getnetbyaddr_r(uint32_t addr, int af, st #endif { 0 } }; - int rval, ret_errno; + int rval, ret_errno = 0; rval = _nsdispatch((void *)result, dtab, NSDB_NETWORKS, "getnetbyaddr_r", default_src, addr, af, ne, buffer, buflen, &ret_errno, h_errorp); - return ((rval == NS_SUCCESS) ? 0 : -1); + if (rval != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } struct netent * Modified: head/lib/libc/net/getproto.c ============================================================================== --- head/lib/libc/net/getproto.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getproto.c Fri Aug 13 06:39:54 2010 (r211276) @@ -33,6 +33,7 @@ static char sccsid[] = "@(#)getproto.c 8 #include __FBSDID("$FreeBSD$"); +#include #include #include #include "netdb_private.h" @@ -72,7 +73,7 @@ files_getprotobynumber(void *retval, voi errnop = va_arg(ap, int *); if ((ped = __protoent_data_init()) == NULL) { - *errnop = -1; + *errnop = errno; return (NS_NOTFOUND); } @@ -83,12 +84,12 @@ files_getprotobynumber(void *retval, voi if (!ped->stayopen) __endprotoent_p(ped); if (error != 0) { - *errnop = -1; + *errnop = errno; return (NS_NOTFOUND); } if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { - *errnop = -1; - return (NS_NOTFOUND); + *errnop = errno; + return (NS_RETURN); } *((struct protoent **)retval) = pptr; @@ -120,10 +121,11 @@ getprotobynumber_r(int proto, struct pro rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobynumber_r", defaultsrc, proto, pptr, buffer, buflen, &ret_errno); - if (rv == NS_SUCCESS) - return (0); - else - return (ret_errno); + if (rv != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } struct protoent * Modified: head/lib/libc/net/getprotoent.c ============================================================================== --- head/lib/libc/net/getprotoent.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getprotoent.c Fri Aug 13 06:39:54 2010 (r211276) @@ -424,8 +424,10 @@ files_getprotoent_r(void *retval, void * buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); - if ((ped = __protoent_data_init()) == NULL) - return (-1); + if ((ped = __protoent_data_init()) == NULL) { + *errnop = errno; + return (NS_NOTFOUND); + } if (__getprotoent_p(&pe, ped) != 0) { *errnop = errno; @@ -434,7 +436,7 @@ files_getprotoent_r(void *retval, void * if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { *errnop = errno; - return (NS_NOTFOUND); + return (NS_RETURN); } *((struct protoent **)retval) = pptr; @@ -490,10 +492,11 @@ getprotoent_r(struct protoent *pptr, cha rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotoent_r", defaultsrc, pptr, buffer, buflen, &ret_errno); - if (rv == NS_SUCCESS) - return (0); - else - return (ret_errno); + if (rv != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } void Modified: head/lib/libc/net/getprotoname.c ============================================================================== --- head/lib/libc/net/getprotoname.c Fri Aug 13 06:03:54 2010 (r211275) +++ head/lib/libc/net/getprotoname.c Fri Aug 13 06:39:54 2010 (r211276) @@ -33,6 +33,7 @@ static char sccsid[] = "@(#)getprotoname #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -75,7 +76,7 @@ files_getprotobyname(void *retval, void if ((ped = __protoent_data_init()) == NULL) { - *errnop = -1; + *errnop = errno; return (NS_NOTFOUND); } @@ -91,12 +92,12 @@ found: if (!ped->stayopen) __endprotoent_p(ped); if (error != 0) { - *errnop = -1; + *errnop = errno; return (NS_NOTFOUND); } if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { - *errnop = -1; - return (NS_NOTFOUND); + *errnop = errno; + return (NS_RETURN); } *((struct protoent **)retval) = pptr; @@ -128,10 +129,11 @@ getprotobyname_r(const char *name, struc rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobyname_r", defaultsrc, name, pptr, buffer, buflen, &ret_errno); - if (rv == NS_SUCCESS) - return (0); - else - return (ret_errno); + if (rv != NS_SUCCESS) { + errno = ret_errno; + return ((ret_errno != 0) ? ret_errno : -1); + } + return (0); } struct protoent *