From patchwork Mon Oct 17 17:32:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9380065 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 56C98600CA for ; Mon, 17 Oct 2016 17:36:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E50828D68 for ; Mon, 17 Oct 2016 17:36:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42A6728ECB; Mon, 17 Oct 2016 17:36: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.3 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 EAEB528D68 for ; Mon, 17 Oct 2016 17:36:04 +0000 (UTC) Received: from localhost ([::1]:34675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwBpT-0005no-OY for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 13:36:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwBou-0005mo-2S for qemu-devel@nongnu.org; Mon, 17 Oct 2016 13:35:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwBop-0006cO-9l for qemu-devel@nongnu.org; Mon, 17 Oct 2016 13:35:28 -0400 Received: from mail-pa0-x243.google.com ([2607:f8b0:400e:c03::243]:36153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bwBop-0006cC-4n; Mon, 17 Oct 2016 13:35:23 -0400 Received: by mail-pa0-x243.google.com with SMTP id os4so5370843pac.3; Mon, 17 Oct 2016 10:35:23 -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=mwdm6o0Py2P28hNCvVB1ewbtvS5boOjchlZZzf5S70w=; b=0Jcc1qeKcuiJ47SJ/ny1IQqD+YgbhUixOBonw7/b0L/rez6LleHy34+a14mAmYVWgP YZRtprb73QpZ6GF75zYrAaJeLD+3asbN1SrYiw03DcSEgIOqHS6dkaQTTwEsdAnWu6jk zL4BHjKp0aLAuSPd2oNck9QlNFfl7XYI4ekp2NOhU1mcDqw+d7f1+IMbu7LjIzN3GLWL KpXLeXeHvBOq43nI05NURBGX1FjO4mCP0qx1Ajza3qesNauEYD5A1BMA9bW4R9EpycGR lW0yVtxDSLRBgMzgbAacEq8Lf0RMC52l70gusMSsXTh+LQFSoNf8Oc5BUkZL+ETwlGbM npEQ== 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=mwdm6o0Py2P28hNCvVB1ewbtvS5boOjchlZZzf5S70w=; b=D5N9eiCzDlJ9td+1POrhzsqhCrksu6VNX8+U+pnpnR8ddtqxSgHup7aCKCFNX9+l0M LDPF7Wrbpw39pjWcwEWgidnp20BR/NFXBte6U5MYprjyO6dSNNoLBgpylA8ws24aGazI foc43ylow6qjHHqCrEjr4SL7IYdbb9KiL8rC0l+nUGmsHyhWKulFwADntWfN/LxVbKRl xibg/Gzv+Q8Tf9LLXNw2E/RmPaw9y+0hsu2a4JB0Rpe6KtIZxB+5hCs1QEO39n+o0piF gvZqLVILQoZATWYHMf8CxY4avTE/ix3XbyUWT0crGfXjoW3iCeouHi8DoubKEFn1+0yk 0IkQ== X-Gm-Message-State: AA6/9RmHSgrNhmsQNgec/pdA5tC5d5Rkr+Vjn4FMaM3JI2nMITS9gGISL8M6Pc3RPBa96Q== X-Received: by 10.66.87.162 with SMTP id az2mr32503964pab.158.1476725722151; Mon, 17 Oct 2016 10:35:22 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id 188sm49641264pfz.2.2016.10.17.10.35.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 10:35:21 -0700 (PDT) From: Ashijeet Acharya To: kwolf@redhat.com Date: Mon, 17 Oct 2016 23:02:11 +0530 Message-Id: <1476725535-3350-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1476725535-3350-1-git-send-email-ashijeetacharya@gmail.com> References: <1476725535-3350-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:c03::243 Subject: [Qemu-devel] [PATCH v3 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, rjones@redhat.com, mreitz@redhat.com, Ashijeet Acharya , pbonzini@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 Reviewed-by: Kevin Wolf --- 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; }