@@ -119,12 +119,11 @@ static inline int selabel_is_validate_set(const struct selinux_opt *opts,
return 0;
}
-int selabel_validate(const struct selabel_handle *rec,
- struct selabel_lookup_rec *contexts)
+int selabel_validate(struct selabel_lookup_rec *contexts)
{
int rc = 0;
- if (!rec->validating || contexts->validated)
+ if (contexts->validated)
goto out;
rc = selinux_validate(&contexts->ctx_raw);
@@ -126,7 +126,7 @@ static int process_line(struct selabel_handle *rec,
spec_arr[nspec].lr.ctx_raw = context;
if (rec->validating) {
- if (selabel_validate(rec, &spec_arr[nspec].lr) < 0) {
+ if (selabel_validate(&spec_arr[nspec].lr) < 0) {
selinux_log(SELINUX_ERROR,
"%s: line %u has invalid context %s\n",
path, lineno, spec_arr[nspec].lr.ctx_raw);
@@ -404,7 +404,7 @@ end_arch_check:
spec->lr.ctx_raw = str_buf;
if (strcmp(spec->lr.ctx_raw, "<<none>>") && rec->validating) {
- if (selabel_validate(rec, &spec->lr) < 0) {
+ if (selabel_validate(&spec->lr) < 0) {
selinux_log(SELINUX_ERROR,
"%s: context %s is invalid\n",
path, spec->lr.ctx_raw);
@@ -118,8 +118,7 @@ struct selabel_handle {
* Validation function
*/
extern int
-selabel_validate(const struct selabel_handle *rec,
- struct selabel_lookup_rec *contexts) ;
+selabel_validate(struct selabel_lookup_rec *contexts);
/*
* Compatibility support
@@ -46,8 +46,8 @@ int compat_validate(const struct selabel_handle *rec,
rc = myinvalidcon(path, lineno, *ctx);
else if (mycanoncon)
rc = mycanoncon(path, lineno, ctx);
- else {
- rc = selabel_validate(rec, contexts);
+ else if (rec->validating) {
+ rc = selabel_validate(contexts);
if (rc < 0) {
if (lineno) {
COMPAT_LOG(SELINUX_WARNING,
@@ -58,7 +58,8 @@ int compat_validate(const struct selabel_handle *rec,
"%s: has invalid context %s\n", path, *ctx);
}
}
- }
+ } else
+ rc = 0;
return rc ? -1 : 0;
}
Move the check whether to validate or not to the caller, to avoid all having to carry the complete selabel_handle around. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libselinux/src/label.c | 5 ++--- libselinux/src/label_backends_android.c | 2 +- libselinux/src/label_file.c | 2 +- libselinux/src/label_internal.h | 3 +-- libselinux/src/matchpathcon.c | 7 ++++--- 5 files changed, 9 insertions(+), 10 deletions(-)