From owner-svn-src-all@freebsd.org Sun Nov 4 19:31:45 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C0F8310E882B; Sun, 4 Nov 2018 19:31:45 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4E9DD82F4C; Sun, 4 Nov 2018 19:31:45 +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 18AEC538F; Sun, 4 Nov 2018 19:31:45 +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 wA4JViu8020413; Sun, 4 Nov 2018 19:31:44 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wA4JViqI020412; Sun, 4 Nov 2018 19:31:44 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201811041931.wA4JViqI020412@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sun, 4 Nov 2018 19:31:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340140 - head/lib/libcasper/services/cap_dns X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/lib/libcasper/services/cap_dns X-SVN-Commit-Revision: 340140 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4E9DD82F4C X-Spamd-Result: default: False [-0.40 / 200.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; DMARC_NA(0.00)[FreeBSD.org]; RCVD_COUNT_THREE(0.00)[4]; MX_GOOD(-0.01)[cached: mx1.FreeBSD.org]; NEURAL_HAM_SHORT(-0.29)[-0.288,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Sun, 04 Nov 2018 19:31:46 -0000 Author: oshogbo Date: Sun Nov 4 19:31:44 2018 New Revision: 340140 URL: https://svnweb.freebsd.org/changeset/base/340140 Log: libcasper: Update example in man page to use cap_getnameinfo function. Reviewed by: hrs Differential Revision: https://reviews.freebsd.org/D16931 Modified: head/lib/libcasper/services/cap_dns/cap_dns.3 Modified: head/lib/libcasper/services/cap_dns/cap_dns.3 ============================================================================== --- head/lib/libcasper/services/cap_dns/cap_dns.3 Sun Nov 4 19:29:19 2018 (r340139) +++ head/lib/libcasper/services/cap_dns/cap_dns.3 Sun Nov 4 19:31:44 2018 (r340140) @@ -160,19 +160,22 @@ capability to create the casper service and uses it to resolve an IP address. .Bd -literal cap_channel_t *capcas, *capdns; -const char *typelimit = "ADDR"; -int familylimit; +int familylimit, error; const char *ipstr = "127.0.0.1"; -struct in_addr ip; -struct hostent *hp; +const char *typelimit = "ADDR"; +char hname[NI_MAXHOST]; +struct addrinfo hints, *res; /* Open capability to Casper. */ capcas = cap_init(); if (capcas == NULL) err(1, "Unable to contact Casper"); +/* Cache NLA for gai_strerror. */ +caph_cache_catpages(); + /* Enter capability mode sandbox. */ -if (cap_enter() < 0 && errno != ENOSYS) +if (caph_enter() < 0) err(1, "Unable to enter capability mode"); /* Use Casper capability to create capability to the system.dns service. */ @@ -183,28 +186,34 @@ if (capdns == NULL) /* Close Casper capability, we don't need it anymore. */ cap_close(capcas); -/* Limit system.dns to reverse DNS lookups. */ -if (cap_dns_type_limit(capdns, &typelimit, 1) < 0) - err(1, "Unable to limit access to the system.dns service"); - /* Limit system.dns to reserve IPv4 addresses */ familylimit = AF_INET; if (cap_dns_family_limit(capdns, &familylimit, 1) < 0) err(1, "Unable to limit access to the system.dns service"); -/* Convert IP address in C-string to in_addr. */ -if (!inet_aton(ipstr, &ip)) - errx(1, "Unable to parse IP address %s.", ipstr); +/* Convert IP address in C-string to struct sockaddr. */ +memset(&hints, 0, sizeof(hints)); +hints.ai_family = familylimit; +hints.ai_flags = AI_NUMERICHOST; +error = cap_getaddrinfo(capdns, ipstr, NULL, &hints, &res); +if (error != 0) + errx(1, "cap_getaddrinfo(): %s: %s", ipstr, gai_strerror(error)); +/* Limit system.dns to reverse DNS lookups. */ +if (cap_dns_type_limit(capdns, &typelimit, 1) < 0) + err(1, "Unable to limit access to the system.dns service"); + /* Find hostname for the given IP address. */ -hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET); -if (hp == NULL) - errx(1, "No name associated with %s.", ipstr); +error = cap_getnameinfo(capdns, res->ai_addr, res->ai_addrlen, hname, sizeof(hname), + NULL, 0, 0); +if (error != 0) + errx(1, "cap_getnameinfo(): %s: %s", ipstr, gai_strerror(error)); -printf("Name associated with %s is %s.\\n", ipstr, hp->h_name); +printf("Name associated with %s is %s.\\n", ipstr, hname); .Ed .Sh SEE ALSO .Xr cap_enter 2 , +.Xr caph_enter 3 , .Xr err 3 , .Xr gethostbyaddr 3 , .Xr gethostbyname 3 ,