From patchwork Sun Mar 21 19:20:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 48227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by ozlabs.org (Postfix) with ESMTP id CAF5AB7CF6 for ; Mon, 22 Mar 2010 06:20:40 +1100 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 75062AD23E; Sun, 21 Mar 2010 13:20:41 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=3.8 tests=AWL, BAYES_00, NO_MORE_FUNN, SPF_PASS autolearn=no version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from cdptpa-omtalb.mail.rr.com (cdptpa-omtalb.mail.rr.com [75.180.132.120]) by lists.samba.org (Postfix) with ESMTP id 0E887AD14C for ; Sun, 21 Mar 2010 13:20:29 -0600 (MDT) X-Authority-Analysis: v=1.0 c=1 a=C_aNzjLGdccA:10 a=20KFwNOVAAAA:8 a=b8v1LGMt2nBja05RxpwA:9 a=8vXQI5C773Z-wKLZFAgA:7 a=xs2w3cQN3hh4d9BkHn1ciX05gCUA:4 a=jEp0ucaQiEUA:10 a=3vGVw8fXuXM-9puz:21 a=SaeVQ2ijR3WQXS5J:21 X-Cloudmark-Score: 0 X-Originating-IP: 71.70.153.3 Received: from [71.70.153.3] ([71.70.153.3:53418] helo=mail.poochiereds.net) by cdptpa-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id C3/AF-07392-B7176AB4; Sun, 21 Mar 2010 19:20:27 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id 55D0858057; Sun, 21 Mar 2010 15:20:27 -0400 (EDT) From: Jeff Layton To: linux-cifs-client@lists.samba.org Date: Sun, 21 Mar 2010 15:20:18 -0400 Message-Id: <1269199227-21446-2-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: Subject: [linux-cifs-client] [PATCH 01/10] mount.cifs: clean up parse_server X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org Get rid of a lot of unnecessary nesting. Signed-off-by: Jeff Layton --- mount.cifs.c | 138 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 69 insertions(+), 69 deletions(-) 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' },