~ubuntu-branches/ubuntu/hardy/gnupg/hardy-updates

« back to all changes in this revision

Viewing changes to g10/card-util.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-16 16:57:39 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051216165739-v0m2d1you6hd8jho
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
17
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 
19
 * USA.
19
20
 */
20
21
 
21
22
#include <config.h>
27
28
 
28
29
#if GNUPG_MAJOR_VERSION != 1
29
30
#include "gpg.h"
30
 
#endif
 
31
#endif /*GNUPG_MAJOR_VERSION != 1*/
31
32
#include "util.h"
32
33
#include "i18n.h"
33
34
#include "ttyio.h"
36
37
#include "main.h"
37
38
#include "keyserver-internal.h"
38
39
#if GNUPG_MAJOR_VERSION == 1
 
40
#ifdef HAVE_LIBREADLINE
 
41
#include <stdio.h>
 
42
#include <readline/readline.h>
 
43
#endif /*HAVE_LIBREADLINE*/
39
44
#include "cardglue.h"
40
 
#else
 
45
#else /*GNUPG_MAJOR_VERSION!=1*/
41
46
#include "call-agent.h"
42
 
#endif
 
47
#endif /*GNUPG_MAJOR_VERSION!=1*/
43
48
 
44
49
#define CONTROL_D ('D' - 'A' + 1)
45
50
 
63
68
  log_info (_("OpenPGP card no. %s detected\n"),
64
69
              info.serialno? info.serialno : "[none]");
65
70
 
 
71
  agent_clear_pin_cache (info.serialno);
 
72
 
66
73
  agent_release_card_info (&info);
67
74
 
68
75
  if (opt.batch)
283
290
  int rc;
284
291
  unsigned int uval;
285
292
  const unsigned char *thefpr;
 
293
  int i;
286
294
 
287
295
  if (serialno && serialnobuflen)
288
296
    *serialno = 0;
359
367
                   info.chvretry[0], info.chvretry[1], info.chvretry[2]);
360
368
      fprintf (fp, "sigcount:%lu:::\n", info.sig_counter);
361
369
 
 
370
      for (i=0; i < 4; i++)
 
371
        {
 
372
          if (info.private_do[i])
 
373
            {
 
374
              fprintf (fp, "private_do:%d:", i+1);
 
375
              print_string (fp, info.private_do[i],
 
376
                            strlen (info.private_do[i]), ':');
 
377
              fputs (":\n", fp);
 
378
            }
 
379
        }
 
380
 
362
381
      fputs ("cafpr:", fp);
363
382
      print_sha1_fpr_colon (fp, info.cafpr1valid? info.cafpr1:NULL);
364
383
      print_sha1_fpr_colon (fp, info.cafpr2valid? info.cafpr2:NULL);
