Browse Source

Add the -l, --list-supports option to gfsec-split

Add a new -l, --list-supports option to the gfsec-split program,
to print a list of all currently connected and available supports.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
0e2a23f4a2
  1. 33
      src/gfsec-split.c
  2. 6
      src/scheme-file.c
  3. 4
      src/scheme-file.h
  4. 34
      src/scheme-gio.c
  5. 4
      src/scheme-gio.h
  6. 25
      src/scheme-libmtp.c
  7. 4
      src/scheme-libmtp.h
  8. 22
      src/scheme-module.c
  9. 4
      src/scheme-module.h

33
src/gfsec-split.c

@ -61,6 +61,9 @@ Split the specified file for later use with gfsec-use.\n");
puts("\
-k, --keep Do not delete the original file.\n");
puts("\
-l, --list-supports List available supports and exit.\n");
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit(status);
@ -97,24 +100,25 @@ get_uinteger_or_die(const char *arg)
int
main(int argc, char **argv)
{
int c;
int c, list_mode;
unsigned threshold, keep_original;
char *output_base, *config_path;
gfsec_secret_t *cfg;
struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "treshold", 1, NULL, 'n' },
{ "share", 1, NULL, 's' },
{ "config", 1, NULL, 'c' },
{ "keep", 0, NULL, 'k' },
{ NULL, 0, NULL, 0 }
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "treshold", 1, NULL, 'n' },
{ "share", 1, NULL, 's' },
{ "config", 1, NULL, 'c' },
{ "keep", 0, NULL, 'k' },
{ "list-supports", 0, NULL, 'l' },
{ NULL, 0, NULL, 0 }
};
setprogname(argv[0]);
threshold = 2;
keep_original = 0;
keep_original = list_mode = 0;
output_base = config_path = NULL;
srandom(time(NULL));
@ -122,7 +126,7 @@ main(int argc, char **argv)
if ( ! (cfg = gfsec_secret_new()) )
err(EXIT_FAILURE, "Cannot create secret");
while ( (c = getopt_long(argc, argv, "hvn:s:c:k",
while ( (c = getopt_long(argc, argv, "hvn:s:c:kl",
options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
@ -153,11 +157,20 @@ main(int argc, char **argv)
case 'k':
keep_original = 1;
break;
case 'l':
list_mode = 1;
break;
}
}
gfsec_scheme_module_init();
if ( list_mode ) {
gfsec_scheme_module_list_authorities(stdout);
exit(EXIT_SUCCESS);
}
if ( ! gcry_check_version(GCRYPT_VERSION) )
errx(EXIT_FAILURE, "libgcrypt version mismatch");

6
src/scheme-file.c

@ -60,3 +60,9 @@ gfsec_scheme_file_put_file(gfsec_scheme_t scheme,
else
return GFSEC_SCHEME_STATUS_ERROR;
}
void
gfsec_scheme_file_lst_auth(FILE *f)
{
fprintf(f, "file:// Local filesystem\n");
}

4
src/scheme-file.h

@ -19,6 +19,7 @@
#ifndef ICP20160821_SCHEME_FILE_H
#define ICP20160821_SCHEME_FILE_H
#include <stdio.h>
#include "schemes.h"
#ifdef __cpluscplus
@ -39,6 +40,9 @@ gfsec_scheme_file_put_file(gfsec_scheme_t,
unsigned char *,
size_t);
void
gfsec_scheme_file_lst_auth(FILE *);
#ifdef __cplusplus
}
#endif

34
src/scheme-gio.c

@ -292,4 +292,38 @@ gfsec_scheme_gio_put_file(gfsec_scheme_t scheme,
return rc;
}
void
gfsec_scheme_gio_lst_auth(FILE *f)
{
GVolumeMonitor *volmon;
GList *volumes, *l;
volmon = g_volume_monitor_get();
volumes = g_volume_monitor_get_volumes(volmon);
for ( l = volumes; l != NULL; l = l->next ) {
char *label, *uuid;
GVolume *volume;
volume = G_VOLUME(l->data);
label = g_volume_get_name(volume);
uuid = g_volume_get_uuid(volume);
if ( label ) {
fprintf(f, "label://%s GIO volume\n", label);
free(label);
}
if ( uuid ) {
fprintf(f, "uuid://%S GIO volume\n", uuid);
free(uuid);
}
g_object_unref(l->data);
}
g_list_free(volumes);
g_object_unref(volmon);
}
#endif /* HAVE_GIO */

4
src/scheme-gio.h

@ -19,6 +19,7 @@
#ifndef ICP20160207_SCHEME_GIO_H
#define ICP20160207_SCHEME_GIO_H
#include <stdio.h>
#include "schemes.h"
#ifdef __cpluscplus
@ -39,6 +40,9 @@ gfsec_scheme_gio_put_file(gfsec_scheme_t,
unsigned char *,
size_t);
void
gfsec_scheme_gio_lst_auth(FILE *);
#ifdef __cplusplus
}
#endif

25
src/scheme-libmtp.c

@ -392,4 +392,29 @@ gfsec_scheme_libmtp_put_file(gfsec_scheme_t scheme,
return rc;
}
void
gfsec_scheme_libmtp_lst_auth(FILE *f)
{
LIBMTP_raw_device_t *raw_devices;
LIBMTP_mtpdevice_t *device;
int i, n;
if ( LIBMTP_Detect_Raw_Devices(&raw_devices, &n) != 0 )
return;
for ( i = 0, device = NULL; i < n && device == NULL; i++ ) {
char *serial, *name;
device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]));
serial = LIBMTP_Get_Serialnumber(device);
name = LIBMTP_Get_Friendlyname(device);
fprintf(f, "mtp://%s %s\n", serial, name);
free(serial);
free(name);
LIBMTP_Release_Device(device);
}
}
#endif /* HAVE_LIBMTP */

