now the password is hidden
This commit is contained in:
parent
d037a43136
commit
5e363aed5e
@ -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.
|
||||
|
32
src/main.c
32
src/main.c
@ -7,6 +7,8 @@
|
||||
#include <shadow.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user