Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Aug 2014 19:07:26 +0000 (UTC)
From:      Kurt Jaeger <pi@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r364862 - in head/dns: . mDNSResponder_nss mDNSResponder_nss/files
Message-ID:  <201408141907.s7EJ7QhE052078@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pi
Date: Thu Aug 14 19:07:26 2014
New Revision: 364862
URL: http://svnweb.freebsd.org/changeset/ports/364862
QAT: https://qat.redports.org/buildarchive/r364862/

Log:
  New port: dns/mDNSResponder_nss
  
  This is a nsswitch plugin from Apple's mDNSResponder code, adapted
  for FreeBSD's nsswitch and libc.
  
  WWW: https://developer.apple.com/bonjour/
  WWW: http://opensource.apple.com/tarballs/mDNSResponder/
  
  PR:		178052
  Submitted by:	Matthieu Volat <mazhe@alkumuna.eu>

Added:
  head/dns/mDNSResponder_nss/
  head/dns/mDNSResponder_nss/Makefile   (contents, props changed)
  head/dns/mDNSResponder_nss/distinfo   (contents, props changed)
  head/dns/mDNSResponder_nss/files/
  head/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c   (contents, props changed)
  head/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c   (contents, props changed)
  head/dns/mDNSResponder_nss/pkg-descr   (contents, props changed)
  head/dns/mDNSResponder_nss/pkg-plist   (contents, props changed)
Modified:
  head/dns/Makefile

Modified: head/dns/Makefile
==============================================================================
--- head/dns/Makefile	Thu Aug 14 18:45:19 2014	(r364861)
+++ head/dns/Makefile	Thu Aug 14 19:07:26 2014	(r364862)
@@ -78,6 +78,7 @@
     SUBDIR += linux-f10-libasyncns
     SUBDIR += maradns
     SUBDIR += maradns1
+    SUBDIR += mDNSResponder_nss
     SUBDIR += mdnsd
     SUBDIR += mydns
     SUBDIR += mydns-ng

