|
|
|
@ -103,22 +103,35 @@ int main (int argc, char *argv[]) |
|
|
|
|
shell = "/bin/sh"; |
|
|
|
|
|
|
|
|
|
/* Set argc and argv */ |
|
|
|
|
char *command = NULL; |
|
|
|
|
int size, popind = optind; |
|
|
|
|
if (argc - optind) { |
|
|
|
|
for (size = 0; optind < argc; optind++) |
|
|
|
|
size += strlen(argv[optind]) + 1; |
|
|
|
|
command = malloc(sizeof(char) * size + 1); |
|
|
|
|
if (!command) { |
|
|
|
|
int c_argc = argc - optind; |
|
|
|
|
char **c_argv; |
|
|
|
|
if (c_argc) { |
|
|
|
|
c_argv = malloc(sizeof(char *) * (c_argc + 1)); |
|
|
|
|
if (!c_argv) { |
|
|
|
|
fprintf(stderr, "malloc: %s\n", strerror(errno)); |
|
|
|
|
exit(errno); |
|
|
|
|
} |
|
|
|
|
memset(command, 0, size + 1); |
|
|
|
|
for (optind = popind; optind < argc; optind++) { |
|
|
|
|
strcat(command, argv[optind]); |
|
|
|
|
strcat(command, " "); |
|
|
|
|
for (int i = 0; optind < argc; optind++, i++) { |
|
|
|
|
c_argv[i] = strdup(argv[optind]); |
|
|
|
|
if (!c_argv[i]) { |
|
|
|
|
fprintf(stderr, "strdup: %s\n", strerror(errno)); |
|
|
|
|
exit(errno); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
c_argc = 1; |
|
|
|
|
c_argv = malloc(sizeof(char *) * (c_argc + 1)); |
|
|
|
|
if (!c_argv) { |
|
|
|
|
fprintf(stderr, "malloc: %s\n", strerror(errno)); |
|
|
|
|
exit(errno); |
|
|
|
|
} |
|
|
|
|
c_argv[0] = strdup(shell); |
|
|
|
|
if (!c_argv[0]) { |
|
|
|
|
fprintf(stderr, "strdup: %s\n", strerror(errno)); |
|
|
|
|
exit(errno); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
c_argv[c_argc] = NULL; |
|
|
|
|
|
|
|
|
|
/* Authenticate */ |
|
|
|
|
if (authenticate(uname) != PAM_SUCCESS) |
|
|
|
@ -135,17 +148,16 @@ int main (int argc, char *argv[]) |
|
|
|
|
|
|
|
|
|
/* Execute the command */ |
|
|
|
|
int err; |
|
|
|
|
if (command) |
|
|
|
|
err = execl(shell, shell, "-c", command, (char *)NULL); |
|
|
|
|
else |
|
|
|
|
err = execl(shell, shell, (char *)NULL); |
|
|
|
|
err = execvp(c_argv[0], c_argv); |
|
|
|
|
if (err == -1) |
|
|
|
|
fprintf(stderr, "execl: %s\n", strerror(errno)); |
|
|
|
|
|
|
|
|
|
/* Cleanup and return */ |
|
|
|
|
fail_end: |
|
|
|
|
/* Free up the copied argv */ |
|
|
|
|
free(command); |
|
|
|
|
for (int i=0; c_argv[i]; i++) |
|
|
|
|
free(c_argv[i]); |
|
|
|
|
free(c_argv); |
|
|
|
|
return errno; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|