From 2a06eb791ac0ad96eb8f05966674fde4a80990f1 Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Fri, 20 Jan 2023 09:26:31 -0500 Subject: [PATCH] CHeck the output of setgid and setuid. --- programs/login.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/programs/login.c b/programs/login.c index 150f7fb..7df633d 100644 --- a/programs/login.c +++ b/programs/login.c @@ -93,7 +93,7 @@ static inline bool_t __get_input(char *input, size_t max_len, bool_t hide) } else if (c == '\033') { c = getchar(); if (c == '[') { - c = getchar(); // Get the char, and ignore it. + getchar(); // Get the char, and ignore it. } else if (c == '^') { c = getchar(); // Get the char. if (c == 'C') { @@ -199,10 +199,16 @@ int main(int argc, char **argv) } // Set the group id. - setgid(pwd->pw_gid); + if (setgid(pwd->pw_gid) < 0) { + printf("login: Failed to change group id: %s\n", strerror(errno)); + return 1; + } // Set the user id. - setuid(pwd->pw_uid); + if (setuid(pwd->pw_uid) < 0) { + printf("login: Failed to change user id: %s\n", strerror(errno)); + return 1; + } printf("\n");