Get passphrase from TTY

This is required for #1.
This commit is contained in:
sw1tchbl4d3 2021-07-13 22:23:27 +02:00
parent dcd1e4061c
commit 336221e5e2
2 changed files with 7 additions and 18 deletions

View file

@ -1,5 +1,5 @@
rdo: rdo.c rdo: rdo.c
gcc rdo.c -lcrypt -o rdo -Wall gcc rdo.c -lcrypt -lbsd -o rdo -Wall
install: rdo install: rdo
cp rdo /usr/bin/rdo cp rdo /usr/bin/rdo

23
rdo.c
View file

@ -4,22 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <termios.h> #include <bsd/readpassphrase.h>
void getpwd(char* password){
struct termios raw;
tcgetattr(STDIN_FILENO, &raw);
raw.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, 0, &raw);
printf("Password: ");
fgets(password, 128, stdin);
password[strcspn(password, "\n")] = 0;
raw.c_lflag |= ECHO;
tcsetattr(STDIN_FILENO, 0, &raw);
printf("\n");
}
void runprog(int argc, char** argv) { void runprog(int argc, char** argv) {
for(int i=0; i<argc; i++) for(int i=0; i<argc; i++)
@ -76,7 +61,11 @@ int main(int argc, char** argv) {
int tries = 0; int tries = 0;
char password[128]; char password[128];
while (tries < 3) { while (tries < 3) {
getpwd(password); if (!readpassphrase("(rdo) Password: ", password, sizeof(password), RPP_REQUIRE_TTY)) {
fprintf(stderr, "Could not get passphrase, not in a TTY?\n");
return -7;
}
if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0) { if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0) {
runprog(argc, argv); runprog(argc, argv);
return 0; return 0;