From zeising@daemonic.se  Mon Jul 16 14:46:01 2012
Return-Path: <zeising@daemonic.se>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 721E5106566C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 14:46:01 +0000 (UTC)
	(envelope-from zeising@daemonic.se)
Received: from mail.lysator.liu.se (mail.lysator.liu.se [IPv6:2001:6b0:17:f0a0::3])
	by mx1.freebsd.org (Postfix) with ESMTP id C4F698FC17
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 14:46:00 +0000 (UTC)
Received: from mail.lysator.liu.se (localhost [127.0.0.1])
	by mail.lysator.liu.se (Postfix) with ESMTP id B60FB40002
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 16:45:58 +0200 (CEST)
Received: by mail.lysator.liu.se (Postfix, from userid 1004)
	id ABC5440006; Mon, 16 Jul 2012 16:45:58 +0200 (CEST)
Received: from mx.daemonic.se (h-45-105.a163.priv.bahnhof.se [94.254.45.105])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mail.lysator.liu.se (Postfix) with ESMTPSA id 3155B40002
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 16:45:58 +0200 (CEST)
Received: from mailscanner.daemonic.se (mailscanner.daemonic.se [IPv6:2001:470:dca9:0:1::6])
	by mx.daemonic.se (Postfix) with ESMTPS id 3WbS9K3hRKz8gtM
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 16:45:57 +0200 (CEST)
Received: from mx.daemonic.se ([IPv6:2001:470:dca9:0:1::3]) (using TLS with cipher CAMELLIA256-SHA)
	by mailscanner.daemonic.se (mailscanner.daemonic.se [2001:470:dca9:0:1::6]) (amavisd-new, port 10025)
	with ESMTPS id g94IXciPVoxw for <FreeBSD-gnats-submit@freebsd.org>;
	Mon, 16 Jul 2012 16:45:51 +0200 (CEST)
Received: from mail.daemonic.se (mail.daemonic.se [IPv6:2001:470:dca9:0:1::4])
	by mx.daemonic.se (Postfix) with ESMTPS id 3WbS9C5727z8gtL
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 16:45:51 +0200 (CEST)
Received: from tifa.daemonic.se (tifa.daemonic.se [IPv6:2001:470:dca9:1::6])
	by mail.daemonic.se (Postfix) with ESMTPSA id 3WbS9C4c4Sz9Ctj
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Jul 2012 16:45:51 +0200 (CEST)
Received: by tifa.daemonic.se (Postfix, from userid 1001)
	id 191A7228F5; Mon, 16 Jul 2012 16:45:51 +0200 (CEST)
Message-Id: <20120716144551.191A7228F5@tifa.daemonic.se>
Date: Mon, 16 Jul 2012 16:45:51 +0200 (CEST)
From: Niclas Zeising <zeising@daemonic.se>
Reply-To: Niclas Zeising <zeising@daemonic.se>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] make it possible for yp_mkdb to send YPPROC_CLEAR to specified host
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         169911
>Category:       bin
>Synopsis:       [PATCH] make it possible for yp_mkdb(8) to send YPPROC_CLEAR to specified host
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 16 14:50:10 UTC 2012
>Closed-Date:    
>Last-Modified:  Mon Jul 16 15:55:09 UTC 2012
>Originator:     Niclas Zeising
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
>Environment:
System: FreeBSD tifa.daemonic.se 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r231776M: Wed Feb 15 22:30:06 CET 2012 root@tifa.daemonic.se:/usr/obj/usr/src/sys/TIFA amd64


	
>Description:
	yp_mkdb is used to generate maps for NIS to hand out.  It is possible to have yp_mkdb send a YPPROC_CLEAR to localhost to have the local NIS server to close open connections and flush it's cache.
	When running a NIS server in a jail, localhost does not exists, which means there is no way to accomplish this 'clearing'.
>How-To-Repeat:
	
>Fix:

	Attached patch adds a new option -C hostname to yp_mkdb that makes it send the YPPROC_CLEAR to the specified hostname instead of localhost.
	This makes it possible to 'clear' a NIS server running in a jail.  This option is mutually exclusive with -c.

--- usr.sbin.yp_mkdb.c.diff begins here ---
Index: head/usr.sbin/yp_mkdb/yp_mkdb.c
===================================================================
--- head/usr.sbin/yp_mkdb/yp_mkdb.c	(revision 238532)
+++ head/usr.sbin/yp_mkdb/yp_mkdb.c	(working copy)
@@ -57,11 +57,12 @@
 static void
 usage(void)
 {
-	fprintf(stderr, "%s\n%s\n%s\n%s\n",
-	"usage: yp_mkdb -c",
+	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+	"usage: yp_mkdb [-c | -C hostname]",
 	"       yp_mkdb -u dbname",
-	"       yp_mkdb [-c] [-b] [-s] [-f] [-i inputfile] [-o outputfile]",
-	"               [-d domainname ] [-m mastername] inputfile dbname");
+	"       yp_mkdb [-c | -C hostname] [-b] [-s] [-f] [-i inputfile]",
+	"               [-o outputfile] [-d domainname ] [-m mastername]",
+	"               inputfile dbname");
 	exit(1);
 }
 
@@ -105,6 +106,7 @@
 	char *infile = NULL;
 	char *map = NULL;
 	char *domain = NULL;
+	char *clearhost = "localhost";
 	char *infilename = NULL;
 	char *outfilename = NULL;
 	char *mastername = NULL;
@@ -117,7 +119,7 @@
 	FILE *ifp;
 	char hname[MAXHOSTNAMELEN + 2];
 
-	while ((ch = getopt(argc, argv, "uhcbsfd:i:o:m:")) != -1) {
+	while ((ch = getopt(argc, argv, "uhcC:bsfd:i:o:m:")) != -1) {
 		switch (ch) {
 		case 'f':
 			filter_plusminus++;
@@ -128,6 +130,10 @@
 		case 'c':
 			clear++;
 			break;
+		case 'C':
+			clear++;
+			clearhost = optarg;
+			break;
 		case 'b':
 			interdom++;
 			break;
@@ -156,6 +162,9 @@
 	argc -= optind;
 	argv += optind;
 
+	if (clear > 1)
+		usage();
+
 	if (un) {
 		map = argv[0];
 		if (map == NULL)
@@ -332,7 +341,7 @@
 		char in = 0;
 		char *out = NULL;
 		int stat;
-		if ((stat = callrpc("localhost", YPPROG,YPVERS, YPPROC_CLEAR,
+		if ((stat = callrpc(clearhost, YPPROG,YPVERS, YPPROC_CLEAR,
 			(xdrproc_t)xdr_void, &in,
 			(xdrproc_t)xdr_void, out)) != RPC_SUCCESS) {
 			warnx("failed to send 'clear' to local ypserv: %s",
Index: head/usr.sbin/yp_mkdb/yp_mkdb.8
===================================================================
--- head/usr.sbin/yp_mkdb/yp_mkdb.8	(revision 238532)
+++ head/usr.sbin/yp_mkdb/yp_mkdb.8	(working copy)
@@ -42,7 +42,7 @@
 .Nm
 .Fl u Ar dbname
 .Nm
-.Op Fl c
+.Op Fl c | Fl C Ar hostname
 .Op Fl b
 .Op Fl s
 .Op Fl f
@@ -111,6 +111,12 @@
 .Nm
 will send the signal only after the new database has been successfully
 created.
+.It Fl C
+As
+.Fl c
+but send the YPPROC_CLEAR to the specified
+.Ar hostname
+instead.
 .It Fl b
 Cause
 .Nm
--- usr.sbin.yp_mkdb.c.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:
