Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add nss_mdns, a nsswitch plugin for host lookups vis mDNS ("...
details: https://anonhg.NetBSD.org/src/rev/ba456a76da2d
branches: trunk
changeset: 747899:ba456a76da2d
user: tsarna <tsarna%NetBSD.org@localhost>
date: Mon Oct 05 03:54:17 2009 +0000
description:
Add nss_mdns, a nsswitch plugin for host lookups vis mDNS ("Bonjour"),
eg "hostname.local". This is a work in progress, but basically
functional. (note: this requires mdnsd to be running.)
diffstat:
distrib/sets/lists/base/shl.mi | 3 +-
external/apache2/mDNSResponder/Makefile | 4 +-
external/apache2/mDNSResponder/nss/Makefile | 36 +
external/apache2/mDNSResponder/nss/nss_mdns.c | 673 ++++++++++++++++++++++++++
4 files changed, 713 insertions(+), 3 deletions(-)
diffs (truncated from 745 to 300 lines):
diff -r a529a31f2b76 -r ba456a76da2d distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi Mon Oct 05 03:44:01 2009 +0000
+++ b/distrib/sets/lists/base/shl.mi Mon Oct 05 03:54:17 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.495 2009/10/04 22:06:34 christos Exp $
+# $NetBSD: shl.mi,v 1.496 2009/10/05 03:54:17 tsarna Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -166,6 +166,7 @@
./usr/lib/libutil.so.7.17 base-sys-shlib
./usr/lib/libwrap.so.1.0 base-net-shlib
./usr/lib/libz.so.1.0 base-sys-shlib
+./usr/lib/nss_mdns.so.0 base-mdns-shlib mdns
./usr/lib/security/pam_afslog.so.3 base-sys-shlib kerberos,pam
./usr/lib/security/pam_chroot.so.3 base-sys-shlib pam
./usr/lib/security/pam_deny.so.3 base-sys-shlib pam
diff -r a529a31f2b76 -r ba456a76da2d external/apache2/mDNSResponder/Makefile
--- a/external/apache2/mDNSResponder/Makefile Mon Oct 05 03:44:01 2009 +0000
+++ b/external/apache2/mDNSResponder/Makefile Mon Oct 05 03:54:17 2009 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: Makefile,v 1.1 2009/09/29 23:56:27 tsarna Exp $
+# $NetBSD: Makefile,v 1.2 2009/10/05 03:54:17 tsarna Exp $
-SUBDIR= usr.bin usr.sbin
+SUBDIR= usr.bin usr.sbin nss
.include <bsd.subdir.mk>
diff -r a529a31f2b76 -r ba456a76da2d external/apache2/mDNSResponder/nss/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/external/apache2/mDNSResponder/nss/Makefile Mon Oct 05 03:54:17 2009 +0000
@@ -0,0 +1,36 @@
+# $NetBSD: Makefile,v 1.1 2009/10/05 03:54:17 tsarna Exp $
+
+LIB= nss_mdns
+SHLIB_MAJOR= 0
+
+NOLINT= # don't build a lint library
+NOPROFILE= # don't build a profile library
+NOPICINSTALL= # don't install _pic.a library
+
+.include <bsd.own.mk>
+
+.include "${.CURDIR}/../Makefile.inc"
+
+SRCS= nss_mdns.c
+LDADD+= -ldns_sd
+DPADD+= ${LIBDNS_SD}
+
+.if ${MKPIC} != "no"
+.PRECIOUS: ${DESTDIR}${LIBDIR}/${LIB}.so.${SHLIB_MAJOR}
+libinstall:: ${DESTDIR}${LIBDIR}/${LIB}.so.${SHLIB_MAJOR}
+.else
+libinstall::
+.endif
+
+.include <bsd.lib.mk>
+
+${DESTDIR}${LIBDIR}/${LIB}.so.${SHLIB_MAJOR}: lib${LIB}.so.${SHLIB_FULLVERSION}
+ ${_MKTARGET_INSTALL}
+ ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${.ALLSRC} ${.TARGET}
+
+#.if defined(LD32DIR)
+#LIBDIR=/usr/lib/${LD32DIR}
+#.else
+#LIBDIR=/usr/lib
+#.endif
diff -r a529a31f2b76 -r ba456a76da2d external/apache2/mDNSResponder/nss/nss_mdns.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/external/apache2/mDNSResponder/nss/nss_mdns.c Mon Oct 05 03:54:17 2009 +0000
@@ -0,0 +1,673 @@
+/* $NetBSD: nss_mdns.c,v 1.1 2009/10/05 03:54:17 tsarna Exp $ */
+
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Tyler C. Sarna
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Multicast DNS ("Bonjour") hosts name service switch
+ *
+ * Documentation links:
+ *
+ * http://developer.apple.com/bonjour/
+ * http://www.multicastdns.org/
+ * http://www.dns-sd.org/
+ */
+
+#include <nsswitch.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/param.h>
+#include <netdb.h>
+#include <arpa/nameser.h>
+#include <dns_sd.h>
+#include <poll.h>
+#include <string.h>
+#include <stdio.h>
+
+#ifndef lint
+#define UNUSED(a) (void)&a
+#else
+#define UNUSED(a) a = a
+#endif
+
+#if defined(__NetBSD__) && (__NetBSD_Version__ < 599002000)
+static struct addrinfo *
+allocaddrinfo(socklen_t addrlen)
+{
+ struct addrinfo *ai;
+
+ ai = calloc(sizeof(struct addrinfo) + addrlen, 1);
+ if (ai) {
+ ai->ai_addrlen = addrlen;
+ ai->ai_addr = (void *)(ai+1);
+ }
+
+ return ai;
+}
+#endif
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+typedef struct callback_ctx {
+ int done;
+} callback_ctx;
+
+typedef struct hostent_ctx {
+ callback_ctx cb_ctx; /* must come first */
+ struct hostent host;
+ char *h_addr_ptrs[MAXADDRS + 1];
+ char *host_aliases[MAXALIASES];
+ char addrs[MAXADDRS * 16];
+ char buf[8192], *next;
+ int done, naliases, naddrs;
+} hostent_ctx;
+
+typedef struct addrinfo_ctx {
+ callback_ctx cb_ctx; /* must come first */
+ struct addrinfo start, *last;
+} addrinfo_ctx;
+
+#define HCTX_BUFLEFT(c) (sizeof((c)->buf) - ((c)->next - (c)->buf))
+
+static hostent_ctx h_ctx;
+
+
+static int _mdns_getaddrinfo(void *cbrv, void *cbdata, va_list ap);
+static int _mdns_gethtbyaddr(void *cbrv, void *cbdata, va_list ap);
+static int _mdns_gethtbyname(void *cbrv, void *cbdata, va_list ap);
+
+static void _mdns_addrinfo_init(addrinfo_ctx *ctx, const struct addrinfo *ai);
+static void _mdns_addrinfo_add_ai(addrinfo_ctx *ctx, struct addrinfo *ai);
+static struct addrinfo *_mdns_addrinfo_done(addrinfo_ctx *ctx);
+
+static void _mdns_hostent_init(hostent_ctx *ctx, int af, int addrlen);
+static void _mdns_hostent_add_host(hostent_ctx *ctx, const char *name);
+static void _mdns_hostent_add_addr(hostent_ctx *ctx, const void *addr, uint16_t len);
+static struct hostent *_mdns_hostent_done(hostent_ctx *ctx);
+
+static void _mdns_addrinfo_cb(DNSServiceRef sdRef, DNSServiceFlags flags,
+ uint32_t interfaceIndex, DNSServiceErrorType errorCode,
+ const char *hostname, const struct sockaddr *address, uint32_t ttl,
+ void *context);
+static void _mdns_hostent_cb(DNSServiceRef sdRef, DNSServiceFlags flags,
+ uint32_t interfaceIndex, DNSServiceErrorType errorCode,
+ const char *fullname, uint16_t rrtype, uint16_t rrclass,
+ uint16_t rdlen, const void *rdata, uint32_t ttl, void *context);
+static void _mdns_eventloop(DNSServiceRef sdRef, callback_ctx *ctx);
+
+static char *_mdns_rdata2name(const unsigned char *rdata, uint16_t rdlen,
+ char *buf, size_t buflen);
+
+
+static ns_mtab mtab[] = {
+ { NSDB_HOSTS, "getaddrinfo", _mdns_getaddrinfo, NULL },
+ { NSDB_HOSTS, "gethostbyaddr", _mdns_gethtbyaddr, NULL },
+ { NSDB_HOSTS, "gethostbyname", _mdns_gethtbyname, NULL },
+};
+
+
+
+ns_mtab *
+nss_module_register(const char *source, u_int *nelems,
+ nss_module_unregister_fn *unreg)
+{
+ UNUSED(source);
+ UNUSED(unreg);
+
+ *nelems = sizeof(mtab) / sizeof(mtab[0]);
+ *unreg = NULL;
+
+ return mtab;
+}
+
+
+
+static int
+_mdns_getaddrinfo(void *cbrv, void *cbdata, va_list ap)
+{
+ const struct addrinfo *pai;
+ const char *name;
+ addrinfo_ctx ctx;
+ DNSServiceProtocol proto;
+ DNSServiceErrorType err;
+ DNSServiceRef sdRef;
+
+ UNUSED(cbdata);
+
+ name = va_arg(ap, char *);
+ pai = va_arg(ap, struct addrinfo *);
+
+ //XXX check valid name space
+
+ switch (pai->ai_family) {
+ case AF_UNSPEC:
+ proto = kDNSServiceProtocol_IPv6 | kDNSServiceProtocol_IPv4;
+ break;
+
+ case AF_INET6:
+ proto = kDNSServiceProtocol_IPv6;
+ break;
+
+ case AF_INET:
+ proto = kDNSServiceProtocol_IPv4;
+ break;
+
+ default:
+ return NS_UNAVAIL;
+ }
+
+ _mdns_addrinfo_init(&ctx, pai);
+
+ err = DNSServiceGetAddrInfo(
+ &sdRef,
+ kDNSServiceFlagsForceMulticast,
+ kDNSServiceInterfaceIndexAny,
+ proto,
+ name,
+ _mdns_addrinfo_cb,
+ &ctx
+ );
+
+ if (err) {
+ h_errno = NETDB_INTERNAL;
+ return NS_UNAVAIL;
+ }
+
+ _mdns_eventloop(sdRef, (void *)&h_ctx);
+
+ DNSServiceRefDeallocate(sdRef);
+
+ if (ctx.start.ai_next) {
+ *(struct addrinfo **)cbrv = _mdns_addrinfo_done(&ctx);
+
+ return NS_SUCCESS;
+ } else {
+ return NS_NOTFOUND;
+ }
+}
+
+
+
+static int
+_mdns_gethtbyaddr(void *cbrv, void *cbdata, va_list ap)
+{
+ const unsigned char *addr;
+ int addrlen, af;
+ char qbuf[NS_MAXDNAME + 1], *qp, *ep;
+ int advance, n;
+ DNSServiceErrorType err;
+ DNSServiceRef sdRef;
+
Home |
Main Index |
Thread Index |
Old Index