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:
parent
f1b75ffe48
commit
6b6d607ea6
1 changed files with 7 additions and 3 deletions
10
rdo.c
10
rdo.c
|
@ -79,12 +79,16 @@ int main(int argc, char** argv) {
|
|||
return runprog(argc, argv);
|
||||
|
||||
struct passwd* p = getpwnam(username);
|
||||
if (!p)
|
||||
err(1, "Could not get user info");
|
||||
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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue