From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrg3-0004Lf-PE for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:40:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btrfy-0006cA-K9 for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:40:42 -0400 From: Ashijeet Acharya Date: Tue, 11 Oct 2016 13:07:14 +0530 Message-Id: <1476171437-11830-2-git-send-email-ashijeetacharya@gmail.com> In-Reply-To: <1476171437-11830-1-git-send-email-ashijeetacharya@gmail.com> References: <1476171437-11830-1-git-send-email-ashijeetacharya@gmail.com> Subject: [Qemu-devel] [PATCH 1/4] block/ssh: Add ssh_has_filename_options_conflict() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com Cc: rjones@redhat.com, jcody@redhat.com, eblake@redhat.com, mreitz@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, Ashijeet Acharya 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 --- 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; } -- 2.6.2