From patchwork Fri Nov 16 17:36:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1756761 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B0ADF4005F for ; Fri, 16 Nov 2012 17:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752253Ab2KPRhO (ORCPT ); Fri, 16 Nov 2012 12:37:14 -0500 Received: from mail-vc0-f174.google.com ([209.85.220.174]:47263 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233Ab2KPRhN (ORCPT ); Fri, 16 Nov 2012 12:37:13 -0500 Received: by mail-vc0-f174.google.com with SMTP id fk26so3086806vcb.19 for ; Fri, 16 Nov 2012 09:37:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=UHFTcTzMeg53ZnSo8SIjE64e3vcLtc42dZq2+cJ/sfw=; b=ALGNXGBREtu537814OCsx7AgFWe4UIqdISdYZGOe06nsINqZfm734du1SOAdjIw/wW kV3eDSnqBaz42AN2qcsDRlE2hNjjVadxfMnw2f8A+mwZDZvKWbgg58ZV5g5E1J1o6zvw GZlf3zCrHyVg0QpqKngm9gUMF7KVBqTnW5Jryv5D9Owt6ABN5W3hsk4r4khYxGUUPWf9 MdWi84Kyfy/ebVT80GbgyvLrxKxfWeOLqPyjwRy9DXX09/e2jLWqsARPSf2G5Q9xK32M +4g/rOFPze2M3nnD+nYYw4VhrA0gRh9ruZDQ/352Ul5JmU+Kr1qF7wPTRKp9KUnDaxvO O68Q== Received: by 10.58.67.199 with SMTP id p7mr5587814vet.40.1353087433311; Fri, 16 Nov 2012 09:37:13 -0800 (PST) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id u6sm1189621vdi.20.2012.11.16.09.37.11 (version=SSLv3 cipher=OTHER); Fri, 16 Nov 2012 09:37:12 -0800 (PST) From: Jeff Layton To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, fsauter@innominate.com, almiller_1@yahoo.co.uk Subject: [PATCH 6/6] cifs: parse the device name into UNC and prepath Date: Fri, 16 Nov 2012 12:36:54 -0500 Message-Id: <1353087414-32152-7-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1353087414-32152-1-git-send-email-jlayton@redhat.com> References: <1353087414-32152-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQnyAPlJxv0GFBMJhwJ3nL6nKS178r7zhe1Kz3orfalhR5Hx+oEYfB5JVB8VE8OFxSTV26jA Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org This should fix a regression that was introduced when the new mount option parser went in. Also, when the unc= and prefixpath= options are provided, check their values against the ones we parsed from the device string. If they differ, then throw a warning that tells the user that we're using the values from the unc= option for now, but that that will change in 3.10. Signed-off-by: Jeff Layton --- fs/cifs/connect.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 7 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index b1f352a..b9f3dd7 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1090,6 +1090,52 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol) return 0; } +/* + * Parse a devname into substrings and populate the vol->UNC and vol->prepath + * fields with the result. Returns 0 on success and an error otherwise. + */ +static int +cifs_parse_devname(const char *devname, struct smb_vol *vol) +{ + char *pos; + const char *delims = "/\\"; + size_t len; + + /* make sure we have a valid UNC double delimiter prefix */ + len = strspn(devname, delims); + if (len != 2) + return -EINVAL; + + /* find delimiter between host and sharename */ + pos = strpbrk(devname + 2, delims); + if (!pos) + return -EINVAL; + + /* skip past delimiter */ + ++pos; + + /* now go until next delimiter or end of string */ + len = strcspn(pos, delims); + + /* move "pos" up to delimiter or NULL */ + pos += len; + vol->UNC = kstrndup(devname, pos - devname, GFP_KERNEL); + if (!vol->UNC) + return -ENOMEM; + + convert_delimiter(vol->UNC, '\\'); + + /* If pos is NULL, or is a bogus trailing delimiter then no prepath */ + if (!*pos++ || !*pos) + return 0; + + vol->prepath = kstrdup(pos, GFP_KERNEL); + if (!vol->prepath) + return -ENOMEM; + + return 0; +} + static int cifs_parse_mount_options(const char *mountdata, const char *devname, struct smb_vol *vol) @@ -1172,6 +1218,16 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, vol->backupuid_specified = false; /* no backup intent for a user */ vol->backupgid_specified = false; /* no backup intent for a group */ + /* + * For now, we ignore -EINVAL errors under the assumption that the + * unc= and prefixpath= options will be usable. + */ + if (cifs_parse_devname(devname, vol) == -ENOMEM) { + printk(KERN_ERR "CIFS: Unable to allocate memory to parse " + "device string.\n"); + goto out_nomem; + } + while ((data = strsep(&options, separator)) != NULL) { substring_t args[MAX_OPT_ARGS]; unsigned long option; @@ -1557,18 +1613,31 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, got_ip = true; break; case Opt_unc: - kfree(vol->UNC); + string = vol->UNC; vol->UNC = match_strdup(args); - if (vol->UNC == NULL) + if (vol->UNC == NULL) { + kfree(string); goto out_nomem; + } convert_delimiter(vol->UNC, '\\'); if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') { - printk(KERN_WARNING "CIFS: UNC Path does not " + kfree(string); + printk(KERN_ERR "CIFS: UNC Path does not " "begin with // or \\\\\n"); goto cifs_parse_mount_err; } + /* Compare old unc= option to new one */ + if (!string || strcmp(string, vol->UNC)) + printk(KERN_WARNING "CIFS: the value of the " + "unc= mount option does not match the " + "device string. Using the unc= option " + "for now. In 3.10, that option will " + "be ignored and the contents of the " + "device string will be used " + "instead. (%s != %s)\n", string, + vol->UNC); break; case Opt_domain: string = match_strdup(args); @@ -1607,10 +1676,22 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, if (*args[0].from == '/' || *args[0].from == '\\') args[0].from++; - kfree(vol->prepath); + string = vol->prepath; vol->prepath = match_strdup(args); - if (vol->prepath == NULL) + if (vol->prepath == NULL) { + kfree(string); goto out_nomem; + } + /* Compare old prefixpath= option to new one */ + if (!string || strcmp(string, vol->prepath)) + printk(KERN_WARNING "CIFS: the value of the " + "prefixpath= mount option does not " + "match the device string. Using the " + "prefixpath= option for now. In 3.10, " + "that option will be ignored and the " + "contents of the device string will be " + "used instead.(%s != %s)\n", string, + vol->prepath); break; case Opt_iocharset: string = match_strdup(args); @@ -1768,8 +1849,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, } #endif if (!vol->UNC) { - cERROR(1, "CIFS mount error: No UNC path (e.g. -o " - "unc=\\\\192.168.1.100\\public) specified"); + cERROR(1, "CIFS mount error: No usable UNC path provided in " + "device string or in unc= option!"); goto cifs_parse_mount_err; }