walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
f5b3ef3
commit 60107345a32982bb0ff9eb8a17f8f0edf0276a98
f5b3ef3
Author: J. Bruce Fields <bfields@citi.umich.edu>
f5b3ef3
Date:   Thu Aug 28 11:20:58 2008 -0400
f5b3ef3
f5b3ef3
    Minor mountd.c cleanup
f5b3ef3
    
f5b3ef3
    I find it more readable to have the normal (non-error) case unindented,
f5b3ef3
    and to keep conditionals relatively simple, as is the usual kernel
f5b3ef3
    style.  Fix some inconsistent indentation while we're there.
f5b3ef3
    
f5b3ef3
    Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
f5b3ef3
    Signed-off-by: Steve Dickson <steved@redhat.com>
f5b3ef3
f5b3ef3
diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
f5b3ef3
index 0facf89..d5b8c0d 100644
f5b3ef3
--- a/utils/mountd/mountd.c
f5b3ef3
+++ b/utils/mountd/mountd.c
f5b3ef3
@@ -175,9 +175,9 @@ killer (int sig)
f5b3ef3
 static void
f5b3ef3
 sig_hup (int sig)
f5b3ef3
 {
f5b3ef3
-  /* don't exit on SIGHUP */
f5b3ef3
-  xlog (L_NOTICE, "Received SIGHUP... Ignoring.\n", sig);
f5b3ef3
-  return;
f5b3ef3
+	/* don't exit on SIGHUP */
f5b3ef3
+	xlog (L_NOTICE, "Received SIGHUP... Ignoring.\n", sig);
f5b3ef3
+	return;
f5b3ef3
 }
f5b3ef3
 
f5b3ef3
 bool_t
f5b3ef3
@@ -192,7 +192,8 @@ mount_mnt_1_svc(struct svc_req *rqstp, dirpath *path, fhstatus *res)
f5b3ef3
 	struct nfs_fh_len *fh;
f5b3ef3
 
f5b3ef3
 	xlog(D_CALL, "MNT1(%s) called", *path);
f5b3ef3
-	if ((fh = get_rootfh(rqstp, path, &res->fhs_status, 0)) != NULL)
f5b3ef3
+	fh = get_rootfh(rqstp, path, &res->fhs_status, 0);
f5b3ef3
+	if (fh)
f5b3ef3
 		memcpy(&res->fhstatus_u.fhs_fhandle, fh->fh_handle, 32);
f5b3ef3
 	return 1;
f5b3ef3
 }
f5b3ef3
@@ -304,7 +305,8 @@ mount_pathconf_2_svc(struct svc_req *rqstp, dirpath *path, ppathcnf *res)
f5b3ef3
 	}
f5b3ef3
 
f5b3ef3
 	/* Now authenticate the intruder... */
f5b3ef3
-	if (!(exp = auth_authenticate("pathconf", sin, p))) {
f5b3ef3
+	exp = auth_authenticate("pathconf", sin, p);
f5b3ef3
+	if (!exp) {
f5b3ef3
 		return 1;
f5b3ef3
 	} else if (stat(p, &stb) < 0) {
f5b3ef3
 		xlog(L_WARNING, "can't stat exported dir %s: %s",
f5b3ef3
@@ -344,18 +346,18 @@ mount_mnt_3_svc(struct svc_req *rqstp, dirpath *path, mountres3 *res)
f5b3ef3
 	 * issue with older Linux clients, who inspect the list in reversed
f5b3ef3
 	 * order.
f5b3ef3
 	 */
f5b3ef3
+	struct mountres3_ok *ok = &res->mountres3_u.mountinfo;
f5b3ef3
 	struct nfs_fh_len *fh;
f5b3ef3
 
f5b3ef3
 	xlog(D_CALL, "MNT3(%s) called", *path);
f5b3ef3
-	if ((fh = get_rootfh(rqstp, path, &res->fhs_status, 1)) != NULL) {
f5b3ef3
-		struct mountres3_ok	*ok = &res->mountres3_u.mountinfo;
f5b3ef3
-
f5b3ef3
-		ok->fhandle.fhandle3_len = fh->fh_size;
f5b3ef3
-		ok->fhandle.fhandle3_val = (char *)fh->fh_handle;
f5b3ef3
-		ok->auth_flavors.auth_flavors_len
f5b3ef3
-			= sizeof(flavors)/sizeof(flavors[0]);
f5b3ef3
-		ok->auth_flavors.auth_flavors_val = flavors;
f5b3ef3
-	}
f5b3ef3
+	fh = get_rootfh(rqstp, path, &res->fhs_status, 1);
f5b3ef3
+	if (!fh)
f5b3ef3
+		return 1;
f5b3ef3
+
f5b3ef3
+	ok->fhandle.fhandle3_len = fh->fh_size;
f5b3ef3
+	ok->fhandle.fhandle3_val = (char *)fh->fh_handle;
f5b3ef3
+	ok->auth_flavors.auth_flavors_len = sizeof(flavors)/sizeof(flavors[0]);
f5b3ef3
+	ok->auth_flavors.auth_flavors_val = flavors;
f5b3ef3
 	return 1;
f5b3ef3
 }
f5b3ef3
 
f5b3ef3
@@ -366,6 +368,7 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, mountstat3 *error, int v3)
f5b3ef3
 		(struct sockaddr_in *) svc_getcaller(rqstp->rq_xprt);
f5b3ef3
 	struct stat	stb, estb;
f5b3ef3
 	nfs_export	*exp;
f5b3ef3
+	struct nfs_fh_len *fh;
f5b3ef3
 	char		rpath[MAXPATHLEN+1];
f5b3ef3
 	char		*p = *path;
f5b3ef3
 
f5b3ef3
@@ -382,57 +385,65 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, mountstat3 *error, int v3)
f5b3ef3
 	}
