Skip to contentSkip to conversation

selabel_partial_match_all

DEV-TOOL - DO NOT APPLY Christian Göttsche 2 participants 2 messages Mar 20 – Apr 2 SELinux security module

lore
Share & tools
lore
#0 lore raw

From: Christian Göttsche <[email protected]>

Tool to test the patch "libselinux: correctly find partial matches".

---
 libselinux/include/selinux/label.h           |   1 +
 libselinux/src/label.c                       |   9 ++
 libselinux/src/label_file.c                  |   6 +
 libselinux/src/label_internal.h              |   1 +
 libselinux/src/libselinux.map                |   5 +
 libselinux/utils/.gitignore                  |   1 +
 libselinux/utils/Makefile                    |   2 +-
 libselinux/utils/selabel_partial_match_all.c | 156 +++++++++++++++++++
 8 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 libselinux/utils/selabel_partial_match_all.c
libselinux/include/selinux/label.h +1 -0
index ce189a3a..cbf4b482 100644
@@ -105,6 +105,7 @@ extern int selabel_lookup_raw(struct selabel_handle *handle, char **con,
 			      const char *key, int type);
 
 extern bool selabel_partial_match(struct selabel_handle *handle, const char *key);
+extern struct lookup_result *selabel_partial_match_all(struct selabel_handle *handle, const char *key);
 
 extern bool selabel_get_digests_all_partial_matches(struct selabel_handle *rec,
 						    const char *key,
libselinux/src/label.c +9 -0
index 2c510290..7269864e 100644
@@ -310,6 +310,15 @@ bool selabel_partial_match(struct selabel_handle *rec, const char *key)
 	return rec->func_partial_match(rec, key);
 }
 
+struct lookup_result *selabel_partial_match_all(struct selabel_handle *rec, const char *key)
+{
+	if (!rec->func_partial_match_all) {
+		return NULL;
+	}
+
+	return rec->func_partial_match_all(rec, key);
+}
+
 bool selabel_get_digests_all_partial_matches(struct selabel_handle *rec,
 					     const char *key,
 					     uint8_t **calculated_digest,
libselinux/src/label_file.c +6 -0
index 31f134f9..2412a6d7 100644
@@ -2204,6 +2204,11 @@ static bool partial_match(struct selabel_handle *rec, const char *key)
 	return !!lookup_common(rec, key, 0, true, &buf);
 }
 
+static struct lookup_result *partial_match_all(struct selabel_handle *rec, const char *key)
+{
+	return lookup_all(rec, key, 0, true, true, NULL);
+}
+
 static struct selabel_lookup_rec *lookup_best_match(struct selabel_handle *rec,
 						    const char *key,
 						    const char **aliases,
@@ -2634,6 +2639,7 @@ int selabel_file_init(struct selabel_handle *rec,
 	rec->func_stats = &stats;
 	rec->func_lookup = &lookup;
 	rec->func_partial_match = &partial_match;
+	rec->func_partial_match_all = &partial_match_all;
 	rec->func_get_digests_all_partial_matches = &get_digests_all_partial_matches;
 	rec->func_hash_all_partial_matches = &hash_all_partial_matches;
 	rec->func_lookup_best_match = &lookup_best_match;
libselinux/src/label_internal.h +1 -0
index 743dbf94..33b93b77 100644
@@ -87,6 +87,7 @@ struct selabel_handle {
 	void (*func_close) (struct selabel_handle *h);
 	void (*func_stats) (struct selabel_handle *h);
 	bool (*func_partial_match) (struct selabel_handle *h, const char *key);
+	struct lookup_result* (*func_partial_match_all) (struct selabel_handle *h, const char *key);
 	bool (*func_get_digests_all_partial_matches) (struct selabel_handle *h,
 						      const char *key,
 						      uint8_t **calculated_digest,
libselinux/src/libselinux.map +5 -0
index 95cd53b0..a62f6bca 100644
@@ -267,3 +267,8 @@ LIBSELINUX_3.10 {
   global:
     selinux_restorecon_get_relabeled_files;
 } LIBSELINUX_3.9;
+
+LIBSELINUX_3.11 {
+  global:
+    selabel_partial_match_all;
+} LIBSELINUX_3.10;
libselinux/utils/.gitignore +1 -0
index 2e10b14f..141fe76c 100644
@@ -22,6 +22,7 @@ selabel_get_digests_all_partial_matches
 selabel_lookup
 selabel_lookup_best_match
 selabel_partial_match
+selabel_partial_match_all
 selinux_check_securetty_context
 selinuxenabled
 selinuxexeccon
libselinux/utils/Makefile +1 -1
index 20dc44eb..c653d71a 100644
@@ -58,7 +58,7 @@ sefcontext_compile: LDLIBS += ../src/libselinux.a -lsepol
 PCRE_USERS = matchpathcon sefcontext_compile selabel_compare \
 	selabel_digest selabel_get_digests_all_partial_matches \
 	selabel_lookup selabel_lookup_best_match \
-	selabel_partial_match
+	selabel_partial_match selabel_partial_match_all
 $(PCRE_USERS): LDLIBS += $(PCRE_LDLIBS)
 
 all: $(TARGETS)
libselinux/utils/selabel_partial_match_all.c new file +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw
Quoted 22 lines · Christian Göttsche

From: Christian Göttsche <[email protected]>

Tool to test the patch "libselinux: correctly find partial matches".

---
 libselinux/include/selinux/label.h           |   1 +
 libselinux/src/label.c                       |   9 ++
 libselinux/src/label_file.c                  |   6 +
 libselinux/src/label_internal.h              |   1 +
 libselinux/src/libselinux.map                |   5 +
 libselinux/utils/.gitignore                  |   1 +
 libselinux/utils/Makefile                    |   2 +-
 libselinux/utils/selabel_partial_match_all.c | 156 +++++++++++++++++++
 8 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 libselinux/utils/selabel_partial_match_all.c
libselinux/include/selinux/label.h +0 -0
index ce189a3a..cbf4b482 100644

libselinux/include/selinux/label.h extern int selabel_lookup_raw(struct selabel_handle *handle, char **con, · line 109

Quoted 5 lines
libselinux/include/selinux/label.h +1 -0
@@ -105,6 +105,7 @@ extern int selabel_lookup_raw(struct selabel_handle *handle, char **con,
                              const char *key, int type);
 
 extern bool selabel_partial_match(struct selabel_handle *handle, const char *key);
+extern struct lookup_result *selabel_partial_match_all(struct selabel_handle *handle, const char *key);
 

I think there is value in exposing a similar function beyond this test tool. What about something like:

extern bool selabel_partial_match_all(struct selabel_handle *handle, const char *key, char ***cons, size_t num_cons);

which would populate cons and num_cons with the contexts that are partially matching?