static EGwConnection * get_cnc (GtkWindow *parent_window) { CamelNetworkSettings *network_settings; const gchar *failed_auth; gchar *uri, *key, *prompt, *password = NULL; CamelNetworkSecurityMethod security_method; const gchar *scheme; const gchar *host; const gchar *user; gboolean remember; gchar *soap_port; if (!CAMEL_IS_NETWORK_SETTINGS (settings)) return NULL; network_settings = CAMEL_NETWORK_SETTINGS (settings); host = camel_network_settings_get_host (network_settings); user = camel_network_settings_get_user (network_settings); if (host == NULL || *host == '\0') return NULL; if (user == NULL || *user == '\0') return NULL; g_object_get ( settings, "soap-port", &soap_port, "security-method", &security_method, NULL); if (security_method == CAMEL_NETWORK_SECURITY_METHOD_NONE) scheme = "http"; else scheme = "https"; key = g_strdup_printf ("groupwise://%s@%s/", user, host); uri = g_strdup_printf ("%s://%s:%s/soap", scheme, host, soap_port); failed_auth = ""; prompt = g_strdup_printf (_("%sEnter password for %s (user %s)"), failed_auth, host, user); password = e_passwords_get_password (NULL, key); if (!password) password = e_passwords_ask_password (prompt, NULL, key, prompt, E_PASSWORDS_REMEMBER_FOREVER | E_PASSWORDS_SECRET, &remember, parent_window); g_free (prompt); return e_gw_connection_new (uri, user, password); }
static char * auth_func_cb (ECal *ecal, const char *prompt, const char *key, gpointer user_data) { ESource *source; const gchar *auth_domain; const gchar *component_name; source = e_cal_get_source (ecal); auth_domain = e_source_get_property (source, "auth-domain"); component_name = auth_domain ? auth_domain : "Calendar"; return e_passwords_get_password (component_name, key); }
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; }
gboolean eee_account_auth(EeeAccount *self) { GError *err = NULL; guint32 flags = E_PASSWORDS_REMEMBER_FOREVER | E_PASSWORDS_SECRET; GConfClient *gconf; gboolean remember = TRUE; char *fail_msg = ""; char *password; int retry_limit = 3; gboolean rs; char *key; if (!eee_account_connect(self)) { return FALSE; } if (self->priv->is_authorized) { return TRUE; } key = g_strdup_printf("eee://%s", self->name); password = e_passwords_get_password(EEE_PASSWORD_COMPONENT, key); while (retry_limit--) { if (password == NULL) { gconf = gconf_client_get_default(); char *path = g_strdup_printf(EEE_KEY "accounts/%s/remember_password", self->name); remember = gconf_client_get_bool(gconf, path, NULL); char *prompt = g_strdup_printf("%sEnter password for your 3e calendar account: %s.", fail_msg, self->name); // key must have uri format or unpatched evolution segfaults in // ep_get_password_keyring() password = e_passwords_ask_password(prompt, EEE_PASSWORD_COMPONENT, key, prompt, flags, &remember, NULL); gconf_client_set_bool(gconf, path, remember, NULL); g_free(path); g_object_unref(gconf); g_free(prompt); if (password == NULL) { goto err; } } rs = ESClient_authenticate(self->priv->conn, self->name, password, &err); g_free(password); password = NULL; if (!err && rs == TRUE) { self->priv->is_authorized = TRUE; g_free(key); return TRUE; } if (err) { g_warning("** EEE ** Authentization failed for user '%s'. (%d:%s)", self->name, err->code, err->message); if (err->code == ES_XMLRPC_ERROR_AUTH_FAILED) { g_clear_error(&err); fail_msg = "Invalid password. "; } else { g_clear_error(&err); goto err; } } else { g_warning("** EEE ** Authentization failed for user '%s' without error.", self->name); fail_msg = "Invalid password. "; } e_passwords_forget_password(EEE_PASSWORD_COMPONENT, key); flags |= E_PASSWORDS_REPROMPT; } err: g_free(key); return FALSE; }
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; }
static EPublishUri * migrateURI (const gchar *xml, xmlDocPtr doc) { GSettings *settings; GSList *events = NULL; gchar **set_uris; GPtrArray *uris_array; xmlChar *location, *enabled, *frequency, *username; xmlNodePtr root, p; EPublishUri *uri; gchar *password, *temp; SoupURI *soup_uri; gint ii; gboolean found = FALSE; uri = g_new0 (EPublishUri, 1); root = doc->children; location = xmlGetProp (root, (const guchar *)"location"); enabled = xmlGetProp (root, (const guchar *)"enabled"); frequency = xmlGetProp (root, (const guchar *)"frequency"); username = xmlGetProp (root, (const guchar *)"username"); soup_uri = soup_uri_new ((gchar *) location); if (soup_uri == NULL) { g_warning ("Could not form the uri for %s \n", location); goto cleanup; } soup_uri_set_user (soup_uri, (gchar *) username); temp = soup_uri_to_string (soup_uri, FALSE); uri->location = g_strdup_printf ("dav://%s", strstr (temp, "//") + 2); g_free (temp); soup_uri_free (soup_uri); if (enabled != NULL) uri->enabled = atoi ((gchar *) enabled); if (frequency != NULL) uri->publish_frequency = atoi ((gchar *) frequency); uri->publish_format = URI_PUBLISH_AS_FB; password = e_passwords_get_password ((gchar *) location); if (password) { e_passwords_forget_password ((gchar *) location); e_passwords_add_password (uri->location, password); e_passwords_remember_password (uri->location); } for (p = root->children; p != NULL; p = p->next) { xmlChar *uid = xmlGetProp (p, (const guchar *)"uid"); if (strcmp ((gchar *) p->name, "source") == 0) { events = g_slist_append (events, uid); } else { g_free (uid); } } uri->events = events; uris_array = g_ptr_array_new_full (3, g_free); settings = g_settings_new (PC_SETTINGS_ID); set_uris = g_settings_get_strv (settings, PC_SETTINGS_URIS); for (ii = 0; set_uris && set_uris[ii]; ii++) { const gchar *str = set_uris[ii]; if (!found && g_str_equal (xml, str)) { found = TRUE; g_ptr_array_add (uris_array, e_publish_uri_to_xml (uri)); } else { g_ptr_array_add (uris_array, g_strdup (str)); } } g_strfreev (set_uris); /* this should not happen, right? */ if (!found) g_ptr_array_add (uris_array, e_publish_uri_to_xml (uri)); g_ptr_array_add (uris_array, NULL); g_settings_set_strv (settings, PC_SETTINGS_URIS, (const gchar * const *) uris_array->pdata); g_ptr_array_free (uris_array, TRUE); g_object_unref (settings); cleanup: xmlFree (location); xmlFree (enabled); xmlFree (frequency); xmlFree (username); xmlFreeDoc (doc); return uri; }