forked from soccera/rdo
Reduce memory access in runprog
Previously, we used a for loop to rearrange argv to omit the first argument, the rdo call itself. It's way smarter to just dereference the first argv argument, and use it as an argv pointer, to achieve the same result.
This commit is contained in:
parent
9395a6ca7e
commit
08d66239fa
1 changed files with 7 additions and 10 deletions
17
rdo.c
17
rdo.c
|
@ -33,19 +33,16 @@ void getconf(FILE* fp, const char* entry, char* result, size_t len_result) {
|
|||
errx(1, "Could not get '%s' entry in config", entry);
|
||||
}
|
||||
|
||||
int runprog(int argc, char** argv) {
|
||||
for(int i=0; i<argc; i++)
|
||||
argv[i] = argv[i + 1];
|
||||
|
||||
void runprog(char** program_argv) {
|
||||
if (setuid(0) < 0)
|
||||
err(1, "Could not setuid");
|
||||
if (setgid(0) < 0)
|
||||
err(1, "Could not setgid");
|
||||
|
||||
if (execvp(argv[0], argv) != 0)
|
||||
perror(argv[0]);
|
||||
// NOTE: this does not return when no error occurred.
|
||||
execvp(program_argv[0], program_argv);
|
||||
|
||||
return 0;
|
||||
err(1, program_argv[0]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
@ -63,7 +60,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
int ruid = getuid();
|
||||
if (ruid == 0)
|
||||
return runprog(argc, argv);
|
||||
runprog(&argv[1]);
|
||||
|
||||
FILE* fp = fopen("/etc/rdo.conf", "r");
|
||||
|
||||
|
@ -79,7 +76,7 @@ int main(int argc, char** argv) {
|
|||
fclose(fp);
|
||||
|
||||
if (getsession(getppid(), ts_ttl) == 0)
|
||||
return runprog(argc, argv);
|
||||
runprog(&argv[1]);
|
||||
|
||||
struct passwd* p = getpwnam(username);
|
||||
if (!p) {
|
||||
|
@ -111,7 +108,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
if (strcmp(shadowEntry->sp_pwdp, hashed_pw) == 0) {
|
||||
setsession(getppid(), ts_ttl);
|
||||
return runprog(argc, argv);
|
||||
runprog(&argv[1]);
|
||||
}
|
||||
|
||||
usleep(sleep_ms);
|
||||
|
|
Loading…
Add table
Reference in a new issue