From 3963e3516b4177215d5264fc3055ce0fa54b8a1b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 20 Jan 2024 20:28:02 +0300 Subject: [PATCH] fixed login --- include/libmu/pw_check.h | 7 +------ src/loginutils/login/login.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/libmu/pw_check.h b/include/libmu/pw_check.h index adb73dd..7ed9767 100644 --- a/include/libmu/pw_check.h +++ b/include/libmu/pw_check.h @@ -3,7 +3,6 @@ #include #include -#include #include int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) { @@ -20,11 +19,7 @@ int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) { return 1; } - char *cryptpass = crypt(pass, pw->pw_passwd); - if (cryptpass == NULL) - return 1; - - if (!strcmp(pw->pw_passwd, cryptpass)) + if (!strcmp(pass, pw->pw_passwd)) return 0; return 1; diff --git a/src/loginutils/login/login.c b/src/loginutils/login/login.c index 989dd84..98bb406 100644 --- a/src/loginutils/login/login.c +++ b/src/loginutils/login/login.c @@ -6,9 +6,29 @@ #include #include #include +#include #include "get_string.h" #include "pw_check.h" +#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) + +int hide_input(int fd, int flag) { + struct termios term; + if (tcgetattr(fd, &term) < 0) + return 1; + + if (flag) + term.c_lflag &= ~ECHOFLAGS; + + else + term.c_lflag |= ECHOFLAGS; + + if (tcsetattr(fd, TCSAFLUSH, &term) < 0) + return 1; + + return 0; +} + void login(const struct passwd *pw) { char *shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell; @@ -42,6 +62,9 @@ struct passwd *proccess_input(char *hostname) { /* Password */ printf("\nPassword:\n"); + if (hide_input(STDIN_FILENO, 1)) + return NULL; + if (!mu_get_string("login", psswd, sizeof(psswd))) return NULL; @@ -73,6 +96,7 @@ int main(void) { signal(SIGHUP, SIG_IGN); struct passwd *pw = proccess_input(hostname); + hide_input(STDIN_FILENO, 0); if (!pw) return 1;