Exemplo n.º 1
0
void
cpr_kill_prompt(void)
{
    if( opt.command_fd != -1 )
	return;
    tty_kill_prompt();
    return;
}
Exemplo n.º 2
0
int
tty_get_answer_is_yes( const char *prompt )
{
    int yes;
    char *p = tty_get( prompt );
    tty_kill_prompt();
    yes = answer_is_yes(p);
    xfree(p);
    return yes;
}
Exemplo n.º 3
0
void
display_online_help( const char *keyword )
{

    tty_kill_prompt();
    if( !keyword )
	tty_printf(_("No help available") );
    else {
	const char *p;
	int i;

	for(i=0; (p=helptexts[i].key) && strcmp( p, keyword ); i++ )
	    ;
	if( !p || !*helptexts[i].help )
	    tty_printf(_("No help available for `%s'"), keyword );
	else
	    tty_printf("%s", _(helptexts[i].help) );
    }
    tty_printf("\n");
}
Exemplo n.º 4
0
int
cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt )
{
    int yes;
    char *p;

    if( opt.command_fd != -1 )
	return !!do_get_from_fd ( keyword, 0, 1 );
    for(;;) {
	p = tty_get( prompt );
	trim_spaces(p); /* it is okay to do this here */
	if( *p == '?' && !p[1] ) {
	    xfree(p);
	    display_online_help( keyword );
	}
	else {
	    tty_kill_prompt();
	    yes = answer_is_yes_no_quit(p);
	    xfree(p);
	    return yes;
	}
    }
}
Exemplo n.º 5
0
void
display_online_help( const char *keyword )
{
  char *result;
  int need_final_lf = 1;

  tty_kill_prompt();
  if ( !keyword )
    tty_printf (_("No help available") );
  else if ( (result = get_help_from_file (keyword)) )
    {
      tty_printf ("%s", result);
      if (*result && result[strlen (result)-1] == '\n')
        need_final_lf = 0;
      xfree (result);
    }
  else
    {
      tty_printf (_("No help available for '%s'"), keyword );
    }
  if (need_final_lf)
    tty_printf("\n");
}
Exemplo n.º 6
0
int
cpr_get_answer_okay_cancel (const char *keyword,
                            const char *prompt,
                            int def_answer)
{
  int yes;
  char *answer = NULL;
  char *p;

  if( opt.command_fd != -1 )
    answer = do_get_from_fd ( keyword, 0, 0 );

  if (answer)
    {
      yes = answer_is_okay_cancel (answer, def_answer);
      xfree (answer);
      return yes;
    }

  for(;;)
    {
      p = tty_get( prompt );
      trim_spaces(p); /* it is okay to do this here */
      if (*p == '?' && !p[1])
        {
          xfree(p);
          display_online_help (keyword);
	}
      else
        {
          tty_kill_prompt();
          yes = answer_is_okay_cancel (p, def_answer);
          xfree(p);
          return yes;
	}
    }
}
Exemplo n.º 7
0
/* Query the card, show a list of already stored keys and ask the user
   where to store the key.  Returns the key number or 0 for cancel
   operation. */
static int
query_card (APP app)
{
  int keyno = 0;
  char *serialno, *disp_name, *pubkey_url;
  unsigned char *fpr1, *fpr2, *fpr3;


  if (app_openpgp_cardinfo (app,
                            &serialno,
                            &disp_name,
                            &pubkey_url,
                            &fpr1, &fpr2, &fpr3))
    return 0;


  for (;;)
    {
      char *answer;

      tty_printf ("\n");

      tty_printf ("Serial number ....: %s\n",
                  serialno? serialno : "[none]");
      tty_printf ("Name of cardholder: %s\n",
                  disp_name && *disp_name? disp_name : "[not set]");
      tty_printf ("URL of public key : %s\n",
                  pubkey_url && *pubkey_url? pubkey_url : "[not set]");
      tty_printf ("Signature key ....:");
      show_sha1_fpr (fpr1);
      tty_printf ("Encryption key....:");
      show_sha1_fpr (fpr2);
      tty_printf ("Authentication key:");
      show_sha1_fpr (fpr3);

      tty_printf ("\n"
                  "1 - store as signature key and reset usage counter\n"
                  "2 - store as encryption key\n"
                  "3 - store as authentication key\n"
                  "Q - quit\n"
                  "\n");

      answer = tty_get("Your selection? ");
      tty_kill_prompt();
      if (strlen (answer) != 1)
        ;
      else if ( *answer == '1' )
        {
          if ( (fpr1 && !fpr_is_zero (fpr1)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: signature key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 1;
                  break;
                }
            }
          else
            {
              keyno = 1;
              break;
            }
        }
      else if ( *answer == '2' )
        {
          if ( (fpr2 && !fpr_is_zero (fpr2)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: encryption key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 2;
                  break;
                }
            }
          else
            {
              keyno = 2;
              break;
            }
        }
      else if ( *answer == '3' )
        {
          if ( (fpr3 && !fpr_is_zero (fpr3)) )
            {
              tty_printf ("\n");
              log_error ("WARNING: authentication key does already exists!\n");
              tty_printf ("\n");
              if ( tty_get_answer_is_yes ("Replace existing key? ") )
                {
                  keyno = 3;
                  break;
                }
            }
          else
            {
              keyno = 3;
              break;
            }
        }
      else if ( *answer == 'q' || *answer == 'Q')
        {
          keyno = 0;
          break;
        }
    }

  xfree (serialno);
  xfree (disp_name);
  xfree (pubkey_url);
  xfree (fpr1);
  xfree (fpr2);
  xfree (fpr3);

  return keyno;
}