New files to handle the LOGIN SASL mechanism.
2001-04-01 Jeffrey Stedfast <fejj@ximian.com> * camel-sasl-login.[c,h]: New files to handle the LOGIN SASL mechanism. * camel-sasl-plain.c: Removed the definition of camel_sasl_login_authtype. * camel-sasl.c (camel_sasl_new): Oops. I thought LOGIN was an alias to PLAIN. I was wrong. These two SASL objects have to be separate. * providers/smtp/camel-smtp-transport.c (smtp_auth): Updated to check for and use authmech->quick_login when available. svn path=/trunk/; revision=9088
This commit is contained in:

committed by
Jeffrey Stedfast

parent
1193763d9e
commit
b27a35eae5
@ -1,3 +1,18 @@
|
|||||||
|
2001-04-01 Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
|
||||||
|
* camel-sasl-login.[c,h]: New files to handle the LOGIN SASL
|
||||||
|
mechanism.
|
||||||
|
|
||||||
|
* camel-sasl-plain.c: Removed the definition of
|
||||||
|
camel_sasl_login_authtype.
|
||||||
|
|
||||||
|
* camel-sasl.c (camel_sasl_new): Oops. I thought LOGIN was an
|
||||||
|
alias to PLAIN. I was wrong. These two SASL objects have to be
|
||||||
|
separate.
|
||||||
|
|
||||||
|
* providers/smtp/camel-smtp-transport.c (smtp_auth): Updated to
|
||||||
|
check for and use authmech->quick_login when available.
|
||||||
|
|
||||||
2001-04-01 Jeffrey Stedfast <fejj@ximian.com>
|
2001-04-01 Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
|
||||||
* providers/pop3/camel-pop3-provider.c: Updated the authtypes here
|
* providers/pop3/camel-pop3-provider.c: Updated the authtypes here
|
||||||
|
@ -60,6 +60,7 @@ libcamel_la_SOURCES = \
|
|||||||
camel-sasl-cram-md5.c \
|
camel-sasl-cram-md5.c \
|
||||||
camel-sasl-digest-md5.c \
|
camel-sasl-digest-md5.c \
|
||||||
camel-sasl-kerberos4.c \
|
camel-sasl-kerberos4.c \
|
||||||
|
camel-sasl-login.c \
|
||||||
camel-sasl-plain.c \
|
camel-sasl-plain.c \
|
||||||
camel-search-private.c \
|
camel-search-private.c \
|
||||||
camel-seekable-stream.c \
|
camel-seekable-stream.c \
|
||||||
@ -131,6 +132,7 @@ libcamelinclude_HEADERS = \
|
|||||||
camel-sasl-cram-md5.h \
|
camel-sasl-cram-md5.h \
|
||||||
camel-sasl-digest-md5.h \
|
camel-sasl-digest-md5.h \
|
||||||
camel-sasl-kerberos4.h \
|
camel-sasl-kerberos4.h \
|
||||||
|
camel-sasl-login.h \
|
||||||
camel-sasl-plain.h \
|
camel-sasl-plain.h \
|
||||||
camel-seekable-stream.h \
|
camel-seekable-stream.h \
|
||||||
camel-seekable-substream.h \
|
camel-seekable-substream.h \
|
||||||
|
135
camel/camel-sasl-login.c
Normal file
135
camel/camel-sasl-login.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||||
|
/*
|
||||||
|
* Authors: Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
*
|
||||||
|
* Copyright 2001 Ximian, Inc. (www.ximian.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "camel-sasl-login.h"
|
||||||
|
#include "camel-service.h"
|
||||||
|
|
||||||
|
CamelServiceAuthType camel_sasl_login_authtype = {
|
||||||
|
N_("NT Login"),
|
||||||
|
|
||||||
|
N_("This option will connect to the server using a "
|
||||||
|
"simple password."),
|
||||||
|
|
||||||
|
"LOGIN",
|
||||||
|
TRUE,
|
||||||
|
TRUE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
LOGIN_USER,
|
||||||
|
LOGIN_PASSWD
|
||||||
|
};
|
||||||
|
|
||||||
|
static CamelSaslClass *parent_class = NULL;
|
||||||
|
|
||||||
|
/* Returns the class for a CamelSaslLogin */
|
||||||
|
#define CSP_CLASS(so) CAMEL_SASL_LOGIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
|
||||||
|
|
||||||
|
static GByteArray *login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
|
||||||
|
|
||||||
|
struct _CamelSaslLoginPrivate {
|
||||||
|
int state;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
camel_sasl_login_class_init (CamelSaslLoginClass *camel_sasl_login_class)
|
||||||
|
{
|
||||||
|
CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_login_class);
|
||||||
|
|
||||||
|
parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
|
||||||
|
|
||||||
|
/* virtual method overload */
|
||||||
|
camel_sasl_class->challenge = login_challenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
camel_sasl_login_init (gpointer object, gpointer klass)
|
||||||
|
{
|
||||||
|
CamelSaslLogin *sasl_login = CAMEL_SASL_LOGIN (object);
|
||||||
|
|
||||||
|
sasl_login->priv = g_new0 (struct _CamelSaslLoginPrivate, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
camel_sasl_login_finalize (CamelObject *object)
|
||||||
|
{
|
||||||
|
CamelSaslLogin *sasl = CAMEL_SASL_LOGIN (object);
|
||||||
|
|
||||||
|
g_free (sasl->priv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CamelType
|
||||||
|
camel_sasl_login_get_type (void)
|
||||||
|
{
|
||||||
|
static CamelType type = CAMEL_INVALID_TYPE;
|
||||||
|
|
||||||
|
if (type == CAMEL_INVALID_TYPE) {
|
||||||
|
type = camel_type_register (camel_sasl_get_type (),
|
||||||
|
"CamelSaslLogin",
|
||||||
|
sizeof (CamelSaslLogin),
|
||||||
|
sizeof (CamelSaslLoginClass),
|
||||||
|
(CamelObjectClassInitFunc) camel_sasl_login_class_init,
|
||||||
|
NULL,
|
||||||
|
(CamelObjectInitFunc) camel_sasl_login_init,
|
||||||
|
(CamelObjectFinalizeFunc) camel_sasl_login_finalize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GByteArray *
|
||||||
|
login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
|
||||||
|
{
|
||||||
|
struct _CamelSaslLoginPrivate *priv = CAMEL_SASL_LOGIN (sasl)->priv;
|
||||||
|
GByteArray *buf = NULL;
|
||||||
|
CamelURL *url = sasl->service->url;
|
||||||
|
|
||||||
|
g_return_val_if_fail (url->passwd != NULL, NULL);
|
||||||
|
|
||||||
|
switch (priv->state) {
|
||||||
|
case LOGIN_USER:
|
||||||
|
buf = g_byte_array_new ();
|
||||||
|
g_byte_array_append (buf, url->user, strlen (url->user));
|
||||||
|
break;
|
||||||
|
case LOGIN_PASSWD:
|
||||||
|
buf = g_byte_array_new ();
|
||||||
|
g_byte_array_append (buf, url->passwd, strlen (url->passwd));
|
||||||
|
|
||||||
|
sasl->authenticated = TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!camel_exception_is_set (ex)) {
|
||||||
|
camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
|
||||||
|
_("Unknown authentication state."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->state++;
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
61
camel/camel-sasl-login.h
Normal file
61
camel/camel-sasl-login.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||||
|
/*
|
||||||
|
* Authors: Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
*
|
||||||
|
* Copyright 2001 Ximian, Inc. (www.ximian.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CAMEL_SASL_LOGIN_H
|
||||||
|
#define CAMEL_SASL_LOGIN_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#pragma }
|
||||||
|
#endif /* __cplusplus }*/
|
||||||
|
|
||||||
|
#include <camel/camel-sasl.h>
|
||||||
|
|
||||||
|
#define CAMEL_SASL_LOGIN_TYPE (camel_sasl_login_get_type ())
|
||||||
|
#define CAMEL_SASL_LOGIN(obj) (CAMEL_CHECK_CAST((obj), CAMEL_SASL_LOGIN_TYPE, CamelSaslLogin))
|
||||||
|
#define CAMEL_SASL_LOGIN_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_LOGIN_TYPE, CamelSaslLoginClass))
|
||||||
|
#define CAMEL_IS_SASL_LOGIN(o) (CAMEL_CHECK_TYPE((o), CAMEL_SASL_LOGIN_TYPE))
|
||||||
|
|
||||||
|
typedef struct _CamelSaslLogin {
|
||||||
|
CamelSasl parent_object;
|
||||||
|
|
||||||
|
struct _CamelSaslLoginPrivate *priv;
|
||||||
|
|
||||||
|
} CamelSaslLogin;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _CamelSaslLoginClass {
|
||||||
|
CamelSaslClass parent_class;
|
||||||
|
|
||||||
|
} CamelSaslLoginClass;
|
||||||
|
|
||||||
|
|
||||||
|
/* Standard Camel function */
|
||||||
|
CamelType camel_sasl_login_get_type (void);
|
||||||
|
|
||||||
|
extern CamelServiceAuthType camel_sasl_login_authtype;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* CAMEL_SASL_LOGIN_H */
|
@ -39,17 +39,6 @@ CamelServiceAuthType camel_sasl_plain_authtype = {
|
|||||||
FALSE
|
FALSE
|
||||||
};
|
};
|
||||||
|
|
||||||
CamelServiceAuthType camel_sasl_login_authtype = {
|
|
||||||
N_("NT Login"),
|
|
||||||
|
|
||||||
N_("This option will connect to the server using a "
|
|
||||||
"simple password."),
|
|
||||||
|
|
||||||
"LOGIN",
|
|
||||||
TRUE,
|
|
||||||
TRUE
|
|
||||||
};
|
|
||||||
|
|
||||||
static CamelSaslClass *parent_class = NULL;
|
static CamelSaslClass *parent_class = NULL;
|
||||||
|
|
||||||
/* Returns the class for a CamelSaslPlain */
|
/* Returns the class for a CamelSaslPlain */
|
||||||
|
@ -52,8 +52,6 @@ CamelType camel_sasl_plain_get_type (void);
|
|||||||
|
|
||||||
extern CamelServiceAuthType camel_sasl_plain_authtype;
|
extern CamelServiceAuthType camel_sasl_plain_authtype;
|
||||||
|
|
||||||
extern CamelServiceAuthType camel_sasl_login_authtype;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "camel-sasl-cram-md5.h"
|
#include "camel-sasl-cram-md5.h"
|
||||||
#include "camel-sasl-digest-md5.h"
|
#include "camel-sasl-digest-md5.h"
|
||||||
#include "camel-sasl-kerberos4.h"
|
#include "camel-sasl-kerberos4.h"
|
||||||
|
#include "camel-sasl-login.h"
|
||||||
#include "camel-sasl-plain.h"
|
#include "camel-sasl-plain.h"
|
||||||
|
|
||||||
static CamelObjectClass *parent_class = NULL;
|
static CamelObjectClass *parent_class = NULL;
|
||||||
@ -191,8 +192,10 @@ camel_sasl_new (const char *service_name, const char *mechanism, CamelService *s
|
|||||||
else if (!strcmp (mechanism, "KERBEROS_V4"))
|
else if (!strcmp (mechanism, "KERBEROS_V4"))
|
||||||
sasl = (CamelSasl *)camel_object_new (CAMEL_SASL_KERBEROS4_TYPE);
|
sasl = (CamelSasl *)camel_object_new (CAMEL_SASL_KERBEROS4_TYPE);
|
||||||
#endif
|
#endif
|
||||||
else if (!strcmp (mechanism, "PLAIN") || !strcmp (mechanism, "LOGIN"))
|
else if (!strcmp (mechanism, "PLAIN"))
|
||||||
sasl = (CamelSasl *)camel_object_new (CAMEL_SASL_PLAIN_TYPE);
|
sasl = (CamelSasl *)camel_object_new (CAMEL_SASL_PLAIN_TYPE);
|
||||||
|
else if (!strcmp (mechanism, "LOGIN"))
|
||||||
|
sasl = (CamelSasl *)camel_object_new (CAMEL_SASL_LOGIN_TYPE);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -696,18 +696,39 @@ smtp_helo (CamelSmtpTransport *transport, CamelException *ex)
|
|||||||
static gboolean
|
static gboolean
|
||||||
smtp_auth (CamelSmtpTransport *transport, const char *mech, CamelException *ex)
|
smtp_auth (CamelSmtpTransport *transport, const char *mech, CamelException *ex)
|
||||||
{
|
{
|
||||||
|
CamelServiceAuthType *authtype;
|
||||||
gchar *cmdbuf, *respbuf = NULL;
|
gchar *cmdbuf, *respbuf = NULL;
|
||||||
CamelSasl *sasl;
|
CamelSasl *sasl;
|
||||||
|
|
||||||
|
sasl = camel_sasl_new ("smtp", mech, CAMEL_SERVICE (transport));
|
||||||
|
if (!sasl) {
|
||||||
|
g_free (respbuf);
|
||||||
|
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
|
||||||
|
_("Error creating SASL authentication object."));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the authtype object so we know if we can challenge the server */
|
||||||
|
authtype = camel_sasl_authtype (mech);
|
||||||
|
|
||||||
/* tell the server we want to authenticate... */
|
/* tell the server we want to authenticate... */
|
||||||
|
if (authtype && authtype->quick_login) {
|
||||||
|
/* cool, we can challenge the server in our initial request */
|
||||||
|
char *challenge;
|
||||||
|
|
||||||
|
challenge = camel_sasl_challenge_base64 (sasl, NULL, ex);
|
||||||
|
cmdbuf = g_strdup_printf ("AUTH %s %s\r\n", mech, challenge);
|
||||||
|
g_free (challenge);
|
||||||
|
} else
|
||||||
cmdbuf = g_strdup_printf ("AUTH %s\r\n", mech);
|
cmdbuf = g_strdup_printf ("AUTH %s\r\n", mech);
|
||||||
|
|
||||||
d(fprintf (stderr, "sending : %s", cmdbuf));
|
d(fprintf (stderr, "sending : %s", cmdbuf));
|
||||||
if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) {
|
if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) {
|
||||||
g_free (cmdbuf);
|
g_free (cmdbuf);
|
||||||
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
|
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
|
||||||
_("AUTH request timed out: %s"),
|
_("AUTH request timed out: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return FALSE;
|
goto lose;
|
||||||
}
|
}
|
||||||
g_free (cmdbuf);
|
g_free (cmdbuf);
|
||||||
|
|
||||||
@ -719,13 +740,7 @@ smtp_auth (CamelSmtpTransport *transport, const char *mech, CamelException *ex)
|
|||||||
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
|
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
|
||||||
_("AUTH request timed out: %s"),
|
_("AUTH request timed out: %s"),
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return FALSE;
|
goto lose;
|
||||||
}
|
|
||||||
|
|
||||||
sasl = camel_sasl_new ("smtp", mech, CAMEL_SERVICE (transport));
|
|
||||||
if (!sasl) {
|
|
||||||
g_free (respbuf);
|
|
||||||
goto break_and_lose;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!camel_sasl_authenticated (sasl)) {
|
while (!camel_sasl_authenticated (sasl)) {
|
||||||
|
Reference in New Issue
Block a user