From owner-svn-src-stable-12@freebsd.org Tue Sep 10 20:41:43 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2EA61E4021; Tue, 10 Sep 2019 20:41:43 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46ScQH0Td1z416P; Tue, 10 Sep 2019 20:41:43 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E7BB02BBBC; Tue, 10 Sep 2019 20:41:42 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x8AKfgRE068984; Tue, 10 Sep 2019 20:41:42 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x8AKfgA8068981; Tue, 10 Sep 2019 20:41:42 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201909102041.x8AKfgA8068981@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Tue, 10 Sep 2019 20:41:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r352187 - in stable/12/lib/libcasper/services/cap_dns: . tests X-SVN-Group: stable-12 X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: in stable/12/lib/libcasper/services/cap_dns: . tests X-SVN-Commit-Revision: 352187 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Sep 2019 20:41:43 -0000 Author: oshogbo Date: Tue Sep 10 20:41:42 2019 New Revision: 352187 URL: https://svnweb.freebsd.org/changeset/base/352187 Log: MFCr340141: libcasper: fix limitations in dns service The getaddrinfo(3) and gethostbyname(3) are used to return the address for a given hostname. The getnameinfo(3) and gethostbyaddr(3) are used to return hostname for a given address. Right now in casper, we have two limitations: - NAME which allows resolving DNS names. - ADDR which allows to do revert DNS lookups. Before this change the rights was mixed up: NAME - getnameinfo(3) and gethostbyname(3) ADDR - gethostbyaddr(3) and getaddrinfo(3) Which no matters on limitation allowed us to resolve DNS names and do DNS lookups basically by using a different set of functions. Now the NAME type allows getaddrinfo(3) and gethostbyname (3)functions, and the ADDR names allow to use gethostbyaddr(3) and getnameinfo(3) functions. Reviewed by: pjd, bcr Discussed with: hrs Differential Revision: https://reviews.freebsd.org/D16930 Modified: stable/12/lib/libcasper/services/cap_dns/cap_dns.3 stable/12/lib/libcasper/services/cap_dns/cap_dns.c stable/12/lib/libcasper/services/cap_dns/tests/dns_test.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libcasper/services/cap_dns/cap_dns.3 ============================================================================== --- stable/12/lib/libcasper/services/cap_dns/cap_dns.3 Tue Sep 10 20:27:44 2019 (r352186) +++ stable/12/lib/libcasper/services/cap_dns/cap_dns.3 Tue Sep 10 20:41:42 2019 (r352187) @@ -118,19 +118,21 @@ or .Dv NAME . The .Dv ADDR -means that functions -.Fn cap_gethostbyname , -.Fn cap_gethostbyname2 +means that reverse DNS lookups are allowed with +.Fn cap_getnameinfo and .Fn cap_gethostbyaddr -are allowed. +functions. In case when .Va type is set to .Dv NAME -the -.Fn cap_getnameinfo -function is allowed. +the name resolution is allowed with +.Fn cap_getaddrinfo , +.Fn cap_gethostbyname , +and +.Fn cap_gethostbyname2 +functions. .It family ( NV_TYPE_NUMBER ) The .Va family Modified: stable/12/lib/libcasper/services/cap_dns/cap_dns.c ============================================================================== --- stable/12/lib/libcasper/services/cap_dns/cap_dns.c Tue Sep 10 20:27:44 2019 (r352186) +++ stable/12/lib/libcasper/services/cap_dns/cap_dns.c Tue Sep 10 20:41:42 2019 (r352187) @@ -524,7 +524,7 @@ dns_getnameinfo(const nvlist_t *limits, const nvlist_t socklen_t salen; int error, flags; - if (!dns_allowed_type(limits, "NAME")) + if (!dns_allowed_type(limits, "ADDR")) return (NO_RECOVERY); error = 0; @@ -617,7 +617,7 @@ dns_getaddrinfo(const nvlist_t *limits, const nvlist_t unsigned int ii; int error, family, n; - if (!dns_allowed_type(limits, "ADDR")) + if (!dns_allowed_type(limits, "NAME")) return (NO_RECOVERY); hostname = dnvlist_get_string(nvlin, "hostname", NULL); Modified: stable/12/lib/libcasper/services/cap_dns/tests/dns_test.c ============================================================================== --- stable/12/lib/libcasper/services/cap_dns/tests/dns_test.c Tue Sep 10 20:27:44 2019 (r352186) +++ stable/12/lib/libcasper/services/cap_dns/tests/dns_test.c Tue Sep 10 20:41:42 2019 (r352187) @@ -393,7 +393,8 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 2) == 0); CHECK(runtest(capdns) == - (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET | GETHOSTBYNAME2_AF_INET6)); + (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET | GETHOSTBYNAME2_AF_INET6 | + GETADDRINFO_AF_INET | GETADDRINFO_AF_INET6)); cap_close(capdns); @@ -419,9 +420,7 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 2) == 0); CHECK(runtest(capdns) == - (GETHOSTBYADDR_AF_INET | GETHOSTBYADDR_AF_INET6 | - GETADDRINFO_AF_INET | GETADDRINFO_AF_INET6)); - + (GETHOSTBYADDR_AF_INET | GETHOSTBYADDR_AF_INET6)); cap_close(capdns); /* @@ -512,7 +511,8 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 1) == -1 && errno == ENOTCAPABLE); - CHECK(runtest(capdns) == (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET)); + CHECK(runtest(capdns) == + (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET | GETADDRINFO_AF_INET)); cap_close(capdns); @@ -548,7 +548,8 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 1) == -1 && errno == ENOTCAPABLE); - CHECK(runtest(capdns) == GETHOSTBYNAME2_AF_INET6); + CHECK(runtest(capdns) == + (GETHOSTBYNAME2_AF_INET6 | GETADDRINFO_AF_INET6)); cap_close(capdns); @@ -584,7 +585,7 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 1) == -1 && errno == ENOTCAPABLE); - CHECK(runtest(capdns) == (GETHOSTBYADDR_AF_INET | GETADDRINFO_AF_INET)); + CHECK(runtest(capdns) == GETHOSTBYADDR_AF_INET); cap_close(capdns); @@ -620,8 +621,7 @@ main(void) CHECK(cap_dns_family_limit(capdns, families, 1) == -1 && errno == ENOTCAPABLE); - CHECK(runtest(capdns) == (GETHOSTBYADDR_AF_INET6 | - GETADDRINFO_AF_INET6)); + CHECK(runtest(capdns) == GETHOSTBYADDR_AF_INET6); cap_close(capdns); @@ -657,7 +657,8 @@ main(void) errno == ENOTCAPABLE); /* Do the limits still hold? */ - CHECK(runtest(capdns) == (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET)); + CHECK(runtest(capdns) == (GETHOSTBYNAME | GETHOSTBYNAME2_AF_INET | + GETADDRINFO_AF_INET)); cap_close(capdns); @@ -691,8 +692,7 @@ main(void) errno == ENOTCAPABLE); /* Do the limits still hold? */ - CHECK(runtest(capdns) == (GETHOSTBYADDR_AF_INET6 | - GETADDRINFO_AF_INET6)); + CHECK(runtest(capdns) == GETHOSTBYADDR_AF_INET6); cap_close(capdns);