コード例 #1
0
ファイル: gkm-wrap-prompt.c プロジェクト: GNOME/gnome-keyring
static const gchar *
gkm_wrap_prompt_request_password (GkmWrapPrompt *self)
{
	GError *error = NULL;
	const gchar *password;

	g_assert (GKM_IS_WRAP_PROMPT (self));

	if (!gkm_wrap_prompt_prepare (self))
		return NULL;

	password = gcr_prompt_password (GCR_PROMPT (self), NULL, &error);
	if (error != NULL) {
		g_warning ("couldn't prompt for password: %s", egg_error_message (error));
		g_error_free (error);
	}

	return password;
}
コード例 #2
0
static gchar*
do_get_password (GckSession *session, const gchar *keyid, const gchar *errmsg,
                 const gchar *prompt_text, const gchar *description, gboolean confirm)
{
	GSettings *settings;
	gchar *password = NULL;
	GcrPrompt *prompt;
	gboolean chosen;
	GError *error = NULL;
	gint lifetime;
	gchar *method;
	gchar *label;
	gchar *text;

	g_assert (GCK_IS_SESSION (session));

	/* Do we have the keyid? */
	password = gkd_login_lookup_password (session, "keyid", keyid,
	                                      "source", "gnome-keyring:gpg-agent", NULL);
	if (password != NULL)
		return password;

	prompt = open_password_prompt (session, keyid, errmsg, prompt_text,
	                               description, confirm);
	if (prompt != NULL) {
		password = egg_secure_strdup (gcr_prompt_password (prompt, NULL, &error));
		if (password == NULL) {
			if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
				g_warning ("couldn't prompt for password: %s", egg_error_message (error));
			g_clear_error (&error);
		}
	}

	if (password != NULL && keyid != NULL) {
		settings = gkd_gpg_agent_settings ();

		/* Load up the save options */
		chosen = gcr_prompt_get_choice_chosen (prompt);

		if (chosen) {
			method = g_strdup (GCR_UNLOCK_OPTION_ALWAYS);
			lifetime = -1;

		} else {
			method = g_settings_get_string (settings, "gpg-cache-method");
			lifetime = g_settings_get_int (settings, "gpg-cache-ttl");
			if (g_str_equal (method, GCR_UNLOCK_OPTION_ALWAYS)) {
				g_free (method);
				method = NULL;
			}
		}

		/* Now actually save the password */
		text = calculate_label_for_key (keyid, description);
		label = g_strdup_printf (_("PGP Key: %s"), text);
		gkd_login_store_password (session, password, label, method, lifetime,
		                          "keyid", keyid, "source", "gnome-keyring:gpg-agent", NULL);
		g_free (label);
		g_free (method);
		g_free (text);
	}

	g_clear_object (&prompt);
	return password;
}