selinux: rename comparison functions for clarity
The functions context_cmp(), mls_context_cmp() and ebitmap_cmp() are not traditional C style compare functions returning -1, 0, and 1 for less than, equal, and greater than; they only return whether their arguments are equal. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
committed by
Paul Moore
parent
5e99b81f48
commit
83e7e18eed
@@ -20,7 +20,7 @@ u32 context_compute_hash(const struct context *c)
|
||||
* context struct with only the len & str set (and vice versa)
|
||||
* under a given policy. Since context structs from different
|
||||
* policies should never meet, it is safe to hash valid and
|
||||
* invalid contexts differently. The context_cmp() function
|
||||
* invalid contexts differently. The context_equal() function
|
||||
* already operates under the same assumption.
|
||||
*/
|
||||
if (c->len)
|
||||
|
||||
@@ -132,13 +132,13 @@ out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int mls_context_cmp(const struct context *c1,
|
||||
const struct context *c2)
|
||||
static inline bool mls_context_equal(const struct context *c1,
|
||||
const struct context *c2)
|
||||
{
|
||||
return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
|
||||
ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
|
||||
ebitmap_equal(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
|
||||
(c1->range.level[1].sens == c2->range.level[1].sens) &&
|
||||
ebitmap_cmp(&c1->range.level[1].cat, &c2->range.level[1].cat));
|
||||
ebitmap_equal(&c1->range.level[1].cat, &c2->range.level[1].cat));
|
||||
}
|
||||
|
||||
static inline void mls_context_destroy(struct context *c)
|
||||
@@ -188,15 +188,15 @@ static inline void context_destroy(struct context *c)
|
||||
mls_context_destroy(c);
|
||||
}
|
||||
|
||||
static inline int context_cmp(const struct context *c1,
|
||||
const struct context *c2)
|
||||
static inline bool context_equal(const struct context *c1,
|
||||
const struct context *c2)
|
||||
{
|
||||
if (c1->len && c2->len)
|
||||
return (c1->len == c2->len && !strcmp(c1->str, c2->str));
|
||||
if (c1->len || c2->len)
|
||||
return 0;
|
||||
return ((c1->user == c2->user) && (c1->role == c2->role) &&
|
||||
(c1->type == c2->type) && mls_context_cmp(c1, c2));
|
||||
(c1->type == c2->type) && mls_context_equal(c1, c2));
|
||||
}
|
||||
|
||||
u32 context_compute_hash(const struct context *c);
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
|
||||
static struct kmem_cache *ebitmap_node_cachep __ro_after_init;
|
||||
|
||||
int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
|
||||
bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2)
|
||||
{
|
||||
const struct ebitmap_node *n1, *n2;
|
||||
|
||||
if (e1->highbit != e2->highbit)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
n1 = e1->node;
|
||||
n2 = e2->node;
|
||||
@@ -41,9 +41,9 @@ int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
|
||||
}
|
||||
|
||||
if (n1 || n2)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)
|
||||
|
||||
@@ -120,7 +120,7 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, u32 bit)
|
||||
(bit) < ebitmap_length(e); \
|
||||
(bit) = ebitmap_next_positive(e, &(n), bit))
|
||||
|
||||
int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2);
|
||||
bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2);
|
||||
int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src);
|
||||
int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
|
||||
const struct ebitmap *e2);
|
||||
|
||||
@@ -29,7 +29,7 @@ struct mls_range {
|
||||
static inline int mls_level_eq(const struct mls_level *l1,
|
||||
const struct mls_level *l2)
|
||||
{
|
||||
return ((l1->sens == l2->sens) && ebitmap_cmp(&l1->cat, &l2->cat));
|
||||
return ((l1->sens == l2->sens) && ebitmap_equal(&l1->cat, &l2->cat));
|
||||
}
|
||||
|
||||
static inline int mls_level_dom(const struct mls_level *l1,
|
||||
|
||||
@@ -3331,7 +3331,7 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
|
||||
__func__, xfrm_sid);
|
||||
goto out;
|
||||
}
|
||||
rc = (mls_context_cmp(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
|
||||
rc = (mls_context_equal(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
|
||||
if (rc)
|
||||
goto out;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ static u32 context_to_sid(struct sidtab *s, struct context *context, u32 hash)
|
||||
hash_for_each_possible_rcu(s->context_to_sid, entry, list, hash) {
|
||||
if (entry->hash != hash)
|
||||
continue;
|
||||
if (context_cmp(&entry->context, context)) {
|
||||
if (context_equal(&entry->context, context)) {
|
||||
sid = entry->sid;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user