aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-sasl-anonymous.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-03-02 06:23:23 +0800
committerDan Winship <danw@src.gnome.org>2001-03-02 06:23:23 +0800
commit61a496ffcad857b0dac176861206c4a98edc1620 (patch)
tree7c82b6f1f675b9baee5b06bd1b7406663e771b74 /camel/camel-sasl-anonymous.c
parent63a09dc65bc9f54ec389cabb99c848ce56ef2fbc (diff)
downloadgsoc2013-evolution-61a496ffcad857b0dac176861206c4a98edc1620.tar.gz
gsoc2013-evolution-61a496ffcad857b0dac176861206c4a98edc1620.tar.zst
gsoc2013-evolution-61a496ffcad857b0dac176861206c4a98edc1620.zip
Take a GByteArray as input as well. Comment that you can pass %NULL for
* camel-sasl.c (camel_sasl_challenge): Take a GByteArray as input as well. Comment that you can pass %NULL for @token to get the initial auth data for mechanisms that are client-initiated. (camel_sasl_challenge_base64): Convenience function for protocols that use base64-encoded SASL. (camel_sasl_authenticated): Implement this... (it was prototyped already) (camel_sasl_new): Function to take a service name, a mechanism name, and a CamelService, and return a CamelSasl for it. (camel_sasl_authtype, camel_sasl_authtype_list): Functions to return CamelServiceAuthType information about SASL mechanisms, to allow providers to deal with them generically. * camel-sasl-anonymous.c, camel-sasl-plain.c: Update/simplify for CamelSasl changes. Both of these are single-round (client-initiated) mechanisms, so they don't need to keep state. (camel_sasl_plain_new): Removed; use camel_sasl_new instead. (Can't get rid of camel_sasl_anonymous_new though...) * camel-sasl-cram-md5.c: Update/simplify for CamelSasl changes. (camel_sasl_cram_md5_new): Removed; use camel_sasl_new instead. (cram_md5_challenge): Use md5_get_digest where possible, and various other minor simplifications. CRAM-MD5 only has a single round, so there's no need to keep track of state. This code is now tested (against Cyrus IMAPd) and known to work. * camel-sasl-kerberos4.h: Update/simplify for CamelSasl changes. Make only a single #ifdef HAVE_KRB4. Remove stuff from priv that isn't needed between rounds. (camel_sasl_kerberos4_new): Removed; use camel_sasl_new instead (krb4_challenge): Fix up the logic I broke in my previous "at least make it compile" fixes, update to match other changes, and remove IMAP-isms that shouldn't be in the generic code. This still isn't tested, because we're stuck behind a NAT right now... svn path=/trunk/; revision=8462
Diffstat (limited to 'camel/camel-sasl-anonymous.c')
-rw-r--r--camel/camel-sasl-anonymous.c100
1 files changed, 37 insertions, 63 deletions
diff --git a/camel/camel-sasl-anonymous.c b/camel/camel-sasl-anonymous.c
index ec9fe38f07..f6d7d4ec24 100644
--- a/camel/camel-sasl-anonymous.c
+++ b/camel/camel-sasl-anonymous.c
@@ -30,16 +30,7 @@ static CamelSaslClass *parent_class = NULL;
/* Returns the class for a CamelSaslAnonymous */
#define CSA_CLASS(so) CAMEL_SASL_ANONYMOUS_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-static GByteArray *anon_challenge (CamelSasl *sasl, const char *token, CamelException *ex);
-
-enum {
- STATE_AUTH,
- STATE_FINAL
-};
-
-struct _CamelSaslAnonymousPrivate {
- int state;
-};
+static GByteArray *anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
static void
camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *camel_sasl_anonymous_class)
@@ -53,20 +44,11 @@ camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *camel_sasl_anonymous_c
}
static void
-camel_sasl_anonymous_init (gpointer object, gpointer klass)
-{
- CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (object);
-
- sasl_anon->priv = g_new0 (struct _CamelSaslAnonymousPrivate, 1);
-}
-
-static void
camel_sasl_anonymous_finalize (CamelObject *object)
{
CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
g_free (sasl->trace_info);
- g_free (sasl->priv);
}
@@ -82,7 +64,7 @@ camel_sasl_anonymous_get_type (void)
sizeof (CamelSaslAnonymousClass),
(CamelObjectClassInitFunc) camel_sasl_anonymous_class_init,
NULL,
- (CamelObjectInitFunc) camel_sasl_anonymous_init,
+ NULL,
(CamelObjectFinalizeFunc) camel_sasl_anonymous_finalize);
}
@@ -104,60 +86,52 @@ camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const char *trace_info)
}
static GByteArray *
-anon_challenge (CamelSasl *sasl, const char *token, CamelException *ex)
+anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
{
CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
- struct _CamelSaslAnonymousPrivate *priv = sasl_anon->priv;
CamelInternetAddress *cia;
GByteArray *ret = NULL;
- char *buf = NULL;
-
- switch (priv->state) {
- case STATE_AUTH:
- switch (sasl_anon->type) {
- case CAMEL_SASL_ANON_TRACE_EMAIL:
- cia = camel_internet_address_new ();
- if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Invalid email address trace information:\n%s"),
- sasl_anon->trace_info);
- camel_object_unref (CAMEL_OBJECT (cia));
- return NULL;
- }
- camel_object_unref (CAMEL_OBJECT (cia));
- buf = sasl_anon->trace_info;
- break;
- case CAMEL_SASL_ANON_TRACE_OPAQUE:
- if (strchr (sasl_anon->trace_info, '@')) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Invalid opaque trace information:\n%s"),
- sasl_anon->trace_info);
- return NULL;
- }
- buf = sasl_anon->trace_info;
- break;
- case CAMEL_SASL_ANON_TRACE_EMPTY:
- buf = "";
- break;
- default:
+
+ if (token) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+ _("Authentication failed."));
+ return NULL;
+ }
+
+ switch (sasl_anon->type) {
+ case CAMEL_SASL_ANON_TRACE_EMAIL:
+ cia = camel_internet_address_new ();
+ if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Invalid trace information:\n%s"),
+ _("Invalid email address trace information:\n%s"),
sasl_anon->trace_info);
+ camel_object_unref (CAMEL_OBJECT (cia));
return NULL;
}
+ camel_object_unref (CAMEL_OBJECT (cia));
+ ret = g_byte_array_new ();
+ g_byte_array_append (ret, sasl_anon->trace_info, strlen (sasl_anon->trace_info));
break;
- case STATE_FINAL:
- sasl->authenticated = TRUE;
- default:
+ case CAMEL_SASL_ANON_TRACE_OPAQUE:
+ if (strchr (sasl_anon->trace_info, '@')) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+ _("Invalid opaque trace information:\n%s"),
+ sasl_anon->trace_info);
+ return NULL;
+ }
+ ret = g_byte_array_new ();
+ g_byte_array_append (ret, sasl_anon->trace_info, strlen (sasl_anon->trace_info));
break;
- }
-
- priv->state++;
-
- if (buf) {
+ case CAMEL_SASL_ANON_TRACE_EMPTY:
ret = g_byte_array_new ();
- g_byte_array_append (ret, buf, strlen (buf));
+ break;
+ default:
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+ _("Invalid trace information:\n%s"),
+ sasl_anon->trace_info);
+ return NULL;
}
-
+
+ sasl->authenticated = TRUE;
return ret;
}