From patchwork Sat Oct 15 09:04:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9377743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF12860779 for ; Sat, 15 Oct 2016 09:11:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B7C728834 for ; Sat, 15 Oct 2016 09:11:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A2F1291A0; Sat, 15 Oct 2016 09:11:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 230CD28834 for ; Sat, 15 Oct 2016 09:11:05 +0000 (UTC) Received: from localhost ([::1]:51031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvKzf-0007hI-TX for patchwork-qemu-devel@patchwork.kernel.org; Sat, 15 Oct 2016 05:11:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvKvw-00051i-97 for qemu-devel@nongnu.org; Sat, 15 Oct 2016 05:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvKvu-0001lV-2h for qemu-devel@nongnu.org; Sat, 15 Oct 2016 05:07:11 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bvKvt-0001ks-Rp; Sat, 15 Oct 2016 05:07:10 -0400 Received: by mail-pf0-x242.google.com with SMTP id 128so8856436pfz.1; Sat, 15 Oct 2016 02:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9qIhR9pXYMpy6MLj6nyF//6RcNLSpBjKUL0jF7AXEtY=; b=NeB1MxhvulriW0Y0gWMC0nmB6ZVWgfBg2BxLbujRn+nmKG+aCO5VAOngfc8jqpkWTn TQVo94qWogZ+eroX3jZBgtRRUYr4b2ATtyR7eM+FtF/u0YEu6K5RDNfUziJwXdyy86hi Z3pVd2mVy6IxU/+k9xRSFC5wmDoQe4EzArvoVDEJO/03HSYC4I2oi3F/TJF0q6vhF+es 2gmqtMGgGrVFI4el2z/vpg7mcIpBZ32kEclaPi05O1vbUjKT6lszSX+4GaVdFZmhTLU0 OA1PkZKKjTvYo377FLEb9HOzy4slZaA3BOTi04hUYJhR5bCExO0M/go0HThBby1nojgF fxTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9qIhR9pXYMpy6MLj6nyF//6RcNLSpBjKUL0jF7AXEtY=; b=G0YcF1GPQDrOzcwXsw2YL/kZwalEBRcnalNf1Xpp5LCLCTaPFs8qnpE7ByLODW3BUU F+If/unTlLb0x64Q1wvEXrNVrHmsHPt665HN8xsfPh0+yqm11HFqTL43VXNVvHqPfZPR RBMYTENFVtqv5YOLtsTvO03VmnoBBNeFdb/RoFjzRtk/51lrXGC8kIzIOQn7o68RsjqE tX3I3tARxR2kshn9Zi2p05zZs+binnRnYBfH2BgnhZqZ2RyU4V1UYjUJjHeX2ytXcGHk q6SEUGfWS3Kw2LduSD/HQ5xOO2a8M4DdWXQ5W8GsTnRwkUuvFTy6MG1TH8be/0bCuaOn X2kg== X-Gm-Message-State: AA6/9Rnk8gPVSESFdJfregztOLqKiKquGF2mvKrZrN0VuAQNp3sXhiXmfUGeW/BCAK360Q== X-Received: by 10.99.157.135 with SMTP id i129mr20209237pgd.16.1476522428631; Sat, 15 Oct 2016 02:07:08 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id a7sm5295159pan.34.2016.10.15.02.07.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 15 Oct 2016 02:07:08 -0700 (PDT) From: Ashijeet Acharya To: kwolf@redhat.com Date: Sat, 15 Oct 2016 14:34:36 +0530 Message-Id: <1476522280-23211-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1476522280-23211-1-git-send-email-ashijeetacharya@gmail.com> References: <1476522280-23211-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [v2 1/5] block/ssh: Add ssh_has_filename_options_conflict() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, rjones@redhat.com, kraxel@redhat.com, Ashijeet Acharya , pbonzini@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We have 5 options plus ("server") option which is added in the next patch that conflict with specifying a SSH filename. We need to iterate over all the options to check whether its key has an "server." prefix. This iteration will help us adding the new option "server" easily. Signed-off-by: Ashijeet Acharya Reviewed-by: Max Reitz --- block/ssh.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 5ce12b6..75cb7bc 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -254,15 +254,30 @@ static int parse_uri(const char *filename, QDict *options, Error **errp) return -EINVAL; } +static bool ssh_has_filename_options_conflict(QDict *options, Error **errp) +{ + const QDictEntry *qe; + + for (qe = qdict_first(options); qe; qe = qdict_next(options, qe)) { + if (!strcmp(qe->key, "host") || + !strcmp(qe->key, "port") || + !strcmp(qe->key, "path") || + !strcmp(qe->key, "user") || + !strcmp(qe->key, "host_key_check")) + { + error_setg(errp, "Option '%s' cannot be used with a file name", + qe->key); + return true; + } + } + + return false; +} + static void ssh_parse_filename(const char *filename, QDict *options, Error **errp) { - if (qdict_haskey(options, "user") || - qdict_haskey(options, "host") || - qdict_haskey(options, "port") || - qdict_haskey(options, "path") || - qdict_haskey(options, "host_key_check")) { - error_setg(errp, "user, host, port, path, host_key_check cannot be used at the same time as a file option"); + if (ssh_has_filename_options_conflict(options, errp)) { return; }