mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-07 10:01:20 +00:00
qpol.i: throw exceptions when getting the conditional block on unconditional rules
Standardize on AttributeError for the exception type.
This commit is contained in:
parent
3434618aef
commit
fcfba569cc
@ -2514,16 +2514,13 @@ typedef struct qpol_avrule {} qpol_avrule_t;
|
|||||||
%exception cond {
|
%exception cond {
|
||||||
$action
|
$action
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Rule is not conditional.");
|
PyErr_SetString(PyExc_AttributeError, "Rule is not conditional.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const qpol_cond_t *cond(qpol_policy_t *p) {
|
const qpol_cond_t *cond(qpol_policy_t *p) {
|
||||||
const qpol_cond_t *c;
|
const qpol_cond_t *c;
|
||||||
if (qpol_avrule_get_cond(p, self, &c)) {
|
qpol_avrule_get_cond(p, self, &c);
|
||||||
SWIG_exception(SWIG_ValueError, "Could not get conditional for av rule");
|
|
||||||
}
|
|
||||||
fail:
|
|
||||||
return c;
|
return c;
|
||||||
};
|
};
|
||||||
int is_enabled(qpol_policy_t *p) {
|
int is_enabled(qpol_policy_t *p) {
|
||||||
@ -2534,14 +2531,22 @@ typedef struct qpol_avrule {} qpol_avrule_t;
|
|||||||
fail:
|
fail:
|
||||||
return (int) e;
|
return (int) e;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
%exception which_list {
|
||||||
|
$action
|
||||||
|
if (result < 0) {
|
||||||
|
PyErr_SetString(PyExc_AttributeError, "Rule is not conditional.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
int which_list(qpol_policy_t *p) {
|
int which_list(qpol_policy_t *p) {
|
||||||
const qpol_cond_t *c;
|
const qpol_cond_t *c;
|
||||||
uint32_t which = 0;
|
uint32_t which = 0;
|
||||||
qpol_avrule_get_cond(p, self, &c);
|
qpol_avrule_get_cond(p, self, &c);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
SWIG_exception(SWIG_TypeError, "Rule is not conditional");
|
return -1;
|
||||||
} else if (qpol_avrule_get_which_list(p, self, &which)) {
|
} else if (qpol_avrule_get_which_list(p, self, &which)) {
|
||||||
SWIG_exception(SWIG_ValueError, "Could not get conditional list for av rule");
|
return -1;
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
return (int) which;
|
return (int) which;
|
||||||
@ -2626,16 +2631,13 @@ typedef struct qpol_terule {} qpol_terule_t;
|
|||||||
%exception cond {
|
%exception cond {
|
||||||
$action
|
$action
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Rule is not conditional.");
|
PyErr_SetString(PyExc_AttributeError, "Rule is not conditional.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const qpol_cond_t *cond(qpol_policy_t *p) {
|
const qpol_cond_t *cond(qpol_policy_t *p) {
|
||||||
const qpol_cond_t *c;
|
const qpol_cond_t *c;
|
||||||
if (qpol_terule_get_cond(p, self, &c)) {
|
qpol_terule_get_cond(p, self, &c);
|
||||||
SWIG_exception(SWIG_ValueError, "Could not get conditional for te rule");
|
|
||||||
}
|
|
||||||
fail:
|
|
||||||
return c;
|
return c;
|
||||||
};
|
};
|
||||||
int is_enabled(qpol_policy_t *p) {
|
int is_enabled(qpol_policy_t *p) {
|
||||||
@ -2646,18 +2648,27 @@ typedef struct qpol_terule {} qpol_terule_t;
|
|||||||
fail:
|
fail:
|
||||||
return (int) e;
|
return (int) e;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
%exception which_list {
|
||||||
|
$action
|
||||||
|
if (result < 0) {
|
||||||
|
PyErr_SetString(PyExc_AttributeError, "Rule is not conditional.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
int which_list(qpol_policy_t *p) {
|
int which_list(qpol_policy_t *p) {
|
||||||
const qpol_cond_t *c;
|
const qpol_cond_t *c;
|
||||||
uint32_t which = 0;
|
uint32_t which = 0;
|
||||||
qpol_terule_get_cond(p, self, &c);
|
qpol_terule_get_cond(p, self, &c);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
SWIG_exception(SWIG_TypeError, "Rule is not conditional");
|
return -1;
|
||||||
} else if (qpol_terule_get_which_list(p, self, &which)) {
|
} else if (qpol_terule_get_which_list(p, self, &which)) {
|
||||||
SWIG_exception(SWIG_ValueError, "Could not get conditional list for te rule");
|
return -1;
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
return (int) which;
|
return (int) which;
|
||||||
};
|
};
|
||||||
|
|
||||||
%newobject syn_terule_iter(qpol_policy_t*);
|
%newobject syn_terule_iter(qpol_policy_t*);
|
||||||
qpol_iterator_t *syn_terule_iter(qpol_policy_t *p) {
|
qpol_iterator_t *syn_terule_iter(qpol_policy_t *p) {
|
||||||
qpol_iterator_t *iter;
|
qpol_iterator_t *iter;
|
||||||
|
@ -92,10 +92,7 @@ class BaseTERule(rule.PolicyRule):
|
|||||||
"""The rule's conditional expression."""
|
"""The rule's conditional expression."""
|
||||||
try:
|
try:
|
||||||
return boolcond.condexpr_factory(self.policy, self.qpol_symbol.cond(self.policy))
|
return boolcond.condexpr_factory(self.policy, self.qpol_symbol.cond(self.policy))
|
||||||
except (AttributeError, ValueError):
|
except AttributeError:
|
||||||
# AttributeError: name filetrans rules cannot be conditional
|
|
||||||
# so no member function
|
|
||||||
# ValueError: The rule is not conditional
|
|
||||||
raise exception.RuleNotConditional
|
raise exception.RuleNotConditional
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -103,10 +100,7 @@ class BaseTERule(rule.PolicyRule):
|
|||||||
"""The conditional block of the rule (T/F)"""
|
"""The conditional block of the rule (T/F)"""
|
||||||
try:
|
try:
|
||||||
return bool(self.qpol_symbol.which_list(self.policy))
|
return bool(self.qpol_symbol.which_list(self.policy))
|
||||||
except (AttributeError, ValueError):
|
except AttributeError:
|
||||||
# AttributeError: name filetrans rules cannot be conditional
|
|
||||||
# so no member function
|
|
||||||
# ValueError: The rule is not conditional
|
|
||||||
raise exception.RuleNotConditional
|
raise exception.RuleNotConditional
|
||||||
|
|
||||||
def expand(self):
|
def expand(self):
|
||||||
|
@ -48,7 +48,7 @@ class AVRuleTest(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
# this actually comes out of condexpr_factory
|
# this actually comes out of condexpr_factory
|
||||||
# but it's simpler to have here
|
# but it's simpler to have here
|
||||||
mock_rule.cond.side_effect = ValueError
|
mock_rule.cond.side_effect = AttributeError
|
||||||
|
|
||||||
return te_rule_factory(self.p, mock_rule)
|
return te_rule_factory(self.p, mock_rule)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ class TERuleTest(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
# this actually comes out of condexpr_factory
|
# this actually comes out of condexpr_factory
|
||||||
# but it's simpler to have here
|
# but it's simpler to have here
|
||||||
mock_rule.cond.side_effect = ValueError
|
mock_rule.cond.side_effect = AttributeError
|
||||||
|
|
||||||
mock_rule.rule_type.return_value = ruletype
|
mock_rule.rule_type.return_value = ruletype
|
||||||
mock_rule.source_type.return_value = source
|
mock_rule.source_type.return_value = source
|
||||||
|
Loading…
Reference in New Issue
Block a user