From: Matthew Booth <mbooth@redhat.com>
To: "Richard W.M. Jones" <rjones@redhat.com>, qemu-devel@nongnu.org
Cc: famz@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] curl: Allow a cookie or cookies to be sent with http/https requests.
Date: Fri, 29 Aug 2014 15:43:53 +0100 [thread overview]
Message-ID: <540091A9.3070008@redhat.com> (raw)
In-Reply-To: <1409234114-20021-1-git-send-email-rjones@redhat.com>
Looks good to me. 1 inline nit.
Matt
On 28/08/14 14:55, Richard W.M. Jones wrote:
> In order to access VMware ESX efficiently, we need to send a session
> cookie. This patch is very simple and just allows you to send that
> session cookie. It punts on the question of how you get the session
> cookie in the first place, but in practice you can just run a `curl'
> command against the server and extract the cookie that way.
>
> To use it, add file.cookie to the curl URL. For example:
>
> $ qemu-img info 'json: {
> "file.driver":"https",
> "file.url":"https://vcenter/folder/Windows%202003/Windows%202003-flat.vmdk?dcPath=Datacenter&dsName=datastore1",
> "file.sslverify":"off",
> "file.cookie":"vmware_soap_session=\"52a01262-bf93-ccce-d379-8dabb3e55560\""}'
> image: [...]
> file format: raw
> virtual size: 8.0G (8589934592 bytes)
> disk size: unavailable
>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
> block/curl.c | 20 ++++++++++++++++++++
> qemu-options.hx | 5 +++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/block/curl.c b/block/curl.c
> index f59615d..c1c2e35 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -71,6 +71,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
> #define CURL_BLOCK_OPT_URL "url"
> #define CURL_BLOCK_OPT_READAHEAD "readahead"
> #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
> +#define CURL_BLOCK_OPT_COOKIE "cookie"
>
> struct BDRVCURLState;
>
> @@ -109,6 +110,7 @@ typedef struct BDRVCURLState {
> char *url;
> size_t readahead_size;
> bool sslverify;
> + char *cookie;
> bool accept_range;
> AioContext *aio_context;
> } BDRVCURLState;
> @@ -382,6 +384,9 @@ static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
> curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
> curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,
> (long) s->sslverify);
> + if (s->cookie) {
> + curl_easy_setopt(state->curl, CURLOPT_COOKIE, s->cookie);
> + }
> curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
> curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
> (void *)curl_read_cb);
> @@ -489,6 +494,11 @@ static QemuOptsList runtime_opts = {
> .type = QEMU_OPT_BOOL,
> .help = "Verify SSL certificate"
> },
> + {
> + .name = CURL_BLOCK_OPT_COOKIE,
> + .type = QEMU_OPT_STRING,
> + .help = "Pass the cookie or list of cookies with each request"
> + },
> { /* end of list */ }
> },
> };
> @@ -501,6 +511,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
> QemuOpts *opts;
> Error *local_err = NULL;
> const char *file;
> + const char *cookie;
> double d;
>
> static int inited = 0;
> @@ -527,6 +538,13 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
>
> s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
>
> + cookie = qemu_opt_get(opts, CURL_BLOCK_OPT_COOKIE);
g_strdup() returns NULL when given NULL, so you can simplify below to:
s->cookie = g_strdup(cookie)
> + if (cookie) {
> + s->cookie = g_strdup(cookie);
> + } else {
> + s->cookie = NULL;
> + }
> +
> file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
> if (file == NULL) {
> error_setg(errp, "curl block driver requires an 'url' option");
> @@ -582,6 +600,7 @@ out:
> curl_easy_cleanup(state->curl);
> state->curl = NULL;
> out_noclean:
> + g_free(s->cookie);
> g_free(s->url);
> qemu_opts_del(opts);
> return -EINVAL;
> @@ -684,6 +703,7 @@ static void curl_close(BlockDriverState *bs)
> DPRINTF("CURL: Close\n");
> curl_detach_aio_context(bs);
>
> + g_free(s->cookie);
> g_free(s->url);
> }
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index c573dd8..7b4a58a 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2351,6 +2351,11 @@ multiple of 512 bytes. It defaults to 256k.
> @item sslverify
> Whether to verify the remote server's certificate when connecting over SSL. It
> can have the value 'on' or 'off'. It defaults to 'on'.
> +
> +@item cookie
> +Send this cookie (it can also be a list of cookies separated by ';') with
> +each outgoing request. Only supported when using protocols such as HTTP
> +which support cookies, otherwise ignored.
> @end table
>
> Note that when passing options to qemu explicitly, @option{driver} is the value
>
--
Matthew Booth
Red Hat Engineering, Virtualisation Team
Phone: +442070094448 (UK)
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
prev parent reply other threads:[~2014-08-29 14:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-28 13:55 [Qemu-devel] [PATCH] curl: Allow a cookie or cookies to be sent with http/https requests Richard W.M. Jones
2014-08-29 14:43 ` Matthew Booth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=540091A9.3070008@redhat.com \
--to=mbooth@redhat.com \
--cc=famz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.