Subject: bin/3504: two ypserv problems: logging and NIS v1 support
To: None <gnats-bugs@gnats.netbsd.org>
From: Brian Baird <brb@brig.com>
List: netbsd-bugs
Date: 04/16/1997 02:34:51
>Number:         3504
>Category:       bin
>Synopsis:       two ypserv problems: logging and NIS v1 support
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 16 03:05:01 1997
>Last-Modified:
>Originator:     Brian Baird
>Organization:
Brian Baird				Brig Systems, Pleasanton CA
brb@brig.com				+1 510 484 1342
>Release:        1.2D 970415
>Environment:
System: NetBSD tardis.brig.com 1.2D NetBSD 1.2D (BRIG) #1: Fri Apr 11 05:05:34 PDT 1997 brb@tardis.brig.com:/u/netbsd/ksrc-970326/sys/arch/i386/compile/BRIG i386

>Description:
	ypserv's man page says that it only logs into /var/yp/ypserv.log
	if it exists.  The code does an fopen(,"a") which always
	creates the file.

	SunOS 4's ypbind makes some simple NIS version 1 rpc calls in
	order to talk to ypserv (v1 domain_nonack at least).  Our
	ypserv supports only NIS v2 procedures. The first three rpc
	procedures (null, domain, and domain_nonack) are identical
	between NIS v1 and v2, so support for them is trivial.  With
	support for these v1 calls, SunOS 4 clients work fine talking
	to a NetBSD ypserv.  FYI: SunOS 4's ypserv appears to have
	complete NIS v1 support, but Solaris's ypserv (or moral
	equivalent) only supports the above noted three v1 procedures.

>How-To-Repeat:
	rm /var/yp/ypserv.log; ypserv; ls -l /var/yp/ypserv.log

	Use NetBSD as a NIS server for a network that has SunOS 4
	client machines.  Note the "NIS: server not responding..."
	messages.
>Fix:
--- src/usr.sbin/ypserv/common/yplog.c.dist	Mon Oct 14 10:08:08 1996
+++ src/usr.sbin/ypserv/common/yplog.c	Thu Apr 10 02:33:53 1997
@@ -37,6 +37,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <stdio.h>
 #include <unistd.h>
 
@@ -85,7 +86,8 @@
 {
         time_t t;
 
-	if (!logfp) return;
+	if (logfp == NULL)
+		return;
 	(void)time(&t);
 	fprintf(logfp,"%.15s ", ctime(&t) + 4);
 	vfprintf(logfp, fmt, ap);
@@ -100,8 +102,14 @@
 void
 ypopenlog()
 {
-	logfp = fopen("/var/yp/ypserv.log", "a");
-	if (!logfp) return;
+	struct stat sbuf;
+	static char logfn[] = "/var/yp/ypserv.log";
+
+	if (stat(logfn, &sbuf) < 0)
+		return;
+	logfp = fopen(logfn, "a");
+	if (logfp == NULL)
+		return;
 	yplog("yplog opened");
 }
 
--- src/usr.sbin/ypserv/ypserv/ypserv.c.dist	Wed Mar  5 04:25:10 1997
+++ src/usr.sbin/ypserv/ypserv/ypserv.c	Wed Apr 16 01:39:25 1997
@@ -238,6 +238,28 @@
 	return;
 }
 
+/*
+ * limited NIS version 1 support: the null, domain, and domain_nonack
+ * request/reply format is identical between v1 and v2.  SunOS4's ypbind
+ * makes v1 domain_nonack calls.
+ */
+static void
+ypprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
+{
+	switch (rqstp->rq_proc) {
+	case YPPROC_NULL:
+	case YPPROC_DOMAIN:
+	case YPPROC_DOMAIN_NONACK:
+		ypprog_2(rqstp, transp);
+		return;
+
+	default:
+		svcerr_noproc(transp);
+		_rpcsvcdirty = 0;
+		return;
+	}
+}
+
 int
 main(argc, argv)
 	int argc;
@@ -297,6 +319,7 @@
 
 	sock = RPC_ANYSOCK;
 	(void) pmap_unset(YPPROG, YPVERS);
+	(void) pmap_unset(YPPROG, YPVERS_ORIG);
 
 	ypopenlog();	/* open log file */
 	ypdb_init();	/* init db stuff */
@@ -312,6 +335,10 @@
 		}
 		if (!_rpcpmstart)
 			proto = IPPROTO_UDP;
+		if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1, proto)) {
+			_msgout("unable to register (YPPROG, YPVERS_ORIG, udp).");
+			exit(1);
+		}
 		if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
 			_msgout("unable to register (YPPROG, YPVERS, udp).");
 			exit(1);
@@ -329,6 +356,10 @@
 		}
 		if (!_rpcpmstart)
 			proto = IPPROTO_TCP;
+		if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1, proto)) {
+			_msgout("unable to register (YPPROG, YPVERS_ORIG, tcp).");
+			exit(1);
+		}
 		if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
 			_msgout("unable to register (YPPROG, YPVERS, tcp).");
 			exit(1);
>Audit-Trail:
>Unformatted: