[tarantool-patches] Re: [PATCH v2] Introduce separate entity object types for entity privileges.

  • From: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
  • To: Serge Petrenko <sergepetrenko@xxxxxxxxxxxxx>
  • Date: Fri, 17 Aug 2018 18:57:34 +0300

On Fri, Aug 17, 2018 at 03:19:29PM +0300, Serge Petrenko wrote:

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 3007a131d..f586a2695 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -2537,10 +2537,35 @@ priv_def_create_from_tuple(struct priv_def *priv, 
struct tuple *tuple)
 {
      priv->grantor_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_ID);
      priv->grantee_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_UID);
+
      const char *object_type =
              tuple_field_cstr_xc(tuple, BOX_PRIV_FIELD_OBJECT_TYPE);
-     priv->object_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_OBJECT_ID);
      priv->object_type = schema_object_type(object_type);
+
+     const char *data = tuple_field(tuple, BOX_PRIV_FIELD_OBJECT_ID);
+     if (data == NULL) {
+         tnt_raise(ClientError, ER_NO_SUCH_FIELD,

Bad indentation - should be a tab here. Please fix.

+ *
+ * When adding new types please keep the
+ * same order between objects and corresponding entity types.
+ * schema_entity_type() relies on this convention.
  */
 enum schema_object_type {
      SC_UNKNOWN = 0,
@@ -228,9 +232,21 @@ enum schema_object_type {
      SC_ROLE = 5,
      SC_SEQUENCE = 6,
      SC_COLLATION = 7,
-     schema_object_type_MAX = 8
+     schema_object_type_MAX = 8,

Please add a comment here that says that below this point only entity
types are supposed to be defined.

+     SC_ENTITY_SPACE,
+     SC_ENTITY_FUNCTION,
+     SC_ENTITY_USER,
+     SC_ENTITY_ROLE,
+     SC_ENTITY_SEQUENCE,
+     SC_ENTITY_COLLATION
 };

+enum schema_object_type
+schema_entity_type(enum schema_object_type type)
+{
+     assert((int) type < (int) schema_object_type_MAX);
+     return type + schema_object_type_MAX - 1;
+}

No. Too fragile - easy to make a mistake when adding a new type.
And this -1 looks suspicious. Kostja isn't going to like it.

I vote for rewriting this code with a simple switch-case.

Other related posts: