Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
static EUri *
ep_keyring_uri_new (const gchar *string,
                    GError **error)
{
	EUri *uri;

	uri = e_uri_new (string);
	g_return_val_if_fail (uri != NULL, NULL);

	/* LDAP URIs do not have usernames, so use the URI as the username. */
	if (uri->user == NULL && uri->protocol != NULL &&
			(strcmp (uri->protocol, "ldap") == 0|| strcmp (uri->protocol, "google") == 0))
		uri->user = g_strdelimit (g_strdup (string), "/=", '_');

	/* Make sure the URI has the required components. */
	if (uri->user == NULL && uri->host == NULL) {
		g_set_error_literal (
			error, EP_KEYRING_ERROR,
			GNOME_KEYRING_RESULT_BAD_ARGUMENTS,
			_("Keyring key is unusable: no user or host name"));
		e_uri_free (uri);
		uri = NULL;
	}

	return uri;
}
Exemplo n.º 3
0
static void
create_ldap_source (EAccount * account, ESourceGroup * group)
{
    ESource *source;
    EUri *euri;
    char *uri;
    char *uid;
    xmlNodePtr node;

    euri = e_uri_new (account->source->url);

    uri = g_strdup_printf ("ldap://%s:389/o=Scalix?sub", euri->host);
    uid = g_strdup_printf ("system-ldap@%s", account->uid);

    node = xmlNewNode (NULL, "source");
    xmlSetProp (node, "uid", uid);
    xmlSetProp (node, "name", _("System"));
    xmlSetProp (node, "uri", uri);

    source = e_source_new_from_xml_node (node);
    xmlFreeNode (node);
    e_source_set_property (source, "completion", "TRUE");

    if (!e_source_group_add_source (group, source, 1)) {
        g_print ("Could not add ldap source\n");
    }

    g_free (uri);
    g_free (uid);
    e_uri_free (euri);
}
Exemplo n.º 4
0
static ESourceGroup *
create_group (EAccount * account, const char *type_string)
{
    ESourceGroup *gfake;
    char *uid;
    char *base_uri;
    xmlDocPtr doc;
    xmlNodePtr root;
    EUri *euri;
    const char *surl;

    uid = g_strdup_printf ("%s@%s", type_string, account->uid);

    doc = xmlNewDoc ("1.0");
    root = xmlNewDocNode (doc, NULL, "group", NULL);
    xmlDocSetRootElement (doc, root);

    surl = e_account_get_string (account, E_ACCOUNT_SOURCE_URL);
    euri = e_uri_new (surl);
    base_uri = create_base_uri (euri);
    e_uri_free (euri);

    xmlSetProp (root, "uid", uid);
    xmlSetProp (root, "name", account->name);
    xmlSetProp (root, "base_uri", base_uri);

    gfake = e_source_group_new_from_xmldoc (doc);
    g_free (base_uri);
    g_free (uid);
    xmlFreeDoc (doc);

    return gfake;
}
Exemplo n.º 5
0
static void
addressbook_authenticate (EBook *book,
			  gpointer data)
{
	gchar *auth;
	gchar *user;
	gchar *passwd;
	gchar *str_uri;
	gchar *pass_key;
	gchar *auth_domain;
	gchar *component_name;
	EUri *e_uri;

	ESource *source = (ESource *)data;

	auth = (gchar *)e_source_get_property (source, "auth");
	auth_domain = (gchar *)e_source_get_property (source, "auth-domain");
	component_name = auth_domain ? auth_domain : "Addressbook";

	if (auth && !strcmp ("plain/password", auth))
		user = (gchar *)e_source_get_property (source, "user");
	else
		user = (gchar *)e_source_get_property (source, "email_addr");
	if (!user)
		user = "";

	str_uri = e_source_get_uri (source);
	e_uri = e_uri_new (str_uri);
	pass_key = e_uri_to_string (e_uri, FALSE);
	e_uri_free (e_uri);

	passwd = e_passwords_get_password (component_name, pass_key);
	if (passwd)
		passwd = "";

	if (book)
		if (!e_book_authenticate_user (book, user, passwd, auth, NULL))
			LOG (g_warning ("Authentication failed"));
	g_free (pass_key);
	g_free (str_uri);

	return;
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
static EPublishUri *
migrateURI (const gchar *xml, xmlDocPtr doc)
{
	GConfClient *client;
	GSList *uris, *l, *events = NULL;
	xmlChar *location, *enabled, *frequency, *username;
	xmlNodePtr root, p;
	EPublishUri *uri;
	gchar *password, *temp;
	EUri *euri;

	client = gconf_client_get_default ();
	uris = gconf_client_get_list (client, "/apps/evolution/calendar/publish/uris", GCONF_VALUE_STRING, NULL);
	l = uris;
	while (l && l->data) {
		gchar *str = l->data;
		if (strcmp (xml, str) == 0) {
			uris = g_slist_remove (uris, str);
			g_free (str);
		}
		l = g_slist_next (l);
	}

	uri = g_new0 (EPublishUri, 1);

	root = doc->children;
	location = xmlGetProp (root, (const unsigned char *)"location");
	enabled = xmlGetProp (root, (const unsigned char *)"enabled");
	frequency = xmlGetProp (root, (const unsigned char *)"frequency");
	username = xmlGetProp (root, (const unsigned char *)"username");

	euri = e_uri_new ((const char *)location);

	if (!euri) {
		g_warning ("Could not form the uri for %s \n", location);
		goto cleanup;
	}

	if (euri->user)
		g_free (euri->user);

	euri->user = g_strdup ((const char *)username);

	temp = e_uri_to_string (euri, FALSE);
	uri->location = g_strdup_printf ("dav://%s", strstr (temp, "//") + 2);
	g_free (temp);
	e_uri_free (euri);

	if (enabled != NULL)
		uri->enabled = atoi ((char *)enabled);
	if (frequency != NULL)
		uri->publish_frequency = atoi ((char *)frequency);
	uri->publish_format = URI_PUBLISH_AS_FB;

	password = e_passwords_get_password ("Calendar", (char *)location);
	if (password) {
		e_passwords_forget_password ("Calendar", (char *)location);
		e_passwords_add_password (uri->location, password);
		e_passwords_remember_password ("Calendar", uri->location);
	}

	for (p = root->children; p != NULL; p = p->next) {
		xmlChar *uid = xmlGetProp (p, (const unsigned char *)"uid");
		if (strcmp ((char *)p->name, "source") == 0) {
			events = g_slist_append (events, uid);
		} else {
			g_free (uid);
		}
	}
	uri->events = events;

	uris = g_slist_prepend (uris, e_publish_uri_to_xml (uri));
	gconf_client_set_list (client, "/apps/evolution/calendar/publish/uris", GCONF_VALUE_STRING, uris, NULL);
	g_slist_foreach (uris, (GFunc) g_free, NULL);
	g_slist_free (uris);
	g_object_unref (client);

cleanup:
	xmlFree (location);
	xmlFree (enabled);
	xmlFree (frequency);
	xmlFree (username);
	xmlFreeDoc (doc);

	return uri;
}
Exemplo n.º 8
0
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);
}