diff options
author | xSlendiX <gamingxslendix@gmail.com> | 2021-09-08 01:23:24 +0300 |
---|---|---|
committer | xSlendiX <gamingxslendix@gmail.com> | 2021-09-08 01:23:24 +0300 |
commit | 7d2966b3f73cca5560b5aea1e47688190a22d8d3 (patch) | |
tree | 1cd1db02d27f28194887c2b285509933e3e8a949 | |
parent | 253e48af77129cded4919c734e3f990cb80861c7 (diff) |
Replace system call with execvpe
-rw-r--r-- | sus.c | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -1,5 +1,7 @@ +#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <termios.h> @@ -7,14 +9,11 @@ #include <string.h> -#define _XOPEN_SOURCE - #include <fcntl.h> #include <grp.h> #include <pwd.h> #include <shadow.h> #include <sys/types.h> -#include <unistd.h> #include <errno.h> @@ -98,13 +97,13 @@ int main(int argc, char** argv) memmove(username, username + 1, strlen(username)); } - char* command = ""; - for (int i = command_start; i < argc; i++) { - cats(&command, argv[i]); - cats(&command, " "); - } + // char* command = ""; + // for (int i = command_start; i < argc; i++) { + // cats(&command, argv[i]); + // cats(&command, " "); + // } - command[strlen(command) - 1] = '\0'; + // command[strlen(command) - 1] = '\0'; if (username[0] == '\0') uid = 0; @@ -113,10 +112,13 @@ int main(int argc, char** argv) return 1; } - if (fork() == 0) { - setuid(uid); - system(command); - } + argv += command_start; + setuid(uid); + char* path = getenv("PATH"); + char pathenv[strlen(path) + sizeof("PATH=")]; + sprintf(pathenv, "PATH=%s", path); + char* envp[] = { pathenv, NULL }; + execvpe(argv[0], argv, envp); return 0; } |