forked from soccera/rdo
Check uid before opening file
This commit is contained in:
parent
a9fcfe3be9
commit
9948bd3fc7
1 changed files with 8 additions and 7 deletions
15
rdo.c
15
rdo.c
|
@ -50,22 +50,23 @@ int main(int argc, char** argv) {
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
errx(1, "Please specify a program to run");
|
errx(1, "Please specify a program to run");
|
||||||
|
|
||||||
|
int ruid = getuid();
|
||||||
|
if (ruid == 0) {
|
||||||
|
runprog(argc, argv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
FILE* fp = fopen("/etc/rdo.conf", "r");
|
FILE* fp = fopen("/etc/rdo.conf", "r");
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
err(1, "Could not open /etc/rdo.conf");
|
err(1, "Could not open /etc/rdo.conf");
|
||||||
|
|
||||||
int ruid = getuid();
|
|
||||||
if (ruid == 0) {
|
|
||||||
fclose(fp);
|
|
||||||
runprog(argc, argv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
getconf(fp, "username", username, sizeof(username));
|
getconf(fp, "username", username, sizeof(username));
|
||||||
getconf(fp, "wrong_pw_sleep", wrong_pw_sleep, sizeof(wrong_pw_sleep));
|
getconf(fp, "wrong_pw_sleep", wrong_pw_sleep, sizeof(wrong_pw_sleep));
|
||||||
sleep_ms = atoi(wrong_pw_sleep) * 1000;
|
sleep_ms = atoi(wrong_pw_sleep) * 1000;
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
struct passwd* p = getpwnam(username);
|
struct passwd* p = getpwnam(username);
|
||||||
if (!p)
|
if (!p)
|
||||||
err(1, "Could not get user info");
|
err(1, "Could not get user info");
|
||||||
|
|
Loading…
Add table
Reference in a new issue