934
953
{     
935
954
  int rc = 0;
936
955
 
 
956
  agent_clear_pin_cache (info->serialno);
 
957
 
937
958
  *forced_chv1 = !info->chv1_cached;
938
959
  if (*forced_chv1)
939
960
    { /* Switch of the forced mode so that during key generation we
1272
1293
}
1273
1294
 
1274
1295
 
1275
 
/* Menu to edit all user changeable values on an OpenPGP card.  Only
1276
 
   Key creation is not handled here. */
1277
 
void
1278
 
card_edit (STRLIST commands)
1279
 
{
1280
 
  enum cmdids {
 
1296
 
 
1297
/* Data used by the command parser.  This needs to be outside of the
 
1298
   function scope to allow readline based command completion.  */
 
1299
enum cmdids
 
1300
  {
1281
1301
    cmdNOP = 0,
1282
 
    cmdQUIT, cmdADMIN, cmdHELP, cmdLIST, cmdDEBUG,
 
1302
    cmdQUIT, cmdADMIN, cmdHELP, cmdLIST, cmdDEBUG, cmdVERIFY,
1283
1303
    cmdNAME, cmdURL, cmdFETCH, cmdLOGIN, cmdLANG, cmdSEX, cmdCAFPR,
1284
1304
    cmdFORCESIG, cmdGENERATE, cmdPASSWD, cmdPRIVATEDO,
1285
1305
    cmdINVCMD
1286
1306
  };
1287
1307
 
1288
 
  static struct {
1289
 
    const char *name;
1290
 
    enum cmdids id;
1291
 
    int admin_only;
1292
 
    const char *desc;
1293
 
  } cmds[] = {
 
1308
static struct
 
1309
{
 
1310
  const char *name;
 
1311
  enum cmdids id;
 
1312
  int admin_only;
 
1313
  const char *desc;
 
1314
} cmds[] =
 
1315
  {
1294
1316
    { "quit"    , cmdQUIT  , 0, N_("quit this menu")},
1295
1317
    { "q"       , cmdQUIT  , 0, NULL },
1296
1318
    { "admin"   , cmdADMIN , 0, N_("show admin commands")},
1309
1331
    { "forcesig", cmdFORCESIG, 1, N_("toggle the signature force PIN flag")},
1310
1332
    { "generate", cmdGENERATE, 1, N_("generate new keys")},
1311
1333
    { "passwd"  , cmdPASSWD, 0, N_("menu to change or unblock the PIN")},
 
1334
    { "verify"  , cmdVERIFY, 0, N_("verify the PIN and list all data")},
1312
1335
    /* Note, that we do not announce this command yet. */
1313
1336
    { "privatedo", cmdPRIVATEDO, 0, NULL },
1314
1337
    { NULL, cmdINVCMD, 0, NULL } 
1315
1338
  };
1316
 
 
 
1339
 
 
1340
 
 
1341
#if GNUPG_MAJOR_VERSION == 1 && defined (HAVE_LIBREADLINE)
 
1342
 
 
1343
/* These two functions are used by readline for command completion. */
 
1344
 
 
1345
static char *
 
1346
command_generator(const char *text,int state)
 
1347
{
 
1348
  static int list_index,len;
 
1349
  const char *name;
 
1350
 
 
1351
  /* If this is a new word to complete, initialize now.  This includes
 
1352
     saving the length of TEXT for efficiency, and initializing the
 
1353
     index variable to 0. */
 
1354
  if(!state)
 
1355
    {
 
1356
      list_index=0;
 
1357
      len=strlen(text);
 
1358
    }
 
1359
 
 
1360
  /* Return the next partial match */
 
1361
  while((name=cmds[list_index].name))
 
1362
    {
 
1363
      /* Only complete commands that have help text */
 
1364
      if(cmds[list_index++].desc && strncmp(name,text,len)==0)
 
1365
        return strdup(name);
 
1366
    }
 
1367
 
 
1368
  return NULL;
 
1369
}
 
1370
 
 
1371
static char **
 
1372
card_edit_completion(const char *text, int start, int end)
 
1373
{
 
1374
  /* If we are at the start of a line, we try and command-complete.
 
1375
     If not, just do nothing for now. */
 
1376
 
 
1377
  if(start==0)
 
1378
    return rl_completion_matches(text,command_generator);
 
1379
 
 
1380
  rl_attempted_completion_over=1;
 
1381
 
 
1382
  return NULL;
 
1383
}
 
1384
#endif /* GNUPG_MAJOR_VERSION == 1 && HAVE_LIBREADLINE */
 
1385
 
 
1386
/* Menu to edit all user changeable values on an OpenPGP card.  Only
 
1387
   Key creation is not handled here. */
 
1388
void
 
1389
card_edit (STRLIST commands)
 
1390
{
1317
1391
  enum cmdids cmd = cmdNOP;
1318
1392
  int have_commands = !!commands;
1319
1393
  int redisplay = 1;
1374
1448
 
1375
1449
            if (!have_commands)
1376
1450
              {
 
1451
#if GNUPG_MAJOR_VERSION == 1
 
1452
                tty_enable_completion (card_edit_completion);
 
1453
#endif
1377
1454
                answer = cpr_get_no_help("cardedit.prompt", _("Command> "));
1378
1455
                cpr_kill_prompt();
 
1456
#if GNUPG_MAJOR_VERSION == 1
 
1457
                tty_disable_completion ();
 
1458
#endif
1379
1459
            }
1380
1460
            trim_spaces(answer);
1381
1461
        }
1423
1503
          break;
1424
1504
 
1425
1505
        case cmdADMIN:
1426
 
          allow_admin=!allow_admin;
 
1506
          if ( !strcmp (arg_string, "on") )
 
1507
            allow_admin = 1;
 
1508
          else if ( !strcmp (arg_string, "off") )
 
1509
            allow_admin = 0;
 
1510
          else if ( !strcmp (arg_string, "verify") )
 
1511
            {
 
1512
              /* Force verification of the Admin Command.  However,
 
1513
                 this is only done if the retry counter is at initial
 
1514
                 state.  */
 
1515
              char *tmp = xmalloc (strlen (serialnobuf) + 6 + 1);
 
1516
              strcpy (stpcpy (tmp, serialnobuf), "[CHV3]");
 
1517
              allow_admin = !agent_scd_checkpin (tmp);
 
1518
              xfree (tmp);
 
1519
            }
 
1520
          else /* Toggle. */
 
1521
            allow_admin=!allow_admin;
1427
1522
          if(allow_admin)
1428
1523
            tty_printf(_("Admin commands are allowed\n"));
1429
1524
          else
1430
1525
            tty_printf(_("Admin commands are not allowed\n"));
1431
1526
          break;
1432
1527
 
 
1528
        case cmdVERIFY:
 
1529
          agent_scd_checkpin (serialnobuf);
 
1530
          redisplay = 1;
 
1531
          break;
 
1532
 
1433
1533
        case cmdLIST:
1434
1534
          redisplay = 1;
1435
1535
          break;