From 9df42871ff0294b87a332e8c307fa49daed67ccf Mon Sep 17 00:00:00 2001 From: Felix Schulze <39433012+thefeli73@users.noreply.github.com> Date: Sat, 29 Jan 2022 16:07:55 +0100 Subject: [PATCH] check for return values!!! --- lab1/login_linux.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lab1/login_linux.c b/lab1/login_linux.c index 1b2d4cd..b97f329 100755 --- a/lab1/login_linux.c +++ b/lab1/login_linux.c @@ -91,20 +91,27 @@ int main(int argc, char *argv[]) { printf(" You're in !\n"); passwddata->pwfailed = 0; passwddata->pwage = passwddata->pwage + 1; - mysetpwent(user, passwddata); + if (mysetpwent(user, passwddata) < 0) { /* execute the command */ + perror("Error");exit(EXIT_FAILURE); + } if (passwddata->pwage > 100) { printf(" Your password is OLD!!!!\n"); } /* check UID, see setuid(2) */ - setuid(passwddata->uid); + + if (setuid(passwddata->uid) < 0) { /* execute the command */ + perror("Error");exit(EXIT_FAILURE); + } /* start a shell, use execve(2) */ if (execve("/bin/bash",NULL,NULL) < 0) { /* execute the command */ perror("Error");exit(EXIT_FAILURE); } } else { passwddata->pwfailed = passwddata->pwfailed + 1; - mysetpwent(user, passwddata); + if (mysetpwent(user, passwddata) < 0) { /* execute the command */ + perror("Error");exit(EXIT_FAILURE); + } } } printf("Login Incorrect \n");