~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to addressbook/backends/ldap/e-book-backend-ldap.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#undef interface
51
51
#include <winldap.h>
52
52
#define LDAP_RES_RENAME LDAP_RES_MODRDN
 
53
#include <winber.h>
53
54
#include "openldap-extract.h"
54
55
 
55
56
/* map between the WinLDAP API and OpenLDAP API */
340
341
        /* name fields */
341
342
        STRING_PROP (E_CONTACT_FULL_NAME,   "cn" ),
342
343
        /* WRITE_ONLY_STRING_PROP (E_CONTACT_FAMILY_NAME, "sn" ), */
 
344
        STRING_PROP (E_CONTACT_GIVEN_NAME, "givenName"),
343
345
        STRING_PROP (E_CONTACT_FAMILY_NAME, "sn" ),
344
346
 
345
347
        /* email addresses */
427
429
#undef GROUP_PROP
428
430
};
429
431
 
430
 
static gint num_prop_infos = sizeof(prop_info) / sizeof(prop_info[0]);
431
 
 
432
432
#if 0
433
433
static void
434
434
remove_view (gint msgid, LDAPOp *op, EDataBookView *view)
595
595
        gint i;
596
596
        GHashTable *attr_hash = g_hash_table_new (g_str_hash, g_str_equal);
597
597
 
598
 
        for (i = 0; i < num_prop_infos; i ++)
 
598
        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++)
599
599
                g_hash_table_insert (attr_hash, (gpointer) prop_info[i].ldap_attr, (gchar *)e_contact_field_name (prop_info[i].field_id));
600
600
 
601
601
        if (oc->oc_at_oids_must)
886
886
 
887
887
        blpriv->ldap = ldap_init (blpriv->ldap_host, blpriv->ldap_port);
