From efe21d7fb18501b94da66445e822ab43a8e4a4bf Mon Sep 17 00:00:00 2001 From: William Roberts Date: Mon, 27 Apr 2020 15:13:40 -0500 Subject: [PATCH] matchpathcon: create internal matchpathcon_fini interface Now that matchpathcon_fini is marked deprecated, create an matchpathcon_fini_internal interface for internal users. We create a new header file for matchpathcon_internal interfaces. Signed-off-by: William Roberts --- libselinux/src/matchpathcon.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c index bddf77a4..2ec66650 100644 --- a/libselinux/src/matchpathcon.c +++ b/libselinux/src/matchpathcon.c @@ -315,9 +315,19 @@ void matchpathcon_filespec_destroy(void) fl_head = NULL; } +static void matchpathcon_fini_internal(void) +{ + free_array_elts(); + + if (hnd) { + selabel_close(hnd); + hnd = NULL; + } +} + static void matchpathcon_thread_destructor(void __attribute__((unused)) *ptr) { - matchpathcon_fini(); + matchpathcon_fini_internal(); } void __attribute__((destructor)) matchpathcon_lib_destructor(void); @@ -359,12 +369,7 @@ int matchpathcon_init(const char *path) void matchpathcon_fini(void) { - free_array_elts(); - - if (hnd) { - selabel_close(hnd); - hnd = NULL; - } + matchpathcon_fini_internal(); } /* @@ -427,7 +432,7 @@ out: return rc; } -int matchpathcon(const char *path, mode_t mode, char ** con) +static int matchpathcon_internal(const char *path, mode_t mode, char ** con) { char stackpath[PATH_MAX + 1]; char *p = NULL; @@ -448,9 +453,13 @@ int matchpathcon(const char *path, mode_t mode, char ** con) selabel_lookup(hnd, con, path, mode); } +int matchpathcon(const char *path, mode_t mode, char ** con) { + return matchpathcon_internal(path, mode, con); +} + int matchpathcon_index(const char *name, mode_t mode, char ** con) { - int i = matchpathcon(name, mode, con); + int i = matchpathcon_internal(name, mode, con); if (i < 0) return -1;