[lxc-devel] [lxd/master] client: Fix crash when missing cookiejar
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Oct 18 21:55:57 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171018/24c74674/attachment.bin>
-------------- next part --------------
From 7e9d4966cbecdcc7fc9a5f7136f95f946c39b380 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 18 Oct 2017 17:51:28 -0400
Subject: [PATCH] client: Fix crash when missing cookiejar
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
client/connection.go | 2 ++
client/lxd.go | 1 +
lxc/config/config.go | 2 ++
lxc/config/remote.go | 5 ++++-
4 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/client/connection.go b/client/connection.go
index 825c8a415..0a606452d 100644
--- a/client/connection.go
+++ b/client/connection.go
@@ -173,9 +173,11 @@ func httpsLXD(url string, args *ConnectionArgs) (ContainerServer, error) {
if err != nil {
return nil, err
}
+
if args.CookieJar != nil {
httpClient.Jar = args.CookieJar
}
+
server.http = httpClient
if args.AuthType == "macaroons" {
server.setupBakeryClient()
diff --git a/client/lxd.go b/client/lxd.go
index d85c43e5f..6aef4cf17 100644
--- a/client/lxd.go
+++ b/client/lxd.go
@@ -76,6 +76,7 @@ func (r *ProtocolLXD) do(req *http.Request) (*http.Response, error) {
r.addMacaroonHeaders(req)
return r.bakeryClient.Do(req)
}
+
return r.http.Do(req)
}
diff --git a/lxc/config/config.go b/lxc/config/config.go
index 3a175f1eb..486b39afd 100644
--- a/lxc/config/config.go
+++ b/lxc/config/config.go
@@ -64,10 +64,12 @@ func NewConfig(configDir string, defaults bool) *Config {
config.Remotes = DefaultRemotes
config.DefaultRemote = "local"
}
+
if configDir != "" {
config.cookiejar, _ = cookiejar.New(
&cookiejar.Options{
Filename: filepath.Join(configDir, "cookies")})
}
+
return config
}
diff --git a/lxc/config/remote.go b/lxc/config/remote.go
index 1aa54ed82..bc1acf63e 100644
--- a/lxc/config/remote.go
+++ b/lxc/config/remote.go
@@ -137,11 +137,14 @@ func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {
remote, _ := c.Remotes[name]
args := lxd.ConnectionArgs{
UserAgent: c.UserAgent,
- CookieJar: c.cookiejar,
AuthType: remote.AuthType,
AuthInteractor: c.authInteractor,
}
+ if c.cookiejar != nil {
+ args.CookieJar = c.cookiejar
+ }
+
// Client certificate
if shared.PathExists(c.ConfigPath("client.crt")) {
content, err := ioutil.ReadFile(c.ConfigPath("client.crt"))
More information about the lxc-devel
mailing list