4
src/scheme-libmtp.h

@ -19,6 +19,7 @@
#ifndef ICP20160207_SCHEME_LIBMTP_H
#define ICP20160207_SCHEME_LIBMTP_H
#include <stdio.h>
#include "schemes.h"
#ifdef __cpluscplus
@ -39,6 +40,9 @@ gfsec_scheme_libmtp_put_file(gfsec_scheme_t,
unsigned char *,
size_t);
void
gfsec_scheme_libmtp_lst_auth(FILE *);
#ifdef __cplusplus
}
#endif

22
src/scheme-module.c

@ -41,10 +41,13 @@ typedef int (*fn_put_file)(gfsec_scheme_t,
unsigned char *,
size_t);
typedef void (*fn_lst_auth)(FILE *);
typedef struct module {
int present;
fn_get_file get_file;
fn_put_file put_file;
fn_lst_auth lst_auth;
} module_t;
static module_t *modules;
@ -62,18 +65,21 @@ gfsec_scheme_module_init(void)
mods[n].get_file = gfsec_scheme_file_get_file;
mods[n].put_file = gfsec_scheme_file_put_file;
mods[n].lst_auth = gfsec_scheme_file_lst_auth;
mods[n++].present = 1;
#ifdef HAVE_LIBMTP
LIBMTP_Init();
mods[n].get_file = gfsec_scheme_libmtp_get_file;
mods[n].put_file = gfsec_scheme_libmtp_put_file;
mods[n].lst_auth = gfsec_scheme_libmtp_lst_auth;
mods[n++].present = 1;
#endif
#ifdef HAVE_GIO
mods[n].get_file = gfsec_scheme_gio_get_file;
mods[n].put_file = gfsec_scheme_gio_put_file;
mods[n].lst_auth = gfsec_scheme_gio_lst_auth;
mods[n++].present = 1;
#endif
@ -159,3 +165,19 @@ gfsec_scheme_module_put_file(gfsec_scheme_t scheme,
return rc;
}
/**
* List currently available authorities reported by all modules.
*
* @param f The stream to write into.
*/
void
gfsec_scheme_module_list_authorities(FILE *f)
{
module_t *mod;
for ( mod = modules; mod->present; mod++ ) {
if ( mod->lst_auth )
mod->lst_auth(f);
}
}

4
src/scheme-module.h

@ -20,6 +20,7 @@
#define ICP20160820_SCHEME_MODULE_H
#include <stdlib.h>
#include <stdio.h>
#include "schemes.h"
@ -50,6 +51,9 @@ gfsec_scheme_module_put_file(gfsec_scheme_t,
unsigned char *,
size_t);
void
gfsec_scheme_module_list_authorities(FILE *);
#ifdef __cpluscplus
}
#endif

Loading…
Cancel
Save