Patchwork [01/10] mount.cifs: clean up parse_server

login
register
mail settings
Submitter Jeff Layton
Date March 21, 2010, 7:20 p.m.
Message ID <1269199227-21446-2-git-send-email-jlayton@redhat.com>
Download mbox | patch
Permalink /patch/48227/
State New
Headers show

Comments

Jeff Layton - March 21, 2010, 7:20 p.m.
Get rid of a lot of unnecessary nesting.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 mount.cifs.c |  138 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 69 insertions(+), 69 deletions(-)

Patch

diff --git a/mount.cifs.c b/mount.cifs.c
index 18f2a1e..dcd8584 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -991,94 +991,94 @@  static void replace_char(char *string, char from, char to, int maxlen)
 
 /* Note that caller frees the returned buffer if necessary */
 static struct addrinfo *
-parse_server(char ** punc_name)
+parse_server(char **punc_name)
 {
-	char * unc_name = *punc_name;
+	char *unc_name = *punc_name;
 	int length = strnlen(unc_name, MAX_UNC_LEN);
-	char * share;
+	char *share;
 	struct addrinfo *addrlist;
 	int rc;
 
 	if(length > (MAX_UNC_LEN - 1)) {
-		fprintf(stderr, "mount error: UNC name too long");
+		fprintf(stderr, "mount error: UNC name too long\n");
 		return NULL;
 	}
+
+	if(length < 3) {
+		fprintf(stderr, "mount error: UNC name too short\n");
+		return NULL;
+	}
+
 	if ((strncasecmp("cifs://", unc_name, 7) == 0) ||
 	    (strncasecmp("smb://", unc_name, 6) == 0)) {
-		fprintf(stderr, "\nMounting cifs URL not implemented yet. Attempt to mount %s\n", unc_name);
+		fprintf(stderr, "Mounting cifs URL not implemented yet. Attempt to mount %s\n", unc_name);
 		return NULL;
 	}
 
-	if(length < 3) {
-		/* BB add code to find DFS root here */
-		fprintf(stderr, "\nMounting the DFS root for domain not implemented yet\n");
-		return NULL;
-	} else {
-		if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) {
-			/* check for nfs syntax ie server:share */
-			share = strchr(unc_name,':');
-			if(share) {
-				*punc_name = (char *)malloc(length+3);
-				if(*punc_name == NULL) {
-					/* put the original string back  if 
-					   no memory left */
-					*punc_name = unc_name;
-					return NULL;
-				}
-				*share = '/';
-				strlcpy((*punc_name)+2,unc_name,length+1);
-				SAFE_FREE(unc_name);
-				unc_name = *punc_name;
-				unc_name[length+2] = 0;
-				goto continue_unc_parsing;
-			} else {
-				fprintf(stderr, "mount error: improperly formatted UNC name.");
-				fprintf(stderr, " %s does not begin with \\\\ or //\n",unc_name);
-				return NULL;
-			}
-		} else {
-continue_unc_parsing:
-			unc_name[0] = '/';
-			unc_name[1] = '/';
-			unc_name += 2;
-
-			/* allow for either delimiter between host and sharename */
-			if ((share = strpbrk(unc_name, "/\\"))) {
-				*share = 0;  /* temporarily terminate the string */
-				share += 1;
-				if(got_ip == 0) {
-					rc = getaddrinfo(unc_name, NULL, NULL, &addrlist);
-					if (rc != 0) {
-						fprintf(stderr, "mount error: could not resolve address for %s: %s\n",
-							unc_name, gai_strerror(rc));
-						addrlist = NULL;
-					}
-				}
-				*(share - 1) = '/'; /* put delimiter back */
+	if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) {
+		/* check for nfs syntax ie server:share */
+		share = strchr(unc_name,':');
+		if(!share) {
+			fprintf(stderr, "mount error: improperly formatted UNC name.");
+			fprintf(stderr, " %s does not begin with \\\\ or //\n",unc_name);
+			return NULL;
+		}
 
-				/* we don't convert the prefixpath delimiters since '\\' is a valid char in posix paths */
-				if ((prefixpath = strpbrk(share, "/\\"))) {
-					*prefixpath = 0;  /* permanently terminate the string */
-					if (!strlen(++prefixpath))
-						prefixpath = NULL; /* this needs to be done explicitly */
-				}
-				if(got_ip) {
-					if(verboseflag)
-						fprintf(stderr, "ip address specified explicitly\n");
-					return NULL;
-				}
-				/* BB should we pass an alternate version of the share name as Unicode */
+		*punc_name = (char *)malloc(length + 3);
+		if(*punc_name == NULL) {
+			*punc_name = unc_name;
+			return NULL;
+		}
 
-				return addrlist; 
-			} else {
-				/* BB add code to find DFS root (send null path on get DFS Referral to specified server here */
-				fprintf(stderr, "Mounting the DFS root for a particular server not implemented yet\n");
-				return NULL;
-			}
+		*share = '/';
+		strlcpy((*punc_name)+2, unc_name, length + 1);
+		SAFE_FREE(unc_name);
+		unc_name = *punc_name;
+		unc_name[length+2] = 0;
+	}
+
+	unc_name[0] = '/';
+	unc_name[1] = '/';
+	unc_name += 2;
+
+	/*
+	 * allow for either delimiter between host and sharename
+	 * If there's not one, then the UNC is malformed
+	 */
+	if (!(share = strpbrk(unc_name, "/\\"))) {
+		fprintf(stderr, "mount error: Malformed UNC\n");
+		return NULL;
+	}
+
+	*share = 0;  /* temporarily terminate the string */
+	share += 1;
+	if(got_ip == 0) {
+		rc = getaddrinfo(unc_name, NULL, NULL, &addrlist);
+		if (rc != 0) {
+			fprintf(stderr, "mount error: could not resolve address for %s: %s\n",
+				unc_name, gai_strerror(rc));
+			addrlist = NULL;
 		}
 	}
+	*(share - 1) = '/'; /* put delimiter back */
+
+	/* we don't convert the prefixpath delimiters since '\\' is a valid char in posix paths */
+	if ((prefixpath = strpbrk(share, "/\\"))) {
+		*prefixpath = 0;  /* permanently terminate the string */
+		if (!strlen(++prefixpath))
+			prefixpath = NULL; /* this needs to be done explicitly */
+	}
+	if(got_ip) {
+		if(verboseflag)
+			fprintf(stderr, "ip address specified explicitly\n");
+		return NULL;
+	}
+	/* BB should we pass an alternate version of the share name as Unicode */
+
+	return addrlist; 
 }
 
+
 static struct option longopts[] = {
 	{ "all", 0, NULL, 'a' },
 	{ "help",0, NULL, 'h' },