static gboolean
emss_process_message (struct _write_msg *msg)
{
	struct _EMSyncStream *emss = msg->emss;

	/* Force out any pending data before doing anything else. */
	if (emss->buffer != NULL && emss->buffer->len > 0) {
		EMSS_CLASS (emss)->sync_write (
			CAMEL_STREAM (emss), emss->buffer->str,
			emss->buffer->len);
		g_string_set_size (emss->buffer, 0);
	}

	switch (msg->op) {
		case EMSS_WRITE:
			EMSS_CLASS (emss)->sync_write (
				CAMEL_STREAM (emss), msg->string, msg->len);
			break;
		case EMSS_FLUSH:
			EMSS_CLASS (emss)->sync_flush (
				CAMEL_STREAM (emss));
			break;
		case EMSS_CLOSE:
			EMSS_CLASS (emss)->sync_close (
				CAMEL_STREAM (emss));
			break;
	}

	e_flag_set (msg->done);

	return FALSE;
}
static void
ep_clear_passwords (EPassMsg *msg)
{
	GList *passwords;
	GError *error = NULL;

	/* Find all Evolution passwords and delete them. */
	passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error);
	if (passwords != NULL) {
		ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error);
		gnome_keyring_found_list_free (passwords);
	}

	/* Not finding the requested key is acceptable, but we still
	 * want to leave an informational message on the terminal. */
	if (g_error_matches (error, EP_KEYRING_ERROR, GNOME_KEYRING_RESULT_NO_MATCH)) {
		g_message ("%s", error->message);
		g_error_free (error);

	} else if (error != NULL)
		g_propagate_error (&msg->error, error);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
