From ce624788c46257e18398f770ee2f90bebb36d474 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Tue, 7 Sep 2021 12:25:58 +1100 Subject: [PATCH] provide -h option. Deny regular user execution --- src/extra-tools/66-nuke.c | 54 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/extra-tools/66-nuke.c b/src/extra-tools/66-nuke.c index 99a0df7f..2f3162f7 100644 --- a/src/extra-tools/66-nuke.c +++ b/src/extra-tools/66-nuke.c @@ -11,14 +11,60 @@ * This file may not be copied, modified, propagated, or distributed * except according to the terms contained in the LICENSE file./ * - * This file is a strict copy of s6-echo.c file - * coming from skarnet software at https://skarnet.org/software/s6-portable-utils. + * This file is a modified copy of s6-linux-init-nuke.c file + * coming from skarnet software at https://skarnet.org/software/s6-linux-init. * All credits goes to Laurent Bercot <ska-remove-this-if-you-are-not-a-bot@skarnet.org> * */ #include <signal.h> +#include <unistd.h> -int main (void) +#include <oblibs/log.h> + +#include <skalibs/sgetopt.h> + +#define USAGE "66-nuke" + +static inline void info_help (void) +{ + DEFAULT_MSG = 0 ; + + static char const *help = +"\n" +"options :\n" +" -h: print this help\n" +; + + log_info(USAGE,"\n",help) ; +} + +int main (int argc, char const *const *argv) { - return kill(-1, SIGKILL) < 0 ; + + { + subgetopt_t l = SUBGETOPT_ZERO ; + + for (;;) + { + int opt = subgetopt_r(argc,argv, "h", &l) ; + + if (opt == -1) break ; + switch (opt) + { + case 'h' : + + info_help(); + return 0 ; + + default : + + log_usage(USAGE) ; + } + } + } + + if (getuid()) + log_die(LOG_EXIT_SYS,"You must be root to use this program") ; + + return kill(-1, SIGKILL) < 0 ; } -- GitLab