示例#1
0
static void
display_password (ply_boot_splash_plugin_t *plugin,
                  const char               *prompt,
                  int                       bullets)
{
  pause_views (plugin);
  if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_NORMAL)
    stop_animation (plugin, NULL);

  plugin->state = PLY_BOOT_SPLASH_DISPLAY_PASSWORD_ENTRY;
  show_password_prompt (plugin, prompt, bullets);
  redraw_views (plugin);
  unpause_views (plugin);
}
示例#2
0
int main(int argc, char** argv) {
  if (DEBUG)
    printf("starting cryptsetup-gui\n");

  arg0 = *argv;

  argv++;
  argc--;

  if (argc == 0) {
    usage();
    exit(EXIT_SUCCESS);
  }

  if (strcmp(*argv, "-m") == 0) {
    do_mount = true;
    argv++;
    argc--;
    if (DEBUG)
      printf("mount after unlocking\n");
  }

  if (argc != 1) {
    usage();
    exit(EXIT_SUCCESS);
  }

  char* cryptpoint = *argv;
  char* ct = cryptpoint;

  if (DEBUG)
    printf("verifying cryptpoint\n");

  while (*ct != 0) {
    if (*ct < 'a' || *ct > 'z') {
      fprintf(stderr, "Non a-z cryptpoint given\n");
      exit(EXIT_FAILURE);
    }
    ct++;
  }

  if (DEBUG)
    printf("cryptpoint verified\n");

  size_t mps = strlen(mountpoint);
  size_t cps = strlen(cryptpoint);
  char* tmp = malloc(sizeof(char) * (mps + cps));
  strncpy(tmp, mountpoint, mps);
  strncpy(tmp + mps, cryptpoint, cps);
  mountpoint = tmp;

  if (DEBUG)
    printf("mountpoint resolved to '%s'\n", mountpoint);

  if (access(mountpoint, F_OK) == 0) {
    if (DEBUG)
      printf("/dev/mapper listing already exists\n");

    if (DEBUG && !do_mount)
      printf("not told to mount automatically (-m), exiting...\n");

    // Mountpoint already exists...
    if (do_mount && !mount(mountpoint)) {
      fprintf(stderr, "Failed to mount device %s\n", cryptpoint);
      exit(EXIT_FAILURE);
    }

    if (DEBUG && do_mount)
      printf("mountpoint successfully mounted\n");

    exit(EXIT_SUCCESS);
  }

  if (DEBUG)
    printf("parsing crypttab\n");

  FILE *f = fopen("/etc/crypttab", "re");
  if (!f) {
    perror("Failed to open crypttab for reading");
    exit(EXIT_FAILURE);
  }

  if (DEBUG)
    printf("crypttab opened\n");

  char *l, *p = NULL;
  char line[1024];
  int n = 0;
  for (;;) {
    int k;

    if (!fgets(line, sizeof(line), f))
      break;

    n++;

    l = strstrip(line);
    if (*l == '#' || *l == 0)
      continue;

    k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &p, &options);
    free(p);
    p = NULL;
    if (k < 2 || k > 4) {
      fprintf(stderr, "Failed to parse /etc/crypttab:%u, ignoring\n", n);
      goto next;
    }

    if (strcmp(name, cryptpoint) == 0) {
      // We found our cryptpoint
      if (DEBUG)
        printf("crypttab entry found for cryptpoint '%s'\n", device);
      break;
    }

    next:
      free(name);
      free(device);
      free(options);
      name = NULL;
      device = NULL;
      options = NULL;
  }
  fclose(f);

  if (DEBUG)
    printf("crypttab parsing ended\n");

  if (name == NULL || device == NULL) {
    fprintf(stderr, "Entry for %s not found in crypttab\n", cryptpoint);
  }

  show_password_prompt(arg0);

  return 0;
}