libselinux: add selabel_cmp interface and label_file backend
PATCH 1/1 libselinux: add selabel_cmp interface and label_file backend
Add a selabel_cmp() interface for comparing two label configurations, and implement it for the file backend (i.e. for file_contexts). This allows comparing two file_contexts configurations to see if the first is a subset of, equal/identical to, a superset of, or incomparable to the second. The motivating use case is to allow comparing two file_contexts.bin files in Android CTS to confirm that a device file_contexts.bin file contains all of the entries in the AOSP general file_contexts.
Change-Id I0fe63e0c7f11ae067b5aac2f468f7842e5d76986
Signed-off-by Stephen Smalley <[email protected]>
--- libselinux/include/selinux/label.h | 20 +++++++++ libselinux/src/label.c | 9 ++++ libselinux/src/label_file.c | 92 ++++++++++++++++++++++++++++++++++++++ libselinux/src/label_internal.h | 2 + 4 files changed, 123 insertions(+)
libselinux/include/selinux/label.h +20 -0
@@ -106,6 +106,26 @@ int selabel_lookup_best_match(struct selabel_handle *rec, char **con,int selabel_lookup_best_match_raw (struct selabel_handle *rec,char **con,const char *key,const char **aliases,int type); +enum selabel_cmp_result { +SELABEL_SUBSET , +SELABEL_EQUAL , +SELABEL_SUPERSET , +SELABEL_INCOMPARABLE +}; + +/** +* selabel_cmp - Compare two label configurations. +* @h1: handle for the first label configuration +* @h2: handle for the first label configuration +* +* Compare two label configurations. +* Return %SELABEL_SUBSET if @h1 is a subset of @h2, %SELABEL_EQUAL +* if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset +* of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable. +*/ +enum selabel_cmp_result selabel_cmp (struct selabel_handle *h1, +struct selabel_handle *h2); +/** * selabel_stats - log labeling operation statistics. * @handle: specifies backend instance to query
libselinux/src/label.c +9 -0
@@ -369,6 +369,15 @@ int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con,return *con ?0 :-1 ; } +enum selabel_cmp_result selabel_cmp (struct selabel_handle *h1, +struct selabel_handle *h2) +{ +if (!h1->func_cmp || h1->func_cmp != h2->func_cmp) +return SELABEL_INCOMPARABLE ; + +return h1->func_cmp (h1, h2); +} +void selabel_close (struct selabel_handle *rec) {selabel_subs_fini (rec->subs);
libselinux/src/label_file.c +92 -0
110 lines not on this page · raw message
libselinux/src/label_internal.h +2 -0
@@ -68,6 +68,8 @@ struct selabel_handle {const char *key, const char **aliases, int type); +enum selabel_cmp_result (*func_cmp)(struct selabel_handle *h1, +struct selabel_handle *h2);/* supports backend-specific state information */ void *data;
Signature · 1 line
2.1.0