From: Lennart Poettering Date: Tue, 25 May 2021 15:40:54 +0000 (+0200) Subject: loginctl: kill calling user when invoked with empty string X-Git-Tag: v249-rc1~153^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=68892f94aee1400cebbe9f7360cc4a5804c3c2b1;p=thirdparty%2Fsystemd.git loginctl: kill calling user when invoked with empty string A suggested by: #19711 --- diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 7a2b13e4426..cbb6518f4d2 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1086,9 +1086,15 @@ static int terminate_user(int argc, char *argv[], void *userdata) { for (int i = 1; i < argc; i++) { uid_t uid; - r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0); - if (r < 0) - return log_error_errno(r, "Failed to look up user %s: %m", argv[i]); + if (isempty(argv[i])) + uid = getuid(); + else { + const char *u = argv[i]; + + r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0); + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", argv[i]); + } r = bus_call_method(bus, bus_login_mgr, "TerminateUser", &error, NULL, "u", (uint32_t) uid); if (r < 0) @@ -1114,9 +1120,15 @@ static int kill_user(int argc, char *argv[], void *userdata) { for (int i = 1; i < argc; i++) { uid_t uid; - r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0); - if (r < 0) - return log_error_errno(r, "Failed to look up user %s: %m", argv[i]); + if (isempty(argv[i])) + uid = getuid(); + else { + const char *u = argv[i]; + + r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0); + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", argv[i]); + } r = bus_call_method( bus,