Merge pull request #1026 from jglukasik/hide-passcode-pr

Disable terminal echo on passcode entry
This commit is contained in:
Elliot Glaysher 2018-10-05 13:59:55 -07:00 committed by GitHub
commit 343ac8d252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,14 +295,28 @@ _sist_cask(c3_c* dir_c, u3_noun nun)
{
c3_c paw_c[60];
u3_noun key;
u3_utty* uty_u = calloc(1, sizeof(u3_utty));
uty_u->fid_i = 0;
uH;
// disable terminal echo when typing in passcode
if ( 0 != tcgetattr(uty_u->fid_i, &uty_u->bak_u) ) {
c3_assert(!"init-tcgetattr");
}
uty_u->raw_u = uty_u->bak_u;
uty_u->raw_u.c_lflag &= ~ECHO;
if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->raw_u) ) {
c3_assert(!"init-tcsetattr");
}
while ( 1 ) {
printf("passcode for %s%s? ~", dir_c, (c3y == nun) ? " [none]" : "");
paw_c[0] = 0;
c3_fpurge(stdin);
fgets(paw_c, 59, stdin);
printf("\n");
if ( '\n' == paw_c[0] ) {
if ( c3y == nun ) {
@ -334,6 +348,10 @@ _sist_cask(c3_c* dir_c, u3_noun nun)
break;
}
}
if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->bak_u) ) {
c3_assert(!"init-tcsetattr");
}
free(uty_u);
uL(0);
return key;
}