Browse Source

Add infrastructure to handle HTTP-based shares.

Add an optional dependency to libcurl. Create a new scheme-libcurl
module to handle http{,s}:// share URIs.
master
Damien Goutte-Gattat 3 months ago
parent
commit
ac2cbe7bd8
  1. 8
      configure.ac
  2. 1
      src/Makefile.am
  3. 62
      src/scheme-libcurl.c
  4. 50
      src/scheme-libcurl.h
  5. 10
      src/scheme-module.c
  6. 4
      src/schemes.h
  7. 2
      src/secret.c
  8. 4
      src/secretcfg.c

8
configure.ac

@ -44,6 +44,13 @@ PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.22],
LIBS="$LIBS $GIO_LIBS"],
[have_gio=no])
dnl Check for LibCURL
LIBCURL_CHECK_CONFIG([yes], [],
[have_libcurl=yes
CFLAGS="$CFLAGS $LIBCURL_CPPFLAGS"
LIBS="$LIBS $LIBCURL"],
[have_libcurl=no])
dnl Set max size for secret
AC_ARG_ENABLE([max-size],
[AS_HELP_STRING([--enable-max-size],
@ -91,6 +98,7 @@ Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}'
MTP support: ${have_libmtp}
GIO support: ${have_gio}
HTTP support: ${have_libcurl}
Secret max size: ${max_secret_size_string}
"

1
src/Makefile.am

@ -6,6 +6,7 @@ common_sources = util.c util.h secret.c secret.h \
scheme-libmtp.c scheme-libmtp.h \
scheme-gio.c scheme-gio.h \
scheme-file.c scheme-file.h \
scheme-libcurl.c scheme-libcurl.h \
support.c support.h
gfsec_use_SOURCES = gfsec-use.c $(common_sources)

62
src/scheme-libcurl.c

@ -0,0 +1,62 @@
/*
* gfsecret - Secret sharing tools
* Copyright (C) 2021 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "scheme-libcurl.h"
#include "scheme-module.h"
int
gfsec_scheme_libcurl_get_file(gfsec_scheme_t scheme,
const char *authority,
const char *path,
unsigned char **buffer,
size_t *len)
{
if ( scheme != GFSEC_SCHEME_HTTP )
return GFSEC_SCHEME_STATUS_UNSUPPORTED_SCHEME;
return GFSEC_SCHEME_STATUS_UNSUPPORTED_SCHEME;
}
int
gfsec_scheme_libcurl_put_file(gfsec_scheme_t scheme,
const char *authority,
const char *path,
unsigned char *buffer,
size_t len)
{
(void) scheme;
(void) authority;
(void) path;
(void) buffer;
(void) len;
return GFSEC_SCHEME_STATUS_UNSUPPORTED_SCHEME;
}
int
gfsec_scheme_libcurl_get_supports(gfsec_supports_list_t *list)
{
(void) list;
return 0;
}

50
src/scheme-libcurl.h

@ -0,0 +1,50 @@
/*
* gfsecret - Secret sharing tools
* Copyright (C) 2021 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ICP20210704_SCHEME_LIBCURL_H
#define ICP20210704_SCHEME_LIBCURL_H
#include "schemes.h"
#include "support.h"
#ifdef __cplusplus
extern "C" {
#endif
int
gfsec_scheme_libcurl_get_file(gfsec_scheme_t,
const char *,
const char *,
unsigned char **,
size_t *);
int
gfsec_scheme_libcurl_put_file(gfsec_scheme_t,
const char *,
const char *,
unsigned char *,
size_t);
int
gfsec_scheme_libcurl_get_supports(gfsec_supports_list_t *);
#ifdef __cplusplus
}
#endif
#endif /* !ICP20210704_SCHEME_LIBCURL_H */

10
src/scheme-module.c

@ -24,6 +24,7 @@
#include "scheme-file.h"
#include "scheme-libmtp.h"
#include "scheme-gio.h"
#include "scheme-libcurl.h"
#ifdef HAVE_LIBMTP
#include <libmtp.h>
@ -60,7 +61,7 @@ static module_t *modules;
void
gfsec_scheme_module_init(void)
{
static module_t mods[4];
static module_t mods[5];
int n = 0;
mods[n].get_file = gfsec_scheme_file_get_file;
@ -83,6 +84,13 @@ gfsec_scheme_module_init(void)
mods[n++].present = 1;
#endif
#ifdef HAVE_LIBCURL
mods[n].get_file = gfsec_scheme_libcurl_get_file;
mods[n].put_file = gfsec_scheme_libcurl_put_file;
mods[n].get_supp = gfsec_scheme_libcurl_get_supports;
mods[n++].present = 1;
#endif
mods[n++].present = 0;
modules = mods;

4
src/schemes.h

@ -23,7 +23,9 @@ typedef enum gfsec_scheme {
GFSEC_SCHEME_FILE = 0,
GFSEC_SCHEME_UUID,
GFSEC_SCHEME_LABEL,
GFSEC_SCHEME_MTP
GFSEC_SCHEME_MTP,
GFSEC_SCHEME_HTTP,
GFSEC_SCHEME_HTTPS
} gfsec_scheme_t;
#define GFSEC_SCHEME_MAX 4

2
src/secret.c

@ -235,7 +235,7 @@ gfsec_share_get_uri(gfsec_share_t *share,
char *buffer,
size_t len)
{
static char *schemes[] = { "file://", "uuid://", "label://", "mtp://" };
static char *schemes[] = { "file://", "uuid://", "label://", "mtp://", "http://", "https://" };
int ret;
assert(share != NULL);

4
src/secretcfg.c

@ -272,6 +272,10 @@ gfsec_parse_uri(const char *uri, gfsec_secret_t *secret, int assign)
share->scheme = GFSEC_SCHEME_LABEL;
else if ( strncmp(p, "mtp://", 6) == 0 && (p += 6) )
share->scheme = GFSEC_SCHEME_MTP;
else if ( strncmp(p, "http://", 7) == 0 && (p += 7) )
share->scheme = GFSEC_SCHEME_HTTP;
else if ( strncmp(p, "https://", 8) == 0 && (p += 8) )
share->scheme = GFSEC_SCHEME_HTTPS;
else
rc = GFSEC_ERR_CONFIG_UNKNOWN_SCHEME;

Loading…
Cancel
Save