From patchwork Sun Apr 14 18:19:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Lovenberg X-Patchwork-Id: 2442601 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 0E9133FD1A for ; Sun, 14 Apr 2013 18:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752905Ab3DNSUW (ORCPT ); Sun, 14 Apr 2013 14:20:22 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:50642 "EHLO mail-pb0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752793Ab3DNSUW (ORCPT ); Sun, 14 Apr 2013 14:20:22 -0400 Received: by mail-pb0-f53.google.com with SMTP id un15so2132139pbc.40 for ; Sun, 14 Apr 2013 11:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=SmterVyONC/ecgUpKM0+2r65ibrLfjlTZtBBKPig2+M=; b=tn5CRNYMXQ4zipO2z/cbZ+rd2JERJeEnXuCtkXNy6l1aPudfaSPWTPhOmz0oneIXRb rhAzFw0WgQsJr/gwmDOCJoLQ9MeWv1tVwqYmKtC0/2wOrbffREsWOL9CTG3/TR3RAj/3 Jq4Ua2Ko0n/NLN/gz3HIBFxSAxOTpTj7NgDoVYLxDYb2Chl6VZXu2LN6yzZIkTCxNBWD GCNIp7Ks4AgqQl4CapDjYA9F6jTMyOafYSVkfOAsh6GtCkGIResWP8cEQKWEniBdkaIF V1EQ8DeA5mpJ3xVyDLKlr64YZdpcv1bb87aLZAIPTDnp5fLPYYmoCX2tipqLls4NXJ+X RtqQ== X-Received: by 10.67.1.39 with SMTP id bd7mr25071182pad.194.1365963621608; Sun, 14 Apr 2013 11:20:21 -0700 (PDT) Received: from testBox.local ([64.9.42.174]) by mx.google.com with ESMTPS id jw10sm17150748pbb.3.2013.04.14.11.20.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 14 Apr 2013 11:20:20 -0700 (PDT) From: scott.lovenberg@gmail.com To: jlayton@samba.org, smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Scott Lovenberg Subject: [PATCH] mount.cifs: Add support for parsing IPv6 addresses enclosed in brackets. Date: Sun, 14 Apr 2013 14:19:18 -0400 Message-Id: <1365963558-20082-1-git-send-email-scott.lovenberg@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Scott Lovenberg The standard for formatting IPv6 addresses is to enclose them in brackets. This patch allows the mount helper to parse IPv6 addresses that are enclosed in brackets. There is a slight change of behavior in this patch; specifying the --ip option without supplying an address now exits the mount helper rather than just ignoring and continuing. Signed-off-by: Scott Lovenberg --- AUTHORS | 1 + mount.cifs.c | 63 ++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2807079..081c2fe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,5 +5,6 @@ Shirish Pargaonkar Suresh Jayaraman Pavel Shilovsky Igor Druzhinin +Scott Lovenberg ...and others. diff --git a/mount.cifs.c b/mount.cifs.c index 3b2b89e..276f50d 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -751,6 +751,48 @@ static int parse_opt_token(const char *token) return OPT_ERROR; } +/* + Extract an ipv4 or ipv6 address and put it into parsed_info. + Returns 0 on success. +*/ +static int parse_ip(char *value, struct parsed_mount_info *parsed_info) +{ + char *closingBracket = NULL; + + if (!value || !*value) { + fprintf(stderr, "target ip address argument missing\n"); + return OPT_ERROR; + } + + /* check for ipv6 in brackets */ + if (value[0] == '[') { + value++; + /* temporarily null the closing bracket */ + closingBracket = strchr(value, ']'); + if (closingBracket) + *closingBracket = '\0'; + } + + /* check length of address*/ + if (strnlen(value, MAX_ADDRESS_LEN + 1) > MAX_ADDRESS_LEN) { + fprintf(stderr, "ip address too long\n"); + if (closingBracket) + *closingBracket = ']'; + return EX_USAGE; + } + + /* all test pass, copy it */ + strcpy(parsed_info->addrlist, value); + if (parsed_info->verboseflag) + fprintf(stderr, "ip address %s override specified\n", value); + + /* put back closing bracket */ + if (closingBracket) + *closingBracket = ']'; + + return 0; +} + static int parse_options(const char *data, struct parsed_mount_info *parsed_info) { @@ -861,23 +903,10 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) break; case OPT_IP: - if (!value || !*value) { - fprintf(stderr, - "target ip address argument missing\n"); - } else if (strnlen(value, MAX_ADDRESS_LEN) <= - MAX_ADDRESS_LEN) { - strcpy(parsed_info->addrlist, value); - if (parsed_info->verboseflag) - fprintf(stderr, - "ip address %s override specified\n", - value); - goto nocopy; - } else { - fprintf(stderr, "ip address too long\n"); - return EX_USAGE; - - } - break; + rc = parse_ip(value, parsed_info); + if (rc) + return rc; + goto nocopy; /* unc || target || path */ case OPT_UNC: