From: Masatake YAMATO Date: Tue, 23 Jan 2024 20:20:49 +0000 (+0900) Subject: lsfd: add --_drop-prvilege option for testing purpose X-Git-Tag: v2.42-start~545^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd38c759ea0c42071859c0454aa3f5822f953438;p=thirdparty%2Futil-linux.git lsfd: add --_drop-prvilege option for testing purpose Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 6286577a50..0e59781ab2 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -1909,6 +1909,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -C, --counter : define custom counter for --summary output\n"), out); fputs(_(" --dump-counters dump counter definitions\n"), out); fputs(_(" --summary[=] print summary information (only, append, or never)\n"), out); + fputs(_(" --_drop-privilege (testing purpose) do setuid(1) just after starting\n"), out); fputs(USAGE_SEPARATOR, out); fputs(_(" -H, --list-columns list the available columns\n"), out); @@ -2253,6 +2254,7 @@ int main(int argc, char *argv[]) OPT_DEBUG_FILTER = CHAR_MAX + 1, OPT_SUMMARY, OPT_DUMP_COUNTERS, + OPT_DROP_PRIVILEGE, }; static const struct option longopts[] = { { "noheadings", no_argument, NULL, 'n' }, @@ -2271,6 +2273,7 @@ int main(int argc, char *argv[]) { "counter", required_argument, NULL, 'C' }, { "dump-counters",no_argument, NULL, OPT_DUMP_COUNTERS }, { "list-columns",no_argument, NULL, 'H' }, + { "_drop-privilege",no_argument,NULL,OPT_DROP_PRIVILEGE }, { NULL, 0, NULL, 0 }, }; @@ -2347,6 +2350,10 @@ int main(int argc, char *argv[]) case OPT_DUMP_COUNTERS: dump_counters = true; break; + case OPT_DROP_PRIVILEGE: + if (setuid(1) == -1) + err(EXIT_FAILURE, _("failed to drop privilege")); + break; case 'V': print_version(EXIT_SUCCESS); case 'h':