888
888
 
 
889
        if (NULL != blpriv->ldap) {
 
890
                gint ldap_error;
 
891
 
889
892
#if defined (DEBUG) && defined (LDAP_OPT_DEBUG_LEVEL)
890
893
        {
891
894
                gint debug_level = 4;
892
895
                ldap_set_option (blpriv->ldap, LDAP_OPT_DEBUG_LEVEL, &debug_level);
893
896
        }
894
897
#endif
895
 
        if (NULL != blpriv->ldap) {
896
 
                gint ldap_error;
897
 
 
898
898
                ldap_error = ldap_set_option (blpriv->ldap, LDAP_OPT_PROTOCOL_VERSION, &protocol_version);
899
899
                if (LDAP_SUCCESS != ldap_error) {
900
900
                        g_warning ("failed to set protocol version to LDAPv3");
1012
1012
                        return (GNOME_Evolution_Addressbook_AuthenticationFailed);
1013
1013
                }
1014
1014
 
1015
 
                g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
1016
1015
                if (ldap_error == LDAP_INSUFFICIENT_ACCESS)
1017
1016
                        ldap_error = LDAP_SUCCESS;
1018
1017
                else
1030
1029
                if (ldap_error == LDAP_SUCCESS
1031
1030
                    || ldap_error == LDAP_PARTIAL_RESULTS
1032
1031
                    || LDAP_NAME_ERROR (ldap_error)) {
 
1032
                        e_book_backend_set_is_loaded (E_BOOK_BACKEND (bl), TRUE);
1033
1033
                        blpriv->connected = TRUE;
 
1034
                        g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
1034
1035
 
1035
1036
                        /* check to see if evolutionPerson is supported, if we can (me
1036
1037
                           might not be able to if we can't authenticate.  if we
1038
1039
                        if (!bl->priv->evolutionPersonChecked)
1039
1040
                                check_schema_support (bl);
1040
1041
 
1041
 
                        e_book_backend_set_is_loaded (E_BOOK_BACKEND (bl), TRUE);
1042
 
 
1043
1042
                        if (enable_debug) {
1044
1043
                                printf ("e_book_backend_ldap_connect ... success \n");
1045
1044
                                g_get_current_time (&end);
1051
1050
                        return GNOME_Evolution_Addressbook_Success;
1052
1051
                } else if (ldap_error == LDAP_UNWILLING_TO_PERFORM) {
1053
1052
                        e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
 
1053
                        g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
1054
1054
                        return GNOME_Evolution_Addressbook_AuthenticationRequired;
1055
 
                } else
 
1055
                } else {
 
1056
                        g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
1056
1057
                        g_warning ("Failed to perform root dse query anonymously, (ldap_error 0x%02x)", ldap_error);
 
1058
                }
1057
1059
        }
1058
1060
        else {
1059
1061
                g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
1345
1347
        /* we walk down the list of properties we can deal with (that
1346
1348
         big table at the top of the file) */
1347
1349
 
1348
 
        for (i = 0; i < num_prop_infos; i ++) {
 
1350
        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++) {
1349
1351
                gboolean include;
1350
1352
                gboolean new_prop_present = FALSE;
1351
1353
                gboolean current_prop_present = FALSE;
3676
3678
        gchar ** strings;
3677
3679
 
3678
3680
        if (argc > 0) {
3679
 
                gint i;
 
3681
                gint i, empty;
3680
3682
 
3681
3683
                strings = g_new0(gchar *, argc+3);
3682
3684
                strings[0] = g_strdup ("(&");
3683
3685
                strings[argc+3 - 2] = g_strdup (")");
3684
3686
 
 
3687
                empty = 0;
3685
3688
                for (i = 0; i < argc; i ++) {
3686
3689
                        GList *list_head = ldap_data->list;
3687
3690
                        if (!list_head)
3688
3691
                                break;
 
3692
                        if (strlen (list_head->data) == 0)
 
3693
                                empty++;
3689
3694
                        strings[argc - i] = list_head->data;
3690
3695
                        ldap_data->list = g_list_remove_link(list_head, list_head);
3691
3696
                        g_list_free_1(list_head);
3692
3697
                }
3693
3698
 
3694
 
                ldap_data->list = g_list_prepend(ldap_data->list, g_strjoinv(" ", strings));
 
3699
                if (empty == argc)
 
3700
                        ldap_data->list = g_list_prepend (ldap_data->list, g_strdup (" "));
 
3701
                else
 
3702
                        ldap_data->list = g_list_prepend (ldap_data->list, g_strjoinv (" ", strings));
3695
3703
 
3696
3704
                for (i = 0; i < argc + 2; i ++)
3697
3705
                        g_free (strings[i]);
3713
3721
        gchar ** strings;
3714
3722
 
3715
3723
        if (argc > 0) {
3716
 
                gint i;
 
3724
                gint i, empty;
3717
3725
 
3718
3726
                strings = g_new0(gchar *, argc+3);
3719
3727
                strings[0] = g_strdup ("(|");
3720
3728
                strings[argc+3 - 2] = g_strdup (")");
3721
3729
 
 
3730
                empty = 0;
3722
3731
                for (i = 0; i < argc; i ++) {
3723
3732
                        GList *list_head = ldap_data->list;
3724
3733
                        if (!list_head)
3725
3734
                                break;
 
3735
                        if (strlen (list_head->data) == 0)
 
3736
                                empty++;
3726
3737
                        strings[argc - i] = list_head->data;
3727
3738
                        ldap_data->list = g_list_remove_link(list_head, list_head);
3728
3739
                        g_list_free_1(list_head);
3729
3740
                }
3730
3741
 
3731
 
                ldap_data->list = g_list_prepend(ldap_data->list, g_strjoinv(" ", strings));
 
3742
                if (empty == argc)
 
3743
                        ldap_data->list = g_list_prepend (ldap_data->list, g_strdup (" "));
 
3744
                else
 
3745
                        ldap_data->list = g_list_prepend (ldap_data->list, g_strjoinv (" ", strings));
3732
3746
 
3733
3747
                for (i = 0; i < argc + 2; i ++)
3734
3748
                        g_free (strings[i]);
3795
3809
 
3796
3810
                        query_length = 3; /* strlen ("(|") + strlen (")") */
3797
3811
 
3798
 
                        for (i = 0; i < num_prop_infos; i ++) {
 
3812
                        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++) {
3799
3813
                                query_length += 1 /* strlen ("(") */ + strlen(prop_info[i].ldap_attr) + strlen (match_str);
3800
3814
                        }
3801
3815
 
3802
3816
                        big_query = g_malloc0(query_length + 1);
3803
3817
                        strcat (big_query, "(|");
3804
 
                        for (i = 0; i < num_prop_infos; i ++) {
 
3818
                        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++) {
3805
3819
                                strcat (big_query, "(");
3806
3820
                                strcat (big_query, prop_info[i].ldap_attr);
3807
3821
                                strcat (big_query, match_str);
3881
3895
                if (strlen (str) == 0) {
3882
3896
                        g_free (str);
3883
3897
 
 
3898
                        ldap_data->list = g_list_prepend (ldap_data->list, g_strdup (""));
 
3899
 
3884
3900
                        r = e_sexp_result_new (f, ESEXP_RES_BOOL);
3885
3901
                        r->value.bool = FALSE;
3886
3902
                        return r;
3969
3985
 
3970
3986
                        query_length = 3; /* strlen ("(|") + strlen (")") */
3971
3987
 
3972
 
                        for (i = 0; i < num_prop_infos; i ++) {
 
3988
                        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++) {
3973
3989
                                query_length += 1 /* strlen ("(") */ + strlen(prop_info[i].ldap_attr) + strlen (match_str);
3974
3990
                        }
3975
3991
 
3976
3992
                        big_query = g_malloc0(query_length + 1);
3977
3993
                        strcat (big_query, "(|");
3978
 
                        for (i = 0; i < num_prop_infos; i ++) {
 
3994
                        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++) {
3979
3995
                                strcat (big_query, "(");
3980
3996
                                strcat (big_query, prop_info[i].ldap_attr);
3981
3997
                                strcat (big_query, match_str);
4033
4049
 
4034
4050
        sexp = e_sexp_new();
4035
4051
 
4036
 
        for (i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) {
 
4052
        for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
4037
4053
                if (symbols[i].type == 1) {
4038
4054
                        e_sexp_add_ifunction(sexp, 0, symbols[i].name,
4039
4055
                                             (ESExpIFunc *)symbols[i].func, &data);
4089
4105
{
4090
4106
        gint i;
4091
4107
 
4092
 
        for (i = 0; i < num_prop_infos; i ++)
 
4108
        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++)
4093
4109
                if (!strcmp (query_prop, e_contact_field_name (prop_info[i].field_id)))
4094
4110
                        return prop_info[i].ldap_attr;
4095
4111
 
4160
4176
                        ldap_value_free (values);
4161
4177
                }
4162
4178
                else {
4163
 
                        for (i = 0; i < num_prop_infos; i ++)
 
4179
                        for (i = 0; i < G_N_ELEMENTS (prop_info); i ++)
4164
4180
                                if (!g_ascii_strcasecmp (attr, prop_info[i].ldap_attr)) {
4165
4181
                                        info = &prop_info[i];
4166
4182
                                        break;
4812
4828
        if (enable_debug)
4813
4829
                printf ("e_book_backend_ldap_authenticate_user ... \n");
4814
4830
 
 
4831
        g_static_rec_mutex_lock (&eds_ldap_handler_lock);
4815
4832
        if (bl->priv->mode == GNOME_Evolution_Addressbook_MODE_LOCAL) {
4816
4833
                e_book_backend_notify_writable (backend, FALSE);
4817
4834
                e_book_backend_notify_connection_status (backend, FALSE);
4818
4835
                e_data_book_respond_authenticate_user (book,
4819
4836
                                                       opid,
4820
4837
                                                       GNOME_Evolution_Addressbook_Success);
4821
 
                return;
4822
 
        }
 
4838
                g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 
4839
                return;
 
4840
        }
 
4841
 
 
4842
        if (bl->priv->connected) {
 
4843
                /* other client connected meanwhile, report success and return */
 
4844
                e_data_book_respond_authenticate_user (book, opid, GNOME_Evolution_Addressbook_Success);
 
4845
                g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
 
4846
                return;
 
4847
        }
 
4848
        g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
4823
4849
 
4824
4850
        if (!g_ascii_strncasecmp (auth_method, LDAP_SIMPLE_PREFIX, strlen (LDAP_SIMPLE_PREFIX))) {
4825
4851
 
5082
5108
        if (str)
5083
5109
                limit = atoi (str);
5084
5110
 
 
5111
        bl->priv->use_tls = E_BOOK_BACKEND_LDAP_TLS_NO;
 
5112
 
5085
5113
        str = e_source_get_property (source, "ssl");
5086
5114
        if (str) {
5087
5115
                if (!strcmp (str, "always"))
5091
5119
                else if (strcmp (str, "never"))
5092
5120
                        g_warning ("Unhandled value for 'ssl', not using it.");
5093
5121
        }
5094
 
        else
5095
 
                bl->priv->use_tls = E_BOOK_BACKEND_LDAP_TLS_NO;
5096
5122
 
5097
5123
        str = e_source_get_property (source, "timeout");
5098
5124
        if (str)
5161
5187
                if (enable_debug)
5162
5188
                        printf ("e_book_backend_ldap_load_source ... skipping anonymous bind, because auth required\n");
5163
5189
 
5164
 
                e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
 
5190
                if (!e_book_backend_is_loaded (backend))
 
5191
                        e_book_backend_notify_auth_required (backend);
 
5192
                e_book_backend_set_is_loaded (backend, TRUE);
5165
5193
                return GNOME_Evolution_Addressbook_Success;
5166
5194
        }
5167
5195
 
5173
5201
                return result;
5174
5202
        }
5175
5203
 
5176
 
        if (auth_required) {
 
5204
        if (auth_required && !e_book_backend_is_loaded (backend)) {
5177
5205
                e_book_backend_notify_auth_required (E_BOOK_BACKEND (bl));
5178
5206
                return result;
5179
5207
        }
5243
5271
#endif
5244
5272
 
5245
5273
static void
5246
 
e_book_backend_ldap_set_mode (EBookBackend *backend, gint mode)
 
5274
e_book_backend_ldap_set_mode (EBookBackend *backend,
 
5275
                              GNOME_Evolution_Addressbook_BookMode mode)
5247
5276
{
5248
5277
        EBookBackendLDAP *bl = E_BOOK_BACKEND_LDAP (backend);
5249
5278
 
5308
5337
        g_assert (backend != NULL);
5309
5338
        g_assert (E_IS_BOOK_BACKEND_LDAP (backend));
5310
5339
 
5311
 
        if (! e_book_backend_construct (E_BOOK_BACKEND (backend)))
 
5340
        if (!e_book_backend_construct (E_BOOK_BACKEND (backend)))
5312
5341
                return FALSE;
5313
5342
 
5314
5343
        return TRUE;
5324
5353
 
5325
5354
        backend = g_object_new (E_TYPE_BOOK_BACKEND_LDAP, NULL);
5326
5355
 
5327
 
        if (! e_book_backend_ldap_construct (backend)) {
 
5356
        if (!e_book_backend_ldap_construct (backend)) {
5328
5357
                g_object_unref (backend);
5329
5358
                return NULL;
5330
5359
        }