linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/7] mountd: Make NFS version checks more strict
Date: Mon, 20 Sep 2010 12:32:34 -0400	[thread overview]
Message-ID: <20100920163234.3170.57979.stgit@ellison.1015granger.net> (raw)
In-Reply-To: <20100920162616.3170.24625.stgit@ellison.1015granger.net>

Ensure users and programmers specify NFS version numbers correctly.
This also makes the next patch more clean.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 utils/mountd/mountd.c |   47 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
index 982b06e..753fd37 100644
--- a/utils/mountd/mountd.c
+++ b/utils/mountd/mountd.c
@@ -71,16 +71,34 @@ static struct option longopts[] =
 	{ NULL, 0, 0, 0 }
 };
 
-static int nfs_version = -1;
+#define NFSVERSBIT(vers)	(0x1 << (vers - 1))
+#define NFSVERSBIT_ALL		(NFSVERSBIT(2) | NFSVERSBIT(3) | NFSVERSBIT(4))
+
+static int nfs_version = NFSVERSBIT_ALL;
+
+static int version2(void)
+{
+	return nfs_version & NFSVERSBIT(2);
+}
+
+static int version3(void)
+{
+	return nfs_version & NFSVERSBIT(3);
+}
+
+static int version_any(void)
+{
+	return nfs_version & NFSVERSBIT_ALL;
+}
 
 static void
 unregister_services (void)
 {
-	if (nfs_version & (0x1 << 1)) {
+	if (version2()) {
 		pmap_unset (MOUNTPROG, MOUNTVERS);
 		pmap_unset (MOUNTPROG, MOUNTVERS_POSIX);
 	}
-	if (nfs_version & (0x1 << 2))
+	if (version3())
 		pmap_unset (MOUNTPROG, MOUNTVERS_NFSV3);
 }
 
@@ -673,6 +691,7 @@ main(int argc, char **argv)
 	int	port = 0;
 	int	descriptors = 0;
 	int	c;
+	int	vers;
 	struct sigaction sa;
 	struct rlimit rlim;
 
@@ -716,7 +735,13 @@ main(int argc, char **argv)
 			}
 			break;
 		case 'N':
-			nfs_version &= ~(1 << (atoi (optarg) - 1));
+			vers = atoi(optarg);
+			if (vers < 2 || vers > 4) {
+				fprintf(stderr, "%s: bad version number: %s\n",
+					argv[0], optarg);
+				usage(argv[0], 1);
+			}
+			nfs_version &= ~NFSVERSBIT(vers);
 			break;
 		case 'n':
 			_rpcfdtype = SOCK_DGRAM;
@@ -735,7 +760,13 @@ main(int argc, char **argv)
 			num_threads = atoi (optarg);
 			break;
 		case 'V':
-			nfs_version |= 1 << (atoi (optarg) - 1);
+			vers = atoi(optarg);
+			if (vers < 2 || vers > 4) {
+				fprintf(stderr, "%s: bad version number: %s\n",
+					argv[0], optarg);
+				usage(argv[0], 1);
+			}
+			nfs_version |= NFSVERSBIT(vers);
 			break;
 		case 'v':
 			printf("kmountd %s\n", VERSION);
@@ -750,7 +781,7 @@ main(int argc, char **argv)
 	/* No more arguments allowed.
 	 * Require at least one valid version (2, 3, or 4)
 	 */
-	if (optind != argc || !(nfs_version & 0xE))
+	if (optind != argc || !version_any())
 		usage(argv [0], 1);
 
 	if (chdir(state_dir)) {
@@ -798,13 +829,13 @@ main(int argc, char **argv)
 	if (new_cache)
 		cache_open();
 
-	if (nfs_version & (0x1 << 1)) {
+	if (version2()) {
 		rpc_init("mountd", MOUNTPROG, MOUNTVERS,
 			 mount_dispatch, port);
 		rpc_init("mountd", MOUNTPROG, MOUNTVERS_POSIX,
 			 mount_dispatch, port);
 	}
-	if (nfs_version & (0x1 << 2))
+	if (version3())
 		rpc_init("mountd", MOUNTPROG, MOUNTVERS_NFSV3,
 			 mount_dispatch, port);
 


  reply	other threads:[~2010-09-20 16:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-20 16:32 [PATCH 0/7] The final patches for mountd IPv6 support Chuck Lever
2010-09-20 16:32 ` Chuck Lever [this message]
2010-09-20 16:32 ` [PATCH 2/7] mountd: Support TI-RPC mountd listener Chuck Lever
2010-09-20 16:32 ` [PATCH 3/7] mountd: Unregister mountd if my_svc_run() returns Chuck Lever
2010-09-20 16:33 ` [PATCH 4/7] mountd: Fix up version and usage messages Chuck Lever
2010-09-20 16:33 ` [PATCH 5/7] mountd: Use MNT status values instead of NFSERR Chuck Lever
2010-09-20 16:33 ` [PATCH 6/7] mountd: Update mountd/exportfs man pages to reflect IPv6 changes Chuck Lever
2010-09-20 16:33 ` [PATCH 7/7] nfsd: Enable IPv6 support in rpc.nfsd again Chuck Lever
     [not found] ` <20100920162616.3170.24625.stgit-ewv44WTpT0t9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-09-28 12:08   ` [PATCH 0/7] The final patches for mountd IPv6 support Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100920163234.3170.57979.stgit@ellison.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).