Module Name:    src
Committed By:   tsarna
Date:           Thu Oct  1 16:36:21 UTC 2009

Modified Files:
        src/etc/defaults: rc.conf
        src/external/apache2/mDNSResponder/dist/mDNSPosix: PosixDaemon.c
            mDNSPosix.c
        src/external/apache2/mDNSResponder/usr.sbin: Makefile.inc

Log Message:
mdnsd enhancements and fixes:

- Enhance the built-in drop-privs support and use it instead of
  having the rc.conf do it. Avoids log error on startup.
  From OpenSolaris, with enhancements.
- Add dumping of the unicast server list to the DumpStateLog
  debugging output, a'la Mac OS X.
- Fix a locking botch that caused warnings in the log.
- Fix FILE leak. From OpenSolaris.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/etc/defaults/rc.conf
cvs rdiff -u -r1.1.1.1 -r1.2 \
    src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c
cvs rdiff -u -r1.2 -r1.3 \
    src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c
cvs rdiff -u -r1.1 -r1.2 \
    src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/defaults/rc.conf
diff -u src/etc/defaults/rc.conf:1.108 src/etc/defaults/rc.conf:1.109
--- src/etc/defaults/rc.conf:1.108	Tue Sep 29 23:56:27 2009
+++ src/etc/defaults/rc.conf	Thu Oct  1 16:36:20 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: rc.conf,v 1.108 2009/09/29 23:56:27 tsarna Exp $
+#	$NetBSD: rc.conf,v 1.109 2009/10/01 16:36:20 tsarna Exp $
 #
 # /etc/defaults/rc.conf --
 #	default configuration of /etc/rc.conf
@@ -160,7 +160,7 @@
 
 # Networking startup.
 #
-mdnsd=NO		mdnsd_user="_mdnsd"
+mdnsd=NO
 ipfilter=NO		ipfilter_flags=""	# uses /etc/ipf.conf
 ipnat=NO					# uses /etc/ipnat.conf
 ipfs=NO			ipfs_flags=""		# save/load ipnat and ipf states

Index: src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c
diff -u src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c:1.1.1.1 src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c:1.2
--- src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c:1.1.1.1	Tue Sep 29 22:14:13 2009
+++ src/external/apache2/mDNSResponder/dist/mDNSPosix/PosixDaemon.c	Thu Oct  1 16:36:20 2009
@@ -101,8 +101,13 @@
 #include "mDNSPosix.h"
 #include "mDNSUNP.h"		// For daemon()
 #include "uds_daemon.h"
+#include "DNSCommon.h"
 #include "PlatformCommon.h"
 
+#ifndef MDNSD_USER
+#define MDNSD_USER "nobody"
+#endif
+
 #define CONFIG_FILE "/etc/mdnsd.conf"
 static domainname DynDNSZone;                // Default wide-area zone for service registration
 static domainname DynDNSHostname;
@@ -143,8 +148,10 @@
 	mDNSAddr DynDNSIP;
 	const mDNSAddr dummy = { mDNSAddrType_IPv4, { { { 1, 1, 1, 1 } } } };;
 	mDNS_SetPrimaryInterfaceInfo(m, NULL, NULL, NULL);
+        mDNS_Lock(m);
 	if (ParseDNSServers(m, uDNS_SERVERS_FILE) < 0)
 		LogMsg("Unable to parse DNS server list. Unicast DNS-SD unavailable");
+        mDNS_Unlock(m);
 	ReadDDNSSettingsFromConfFile(m, CONFIG_FILE, &DynDNSHostname, &DynDNSZone, NULL);
 	mDNSPlatformSourceAddrForDest(&DynDNSIP, &dummy);
 	if (DynDNSHostname.c[0]) mDNS_AddDynDNSHostName(m, &DynDNSHostname, NULL, NULL);
@@ -175,8 +182,26 @@
 mDNSlocal void DumpStateLog(mDNS *const m)
 // Dump a little log of what we've been up to.
 	{
+	DNSServer *s;
+
 	LogMsg("---- BEGIN STATE LOG ----");
 	udsserver_info(m);
+
+        LogMsgNoIdent("--------- DNS Servers ----------");
+        if (!mDNSStorage.DNSServers) LogMsgNoIdent("<None>");
+        else
+                {               
+                for (s = m->DNSServers; s; s = s->next)
+                        {
+                        LogMsgNoIdent("DNS Server %##s %#a:%d %s",
+                                s->domain.c, &s->addr, mDNSVal16(s->port),
+                                s->teststate == DNSServer_Untested ? "(Untested)" :
+                                s->teststate == DNSServer_Passed   ? ""           :
+                                s->teststate == DNSServer_Failed   ? "(Failed)"   :
+                                s->teststate == DNSServer_Disabled ? "(Disabled)" : "(Unknown state)");
+                        }
+                }               
+
 	LogMsg("----  END STATE LOG  ----");
 	}
 
@@ -241,11 +266,21 @@
 	// Now that we're finished with anything privileged, switch over to running as "nobody"
 	if (mStatus_NoError == err)
 		{
-		const struct passwd *pw = getpwnam("nobody");
+		const struct passwd *pw = getpwnam(MDNSD_USER);
 		if (pw != NULL)
+		        {
+			setgid(pw->pw_gid);
 			setuid(pw->pw_uid);
+		        }
 		else
-			LogMsg("WARNING: mdnsd continuing as root because user \"nobody\" does not exist");
+#ifdef MDNSD_NOROOT
+                        {
+    			LogMsg("WARNING: mdnsd exiting because user \""MDNSD_USER"\" does not exist");
+                        err = mStatus_Invalid;
+                        }
+#else
+    			LogMsg("WARNING: mdnsd continuing as root because user \""MDNSD_USER"\" does not exist");
+#endif
 		}
 
 	if (mStatus_NoError == err)

Index: src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c
diff -u src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c:1.2 src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c:1.3
--- src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c:1.2	Tue Sep 29 23:56:28 2009
+++ src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c	Thu Oct  1 16:36:20 2009
@@ -600,6 +600,7 @@
 			numOfServers++;
 			}
 		}  
+	fclose(fp);
 	return (numOfServers > 0) ? 0 : -1;
 	}
 

Index: src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc
diff -u src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc:1.1 src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc:1.2
--- src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc:1.1	Tue Sep 29 23:56:34 2009
+++ src/external/apache2/mDNSResponder/usr.sbin/Makefile.inc	Thu Oct  1 16:36:20 2009
@@ -1,7 +1,9 @@
-# $NetBSD: Makefile.inc,v 1.1 2009/09/29 23:56:34 tsarna Exp $
+# $NetBSD: Makefile.inc,v 1.2 2009/10/01 16:36:20 tsarna Exp $
 
 .include <bsd.own.mk>
 
 .include "${.PARSEDIR}/../Makefile.inc"
 
+CPPFLAGS+=      -DMDNSD_NOROOT -DMDNSD_USER=\"_mdnsd\"
+
 BINDIR?=	/usr/sbin

Reply via email to