[libgda] Use the new capabilities of GdaQuarkList
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Use the new capabilities of GdaQuarkList
- Date: Tue, 1 May 2012 18:22:33 +0000 (UTC)
commit 21f3bf07dbb6b829265dec6a6c264b750a504570
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue May 1 19:59:12 2012 +0200
Use the new capabilities of GdaQuarkList
to mangle authentification data
libgda/gda-connection.c | 3 +
libgda/sqlite/virtual/gda-vprovider-data-model.c | 4 ++
providers/ldap/gda-ldap-provider.c | 45 +++++++++++++++++-----
providers/ldap/gda-ldap.h | 4 +-
4 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 381b633..d924700 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -1704,6 +1704,9 @@ gda_connection_open (GdaConnection *cnc, GError **error)
opened = PROV_CLASS (cnc->priv->provider_obj)->open_connection (cnc->priv->provider_obj, cnc, params, auth,
NULL, NULL, NULL);
+ gda_quark_list_protect_values (params);
+ gda_quark_list_protect_values (auth);
+
if (opened && !cnc->priv->provider_data) {
g_warning ("Internal error: connection reported as opened, yet no provider data set");
opened = FALSE;
diff --git a/libgda/sqlite/virtual/gda-vprovider-data-model.c b/libgda/sqlite/virtual/gda-vprovider-data-model.c
index 23595d2..ca407e6 100644
--- a/libgda/sqlite/virtual/gda-vprovider-data-model.c
+++ b/libgda/sqlite/virtual/gda-vprovider-data-model.c
@@ -374,9 +374,13 @@ gda_vprovider_data_model_open_connection (GdaServerProvider *provider, GdaConnec
if (! GDA_SERVER_PROVIDER_CLASS (parent_class)->open_connection (GDA_SERVER_PROVIDER (provider), cnc, m_params,
auth, NULL, NULL, NULL)) {
+ if (auth)
+ gda_quark_list_protect_values (auth);
gda_quark_list_free (m_params);
return FALSE;
}
+ if (auth)
+ gda_quark_list_protect_values (auth);
gda_quark_list_free (m_params);
SqliteConnectionData *scnc;
diff --git a/providers/ldap/gda-ldap-provider.c b/providers/ldap/gda-ldap-provider.c
index 811d112..33cdd65 100644
--- a/providers/ldap/gda-ldap-provider.c
+++ b/providers/ldap/gda-ldap-provider.c
@@ -564,14 +564,31 @@ gda_ldap_provider_open_connection (GdaServerProvider *provider, GdaConnection *c
g_free (dnuser);
return FALSE;
}
- if (pwd)
- cdata->pass = g_strdup (pwd);
+ if (pwd) {
+ gchar *tmp;
+ tmp = g_strdup_printf ("PASSWORD=%s", pwd);
+ cdata->auth = gda_quark_list_new_from_string (tmp);
+ g_free (tmp);
+ }
if (dnuser) {
- cdata->user = dnuser;
+ gchar *tmp;
+ tmp = g_strdup_printf ("USERNAME=%s", dnuser);
+ if (cdata->auth)
+ gda_quark_list_add_from_string (cdata->auth, tmp, FALSE);
+ else
+ cdata->auth = gda_quark_list_new_from_string (tmp);
+ g_free (tmp);
dnuser = NULL;
}
- else if (user)
- cdata->user = g_strdup (user);
+ else if (user) {
+ gchar *tmp;
+ tmp = g_strdup_printf ("USERNAME=%s", user);
+ if (cdata->auth)
+ gda_quark_list_add_from_string (cdata->auth, tmp, FALSE);
+ else
+ cdata->auth = gda_quark_list_new_from_string (tmp);
+ g_free (tmp);
+ }
/* set startup file name */
gchar *fname;
@@ -663,12 +680,20 @@ gda_ldap_rebind (LdapConnectionData *cdata, GError **error)
/* authentication */
struct berval cred;
- const gchar *pwd;
- pwd = cdata->pass;
+ const gchar *pwd = "";
+ const gchar *user = "";
+ if (cdata->auth)
+ pwd = gda_quark_list_find (cdata->auth, "PASSWORD");
memset (&cred, 0, sizeof (cred));
cred.bv_len = pwd && *pwd ? strlen (pwd) : 0;
cred.bv_val = pwd && *pwd ? (char *) pwd : NULL;
- res = ldap_sasl_bind_s (ld, cdata->user, NULL, &cred, NULL, NULL, NULL);
+
+ if (cdata->auth)
+ user = gda_quark_list_find (cdata->auth, "USERNAME");
+ res = ldap_sasl_bind_s (ld, user, NULL, &cred, NULL, NULL, NULL);
+ if (cdata->auth)
+ gda_quark_list_protect_values (cdata->auth);
+
if (res != LDAP_SUCCESS) {
g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_OPEN_ERROR,
"%s", ldap_err2string (res));
@@ -939,8 +964,8 @@ gda_ldap_free_cnc_data (LdapConnectionData *cdata)
g_free (cdata->base_dn);
g_free (cdata->server_version);
g_free (cdata->url);
- g_free (cdata->user);
- g_free (cdata->pass);
+ if (cdata->auth)
+ gda_quark_list_free (cdata->auth);
g_free (cdata);
}
diff --git a/providers/ldap/gda-ldap.h b/providers/ldap/gda-ldap.h
index baff245..776bfad 100644
--- a/providers/ldap/gda-ldap.h
+++ b/providers/ldap/gda-ldap.h
@@ -31,6 +31,7 @@
#include <ldap.h>
#include <ldap_schema.h>
#include <glib.h>
+#include <libgda.h>
/*
* Provider's specific connection data
@@ -42,8 +43,7 @@ typedef struct {
gchar *base_dn;
gchar *server_version;
gchar *url;
- gchar *user;
- gchar *pass;
+ GdaQuarkList *auth;
int time_limit;
int size_limit;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]