aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorChris Toshok <toshok@helixcode.com>2000-10-05 04:36:10 +0800
committerChris Toshok <toshok@src.gnome.org>2000-10-05 04:36:10 +0800
commitaedfd03572bcbb2183b6bac4b429cc245aea45f1 (patch)
treeba0573dd720e5992a8486fe30893083ebf8a08c1 /camel
parent032dceebc5eb1bb8ca07141a54d83c765f28d3b6 (diff)
downloadgsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar.gz
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar.bz2
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar.lz
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar.xz
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.tar.zst
gsoc2013-evolution-aedfd03572bcbb2183b6bac4b429cc245aea45f1.zip
borrow some code from the imap provider to query the user for their
2000-10-04 Chris Toshok <toshok@helixcode.com> * providers/nntp/camel-nntp-auth.c (camel_nntp_auth_authenticate): borrow some code from the imap provider to query the user for their password, and pass the user/passwd to nntp. be extra paranoid and zero out the password before freeing it. * providers/nntp/camel-nntp-store.c (camel_nntp_store_init): add ALLOW_USER/ALLOW_PASSWORD/ALLOW_AUTH to the url flags. (nntp_store_query_auth_types_generic): return our list of auth_types. (nntp_store_query_auth_types_connected): broken, return same as in query_auth_types_generic. svn path=/trunk/; revision=5716
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog14
-rw-r--r--camel/providers/nntp/camel-nntp-auth.c42
-rw-r--r--camel/providers/nntp/camel-nntp-store.c97
3 files changed, 123 insertions, 30 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index e04372d09e..3a2b1113ea 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,17 @@
+2000-10-04 Chris Toshok <toshok@helixcode.com>
+
+ * providers/nntp/camel-nntp-auth.c (camel_nntp_auth_authenticate):
+ borrow some code from the imap provider to query the user for
+ their password, and pass the user/passwd to nntp. be extra
+ paranoid and zero out the password before freeing it.
+
+ * providers/nntp/camel-nntp-store.c (camel_nntp_store_init): add
+ ALLOW_USER/ALLOW_PASSWORD/ALLOW_AUTH to the url flags.
+ (nntp_store_query_auth_types_generic): return our list of
+ auth_types.
+ (nntp_store_query_auth_types_connected): broken, return same as in
+ query_auth_types_generic.
+
2000-10-04 Dan Winship <danw@helixcode.com>
* providers/imap/camel-imap-store.c (imap_connect): IMAP4
diff --git a/camel/providers/nntp/camel-nntp-auth.c b/camel/providers/nntp/camel-nntp-auth.c
index 2490329b81..1a7402a339 100644
--- a/camel/providers/nntp/camel-nntp-auth.c
+++ b/camel/providers/nntp/camel-nntp-auth.c
@@ -26,33 +26,65 @@
#include <camel-nntp-store.h>
#include <camel-nntp-resp-codes.h>
#include <camel-exception.h>
+#include <camel-session.h>
int
camel_nntp_auth_authenticate (CamelNNTPStore *store, CamelException *ex)
{
+ CamelService *service = CAMEL_SERVICE (store);
+ CamelSession *session = camel_service_get_session (service);
int resp;
+ if (!service->url->authmech && !service->url->passwd) {
+ gchar *prompt;
+
+ prompt = g_strdup_printf ("Please enter the NNTP password for %s@%s",
+ service->url->user, service->url->host);
+ service->url->passwd =
+ camel_session_query_authenticator (session,
+ CAMEL_AUTHENTICATOR_ASK, prompt,
+ TRUE, service, "password", ex);
+ g_free (prompt);
+
+ if (!service->url->passwd) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
+ "You didn\'t enter a password.");
+ resp = 666;
+ goto done;
+ }
+ }
+
/* first send username */
- resp = camel_nntp_command (store, ex, NULL, "AUTHINFO USER %s", "username"); /* XXX */
+ resp = camel_nntp_command (store, ex, NULL, "AUTHINFO USER %s", service->url->user);
if (resp == NNTP_AUTH_REJECTED) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
"Server rejected username");
- return resp;
+ goto done;
+
}
else if (resp != NNTP_AUTH_CONTINUE) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
"Failed to send username to server");
- return resp;
+ goto done;
}
/* then send the username if the server asks for it */
- resp = camel_nntp_command (store, ex, NULL, "AUTHINFO PASS %s", "password"); /* XXX */
+ resp = camel_nntp_command (store, ex, NULL, "AUTHINFO PASS %s", service->url->passwd);
+
if (resp == NNTP_AUTH_REJECTED) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
"Server rejected username/password");
- return resp;
+ goto done;
}
+ done:
+
+ if (service->url->passwd) {
+ /* let's be paranoid */
+ memset (service->url->passwd, 0, strlen (service->url->passwd));
+ g_free (service->url->passwd);
+ service->url->passwd = NULL;
+ }
return resp;
}
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 710e1d2e13..d51e3b2cf6 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -272,6 +272,33 @@ nntp_store_get_name (CamelService *service, gboolean brief)
return g_strdup_printf ("USENET news via %s", service->url->host);
}
+static CamelServiceAuthType password_authtype = {
+ "Password",
+
+ "This option will authenticate with the NNTP server using a "
+ "plaintext password.",
+
+ "",
+ TRUE
+};
+
+static GList *
+nntp_store_query_auth_types_generic (CamelService *service, CamelException *ex)
+{
+ GList *prev;
+
+ prev = CAMEL_SERVICE_CLASS (remote_store_class)->query_auth_types_generic (service, ex);
+ return g_list_prepend (prev, &password_authtype);
+}
+
+static GList *
+nntp_store_query_auth_types_connected (CamelService *service, CamelException *ex)
+{
+ g_warning ("nntp::query_auth_types_connected: not implemented. Defaulting.");
+ /* FIXME: use the classfunc instead of the local? */
+ return nntp_store_query_auth_types_generic (service, ex);
+}
+
static CamelFolder *
nntp_store_get_folder (CamelStore *store, const gchar *folder_name,
gboolean get_folder, CamelException *ex)
@@ -301,43 +328,58 @@ nntp_store_get_folder_info (CamelStore *store, const char *top,
gboolean fast, gboolean recursive,
CamelException *ex)
{
+ CamelURL *url = CAMEL_SERVICE (store)->url;
CamelNNTPStore *nntp_store = (CamelNNTPStore *)store;
GPtrArray *names;
- CamelFolderInfo *topfi, *last = NULL, *fi;
+ CamelFolderInfo *groups = NULL, *last = NULL, *fi;
int i;
+ /* if we haven't already read our .newsrc, read it now */
if (!nntp_store->newsrc)
+ nntp_store->newsrc =
+ camel_nntp_newsrc_read_for_server (CAMEL_SERVICE(store)->url->host);
+
+ if (!nntp_store->newsrc) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ "Unable to open or create .newsrc file for %s: %s",
+ CAMEL_SERVICE(store)->url->host,
+ strerror(errno));
return NULL;
+ }
- topfi = g_new0 (CamelFolderInfo, 1);
- topfi->name = g_strdup (top);
- topfi->full_name = g_strdup (top);
- if (*top)
- topfi->url = g_strdup_printf ("news:%s", top);
- /* FIXME: message_count if top != "" */
- topfi->message_count = topfi->unread_message_count = -1;
+ if (top == NULL) {
+ /* return the list of groups */
+ names = camel_nntp_newsrc_get_subscribed_group_names (nntp_store->newsrc);
+ for (i = 0; i < names->len; i++) {
+ fi = g_new0 (CamelFolderInfo, 1);
+ fi->name = g_strdup (names->pdata[i]);
+ fi->full_name = g_strdup (names->pdata[i]);
+ fi->url = g_strdup_printf ("news://%s/%s", url->host, (char *)names->pdata[i]);
+ /* FIXME */
+ fi->message_count = fi->unread_message_count = -1;
+
+ if (last)
+ last->sibling = fi;
+ else
+ groups = fi;
+ last = fi;
+ }
+ camel_nntp_newsrc_free_group_names (nntp_store->newsrc, names);
- if (!recursive || *top)
- return topfi;
+ return groups;
+ }
+ else {
+ /* getting a specific group */
- names = camel_nntp_newsrc_get_subscribed_group_names (nntp_store->newsrc);
- for (i = 0; i < names->len; i++) {
fi = g_new0 (CamelFolderInfo, 1);
- fi->name = g_strdup (names->pdata[i]);
- fi->full_name = g_strdup (names->pdata[i]);
- fi->url = g_strdup_printf ("news:%s", (char *)names->pdata[i]);
+ fi->name = g_strdup (top);
+ fi->full_name = g_strdup (top);
+ fi->url = g_strdup_printf ("news://%s/%s", url->host, top);
/* FIXME */
fi->message_count = fi->unread_message_count = -1;
- if (last)
- last->sibling = fi;
- else
- topfi->child = fi;
- last = fi;
+ return fi;
}
- camel_nntp_newsrc_free_group_names (nntp_store->newsrc, names);
-
- return topfi;
}
static char *
@@ -372,6 +414,8 @@ camel_nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class)
/* virtual method overload */
camel_service_class->connect = nntp_store_connect;
camel_service_class->disconnect = nntp_store_disconnect;
+ camel_service_class->query_auth_types_generic = nntp_store_query_auth_types_generic;
+ camel_service_class->query_auth_types_connected = nntp_store_query_auth_types_connected;
camel_service_class->get_name = nntp_store_get_name;
camel_store_class->get_folder = nntp_store_get_folder;
@@ -388,8 +432,11 @@ camel_nntp_store_init (gpointer object, gpointer klass)
CamelService *service = CAMEL_SERVICE (object);
CamelRemoteStore *remote_store = CAMEL_REMOTE_STORE (object);
- service->url_flags = CAMEL_SERVICE_URL_NEED_HOST;
- remote_store->default_port = 119;
+ service->url_flags = (CAMEL_SERVICE_URL_NEED_HOST
+ | CAMEL_SERVICE_URL_ALLOW_USER
+ | CAMEL_SERVICE_URL_ALLOW_PASSWORD
+ | CAMEL_SERVICE_URL_ALLOW_AUTH);
+ remote_store->default_port = NNTP_PORT;
}
CamelType