diff options
author | pi <pi@FreeBSD.org> | 2014-08-15 03:07:26 +0800 |
---|---|---|
committer | pi <pi@FreeBSD.org> | 2014-08-15 03:07:26 +0800 |
commit | c0063913a1458c8a93b3a09db7ce504bac70e54b (patch) | |
tree | aa73dcbb4e136334560254515a5345e4ae346301 /dns | |
parent | 9cb2e1bf3a1f73fe1d19eb4f6a4c09a2b1c43299 (diff) | |
download | freebsd-ports-gnome-c0063913a1458c8a93b3a09db7ce504bac70e54b.tar.gz freebsd-ports-gnome-c0063913a1458c8a93b3a09db7ce504bac70e54b.tar.zst freebsd-ports-gnome-c0063913a1458c8a93b3a09db7ce504bac70e54b.zip |
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>
Diffstat (limited to 'dns')
-rw-r--r-- | dns/Makefile | 1 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/Makefile | 41 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/distinfo | 2 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/files/nss_mdns_freebsd.c | 156 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c | 31 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/pkg-descr | 5 | ||||
-rw-r--r-- | dns/mDNSResponder_nss/pkg-plist | 5 |
7 files changed, 241 insertions, 0 deletions
diff --git a/dns/Makefile b/dns/Makefile index 4b897c7cfd8d..4ef3e025923c 100644 --- a/dns/Makefile +++ b/dns/Makefile @@ -78,6 +78,7 @@ SUBDIR += linux-f10-libasyncns SUBDIR += maradns SUBDIR += maradns1 + SUBDIR += mDNSResponder_nss SUBDIR += mdnsd SUBDIR += mydns SUBDIR += mydns-ng diff --git a/dns/mDNSResponder_nss/Makefile b/dns/mDNSResponder_nss/Makefile new file mode 100644 index 000000000000..ce57e84b9e10 --- /dev/null +++ b/dns/mDNSResponder_nss/Makefile @@ -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> diff --git a/dns/mDNSResponder_nss/distinfo b/dns/mDNSResponder_nss/distinfo new file mode 100644 index 000000000000..ee78b1934d72 --- /dev/null +++ b/dns/mDNSResponder_nss/distinfo @@ -0,0 +1,2 @@ +SHA256 (mDNSResponder-544.tar.gz) = c6ad1d53c28d28c0e3689bdf5efd9ce6f5c4c3692e8ad76e5eeb4d0c248929ac +SIZE (mDNSResponder-544.tar.gz) = 2153326 diff --git a/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c b/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c new file mode 100644 index 000000000000..bf05ea63793d --- /dev/null +++ b/dns/mDNSResponder_nss/files/nss_mdns_freebsd.c @@ -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; +} + diff --git a/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c b/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c new file mode 100644 index 000000000000..9a8bc516b039 --- /dev/null +++ b/dns/mDNSResponder_nss/files/patch-mDNSPosix__nss_mdns.c @@ -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 = '#'; diff --git a/dns/mDNSResponder_nss/pkg-descr b/dns/mDNSResponder_nss/pkg-descr new file mode 100644 index 000000000000..f1ac1dee840c --- /dev/null +++ b/dns/mDNSResponder_nss/pkg-descr @@ -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/ diff --git a/dns/mDNSResponder_nss/pkg-plist b/dns/mDNSResponder_nss/pkg-plist new file mode 100644 index 000000000000..5726b8614252 --- /dev/null +++ b/dns/mDNSResponder_nss/pkg-plist @@ -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%% |