[libsecret] Validate that we have attributes when looking up
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsecret] Validate that we have attributes when looking up
- Date: Tue, 10 Jul 2012 19:40:05 +0000 (UTC)
commit c85cadce76b99e5a3b20a9408edff09df3d7c777
Author: Stef Walter <stefw gnome org>
Date: Tue Jul 10 21:37:20 2012 +0200
Validate that we have attributes when looking up
* When matching items, make sure we have attributes if
no schema name was included in the match
* This is particularly important because we don't want to
remove all the items.
library/secret-attributes.c | 33 ++++++++++++++++++++++-----------
library/secret-collection.c | 4 ++--
library/secret-methods.c | 16 ++++++++--------
library/secret-password.c | 16 ++++++++--------
library/secret-paths.c | 6 +++---
library/secret-private.h | 4 +++-
6 files changed, 46 insertions(+), 33 deletions(-)
---
diff --git a/library/secret-attributes.c b/library/secret-attributes.c
index 298101b..7601d34 100644
--- a/library/secret-attributes.c
+++ b/library/secret-attributes.c
@@ -190,10 +190,13 @@ secret_attributes_buildv (const SecretSchema *schema,
gboolean
_secret_attributes_validate (const SecretSchema *schema,
- GHashTable *attributes)
+ GHashTable *attributes,
+ const char *pretty_function,
+ gboolean matching)
{
const SecretSchemaAttribute *attribute;
GHashTableIter iter;
+ gboolean any;
gchar *key;
gchar *value;
gchar *end;
@@ -203,6 +206,7 @@ _secret_attributes_validate (const SecretSchema *schema,
g_hash_table_iter_init (&iter, attributes);
while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value)) {
+ any = TRUE;
/* Find the attribute */
attribute = NULL;
@@ -216,16 +220,16 @@ _secret_attributes_validate (const SecretSchema *schema,
}
if (attribute == NULL) {
- g_warning ("invalid %s attribute in for %s schema",
- key, schema->name);
+ g_critical ("%s: invalid %s attribute in for %s schema",
+ pretty_function, key, schema->name);
return FALSE;
}
switch (attribute->type) {
case SECRET_SCHEMA_ATTRIBUTE_BOOLEAN:
if (!g_str_equal (value, "true") && !g_str_equal (value, "false")) {
- g_warning ("invalid %s boolean value for %s schema: %s",
- key, schema->name, value);
+ g_critical ("%s: invalid %s boolean value for %s schema: %s",
+ pretty_function, key, schema->name, value);
return FALSE;
}
break;
@@ -233,25 +237,32 @@ _secret_attributes_validate (const SecretSchema *schema,
end = NULL;
g_ascii_strtoll (value, &end, 10);
if (!end || end[0] != '\0') {
- g_warning ("invalid %s integer value for %s schema: %s",
- key, schema->name, value);
+ g_warning ("%s: invalid %s integer value for %s schema: %s",
+ pretty_function, key, schema->name, value);
return FALSE;
}
break;
case SECRET_SCHEMA_ATTRIBUTE_STRING:
if (!g_utf8_validate (value, -1, NULL)) {
- g_warning ("invalid %s string value for %s schema: %s",
- key, schema->name, value);
+ g_warning ("%s: invalid %s string value for %s schema: %s",
+ pretty_function, key, schema->name, value);
return FALSE;
}
break;
default:
- g_warning ("invalid %s value type in %s schema",
- key, schema->name);
+ g_warning ("%s: invalid %s value type in %s schema",
+ pretty_function, key, schema->name);
return FALSE;
}
}
+ /* Nothing to match on, resulting search would match everything :S */
+ if (matching && !any && schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME) {
+ g_warning ("%s: must specify at least one attribute to match",
+ pretty_function);
+ return FALSE;
+ }
+
return TRUE;
}
diff --git a/library/secret-collection.c b/library/secret-collection.c
index 4b1932b..a9db480 100644
--- a/library/secret-collection.c
+++ b/library/secret-collection.c
@@ -1414,7 +1414,7 @@ secret_collection_search (SecretCollection *self,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
@@ -1552,7 +1552,7 @@ secret_collection_search_sync (SecretCollection *self,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return NULL;
paths = secret_collection_search_for_dbus_paths_sync (self, schema, attributes,
diff --git a/library/secret-methods.c b/library/secret-methods.c
index 13af30c..75af012 100644
--- a/library/secret-methods.c
+++ b/library/secret-methods.c
@@ -302,7 +302,7 @@ secret_service_search (SecretService *service,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
@@ -455,7 +455,7 @@ secret_service_search_sync (SecretService *service,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return NULL;
if (service == NULL) {
@@ -1064,7 +1064,7 @@ secret_service_store (SecretService *service,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
return;
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
@@ -1181,7 +1181,7 @@ secret_service_store_sync (SecretService *service,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
return FALSE;
sync = _secret_sync_new ();
@@ -1365,7 +1365,7 @@ secret_service_lookup (SecretService *service,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
@@ -1464,7 +1464,7 @@ secret_service_lookup_sync (SecretService *service,
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return NULL;
sync = _secret_sync_new ();
@@ -1625,7 +1625,7 @@ secret_service_remove (SecretService *service,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
@@ -1721,7 +1721,7 @@ secret_service_remove_sync (SecretService *service,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return FALSE;
sync = _secret_sync_new ();
diff --git a/library/secret-password.c b/library/secret-password.c
index 92d640e..78a2157 100644
--- a/library/secret-password.c
+++ b/library/secret-password.c
@@ -142,7 +142,7 @@ secret_password_storev (const SecretSchema *schema,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
return;
value = secret_value_new (password, -1, "text/plain");
@@ -277,7 +277,7 @@ secret_password_storev_sync (const SecretSchema *schema,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
return FALSE;
sync = _secret_sync_new ();
@@ -368,7 +368,7 @@ secret_password_lookupv (const SecretSchema *schema,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
secret_service_lookup (NULL, schema, attributes,
@@ -555,7 +555,7 @@ secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return FALSE;
sync = _secret_sync_new ();
@@ -610,7 +610,7 @@ secret_password_lookupv_sync (const SecretSchema *schema,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return FALSE;
sync = _secret_sync_new ();
@@ -680,7 +680,7 @@ secret_password_remove (const SecretSchema *schema,
* @callback: called when the operation completes
* @user_data: data to be passed to the callback
*
- * Remove a password from the secret service.
+ * Remove passwords from the secret service.
*
* The @attributes should be a set of key and value string pairs.
*
@@ -702,7 +702,7 @@ secret_password_removev (const SecretSchema *schema,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
secret_service_remove (NULL, schema, attributes,
@@ -809,7 +809,7 @@ secret_password_removev_sync (const SecretSchema *schema,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Warnings raised already */
- if (!_secret_attributes_validate (schema, attributes))
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return FALSE;
sync = _secret_sync_new ();
diff --git a/library/secret-paths.c b/library/secret-paths.c
index 1d48836..85ec118 100644
--- a/library/secret-paths.c
+++ b/library/secret-paths.c
@@ -344,7 +344,7 @@ secret_collection_search_for_dbus_paths (SecretCollection *collection,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
@@ -486,7 +486,7 @@ secret_service_search_for_dbus_paths (SecretService *self,
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
@@ -626,7 +626,7 @@ secret_service_search_for_dbus_paths_sync (SecretService *self,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Warnings raised already */
- if (schema != NULL && !_secret_attributes_validate (schema, attributes))
+ if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
return FALSE;
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
diff --git a/library/secret-private.h b/library/secret-private.h
index f5efa42..c33b57c 100644
--- a/library/secret-private.h
+++ b/library/secret-private.h
@@ -81,7 +81,9 @@ GHashTable * _secret_attributes_for_variant (GVariant *variant
GHashTable * _secret_attributes_copy (GHashTable *attributes);
gboolean _secret_attributes_validate (const SecretSchema *schema,
- GHashTable *attributes);
+ GHashTable *attributes,
+ const gchar *pretty_function,
+ gboolean matching);
GVariant * _secret_util_variant_for_properties (GHashTable *properties);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]