aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/pas
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2003-01-10 09:55:27 +0800
committerChris Toshok <toshok@src.gnome.org>2003-01-10 09:55:27 +0800
commit2a174936f49118ce60e76b0debe4600fdbb4bc33 (patch)
tree7bce87f3a0a6ca53f04d5c63f6ed2aa4aece5fea /addressbook/backend/pas
parent50a352b3670e6b8e8d29a9559d2442fcf0b62c5e (diff)
downloadgsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar.gz
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar.bz2
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar.lz
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar.xz
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.tar.zst
gsoc2013-evolution-2a174936f49118ce60e76b0debe4600fdbb4bc33.zip
build up the list of supported auth_methods.
2003-01-09 Chris Toshok <toshok@ximian.com> * backend/pas/pas-backend-ldap.c (query_ldap_root_dse): build up the list of supported auth_methods. (pas_backend_ldap_process_get_supported_auth_methods): respond with the list of auth methods we've built up. (pas_backend_ldap_dispose): unref the auth_method list. (pas_backend_ldap_class_init): hook up pas_backend_ldap_process_get_supported_auth_methods. * backend/pas/pas-backend.c (pas_backend_get_supported_auth_methods): new function. (process_client_requests): add clause for GetSupportedAuthMethods. * backend/pas/pas-backend.h: add prototype for pas_backend_get_supported_auth_methods, and add it to the class vtable. * backend/pas/pas-book.h: add GetSupportedAuthMethods enum member and PASGetSupportedAuthMethodsRequest. and add prototype for pas_book_respond_get_supported_auth_methods. * backend/pas/pas-book.c (pas_book_queue_get_supported_auth_methods): new function. (impl_GNOME_Evolution_Addressbook_Book_getSupportedAuthMethods): new function. (pas_book_respond_get_supported_auth_methods): new function. (pas_book_free_request): add clause for GetSupportedAuthMethods. (pas_book_class_init): hook up getSupportedAuthMethods. * backend/ebook/e-book-listener.c (e_book_listener_queue_get_supported_fields_response): fields -> list. (e_book_listener_queue_get_supported_auth_methods_response): new function. (impl_BookListener_response_get_supported_auth_methods): new function. (e_book_listener_class_init): hook up epv->notifySupportedAuthMethods. * backend/ebook/e-book-listener.h: add GetSupportedAuthMethodsResponse enum member, and change the field name from "fields" to list (and use it for both GetSupportedFields and GetSupportedAuthMethods) * backend/ebook/e-book.c (e_book_get_supported_auth_methods): new function. (e_book_do_response_get_supported_auth_methods): new function. * backend/ebook/e-book.h: add prototype for e_book_get_supported_auth_methods. * backend/idl/addressbook.idl: add getSupportedAuthMethods IDL call. svn path=/trunk/; revision=19386
Diffstat (limited to 'addressbook/backend/pas')
-rw-r--r--addressbook/backend/pas/pas-backend-ldap.c136
-rw-r--r--addressbook/backend/pas/pas-backend.c18
-rw-r--r--addressbook/backend/pas/pas-backend.h4
-rw-r--r--addressbook/backend/pas/pas-book.c85
-rw-r--r--addressbook/backend/pas/pas-book.h37
5 files changed, 220 insertions, 60 deletions
diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c
index 353879e6e1..3ef2bcb4dd 100644
--- a/addressbook/backend/pas/pas-backend-ldap.c
+++ b/addressbook/backend/pas/pas-backend-ldap.c
@@ -44,6 +44,9 @@
#include <stdlib.h>
+/* this is broken currently, don't enable it */
+/*#define ENABLE_SASL_BINDS*/
+
typedef enum {
PAS_BACKEND_LDAP_TLS_NO,
PAS_BACKEND_LDAP_TLS_ALWAYS,
@@ -109,6 +112,7 @@ struct _PASBackendLDAPPrivate {
LDAP *ldap;
EList *supported_fields;
+ EList *supported_auth_methods;
/* whether or not there's support for the objectclass we need
to store all our additional fields */
@@ -585,8 +589,25 @@ query_ldap_root_dse (PASBackendLDAP *bl)
values = ldap_get_values (ldap, resp, "supportedSASLMechanisms");
if (values) {
- for (i = 0; values[i]; i++)
+ char *auth_method;
+ if (bl->priv->supported_auth_methods)
+ g_object_unref (bl->priv->supported_auth_methods);
+ bl->priv->supported_auth_methods = e_list_new ((EListCopyFunc)g_strdup, (EListFreeFunc)g_free, NULL);
+
+ auth_method = g_strdup_printf ("ldap/simple-binddn|%s", _());
+ e_list_append (bl->priv->supported_auth_methods, auth_method);
+ g_free (auth_method);
+
+ auth_method = g_strdup_printf ("ldap/simple-email|%s");
+ e_list_append (bl->priv->supported_auth_methods, auth_method);
+ g_free (auth_method);
+
+ for (i = 0; values[i]; i++) {
+ auth_method = g_strdup_printf ("sasl/%s|%s", values[i], values[i]);
+ e_list_append (bl->priv->supported_auth_methods, auth_method);
+ g_free (auth_method);
g_message ("supported SASL mechanism: %s", values[i]);
+ }
ldap_value_free (values);
}
@@ -3129,6 +3150,9 @@ pas_backend_ldap_process_check_connection (PASBackend *backend,
pas_book_report_connection (book, bl->priv->connected);
}
+#define LDAP_SIMPLE_PREFIX "ldap/simple-"
+#define SASL_PREFIX "sasl/"
+
static void
pas_backend_ldap_process_authenticate_user (PASBackend *backend,
PASBook *book,
@@ -3138,51 +3162,78 @@ pas_backend_ldap_process_authenticate_user (PASBackend *backend,
int ldap_error;
char *dn = NULL;
- if (!strcmp (req->auth_method, "ldap/simple-email")) {
- LDAPMessage *res, *e;
- char *query = g_strdup_printf ("(mail=%s)", req->user);
+ if (!strncasecmp (req->auth_method, LDAP_SIMPLE_PREFIX, strlen (LDAP_SIMPLE_PREFIX))) {
+
+ if (!strcmp (req->auth_method, "ldap/simple-email")) {
+ LDAPMessage *res, *e;
+ char *query = g_strdup_printf ("(mail=%s)", req->user);
- ldap_error = ldap_search_s (bl->priv->ldap,
- bl->priv->ldap_rootdn,
- bl->priv->ldap_scope,
- query,
- NULL, 0, &res);
- g_free (query);
+ ldap_error = ldap_search_s (bl->priv->ldap,
+ bl->priv->ldap_rootdn,
+ bl->priv->ldap_scope,
+ query,
+ NULL, 0, &res);
+ g_free (query);
- if (ldap_error == LDAP_SUCCESS) {
- char *entry_dn;
+ if (ldap_error == LDAP_SUCCESS) {
+ char *entry_dn;
- e = ldap_first_entry (bl->priv->ldap, res);
+ e = ldap_first_entry (bl->priv->ldap, res);
- entry_dn = ldap_get_dn (bl->priv->ldap, e);
- dn = g_strdup(entry_dn);
+ entry_dn = ldap_get_dn (bl->priv->ldap, e);
+ dn = g_strdup(entry_dn);
- ldap_memfree (entry_dn);
- ldap_msgfree (res);
+ ldap_memfree (entry_dn);
+ ldap_msgfree (res);
+ }
+ else {
+ pas_book_respond_authenticate_user (book,
+ GNOME_Evolution_Addressbook_BookListener_PermissionDenied);
+ return;
+ }
}
- else {
- pas_book_respond_authenticate_user (book,
- GNOME_Evolution_Addressbook_BookListener_PermissionDenied);
- return;
+ else if (!strcmp (req->auth_method, "ldap/simple-binddn")) {
+ dn = g_strdup (req->user);
}
- }
- else if (!strcmp (req->auth_method, "ldap/simple-binddn")) {
- dn = g_strdup (req->user);
- }
- /* now authenticate against the DN we were either supplied or queried for */
- printf ("authenticating as %s\n", dn);
- ldap_error = ldap_simple_bind_s(bl->priv->ldap,
- dn,
- req->passwd);
+ /* now authenticate against the DN we were either supplied or queried for */
+ printf ("simple auth as %s\n", dn);
+ ldap_error = ldap_simple_bind_s(bl->priv->ldap,
+ dn,
+ req->passwd);
- bl->priv->auth_dn = dn;
- bl->priv->auth_passwd = g_strdup (req->passwd);
+ pas_book_respond_authenticate_user (book,
+ ldap_error_to_response (ldap_error));
+ }
+#ifdef ENABLE_SASL_BINDS
+ else if (!strncasecmp (req->auth_method, SASL_PREFIX, strlen (SASL_PREFIX))) {
+ g_print ("sasl bind (mech = %s) as %s", req->auth_method + strlen (SASL_PREFIX), req->user);
+ ldap_error = ldap_sasl_bind_s (bl->priv->ldap,
+ NULL,
+ req->auth_method + strlen (SASL_PREFIX),
+ req->passwd,
+ NULL,
+ NULL,
+ NULL);
- pas_book_respond_authenticate_user (book,
- ldap_error_to_response (ldap_error));
+ if (ldap_error == LDAP_NOT_SUPPORTED)
+ pas_book_respond_authenticate_user (book,
+ GNOME_Evolution_Addressbook_BookListener_UnsupportedAuthenticationMethod);
+ else
+ pas_book_respond_authenticate_user (book,
+ ldap_error_to_response (ldap_error));
+ }
+#endif
+ else {
+ pas_book_respond_authenticate_user (book,
+ GNOME_Evolution_Addressbook_BookListener_UnsupportedAuthenticationMethod);
+ return;
+ }
if (ldap_error == LDAP_SUCCESS) {
+ bl->priv->auth_dn = dn;
+ bl->priv->auth_passwd = g_strdup (req->passwd);
+
pas_backend_set_is_writable (backend, TRUE);
/* force a requery on the root dse since some ldap
@@ -3218,6 +3269,19 @@ pas_backend_ldap_process_get_supported_fields (PASBackend *backend,
bl->priv->supported_fields);
}
+static void
+pas_backend_ldap_process_get_supported_auth_methods (PASBackend *backend,
+ PASBook *book,
+ PASGetSupportedAuthMethodsRequest *req)
+
+{
+ PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend);
+
+ pas_book_respond_get_supported_auth_methods (book,
+ GNOME_Evolution_Addressbook_BookListener_Success,
+ bl->priv->supported_auth_methods);
+}
+
static GNOME_Evolution_Addressbook_BookListener_CallStatus
pas_backend_ldap_load_uri (PASBackend *backend,
const char *uri)
@@ -3377,6 +3441,9 @@ pas_backend_ldap_dispose (GObject *object)
if (bl->priv->supported_fields)
g_object_unref (bl->priv->supported_fields);
+ if (bl->priv->supported_auth_methods)
+ g_object_unref (bl->priv->supported_auth_methods);
+
g_free (bl->priv->uri);
g_free (bl->priv);
@@ -3416,6 +3483,7 @@ pas_backend_ldap_class_init (PASBackendLDAPClass *klass)
parent_class->get_changes = pas_backend_ldap_process_get_changes;
parent_class->authenticate_user = pas_backend_ldap_process_authenticate_user;
parent_class->get_supported_fields = pas_backend_ldap_process_get_supported_fields;
+ parent_class->get_supported_auth_methods = pas_backend_ldap_process_get_supported_auth_methods;
object_class->dispose = pas_backend_ldap_dispose;
}
diff --git a/addressbook/backend/pas/pas-backend.c b/addressbook/backend/pas/pas-backend.c
index 513632c909..c8acad3c93 100644
--- a/addressbook/backend/pas/pas-backend.c
+++ b/addressbook/backend/pas/pas-backend.c
@@ -220,6 +220,20 @@ pas_backend_get_supported_fields (PASBackend *backend,
return (* PAS_BACKEND_GET_CLASS (backend)->get_supported_fields) (backend, book, req);
}
+void
+pas_backend_get_supported_auth_methods (PASBackend *backend,
+ PASBook *book,
+ PASGetSupportedAuthMethodsRequest *req)
+{
+ g_return_if_fail (PAS_IS_BACKEND (backend));
+ g_return_if_fail (PAS_IS_BOOK (book));
+ g_return_if_fail (req != NULL);
+
+ g_assert (PAS_BACKEND_GET_CLASS (backend)->get_supported_auth_methods != NULL);
+
+ return (* PAS_BACKEND_GET_CLASS (backend)->get_supported_auth_methods) (backend, book, req);
+}
+
static void
process_client_requests (PASBook *book, gpointer user_data)
{
@@ -276,6 +290,10 @@ process_client_requests (PASBook *book, gpointer user_data)
case GetSupportedFields:
pas_backend_get_supported_fields (backend, book, &req->get_supported_fields);
break;
+
+ case GetSupportedAuthMethods:
+ pas_backend_get_supported_auth_methods (backend, book, &req->get_supported_auth_methods);
+ break;
}
pas_book_free_request (req);
diff --git a/addressbook/backend/pas/pas-backend.h b/addressbook/backend/pas/pas-backend.h
index 8c3cab2c60..a87e28c2a2 100644
--- a/addressbook/backend/pas/pas-backend.h
+++ b/addressbook/backend/pas/pas-backend.h
@@ -64,6 +64,7 @@ typedef struct {
void (*get_changes) (PASBackend *backend, PASBook *book, PASGetChangesRequest *req);
void (*authenticate_user) (PASBackend *backend, PASBook *book, PASAuthenticateUserRequest *req);
void (*get_supported_fields) (PASBackend *backend, PASBook *book, PASGetSupportedFieldsRequest *req);
+ void (*get_supported_auth_methods) (PASBackend *backend, PASBook *book, PASGetSupportedAuthMethodsRequest *req);
/* Notification signals */
void (* last_client_gone) (PASBackend *backend);
@@ -121,6 +122,9 @@ void pas_backend_authenticate_user (PASBackend *backen
void pas_backend_get_supported_fields (PASBackend *backend,
PASBook *book,
PASGetSupportedFieldsRequest *req);
+void pas_backend_get_supported_auth_methods (PASBackend *backend,
+ PASBook *book,
+ PASGetSupportedAuthMethodsRequest *req);
GType pas_backend_get_type (void);
diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c
index 9ca049e350..2cb373b9d7 100644
--- a/addressbook/backend/pas/pas-book.c
+++ b/addressbook/backend/pas/pas-book.c
@@ -153,6 +153,17 @@ pas_book_queue_get_supported_fields (PASBook *book)
pas_book_queue_request (book, req);
}
+static void
+pas_book_queue_get_supported_auth_methods (PASBook *book)
+{
+ PASRequest *req;
+
+ req = g_new0 (PASRequest, 1);
+ req->op = GetSupportedAuthMethods;
+
+ pas_book_queue_request (book, req);
+}
+
static void
pas_book_queue_get_book_view (PASBook *book, const GNOME_Evolution_Addressbook_BookViewListener listener, const char *search)
@@ -365,6 +376,15 @@ impl_GNOME_Evolution_Addressbook_Book_getSupportedFields (PortableServer_Servant
pas_book_queue_get_supported_fields (book);
}
+static void
+impl_GNOME_Evolution_Addressbook_Book_getSupportedAuthMethods (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ PASBook *book = PAS_BOOK (bonobo_object (servant));
+
+ pas_book_queue_get_supported_auth_methods (book);
+}
+
/**
* pas_book_get_backend:
*/
@@ -584,6 +604,43 @@ pas_book_respond_get_supported_fields (PASBook *book,
CORBA_free(stringlist._buffer);
}
+void
+pas_book_respond_get_supported_auth_methods (PASBook *book,
+ GNOME_Evolution_Addressbook_BookListener_CallStatus status,
+ EList *auth_methods)
+{
+ CORBA_Environment ev;
+ GNOME_Evolution_Addressbook_stringlist stringlist;
+ int num_auth_methods;
+ EIterator *iter;
+ int i;
+
+ CORBA_exception_init (&ev);
+
+ num_auth_methods = e_list_length (auth_methods);
+
+ stringlist._buffer = CORBA_sequence_CORBA_string_allocbuf (num_auth_methods);
+ stringlist._maximum = num_auth_methods;
+ stringlist._length = num_auth_methods;
+
+ iter = e_list_get_iterator (auth_methods);
+
+ for (i = 0; e_iterator_is_valid (iter); e_iterator_next (iter), i ++) {
+ stringlist._buffer[i] = CORBA_string_dup (e_iterator_get(iter));
+ }
+
+ g_object_unref (auth_methods);
+
+ GNOME_Evolution_Addressbook_BookListener_notifySupportedAuthMethods (
+ book->priv->listener, status,
+ &stringlist,
+ &ev);
+
+ CORBA_exception_free (&ev);
+
+ CORBA_free(stringlist._buffer);
+}
+
/**
* pas_book_respond_get_cursor:
*/
@@ -861,6 +918,9 @@ pas_book_free_request (PASRequest *req)
case GetSupportedFields:
/* nothing to free */
break;
+ case GetSupportedAuthMethods:
+ /* nothing to free */
+ break;
}
g_free (req);
@@ -927,18 +987,19 @@ pas_book_class_init (PASBookClass *klass)
epv = &klass->epv;
- epv->getVCard = impl_GNOME_Evolution_Addressbook_Book_getVCard;
- epv->authenticateUser = impl_GNOME_Evolution_Addressbook_Book_authenticateUser;
- epv->addCard = impl_GNOME_Evolution_Addressbook_Book_addCard;
- epv->removeCard = impl_GNOME_Evolution_Addressbook_Book_removeCard;
- epv->modifyCard = impl_GNOME_Evolution_Addressbook_Book_modifyCard;
- epv->checkConnection = impl_GNOME_Evolution_Addressbook_Book_checkConnection;
- epv->getStaticCapabilities = impl_GNOME_Evolution_Addressbook_Book_getStaticCapabilities;
- epv->getSupportedFields = impl_GNOME_Evolution_Addressbook_Book_getSupportedFields;
- epv->getCursor = impl_GNOME_Evolution_Addressbook_Book_getCursor;
- epv->getBookView = impl_GNOME_Evolution_Addressbook_Book_getBookView;
- epv->getCompletionView = impl_GNOME_Evolution_Addressbook_Book_getCompletionView;
- epv->getChanges = impl_GNOME_Evolution_Addressbook_Book_getChanges;
+ epv->getVCard = impl_GNOME_Evolution_Addressbook_Book_getVCard;
+ epv->authenticateUser = impl_GNOME_Evolution_Addressbook_Book_authenticateUser;
+ epv->addCard = impl_GNOME_Evolution_Addressbook_Book_addCard;
+ epv->removeCard = impl_GNOME_Evolution_Addressbook_Book_removeCard;
+ epv->modifyCard = impl_GNOME_Evolution_Addressbook_Book_modifyCard;
+ epv->checkConnection = impl_GNOME_Evolution_Addressbook_Book_checkConnection;
+ epv->getStaticCapabilities = impl_GNOME_Evolution_Addressbook_Book_getStaticCapabilities;
+ epv->getSupportedFields = impl_GNOME_Evolution_Addressbook_Book_getSupportedFields;
+ epv->getSupportedAuthMethods = impl_GNOME_Evolution_Addressbook_Book_getSupportedAuthMethods;
+ epv->getCursor = impl_GNOME_Evolution_Addressbook_Book_getCursor;
+ epv->getBookView = impl_GNOME_Evolution_Addressbook_Book_getBookView;
+ epv->getCompletionView = impl_GNOME_Evolution_Addressbook_Book_getCompletionView;
+ epv->getChanges = impl_GNOME_Evolution_Addressbook_Book_getChanges;
}
static void
diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h
index 2ed87ff799..1474e760f4 100644
--- a/addressbook/backend/pas/pas-book.h
+++ b/addressbook/backend/pas/pas-book.h
@@ -41,7 +41,8 @@ typedef enum {
GetChanges,
CheckConnection,
AuthenticateUser,
- GetSupportedFields
+ GetSupportedFields,
+ GetSupportedAuthMethods
} PASOperation;
typedef struct {
@@ -103,20 +104,25 @@ typedef struct {
PASOperation op;
} PASGetSupportedFieldsRequest;
+typedef struct {
+ PASOperation op;
+} PASGetSupportedAuthMethodsRequest;
+
typedef union {
- PASOperation op;
-
- PASCreateCardRequest create;
- PASRemoveCardRequest remove;
- PASModifyCardRequest modify;
- PASGetVCardRequest get_vcard;
- PASGetCursorRequest get_cursor;
- PASGetBookViewRequest get_book_view;
- PASGetCompletionViewRequest get_completion_view;
- PASGetChangesRequest get_changes;
- PASCheckConnectionRequest check_connection;
- PASAuthenticateUserRequest auth_user;
- PASGetSupportedFieldsRequest get_supported_fields;
+ PASOperation op;
+
+ PASCreateCardRequest create;
+ PASRemoveCardRequest remove;
+ PASModifyCardRequest modify;
+ PASGetVCardRequest get_vcard;
+ PASGetCursorRequest get_cursor;
+ PASGetBookViewRequest get_book_view;
+ PASGetCompletionViewRequest get_completion_view;
+ PASGetChangesRequest get_changes;
+ PASCheckConnectionRequest check_connection;
+ PASAuthenticateUserRequest auth_user;
+ PASGetSupportedFieldsRequest get_supported_fields;
+ PASGetSupportedAuthMethodsRequest get_supported_auth_methods;
} PASRequest;
struct _PASBook {
@@ -158,6 +164,9 @@ void pas_book_respond_authenticate_user (PASBook
void pas_book_respond_get_supported_fields (PASBook *book,
GNOME_Evolution_Addressbook_BookListener_CallStatus status,
EList *fields);
+void pas_book_respond_get_supported_auth_methods (PASBook *book,
+ GNOME_Evolution_Addressbook_BookListener_CallStatus status,
+ EList *fields);
void pas_book_respond_get_cursor (PASBook *book,
GNOME_Evolution_Addressbook_BookListener_CallStatus status,