mirror of
https://github.com/topjohnwu/selinux.git
synced 2024-12-02 16:46:18 +00:00
libsepol/cil: Refactor helper function for cil_gen_node()
Change the name of cil_is_datum_multiple_decl() to cil_allow_multiple_decls() and make it static. The new function takes the CIL db and the flavors of the old and new datum as arguments. Also, put all of the logic of determining if multiple declarations are allowed into the new function. Finally, update the call from cil_gen_node(). Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
parent
22fb6f477b
commit
63ce05ba07
@ -82,30 +82,24 @@ exit:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int cil_allow_multiple_decls(struct cil_db *db, enum cil_flavor f_new, enum cil_flavor f_old)
|
||||||
* Determine whether or not multiple declarations of the same key can share a
|
|
||||||
* datum, given the new datum and the one already present in a given symtab.
|
|
||||||
*/
|
|
||||||
int cil_is_datum_multiple_decl(__attribute__((unused)) struct cil_symtab_datum *cur,
|
|
||||||
struct cil_symtab_datum *old,
|
|
||||||
enum cil_flavor f)
|
|
||||||
{
|
{
|
||||||
int rc = CIL_FALSE;
|
if (f_new != f_old) {
|
||||||
|
return CIL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
switch (f) {
|
switch (f_new) {
|
||||||
case CIL_TYPE:
|
case CIL_TYPE:
|
||||||
case CIL_TYPEATTRIBUTE:
|
case CIL_TYPEATTRIBUTE:
|
||||||
if (!old || f != FLAVOR(old)) {
|
if (db->multiple_decls) {
|
||||||
rc = CIL_FALSE;
|
return CIL_TRUE;
|
||||||
} else {
|
|
||||||
/* type and typeattribute statements insert empty datums */
|
|
||||||
rc = CIL_TRUE;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
|
return CIL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor)
|
int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor)
|
||||||
@ -135,8 +129,7 @@ int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_s
|
|||||||
cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(ast_node), key);
|
cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(ast_node), key);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!db->multiple_decls ||
|
if (!cil_allow_multiple_decls(db, nflavor, FLAVOR(prev))) {
|
||||||
!cil_is_datum_multiple_decl(datum, prev, nflavor)) {
|
|
||||||
/* multiple_decls not ok, ret error */
|
/* multiple_decls not ok, ret error */
|
||||||
struct cil_tree_node *node = NODE(prev);
|
struct cil_tree_node *node = NODE(prev);
|
||||||
cil_log(CIL_ERR, "Re-declaration of %s %s\n",
|
cil_log(CIL_ERR, "Re-declaration of %s %s\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user