From patchwork Tue Oct 25 13:03:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9394501 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 6A5C060762 for ; Tue, 25 Oct 2016 13:07:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C75F2955C for ; Tue, 25 Oct 2016 13:07:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 510BA2959D; Tue, 25 Oct 2016 13:07:23 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 DEBF42955C for ; Tue, 25 Oct 2016 13:07:22 +0000 (UTC) Received: from localhost ([::1]:54353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz1Rp-0007xO-MV for patchwork-qemu-devel@patchwork.kernel.org; Tue, 25 Oct 2016 09:07:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bz1RM-0007tt-DE for qemu-devel@nongnu.org; Tue, 25 Oct 2016 09:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bz1RL-0001jo-Fd for qemu-devel@nongnu.org; Tue, 25 Oct 2016 09:06:52 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34658) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bz1RL-0001je-9w; Tue, 25 Oct 2016 09:06:51 -0400 Received: by mail-pf0-x241.google.com with SMTP id 128so19612466pfz.1; Tue, 25 Oct 2016 06:06:51 -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=sDiYrcOpbBtBU+wYGAqnj7/yjDFcq/Lt7ZvJegp2oRk=; b=jNAa+/LHh5UJRbGHHa7e6arHrW35OWue1MhurVL/l5QDgv4mQOzgsDu3RPSb+pAUmP Fv+Z05xhFmN/J3LFhYN8npbub2+Hlm/gBeI2t3+doJENcIp5nkosu9POr47KAdlPlr/p GKg9aE2vUeuar4xKsp2Nrw9Etm/wNChRNjH0pt/rkSbXAREs71/QcjkUmsNI8rcwd2h6 DuZygO/cuaCyExFA8IOlcfLVZ+EECpISEGll3PafzjqmDvNSyG6UVxor0tfkjv+y8wPO pRbH93EeDC78HnASC10T+BZuFsPbKUbHzd3fTdBe8hO15q3vnRYWwOnIfWjYrNVCb94y nq9A== 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=sDiYrcOpbBtBU+wYGAqnj7/yjDFcq/Lt7ZvJegp2oRk=; b=hhq6kKOA0IAImiM1AskWz870NnQKQvkH8XgEFiwLcAIu8uZ4CdTDdVuNR/iygwxbCD w2Sq1akD22hVXS+OHKSJcMbaiBlTLjt3vZkJ91sWUYGj2hA0xWuIsKRVP7dufQ6BtXx9 ItjCHv6K08nKjx70AZvTbM3WEE11XmQfSM+SVkinbpZBHpoS+rxQkJKKjZHBC/Qcl3KR aNJHRD/evSQq23lWSHXM5t9zU8fBSgsf3Iesx02VoQbuOLwpKGEeWmKhejJX5VlSenCz Z4GrPDLR+hJIaCBK1BXKJlspxW3MenN3SqhtTyzIvRtqVtWj1ICyi7V3JpNZhhJbmDo4 QFuw== X-Gm-Message-State: ABUngvcM5PQmd//84PvIUaCWzuGj1jGuLYXEbzV5+5CWtS7Lc2nO2y+ZJFM5CjBQ9IgJHg== X-Received: by 10.98.66.149 with SMTP id h21mr39074137pfd.32.1477400810335; Tue, 25 Oct 2016 06:06:50 -0700 (PDT) Received: from linux.local ([106.208.9.126]) by smtp.gmail.com with ESMTPSA id u17sm33461160pfi.1.2016.10.25.06.06.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Oct 2016 06:06:49 -0700 (PDT) From: Ashijeet Acharya To: kwolf@redhat.com Date: Tue, 25 Oct 2016 18:33:57 +0530 Message-Id: <1477400641-7750-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1477400641-7750-1-git-send-email-ashijeetacharya@gmail.com> References: <1477400641-7750-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::241 Subject: [Qemu-devel] [PATCH v4 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; }