static gboolean idle_cb (gpointer data) { EGwConnection *cnc; cnc = e_gw_connection_new (arg_hostname, arg_username, arg_password); if (E_IS_GW_CONNECTION (cnc)) { GList *container_list = NULL; g_print ("Connected to %s!\n", arg_hostname); /* get list of containers */ g_print ("Getting list of containers...\n"); if (e_gw_connection_get_container_list (cnc, "folders", &container_list) == E_GW_CONNECTION_STATUS_OK) { GList *container; for (container = container_list; container != NULL; container = container->next) display_container (E_GW_CONTAINER (container->data)); e_gw_connection_free_container_list (container_list); } g_object_unref (cnc); } else g_print ("ERROR: Could not connect to %s\n", arg_hostname); g_main_loop_quit (main_loop); return FALSE; }
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 gboolean groupwise_auth_loop (CamelService *service, GCancellable *cancellable, GError **error) { CamelSession *session = camel_service_get_session (service); CamelStore *store = CAMEL_STORE (service); CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gboolean authenticated = FALSE; gchar *uri; guint32 prompt_flags = CAMEL_SESSION_PASSWORD_SECRET; EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL}; if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never")) uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL); else uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL); service->url->passwd = NULL; while (!authenticated) { if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) { gchar *prompt; prompt = camel_session_build_password_prompt ( "GroupWise", service->url->user, service->url->host); service->url->passwd = camel_session_get_password (session, service, "Groupwise", prompt, "password", prompt_flags, error); g_free (prompt); if (!service->url->passwd) { g_set_error ( error, G_IO_ERROR, G_IO_ERROR_CANCELLED, _("You did not enter a password.")); return FALSE; } } priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors); if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) { gchar *http_uri = g_strconcat ("http://", uri + 8, NULL); priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd); g_free (http_uri); } if (!E_IS_GW_CONNECTION (priv->cnc)) { if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) { /* We need to un-cache the password before prompting again */ prompt_flags |= CAMEL_SESSION_PASSWORD_REPROMPT; g_free (service->url->passwd); service->url->passwd = NULL; } else { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_UNAVAILABLE, "%s", errors.description ? errors.description : _("You must be working online to complete this operation")); return FALSE; } } else authenticated = TRUE; } return TRUE; }
static gboolean groupwise_auth_loop (CamelService *service, CamelException *ex) { CamelSession *session = camel_service_get_session (service); CamelStore *store = CAMEL_STORE (service); CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gboolean authenticated = FALSE; char *uri; EGwConnectionErrors errors; if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never")) uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL); else uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL); service->url->passwd = NULL; while (!authenticated) { if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) { char *prompt; prompt = camel_session_build_password_prompt ( "GroupWise", service->url->user, service->url->host); service->url->passwd = camel_session_get_password (session, service, "Groupwise", prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex); g_free (prompt); if (!service->url->passwd) { camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("You did not enter a password.")); return FALSE; } } priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors); if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) { char *http_uri = g_strconcat ("http://", uri + 8, NULL); priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd); g_free (http_uri); } if (!E_IS_GW_CONNECTION(priv->cnc)) { if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) { /* We need to un-cache the password before prompting again */ camel_session_forget_password (session, service, "Groupwise", "password", ex); g_free (service->url->passwd); service->url->passwd = NULL; camel_exception_clear (ex); } else { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, g_strdup (errors.description)); return FALSE; } } else authenticated = TRUE; } return TRUE; }