diff --git a/Readme.org b/Readme.org index 46a4feb..debc2ec 100644 --- a/Readme.org +++ b/Readme.org @@ -89,7 +89,7 @@ In that code now we have two users: ~lain~ with the settings we mentioned before and a new user ~alyssa~ that will execute commands as ~dbuser~ and ~PERM_PASSWD~ will make that she has to enter her password every time she runs ~beroot~. -** TODO +** TO-DO List I don't want to make this a big program, I want to keep everything as simple as possible, but there are some things that I want to do: @@ -97,6 +97,5 @@ possible, but there are some things that I want to do: standard library. - Some kind of persistency (there can be a ~PERM_PERSIST~ flag) so the password doesn't need to be entered every time. -- Hide the password while it's being typed. Those are the only things I have planned adding to beroot. diff --git a/src/main.c b/src/main.c index 46cd65f..1e1a493 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,8 @@ #include #include +#include + #include "config.h" void @@ -104,6 +106,30 @@ execute (char **command) commands = NULL; } +void +get_password (char *password) +{ + if (!password) + return; + + static struct termios old_t = { 0 }, new_t = { 0 }; + tcgetattr (STDIN_FILENO, &old_t); + new_t = old_t; + new_t.c_lflag &= ~(ECHO); + tcsetattr (STDIN_FILENO, TCSANOW, &new_t); + + int i = 0; + char c = '\0'; + while ((c = getchar ()) != '\n' && c != EOF && i < LOGIN_PASSWD_MAX) + { + password[i++] = c; + } + password[i] = '\0'; + + tcsetattr (STDIN_FILENO, TCSANOW, &old_t); + puts (""); // the \n character is not printed anymore +} + int main (int argc, char *argv[]) { @@ -150,10 +176,12 @@ main (int argc, char *argv[]) else if (user->permissions & PERM_PASSWD) { printf ("Enter the %s password: ", user->target_user); - char entered_password[LOGIN_PASSWD_MAX] = { 0 }; - fgets (entered_password, LOGIN_PASSWD_MAX - 1, stdin); + char *entered_password = calloc (sizeof (char), LOGIN_PASSWD_MAX); + get_password (entered_password); is_authenticated = authenticate_user (target_swpd->sp_pwdp, entered_password); + + free (entered_password); } else {