1
0
Fork 0
forked from soccera/rdo

Be more specific with getpwnam() errors

getpwnam() does not populate errno when the user simply doesn't exist,
making err() print "Success" as the error.

We now check for errno == 0, and print a different error message for it.
This commit is contained in:
sw1tchbl4d3 2022-02-09 20:06:28 +01:00
parent f1b75ffe48
commit 6b6d607ea6

8
rdo.c
View file

@ -79,12 +79,16 @@ int main(int argc, char** argv) {
return runprog(argc, argv);
struct passwd* p = getpwnam(username);
if (!p)
if (!p) {
if (errno == 0)
errx(1, "The user specified in the config file does not exist.");
else
err(1, "Could not get user info");
}
int uid = p->pw_uid;
if (uid != ruid && ruid != 0)
errx(1, "You are not in the username file");
errx(1, "You are not allowed to execute rdo.");
struct spwd* shadowEntry = getspnam(p->pw_name);