Browse Source

Add basic http(s) upload support.

Add partial support for http(s) share URIs in gfsec-split. A created
shared can now be immediately sent to a web server that accepts PUT
requests. Credentials are to be provided in a .netrc file.
master
Damien Goutte-Gattat 2 months ago
parent
commit
1eb9fed5c9
  1. 69
      src/scheme-libcurl.c
  2. 3
      src/secretcfg.c

69
src/scheme-libcurl.c

@ -97,6 +97,35 @@ gfsec_scheme_libcurl_get_file(gfsec_scheme_t scheme,
return ret;
}
struct putfile_cb_data {
unsigned char *buffer;
size_t len;
size_t read;
};
static size_t
read_cb(char *buffer, size_t size, size_t nmemb, void *userp)
{
struct putfile_cb_data *data = (struct putfile_cb_data *)userp;
size_t len = size * nmemb;
if ( len > (data->len - data->read) )
len = data->len - data->read;
memcpy(buffer, data->buffer + data->read, len);
return len;
}
static size_t
dummy_write_cb(char *buffer, size_t size, size_t nmemb, void *userp)
{
(void) buffer;
(void) userp;
return size * nmemb;
}
int
gfsec_scheme_libcurl_put_file(gfsec_scheme_t scheme,
const char *authority,
@ -104,13 +133,41 @@ gfsec_scheme_libcurl_put_file(gfsec_scheme_t scheme,
unsigned char *buffer,
size_t len)
{
(void) scheme;
(void) authority;
(void) path;
(void) buffer;
(void) len;
int ret = GFSEC_SCHEME_STATUS_SUCCESS;
char *url = NULL;
CURL *curl;
struct putfile_cb_data data = { 0 };
return GFSEC_SCHEME_STATUS_UNSUPPORTED_SCHEME;
if ( scheme != GFSEC_SCHEME_HTTP && scheme != GFSEC_SCHEME_HTTPS )
return GFSEC_SCHEME_STATUS_UNSUPPORTED_SCHEME;
if ( ! (curl = curl_easy_init()) )
return GFSEC_SCHEME_STATUS_ERROR;
xasprintf(&url, "http%s://%s%s",
scheme == GFSEC_SCHEME_HTTP ? "" : "s",
authority, path);
data.buffer = buffer;
data.len = len;
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
curl_easy_setopt(curl, CURLOPT_READDATA, (void *)&data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dummy_write_cb);
if ( curl_easy_setopt(curl, CURLOPT_URL, url) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, len) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && curl_easy_perform(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
curl_easy_cleanup(curl);
free(url);
return ret;
}
int

3
src/secretcfg.c

@ -442,7 +442,8 @@ gfsec_write_config(gfsec_secret_t *cfg, const char *filename)
char buffer[65];
unsigned n, m;
static char *schemes[] = { "file://", "uuid://", "label://", "mtp://" };
static char *schemes[] = { "file://", "uuid://", "label://", "mtp://",
"http://", "https://" };
assert(cfg != NULL);
assert(filename != NULL);

Loading…
Cancel
Save