From 9cc6b5cf405bb0ab3dfbd509b79fb9fb7a90da93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 3 Feb 2021 18:16:53 +0100 Subject: [PATCH] libselinux/getconlist: report failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check the given context a priori, to print a more user friendly message, opposed to a generic following get_ordered_context_list/_with_level failure. Notify the user about failures of get_ordered_context_list/_with_level, so no-context-found and a failure results are distinguishable. Signed-off-by: Christian Göttsche --- libselinux/utils/getconlist.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libselinux/utils/getconlist.c b/libselinux/utils/getconlist.c index 29c16640..76654b75 100644 --- a/libselinux/utils/getconlist.c +++ b/libselinux/utils/getconlist.c @@ -58,8 +58,14 @@ int main(int argc, char **argv) free(level); return 2; } - } else + } else { cur_context = argv[optind + 1]; + if (security_check_context(cur_context) != 0) { + fprintf(stderr, "Given context '%s' is invalid.\n", cur_context); + free(level); + return 3; + } + } /* Get the list and print it */ if (level) @@ -72,6 +78,11 @@ int main(int argc, char **argv) for (i = 0; list[i]; i++) puts(list[i]); freeconary(list); + } else { + fprintf(stderr, "get_ordered_context_list%s failure: %d(%s)\n", + level ? "_with_level" : "", errno, strerror(errno)); + free(level); + return 4; } free(level);