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