ep_remember_password (EPassMsg *msg)
{
	gchar *password;
	EUri *uri;
	GError *error = NULL;

	password = g_hash_table_lookup (password_cache, msg->key);
	if (password == NULL) {
		g_warning ("Password for key \"%s\" not found", msg->key);
		goto exit;
	}

	uri = ep_keyring_uri_new (msg->key, &msg->error);
	if (uri == NULL)
		goto exit;

	/* Only remove the password from the session hash
	 * if the keyring insertion was successful. */
	if (ep_keyring_insert_password (uri->user, uri->host, uri->protocol, msg->key, password, &error))
		g_hash_table_remove (password_cache, msg->key);

	if (error != NULL)
		g_propagate_error (&msg->error, error);

	e_uri_free (uri);

exit:
	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
ep_remember_password (EPassMsg *msg)
{
	ep_remember_password_keyfile (msg);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
ep_clear_passwords (EPassMsg *msg)
{
	ep_clear_passwords_keyfile (msg);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
ep_forget_password (EPassMsg *msg)
{
	g_hash_table_remove (password_cache, msg->key);

	ep_forget_password_keyfile (msg);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
ep_add_password (EPassMsg *msg)
{
	g_hash_table_insert (
		password_cache, g_strdup (msg->key),
		g_strdup (msg->oldpass));

	if (!msg->noreply)
		e_flag_set (msg->done);
}
/**
 * e_passwords_cancel:
 *
 * Cancel any outstanding password operations and close any dialogues
 * currently being shown.
 **/
void
e_passwords_cancel (void)
{
	EPassMsg *msg;

	G_LOCK (passwords);
	while ((msg = g_queue_pop_head (&message_queue)) != NULL)
		e_flag_set (msg->done);
	G_UNLOCK (passwords);

	if (password_dialog)
		gtk_dialog_response (password_dialog, GTK_RESPONSE_CANCEL);
}
Exemple #9
0
static void
attachment_load_finished (EAttachmentStore *store,
                          GAsyncResult *result,
                          gpointer user_data)
{
	struct _att_async_cb_data *data = user_data;

	/* XXX Should be no need to check for error here.
	 *     This is just to reset state in the EAttachment. */
	e_attachment_store_load_finish (store, result, NULL);

	e_flag_set (data->flag);
}
static void
ep_get_password (EPassMsg *msg)
{
	gchar *password;

	/* Check the in-memory cache first. */
	password = g_hash_table_lookup (password_cache, msg->key);
	if (password != NULL) {
		msg->password = g_strdup (password);

	} else
		ep_get_password_keyfile (msg);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
Exemple #11
0
static void
attachment_save_finished (EAttachmentStore *store,
                          GAsyncResult *result,
                          gpointer user_data)
{
	struct _att_async_cb_data *data = user_data;
	gchar **uris;
	GError *error = NULL;

	uris = e_attachment_store_save_finish (store, result, &error);
	if (error != NULL)
		data->uris = NULL;
	else
		data->uris = uris;

	g_clear_error (&error);

	e_flag_set (data->flag);
}
static gpointer
book_view_thread (gpointer data)
{
	EDataBookView *book_view = data;
	VCFBackendSearchClosure *closure = get_closure (book_view);
	const gchar *query;
	GList *l;

	/* ref the book view because it'll be removed and unrefed
	   when/if it's stopped */
	e_data_book_view_ref (book_view);

	query = e_data_book_view_get_card_query (book_view);

	if ( !strcmp (query, "(contains \"x-evolution-any-field\" \"\")"))
		e_data_book_view_notify_status_message (book_view, _("Loading..."));
	else
		e_data_book_view_notify_status_message (book_view, _("Searching..."));

	d(printf ("signalling parent thread\n"));
	e_flag_set (closure->running);

	for (l = closure->bvcf->priv->contact_list; l; l = l->next) {
		gchar *vcard_string = l->data;
		EContact *contact = e_contact_new_from_vcard (vcard_string);
		e_data_book_view_notify_update (closure->view, contact);
		g_object_unref (contact);

		if (!e_flag_is_set (closure->running))
			break;
	}

	if (e_flag_is_set (closure->running))
		e_data_book_view_notify_complete (closure->view, NULL /* Success */);

	/* unref the book view */
	e_data_book_view_unref (book_view);

	d(printf ("finished initial population of book view\n"));

	return NULL;
}
/**
 * e_passwords_shutdown:
 *
 * Cleanup routine to call before exiting.
 **/
void
e_passwords_shutdown (void)
{
	EPassMsg *msg;

	G_LOCK (passwords);

	while ((msg = g_queue_pop_head (&message_queue)) != NULL)
		e_flag_set (msg->done);

	if (password_cache != NULL) {
		g_hash_table_destroy (password_cache);
		password_cache = NULL;
	}


	G_UNLOCK (passwords);

	if (password_dialog != NULL)
		gtk_dialog_response (password_dialog, GTK_RESPONSE_CANCEL);
}
static void
ep_forget_passwords (EPassMsg *msg)
{
	GList *passwords;
	GError *error = NULL;

	g_hash_table_remove_all (password_cache);

	/* Find all Evolution passwords and delete them. */
	passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error);
	if (passwords != NULL) {
		ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error);
		gnome_keyring_found_list_free (passwords);
	}

	if (error != NULL)
		g_propagate_error (&msg->error, error);

	if (!msg->noreply)
		e_flag_set (msg->done);
}
static gpointer
book_view_thread (gpointer data)
{
	EDataBookView                          *book_view = data;
	WebdavBackendSearchClosure             *closure   = get_closure (book_view);
	EBookBackendWebdav                     *webdav    = closure->webdav;
	GError *error;

	e_flag_set (closure->running);

	/* ref the book view because it'll be removed and unrefed when/if
	 * it's stopped */
	g_object_ref (book_view);

	error = download_contacts (webdav, closure->running, book_view, NULL);

	g_object_unref (book_view);

	if (error)
		g_error_free (error);

	return NULL;
}
static void
ep_forget_password (EPassMsg *msg)
{
	GList *passwords;
	EUri *uri;
	GError *error = NULL;

	g_hash_table_remove (password_cache, msg->key);

	uri = ep_keyring_uri_new (msg->key, &msg->error);
	if (uri == NULL)
		goto exit;

	/* Find all Evolution passwords matching the URI and delete them.
	 *
	 * XXX We didn't always store protocols in the keyring, so for
	 *     backward-compatibility we need to lookup passwords by user
	 *     and host only (no protocol).  But we do send the protocol
	 *     to ep_keyring_delete_passwords(), which also knows about
	 *     the backward-compatibility issue and will filter the list
	 *     appropriately. */
	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error);
	if (passwords != NULL) {
		ep_keyring_delete_passwords (uri->user, uri->host, uri->protocol, passwords, &error);
		gnome_keyring_found_list_free (passwords);
	}

	if (error != NULL)
		g_propagate_error (&msg->error, error);

	e_uri_free (uri);

exit:
	if (!msg->noreply)
		e_flag_set (msg->done);
}
static void
pass_response (GtkDialog *dialog,
               gint response,
               gpointer data)
{
	EPassMsg *msg = data;
	gint type = msg->flags & E_PASSWORDS_REMEMBER_MASK;
	GList *iter, *trash = NULL;

	if (response == GTK_RESPONSE_OK) {
		msg->password = g_strdup (gtk_entry_get_text ((GtkEntry *) msg->entry));

		if (type != E_PASSWORDS_REMEMBER_NEVER) {
			gint noreply = msg->noreply;

			*msg->remember = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (msg->check));

			msg->noreply = 1;

			if (*msg->remember || type == E_PASSWORDS_REMEMBER_FOREVER) {
				msg->oldpass = msg->password;
				ep_add_password (msg);
			}
			if (*msg->remember && type == E_PASSWORDS_REMEMBER_FOREVER)
				ep_remember_password (msg);

			msg->noreply = noreply;
		}
	}

	gtk_widget_destroy ((GtkWidget *) dialog);
	password_dialog = NULL;

	/* ok, here things get interesting, we suck up any pending
	 * operations on this specific password, and return the same
	 * result or ignore other operations */

	G_LOCK (passwords);
	for (iter = g_queue_peek_head_link (&message_queue); iter != NULL; iter = iter->next) {
		EPassMsg *pending = iter->data;

		if ((pending->dispatch == ep_forget_password
		     || pending->dispatch == ep_get_password
		     || pending->dispatch == ep_ask_password)
			&& strcmp (pending->key, msg->key) == 0) {

			/* Satisfy the pending operation. */
			pending->password = g_strdup (msg->password);
			e_flag_set (pending->done);

			/* Mark the queue node for deletion. */
			trash = g_list_prepend (trash, iter);
		}
	}

	/* Expunge the message queue. */
	for (iter = trash; iter != NULL; iter = iter->next)
		g_queue_delete_link (&message_queue, iter->data);
	g_list_free (trash);

	G_UNLOCK (passwords);

	if (!msg->noreply)
		e_flag_set (msg->done);

	ep_idle_dispatch (NULL);
}
static void
ep_get_password (EPassMsg *msg)
{
	EUri *uri;
	GList *passwords;
	gchar *password;
	GError *error = NULL;

	/* Check the in-memory cache first. */
	password = g_hash_table_lookup (password_cache, msg->key);
	if (password != NULL) {
		msg->password = g_strdup (password);
		goto exit;
	}

	uri = ep_keyring_uri_new (msg->key, &msg->error);
	if (uri == NULL)
		goto exit;

	/* Find the first Evolution password that matches the URI. */
	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, uri->protocol, &error);
	if (passwords != NULL) {
		GList *iter = passwords;

		while (iter != NULL) {
			GnomeKeyringFound *found = iter->data;

			if (default_keyring && strcmp (default_keyring, found->keyring) != 0) {
				g_message ("Received a password from keyring '%s'. But looking for the password from '%s' keyring\n", found->keyring, default_keyring);
				iter = g_list_next (iter);
				continue;
			}

			if (ep_keyring_validate (uri->user, uri->host, uri->protocol, found->attributes)) {
				msg->password = g_strdup (found->secret);
				break;
			}

			iter = g_list_next (iter);
		}

		gnome_keyring_found_list_free (passwords);
	}

	if (msg->password != NULL)
		goto done;

	/* Clear the previous error, if there was one.  If the error was
	 * something other than NO_MATCH then it's likely to occur again. */
	if (error != NULL)
		g_clear_error (&error);

	/* XXX We didn't always store protocols in the keyring, so for
	 *     backward-compatibility we also need to lookup passwords
	 *     by user and host only (no protocol). */
	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error);
	if (passwords != NULL) {
		GList *iter = passwords;

		while (iter != NULL) {
			GnomeKeyringFound *found = iter->data;

			if (default_keyring && strcmp (default_keyring, found->keyring) != 0) {
				g_message ("Received a password from keyring '%s'. But looking for the password from '%s' keyring\n", found->keyring, default_keyring);
				iter = g_list_next (iter);
				continue;
			}
			if (ep_keyring_validate (uri->user, uri->host, NULL, found->attributes)) {
				msg->password = g_strdup (found->secret);
				break;
			}

			iter = g_list_next (iter);
		}

		gnome_keyring_found_list_free (passwords);
	}

done:
	/* Not finding the requested key is acceptable, but we still
	 * want to leave an informational message on the terminal. */
	if (g_error_matches (error, EP_KEYRING_ERROR, GNOME_KEYRING_RESULT_NO_MATCH)) {
		g_message ("%s", error->message);
		g_error_free (error);

	} else if (error != NULL)
		g_propagate_error (&msg->error, error);

	e_uri_free (uri);

exit:
	if (!msg->noreply)
		e_flag_set (msg->done);
}