diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-05-11 23:43:28 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-05-11 23:43:28 +0200 |
commit | 09eeb8c958c15232b6255d135b3161ec74a7939c (patch) | |
tree | 5dc14768227ae5d6a3d775559825b101ba1d6662 | |
parent | f6154f653c36b92e9027dd9ccc57146b157819cb (diff) |
suidcmd: additional checks, error printing
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | dummyshell.c | 2 | ||||
-rw-r--r-- | suidcmd.c | 35 |
3 files changed, 31 insertions, 8 deletions
@@ -40,4 +40,4 @@ ***********/ /* suid commands (e.g.: "first-cmd", "second-cmd", "nth-cmd") */ -#define SUIDCMD_CMDS "/usr/sbin/ether-wake", "/bin/ping" +#define SUIDCMD_CMDS "/usr/sbin/etherwake", "/usr/sbin/ether-wake", "/bin/ping" diff --git a/dummyshell.c b/dummyshell.c index 115b317..db69fb1 100644 --- a/dummyshell.c +++ b/dummyshell.c @@ -123,7 +123,7 @@ static char readInput(char* buf, size_t* siz, size_t szMax, char key, int flags) default: if (isprint(key) && *siz < szMax) buf[(*siz)++] = key; - break; + break; } return key; } @@ -11,6 +11,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#include <errno.h> #include <string.h> /* memset(...), strstr(...) */ #include <sys/wait.h> #include <libgen.h> /* basename(...) */ @@ -120,30 +121,52 @@ int main(int argc, char** argv) } struct stat buf; + if (lstat(argv[0], &buf) != 0) { + perror("lstat"); + return 1; + } + if (!S_ISLNK(buf.st_mode)) { + printCmds(); + return 0; + } + + static char *real_arg0 = NULL; + real_arg0 = realpath(argv[0], NULL); + if (!real_arg0) { + perror("realpath"); + return 1; + } + if (stat(argv[0], &buf) != 0) { perror("stat"); + return 1; } if ((buf.st_mode & S_ISUID) == 0) { - fprintf(stderr, "%s: not set suid\n", argv[0]); + fprintf(stderr, "%s: not suid\n", real_arg0); return 1; } const char* runpath = getCmd(argv[0]); if (!runpath) { - fprintf(stderr, "%s not runnable cmd\n", argv[0]); + fprintf(stderr, "%s: %s not runnable cmd\n", real_arg0, argv[0]); printCmds(); return 1; } + if (stat(runpath, &buf) != 0) { + fprintf(stderr, "%s: %s error: %s\n", real_arg0, runpath, strerror(errno)); + return 1; + } + if (getresuid(&ruid, &euid, &suid) != 0) { - perror("getresuid()"); + perror("getresuid"); } else { printf("%s: RUID:%u , EUID:%u , SUID:%u\n", argv[0], ruid, euid, suid); } - if (setuid(0) != 0) { - perror("setuid(0)"); - } else printf("%s: setuid(0)\n", argv[0]); + if (setresuid(0,0,0) != 0) { + perror("setresuid"); + } char* cmd = NULL; if (asprintf(&cmd, "%s", runpath) <= 0) { |