aboutsummaryrefslogtreecommitdiff
path: root/src/shell/shell.c
blob: 79b4792a6724f4e2277f4f7236acb0be3de4db71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>


int main(int argc, char **argv) {
  struct termios old, new;

  int passfifo_fd = open("/lib/cryptsetup/passfifo", O_WRONLY);
  if (passfifo_fd < 0) {
    perror("open");
    return -1;
  }

  if ( tcgetattr(0, &old) != 0 )
    return -1;
  new = old;
  new.c_lflag &= ~ECHO;

  if ( tcsetattr(0, TCSANOW, &new) != 0 )
    return -1;

  printf("Enter a passphrase: ");
  char *line = calloc(128, sizeof(char));
  size_t len = 128;
  ssize_t read = getline(&line, &len, stdin);
  if (write(passfifo_fd, line, len) == -1)
    perror("write");
  printf("\n");

  if ( tcsetattr(0, TCSANOW, &old) != 0 )
    return -1;

  return 0;
}