2 * reaper.c: A process capable of killing `runner`
4 * Copyright (C) 2018 Citrix Systems UK Ltd
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <sys/types.h>
29 int main(int argc
, char ** argv
) {
33 errx(EXIT_FAILURE
, "Usage: kill-rogue <rogue-uid> <reaper-uid>");
36 uid_t tuid
= atoi(argv
[1]);
37 uid_t xuid
= atoi(argv
[2]);
40 if (tuid
== 0 || xuid
== 0)
42 errx(EXIT_FAILURE
, "rouge-uid or reaper-uid is 0, which should not");
45 /* Check to make sure we have enough permissions */
49 errx(EXIT_FAILURE
, "Must run as euid 0 to set uid");
53 * Set euid to TARGET_UID so that we can kill the rogue 'runner'; but
54 * set ruid to REAPER_UID so that the rogue runner can't kill us.
56 if ( setresuid(xuid
, tuid
, 0) ) {
57 err(EXIT_FAILURE
, "Setting uid to target");
62 err(EXIT_FAILURE
, "No processes killed");
64 warnx("At least one process killed successfully");