diff options
author | Dan Winship <danw@src.gnome.org> | 2001-03-02 06:23:23 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-03-02 06:23:23 +0800 |
commit | 61a496ffcad857b0dac176861206c4a98edc1620 (patch) | |
tree | 7c82b6f1f675b9baee5b06bd1b7406663e771b74 /camel/camel-sasl-plain.c | |
parent | 63a09dc65bc9f54ec389cabb99c848ce56ef2fbc (diff) | |
download | gsoc2013-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-plain.c')
-rw-r--r-- | camel/camel-sasl-plain.c | 92 |
1 files changed, 22 insertions, 70 deletions
diff --git a/camel/camel-sasl-plain.c b/camel/camel-sasl-plain.c index 6b7a4de2bc..e4e4612dc8 100644 --- a/camel/camel-sasl-plain.c +++ b/camel/camel-sasl-plain.c @@ -22,6 +22,7 @@ #include <config.h> #include "camel-sasl-plain.h" +#include "camel-service.h" #include <string.h> static CamelSaslClass *parent_class = NULL; @@ -29,16 +30,7 @@ static CamelSaslClass *parent_class = NULL; /* Returns the class for a CamelSaslPlain */ #define CSP_CLASS(so) CAMEL_SASL_PLAIN_CLASS (CAMEL_OBJECT_GET_CLASS (so)) -static GByteArray *plain_challenge (CamelSasl *sasl, const char *token, CamelException *ex); - -enum { - STATE_LOGIN, - STATE_FINAL -}; - -struct _CamelSaslPlainPrivate { - int state; -}; +static GByteArray *plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex); static void camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class) @@ -51,26 +43,6 @@ camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class) camel_sasl_class->challenge = plain_challenge; } -static void -camel_sasl_plain_init (gpointer object, gpointer klass) -{ - CamelSaslPlain *sasl_plain = CAMEL_SASL_PLAIN (object); - - sasl_plain->priv = g_new0 (struct _CamelSaslPlainPrivate, 1); -} - -static void -camel_sasl_plain_finalize (CamelObject *object) -{ - CamelSaslPlain *sasl = CAMEL_SASL_PLAIN (object); - - g_free (sasl->login); - g_free (sasl->auth_id); - g_free (sasl->passwd); - g_free (sasl->priv); -} - - CamelType camel_sasl_plain_get_type (void) { @@ -83,55 +55,35 @@ camel_sasl_plain_get_type (void) sizeof (CamelSaslPlainClass), (CamelObjectClassInitFunc) camel_sasl_plain_class_init, NULL, - (CamelObjectInitFunc) camel_sasl_plain_init, - (CamelObjectFinalizeFunc) camel_sasl_plain_finalize); + NULL, + NULL); } return type; } -CamelSasl * -camel_sasl_plain_new (const char *login, const char *auth_id, const char *passwd) -{ - CamelSaslPlain *sasl_plain; - - if (!auth_id) return NULL; - if (!passwd) return NULL; - - sasl_plain = CAMEL_SASL_PLAIN (camel_object_new (camel_sasl_plain_get_type ())); - sasl_plain->login = g_strdup (login); - sasl_plain->auth_id = g_strdup (auth_id); - sasl_plain->passwd = g_strdup (passwd); - - return CAMEL_SASL (sasl_plain); -} - static GByteArray * -plain_challenge (CamelSasl *sasl, const char *token, CamelException *ex) +plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex) { - CamelSaslPlain *sasl_plain = CAMEL_SASL_PLAIN (sasl); - struct _CamelSaslPlainPrivate *priv = sasl_plain->priv; GByteArray *buf = NULL; - - switch (priv->state) { - case STATE_LOGIN: - /* FIXME: make sure these are "UTF8-SAFE" */ - buf = g_byte_array_new (); - if (sasl_plain->login) - g_byte_array_append (buf, sasl_plain->login, strlen (sasl_plain->login)); - g_byte_array_append (buf, "", 1); - g_byte_array_append (buf, sasl_plain->auth_id, strlen (sasl_plain->auth_id)); - g_byte_array_append (buf, "", 1); - g_byte_array_append (buf, sasl_plain->passwd, strlen (sasl_plain->passwd)); - break; - case STATE_FINAL: - sasl->authenticated = TRUE; - break; - default: - break; + CamelURL *url = sasl->service->url; + + if (token) { + camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, + _("Authentication failed.")); + return NULL; } - - priv->state++; + + g_return_val_if_fail (url->passwd != NULL, NULL); + + /* FIXME: make sure these are "UTF8-SAFE" */ + buf = g_byte_array_new (); + g_byte_array_append (buf, "", 1); + g_byte_array_append (buf, url->user, strlen (url->user)); + g_byte_array_append (buf, "", 1); + g_byte_array_append (buf, url->passwd, strlen (url->passwd)); + + sasl->authenticated = TRUE; return buf; } |