Added: head/dns/mDNSResponder_nss/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/Makefile	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,41 @@
+# $FreeBSD$
+
+PORTNAME=	mDNSResponder_nss
+PORTVERSION=	544
+CATEGORIES=	dns net
+MASTER_SITES=	http://opensource.apple.com/tarballs/mDNSResponder/
+DISTNAME=	${PORTNAME:S/_nss//}-${PORTVERSION}
+
+MAINTAINER=	mazhe@alkumuna.eu
+COMMENT=	Apple mDNS responder - FreeBSD nsswitch module
+
+LICENSE=	APACHE20 BSD3CLAUSE
+LICENSE_COMB=	dual
+
+LIB_DEPENDS=	libdns_sd.so:${PORTSDIR}/net/mDNSResponder
+
+CONFLICTS_INSTALL=	dns/nss_mdns
+
+WRKSRC=		${WRKDIR}/${PORTNAME:S/_nss//}-${PORTVERSION}
+
+post-extract:
+	@${CP} ${FILESDIR}/nss_mdns_freebsd.c ${WRKSRC}/mDNSPosix
+
+do-build:
+	(cd ${WRKSRC}/mDNSPosix && ${CC} ${CFLAGS} -c -std=c99 -Wall -fPIC \
+		-I. -I${PREFIX}/include -DPREFIX=\"${PREFIX}\" \
+		nss_mdns.c nss_mdns_freebsd.c)
+	(cd ${WRKSRC}/mDNSPosix && ${LD} -shared nss_mdns.o nss_mdns_freebsd.o \
+		-o nss_mdns.so.1 -L${PREFIX}/lib -R${PREFIX}/lib -ldns_sd)
+
+do-install:
+	${INSTALL_LIB} ${WRKSRC}/mDNSPosix/nss_mdns.so.1 ${STAGEDIR}${PREFIX}/lib
+	${LN} -sf ${PREFIX}/lib/nss_mdns.so.1 ${STAGEDIR}${PREFIX}/lib/nss_mdns.so
+	${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
+	${INSTALL_DATA} ${WRKSRC}/mDNSPosix/nss_mdns.conf ${STAGEDIR}${EXAMPLESDIR}
+	${INSTALL_MAN} ${WRKSRC}/mDNSPosix/nss_mdns.conf.5 ${STAGEDIR}${MANPREFIX}/man/man5
+
+post-install:
+	${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/nss_mdns.so.1
+
+.include <bsd.port.mk>

Added: head/dns/mDNSResponder_nss/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/distinfo	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,2 @@
+SHA256 (mDNSResponder-544.tar.gz) = c6ad1d53c28d28c0e3689bdf5efd9ce6f5c4c3692e8ad76e5eeb4d0c248929ac
+SIZE (mDNSResponder-544.tar.gz) = 2153326

Added: head/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,156 @@
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <nsswitch.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+extern int _nss_mdns_gethostbyname2_r(const char *, int,
+		struct hostent *, char *, size_t, int *, int *);
+extern int _nss_mdns_gethostbyaddr_r(const void *, socklen_t, int,
+		struct hostent *, char *, size_t, int *, int *);
+
+static NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname2_r);
+static NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyaddr_r);
+static NSS_METHOD_PROTOTYPE(__nss_compat_getaddrinfo);
+
+static ns_mtab methods[] = {
+	{ NSDB_HOSTS, "gethostbyname_r", __nss_compat_gethostbyname2_r, NULL },
+	{ NSDB_HOSTS, "gethostbyname2_r", __nss_compat_gethostbyname2_r, NULL },
+	{ NSDB_HOSTS, "gethostbyaddr_r", __nss_compat_gethostbyaddr_r, NULL },
+	{ NSDB_HOSTS, "getaddrinfo", __nss_compat_getaddrinfo, NULL },
+};
+
+ns_mtab *
+nss_module_register(const char *source, unsigned int *mtabsize,
+		nss_module_unregister_fn *unreg)
+{
+	*mtabsize = sizeof(methods)/sizeof(methods[0]);
+	*unreg = NULL;
+	return methods;
+}
+
+static int
+__nss_compat_gethostbyname2_r(void *retval, void *mdata, va_list ap)
+{
+	int s;
+
+	const char *name;
+	int af;
+	struct hostent *hptr;
+	char *buffer;
+	size_t buflen;
+	int *errnop;
+	int *h_errnop;
+
+	name = va_arg(ap, const char *);
+	af = va_arg(ap, int);
+	hptr = va_arg(ap, struct hostent *);
+	buffer = va_arg(ap, char *);
+	buflen = va_arg(ap, size_t);
+	errnop = va_arg(ap, int *);
+	h_errnop = va_arg(ap, int *);
+
+	s = _nss_mdns_gethostbyname2_r(
+			name, af, hptr, buffer, buflen, errnop, h_errnop);
+	*(struct hostent **)retval = (s == NS_SUCCESS) ? hptr : NULL;
+
+	return s;
+}
+
+static int
+__nss_compat_gethostbyaddr_r(void *retval, void *mdata, va_list ap)
+{
+	int s;
+	
+	const void *addr;
+	socklen_t addrlen;
+	int af;
+	struct hostent *hptr;
+	char *buffer;
+	size_t buflen;
+	int *errnop;
+	int *h_errnop;
+
+    addr = va_arg(ap, const void *);
+    addrlen = va_arg(ap, socklen_t);
+    af = va_arg(ap, int);
+    hptr = va_arg(ap, struct hostent *);
+    buffer = va_arg(ap, char *);
+    buflen = va_arg(ap, size_t);
+    errnop = va_arg(ap, int *);
+    h_errnop = va_arg(ap, int *);
+
+	s = _nss_mdns_gethostbyaddr_r(
+			addr, addrlen, af, hptr, buffer, buflen, errnop, h_errnop);
+	*(struct hostent **)retval = (s == NS_SUCCESS) ? hptr : NULL;
+
+	return s;
+} 
+
+static void
+aiforaf(const char *name, int af, struct addrinfo *pai, struct addrinfo **aip)
+{
+	int s;
+	struct hostent host;
+	char hostbuf[8*1024];
+	int err, herr;
+	char **addrp;
+	char addrstr[INET6_ADDRSTRLEN];
+	struct addrinfo hints, *res0, *res;
+
+	s = _nss_mdns_gethostbyname2_r(name, af, &host, hostbuf, sizeof(hostbuf),
+			&err, &herr);
+	if (s != NS_SUCCESS)
+		return;
+
+	for (addrp = host.h_addr_list; *addrp; addrp++) {
+		/* XXX this sucks, but get_ai is not public */
+		if (!inet_ntop(host.h_addrtype, *addrp,
+			       addrstr, sizeof(addrstr)))
+			continue;
+		hints = *pai;
+		hints.ai_flags = AI_NUMERICHOST;
+		hints.ai_family = af;
+		if (getaddrinfo(addrstr, NULL, &hints, &res0))
+			continue;
+		for (res = res0; res; res = res->ai_next)
+			res->ai_flags = pai->ai_flags;
+
+		(*aip)->ai_next = res0;
+		while ((*aip)->ai_next)
+			*aip = (*aip)->ai_next;
+	}
+}
+
+static int
+__nss_compat_getaddrinfo(void *retval, void *mdata, va_list ap)
+{
+	struct addrinfo sentinel, *cur;
+	const char *name;
+	struct addrinfo *ai;
+
+	name  = va_arg(ap, char *);
+	ai = va_arg(ap, struct addrinfo *);
+
+	memset(&sentinel, 0, sizeof(sentinel));
+	cur = &sentinel;
+
+	if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET6))
+		aiforaf(name, AF_INET6, ai, &cur);
+	if ((ai->ai_family == AF_UNSPEC) || (ai->ai_family == AF_INET))
+		aiforaf(name, AF_INET, ai, &cur);
+
+	if (!sentinel.ai_next) {
+		h_errno = HOST_NOT_FOUND;
+		return NS_NOTFOUND;
+	}
+	*((struct addrinfo **)retval) = sentinel.ai_next;
+
+	return NS_SUCCESS;
+}
+

Added: head/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,31 @@
+--- ./mDNSPosix/nss_mdns.c.orig	2012-04-15 08:07:19.000000000 +0200
++++ ./mDNSPosix/nss_mdns.c	2013-11-05 11:00:14.000000000 +0100
+@@ -379,7 +379,18 @@
+ #define ENTNAME  hostent
+ #define DATABASE "hosts"
+ 
+-#include <nss.h>
++#if defined __FreeBSD__
++# include <nsswitch.h>
++enum nss_status {
++  NSS_STATUS_SUCCESS = NS_SUCCESS,
++  NSS_STATUS_NOTFOUND = NS_NOTFOUND,
++  NSS_STATUS_UNAVAIL = NS_UNAVAIL,
++  NSS_STATUS_TRYAGAIN = NS_TRYAGAIN,
++  NSS_STATUS_RETURN = NS_RETURN
++};
++#elif defined __Linux__
++# include <nss.h>
++#endif
+ // For nss_status
+ #include <netdb.h>
+ // For hostent
+@@ -1684,7 +1695,7 @@
+ //----------
+ // Types and Constants
+ 
+-const char * k_conf_file = "/etc/nss_mdns.conf";
++const char * k_conf_file = PREFIX"/etc/nss_mdns.conf";
+ #define CONF_LINE_SIZE 1024
+ 
+ const char k_comment_char = '#';

Added: head/dns/mDNSResponder_nss/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/pkg-descr	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,5 @@
+This is a nsswitch plugin from Apple's mDNSResponder code, adapted
+for FreeBSD's nsswitch and libc.
+
+WWW: https://developer.apple.com/bonjour/
+WWW: http://opensource.apple.com/tarballs/mDNSResponder/

Added: head/dns/mDNSResponder_nss/pkg-plist
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/dns/mDNSResponder_nss/pkg-plist	Thu Aug 14 19:07:26 2014	(r364862)
@@ -0,0 +1,5 @@
+lib/nss_mdns.so
+lib/nss_mdns.so.1
+man/man5/nss_mdns.conf.5.gz
+%%EXAMPLESDIR%%/nss_mdns.conf
+@dirrm %%EXAMPLESDIR%%



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408141907.s7EJ7QhE052078>