From 11eb8ba870457337c6067284dde4277e09764c0a Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 12 Jul 2017 09:18:02 +0530 Subject: storage/posix: Don't allow gfid/volume-id xattr to be removed Problem: Bulk xattr removal doesn't check if the xattrs that are coming in xdata have gfid/volume-id xattrs, so there is potential for bulkremovexattr removing gfid/volume-id. I also observed that bulkremovexattr is not available for fremovexattr. Fix: Do proper checks in bulk removexattr to remove gfid/volume-id. Refactor [f]removexattr to reduce the differences. BUG: 1470489 Change-Id: Ia845b31846a149500111c0996646e648f72cdce6 Signed-off-by: Pranith Kumar K Reviewed-on: https://review.gluster.org/17765 Smoke: Gluster Build System Reviewed-by: Jeff Darcy CentOS-regression: Gluster Build System Reviewed-by: Anuradha Talur Reviewed-by: Niels de Vos Reviewed-by: Krutika Dhananjay --- libglusterfs/src/dict.c | 28 ++++++++++++++++++++++++++++ libglusterfs/src/dict.h | 2 ++ 2 files changed, 30 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 04d627dde39..aa06dcb2a8d 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -3077,3 +3077,31 @@ dict_for_key_value (const char *name, const char *value, size_t size) return xattr; } + +/* + * "strings" should be NULL terminated strings array. + */ +int +dict_has_key_from_array (dict_t *dict, char **strings, gf_boolean_t *result) +{ + int i = 0; + uint32_t hash = 0; + + if (!dict || !strings || !result) + return -EINVAL; + + LOCK (&dict->lock); + { + for (i = 0; strings[i]; i++) { + hash = SuperFastHash (strings[i], strlen (strings[i])); + if (dict_lookup_common (dict, strings[i], hash)) { + *result = _gf_true; + goto unlock; + } + } + *result = _gf_false; + } +unlock: + UNLOCK (&dict->lock); + return 0; +} diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index bdc003ea373..b1ba3c20234 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -263,4 +263,6 @@ are_dicts_equal (dict_t *one, dict_t *two, gf_boolean_t (*match) (dict_t *d, char *k, data_t *v, void *data), gf_boolean_t (*value_ignore) (char *k)); +int +dict_has_key_from_array (dict_t *dict, char **strings, gf_boolean_t *result); #endif -- cgit