Date: Mon, 22 Apr 2013 12:59:23 GMT From: Matthieu Volat <mazhe@alkumuna.eu> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/178052: New port submission: dns/mDNSRedponder_nss Message-ID: <201304221259.r3MCxNSr063338@red.freebsd.org> Resent-Message-ID: <201304221300.r3MD00fG014361@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 178052 >Category: ports >Synopsis: New port submission: dns/mDNSRedponder_nss >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Apr 22 13:00:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Matthieu Volat >Release: >Organization: >Environment: >Description: Hello all, I have ported the (Linux) NSS module of the mDNSResponder project to FreeBSD libc and would like to propose the result for inclusion in ports. It allows to use mDNSResponder for hostname resolution as a libc instead of using the dns/nss_mdns port that relies on the Avahi stack (both project creates a nss_mdns.so.1 file). I am volunteering to maintain this port. >How-To-Repeat: >Fix: Patch attached with submission follows: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # mDNSResponder_nss # mDNSResponder_nss/files # mDNSResponder_nss/files/nss_mdns_freebsd.c # mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c # mDNSResponder_nss/Makefile # mDNSResponder_nss/distinfo # mDNSResponder_nss/pkg-descr # mDNSResponder_nss/pkg-plist # echo c - mDNSResponder_nss mkdir -p mDNSResponder_nss > /dev/null 2>&1 echo c - mDNSResponder_nss/files mkdir -p mDNSResponder_nss/files > /dev/null 2>&1 echo x - mDNSResponder_nss/files/nss_mdns_freebsd.c sed 's/^X//' >mDNSResponder_nss/files/nss_mdns_freebsd.c << 'fd1c46f3f4a4f438620948d5ef5dcad0' X#include <sys/param.h> X#include <sys/socket.h> X#include <arpa/inet.h> X#include <netinet/in.h> X#include <netdb.h> X#include <nsswitch.h> X#include <stdarg.h> X#include <stdlib.h> X#include <string.h> X#include <syslog.h> X Xextern int _nss_mdns_gethostbyname2_r(const char *, int, X struct hostent *, char *, size_t, int *, int *); Xextern int _nss_mdns_gethostbyaddr_r(const void *, socklen_t, int, X struct hostent *, char *, size_t, int *, int *); X Xstatic NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname2_r); Xstatic NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyaddr_r); Xstatic NSS_METHOD_PROTOTYPE(__nss_compat_getaddrinfo); X Xstatic ns_mtab methods[] = { X { NSDB_HOSTS, "gethostbyname_r", __nss_compat_gethostbyname2_r, NULL }, X { NSDB_HOSTS, "gethostbyname2_r", __nss_compat_gethostbyname2_r, NULL }, X { NSDB_HOSTS, "gethostbyaddr_r", __nss_compat_gethostbyaddr_r, NULL }, X { NSDB_HOSTS, "getaddrinfo", __nss_compat_getaddrinfo, NULL }, X}; X Xns_mtab * Xnss_module_register(const char *source, unsigned int *mtabsize, X nss_module_unregister_fn *unreg) X{ X *mtabsize = sizeof(methods)/sizeof(methods[0]); X *unreg = NULL; X return methods; X} X Xstatic int X__nss_compat_gethostbyname2_r(void *retval, void *mdata, va_list ap) X{ X int s; X X const char *name; X int af; X struct hostent *hptr; X char *buffer; X size_t buflen; X int *errnop; X int *h_errnop; X X name = va_arg(ap, const char *); X af = va_arg(ap, int); X hptr = va_arg(ap, struct hostent *); X buffer = va_arg(ap, char *); X buflen = va_arg(ap, size_t); X errnop = va_arg(ap, int *); X h_errnop = va_arg(ap, int *); X X s = _nss_mdns_gethostbyname2_r( X name, af, hptr, buffer, buflen, errnop, h_errnop); X *(struct hostent **)retval = (s == NS_SUCCESS) ? hptr : NULL; X X return s; X} X Xstatic int X__nss_compat_gethostbyaddr_r(void *retval, void *mdata, va_list ap) X{ X int s; X X const void *addr; X socklen_t addrlen; X int af; X struct hostent *hptr; X char *buffer; X size_t buflen; X int *errnop; X int *h_errnop; X X addr = va_arg(ap, const void *); X addrlen = va_arg(ap, socklen_t); X af = va_arg(ap, int); X hptr = va_arg(ap, struct hostent *); X buffer = va_arg(ap, char *); X buflen = va_arg(ap, size_t); X errnop = va_arg(ap, int *); X h_errnop = va_arg(ap, int *); X X s = _nss_mdns_gethostbyaddr_r( X addr, addrlen, af, hptr, buffer, buflen, errnop, h_errnop); X *(struct hostent **)retval = (s == NS_SUCCESS) ? hptr : NULL; X X return s; X} X Xstatic void Xaiforaf(const char *name, int af, struct addrinfo *pai, struct addrinfo **aip) X{ X int s; X struct hostent host; X char hostbuf[8*1024]; X int err, herr; X char **addrp; X char addrstr[INET6_ADDRSTRLEN]; X struct addrinfo hints, *res0, *res; X X s = _nss_mdns_gethostbyname2_r(name, af, &host, hostbuf, sizeof(hostbuf), X &err, &herr); X if (s != NS_SUCCESS) X return; X X for (addrp = host.h_addr_list; *addrp; addrp++) { X /* XXX this sucks, but get_ai is not public */ X if (!inet_ntop(host.h_addrtype, *addrp, X addrstr, sizeof(addrstr))) X continue; X hints = *pai; X hints.ai_flags = AI_NUMERICHOST; X hints.ai_family = af; X if (getaddrinfo(addrstr, NULL, &hints, &res0)) X continue; X for (res = res0; res; res = res->ai_next) X res->ai_flags = pai->ai_flags; X X (*aip)->ai_next = res0; X while ((*aip)->ai_next) X *aip = (*aip)->ai_next; X } X} X Xstatic int X__nss_compat_getaddrinfo(void *retval, void *mdata, va_list ap) X{ X struct addrinfo sentinel, *cur; X const char *name; X struct addrinfo *ai; X X name = va_arg(ap, char *); X ai = va_arg(ap, struct addrinfo *); X X memset(&sentinel, 0, sizeof(sentinel)); X cur = &sentinel; X X if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET6)) X aiforaf(name, AF_INET6, ai, &cur); X if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET)) X aiforaf(name, AF_INET, ai, &cur); X X if (!sentinel.ai_next) { X h_errno = HOST_NOT_FOUND; X return NS_NOTFOUND; X } X *((struct addrinfo **)retval) = sentinel.ai_next; X X return NS_SUCCESS; X} X fd1c46f3f4a4f438620948d5ef5dcad0 echo x - mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c sed 's/^X//' >mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c << '04c37d337133d3147a842456f108671e' X--- ./mDNSPosix/nss_mdns.c.orig 2013-04-07 17:44:38.000000000 +0200 X+++ ./mDNSPosix/nss_mdns.c 2013-04-07 17:51:54.000000000 +0200 X@@ -379,7 +379,18 @@ X #define ENTNAME hostent X #define DATABASE "hosts" X X-#include <nss.h> X+#if defined __FreeBSD__ X+# include <nsswitch.h> X+enum nss_status { X+ NSS_STATUS_SUCCESS = NS_SUCCESS, X+ NSS_STATUS_NOTFOUND = NS_NOTFOUND, X+ NSS_STATUS_UNAVAIL = NS_UNAVAIL, X+ NSS_STATUS_TRYAGAIN = NS_TRYAGAIN, X+ NSS_STATUS_RETURN = NS_RETURN X+}; X+#elif defined __Linux__ X+# include <nss.h> X+#endif X // For nss_status X #include <netdb.h> X // For hostent 04c37d337133d3147a842456f108671e echo x - mDNSResponder_nss/Makefile sed 's/^X//' >mDNSResponder_nss/Makefile << '7e3b9888bc2028cc8d4b6de5e5439908' X# $FreeBSD$ X XPORTNAME= mDNSResponder_nss XPORTVERSION= 333.10 XCATEGORIES= dns net XMASTER_SITES= http://opensource.apple.com/tarballs/mDNSResponder/ XDISTNAME= ${PORTNAME:S/_nss//}-${PORTVERSION} X XMAINTAINER= mazhe@alkumuna.eu XCOMMENT= Apple\'s mDNS responder - FreeBSD nsswitch module X XLICENSE= AL2 BSD XLICENSE_COMB= dual X XLIB_DEPENDS= dns_sd:${PORTSDIR}/net/mDNSResponder X XCONFLICTS_INSTALL= dns/nss_mdns X XWRKSRC= ${WRKDIR}/${PORTNAME:S/_nss//}-${PORTVERSION} X XMAN5= nss_mdns.conf.5 XMANCOMPRESSED= no X Xpost-extract: X @${CP} ${FILESDIR}/nss_mdns_freebsd.c ${WRKSRC}/mDNSPosix X Xdo-build: X (cd ${WRKSRC}/mDNSPosix && ${CC} ${CFLAGS} -c -std=c99 -Wall -fPIC \ X -I. -I${PREFIX}/include -DPREFIX=\"${PREFIX}\" \ X nss_mdns.c nss_mdns_freebsd.c) X (cd ${WRKSRC}/mDNSPosix && ${LD} -shared nss_mdns.o nss_mdns_freebsd.o \ X -o nss_mdns.so.1 -L${PREFIX}/lib -R${PREFIX}/lib -ldns_sd) X Xdo-install: X ${INSTALL_LIB} ${WRKSRC}/mDNSPosix/nss_mdns.so.1 ${PREFIX}/lib X ${LN} -sf ${PREFIX}/lib/nss_mdns.so.1 ${PREFIX}/lib/nss_mdns.so X ${MKDIR} ${EXAMPLESDIR} X ${INSTALL_DATA} ${WRKSRC}/mDNSPosix/nss_mdns.conf ${EXAMPLESDIR} X ${INSTALL_MAN} ${WRKSRC}/mDNSPosix/nss_mdns.conf.5 ${MANPREFIX}/man/man5 X Xpost-install: X ${STRIP_CMD} ${PREFIX}/lib/nss_mdns.so.1 X X.include <bsd.port.mk> 7e3b9888bc2028cc8d4b6de5e5439908 echo x - mDNSResponder_nss/distinfo sed 's/^X//' >mDNSResponder_nss/distinfo << 'e71e320fe90ee26782adad7d882aface' XSHA256 (mDNSResponder-333.10.tar.gz) = 3624e39022c9210b819e94423c02f9ae12550cc21511ca979ab87e0c2212967b XSIZE (mDNSResponder-333.10.tar.gz) = 1937483 e71e320fe90ee26782adad7d882aface echo x - mDNSResponder_nss/pkg-descr sed 's/^X//' >mDNSResponder_nss/pkg-descr << '07f8ea0275e014c1f4a148c27143e2e7' XThis is a nsswitch plugin from Apple's mDNSResponder code, adapted for FreeBSD's Xnsswitch and libc. 07f8ea0275e014c1f4a148c27143e2e7 echo x - mDNSResponder_nss/pkg-plist sed 's/^X//' >mDNSResponder_nss/pkg-plist << '58c811c6c92a205f1ff5b1ae9e5fef5e' Xlib/nss_mdns.so Xlib/nss_mdns.so.1 X%%EXAMPLESDIR%%/nss_mdns.conf X@dirrm %%EXAMPLESDIR%% 58c811c6c92a205f1ff5b1ae9e5fef5e exit >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304221259.r3MCxNSr063338>