CVS commit: src/usr.sbin/ypbind

2018-03-14 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Thu Mar 15 02:25:31 UTC 2018

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Initialize ypbind_resp before first possible error return condition.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2018-03-14 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Thu Mar 15 02:25:31 UTC 2018

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Initialize ypbind_resp before first possible error return condition.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.99 src/usr.sbin/ypbind/ypbind.c:1.100
--- src/usr.sbin/ypbind/ypbind.c:1.99	Wed Aug  9 01:56:42 2017
+++ src/usr.sbin/ypbind/ypbind.c	Thu Mar 15 02:25:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.99 2017/08/09 01:56:42 ginsbach Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.100 2018/03/15 02:25:31 ginsbach Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef LINT
-__RCSID("$NetBSD: ypbind.c,v 1.99 2017/08/09 01:56:42 ginsbach Exp $");
+__RCSID("$NetBSD: ypbind.c,v 1.100 2018/03/15 02:25:31 ginsbach Exp $");
 #endif
 
 #include 
@@ -710,15 +710,15 @@ ypbindproc_domain_2(SVCXPRT *transp, voi
 
 	DPRINTF("ypbindproc_domain_2 %s\n", arg);
 
+	(void)memset(, 0, sizeof res);
+	res.ypbind_status = YPBIND_FAIL_VAL;
+
 	/* Reject invalid domains. */
 	if (_yp_invalid_domain(arg)) {
 		res.ypbind_respbody.ypbind_error = YPBIND_ERR_NOSERV;
 		return 
 	}
 
-	(void)memset(, 0, sizeof res);
-	res.ypbind_status = YPBIND_FAIL_VAL;
-
 	/*
 	 * Look for the domain. XXX: Behave erratically if we have
 	 * more than 100 domains. The intent here is to avoid allowing



CVS commit: src/usr.sbin/ypbind

2017-08-08 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Wed Aug  9 01:56:42 UTC 2017

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Make use of the defined YP errors when ypbind encounters one rather than
just returning an empty (successful) RPC result.

Don't exit when allocating memory for a new bound domain received via a RPC.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.98 src/usr.sbin/ypbind/ypbind.c:1.99
--- src/usr.sbin/ypbind/ypbind.c:1.98	Tue Jun 10 17:19:48 2014
+++ src/usr.sbin/ypbind/ypbind.c	Wed Aug  9 01:56:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.98 2014/06/10 17:19:48 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.99 2017/08/09 01:56:42 ginsbach Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef LINT
-__RCSID("$NetBSD: ypbind.c,v 1.98 2014/06/10 17:19:48 dholland Exp $");
+__RCSID("$NetBSD: ypbind.c,v 1.99 2017/08/09 01:56:42 ginsbach Exp $");
 #endif
 
 #include 
@@ -314,7 +314,7 @@ domain_create(const char *name)
 	dom = malloc(sizeof *dom);
 	if (dom == NULL) {
 		yp_log(LOG_ERR, "domain_create: Out of memory");
-		exit(1);
+		return NULL;
 	}
 
 	dom->dom_next = NULL;
@@ -483,7 +483,7 @@ rpc_is_valid_response(char *name, struct
  *
  * whose meaning isn't entirely clear.
  */
-static void
+static int
 rpc_received(char *dom_name, struct sockaddr_in *raddrp, int force,
 	 int is_ypset)
 {
@@ -498,7 +498,7 @@ rpc_received(char *dom_name, struct sock
 
 	/* validate some stuff */
 	if (!rpc_is_valid_response(dom_name, raddrp)) {
-		return;
+		return 0;
 	}
 
 	/* look for the domain */
@@ -509,8 +509,10 @@ rpc_received(char *dom_name, struct sock
 	/* if not found, create it, but only if FORCE; otherwise ignore */
 	if (dom == NULL) {
 		if (force == 0)
-			return;
+			return 0;
 		dom = domain_create(dom_name);
+		if (dom == NULL)
+			return 0;
 	}
 
 	/* the domain needs to know if it's been explicitly ypset */
@@ -536,7 +538,7 @@ rpc_received(char *dom_name, struct sock
 			   inet_ntoa(dom->dom_server_addr.sin_addr),
 			   dom->dom_name);
 		}
-		return;
+		return 0;
 	}
 
 	/*
@@ -563,7 +565,7 @@ rpc_received(char *dom_name, struct sock
 			   inet_ntoa(dom->dom_server_addr.sin_addr),
 			   dom->dom_name);
 		}
-		return;
+		return 0;
 	}
 
 #ifdef HEURISTIC
@@ -647,7 +649,7 @@ rpc_received(char *dom_name, struct sock
 		(void)close(dom->dom_lockfd);
 
 	if ((fd = makelock(dom)) == -1)
-		return;
+		return 0;
 
 	dom->dom_lockfd = fd;
 
@@ -672,7 +674,10 @@ rpc_received(char *dom_name, struct sock
 		(void)close(dom->dom_lockfd);
 		removelock(dom);
 		dom->dom_lockfd = -1;
+		return 0;
 	}
+
+	return 1;
 }
 
 /*
@@ -706,8 +711,10 @@ ypbindproc_domain_2(SVCXPRT *transp, voi
 	DPRINTF("ypbindproc_domain_2 %s\n", arg);
 
 	/* Reject invalid domains. */
-	if (_yp_invalid_domain(arg))
-		return NULL;
+	if (_yp_invalid_domain(arg)) {
+		res.ypbind_respbody.ypbind_error = YPBIND_ERR_NOSERV;
+		return 
+	}
 
 	(void)memset(, 0, sizeof res);
 	res.ypbind_status = YPBIND_FAIL_VAL;
@@ -724,8 +731,10 @@ ypbindproc_domain_2(SVCXPRT *transp, voi
 	for (count = 0, dom = domains;
 	dom != NULL;
 	dom = dom->dom_next, count++) {
-		if (count > 100)
-			return NULL;		/* prevent denial of service */
+		if (count > 100) {
+			res.ypbind_respbody.ypbind_error = YPBIND_ERR_RESC;
+			return 		/* prevent denial of service */
+		}
 		if (!strcmp(dom->dom_name, arg))
 			break;
 	}
@@ -742,15 +751,21 @@ ypbindproc_domain_2(SVCXPRT *transp, voi
 	 */
 	if (dom == NULL) {
 		dom = domain_create(arg);
-		removelock(dom);
-		check++;
-		DPRINTF("unknown domain %s\n", arg);
-		return NULL;
+		if (dom != NULL) {
+			removelock(dom);
+			check++;
+			DPRINTF("unknown domain %s\n", arg);
+			res.ypbind_respbody.ypbind_error = YPBIND_ERR_NOSERV;
+		} else {
+			res.ypbind_respbody.ypbind_error = YPBIND_ERR_RESC;
+		}
+		return 
 	}
 
 	if (dom->dom_state == DOM_NEW) {
 		DPRINTF("new domain %s\n", arg);
-		return NULL;
+		res.ypbind_respbody.ypbind_error = YPBIND_ERR_NOSERV;
+		return 
 	}
 
 #ifdef HEURISTIC
@@ -864,11 +879,12 @@ ypbindproc_setdom_2(SVCXPRT *transp, voi
 	bindsin.sin_len = sizeof(bindsin);
 	bindsin.sin_addr = sd->ypsetdom_addr;
 	bindsin.sin_port = sd->ypsetdom_port;
-	rpc_received(sd->ypsetdom_domain, , 1, 1);
+	if (rpc_received(sd->ypsetdom_domain, , 1, 1)) {
+		DPRINTF("ypset to %s for domain %s succeeded\n",
+			inet_ntoa(bindsin.sin_addr), sd->ypsetdom_domain);
+		res = 1;
+	}
 
-	DPRINTF("ypset to %s for domain %s succeeded\n",
-		inet_ntoa(bindsin.sin_addr), sd->ypsetdom_domain);
-	res = 1;
 	return 
 }
 
@@ -1244,7 +1260,7 @@ try_again:
 			raddr.sin_port = htons((uint16_t)rmtcr_port);
 			dom = 

CVS commit: src/usr.sbin/ypbind

2017-08-08 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Wed Aug  9 01:56:42 UTC 2017

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Make use of the defined YP errors when ypbind encounters one rather than
just returning an empty (successful) RPC result.

Don't exit when allocating memory for a new bound domain received via a RPC.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-09-20 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Sep 20 11:16:05 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Add missing .El. From Henning Petersen in PR 49227.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/ypbind/ypbind.8

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.8
diff -u src/usr.sbin/ypbind/ypbind.8:1.20 src/usr.sbin/ypbind/ypbind.8:1.21
--- src/usr.sbin/ypbind/ypbind.8:1.20	Sun Jun 15 07:24:32 2014
+++ src/usr.sbin/ypbind/ypbind.8	Sat Sep 20 11:16:05 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: ypbind.8,v 1.20 2014/06/15 07:24:32 wiz Exp $
+.\	$NetBSD: ypbind.8,v 1.21 2014/09/20 11:16:05 wiz Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -138,6 +138,7 @@ to immediately retry any unbound domains
 exponential backoff.
 Use this to resume immediately after a long network outage is
 resolved.
+.El
 .Sh FILES
 .Pa /var/yp/binding/\*[Lt]domain\*[Gt].version
 - binding file for \*[Lt]domain\*[Gt].



CVS commit: src/usr.sbin/ypbind

2014-09-20 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Sep 20 11:16:05 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Add missing .El. From Henning Petersen in PR 49227.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/ypbind/ypbind.8

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



Re: CVS commit: src/usr.sbin/ypbind

2014-06-15 Thread David Holland
On Wed, Jun 11, 2014 at 04:23:09AM +1000, matthew green wrote:
   Add a SIGHUP handler; upon SIGHUP do an extra nag_servers on any
   domain that's in DEAD state. This lets you explicitly rescue ypbind
   from its exponential backoff when you know the world's back up.
  
  sounds like something useful to add to the manual?

fixed btw
-- 
David A. Holland
dholl...@netbsd.org


CVS commit: src/usr.sbin/ypbind

2014-06-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jun 15 07:24:32 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Use more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/ypbind/ypbind.8

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.8
diff -u src/usr.sbin/ypbind/ypbind.8:1.19 src/usr.sbin/ypbind/ypbind.8:1.20
--- src/usr.sbin/ypbind/ypbind.8:1.19	Sun Jun 15 01:37:48 2014
+++ src/usr.sbin/ypbind/ypbind.8	Sun Jun 15 07:24:32 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: ypbind.8,v 1.19 2014/06/15 01:37:48 dholland Exp $
+.\	$NetBSD: ypbind.8,v 1.20 2014/06/15 07:24:32 wiz Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -131,7 +131,7 @@ options are inherently insecure and shou
 .Nm
 responds to the following signals:
 .Bl -tag -width TERM -compact
-.It HUP
+.It Dv HUP
 causes
 .Nm
 to immediately retry any unbound domains that are currently in
@@ -158,7 +158,10 @@ facility.
 .Xr yppoll 8 ,
 .Xr ypset 8
 .Sh AUTHORS
+.An -nosplit
 This version of
 .Nm
-was originally implemented by Theo de Raadt.
-The ypservers support was implemented by Luke Mewburn.
+was originally implemented by
+.An Theo de Raadt .
+The ypservers support was implemented by
+.An Luke Mewburn .



CVS commit: src/usr.sbin/ypbind

2014-06-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jun 15 07:24:32 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Use more markup.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/ypbind/ypbind.8

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



CVS commit: src/usr.sbin/ypbind

2014-06-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jun 15 01:37:48 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Document exponential backoff behavior and SIGHUP support, plus a couple
other minor edits.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/ypbind/ypbind.8

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.8
diff -u src/usr.sbin/ypbind/ypbind.8:1.18 src/usr.sbin/ypbind/ypbind.8:1.19
--- src/usr.sbin/ypbind/ypbind.8:1.18	Wed Apr 30 13:11:03 2008
+++ src/usr.sbin/ypbind/ypbind.8	Sun Jun 15 01:37:48 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: ypbind.8,v 1.18 2008/04/30 13:11:03 martin Exp $
+.\	$NetBSD: ypbind.8,v 1.19 2014/06/15 01:37:48 dholland Exp $
 .\
 .\ Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd February 26, 2005
+.Dd June 14, 2014
 .Dt YPBIND 8
 .Os
 .Sh NAME
@@ -94,9 +94,9 @@ it is bound.
 If the binding is somehow lost, e.g by server reboot,
 .Nm
 marks the domain as unbound and attempts to re-establish the binding.
-When the binding is once again successful,
+If a binding cannot be re-established within 60 seconds,
 .Nm
-marks the domain as bound and resumes its periodic check.
+backs off exponentially to trying only once per hour.
 .Pp
 The options are as follows:
 .Bl -tag -width -broadcast
@@ -114,7 +114,7 @@ or
 servers.
 .It Fl ypset
 .Xr ypset 8
-may be used to change the server to which a domain is bound.
+may be used from anywhere to change the server to which a domain is bound.
 .It Fl ypsetme
 .Xr ypset 8
 may be used only from this machine to change the server
@@ -122,11 +122,22 @@ to which a domain is bound.
 .El
 .Pp
 The
-.Fl broadcast
+.Fl broadcast ,
 .Fl ypset ,
 and
-.Fl ypsetme ,
+.Fl ypsetme
 options are inherently insecure and should be avoided.
+.Sh SIGNALS
+.Nm
+responds to the following signals:
+.Bl -tag -width TERM -compact
+.It HUP
+causes
+.Nm
+to immediately retry any unbound domains that are currently in
+exponential backoff.
+Use this to resume immediately after a long network outage is
+resolved.
 .Sh FILES
 .Pa /var/yp/binding/\*[Lt]domain\*[Gt].version
 - binding file for \*[Lt]domain\*[Gt].



CVS commit: src/usr.sbin/ypbind

2014-06-14 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jun 15 01:37:48 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.8

Log Message:
Document exponential backoff behavior and SIGHUP support, plus a couple
other minor edits.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/ypbind/ypbind.8

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:02 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't store the default domain name in a global. While running we
really don't care which domain is the system's default domain.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.90 src/usr.sbin/ypbind/ypbind.c:1.91
--- src/usr.sbin/ypbind/ypbind.c:1.90	Tue Aug 30 17:06:22 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:18:02 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.90 2011/08/30 17:06:22 plunky Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.90 2011/08/30 17:06:22 plunky Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -102,8 +102,6 @@ struct domain {
 
 #define BUFSIZE		1400
 
-static char *domainname;
-
 static struct domain *domains;
 static int check;
 
@@ -1173,6 +1171,7 @@ main(int argc, char *argv[])
 	fd_set fdsr;
 	int width, lockfd;
 	int evil = 0;
+	char *domainname;
 
 	setprogname(argv[0]);
 	(void)yp_get_default_domain(domainname);



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:18 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Factor out some rpc validation code.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.91 src/usr.sbin/ypbind/ypbind.c:1.92
--- src/usr.sbin/ypbind/ypbind.c:1.91	Tue Jun 10 17:18:02 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:18:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -342,6 +342,28 @@ purge_bindingdir(const char *dirpath)
 // sunrpc twaddle
 
 /*
+ * Check if the info coming in is (at least somewhat) valid.
+ */
+static int
+rpc_is_valid_response(char *name, struct sockaddr_in *addr)
+{
+	if (name == NULL) {
+		return 0;
+	}
+
+	if (_yp_invalid_domain(name)) {
+		return 0;
+	}
+
+	/* don't support insecure servers by default */
+	if (!insecure  ntohs(addr-sin_port) = IPPORT_RESERVED) {
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
  * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
  */
 static void
@@ -357,15 +379,9 @@ rpc_received(char *dom_name, struct sock
 	DPRINTF(returned from %s about %s\n,
 		inet_ntoa(raddrp-sin_addr), dom_name);
 
-	if (dom_name == NULL)
-		return;
-
-	if (_yp_invalid_domain(dom_name))
-		return;	
-
-		/* don't support insecure servers by default */
-	if (!insecure  ntohs(raddrp-sin_port) = IPPORT_RESERVED)
+	if (!rpc_is_valid_response(dom_name, raddrp)) {
 		return;
+	}
 
 	for (dom = domains; dom != NULL; dom = dom-dom_next)
 		if (!strcmp(dom-dom_name, dom_name))



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:00 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't rake up the default domain until after processing arguments.
Processing arguments just sets flags -- may as well do it first, and
this way detection of silly errors isn't contingent on having things
fully configured and operating.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.93 src/usr.sbin/ypbind/ypbind.c:1.94
--- src/usr.sbin/ypbind/ypbind.c:1.93	Tue Jun 10 17:18:45 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:19:00 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.93 2014/06/10 17:18:45 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.94 2014/06/10 17:19:00 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.93 2014/06/10 17:18:45 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.94 2014/06/10 17:19:00 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -1190,14 +1190,8 @@ main(int argc, char *argv[])
 	char *domainname;
 
 	setprogname(argv[0]);
-	(void)yp_get_default_domain(domainname);
-	if (domainname[0] == '\0')
-		errx(1, Domainname not set. Aborting.);
-	if (_yp_invalid_domain(domainname))
-		errx(1, Invalid domainname: %s, domainname);
 
 	default_ypbindmode = YPBIND_DIRECT;
-
 	while (--argc) {
 		++argv;
 		if (!strcmp(-insecure, *argv)) {
@@ -1219,6 +1213,12 @@ main(int argc, char *argv[])
 		}
 	}
 
+	(void)yp_get_default_domain(domainname);
+	if (domainname[0] == '\0')
+		errx(1, Domainname not set. Aborting.);
+	if (_yp_invalid_domain(domainname))
+		errx(1, Invalid domainname: %s, domainname);
+
 	/* initialise syslog */
 	openlog(ypbind, LOG_PERROR | LOG_PID, LOG_DAEMON);
 



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:45 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
While there are times it's appropriate to call a state variable
evil, this isn't one of them. Since the logic involved is to wait
until the default domain binds before backgrounding, call the variable
started instead.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.92 src/usr.sbin/ypbind/ypbind.c:1.93
--- src/usr.sbin/ypbind/ypbind.c:1.92	Tue Jun 10 17:18:18 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:18:45 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.93 2014/06/10 17:18:45 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.93 2014/06/10 17:18:45 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -1186,7 +1186,7 @@ main(int argc, char *argv[])
 	struct timeval tv;
 	fd_set fdsr;
 	int width, lockfd;
-	int evil = 0;
+	int started = 0;
 	char *domainname;
 
 	setprogname(argv[0]);
@@ -1271,8 +1271,8 @@ main(int argc, char *argv[])
 			break;
 		}
 
-		if (!evil  domains-dom_alive) {
-			evil = 1;
+		if (!started  domains-dom_alive) {
+			started = 1;
 #ifdef DEBUG
 			if (!debug)
 #endif



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:12 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Load up with comments.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.94 src/usr.sbin/ypbind/ypbind.c:1.95
--- src/usr.sbin/ypbind/ypbind.c:1.94	Tue Jun 10 17:19:00 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:19:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.94 2014/06/10 17:19:00 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.95 2014/06/10 17:19:12 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.94 2014/06/10 17:19:00 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.95 2014/06/10 17:19:12 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -102,24 +102,33 @@ struct domain {
 
 #define BUFSIZE		1400
 
+/* the list of all domains */
 static struct domain *domains;
 static int check;
 
+/* option settings */
 static ypbind_mode_t default_ypbindmode;
-
 static int allow_local_ypset = 0, allow_any_ypset = 0;
 static int insecure;
 
+/* the sockets we use to interact with servers */
 static int rpcsock, pingsock;
+
+/* stuff used for manually interacting with servers */
 static struct rmtcallargs rmtca;
 static struct rmtcallres rmtcr;
 static bool_t rmtcr_outval;
 static unsigned long rmtcr_port;
+
+/* The ypbind service transports */
 static SVCXPRT *udptransp, *tcptransp;
 
 
 // utilities
 
+/*
+ * Combo of open() and flock().
+ */
 static int
 open_locked(const char *path, int flags, mode_t mode)
 {
@@ -148,6 +157,9 @@ static int debug;
 
 static void yp_log(int, const char *, ...) __printflike(2, 3);
 
+/*
+ * Log some stuff, to syslog or stderr depending on the debug setting.
+ */
 static void
 yp_log(int pri, const char *fmt, ...)
 {
@@ -185,6 +197,20 @@ ypservers_filename(const char *domain)
 
 // struct domain
 
+/*
+ * State transition is done like this: 
+ *
+ * STATE	EVENT		ACTION			NEWSTATE	TIMEOUT
+ * no binding	timeout		broadcast 		no binding	5 sec
+ * no binding	answer		--			binding		60 sec
+ * binding	timeout		ping server		checking	5 sec
+ * checking	timeout		ping server + broadcast	checking	5 sec
+ * checking	answer		--			binding		60 sec
+ */
+
+/*
+ * Look up a domain by the XID we assigned it.
+ */
 static struct domain *
 domain_find(uint32_t xid)
 {
@@ -196,6 +222,11 @@ domain_find(uint32_t xid)
 	return dom;
 }
 
+/*
+ * Pick an XID for a domain.
+ *
+ * XXX: this should just generate a random number.
+ */
 static uint32_t
 unique_xid(struct domain *dom)
 {
@@ -208,6 +239,10 @@ unique_xid(struct domain *dom)
 	return tmp_xid;
 }
 
+/*
+ * Construct a new domain. Adds it to the global linked list of all
+ * domains.
+ */
 static struct domain *
 domain_create(const char *name)
 {
@@ -263,6 +298,10 @@ domain_create(const char *name)
 
 // locks
 
+/*
+ * Open a new binding file. Does not write the contents out; the
+ * caller (there's only one) does that.
+ */
 static int
 makelock(struct domain *dom)
 {
@@ -284,6 +323,9 @@ makelock(struct domain *dom)
 	return fd;
 }
 
+/*
+ * Remove a binding file.
+ */
 static void
 removelock(struct domain *dom)
 {
@@ -295,12 +337,14 @@ removelock(struct domain *dom)
 }
 
 /*
- * purge_bindingdir: remove old binding files (i.e. rm BINDINGDIR\/\*.[0-9])
+ * purge_bindingdir: remove old binding files (i.e. rm *.[0-9] in BINDINGDIR)
+ *
+ * The local YP functions [e.g. yp_master()] will fail without even
+ * talking to ypbind if there is a stale (non-flock'd) binding file
+ * present.
  *
- * local YP functions [e.g. yp_master()] will fail without even talking
- * to ypbind if there is a stale (non-flock'd) binding file present.
- * we have to scan the entire BINDINGDIR for binding files, because
- * ypbind may bind more than just the yp_get_default_domain() domain.
+ * We have to remove all binding files in BINDINGDIR, not just the one
+ * for the default domain.
  */
 static int
 purge_bindingdir(const char *dirpath)
@@ -364,7 +408,17 @@ rpc_is_valid_response(char *name, struct
 }
 
 /*
- * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
+ * Take note of the fact that we've received a reply from a ypserver.
+ * Or, in the case of being ypset, that we've been ypset, which
+ * functions much the same.
+ *
+ * Note that FORCE is set if and only if IS_YPSET is set.
+ *
+ * This function has also for the past 20+ years carried the annotation
+ *
+ *  LOOPBACK IS MORE IMPORTANT: PUT IN HACK
+ *
+ * whose meaning isn't entirely clear.
  */
 static void
 

CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:48 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Log state transitions.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.97 src/usr.sbin/ypbind/ypbind.c:1.98
--- src/usr.sbin/ypbind/ypbind.c:1.97	Tue Jun 10 17:19:36 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:19:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.98 2014/06/10 17:19:48 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.98 2014/06/10 17:19:48 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -628,6 +628,12 @@ rpc_received(char *dom_name, struct sock
 	dom-dom_losttime = 0;
 	dom-dom_backofftime = 10;
 
+	if (is_ypset == 0) {
+		yp_log(LOG_NOTICE, Domain %s is alive; server %s,
+		   dom-dom_name,
+		   inet_ntoa(dom-dom_server_addr.sin_addr));
+	}
+
 	/*
 	 * Generate a new binding file. If this fails, forget about it.
 	 * (But we keep the binding and we'll report it to anyone who
@@ -1514,6 +1520,9 @@ checkwork(void)
 			dom-dom_state = DOM_LOST;
 			dom-dom_losttime = t;
 			dom-dom_checktime = t + 5;
+			yp_log(LOG_NOTICE, Domain %s lost its binding to 
+			   server %s, dom-dom_name,
+			   inet_ntoa(dom-dom_server_addr.sin_addr));
 			(void)nag_servers(dom);
 			break;
 
@@ -1521,6 +1530,9 @@ checkwork(void)
 			if (t  dom-dom_losttime + 60) {
 dom-dom_state = DOM_DEAD;
 dom-dom_backofftime = 10;
+yp_log(LOG_NOTICE, Domain %s dead; 
+   going to exponential backoff,
+   dom-dom_name);
 			}
 			dom-dom_checktime = t + 5;
 			(void)nag_servers(dom);



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:22 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Instead of using magic numbers in what looks like a boolean
(dom_alive), create a state enumeration (domainstates) and use it
instead.

Instead of three states (new, alive, and, effectively, 'troubled') go
to five: new, alive, pinging, lost, and dead.

Domains start in the NEW state. When we get a reply from a server, the
state goes to ALIVE. The state is set to PINGING when we ping the
server (once a minute normally) and if the ping times out, it goes to
LOST. If we stay lost for a minute, go to DEAD, and in DEAD, do
exponential backoff of nag_servers calls.

Getting rid of the broken logic attached to the 'troubled' state fixes
PR 15355 (ypbind defeats disk idle spindown) -- it will now only
rewrite the binding file when the binding changes.

Also, fix the HEURISTIC code so it doesn't trigger except in ALIVE
state. I think this was the source of a lot of the spamming behavior
seen in PR 32519, which is now fixed.

Might also fix PR 23135 (broadcast ypbind sometimes fails to find
servers).


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.95 src/usr.sbin/ypbind/ypbind.c:1.96
--- src/usr.sbin/ypbind/ypbind.c:1.95	Tue Jun 10 17:19:12 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:19:22 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.95 2014/06/10 17:19:12 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.95 2014/06/10 17:19:12 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -84,16 +84,26 @@ typedef enum {
 	YPBIND_DIRECT, YPBIND_BROADCAST,
 } ypbind_mode_t;
 
+enum domainstates {
+	DOM_NEW,		/* not yet bound */
+	DOM_ALIVE,		/* bound and healthy */
+	DOM_PINGING,		/* ping outstanding */
+	DOM_LOST,		/* binding timed out, looking for a new one */
+	DOM_DEAD,		/* long-term lost, in exponential backoff */
+};
+
 struct domain {
 	struct domain *dom_next;
 
 	char dom_name[YPMAXDOMAIN + 1];
 	struct sockaddr_in dom_server_addr;
 	long dom_vers;
-	time_t dom_checktime;
-	time_t dom_asktime;
+	time_t dom_checktime;		/* time of next check/contact */
+	time_t dom_asktime;		/* time we were last DOMAIN'd */
+	time_t dom_losttime;		/* time the binding was lost, or 0 */
+	unsigned dom_backofftime;	/* current backoff period, when DEAD */
 	int dom_lockfd;
-	int dom_alive;
+	enum domainstates dom_state;
 	uint32_t dom_xid;
 	FILE *dom_serversfile;		/* /var/yp/binding/foo.ypservers */
 	int dom_been_ypset;		/* ypset been done on this domain? */
@@ -145,6 +155,39 @@ open_locked(const char *path, int flags,
 	return fd;
 }
 
+/*
+ * Exponential backoff for pinging servers for a dead domain.
+ *
+ * We go 10 - 20 - 40 - 60 seconds, then 2 - 4 - 8 - 15 - 30 -
+ * 60 minutes, and stay at 60 minutes. This is overengineered.
+ *
+ * With a 60 minute max backoff the response time for when things come
+ * back is not awful, but we only try (and log) about 60 times even if
+ * things are down for a whole long weekend. This is an acceptable log
+ * load, I think.
+ */
+static void
+backoff(unsigned *psecs)
+{
+	unsigned secs;
+
+	secs = *psecs;
+	if (secs  60) {
+		secs *= 2;
+		if (secs  60) {
+			secs = 60;
+		}
+	} else if (secs  60 * 15) {
+		secs *= 2;
+		if (secs  60 * 15) {
+			secs = 60 * 15;
+		}
+	} else if (secs  60 * 60) {
+		secs *= 2;
+	}
+	*psecs = secs;
+}
+
 
 // logging
 
@@ -198,14 +241,28 @@ ypservers_filename(const char *domain)
 // struct domain
 
 /*
- * State transition is done like this: 
+ * The state transitions of a domain work as follows:
  *
- * STATE	EVENT		ACTION			NEWSTATE	TIMEOUT
- * no binding	timeout		broadcast 		no binding	5 sec
- * no binding	answer		--			binding		60 sec
- * binding	timeout		ping server		checking	5 sec
- * checking	timeout		ping server + broadcast	checking	5 sec
- * checking	answer		--			binding		60 sec
+ * in state NEW:
+ *nag_servers every 5 seconds
+ *upon answer, state is ALIVE
+ *
+ * in state ALIVE:
+ *every 60 seconds, send ping and switch to state PINGING
+ *
+ * in state PINGING:
+ *upon answer, go to state ALIVE
+ *if no answer in 5 seconds, go to state LOST and do nag_servers
+ *
+ * in state LOST:
+ *do nag_servers every 5 seconds
+ *upon answer, go to state ALIVE
+ *if no answer in 60 seconds, go to state DEAD
+ *
+ * in state DEAD
+ *do nag_servers every backofftime seconds (starts at 10)
+ *upon answer go 

CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:36 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Add a SIGHUP handler; upon SIGHUP do an extra nag_servers on any
domain that's in DEAD state. This lets you explicitly rescue ypbind
from its exponential backoff when you know the world's back up.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.96 src/usr.sbin/ypbind/ypbind.c:1.97
--- src/usr.sbin/ypbind/ypbind.c:1.96	Tue Jun 10 17:19:22 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:19:36 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.96 2014/06/10 17:19:22 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.97 2014/06/10 17:19:36 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -50,6 +50,7 @@ __RCSID($NetBSD: ypbind.c,v 1.96 2014/0
 #include ifaddrs.h
 #include limits.h
 #include netdb.h
+#include signal.h
 #include stdarg.h
 #include stdio.h
 #include stdlib.h
@@ -133,6 +134,9 @@ static unsigned long rmtcr_port;
 /* The ypbind service transports */
 static SVCXPRT *udptransp, *tcptransp;
 
+/* set if we get SIGHUP */
+static sig_atomic_t hupped;
+
 
 // utilities
 
@@ -1533,6 +1537,51 @@ checkwork(void)
 	}
 }
 
+/*
+ * Process a hangup signal.
+ *
+ * Do an extra nag_servers() for any domains that are DEAD. This way
+ * if you know things are back up you can restore service by sending
+ * ypbind a SIGHUP rather than waiting for the timeout period.
+ */
+static void
+dohup(void)
+{
+	struct domain *dom;
+
+	hupped = 0;
+	for (dom = domains; dom != NULL; dom = dom-dom_next) {
+		if (dom-dom_state == DOM_DEAD) {
+			(void)nag_servers(dom);
+		}
+	}
+}
+
+/*
+ * Receive a hangup signal.
+ */
+static void
+hup(int __unused sig)
+{
+	hupped = 1;
+}
+
+/*
+ * Initialize hangup processing.
+ */
+static void
+starthup(void)
+{
+	struct sigaction sa;
+
+	sa.sa_handler = hup;
+	sigemptyset(sa.sa_mask);
+	sa.sa_flags = SA_RESTART;
+	if (sigaction(SIGHUP, sa, NULL) == -1) {
+		err(1, sigaction);
+	}
+}
+
 
 // main
 
@@ -1615,6 +1664,9 @@ main(int argc, char *argv[])
 	if (lockfd == -1)
 		err(1, Cannot create %s, _PATH_YPBIND_LOCK);
 
+	/* Accept hangups. */
+	starthup();
+
 	/* Initialize sunrpc stuff. */
 	sunrpc_setup();
 
@@ -1672,12 +1724,24 @@ main(int argc, char *argv[])
 		switch (select(width, fdsr, NULL, NULL, tv)) {
 		case 0:
 			/* select timed out - check for timer-based work */
+			if (hupped) {
+dohup();
+			}
 			checkwork();
 			break;
 		case -1:
-			yp_log(LOG_WARNING, select: %s, strerror(errno));
+			if (hupped) {
+dohup();
+			}
+			if (errno != EINTR) {
+yp_log(LOG_WARNING, select: %s,
+   strerror(errno));
+			}
 			break;
 		default:
+			if (hupped) {
+dohup();
+			}
 			/* incoming of our own; read it */
 			if (FD_ISSET(rpcsock, fdsr))
 (void)handle_replies();
@@ -1716,4 +1780,3 @@ main(int argc, char *argv[])
 		}
 	}
 }
-



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:02 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't store the default domain name in a global. While running we
really don't care which domain is the system's default domain.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:45 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
While there are times it's appropriate to call a state variable
evil, this isn't one of them. Since the logic involved is to wait
until the default domain binds before backgrounding, call the variable
started instead.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:18:18 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Factor out some rpc validation code.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:00 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't rake up the default domain until after processing arguments.
Processing arguments just sets flags -- may as well do it first, and
this way detection of silly errors isn't contingent on having things
fully configured and operating.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:12 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Load up with comments.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:22 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Instead of using magic numbers in what looks like a boolean
(dom_alive), create a state enumeration (domainstates) and use it
instead.

Instead of three states (new, alive, and, effectively, 'troubled') go
to five: new, alive, pinging, lost, and dead.

Domains start in the NEW state. When we get a reply from a server, the
state goes to ALIVE. The state is set to PINGING when we ping the
server (once a minute normally) and if the ping times out, it goes to
LOST. If we stay lost for a minute, go to DEAD, and in DEAD, do
exponential backoff of nag_servers calls.

Getting rid of the broken logic attached to the 'troubled' state fixes
PR 15355 (ypbind defeats disk idle spindown) -- it will now only
rewrite the binding file when the binding changes.

Also, fix the HEURISTIC code so it doesn't trigger except in ALIVE
state. I think this was the source of a lot of the spamming behavior
seen in PR 32519, which is now fixed.

Might also fix PR 23135 (broadcast ypbind sometimes fails to find
servers).


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:36 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Add a SIGHUP handler; upon SIGHUP do an extra nag_servers on any
domain that's in DEAD state. This lets you explicitly rescue ypbind
from its exponential backoff when you know the world's back up.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2014-06-10 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Jun 10 17:19:48 UTC 2014

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Log state transitions.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:56:16 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Sort contents of file.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.67 src/usr.sbin/ypbind/ypbind.c:1.68
--- src/usr.sbin/ypbind/ypbind.c:1.67	Mon May 23 02:54:53 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:56:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.67 2011/05/23 02:54:53 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.68 2011/05/24 06:56:16 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.67 2011/05/23 02:54:53 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.68 2011/05/24 06:56:16 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -68,14 +68,21 @@
 
 #include pathnames.h
 
+#define YPSERVERSSUFF	.ypservers
+#define BINDINGDIR	(_PATH_VAR_YP binding)
+
 #ifndef O_SHLOCK
 #define O_SHLOCK 0
 #endif
 
-#define BUFSIZE		1400
+int _yp_invalid_domain(const char *);		/* XXX libc internal */
 
-#define YPSERVERSSUFF	.ypservers
-#define BINDINGDIR	(_PATH_VAR_YP binding)
+
+// types and globals
+
+typedef enum {
+	YPBIND_DIRECT, YPBIND_BROADCAST, YPBIND_SETLOCAL, YPBIND_SETALL
+} ypbind_mode_t;
 
 struct _dom_binding {
 	struct _dom_binding *dom_pnext;
@@ -91,15 +98,13 @@
 	uint32_t dom_xid;
 };
 
+#define BUFSIZE		1400
+
 static char *domainname;
 
 static struct _dom_binding *ypbindlist;
 static int check;
 
-typedef enum {
-	YPBIND_DIRECT, YPBIND_BROADCAST, YPBIND_SETLOCAL, YPBIND_SETALL
-} ypbind_mode_t;
-
 ypbind_mode_t ypbindmode;
 
 /*
@@ -109,13 +114,6 @@
  */
 int been_ypset;
 
-#ifdef DEBUG
-#define DPRINTF(...) (debug ? (void)printf(__VA_ARGS__) : (void)0)
-static int debug;
-#else
-#define DPRINTF(...)
-#endif
-
 static int insecure;
 static int rpcsock, pingsock;
 static struct rmtcallargs rmtca;
@@ -124,8 +122,8 @@
 static unsigned long rmtcr_port;
 static SVCXPRT *udptransp, *tcptransp;
 
-int	_yp_invalid_domain(const char *);		/* from libc */
-int	main(int, char *[]);
+
+// forward decls of functions
 
 static void usage(void);
 static void yp_log(int, const char *, ...) __printflike(2, 3);
@@ -149,20 +147,16 @@
 static int direct(char *, int);
 static int direct_set(char *, int, struct _dom_binding *);
 
-static void
-usage(void)
-{
-	const char *opt = ;
+
+// logging
+
 #ifdef DEBUG
-	opt =  [-d];
+#define DPRINTF(...) (debug ? (void)printf(__VA_ARGS__) : (void)0)
+static int debug;
+#else
+#define DPRINTF(...)
 #endif
 
-	(void)fprintf(stderr,
-	Usage: %s [-broadcast] [-insecure] [-ypset] [-ypsetme]%s\n,
-	getprogname(), opt);
-	exit(1);
-}
-
 static void
 yp_log(int pri, const char *fmt, ...)
 {
@@ -179,6 +173,32 @@
 	va_end(ap);
 }
 
+
+// struct _dom_binding
+
+static struct _dom_binding *
+xid2ypdb(uint32_t xid)
+{
+	struct _dom_binding *ypdb;
+
+	for (ypdb = ypbindlist; ypdb; ypdb = ypdb-dom_pnext)
+		if (ypdb-dom_xid == xid)
+			break;
+	return (ypdb);
+}
+
+static uint32_t
+unique_xid(struct _dom_binding *ypdb)
+{
+	uint32_t tmp_xid;
+
+	tmp_xid = ((uint32_t)(unsigned long)ypdb)  0x;
+	while (xid2ypdb(tmp_xid) != NULL)
+		tmp_xid++;
+
+	return tmp_xid;
+}
+
 static struct _dom_binding *
 makebinding(const char *dm)
 {
@@ -194,6 +214,9 @@
 	return ypdb;
 }
 
+
+// locks
+
 static int
 makelock(struct _dom_binding *ypdb)
 {
@@ -269,6 +292,97 @@
 	return(0);
 }
 
+
+// sunrpc twaddle
+
+/*
+ * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
+ */
+void
+rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
+{
+	struct _dom_binding *ypdb;
+	struct iovec iov[2];
+	struct ypbind_resp ybr;
+	int fd;
+
+	DPRINTF(returned from %s about %s\n,
+		inet_ntoa(raddrp-sin_addr), dom);
+
+	if (dom == NULL)
+		return;
+
+	if (_yp_invalid_domain(dom))
+		return;	
+
+		/* don't support insecure servers by default */
+	if (!insecure  ntohs(raddrp-sin_port) = IPPORT_RESERVED)
+		return;
+
+	for (ypdb = ypbindlist; ypdb; ypdb = ypdb-dom_pnext)
+		if (!strcmp(ypdb-dom_domain, dom))
+			break;
+
+	if (ypdb == NULL) {
+		if (force == 0)
+			return;
+		ypdb = makebinding(dom);
+		ypdb-dom_lockfd = -1;
+		ypdb-dom_pnext = ypbindlist;
+		ypbindlist = ypdb;
+	}
+
+	/* soft update, alive */
+	if (ypdb-dom_alive == 1  force == 0) {
+		if (!memcmp(ypdb-dom_server_addr, raddrp,
+			sizeof ypdb-dom_server_addr)) {

CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:56:48 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Remove now-unnecessary extra forward decls; sprinkle a little more static.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.68 src/usr.sbin/ypbind/ypbind.c:1.69
--- src/usr.sbin/ypbind/ypbind.c:1.68	Tue May 24 06:56:16 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:56:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.68 2011/05/24 06:56:16 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.69 2011/05/24 06:56:48 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.68 2011/05/24 06:56:16 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.69 2011/05/24 06:56:48 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -105,14 +105,14 @@
 static struct _dom_binding *ypbindlist;
 static int check;
 
-ypbind_mode_t ypbindmode;
+static ypbind_mode_t ypbindmode;
 
 /*
  * If ypbindmode is YPBIND_SETLOCAL or YPBIND_SETALL, this indicates
  * whether or not we've been ypset.  If we haven't, we behave like
  * YPBIND_BROADCAST.  If we have, we behave like YPBIND_DIRECT.
  */
-int been_ypset;
+static int been_ypset;
 
 static int insecure;
 static int rpcsock, pingsock;
@@ -123,31 +123,6 @@
 static SVCXPRT *udptransp, *tcptransp;
 
 
-// forward decls of functions
-
-static void usage(void);
-static void yp_log(int, const char *, ...) __printflike(2, 3);
-static struct _dom_binding *makebinding(const char *);
-static int makelock(struct _dom_binding *);
-static void removelock(struct _dom_binding *);
-static int purge_bindingdir(const char *);
-static void *ypbindproc_null_2(SVCXPRT *, void *);
-static void *ypbindproc_domain_2(SVCXPRT *, void *);
-static void *ypbindproc_setdom_2(SVCXPRT *, void *);
-static void ypbindprog_2(struct svc_req *, SVCXPRT *);
-static void checkwork(void);
-static int ping(struct _dom_binding *);
-static int nag_servers(struct _dom_binding *);
-static enum clnt_stat handle_replies(void);
-static enum clnt_stat handle_ping(void);
-static void rpc_received(char *, struct sockaddr_in *, int);
-static struct _dom_binding *xid2ypdb(uint32_t);
-static uint32_t unique_xid(struct _dom_binding *);
-static int broadcast(char *, int);
-static int direct(char *, int);
-static int direct_set(char *, int, struct _dom_binding *);
-
-
 // logging
 
 #ifdef DEBUG
@@ -157,6 +132,8 @@
 #define DPRINTF(...)
 #endif
 
+static void yp_log(int, const char *, ...) __printflike(2, 3);
+
 static void
 yp_log(int pri, const char *fmt, ...)
 {
@@ -298,7 +275,7 @@
 /*
  * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
  */
-void
+static void
 rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
 {
 	struct _dom_binding *ypdb;
@@ -961,7 +938,7 @@
 	return -1;
 }
 
-int
+static int
 ping(struct _dom_binding *ypdb)
 {
 	char *dom = ypdb-dom_domain;
@@ -1031,7 +1008,7 @@
  * checking	timeout		ping server + broadcast	checking	5 sec
  * checking	answer		--			binding		60 sec
  */
-void
+static void
 checkwork(void)
 {
 	struct _dom_binding *ypdb;



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:57:04 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Check that the domain name is valid up front, instead of doing it
after opening sockets and registering services and whatnot.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.69 src/usr.sbin/ypbind/ypbind.c:1.70
--- src/usr.sbin/ypbind/ypbind.c:1.69	Tue May 24 06:56:48 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:57:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.69 2011/05/24 06:56:48 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.69 2011/05/24 06:56:48 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -1060,6 +1060,8 @@
 	(void)yp_get_default_domain(domainname);
 	if (domainname[0] == '\0')
 		errx(1, Domainname not set. Aborting.);
+	if (_yp_invalid_domain(domainname))
+		errx(1, Invalid domainname: %s, domainname);
 
 	/*
 	 * Per traditional ypbind(8) semantics, if a ypservers
@@ -1145,9 +1147,6 @@
 	rmtcr.xdr_results = xdr_bool;
 	rmtcr.results_ptr = (caddr_t)(void *)rmtcr_outval;
 
-	if (_yp_invalid_domain(domainname))
-		errx(1, bad domainname: %s, domainname);
-
 	/* blow away old bindings in BINDINGDIR */
 	if (purge_bindingdir(BINDINGDIR)  0)
 		errx(1, unable to purge old bindings from %s, BINDINGDIR);



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:57:30 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Abstract out some of the handling of the ypservers file.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.70 src/usr.sbin/ypbind/ypbind.c:1.71
--- src/usr.sbin/ypbind/ypbind.c:1.70	Tue May 24 06:57:04 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:57:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.70 2011/05/24 06:57:04 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -151,6 +151,23 @@
 }
 
 
+// ypservers file
+
+/*
+ * Get pathname for the ypservers file for a given domain
+ * (/var/yp/binding/DOMAIN.ypservers)
+ */
+static const char *
+ypservers_filename(const char *domain)
+{
+	static char ret[PATH_MAX];
+
+	(void)snprintf(ret, sizeof(ret), %s/%s%s,
+			BINDINGDIR, domain, YPSERVERSSUFF);
+	return ret;
+}
+
+
 // struct _dom_binding
 
 static struct _dom_binding *
@@ -612,8 +629,14 @@
 static int
 direct(char *buf, int outlen)
 {
+	/*
+	 * XXX I don't see how this can work if we're binding multiple domains.
+	 * Also, what if someone's editor unlinks and replaces the file?
+	 */
 	static FILE *df;
 	static char ypservers_path[MAXPATHLEN];
+
+	const char *path;
 	char line[_POSIX2_LINE_MAX];
 	char *p;
 	struct hostent *hp;
@@ -623,8 +646,8 @@
 	if (df)
 		rewind(df);
 	else {
-		(void)snprintf(ypservers_path, sizeof(ypservers_path),
-		%s/%s%s, BINDINGDIR, domainname, YPSERVERSSUFF);
+		path = ypservers_filename(domainname);
+		strcpy(ypservers_path, path);
 		df = fopen(ypservers_path, r);
 		if (df == NULL) {
 			yp_log(LOG_ERR, %s: , ypservers_path);
@@ -1053,7 +1076,7 @@
 	fd_set fdsr;
 	int width, lockfd;
 	int evil = 0, one;
-	char pathname[MAXPATHLEN];
+	const char *pathname;
 	struct stat st;
 
 	setprogname(argv[0]);
@@ -1070,8 +1093,7 @@
 	 * Note that we can still override direct mode by passing
 	 * the -broadcast flag.
 	 */
-	(void)snprintf(pathname, sizeof(pathname), %s/%s%s, BINDINGDIR,
-	domainname, YPSERVERSSUFF);
+	pathname = ypservers_filename(domainname);
 	if (stat(pathname, st)  0) {
 		DPRINTF(%s does not exist, defaulting to broadcast\n,
 			pathname);



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:57:55 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Fix up calls to yp_log. They cannot use %m, because if the -d option
is used the messages are sent via printf instead of syslog(3).

Also, make sure that none of the calls include a trailing newline and
issue a trailing newline in the -d case so they actually print properly.
(This was noted by Wolfgang Stukenbrock in PR 43900.)

And finally, fix some cases that could in some circumstances print
uninitialized errnos.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.71 src/usr.sbin/ypbind/ypbind.c:1.72
--- src/usr.sbin/ypbind/ypbind.c:1.71	Tue May 24 06:57:30 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:57:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.72 2011/05/24 06:57:55 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.71 2011/05/24 06:57:30 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.72 2011/05/24 06:57:55 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -142,9 +142,10 @@
 	va_start(ap, fmt);
 
 #if defined(DEBUG)
-	if (debug)
+	if (debug) {
 		(void)vprintf(fmt, ap);
-	else
+		(void)printf(\n);
+	} else
 #endif
 		vsyslog(pri, fmt, ap);
 	va_end(ap);
@@ -199,7 +200,7 @@
 	struct _dom_binding *ypdb;
 
 	if ((ypdb = malloc(sizeof *ypdb)) == NULL) {
-		yp_log(LOG_ERR, makebinding);
+		yp_log(LOG_ERR, makebinding: Out of memory);
 		exit(1);
 	}
 
@@ -298,6 +299,7 @@
 	struct _dom_binding *ypdb;
 	struct iovec iov[2];
 	struct ypbind_resp ybr;
+	ssize_t result;
 	int fd;
 
 	DPRINTF(returned from %s about %s\n,
@@ -368,9 +370,12 @@
 	ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
 	raddrp-sin_port;
 
-	if ((size_t)writev(ypdb-dom_lockfd, iov, 2) !=
-	iov[0].iov_len + iov[1].iov_len) {
-		yp_log(LOG_WARNING, writev: %m);
+	result = writev(ypdb-dom_lockfd, iov, 2);
+	if (result  0 || (size_t)result != iov[0].iov_len + iov[1].iov_len) {
+		if (result  0)
+			yp_log(LOG_WARNING, writev: %s, strerror(errno));
+		else
+			yp_log(LOG_WARNING, writev: short count);
 		(void)close(ypdb-dom_lockfd);
 		removelock(ypdb);
 		ypdb-dom_lockfd = -1;
@@ -591,7 +596,8 @@
 	bindsin.sin_port = htons(PMAPPORT);
 
 	if (getifaddrs(ifap) != 0) {
-		yp_log(LOG_WARNING, broadcast: getifaddrs: %m);
+		yp_log(LOG_WARNING, broadcast: getifaddrs: %s,
+		   strerror(errno));
 		return (-1);
 	}
 	for (ifa = ifap; ifa; ifa = ifa-ifa_next) {
@@ -620,7 +626,8 @@
 		if (sendto(rpcsock, buf, outlen, 0,
 		(struct sockaddr *)(void *)bindsin,
 		(socklen_t)bindsin.sin_len) == -1)
-			yp_log(LOG_WARNING, broadcast: sendto: %m);
+			yp_log(LOG_WARNING, broadcast: sendto: %s,
+			   strerror(errno));
 	}
 	freeifaddrs(ifap);
 	return (0);
@@ -650,7 +657,8 @@
 		strcpy(ypservers_path, path);
 		df = fopen(ypservers_path, r);
 		if (df == NULL) {
-			yp_log(LOG_ERR, %s: , ypservers_path);
+			yp_log(LOG_ERR, %s: %s, ypservers_path,
+			   strerror(errno));
 			exit(1);
 		}
 	}
@@ -688,14 +696,15 @@
 			if (sendto(rpcsock, buf, outlen, 0,
 			(struct sockaddr *)(void *)bindsin,
 			(socklen_t)sizeof(bindsin))  0) {
-yp_log(LOG_WARNING, direct: sendto: %m);
+yp_log(LOG_WARNING, direct: sendto: %s,
+   strerror(errno));
 continue;
 			} else
 count++;
 		}
 	}
 	if (!count) {
-		yp_log(LOG_WARNING, no contactable servers found in %s,
+		yp_log(LOG_WARNING, No contactable servers found in %s,
 		ypservers_path);
 		return -1;
 	}
@@ -722,7 +731,7 @@
 	ypdb-dom_domain, ypdb-dom_vers);
 
 	if ((fd = open(path, O_SHLOCK|O_RDONLY, 0644)) == -1) {
-		yp_log(LOG_WARNING, %s: %m, path);
+		yp_log(LOG_WARNING, %s: %s, path, strerror(errno));
 		been_ypset = 0;
 		return -1;
 	}
@@ -738,9 +747,12 @@
 	iov[1].iov_len = sizeof(ybr);
 	bytes = readv(fd, iov, 2);
 	(void)close(fd);
-	if ((size_t)bytes != (iov[0].iov_len + iov[1].iov_len)) {
+	if (bytes 0 || (size_t)bytes != (iov[0].iov_len + iov[1].iov_len)) {
 		/* Binding file corrupt? */
-		yp_log(LOG_WARNING, %s: %m, path);
+		if (bytes  0)
+			yp_log(LOG_WARNING, %s: %s, path, strerror(errno));
+		else
+			yp_log(LOG_WARNING, %s: short read, path);
 		been_ypset = 0;
 		return -1;
 	}
@@ -751,7 +763,7 @@
 	if (sendto(rpcsock, buf, outlen, 0,
 	(struct sockaddr *)(void *)bindsin,
 	(socklen_t)sizeof(bindsin))  0) {
-		yp_log(LOG_WARNING, direct_set: sendto: %m);
+		yp_log(LOG_WARNING, direct_set: sendto: %s, strerror(errno));
 		return -1;
 	}
 
@@ -941,7 +953,8 @@
 		if (sendto(rpcsock, buf, outlen, 0,
 		(struct 

CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:58:19 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Move a bunch of messy sunrpc-related initialization stuff into its own
function instead of blatting it all into main().


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.73 src/usr.sbin/ypbind/ypbind.c:1.74
--- src/usr.sbin/ypbind/ypbind.c:1.73	Tue May 24 06:58:07 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:58:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.73 2011/05/24 06:58:07 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.74 2011/05/24 06:58:19 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.73 2011/05/24 06:58:07 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.74 2011/05/24 06:58:19 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -599,6 +599,51 @@
 	return;
 }
 
+static void
+sunrpc_setup(void)
+{
+	int one;
+
+	(void)pmap_unset(YPBINDPROG, YPBINDVERS);
+
+	udptransp = svcudp_create(RPC_ANYSOCK);
+	if (udptransp == NULL)
+		errx(1, Cannot create udp service.);
+
+	if (!svc_register(udptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
+	IPPROTO_UDP))
+		errx(1, Unable to register (YPBINDPROG, YPBINDVERS, udp).);
+
+	tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0);
+	if (tcptransp == NULL)
+		errx(1, Cannot create tcp service.);
+
+	if (!svc_register(tcptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
+	IPPROTO_TCP))
+		errx(1, Unable to register (YPBINDPROG, YPBINDVERS, tcp).);
+
+	/* XXX use SOCK_STREAM for direct queries? */
+	if ((rpcsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+		err(1, rpc socket);
+	if ((pingsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+		err(1, ping socket);
+	
+	(void)fcntl(rpcsock, F_SETFL, fcntl(rpcsock, F_GETFL, 0) | FNDELAY);
+	(void)fcntl(pingsock, F_SETFL, fcntl(pingsock, F_GETFL, 0) | FNDELAY);
+
+	one = 1;
+	(void)setsockopt(rpcsock, SOL_SOCKET, SO_BROADCAST, one,
+	(socklen_t)sizeof(one));
+	rmtca.prog = YPPROG;
+	rmtca.vers = YPVERS;
+	rmtca.proc = YPPROC_DOMAIN_NONACK;
+	rmtca.xdr_args = NULL;		/* set at call time */
+	rmtca.args_ptr = NULL;		/* set at call time */
+	rmtcr.port_ptr = rmtcr_port;
+	rmtcr.xdr_results = xdr_bool;
+	rmtcr.results_ptr = (caddr_t)(void *)rmtcr_outval;
+}
+
 
 // operational logic
 
@@ -1104,7 +1149,7 @@
 	struct timeval tv;
 	fd_set fdsr;
 	int width, lockfd;
-	int evil = 0, one;
+	int evil = 0;
 	const char *pathname;
 	struct stat st;
 
@@ -1151,48 +1196,13 @@
 	/* initialise syslog */
 	openlog(ypbind, LOG_PERROR | LOG_PID, LOG_DAEMON);
 
+	/* acquire ypbind.lock */
 	lockfd = open_locked(_PATH_YPBIND_LOCK, O_CREAT|O_RDWR|O_TRUNC, 0644);
 	if (lockfd == -1)
 		err(1, Cannot create %s, _PATH_YPBIND_LOCK);
 
-	(void)pmap_unset(YPBINDPROG, YPBINDVERS);
-
-	udptransp = svcudp_create(RPC_ANYSOCK);
-	if (udptransp == NULL)
-		errx(1, Cannot create udp service.);
-
-	if (!svc_register(udptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
-	IPPROTO_UDP))
-		errx(1, Unable to register (YPBINDPROG, YPBINDVERS, udp).);
-
-	tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0);
-	if (tcptransp == NULL)
-		errx(1, Cannot create tcp service.);
-
-	if (!svc_register(tcptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
-	IPPROTO_TCP))
-		errx(1, Unable to register (YPBINDPROG, YPBINDVERS, tcp).);
-
-	/* XXX use SOCK_STREAM for direct queries? */
-	if ((rpcsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
-		err(1, rpc socket);
-	if ((pingsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
-		err(1, ping socket);
-	
-	(void)fcntl(rpcsock, F_SETFL, fcntl(rpcsock, F_GETFL, 0) | FNDELAY);
-	(void)fcntl(pingsock, F_SETFL, fcntl(pingsock, F_GETFL, 0) | FNDELAY);
-
-	one = 1;
-	(void)setsockopt(rpcsock, SOL_SOCKET, SO_BROADCAST, one,
-	(socklen_t)sizeof(one));
-	rmtca.prog = YPPROG;
-	rmtca.vers = YPVERS;
-	rmtca.proc = YPPROC_DOMAIN_NONACK;
-	rmtca.xdr_args = NULL;		/* set at call time */
-	rmtca.args_ptr = NULL;		/* set at call time */
-	rmtcr.port_ptr = rmtcr_port;
-	rmtcr.xdr_results = xdr_bool;
-	rmtcr.results_ptr = (caddr_t)(void *)rmtcr_outval;
+	/* initialize sunrpc stuff */
+	sunrpc_setup();
 
 	/* blow away old bindings in BINDINGDIR */
 	if (purge_bindingdir(BINDINGDIR)  0)



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:59:35 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The default name for a domain variable should be dom, not ypdb.
Change them all, and make a couple other related adjustments.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.77 src/usr.sbin/ypbind/ypbind.c:1.78
--- src/usr.sbin/ypbind/ypbind.c:1.77	Tue May 24 06:59:07 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:59:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.77 2011/05/24 06:59:07 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.78 2011/05/24 06:59:35 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.77 2011/05/24 06:59:07 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.78 2011/05/24 06:59:35 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -85,7 +85,7 @@
 } ypbind_mode_t;
 
 struct domain {
-	struct domain *dom_pnext;
+	struct domain *dom_next;
 
 	char dom_domain[YPMAXDOMAIN + 1];
 	struct sockaddr_in dom_server_addr;
@@ -194,20 +194,20 @@
 static struct domain *
 domain_find(uint32_t xid)
 {
-	struct domain *ypdb;
+	struct domain *dom;
 
-	for (ypdb = domains; ypdb; ypdb = ypdb-dom_pnext)
-		if (ypdb-dom_xid == xid)
+	for (dom = domains; dom != NULL; dom = dom-dom_next)
+		if (dom-dom_xid == xid)
 			break;
-	return (ypdb);
+	return dom;
 }
 
 static uint32_t
-unique_xid(struct domain *ypdb)
+unique_xid(struct domain *dom)
 {
 	uint32_t tmp_xid;
 
-	tmp_xid = ((uint32_t)(unsigned long)ypdb)  0x;
+	tmp_xid = ((uint32_t)(unsigned long)dom)  0x;
 	while (domain_find(tmp_xid) != NULL)
 		tmp_xid++;
 
@@ -215,31 +215,32 @@
 }
 
 static struct domain *
-domain_create(const char *dm)
+domain_create(const char *name)
 {
-	struct domain *ypdb;
+	struct domain *dom;
 
-	if ((ypdb = malloc(sizeof *ypdb)) == NULL) {
+	dom = malloc(sizeof *dom);
+	if (dom == NULL) {
 		yp_log(LOG_ERR, domain_create: Out of memory);
 		exit(1);
 	}
 
-	(void)memset(ypdb, 0, sizeof *ypdb);
-	(void)strlcpy(ypdb-dom_domain, dm, sizeof ypdb-dom_domain);
-	return ypdb;
+	(void)memset(dom, 0, sizeof *dom);
+	(void)strlcpy(dom-dom_domain, name, sizeof(dom-dom_domain));
+	return dom;
 }
 
 
 // locks
 
 static int
-makelock(struct domain *ypdb)
+makelock(struct domain *dom)
 {
 	int fd;
 	char path[MAXPATHLEN];
 
 	(void)snprintf(path, sizeof(path), %s/%s.%ld, BINDINGDIR,
-	ypdb-dom_domain, ypdb-dom_vers);
+	dom-dom_domain, dom-dom_vers);
 
 	fd = open_locked(path, O_CREAT|O_RDWR|O_TRUNC, 0644);
 	if (fd == -1) {
@@ -254,12 +255,12 @@
 }
 
 static void
-removelock(struct domain *ypdb)
+removelock(struct domain *dom)
 {
 	char path[MAXPATHLEN];
 
 	(void)snprintf(path, sizeof(path), %s/%s.%ld,
-	BINDINGDIR, ypdb-dom_domain, ypdb-dom_vers);
+	BINDINGDIR, dom-dom_domain, dom-dom_vers);
 	(void)unlink(path);
 }
 
@@ -314,69 +315,69 @@
  * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
  */
 static void
-rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
+rpc_received(char *dom_name, struct sockaddr_in *raddrp, int force)
 {
-	struct domain *ypdb;
+	struct domain *dom;
 	struct iovec iov[2];
 	struct ypbind_resp ybr;
 	ssize_t result;
 	int fd;
 
 	DPRINTF(returned from %s about %s\n,
-		inet_ntoa(raddrp-sin_addr), dom);
+		inet_ntoa(raddrp-sin_addr), dom_name);
 
-	if (dom == NULL)
+	if (dom_name == NULL)
 		return;
 
-	if (_yp_invalid_domain(dom))
+	if (_yp_invalid_domain(dom_name))
 		return;	
 
 		/* don't support insecure servers by default */
 	if (!insecure  ntohs(raddrp-sin_port) = IPPORT_RESERVED)
 		return;
 
-	for (ypdb = domains; ypdb; ypdb = ypdb-dom_pnext)
-		if (!strcmp(ypdb-dom_domain, dom))
+	for (dom = domains; dom != NULL; dom = dom-dom_next)
+		if (!strcmp(dom-dom_domain, dom_name))
 			break;
 
-	if (ypdb == NULL) {
+	if (dom == NULL) {
 		if (force == 0)
 			return;
-		ypdb = domain_create(dom);
-		ypdb-dom_lockfd = -1;
-		ypdb-dom_pnext = domains;
-		domains = ypdb;
+		dom = domain_create(dom_name);
+		dom-dom_lockfd = -1;
+		dom-dom_next = domains;
+		domains = dom;
 	}
 
 	/* soft update, alive */
-	if (ypdb-dom_alive == 1  force == 0) {
-		if (!memcmp(ypdb-dom_server_addr, raddrp,
-			sizeof ypdb-dom_server_addr)) {
-			ypdb-dom_alive = 1;
+	if (dom-dom_alive == 1  force == 0) {
+		if (!memcmp(dom-dom_server_addr, raddrp,
+			sizeof(dom-dom_server_addr))) {
+			dom-dom_alive = 1;
 			/* recheck binding in 60 sec */
-			ypdb-dom_checktime = time(NULL) + 60;
+			dom-dom_checktime = time(NULL) + 60;
 		}
 		return;
 	}
 	
-	(void)memcpy(ypdb-dom_server_addr, raddrp,
-	sizeof 

CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:59:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The name field of a domain should be dom-dom_name, not dom-dom_domain.
(This and the previous patch make the code far more readable.)


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.78 src/usr.sbin/ypbind/ypbind.c:1.79
--- src/usr.sbin/ypbind/ypbind.c:1.78	Tue May 24 06:59:35 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 06:59:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.78 2011/05/24 06:59:35 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.79 2011/05/24 06:59:53 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.78 2011/05/24 06:59:35 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.79 2011/05/24 06:59:53 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -87,7 +87,7 @@
 struct domain {
 	struct domain *dom_next;
 
-	char dom_domain[YPMAXDOMAIN + 1];
+	char dom_name[YPMAXDOMAIN + 1];
 	struct sockaddr_in dom_server_addr;
 	int dom_socket;
 	CLIENT *dom_client;
@@ -226,7 +226,7 @@
 	}
 
 	(void)memset(dom, 0, sizeof *dom);
-	(void)strlcpy(dom-dom_domain, name, sizeof(dom-dom_domain));
+	(void)strlcpy(dom-dom_name, name, sizeof(dom-dom_name));
 	return dom;
 }
 
@@ -240,7 +240,7 @@
 	char path[MAXPATHLEN];
 
 	(void)snprintf(path, sizeof(path), %s/%s.%ld, BINDINGDIR,
-	dom-dom_domain, dom-dom_vers);
+	dom-dom_name, dom-dom_vers);
 
 	fd = open_locked(path, O_CREAT|O_RDWR|O_TRUNC, 0644);
 	if (fd == -1) {
@@ -260,7 +260,7 @@
 	char path[MAXPATHLEN];
 
 	(void)snprintf(path, sizeof(path), %s/%s.%ld,
-	BINDINGDIR, dom-dom_domain, dom-dom_vers);
+	BINDINGDIR, dom-dom_name, dom-dom_vers);
 	(void)unlink(path);
 }
 
@@ -337,7 +337,7 @@
 		return;
 
 	for (dom = domains; dom != NULL; dom = dom-dom_next)
-		if (!strcmp(dom-dom_domain, dom_name))
+		if (!strcmp(dom-dom_name, dom_name))
 			break;
 
 	if (dom == NULL) {
@@ -436,7 +436,7 @@
 	dom = dom-dom_next, count++) {
 		if (count  100)
 			return NULL;		/* prevent denial of service */
-		if (!strcmp(dom-dom_domain, arg))
+		if (!strcmp(dom-dom_name, arg))
 			break;
 	}
 
@@ -481,7 +481,7 @@
 		dom-dom_server_addr.sin_addr.s_addr;
 	res.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
 		dom-dom_server_addr.sin_port;
-	DPRINTF(domain %s at %s/%d\n, dom-dom_domain,
+	DPRINTF(domain %s at %s/%d\n, dom-dom_name,
 		inet_ntoa(dom-dom_server_addr.sin_addr),
 		ntohs(dom-dom_server_addr.sin_port));
 	return res;
@@ -794,7 +794,7 @@
 	 * bind again.
 	 */
 	(void)snprintf(path, sizeof(path), %s/%s.%ld, BINDINGDIR,
-	dom-dom_domain, dom-dom_vers);
+	dom-dom_name, dom-dom_vers);
 
 	fd = open_locked(path, O_RDONLY, 0644);
 	if (fd == -1) {
@@ -877,7 +877,7 @@
 			raddr.sin_port = htons((uint16_t)rmtcr_port);
 			dom = domain_find(msg.rm_xid);
 			if (dom != NULL)
-rpc_received(dom-dom_domain, raddr, 0);
+rpc_received(dom-dom_name, raddr, 0);
 		}
 	}
 	xdr.x_op = XDR_FREE;
@@ -931,7 +931,7 @@
 		(msg.acpted_rply.ar_stat == SUCCESS)) {
 			dom = domain_find(msg.rm_xid);
 			if (dom != NULL)
-rpc_received(dom-dom_domain, raddr, 0);
+rpc_received(dom-dom_name, raddr, 0);
 		}
 	}
 	xdr.x_op = XDR_FREE;
@@ -944,7 +944,7 @@
 static int
 nag_servers(struct domain *dom)
 {
-	char *dom_name = dom-dom_domain;
+	char *dom_name = dom-dom_name;
 	struct rpc_msg msg;
 	char buf[BUFSIZE];
 	enum clnt_stat st;
@@ -1040,7 +1040,7 @@
 static int
 ping(struct domain *dom)
 {
-	char *dom_name = dom-dom_domain;
+	char *dom_name = dom-dom_name;
 	struct rpc_msg msg;
 	char buf[BUFSIZE];
 	enum clnt_stat st;



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:00:07 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Fix initialization of struct domain; initialize all fields in all
cases, merge duplicate code, make sure every domain gets an xid
assigned.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.79 src/usr.sbin/ypbind/ypbind.c:1.80
--- src/usr.sbin/ypbind/ypbind.c:1.79	Tue May 24 06:59:53 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:00:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.79 2011/05/24 06:59:53 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.80 2011/05/24 07:00:07 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.79 2011/05/24 06:59:53 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.80 2011/05/24 07:00:07 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -225,8 +225,23 @@
 		exit(1);
 	}
 
-	(void)memset(dom, 0, sizeof *dom);
+	dom-dom_next = NULL;
+
 	(void)strlcpy(dom-dom_name, name, sizeof(dom-dom_name));
+	(void)memset(dom-dom_server_addr, 0, sizeof(dom-dom_server_addr));
+	dom-dom_socket = -1;
+	dom-dom_client = NULL;
+	dom-dom_vers = YPVERS;
+	dom-dom_checktime = 0;
+	dom-dom_asktime = 0;
+	dom-dom_lockfd = -1;
+	dom-dom_alive = 0;
+	dom-dom_xid = unique_xid(dom);
+
+	/* add to global list */
+	dom-dom_next = domains;
+	domains = dom;
+
 	return dom;
 }
 
@@ -344,9 +359,6 @@
 		if (force == 0)
 			return;
 		dom = domain_create(dom_name);
-		dom-dom_lockfd = -1;
-		dom-dom_next = domains;
-		domains = dom;
 	}
 
 	/* soft update, alive */
@@ -442,13 +454,7 @@
 
 	if (dom == NULL) {
 		dom = domain_create(arg);
-		dom-dom_vers = YPVERS;
-		dom-dom_alive = 0;
-		dom-dom_lockfd = -1;
 		removelock(dom);
-		dom-dom_xid = unique_xid(dom);
-		dom-dom_next = domains;
-		domains = dom;
 		check++;
 		DPRINTF(unknown domain %s\n, arg);
 		return NULL;
@@ -1212,9 +1218,6 @@
 
 	/* build initial domain binding, make it unsuccessful */
 	domains = domain_create(domainname);
-	domains-dom_vers = YPVERS;
-	domains-dom_alive = 0;
-	domains-dom_lockfd = -1;
 	removelock(domains);
 
 	checkwork();



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:00:34 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Allowing ypset is a global permission flag, not an operating mode like
broadcast vs. configured/direct. Don't conflate the logic. As I proposed
in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.80 src/usr.sbin/ypbind/ypbind.c:1.81
--- src/usr.sbin/ypbind/ypbind.c:1.80	Tue May 24 07:00:07 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:00:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.80 2011/05/24 07:00:07 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.81 2011/05/24 07:00:34 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.80 2011/05/24 07:00:07 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.81 2011/05/24 07:00:34 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -81,7 +81,7 @@
 // types and globals
 
 typedef enum {
-	YPBIND_DIRECT, YPBIND_BROADCAST, YPBIND_SETLOCAL, YPBIND_SETALL
+	YPBIND_DIRECT, YPBIND_BROADCAST,
 } ypbind_mode_t;
 
 struct domain {
@@ -109,12 +109,13 @@
 static ypbind_mode_t ypbindmode;
 
 /*
- * If ypbindmode is YPBIND_SETLOCAL or YPBIND_SETALL, this indicates
- * whether or not we've been ypset.  If we haven't, we behave like
- * YPBIND_BROADCAST.  If we have, we behave like YPBIND_DIRECT.
+ * This indicates whether or not we've been ypset. If we haven't,
+ * we behave like YPBIND_BROADCAST.  If we have, we behave like
+ * YPBIND_DIRECT.
  */
 static int been_ypset;
 
+static int allow_local_ypset = 0, allow_any_ypset = 0;
 static int insecure;
 static int rpcsock, pingsock;
 static struct rmtcallargs rmtca;
@@ -504,22 +505,15 @@
 	(void)memset(res, 0, sizeof(res));
 	fromsin = svc_getcaller(transp);
 
-	switch (ypbindmode) {
-	case YPBIND_SETLOCAL:
+	if (allow_any_ypset) {
+		/* nothing */
+	} else if (allow_local_ypset) {
 		if (fromsin-sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
-			DPRINTF(ypset from %s denied\n,
+			DPRINTF(ypset denied from %s\n,
 inet_ntoa(fromsin-sin_addr));
 			return NULL;
 		}
-		/* FALLTHROUGH */
-
-	case YPBIND_SETALL:
-		been_ypset = 1;
-		break;
-
-	case YPBIND_DIRECT:
-	case YPBIND_BROADCAST:
-	default:
+	} else {
 		DPRINTF(ypset denied\n);
 		return NULL;
 	}
@@ -534,6 +528,8 @@
 		return res;
 	}
 
+	been_ypset = 1;
+
 	(void)memset(bindsin, 0, sizeof bindsin);
 	bindsin.sin_family = AF_INET;
 	bindsin.sin_len = sizeof(bindsin);
@@ -1027,13 +1023,10 @@
 	}
 
 	switch (ypbindmode) {
-	case YPBIND_SETALL:
-	case YPBIND_SETLOCAL:
-		if (been_ypset)
-			return direct_set(buf, outlen, dom);
-		/* FALLTHROUGH */
-
 	case YPBIND_BROADCAST:
+		if (been_ypset) {
+			return direct_set(buf, outlen, dom);
+		}
 		return broadcast(buf, outlen);
 
 	case YPBIND_DIRECT:
@@ -1185,20 +1178,23 @@
 
 	while (--argc) {
 		++argv;
-		if (!strcmp(-insecure, *argv))
+		if (!strcmp(-insecure, *argv)) {
 			insecure = 1;
-		else if (!strcmp(-ypset, *argv))
-			ypbindmode = YPBIND_SETALL;
-		else if (!strcmp(-ypsetme, *argv))
-			ypbindmode = YPBIND_SETLOCAL;
-		else if (!strcmp(-broadcast, *argv))
+		} else if (!strcmp(-ypset, *argv)) {
+			allow_any_ypset = 1;
+			allow_local_ypset = 1;
+		} else if (!strcmp(-ypsetme, *argv)) {
+			allow_any_ypset = 0;
+			allow_local_ypset = 1;
+		} else if (!strcmp(-broadcast, *argv)) {
 			ypbindmode = YPBIND_BROADCAST;
 #ifdef DEBUG
-		else if (!strcmp(-d, *argv))
-			debug++;
+		} else if (!strcmp(-d, *argv)) {
+			debug = 1;
 #endif
-		else
+		} else {
 			usage();
+		}
 	}
 
 	/* initialise syslog */



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:15 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The ypbindmode really needs to be per-domain, so adjust accordingly.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.81 src/usr.sbin/ypbind/ypbind.c:1.82
--- src/usr.sbin/ypbind/ypbind.c:1.81	Tue May 24 07:00:34 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:01:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.81 2011/05/24 07:00:34 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.82 2011/05/24 07:01:15 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.81 2011/05/24 07:00:34 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.82 2011/05/24 07:01:15 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -97,6 +97,7 @@
 	int dom_lockfd;
 	int dom_alive;
 	uint32_t dom_xid;
+	ypbind_mode_t dom_ypbindmode;
 };
 
 #define BUFSIZE		1400
@@ -106,7 +107,7 @@
 static struct domain *domains;
 static int check;
 
-static ypbind_mode_t ypbindmode;
+static ypbind_mode_t default_ypbindmode;
 
 /*
  * This indicates whether or not we've been ypset. If we haven't,
@@ -219,6 +220,8 @@
 domain_create(const char *name)
 {
 	struct domain *dom;
+	const char *pathname;
+	struct stat st;
 
 	dom = malloc(sizeof *dom);
 	if (dom == NULL) {
@@ -239,6 +242,25 @@
 	dom-dom_alive = 0;
 	dom-dom_xid = unique_xid(dom);
 
+	/*
+	 * Per traditional ypbind(8) semantics, if a ypservers
+	 * file does not exist, we revert to broadcast mode.
+	 *
+	 * The sysadmin can force broadcast mode by passing the
+	 * -broadcast flag. There is currently no way to fail and
+	 * reject domains for which there is no ypservers file.
+	 */
+	dom-dom_ypbindmode = default_ypbindmode;
+	if (dom-dom_ypbindmode == YPBIND_DIRECT) {
+		pathname = ypservers_filename(domainname);
+		if (stat(pathname, st)  0) {
+			/* XXX syslog a warning here? */
+			DPRINTF(%s does not exist, defaulting to broadcast\n,
+pathname);
+			dom-dom_ypbindmode = YPBIND_BROADCAST;
+		}
+	}
+
 	/* add to global list */
 	dom-dom_next = domains;
 	domains = dom;
@@ -1022,7 +1044,7 @@
 			   strerror(errno));
 	}
 
-	switch (ypbindmode) {
+	switch (dom-dom_ypbindmode) {
 	case YPBIND_BROADCAST:
 		if (been_ypset) {
 			return direct_set(buf, outlen, dom);
@@ -1151,8 +1173,6 @@
 	fd_set fdsr;
 	int width, lockfd;
 	int evil = 0;
-	const char *pathname;
-	struct stat st;
 
 	setprogname(argv[0]);
 	(void)yp_get_default_domain(domainname);
@@ -1161,20 +1181,7 @@
 	if (_yp_invalid_domain(domainname))
 		errx(1, Invalid domainname: %s, domainname);
 
-	/*
-	 * Per traditional ypbind(8) semantics, if a ypservers
-	 * file does not exist, we default to broadcast mode.
-	 * If the file does exist, we default to direct mode.
-	 * Note that we can still override direct mode by passing
-	 * the -broadcast flag.
-	 */
-	pathname = ypservers_filename(domainname);
-	if (stat(pathname, st)  0) {
-		DPRINTF(%s does not exist, defaulting to broadcast\n,
-			pathname);
-		ypbindmode = YPBIND_BROADCAST;
-	} else
-		ypbindmode = YPBIND_DIRECT;
+	default_ypbindmode = YPBIND_DIRECT;
 
 	while (--argc) {
 		++argv;
@@ -1187,7 +1194,7 @@
 			allow_any_ypset = 0;
 			allow_local_ypset = 1;
 		} else if (!strcmp(-broadcast, *argv)) {
-			ypbindmode = YPBIND_BROADCAST;
+			default_ypbindmode = YPBIND_BROADCAST;
 #ifdef DEBUG
 		} else if (!strcmp(-d, *argv)) {
 			debug = 1;



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:24 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The been_ypset flag really needs to be per-domain also. Do that.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.82 src/usr.sbin/ypbind/ypbind.c:1.83
--- src/usr.sbin/ypbind/ypbind.c:1.82	Tue May 24 07:01:15 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:01:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.82 2011/05/24 07:01:15 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.83 2011/05/24 07:01:24 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.82 2011/05/24 07:01:15 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.83 2011/05/24 07:01:24 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -97,7 +97,8 @@
 	int dom_lockfd;
 	int dom_alive;
 	uint32_t dom_xid;
-	ypbind_mode_t dom_ypbindmode;
+	ypbind_mode_t dom_ypbindmode;	/* broadcast or direct */
+	int dom_been_ypset;		/* ypset been done on this domain? */
 };
 
 #define BUFSIZE		1400
@@ -109,13 +110,6 @@
 
 static ypbind_mode_t default_ypbindmode;
 
-/*
- * This indicates whether or not we've been ypset. If we haven't,
- * we behave like YPBIND_BROADCAST.  If we have, we behave like
- * YPBIND_DIRECT.
- */
-static int been_ypset;
-
 static int allow_local_ypset = 0, allow_any_ypset = 0;
 static int insecure;
 static int rpcsock, pingsock;
@@ -353,7 +347,8 @@
  * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
  */
 static void
-rpc_received(char *dom_name, struct sockaddr_in *raddrp, int force)
+rpc_received(char *dom_name, struct sockaddr_in *raddrp, int force,
+	 int is_ypset)
 {
 	struct domain *dom;
 	struct iovec iov[2];
@@ -384,6 +379,10 @@
 		dom = domain_create(dom_name);
 	}
 
+	if (is_ypset) {
+		dom-dom_been_ypset = 1;
+	}
+
 	/* soft update, alive */
 	if (dom-dom_alive == 1  force == 0) {
 		if (!memcmp(dom-dom_server_addr, raddrp,
@@ -550,14 +549,12 @@
 		return res;
 	}
 
-	been_ypset = 1;
-
 	(void)memset(bindsin, 0, sizeof bindsin);
 	bindsin.sin_family = AF_INET;
 	bindsin.sin_len = sizeof(bindsin);
 	bindsin.sin_addr = sd-ypsetdom_addr;
 	bindsin.sin_port = sd-ypsetdom_port;
-	rpc_received(sd-ypsetdom_domain, bindsin, 1);
+	rpc_received(sd-ypsetdom_domain, bindsin, 1, 1);
 
 	DPRINTF(ypset to %s succeeded\n, inet_ntoa(bindsin.sin_addr));
 	res = 1;
@@ -823,7 +820,7 @@
 	fd = open_locked(path, O_RDONLY, 0644);
 	if (fd == -1) {
 		yp_log(LOG_WARNING, %s: %s, path, strerror(errno));
-		been_ypset = 0;
+		dom-dom_been_ypset = 0;
 		return -1;
 	}
 
@@ -840,7 +837,7 @@
 			yp_log(LOG_WARNING, %s: %s, path, strerror(errno));
 		else
 			yp_log(LOG_WARNING, %s: short read, path);
-		been_ypset = 0;
+		dom-dom_been_ypset = 0;
 		return -1;
 	}
 
@@ -901,7 +898,7 @@
 			raddr.sin_port = htons((uint16_t)rmtcr_port);
 			dom = domain_find(msg.rm_xid);
 			if (dom != NULL)
-rpc_received(dom-dom_name, raddr, 0);
+rpc_received(dom-dom_name, raddr, 0, 0);
 		}
 	}
 	xdr.x_op = XDR_FREE;
@@ -955,7 +952,7 @@
 		(msg.acpted_rply.ar_stat == SUCCESS)) {
 			dom = domain_find(msg.rm_xid);
 			if (dom != NULL)
-rpc_received(dom-dom_name, raddr, 0);
+rpc_received(dom-dom_name, raddr, 0, 0);
 		}
 	}
 	xdr.x_op = XDR_FREE;
@@ -1046,7 +1043,7 @@
 
 	switch (dom-dom_ypbindmode) {
 	case YPBIND_BROADCAST:
-		if (been_ypset) {
+		if (dom-dom_been_ypset) {
 			return direct_set(buf, outlen, dom);
 		}
 		return broadcast(buf, outlen);



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Merge a couple more minor improvements from Wolfgang Stukenbrock's
patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.84 src/usr.sbin/ypbind/ypbind.c:1.85
--- src/usr.sbin/ypbind/ypbind.c:1.84	Tue May 24 07:01:40 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:01:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.84 2011/05/24 07:01:40 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.85 2011/05/24 07:01:53 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.84 2011/05/24 07:01:40 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.85 2011/05/24 07:01:53 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -401,7 +401,6 @@
 	sizeof(dom-dom_server_addr));
 	/* recheck binding in 60 seconds */
 	dom-dom_checktime = time(NULL) + 60;
-	dom-dom_vers = YPVERS;
 	dom-dom_alive = 1;
 
 	if (dom-dom_lockfd != -1)
@@ -559,7 +558,8 @@
 	bindsin.sin_port = sd-ypsetdom_port;
 	rpc_received(sd-ypsetdom_domain, bindsin, 1, 1);
 
-	DPRINTF(ypset to %s succeeded\n, inet_ntoa(bindsin.sin_addr));
+	DPRINTF(ypset to %s for domain %s succeeded\n,
+		inet_ntoa(bindsin.sin_addr), sd-ypsetdom_domain);
 	res = 1;
 	return res;
 }



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:02:08 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Remove two entirely unused members of struct domain (previously struct
_dom_binding). I guess these were there because it was cutpasted at
some point from struct dom_binding in rpcsvc/yp_prot.h.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.85 src/usr.sbin/ypbind/ypbind.c:1.86
--- src/usr.sbin/ypbind/ypbind.c:1.85	Tue May 24 07:01:53 2011
+++ src/usr.sbin/ypbind/ypbind.c	Tue May 24 07:02:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.85 2011/05/24 07:01:53 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.86 2011/05/24 07:02:08 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.85 2011/05/24 07:01:53 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.86 2011/05/24 07:02:08 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -89,8 +89,6 @@
 
 	char dom_name[YPMAXDOMAIN + 1];
 	struct sockaddr_in dom_server_addr;
-	int dom_socket;
-	CLIENT *dom_client;
 	long dom_vers;
 	time_t dom_checktime;
 	time_t dom_asktime;
@@ -113,6 +111,7 @@
 
 static int allow_local_ypset = 0, allow_any_ypset = 0;
 static int insecure;
+
 static int rpcsock, pingsock;
 static struct rmtcallargs rmtca;
 static struct rmtcallres rmtcr;
@@ -228,8 +227,6 @@
 
 	(void)strlcpy(dom-dom_name, name, sizeof(dom-dom_name));
 	(void)memset(dom-dom_server_addr, 0, sizeof(dom-dom_server_addr));
-	dom-dom_socket = -1;
-	dom-dom_client = NULL;
 	dom-dom_vers = YPVERS;
 	dom-dom_checktime = 0;
 	dom-dom_asktime = 0;



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed May 25 04:33:52 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
When checking if /var/yp/binding/foo.ypservers exists, use the domain
name of the domain being checked instead of the default domain name. Duh.
Necessary for PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.86 src/usr.sbin/ypbind/ypbind.c:1.87
--- src/usr.sbin/ypbind/ypbind.c:1.86	Tue May 24 07:02:08 2011
+++ src/usr.sbin/ypbind/ypbind.c	Wed May 25 04:33:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.86 2011/05/24 07:02:08 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.87 2011/05/25 04:33:52 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.86 2011/05/24 07:02:08 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.87 2011/05/25 04:33:52 dholland Exp $);
 #endif
 
 #include sys/types.h
@@ -246,7 +246,7 @@
 	 */
 	dom-dom_ypbindmode = default_ypbindmode;
 	if (dom-dom_ypbindmode == YPBIND_DIRECT) {
-		pathname = ypservers_filename(domainname);
+		pathname = ypservers_filename(dom-dom_name);
 		if (stat(pathname, st)  0) {
 			/* XXX syslog a warning here? */
 			DPRINTF(%s does not exist, defaulting to broadcast\n,



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:56:48 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Remove now-unnecessary extra forward decls; sprinkle a little more static.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:57:04 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Check that the domain name is valid up front, instead of doing it
after opening sockets and registering services and whatnot.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:57:55 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Fix up calls to yp_log. They cannot use %m, because if the -d option
is used the messages are sent via printf instead of syslog(3).

Also, make sure that none of the calls include a trailing newline and
issue a trailing newline in the -d case so they actually print properly.
(This was noted by Wolfgang Stukenbrock in PR 43900.)

And finally, fix some cases that could in some circumstances print
uninitialized errnos.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:58:19 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Move a bunch of messy sunrpc-related initialization stuff into its own
function instead of blatting it all into main().


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:58:42 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Rename struct _dom_binding - struct domain.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:58:55 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
xid2ypdb() - domain_find()


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:59:07 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
ypbindlist - domains


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:59:35 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The default name for a domain variable should be dom, not ypdb.
Change them all, and make a couple other related adjustments.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 06:59:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The name field of a domain should be dom-dom_name, not dom-dom_domain.
(This and the previous patch make the code far more readable.)


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:00:07 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Fix initialization of struct domain; initialize all fields in all
cases, merge duplicate code, make sure every domain gets an xid
assigned.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:00:34 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Allowing ypset is a global permission flag, not an operating mode like
broadcast vs. configured/direct. Don't conflate the logic. As I proposed
in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:15 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The ypbindmode really needs to be per-domain, so adjust accordingly.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:24 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The been_ypset flag really needs to be per-domain also. Do that.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:40 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
The FILE* kept open for /var/yp/binding/foo.ypservers needs to be
per-domain. Also, use the file for the domain we're servicing instead
of always the file for the default domain.

Partly from Wolfgang Stukenbrock's patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:01:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Merge a couple more minor improvements from Wolfgang Stukenbrock's
patch in PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue May 24 07:02:08 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Remove two entirely unused members of struct domain (previously struct
_dom_binding). I guess these were there because it was cutpasted at
some point from struct dom_binding in rpcsvc/yp_prot.h.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed May 25 04:33:52 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
When checking if /var/yp/binding/foo.ypservers exists, use the domain
name of the domain being checked instead of the default domain name. Duh.
Necessary for PR 43900.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.sbin/ypbind/ypbind.c

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




CVS commit: src/usr.sbin/ypbind

2011-05-24 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed May 25 04:59:22 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't print uninitialized values off the stack, even as debug messages.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:06:42 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
u_int32_t - uint32_t and similar


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.63 src/usr.sbin/ypbind/ypbind.c:1.64
--- src/usr.sbin/ypbind/ypbind.c:1.63	Wed Mar 30 05:24:05 2011
+++ src/usr.sbin/ypbind/ypbind.c	Mon May 23 02:06:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.63 2011/03/30 05:24:05 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.64 2011/05/23 02:06:41 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.63 2011/03/30 05:24:05 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.64 2011/05/23 02:06:41 dholland Exp $);
 #endif
 
 #include sys/param.h
@@ -87,7 +87,7 @@
 	time_t dom_ask_t;
 	int dom_lockfd;
 	int dom_alive;
-	u_int32_t dom_xid;
+	uint32_t dom_xid;
 };
 
 static char *domainname;
@@ -117,7 +117,7 @@
 static struct rmtcallargs rmtca;
 static struct rmtcallres rmtcr;
 static bool_t rmtcr_outval;
-static u_long rmtcr_port;
+static unsigned long rmtcr_port;
 static SVCXPRT *udptransp, *tcptransp;
 
 int	_yp_invalid_domain(const char *);		/* from libc */
@@ -139,8 +139,8 @@
 static enum clnt_stat handle_replies(void);
 static enum clnt_stat handle_ping(void);
 static void rpc_received(char *, struct sockaddr_in *, int);
-static struct _dom_binding *xid2ypdb(u_int32_t);
-static u_int32_t unique_xid(struct _dom_binding *);
+static struct _dom_binding *xid2ypdb(uint32_t);
+static uint32_t unique_xid(struct _dom_binding *);
 static int broadcast(char *, int);
 static int direct(char *, int);
 static int direct_set(char *, int, struct _dom_binding *);
@@ -719,7 +719,7 @@
 	msg.rm_call.cb_verf = rpcua-ah_verf;
 
 	msg.rm_xid = ypdb-dom_xid;
-	xdrmem_create(xdr, buf, (u_int)sizeof(buf), XDR_ENCODE);
+	xdrmem_create(xdr, buf, (unsigned)sizeof(buf), XDR_ENCODE);
 	if (!xdr_callmsg(xdr, msg)) {
 		st = RPC_CANTENCODEARGS;
 		AUTH_DESTROY(rpcua);
@@ -791,7 +791,7 @@
 	msg.rm_call.cb_verf = rpcua-ah_verf;
 
 	msg.rm_xid = ypdb-dom_xid;
-	xdrmem_create(xdr, buf, (u_int)sizeof(buf), XDR_ENCODE);
+	xdrmem_create(xdr, buf, (unsigned)sizeof(buf), XDR_ENCODE);
 	if (!xdr_callmsg(xdr, msg)) {
 		st = RPC_CANTENCODEARGS;
 		AUTH_DESTROY(rpcua);
@@ -1068,18 +1068,18 @@
 #endif
 		return RPC_CANTRECV;
 	}
-	if ((size_t)inlen  sizeof(u_int32_t))
+	if ((size_t)inlen  sizeof(uint32_t))
 		goto recv_again;
 
 	/*
 	 * see if reply transaction id matches sent id.
 	 * If so, decode the results.
 	 */
-	xdrmem_create(xdr, buf, (u_int)inlen, XDR_DECODE);
+	xdrmem_create(xdr, buf, (unsigned)inlen, XDR_DECODE);
 	if (xdr_replymsg(xdr, msg)) {
 		if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) 
 		(msg.acpted_rply.ar_stat == SUCCESS)) {
-			raddr.sin_port = htons((u_short)rmtcr_port);
+			raddr.sin_port = htons((uint16_t)rmtcr_port);
 			ypdb = xid2ypdb(msg.rm_xid);
 			if (ypdb != NULL)
 rpc_received(ypdb-dom_domain, raddr, 0);
@@ -1129,14 +1129,14 @@
 #endif
 		return RPC_CANTRECV;
 	}
-	if ((size_t)inlen  sizeof(u_int32_t))
+	if ((size_t)inlen  sizeof(uint32_t))
 		goto recv_again;
 
 	/*
 	 * see if reply transaction id matches sent id.
 	 * If so, decode the results.
 	 */
-	xdrmem_create(xdr, buf, (u_int)inlen, XDR_DECODE);
+	xdrmem_create(xdr, buf, (unsigned)inlen, XDR_DECODE);
 	if (xdr_replymsg(xdr, msg)) {
 		if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) 
 		(msg.acpted_rply.ar_stat == SUCCESS)) {
@@ -1244,7 +1244,7 @@
 }
 
 static struct _dom_binding *
-xid2ypdb(u_int32_t xid)
+xid2ypdb(uint32_t xid)
 {
 	struct _dom_binding *ypdb;
 
@@ -1254,12 +1254,12 @@
 	return (ypdb);
 }
 
-static u_int32_t
+static uint32_t
 unique_xid(struct _dom_binding *ypdb)
 {
-	u_int32_t tmp_xid;
+	uint32_t tmp_xid;
 
-	tmp_xid = ((u_int32_t)(u_long)ypdb)  0x;
+	tmp_xid = ((uint32_t)(unsigned long)ypdb)  0x;
 	while (xid2ypdb(tmp_xid) != NULL)
 		tmp_xid++;
 



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:43:10 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't use _t as an identifier suffix meaning variable containing a time.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.65 src/usr.sbin/ypbind/ypbind.c:1.66
--- src/usr.sbin/ypbind/ypbind.c:1.65	Mon May 23 02:36:35 2011
+++ src/usr.sbin/ypbind/ypbind.c	Mon May 23 02:43:10 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.65 2011/05/23 02:36:35 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.66 2011/05/23 02:43:10 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.65 2011/05/23 02:36:35 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.66 2011/05/23 02:43:10 dholland Exp $);
 #endif
 
 #include sys/param.h
@@ -83,8 +83,8 @@
 	int dom_socket;
 	CLIENT *dom_client;
 	long dom_vers;
-	time_t dom_check_t;
-	time_t dom_ask_t;
+	time_t dom_checktime;
+	time_t dom_asktime;
 	int dom_lockfd;
 	int dom_alive;
 	uint32_t dom_xid;
@@ -326,19 +326,19 @@
 
 #ifdef HEURISTIC
 	(void)time(now);
-	if (now  ypdb-dom_ask_t + 5) {
+	if (now  ypdb-dom_asktime + 5) {
 		/*
 		 * Hmm. More than 2 requests in 5 seconds have indicated
 		 * that my binding is possibly incorrect.
 		 * Ok, do an immediate poll of the server.
 		 */
-		if (ypdb-dom_check_t = now) {
+		if (ypdb-dom_checktime = now) {
 			/* don't flood it */
-			ypdb-dom_check_t = 0;
+			ypdb-dom_checktime = 0;
 			check++;
 		}
 	}
-	ypdb-dom_ask_t = now;
+	ypdb-dom_asktime = now;
 #endif
 
 	res.ypbind_status = YPBIND_SUCC_VAL;
@@ -643,13 +643,13 @@
 
 	(void)time(t);
 	for (ypdb = ypbindlist; ypdb; ypdb = ypdb-dom_pnext) {
-		if (ypdb-dom_check_t  t) {
+		if (ypdb-dom_checktime  t) {
 			if (ypdb-dom_alive == 1)
 (void)ping(ypdb);
 			else
 (void)nag_servers(ypdb);
 			(void)time(t);
-			ypdb-dom_check_t = t + 5;
+			ypdb-dom_checktime = t + 5;
 		}
 	}
 }
@@ -1134,7 +1134,7 @@
 			sizeof ypdb-dom_server_addr)) {
 			ypdb-dom_alive = 1;
 			/* recheck binding in 60 sec */
-			ypdb-dom_check_t = time(NULL) + 60;
+			ypdb-dom_checktime = time(NULL) + 60;
 		}
 		return;
 	}
@@ -1142,7 +1142,7 @@
 	(void)memcpy(ypdb-dom_server_addr, raddrp,
 	sizeof ypdb-dom_server_addr);
 	/* recheck binding in 60 seconds */
-	ypdb-dom_check_t = time(NULL) + 60;
+	ypdb-dom_checktime = time(NULL) + 60;
 	ypdb-dom_vers = YPVERS;
 	ypdb-dom_alive = 1;
 



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:54:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
sort includes


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.66 src/usr.sbin/ypbind/ypbind.c:1.67
--- src/usr.sbin/ypbind/ypbind.c:1.66	Mon May 23 02:43:10 2011
+++ src/usr.sbin/ypbind/ypbind.c	Mon May 23 02:54:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.66 2011/05/23 02:43:10 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.67 2011/05/23 02:54:53 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,42 +28,43 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.66 2011/05/23 02:43:10 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.67 2011/05/23 02:54:53 dholland Exp $);
 #endif
 
-#include sys/param.h
 #include sys/types.h
+#include sys/param.h
+#include sys/file.h
 #include sys/ioctl.h
 #include sys/signal.h
 #include sys/socket.h
-#include sys/file.h
-#include sys/uio.h
-#include sys/syslog.h
 #include sys/stat.h
+#include sys/syslog.h
+#include sys/uio.h
+#include arpa/inet.h
+#include net/if.h
+#include ctype.h
+#include dirent.h
+#include err.h
+#include errno.h
 #include fcntl.h
+#include ifaddrs.h
 #include limits.h
+#include netdb.h
+#include stdarg.h
 #include stdio.h
 #include stdlib.h
-#include errno.h
-#include syslog.h
-#include stdarg.h
-#include ctype.h
-#include dirent.h
-#include netdb.h
 #include string.h
-#include err.h
+#include syslog.h
+#include unistd.h
+#include util.h
+
 #include rpc/rpc.h
 #include rpc/xdr.h
-#include net/if.h
-#include arpa/inet.h
 #include rpc/pmap_clnt.h
 #include rpc/pmap_prot.h
 #include rpc/pmap_rmt.h
-#include unistd.h
-#include util.h
 #include rpcsvc/yp_prot.h
 #include rpcsvc/ypclnt.h
-#include ifaddrs.h
 
 #include pathnames.h
 



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:06:42 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
u_int32_t - uint32_t and similar


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:36:35 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Introduce DPRINTF() macro, remove most #ifdef DEBUG usages.
No change to compiler output.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:43:10 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't use _t as an identifier suffix meaning variable containing a time.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-05-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 23 02:54:53 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
sort includes


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-03-29 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Mar 30 05:24:06 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't cast return value of malloc


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.sbin/ypbind/ypbind.c

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

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.62 src/usr.sbin/ypbind/ypbind.c:1.63
--- src/usr.sbin/ypbind/ypbind.c:1.62	Wed Mar 30 05:20:59 2011
+++ src/usr.sbin/ypbind/ypbind.c	Wed Mar 30 05:24:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.62 2011/03/30 05:20:59 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.63 2011/03/30 05:24:05 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt dera...@fsa.ca
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef LINT
-__RCSID($NetBSD: ypbind.c,v 1.62 2011/03/30 05:20:59 dholland Exp $);
+__RCSID($NetBSD: ypbind.c,v 1.63 2011/03/30 05:24:05 dholland Exp $);
 #endif
 
 #include sys/param.h
@@ -180,7 +180,7 @@
 {
 	struct _dom_binding *ypdb;
 
-	if ((ypdb = (struct _dom_binding *)malloc(sizeof *ypdb)) == NULL) {
+	if ((ypdb = malloc(sizeof *ypdb)) == NULL) {
 		yp_log(LOG_ERR, makebinding);
 		exit(1);
 	}



CVS commit: src/usr.sbin/ypbind

2011-03-29 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Mar 30 05:21:00 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
use __printflike()


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.sbin/ypbind/ypbind.c

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



CVS commit: src/usr.sbin/ypbind

2011-03-29 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Mar 30 05:24:06 UTC 2011

Modified Files:
src/usr.sbin/ypbind: ypbind.c

Log Message:
Don't cast return value of malloc


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.sbin/ypbind/ypbind.c

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