Esempio n. 1
0
File: secret.c Progetto: vifino/dwb
static void 
on_service_lock_unlock_collection(GObject *source, GAsyncResult *result, dwb_secret_t *secret) {
    SecretService *service = get_service(secret, result);
    if (service == NULL) 
        return;

    GList *cols = NULL;
    GList *collections = secret_service_get_collections(service);
    gboolean lock = secret->action == DWB_SECRET_ACTION_LOCK;

    for (GList *l = collections; l != NULL; l=l->next) {
        SecretCollection *collection = l->data;
        gboolean locked = secret_collection_get_locked(collection);
        if ((lock && !locked) || (!lock && locked)) {
            char *label = secret_collection_get_label(collection);
            if (!g_strcmp0(secret->data, label)) {
                cols = g_list_append(cols, collection);
            }
            g_free(label);
        }
    }
    if (cols != NULL) {
        if (!lock) 
            secret_service_unlock(service, cols, NULL, (GAsyncReadyCallback)on_lock_unlock_collection, secret);
        else 
            secret_service_lock(service, cols, NULL, (GAsyncReadyCallback)on_lock_unlock_collection, secret);
    }
    else {
        invoke(secret, DWB_SECRET_NO_SUCH_COLLECTION, NULL);
    }
    if (collections != NULL) {
        g_list_free_full(collections, g_object_unref);
    }
    g_object_unref(service);
}
Esempio n. 2
0
File: secret.c Progetto: vifino/dwb
static SecretCollection *
collection_first_matching(SecretService *service, const char *name) {
    SecretCollection *ret = NULL;
    GList *collections = secret_service_get_collections(service);
    for (GList *l = collections; l != NULL && ret == NULL; l=l->next) {
        SecretCollection *collection = l->data;
        char *label = secret_collection_get_label(collection);
        if (!g_strcmp0(name, label)) {
            ret = g_object_ref(collection);
        }
    }
    g_list_free_full(collections, g_object_unref);
    return ret;
}
Esempio n. 3
0
static void remmina_plugin_glibsecret_unlock_secret_service()
{
	TRACE_CALL(__func__);

#ifdef LIBSECRET_VERSION_0_18

	GError *error = NULL;
	GList *objects, *ul;
	gchar* lbl;

	if (secretservice && defaultcollection) {
		if (secret_collection_get_locked(defaultcollection)) {
			lbl = secret_collection_get_label(defaultcollection);
			remmina_plugin_service->log_printf("[glibsecret] requesting unlock of the default '%s' collection\n", lbl);
			objects = g_list_append(NULL, defaultcollection);
			secret_service_unlock_sync(secretservice, objects, NULL, &ul, &error);
			g_list_free(objects);
			g_list_free(ul);
		}
	}
#endif
	return;
}
Esempio n. 4
0
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);
  }