f5b3ef3
 
f5b3ef3
 	/* Now authenticate the intruder... */
f5b3ef3
-	if (!(exp = auth_authenticate("mount", sin, p))) {
f5b3ef3
+	exp = auth_authenticate("mount", sin, p);
f5b3ef3
+	if (!exp) {
f5b3ef3
 		*error = NFSERR_ACCES;
f5b3ef3
-	} else if (stat(p, &stb) < 0) {
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+	if (stat(p, &stb) < 0) {
f5b3ef3
 		xlog(L_WARNING, "can't stat exported dir %s: %s",
f5b3ef3
 				p, strerror(errno));
f5b3ef3
 		if (errno == ENOENT)
f5b3ef3
 			*error = NFSERR_NOENT;
f5b3ef3
 		else
f5b3ef3
 			*error = NFSERR_ACCES;
f5b3ef3
-	} else if (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) {
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+	if (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) {
f5b3ef3
 		xlog(L_WARNING, "%s is not a directory or regular file", p);
f5b3ef3
 		*error = NFSERR_NOTDIR;
f5b3ef3
-	} else if (stat(exp->m_export.e_path, &estb) < 0) {
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+	if (stat(exp->m_export.e_path, &estb) < 0) {
f5b3ef3
 		xlog(L_WARNING, "can't stat export point %s: %s",
f5b3ef3
 		     p, strerror(errno));
f5b3ef3
 		*error = NFSERR_NOENT;
f5b3ef3
-	} else if (estb.st_dev != stb.st_dev
f5b3ef3
-		   && (!new_cache || !(exp->m_export.e_flags & NFSEXP_CROSSMOUNT))
f5b3ef3
-		) {
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+	if (estb.st_dev != stb.st_dev
f5b3ef3
+		   && (!new_cache
f5b3ef3
+			   || !(exp->m_export.e_flags & NFSEXP_CROSSMOUNT))) {
f5b3ef3
 		xlog(L_WARNING, "request to export directory %s below nearest filesystem %s",
f5b3ef3
 		     p, exp->m_export.e_path);
f5b3ef3
 		*error = NFSERR_ACCES;
f5b3ef3
-	} else if (exp->m_export.e_mountpoint &&
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+	if (exp->m_export.e_mountpoint &&
f5b3ef3
 		   !is_mountpoint(exp->m_export.e_mountpoint[0]?
f5b3ef3
 				  exp->m_export.e_mountpoint:
f5b3ef3
 				  exp->m_export.e_path)) {
f5b3ef3
 		xlog(L_WARNING, "request to export an unmounted filesystem: %s",
f5b3ef3
 		     p);
f5b3ef3
 		*error = NFSERR_NOENT;
f5b3ef3
-	} else if (new_cache) {
f5b3ef3
+		return NULL;
f5b3ef3
+	}
f5b3ef3
+
f5b3ef3
+	if (new_cache) {
f5b3ef3
 		/* This will be a static private nfs_export with just one
f5b3ef3
 		 * address.  We feed it to kernel then extract the filehandle,
f5b3ef3
 		 * 
f5b3ef3
 		 */
f5b3ef3
-		struct nfs_fh_len  *fh;
f5b3ef3
 
f5b3ef3
 		if (cache_export(exp, p)) {
f5b3ef3
 			*error = NFSERR_ACCES;
f5b3ef3
 			return NULL;
f5b3ef3
 		}
f5b3ef3
 		fh = cache_get_filehandle(exp, v3?64:32, p);
f5b3ef3
-		if (fh == NULL) 
f5b3ef3
+		if (fh == NULL) {
f5b3ef3
 			*error = NFSERR_ACCES;
f5b3ef3
-		else {
f5b3ef3
-			*error = NFS_OK;
f5b3ef3
-			mountlist_add(inet_ntoa(sin->sin_addr), p);
f5b3ef3
+			return NULL;
f5b3ef3
 		}
f5b3ef3
-		return fh;
f5b3ef3
 	} else {
f5b3ef3
-		struct nfs_fh_len  *fh;
f5b3ef3
-
f5b3ef3
 		if (exp->m_exported<1)
f5b3ef3
 			export_export(exp);
f5b3ef3
 		if (!exp->m_xtabent)
f5b3ef3
@@ -448,15 +459,15 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, mountstat3 *error, int v3)
f5b3ef3
 				fh = getfh_old ((struct sockaddr *) sin,
f5b3ef3
 						stb.st_dev, stb.st_ino);
f5b3ef3
 		}
f5b3ef3
-		if (fh != NULL) {
f5b3ef3
-			mountlist_add(inet_ntoa(sin->sin_addr), p);
f5b3ef3
-			*error = NFS_OK;
f5b3ef3
-			return fh;
f5b3ef3
+		if (fh == NULL) {
f5b3ef3
+			xlog(L_WARNING, "getfh failed: %s", strerror(errno));
f5b3ef3
+			*error = NFSERR_ACCES;
f5b3ef3
+			return NULL;
f5b3ef3
 		}
f5b3ef3
-		xlog(L_WARNING, "getfh failed: %s", strerror(errno));
f5b3ef3
-		*error = NFSERR_ACCES;
f5b3ef3
 	}
f5b3ef3
-	return NULL;
f5b3ef3
+	*error = NFS_OK;
f5b3ef3
+	mountlist_add(inet_ntoa(sin->sin_addr), p);
f5b3ef3
+	return fh;
f5b3ef3
 }
f5b3ef3
 
f5b3ef3
 static exports