static GList * pop3_store_query_auth_types_sync (CamelService *service, GCancellable *cancellable, GError **error) { CamelServiceClass *service_class; CamelPOP3Store *store = CAMEL_POP3_STORE (service); GList *types = NULL; GError *local_error = NULL; /* Chain up to parent's query_auth_types() method. */ service_class = CAMEL_SERVICE_CLASS (camel_pop3_store_parent_class); types = service_class->query_auth_types_sync ( service, cancellable, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return NULL; } if (connect_to_server (service, cancellable, error)) { CamelPOP3Engine *pop3_engine; pop3_engine = camel_pop3_store_ref_engine (store); if (pop3_engine) { types = g_list_concat (types, g_list_copy (pop3_engine->auth)); pop3_store_disconnect_sync (service, TRUE, cancellable, NULL); g_clear_object (&pop3_engine); } } return types; }
static gboolean ews_transport_disconnect_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error) { CamelEwsTransport *ews_transport = CAMEL_EWS_TRANSPORT (service); g_mutex_lock (&ews_transport->priv->connection_lock); g_clear_object (&ews_transport->priv->connection); g_mutex_unlock (&ews_transport->priv->connection_lock); return CAMEL_SERVICE_CLASS (camel_ews_transport_parent_class)->disconnect_sync (service, clean, cancellable, error); }
static void offline_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) { CamelOfflineStore *store = CAMEL_OFFLINE_STORE (service); CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex); if (camel_exception_is_set (ex)) return; store->state = camel_session_is_online (session) ? CAMEL_OFFLINE_STORE_NETWORK_AVAIL : CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL; }
static gboolean ews_transport_connect_sync (CamelService *service, GCancellable *cancellable, GError **error) { EEwsConnection *connection; CamelSession *session; CamelSettings *settings; gchar *auth_mech; gboolean success; /* Chain up to parent's method. */ if (!CAMEL_SERVICE_CLASS (camel_ews_transport_parent_class)->connect_sync (service, cancellable, error)) return FALSE; if (camel_service_get_connection_status (service) == CAMEL_SERVICE_DISCONNECTED) return FALSE; connection = ews_transport_ref_connection (CAMEL_EWS_TRANSPORT (service)); if (connection) { g_object_unref (connection); return TRUE; } session = camel_service_ref_session (service); settings = camel_service_ref_settings (service); /* Try running an operation that requires authentication * to make sure we have valid credentials available. */ auth_mech = camel_network_settings_dup_auth_mechanism (CAMEL_NETWORK_SETTINGS (settings)); success = camel_session_authenticate_sync (session, service, auth_mech ? auth_mech : "NTLM", cancellable, error); g_free (auth_mech); g_object_unref (session); g_object_unref (settings); return success; }
static gboolean pop3_store_disconnect_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error) { CamelServiceClass *service_class; CamelPOP3Store *store = CAMEL_POP3_STORE (service); gboolean success; if (clean) { CamelPOP3Engine *pop3_engine; CamelPOP3Command *pc; pop3_engine = camel_pop3_store_ref_engine (store); if (pop3_engine) { pc = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, error, "QUIT\r\n"); while (camel_pop3_engine_iterate (pop3_engine, NULL, cancellable, NULL) > 0) ; camel_pop3_engine_command_free (pop3_engine, pc); g_clear_object (&pop3_engine); } } /* Chain up to parent's disconnect() method. */ service_class = CAMEL_SERVICE_CLASS (camel_pop3_store_parent_class); success = service_class->disconnect_sync (service, clean, cancellable, error); g_mutex_lock (&store->priv->property_lock); g_clear_object (&store->priv->engine); g_mutex_unlock (&store->priv->property_lock); return success; }
static gboolean smtp_transport_disconnect_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error) { CamelServiceClass *service_class; CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service); /*if (!service->connected) * return TRUE; */ if (transport->connected && clean) { /* send the QUIT command to the SMTP server */ smtp_quit (transport, cancellable, NULL); } /* Chain up to parent's disconnect() method. */ service_class = CAMEL_SERVICE_CLASS (camel_smtp_transport_parent_class); if (!service_class->disconnect_sync (service, clean, cancellable, error)) return FALSE; if (transport->authtypes) { g_hash_table_foreach (transport->authtypes, authtypes_free, NULL); g_hash_table_destroy (transport->authtypes); transport->authtypes = NULL; } g_clear_object (&transport->istream); g_clear_object (&transport->ostream); g_clear_object (&transport->local_address); transport->connected = FALSE; return TRUE; }
static gboolean groupwise_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, GError **error) { CamelServiceClass *service_class; CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service); CamelStore *store = CAMEL_STORE (service); const gchar *property_value; CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gchar *path = NULL; d(printf ("\nin groupwise store constrcut\n")); /* Chain up to parent's construct() method. */ service_class = CAMEL_SERVICE_CLASS (camel_groupwise_store_parent_class); if (!service_class->construct (service, session, provider, url, error)) return FALSE; if (!(url->host || url->user)) { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID, _("Host or user not available in url")); } /*storage path*/ priv->storage_path = camel_session_get_storage_path (session, service, error); if (!priv->storage_path) return FALSE; /*store summary*/ path = g_alloca (strlen (priv->storage_path) + 32); sprintf (path, "%s/.summary", priv->storage_path); groupwise_store->summary = camel_groupwise_store_summary_new (); camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path); camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary); camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary); /*host and user*/ priv->server_name = g_strdup (url->host); priv->user = g_strdup (url->user); /*base url*/ priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH) ); /*soap port*/ property_value = camel_url_get_param (url, "soap_port"); if (property_value == NULL) priv->port = g_strdup ("7191"); else if (strlen (property_value) == 0) priv->port = g_strdup ("7191"); else priv->port = g_strdup (property_value); /*filter*/ if (camel_url_get_param (url, "filter")) store->flags |= CAMEL_STORE_FILTER_INBOX; /*Hash Table*/ priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /*ssl*/ priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl")); store->flags &= ~CAMEL_STORE_VJUNK; store->flags &= ~CAMEL_STORE_VTRASH; return TRUE; }
static void groupwise_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) { CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service); CamelStore *store = CAMEL_STORE (service); const char *property_value; CamelGroupwiseStorePrivate *priv = groupwise_store->priv; char *path = NULL; d(printf ("\nin groupwise store constrcut\n")); CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex); if (camel_exception_is_set (ex)) return; if (!(url->host || url->user)) { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Host or user not available in url")); } /*XXX: The number 3 assigned to the list_loaded variable denotes * the number of times the get_folder_info is called during startup. * We are just trying to minimize the call. * This is a dirty hack. But it *WORKS* */ groupwise_store->list_loaded = 3; /*storage path*/ priv->storage_path = camel_session_get_storage_path (session, service, ex); if (!priv->storage_path) return; /*store summary*/ path = g_alloca (strlen (priv->storage_path) + 32); sprintf (path, "%s/.summary", priv->storage_path); groupwise_store->summary = camel_groupwise_store_summary_new (); camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path); camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary); camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary); /*host and user*/ priv->server_name = g_strdup (url->host); priv->user = g_strdup (url->user); /*base url*/ priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH) ); /*soap port*/ property_value = camel_url_get_param (url, "soap_port"); if (property_value == NULL) priv->port = g_strdup ("7191"); else if(strlen(property_value) == 0) priv->port = g_strdup ("7191"); else priv->port = g_strdup (property_value); /*filter*/ if (camel_url_get_param (url, "filter")) store->flags |= CAMEL_STORE_FILTER_INBOX; /*Hash Table*/ priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /*ssl*/ priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl")); store->flags &= ~CAMEL_STORE_VJUNK; store->flags &= ~CAMEL_STORE_VTRASH; }
static gboolean connect_to_server (CamelService *service, GCancellable *cancellable, GError **error) { CamelPOP3Store *store = CAMEL_POP3_STORE (service); CamelNetworkSettings *network_settings; CamelNetworkSecurityMethod method; CamelSettings *settings; CamelStream *tcp_stream; CamelPOP3Engine *pop3_engine = NULL; CamelPOP3Command *pc; gboolean disable_extensions; gboolean success = TRUE; gchar *host; guint32 flags = 0; gint ret; GError *local_error = NULL; settings = camel_service_ref_settings (service); network_settings = CAMEL_NETWORK_SETTINGS (settings); host = camel_network_settings_dup_host (network_settings); method = camel_network_settings_get_security_method (network_settings); disable_extensions = camel_pop3_settings_get_disable_extensions ( CAMEL_POP3_SETTINGS (settings)); g_object_unref (settings); tcp_stream = camel_network_service_connect_sync ( CAMEL_NETWORK_SERVICE (service), cancellable, error); if (tcp_stream == NULL) { success = FALSE; goto exit; } /* parent class connect initialization */ if (CAMEL_SERVICE_CLASS (camel_pop3_store_parent_class)-> connect_sync (service, cancellable, error) == FALSE) { g_object_unref (tcp_stream); success = FALSE; goto exit; } if (disable_extensions) flags |= CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS; if (!(pop3_engine = camel_pop3_engine_new (tcp_stream, flags, cancellable, &local_error)) || local_error != NULL) { if (local_error) g_propagate_error (error, local_error); else g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Failed to read a valid greeting from POP server %s"), host); g_object_unref (tcp_stream); success = FALSE; goto exit; } if (method != CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT) { g_object_unref (tcp_stream); goto exit; } if (!(pop3_engine->capa & CAMEL_POP3_CAP_STLS)) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Failed to connect to POP server %s in secure mode: %s"), host, _("STLS not supported by server")); goto stls_exception; } pc = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, error, "STLS\r\n"); while (camel_pop3_engine_iterate (pop3_engine, NULL, cancellable, NULL) > 0) ; ret = pc->state == CAMEL_POP3_COMMAND_OK; camel_pop3_engine_command_free (pop3_engine, pc); if (ret == FALSE) { gchar *tmp; tmp = get_valid_utf8_error ((gchar *) pop3_engine->line); g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, /* Translators: Last %s is an optional * explanation beginning with ": " separator. */ _("Failed to connect to POP server %s in secure mode%s"), host, (tmp != NULL) ? tmp : ""); g_free (tmp); goto stls_exception; } /* Okay, now toggle SSL/TLS mode */ ret = camel_tcp_stream_ssl_enable_ssl ( CAMEL_TCP_STREAM_SSL (tcp_stream), cancellable, error); if (ret == -1) { g_prefix_error ( error, _("Failed to connect to POP server %s in secure mode: "), host); goto stls_exception; } g_object_unref (tcp_stream); /* rfc2595, section 4 states that after a successful STLS * command, the client MUST discard prior CAPA responses */ if (!camel_pop3_engine_reget_capabilities (pop3_engine, cancellable, error)) goto exception; goto exit; stls_exception: /* As soon as we send a STLS command, all hope * is lost of a clean QUIT if problems arise. */ /* if (clean_quit) { / * try to disconnect cleanly * / pc = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, NULL, "QUIT\r\n"); while (camel_pop3_engine_iterate (pop3_engine, NULL, cancellable, NULL) > 0) ; camel_pop3_engine_command_free (pop3_engine, pc); }*/ exception: g_object_unref (tcp_stream); g_clear_object (&pop3_engine); success = FALSE; exit: g_free (host); g_mutex_lock (&store->priv->property_lock); if (pop3_engine != NULL) store->priv->engine = g_object_ref (pop3_engine); g_mutex_unlock (&store->priv->property_lock); g_clear_object (&pop3_engine); return success; }
static gboolean smtp_transport_connect_sync (CamelService *service, GCancellable *cancellable, GError **error) { CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service); CamelNetworkSettings *network_settings; CamelSettings *settings; gchar *host; gchar *mechanism; gboolean auth_required; gboolean success = TRUE; /* Chain up to parent's method. */ if (!CAMEL_SERVICE_CLASS (camel_smtp_transport_parent_class)->connect_sync (service, cancellable, error)) return FALSE; smtp_debug_print_server_name (service, "Connecting to"); settings = camel_service_ref_settings (service); network_settings = CAMEL_NETWORK_SETTINGS (settings); host = camel_network_settings_dup_host (network_settings); mechanism = camel_network_settings_dup_auth_mechanism (network_settings); g_object_unref (settings); /* We (probably) need to check popb4smtp before we connect ... */ if (g_strcmp0 (mechanism, "POPB4SMTP") == 0) { GByteArray *chal; CamelSasl *sasl; sasl = camel_sasl_new ("smtp", "POPB4SMTP", service); chal = camel_sasl_challenge_sync (sasl, NULL, cancellable, error); if (chal != NULL) g_byte_array_free (chal, TRUE); if (camel_sasl_get_authenticated (sasl)) success = connect_to_server ( service, cancellable, error); else success = FALSE; g_object_unref (sasl); goto exit; } success = connect_to_server (service, cancellable, error); if (!success) return FALSE; /* check to see if AUTH is required, if so...then AUTH ourselves */ auth_required = (mechanism != NULL) && (transport->authtypes != NULL) && (g_hash_table_size (transport->authtypes) > 0) && (transport->flags & CAMEL_SMTP_TRANSPORT_IS_ESMTP); if (auth_required) { CamelSession *session; session = camel_service_ref_session (service); if (g_hash_table_lookup (transport->authtypes, mechanism)) { success = camel_session_authenticate_sync ( session, service, mechanism, cancellable, error); } else { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE, _("SMTP server %s does not support %s " "authentication"), host, mechanism); success = FALSE; } g_object_unref (session); if (!success) transport->connected = FALSE; } exit: g_free (host); g_free (mechanism); return success; }
static gboolean connect_to_server (CamelService *service, GCancellable *cancellable, GError **error) { CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service); CamelNetworkSettings *network_settings; CamelNetworkSecurityMethod method; CamelSettings *settings; CamelStream *stream; GIOStream *base_stream; GIOStream *tls_stream; gchar *respbuf = NULL; gboolean success = TRUE; gchar *host; if (!CAMEL_SERVICE_CLASS (camel_smtp_transport_parent_class)-> connect_sync (service, cancellable, error)) return FALSE; /* set some smtp transport defaults */ transport->flags = 0; transport->authtypes = NULL; settings = camel_service_ref_settings (service); network_settings = CAMEL_NETWORK_SETTINGS (settings); host = camel_network_settings_dup_host (network_settings); method = camel_network_settings_get_security_method (network_settings); g_object_unref (settings); base_stream = camel_network_service_connect_sync ( CAMEL_NETWORK_SERVICE (service), cancellable, error); if (base_stream != NULL) { /* get the localaddr - needed later by smtp_helo */ transport->local_address = g_socket_connection_get_local_address ( G_SOCKET_CONNECTION (base_stream), NULL); stream = camel_stream_new (base_stream); g_object_unref (base_stream); } else { success = FALSE; goto exit; } transport->connected = TRUE; transport->ostream = stream; transport->istream = camel_stream_buffer_new ( stream, CAMEL_STREAM_BUFFER_READ); /* Read the greeting, note whether the server is ESMTP or not. */ do { /* Check for "220" */ g_free (respbuf); respbuf = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER (transport->istream), cancellable, error); d (fprintf (stderr, "[SMTP] received: %s\n", respbuf ? respbuf : "(null)")); if (respbuf == NULL) { g_prefix_error (error, _("Welcome response error: ")); transport->connected = FALSE; success = FALSE; goto exit; } if (strncmp (respbuf, "220", 3)) { smtp_set_error ( transport, respbuf, cancellable, error); g_prefix_error (error, _("Welcome response error: ")); g_free (respbuf); success = FALSE; goto exit; } } while (*(respbuf+3) == '-'); /* if we got "220-" then loop again */ g_free (respbuf); /* Try sending EHLO */ transport->flags |= CAMEL_SMTP_TRANSPORT_IS_ESMTP; if (!smtp_helo (transport, cancellable, error)) { if (!transport->connected) { success = FALSE; goto exit; } /* Fall back to HELO */ g_clear_error (error); transport->flags &= ~CAMEL_SMTP_TRANSPORT_IS_ESMTP; if (!smtp_helo (transport, cancellable, error)) { success = FALSE; goto exit; } } /* Clear any EHLO/HELO exception and assume that * any SMTP errors encountered were non-fatal. */ g_clear_error (error); if (method != CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT) goto exit; /* we're done */ if (!(transport->flags & CAMEL_SMTP_TRANSPORT_STARTTLS)) { g_set_error ( error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Failed to connect to SMTP server %s in secure mode: %s"), host, _("STARTTLS not supported")); success = FALSE; goto exit; } d (fprintf (stderr, "[SMTP] sending: STARTTLS\r\n")); if (camel_stream_write ( stream, "STARTTLS\r\n", 10, cancellable, error) == -1) { g_prefix_error (error, _("STARTTLS command failed: ")); success = FALSE; goto exit; } respbuf = NULL; do { /* Check for "220 Ready for TLS" */ g_free (respbuf); respbuf = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER (transport->istream), cancellable, error); d (fprintf (stderr, "[SMTP] received: %s\n", respbuf ? respbuf : "(null)")); if (respbuf == NULL) { g_prefix_error (error, _("STARTTLS command failed: ")); transport->connected = FALSE; success = FALSE; goto exit; } if (strncmp (respbuf, "220", 3) != 0) { smtp_set_error ( transport, respbuf, cancellable, error); g_prefix_error (error, _("STARTTLS command failed: ")); g_free (respbuf); success = FALSE; goto exit; } } while (*(respbuf+3) == '-'); /* if we got "220-" then loop again */ /* Okay, now toggle SSL/TLS mode */ base_stream = camel_stream_ref_base_stream (stream); tls_stream = camel_network_service_starttls ( CAMEL_NETWORK_SERVICE (service), base_stream, error); g_object_unref (base_stream); if (tls_stream != NULL) { camel_stream_set_base_stream (stream, tls_stream); g_object_unref (tls_stream); } else { g_prefix_error ( error, _("Failed to connect to SMTP server %s in secure mode: "), host); success = FALSE; goto exit; } /* We are supposed to re-EHLO after a successful STARTTLS to * re-fetch any supported extensions. */ if (!smtp_helo (transport, cancellable, error)) { success = FALSE; } exit: g_free (host); if (!success) { transport->connected = FALSE; g_clear_object (&transport->istream); g_clear_object (&transport->ostream); } return success; }