From b7c92420df7adf6790ca426475fd45fa4e86782d Mon Sep 17 00:00:00 2001 From: Veerapuram Varadhan Date: Tue, 6 Dec 2005 08:43:37 +0000 Subject: Authenticate by reading the store-password for calendars that has "auth" * conduits/addressbook-conduit.c: (pre_sync): Authenticate by reading the store-password for calendars that has "auth" property set. * conduits/addressbook-conduit.c: (addressbook_authenticate): Implement authentication using e-passwords. svn path=/trunk/; revision=30730 --- addressbook/conduit/address-conduit.c | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'addressbook/conduit/address-conduit.c') diff --git a/addressbook/conduit/address-conduit.c b/addressbook/conduit/address-conduit.c index 15573c190b..65e64c4931 100644 --- a/addressbook/conduit/address-conduit.c +++ b/addressbook/conduit/address-conduit.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -878,10 +880,15 @@ local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrCondui char *add; /* If the address has 2 lines, make sure both get added */ - if (address->ext != NULL) + if (address->ext != NULL && + strlen (address->ext) > 0) { add = g_strconcat (address->street, "\n", address->ext, NULL); - else + LOG (g_warning ("Address has two lines: [%s]\n", add)); + } + else { add = g_strdup (address->street); + LOG (g_warning ("Address has only one line: [%s]\n", add)); + } local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add); g_free (add); @@ -1151,6 +1158,50 @@ check_for_slow_setting (GnomePilotConduit *c, EAddrConduitContext *ctxt) } } +static void +addressbook_authenticate (EBook *book, + gpointer data) +{ + gchar *auth; + gchar *user; + gchar *passwd; + gchar *str_uri; + gchar *pass_key; + gchar *auth_domain; + gchar *component_name; + EUri *e_uri; + + ESource *source = (ESource *)data; + + auth = e_source_get_property (source, "auth"); + auth_domain = e_source_get_property (source, "auth-domain"); + component_name = auth_domain ? auth_domain : "Addressbook"; + + if (auth && !strcmp ("plain/password", auth)) + user = e_source_get_property (source, "user"); + else + user = e_source_get_property (source, "email_addr"); + if (!user) + user = ""; + + str_uri = e_source_get_uri (source); + e_uri = e_uri_new (str_uri); + pass_key = e_uri_to_string (e_uri, FALSE); + e_uri_free (e_uri); + + passwd = e_passwords_get_password (component_name, pass_key); + if (passwd) + passwd = ""; + + if (book) + if (!e_book_authenticate_user (book, user, passwd, auth, NULL)) + LOG (g_warning ("Authentication failed")); + g_free (pass_key); + g_free (str_uri); + + return; +} + /* Pilot syncing callbacks */ static gint pre_sync (GnomePilotConduit *conduit, @@ -1164,6 +1215,7 @@ pre_sync (GnomePilotConduit *conduit, unsigned char *buf; char *filename; char *change_id; + char *auth; gint num_records, add_records = 0, mod_records = 0, del_records = 0; abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit); @@ -1179,6 +1231,12 @@ pre_sync (GnomePilotConduit *conduit, } else { ctxt->ebook = e_book_new_default_addressbook (NULL); } + auth = e_source_get_property (ctxt->cfg->source, "auth"); + if (auth) { + LOG (g_message ("contacts needs authentication\n")); + g_signal_connect (ctxt->ebook, "auth_required", + G_CALLBACK (addressbook_authenticate), ctxt->cfg->source); + } if (!ctxt->ebook || !e_book_open (ctxt->ebook, TRUE, NULL)) { WARN(_("Could not load addressbook")); gnome_pilot_conduit_error (conduit, _("Could not load addressbook")); -- cgit v1.2.3