Пример #1
0
const backend_gkeyring_context_t*
dt_pwstorage_gkeyring_new()
{
  backend_gkeyring_context_t *context = (backend_gkeyring_context_t*)g_malloc(sizeof(backend_gkeyring_context_t));

#ifdef DARKTABLE_KEYRING
  /* Check if darktable keyring exists, if not create it */
  gboolean keyring_exists = FALSE;
  GList *keyrings = NULL,*item = NULL;
  gnome_keyring_list_keyring_names_sync(&keyrings);
  if ( keyrings && (item = keyrings))
  {
    do
    {
      if (strcmp ((gchar *)item->data,DARKTABLE_KEYRING)==0)
      {
        keyring_exists = TRUE;
        break;
      }
    }
    while ((item = g_list_next (item)) != NULL);
    gnome_keyring_string_list_free(keyrings);
  }

  if (keyring_exists == FALSE)
    gnome_keyring_create_sync (DARKTABLE_KEYRING,NULL);
#else
#define DARKTABLE_KEYRING NULL
#endif
  /* unlock darktable keyring */
  // Keep this locked until accessed..
  //gnome_keyring_lock_sync(DARKTABLE_KEYRING);
  return context;
}
NS_IMETHODIMP GnomeKeyring::Init()
#endif
{
  nsresult ret;
  nsCOMPtr<nsIServiceManager> servMan;
  nsCOMPtr<nsIPrefService> prefService;
  nsCOMPtr<nsIPrefBranch> pref;
#ifdef PR_LOGGING
  gGnomeKeyringLog = PR_NewLogModule("GnomeKeyringLog");
#endif
  keyringName.AssignLiteral(kDefaultKeyring);
  ret = NS_GetServiceManager(getter_AddRefs(servMan));
  if (ret != NS_OK) { return ret; }

  ret = servMan->GetServiceByContractID("@mozilla.org/preferences-service;1",
                                        NS_GET_IID(nsIPrefService),
                                        getter_AddRefs(prefService));
  if (ret != NS_OK) { return ret; }

  ret = prefService->ReadUserPrefs(nullptr);
  if (ret != NS_OK) { return ret; }

  ret = prefService->GetBranch(kPrefsBranch, getter_AddRefs(pref));
  if (ret != NS_OK) { return ret; }

  PRInt32 prefType;
  ret = pref->GetPrefType(kPrefsKeyring, &prefType);
  if (ret != NS_OK) { return ret; }

  if (prefType == 32) {
    char* tempKeyringName;
    pref->GetCharPref(kPrefsKeyring, &tempKeyringName);
    keyringName = tempKeyringName;
    if ( keyringName.IsVoid() || keyringName.IsEmpty() ) keyringName.AssignLiteral(kDefaultKeyring);
  }

  /* Create the password keyring, it doesn't hurt if it already exists */
  GnomeKeyringResult result = gnome_keyring_create_sync(keyringName.get(), NULL);
  if ((result != GNOME_KEYRING_RESULT_OK) &&
      (result != GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS)) {
    NS_ERROR("Can't open or create password keyring!");
    return NS_ERROR_FAILURE;
  }
  return ret;
}
Пример #3
0
int keyring_create(char *keyring, char *password)
{
  GnomeKeyringResult res = gnome_keyring_create_sync(keyring, password);

  return keyring_handle_error(res);
}