Example #1
0
File: secret.c Project: 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);
}
Example #2
0
File: secret.c Project: 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;
}
Example #3
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);
  }