diff --git a/src/box/alter.cc b/src/box/alter.cc index 4110b144156706d10d4db29668830f8469ab4e3b..697b7dbf33eba17f0275964762c022af85257deb 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2026,7 +2026,11 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event) "the space has indexes"); return -1; } - if (schema_find_grants("space", old_space->def->id)) { + bool out; + if (schema_find_grants("space", old_space->def->id, &out) != 0) { + return -1; + } + if (out) { diag_set(ClientError, ER_DROP_SPACE, space_name(old_space), "the space has grants"); @@ -3048,7 +3052,11 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event) PRIV_D) != 0) return -1; /* Can only delete func if it has no grants. */ - if (schema_find_grants("function", old_func->def->fid)) { + bool out; + if (schema_find_grants("function", old_func->def->fid, &out) != 0) { + return -1; + } + if (out) { diag_set(ClientError, ER_DROP_FUNCTION, (unsigned) old_func->def->uid, "function has grants"); @@ -3938,7 +3946,11 @@ on_replace_dd_sequence(struct trigger * /* trigger */, void *event) seq->def->name, "the sequence is in use"); return -1; } - if (schema_find_grants("sequence", seq->def->id)) { + bool out; + if (schema_find_grants("sequence", seq->def->id, &out) != 0) { + return -1; + } + if (out) { diag_set(ClientError, ER_DROP_SEQUENCE, seq->def->name, "the sequence has grants"); return -1; diff --git a/src/box/schema.cc b/src/box/schema.cc index 8d8aae4481e53ab1fea925d6bb3ed9c891a09254..9767207e099be2fbf884b370d11fec68775a7f9d 100644 --- a/src/box/schema.cc +++ b/src/box/schema.cc @@ -599,12 +599,22 @@ func_by_name(const char *name, uint32_t name_len) return (struct func *) mh_strnptr_node(funcs_by_name, func)->val; } -bool -schema_find_grants(const char *type, uint32_t id) +int +schema_find_grants(const char *type, uint32_t id, bool *out) { - struct space *priv = space_cache_find_xc(BOX_PRIV_ID); + struct space *priv = space_cache_find(BOX_PRIV_ID); + if (priv == NULL) + return -1; + /** "object" index */ - struct index *index = index_find_system_xc(priv, 2); + if (!space_is_memtx(priv)) { + diag_set(ClientError, ER_UNSUPPORTED, + priv->engine->name, "system data"); + return -1; + } + struct index *index = index_find(priv, 2); + if (index == NULL) + return -1; /* * +10 = max(mp_sizeof_uint32) + * max(mp_sizeof_strl(uint32)). @@ -612,9 +622,15 @@ schema_find_grants(const char *type, uint32_t id) char key[GRANT_NAME_MAX + 10]; assert(strlen(type) <= GRANT_NAME_MAX); mp_encode_uint(mp_encode_str(key, type, strlen(type)), id); - struct iterator *it = index_create_iterator_xc(index, ITER_EQ, key, 2); + struct iterator *it = index_create_iterator(index, ITER_EQ, key, 2); + if (it == NULL) + return -1; IteratorGuard iter_guard(it); - return iterator_next_xc(it); + struct tuple *tuple; + if (iterator_next(it, &tuple) != 0) + return -1; + *out = (tuple != NULL); + return 0; } struct sequence * diff --git a/src/box/schema.h b/src/box/schema.h index f9d15b38d977ae0c78a9c1e9fc79db9dea52b440..66555ab14c7b67da47ec851b6ab31641dba9ed5a 100644 --- a/src/box/schema.h +++ b/src/box/schema.h @@ -185,11 +185,11 @@ func_cache_find(uint32_t fid) * Check whether or not an object has grants on it (restrict * constraint in drop object). * _priv space to look up by space id - * @retval true object has grants - * @retval false object has no grants + * @retval (bool *out) true object has grants + * @retval (bool *out) false object has no grants */ -bool -schema_find_grants(const char *type, uint32_t id); +int +schema_find_grants(const char *type, uint32_t id, bool *out); /** * A wrapper around sequence_by_id() that raises an exception