yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-curl-Allow-a-cookie-or-cookies-to-be-sent-with-http-.patch

05bba0
From 1eeb050a2cc6c582c390614080fbeaea019b2dac Mon Sep 17 00:00:00 2001
05bba0
From: Richard Jones <rjones@redhat.com>
05bba0
Date: Thu, 11 Jun 2015 11:40:26 +0200
05bba0
Subject: [PATCH 26/30] curl: Allow a cookie or cookies to be sent with
05bba0
 http/https requests.
05bba0
05bba0
Message-id: <1434022828-13037-20-git-send-email-rjones@redhat.com>
05bba0
Patchwork-id: 65854
05bba0
O-Subject: [RHEL-7.2 qemu-kvm v3 PATCH 19/21] curl: Allow a cookie or cookies to be sent with http/https requests.
05bba0
Bugzilla: 1226684
05bba0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
05bba0
05bba0
From: "Richard W.M. Jones" <rjones@redhat.com>
05bba0
05bba0
In order to access VMware ESX efficiently, we need to send a session
05bba0
cookie.  This patch is very simple and just allows you to send that
05bba0
session cookie.  It punts on the question of how you get the session
05bba0
cookie in the first place, but in practice you can just run a `curl'
05bba0
command against the server and extract the cookie that way.
05bba0
05bba0
To use it, add file.cookie to the curl URL.  For example:
05bba0
05bba0
$ qemu-img info 'json: {
05bba0
    "file.driver":"https",
05bba0
    "file.url":"https://vcenter/folder/Windows%202003/Windows%202003-flat.vmdk?dcPath=Datacenter&dsName=datastore1",
05bba0
    "file.sslverify":"off",
05bba0
    "file.cookie":"vmware_soap_session=\"52a01262-bf93-ccce-d379-8dabb3e55560\""}'
05bba0
image: [...]
05bba0
file format: raw
05bba0
virtual size: 8.0G (8589934592 bytes)
05bba0
disk size: unavailable
05bba0
05bba0
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
05bba0
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
Upstream-status: a94f83d94fdf907680f068f1be7ad13d1f697067
05bba0
05bba0
Note this intentionally omits the documentation changes in
05bba0
'qemu-options.hx' from the upstream patch.
05bba0
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/curl.c | 16 ++++++++++++++++
05bba0
 1 file changed, 16 insertions(+)
05bba0
05bba0
diff --git a/block/curl.c b/block/curl.c
05bba0
index 1f1df4f..ca881ee 100644
05bba0
--- a/block/curl.c
05bba0
+++ b/block/curl.c
05bba0
@@ -73,6 +73,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
05bba0
 #define CURL_BLOCK_OPT_READAHEAD "readahead"
05bba0
 #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
05bba0
 #define CURL_BLOCK_OPT_TIMEOUT "timeout"
05bba0
+#define CURL_BLOCK_OPT_COOKIE    "cookie"
05bba0
 
05bba0
 struct BDRVCURLState;
05bba0
 
05bba0
@@ -112,6 +113,7 @@ typedef struct BDRVCURLState {
05bba0
     size_t readahead_size;
05bba0
     bool sslverify;
05bba0
     int timeout;
05bba0
+    char *cookie;
05bba0
     bool accept_range;
05bba0
 } BDRVCURLState;
05bba0
 
05bba0
@@ -382,6 +384,9 @@ static CURLState *curl_init_state(BDRVCURLState *s)
05bba0
         curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
05bba0
         curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,
05bba0
                          (long) s->sslverify);
05bba0
+        if (s->cookie) {
05bba0
+            curl_easy_setopt(state->curl, CURLOPT_COOKIE, s->cookie);
05bba0
+        }
05bba0
         curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, s->timeout);
05bba0
         curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
05bba0
                          (void *)curl_read_cb);
05bba0
@@ -451,6 +456,11 @@ static QemuOptsList runtime_opts = {
05bba0
             .type = QEMU_OPT_NUMBER,
05bba0
             .help = "Curl timeout"
05bba0
         },
05bba0
+        {
05bba0
+            .name = CURL_BLOCK_OPT_COOKIE,
05bba0
+            .type = QEMU_OPT_STRING,
05bba0
+            .help = "Pass the cookie or list of cookies with each request"
05bba0
+        },
05bba0
         { /* end of list */ }
05bba0
     },
05bba0
 };
05bba0
@@ -463,6 +473,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
05bba0
     QemuOpts *opts;
05bba0
     Error *local_err = NULL;
05bba0
     const char *file;
05bba0
+    const char *cookie;
05bba0
     double d;
05bba0
 
05bba0
     static int inited = 0;
05bba0
@@ -488,6 +499,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
05bba0
 
05bba0
     s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
05bba0
 
05bba0
+    cookie = qemu_opt_get(opts, CURL_BLOCK_OPT_COOKIE);
05bba0
+    s->cookie = g_strdup(cookie);
05bba0
+
05bba0
     file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
05bba0
     if (file == NULL) {
05bba0
         qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
05bba0
@@ -556,6 +570,7 @@ out:
05bba0
     curl_easy_cleanup(state->curl);
05bba0
     state->curl = NULL;
05bba0
 out_noclean:
05bba0
+    g_free(s->cookie);
05bba0
     g_free(s->url);
05bba0
     qemu_opts_del(opts);
05bba0
     return -EINVAL;
05bba0
@@ -696,6 +711,7 @@ static void curl_close(BlockDriverState *bs)
05bba0
     qemu_del_timer(s->timer);
05bba0
     qemu_free_timer(s->timer);
05bba0
 
05bba0
+    g_free(s->cookie);
05bba0
     g_free(s->url);
05bba0
 }
05bba0
 
05bba0
-- 
05bba0
1.8.3.1
05bba0