Check uid before opening file

This commit is contained in:
remoof 2021-07-15 14:59:24 +02:00
parent a9fcfe3be9
commit 9948bd3fc7

15
rdo.c
View file

@ -50,22 +50,23 @@ int main(int argc, char** argv) {
if (argc < 2)
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");
if (!fp)
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, "wrong_pw_sleep", wrong_pw_sleep, sizeof(wrong_pw_sleep));
sleep_ms = atoi(wrong_pw_sleep) * 1000;
fclose(fp);
struct passwd* p = getpwnam(username);
if (!p)
err(1, "Could not get user info");