From patchwork Tue Apr 16 01:29:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Lovenberg X-Patchwork-Id: 2447281 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 56714DF2E5 for ; Tue, 16 Apr 2013 01:30:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934897Ab3DPBai (ORCPT ); Mon, 15 Apr 2013 21:30:38 -0400 Received: from mail-vc0-f170.google.com ([209.85.220.170]:53791 "EHLO mail-vc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934873Ab3DPBai (ORCPT ); Mon, 15 Apr 2013 21:30:38 -0400 Received: by mail-vc0-f170.google.com with SMTP id lf10so4485106vcb.1 for ; Mon, 15 Apr 2013 18:30:36 -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:in-reply-to :references; bh=zH4NTzi/cFwxAkginduqsNXHdafPdTC27WeUu8goXok=; b=IYZFLXg3B/PiSKNvwSNM6q0gqWsslgxbrrbQLWnZxkMu6OkWXVJkaKEf2K3+o7LwxE dfk3A0BGWS5A2uTI8GR8sA5kxB2eJl5UkrzaTIS388/fydd4P4woxstfuJfVgeKnQd4F MwP3J+0lmV8SFb5Rm3MDEcZKqNMuLI45IImM0BsuWO1HYUAtA0gpOwUz8sUL9cmCg69r N/+D643cQXCu5XDLPxRZTYQEcUwA5Mi3b5+zgOgJtLmWEAXO4IWbFF66BguiovVmNbsq d7vRRU/jVuSdMt4dOC95SZp6jWEhUc5vmvP2Y8fkeFQwZa+jcxOKIJz/tm3RvRGR6hHG Y0fg== X-Received: by 10.52.243.196 with SMTP id xa4mr139017vdc.22.1366075836402; Mon, 15 Apr 2013 18:30:36 -0700 (PDT) Received: from testBox.local ([64.9.42.174]) by mx.google.com with ESMTPS id b7sm21780593veq.7.2013.04.15.18.30.34 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Apr 2013 18:30:35 -0700 (PDT) From: scott.lovenberg@gmail.com To: jlayton@samba.org Cc: smfrench@gmail.com, linux-cifs@vger.kernel.org, Scott Lovenberg Subject: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2 Date: Mon, 15 Apr 2013 21:29:49 -0400 Message-Id: <1366075789-23137-1-git-send-email-scott.lovenberg@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365963558-20082-1-git-send-email-scott.lovenberg@gmail.com> References: <1365963558-20082-1-git-send-email-scott.lovenberg@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Scott Lovenberg This is a respin of the last patch that returns EX_USAGE rather than OPT_ERROR as per Jeff's suggestion. Signed-off-by: Scott Lovenberg --- AUTHORS | 1 + mount.cifs.c | 62 ++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 46 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..561517b 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -751,6 +751,47 @@ 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 EX_USAGE; + } + + /* 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; + } + + 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 +902,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: