Exemple #1
0
static int
secret_tool_action_store (int argc,
                          char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    SecretService *service;
    GHashTable *attributes;
    SecretValue *value;
    gchar *collection = NULL;

    context = g_option_context_new ("attribute value ...");
    g_option_context_add_main_entries (context, STORE_OPTIONS, GETTEXT_PACKAGE);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("%s\n", error->message);
        usage();
    }

    g_option_context_free (context);

    if (store_label == NULL) {
        g_printerr ("%s: must specify a label for the new item\n", g_get_prgname ());
        usage ();
    }

    attributes = attributes_from_arguments (attribute_args);
    g_strfreev (attribute_args);

    if (store_collection) {
        /* TODO: Verify that the collection is a valid path or path element */
        if (g_str_has_prefix (store_collection, "/"))
            collection = g_strdup (store_collection);
        else
            collection = g_strconcat (SECRET_ALIAS_PREFIX, store_collection, NULL);
    }

    service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
    if (error == NULL) {
        if (isatty (0))
            value = read_password_tty ();
        else
            value = read_password_stdin ();

        secret_service_store_sync (service, NULL, attributes, collection, store_label, value, NULL, &error);
        secret_value_unref (value);
    }

    g_object_unref (service);
    g_hash_table_unref (attributes);
    g_free (store_label);
    g_free (store_collection);
    g_free (collection);

    if (error != NULL) {
        g_printerr ("%s: %s\n", g_get_prgname (), error->message);
        return 1;
    }

    return 0;
}
Exemple #2
0
static int
secret_tool_action_clear (int argc,
                          char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    SecretService *service;
    GHashTable *attributes;

    context = g_option_context_new ("attribute value ...");
    g_option_context_add_main_entries (context, CLEAR_OPTIONS, GETTEXT_PACKAGE);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("%s\n", error->message);
        usage();
    }

    g_option_context_free (context);

    attributes = attributes_from_arguments (attribute_args);
    g_strfreev (attribute_args);

    service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
    if (error == NULL)
        secret_service_clear_sync (service, NULL, attributes, NULL, &error);

    g_object_unref (service);
    g_hash_table_unref (attributes);

    if (error != NULL) {
        g_printerr ("%s: %s\n", g_get_prgname (), error->message);
        return 1;
    }

    return 0;
}
Exemple #3
0
static int keyring_get(struct credential *c)
{
	SecretService *service = NULL;
	GHashTable *attributes = NULL;
	GError *error = NULL;
	GList *items = NULL;

	if (!c->protocol || !(c->host || c->path))
		return EXIT_FAILURE;

	service = secret_service_get_sync(0, NULL, &error);
	if (error != NULL) {
		g_critical("could not connect to Secret Service: %s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	attributes = make_attr_list(c);
	items = secret_service_search_sync(service,
					   SECRET_SCHEMA_COMPAT_NETWORK,
					   attributes,
					   SECRET_SEARCH_LOAD_SECRETS,
					   NULL,
					   &error);
	g_hash_table_unref(attributes);
	if (error != NULL) {
		g_critical("lookup failed: %s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	if (items != NULL) {
		SecretItem *item;
		SecretValue *secret;
		const char *s;

		item = items->data;
		secret = secret_item_get_secret(item);
		attributes = secret_item_get_attributes(item);

		s = g_hash_table_lookup(attributes, "user");
		if (s) {
			g_free(c->username);
			c->username = g_strdup(s);
		}

		s = secret_value_get_text(secret);
		if (s) {
			g_free(c->password);
			c->password = g_strdup(s);
		}

		g_hash_table_unref(attributes);
		secret_value_unref(secret);
		g_list_free_full(items, g_object_unref);
	}

	return EXIT_SUCCESS;
}
Exemple #4
0
G_MODULE_EXPORT gboolean
remmina_plugin_entry(RemminaPluginService *service)
{
	TRACE_CALL(__func__);

	remmina_plugin_service = service;

	if (!service->register_plugin((RemminaPlugin*)&remmina_plugin_glibsecret)) {
		return FALSE;
	}

#ifdef LIBSECRET_VERSION_0_18
	GError *error;
	error = NULL;
	secretservice = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
	if (error) {
		g_print("[glibsecret] unable to get secret service: %s\n", error->message);
		return FALSE;
	}
	if (secretservice == NULL) {
		g_print("[glibsecret] unable to get secret service: Unknown error.\n");
		return FALSE;
	}

	defaultcollection = secret_collection_for_alias_sync(secretservice, SECRET_COLLECTION_DEFAULT, SECRET_COLLECTION_NONE, NULL, &error);
	if (error) {
		g_print("[glibsecret] unable to get secret service default collection: %s\n", error->message);
		return FALSE;
	}

	remmina_plugin_glibsecret_unlock_secret_service();
	return TRUE;

#else
	g_print("Libsecret was too old during compilation, disabling secret service.\n");
	return FALSE;
#endif

}
const backend_libsecret_context_t*
dt_pwstorage_libsecret_new()
{
  backend_libsecret_context_t* context = calloc(1, sizeof(backend_libsecret_context_t));
  if (context == NULL) {
    return NULL;
  }

  context->secret_service = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, NULL);
  if (context->secret_service == NULL) {
    dt_pwstorage_libsecret_destroy(context);
    return NULL;
  }

  /* Ensure to load all collections */
  if (secret_service_load_collections_sync(context->secret_service, NULL, NULL) == FALSE) {
    dt_pwstorage_libsecret_destroy(context);
    return NULL;
  }

  GList* collections = secret_service_get_collections(context->secret_service);
  SecretCollection* item = NULL;

  gboolean collection_exists = FALSE;
  GFOREACH(item, collections) {
    gchar* label = secret_collection_get_label(item);
    if (g_strcmp0(label, DARKTABLE_KEYRING)) {
      collection_exists = TRUE;
      context->secret_collection = item;
      g_object_ref(context->secret_collection);

      g_free(label);
      break;
    }
    g_free(label);
  }
Exemple #6
0
static int
secret_tool_action_search (int argc,
                           char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    SecretService *service;
    GHashTable *attributes;
    SecretSearchFlags flags;
    gboolean flag_all = FALSE;
    gboolean flag_unlock = FALSE;
    GList *items, *l;

    /* secret-tool lookup name xxxx yyyy zzzz */
    const GOptionEntry lookup_options[] = {
        {   "all", 'a', 0, G_OPTION_ARG_NONE, &flag_all,
            N_("return all results, instead of just first one"), NULL
        },
        {   "unlock", 'a', 0, G_OPTION_ARG_NONE, &flag_unlock,
            N_("unlock item results if necessary"), NULL
        },
        {   G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &attribute_args,
            N_("attribute value pairs of item to lookup"), NULL
        },
        { NULL }
    };

    context = g_option_context_new ("attribute value ...");
    g_option_context_add_main_entries (context, lookup_options, GETTEXT_PACKAGE);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("%s\n", error->message);
        usage();
    }

    g_option_context_free (context);

    attributes = attributes_from_arguments (attribute_args);
    g_strfreev (attribute_args);

    service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
    if (error == NULL) {
        flags = SECRET_SEARCH_LOAD_SECRETS;
        if (flag_all)
            flags |= SECRET_SEARCH_ALL;
        if (flag_unlock)
            flags |= SECRET_SEARCH_UNLOCK;
        items = secret_service_search_sync (service, NULL, attributes, flags, NULL, &error);
        if (error == NULL) {
            for (l = items; l != NULL; l = g_list_next (l))
                print_item_details (l->data);
            g_list_free_full (items, g_object_unref);
        }

        g_object_unref (service);
    }

    g_hash_table_unref (attributes);

    if (error != NULL) {
        g_printerr ("%s: %s\n", g_get_prgname (), error->message);
        return 1;
    }

    return 0;
}