summaryrefslogtreecommitdiff
path: root/src/lib/internet.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-01-02 15:07:29 +0000
committerCarl Hetherington <cth@carlh.net>2018-01-02 17:37:36 +0000
commitc9548bb8272ffe5804085f0a7a9f19305f0d513b (patch)
treeeb5ef3e103de07c357539d4aa2ee31c9700f21c4 /src/lib/internet.cc
parent356e2d767c4a3dc65869dc1d75476a94e2e2ba07 (diff)
Fix opening of ZIP files of certificates on Windows (#1124).
Diffstat (limited to 'src/lib/internet.cc')
-rw-r--r--src/lib/internet.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/lib/internet.cc b/src/lib/internet.cc
index aafdf3a83..1e8c5d8e9 100644
--- a/src/lib/internet.cc
+++ b/src/lib/internet.cc
@@ -21,6 +21,7 @@
#include "scoped_temporary.h"
#include "compose.hpp"
#include "exceptions.h"
+#include "cross.h"
#include <curl/curl.h>
#include <zip.h>
#include <boost/function.hpp>
@@ -78,13 +79,23 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
/* Open the ZIP file and read `file' out of it */
- struct zip* zip = zip_open (temp_zip.c_str(), 0, 0);
+ FILE* zip_file = fopen_boost (temp_zip.file (), "rb");
+ if (!zip_file) {
+ return optional<string> (_("Could not open downloaded ZIP file"));
+ }
+
+ zip_source_t* zip_source = zip_source_filep_create (zip_file, 0, -1, 0);
+ if (!zip_source) {
+ return optional<string> (_("Could not open downloaded ZIP file"));
+ }
+
+ zip_t* zip = zip_open_from_source (zip_source, 0, 0);
if (!zip) {
return optional<string> (_("Could not open downloaded ZIP file"));
}
- struct zip_file* zip_file = zip_fopen (zip, file.c_str(), 0);
- if (!zip_file) {
+ struct zip_file* file_in_zip = zip_fopen (zip, file.c_str(), 0);
+ if (!file_in_zip) {
return optional<string> (_("Unexpected ZIP file contents"));
}
@@ -92,12 +103,14 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
f = temp_cert.open ("wb");
char buffer[4096];
while (true) {
- int const N = zip_fread (zip_file, buffer, sizeof (buffer));
+ int const N = zip_fread (file_in_zip, buffer, sizeof (buffer));
fwrite (buffer, 1, N, f);
if (N < int (sizeof (buffer))) {
break;
}
}
+ zip_fclose (file_in_zip);
+ zip_close (zip);
temp_cert.close ();
load (temp_cert.file ());