~ubuntu-branches/ubuntu/precise/mutt/precise

« back to all changes in this revision

Viewing changes to pgp.c

  • Committer: Package Import Robot
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2010-12-17 14:28:28 UTC
  • mfrom: (16.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20101217142828-ve8yy0xf1zomtnx9
Tags: 1.5.21-1ubuntu1
* Merge with Debian experimental (LP: #691512), remaining changes:
  + debian/control, debian/patches/debian-specific/build_doc_adjustments.diff:
    Use w3m (main) instead of elinks (universe) for generating documentation.
  + Drop libtokyocabinet-dev (universe) from Build-Depends, use always
    libgdbm-dev and also use gdbm for the header cache backend. (lp: #607448)

Show diffs side-by-side

added added

removed removed

Lines of Context:
311
311
      have_any_sigs = have_any_sigs || (clearsign && (s->flags & M_VERIFY));
312
312
 
313
313
      /* Copy PGP material to temporary file */
314
 
      mutt_mktemp (tmpfname);
 
314
      mutt_mktemp (tmpfname, sizeof (tmpfname));
315
315
      if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL)
316
316
      {
317
317
        mutt_perror (tmpfname);
350
350
      /* Invoke PGP if needed */
351
351
      if (!clearsign || (s->flags & M_VERIFY))
352
352
      {
353
 
        mutt_mktemp (outfile);
 
353
        mutt_mktemp (outfile, sizeof (outfile));
354
354
        if ((pgpout = safe_fopen (outfile, "w+")) == NULL)
355
355
        {
356
356
          mutt_perror (tmpfname);
482
482
          state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s);
483
483
      }
484
484
    }
485
 
#if 0
486
485
    else
487
486
    {
488
 
      /* why would we want to display this at all? */
 
487
      /* A traditional PGP part may mix signed and unsigned content */
489
488
      /* XXX - we may wish to recode here */
490
489
      if (s->prefix)
491
490
        state_puts (s->prefix, s);
492
491
      state_puts (buf, s);
493
492
    }
494
 
#endif
495
493
  }
496
494
 
497
495
  rc = 0;
537
535
  if (tagged_only && !b->tagged)
538
536
    return 0;
539
537
 
540
 
  mutt_mktemp (tempfile);
 
538
  mutt_mktemp (tempfile, sizeof (tempfile));
541
539
  if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0)
542
540
  {
543
541
    unlink (tempfile);
625
623
  mutt_copy_bytes (s->fpin, fp, sigbdy->length);
626
624
  safe_fclose (&fp);
627
625
  
628
 
  mutt_mktemp(pgperrfile);
 
626
  mutt_mktemp (pgperrfile, sizeof (pgperrfile));
629
627
  if(!(pgperr = safe_fopen(pgperrfile, "w+")))
630
628
  {
631
629
    mutt_perror(pgperrfile);
684
682
      return;
685
683
  }
686
684
 
687
 
  mutt_mktemp (tempfname);
 
685
  mutt_mktemp (tempfname, sizeof (tempfname));
688
686
  if (!(fpout = safe_fopen (tempfname, "w")))
689
687
  {
690
688
    mutt_perror (tempfname);
740
738
  FILE *tempfp;
741
739
  char tempfname[_POSIX_PATH_MAX];
742
740
 
743
 
  mutt_mktemp (tempfname);
 
741
  mutt_mktemp (tempfname, sizeof (tempfname));
744
742
  if (!(tempfp = safe_fopen (tempfname, "w")))
745
743
  {
746
744
    mutt_perror (tempfname);
797
795
  pid_t thepid;
798
796
  int rv;
799
797
  
800
 
  mutt_mktemp (pgperrfile);
 
798
  mutt_mktemp (pgperrfile, sizeof (pgperrfile));
801
799
  if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL)
802
800
  {
803
801
    mutt_perror (pgperrfile);
805
803
  }
806
804
  unlink (pgperrfile);
807
805
 
808
 
  mutt_mktemp (pgptmpfile);
 
806
  mutt_mktemp (pgptmpfile, sizeof (pgptmpfile));
809
807
  if((pgptmp = safe_fopen (pgptmpfile, "w")) == NULL)
810
808
  {
811
809
    mutt_perror (pgptmpfile);
913
911
  
914
912
  memset (&s, 0, sizeof (s));
915
913
  s.fpin = fpin;
916
 
  mutt_mktemp (tempfile);
 
914
  mutt_mktemp (tempfile, sizeof (tempfile));
917
915
  if ((*fpout = safe_fopen (tempfile, "w+")) == NULL)
918
916
  {
919
917
    mutt_perror (tempfile);
955
953
   */
956
954
  a = a->next;
957
955
 
958
 
  mutt_mktemp (tempfile);
 
956
  mutt_mktemp (tempfile, sizeof (tempfile));
959
957
  if ((fpout = safe_fopen (tempfile, "w+")) == NULL)
960
958
  {
961
959
    if (s->flags & M_DISPLAY)
1026
1024
  
1027
1025
  convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
1028
1026
 
1029
 
  mutt_mktemp (sigfile);
 
1027
  mutt_mktemp (sigfile, sizeof (sigfile));
1030
1028
  if ((fp = safe_fopen (sigfile, "w")) == NULL)
1031
1029
  {
1032
1030
    return (NULL);
1033
1031
  }
1034
1032
 
1035
 
  mutt_mktemp (signedfile);
 
1033
  mutt_mktemp (signedfile, sizeof (signedfile));
1036
1034
  if ((sfp = safe_fopen(signedfile, "w")) == NULL)
1037
1035
  {
1038
1036
    mutt_perror(signedfile);
1128
1126
  t->subtype = safe_strdup ("pgp-signature");
1129
1127
  t->filename = safe_strdup (sigfile);
1130
1128
  t->use_disp = 0;
1131
 
  t->disposition = DISPINLINE;
 
1129
  t->disposition = DISPNONE;
1132
1130
  t->encoding = ENC7BIT;
1133
1131
  t->unlink = 1; /* ok to remove this file after sending. */
1134
1132
 
1274
1272
  int empty = 0;
1275
1273
  pid_t thepid;
1276
1274
  
1277
 
  mutt_mktemp (tempfile);
 
1275
  mutt_mktemp (tempfile, sizeof (tempfile));
1278
1276
  if ((fpout = safe_fopen (tempfile, "w+")) == NULL)
1279
1277
  {
1280
1278
    mutt_perror (tempfile);
1281
1279
    return (NULL);
1282
1280
  }
1283
1281
 
1284
 
  mutt_mktemp (pgperrfile);
 
1282
  mutt_mktemp (pgperrfile, sizeof (pgperrfile));
1285
1283
  if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL)
1286
1284
  {
1287
1285
    mutt_perror (pgperrfile);
1291
1289
  }
1292
1290
  unlink (pgperrfile);
1293
1291
 
1294
 
  mutt_mktemp(pgpinfile);
 
1292
  mutt_mktemp (pgpinfile, sizeof (pgpinfile));
1295
1293
  if((fptmp = safe_fopen(pgpinfile, "w")) == NULL)
1296
1294
  {
1297
1295
    mutt_perror(pgpinfile);
1380
1378
  t->parts->next->encoding = ENC7BIT;
1381
1379
  t->parts->next->filename = safe_strdup (tempfile);
1382
1380
  t->parts->next->use_disp = 1;
1383
 
  t->parts->next->disposition = DISPINLINE;
 
1381
  t->parts->next->disposition = DISPATTACH;
1384
1382
  t->parts->next->unlink = 1; /* delete after sending the message */
1385
1383
  t->parts->next->d_filename = safe_strdup ("msg.asc"); /* non pgp/mime can save */
1386
1384
 
1420
1418
    return NULL;
1421
1419
  }
1422
1420
  
1423
 
  mutt_mktemp (pgpinfile);
 
1421
  mutt_mktemp (pgpinfile, sizeof (pgpinfile));
1424
1422
  if ((pgpin = safe_fopen (pgpinfile, "w")) == NULL)
1425
1423
  {
1426
1424
    mutt_perror (pgpinfile);
1465
1463
  safe_fclose (&fp);
1466
1464
  safe_fclose (&pgpin);
1467
1465
 
1468
 
  mutt_mktemp (pgpoutfile);
1469
 
  mutt_mktemp (pgperrfile);
 
1466
  mutt_mktemp (pgpoutfile, sizeof (pgpoutfile));
 
1467
  mutt_mktemp (pgperrfile, sizeof (pgperrfile));
1470
1468
  if ((pgpout = safe_fopen (pgpoutfile, "w+")) == NULL ||
1471
1469
      (pgperr = safe_fopen (pgperrfile, "w+")) == NULL)
1472
1470
  {
1559
1557
 
1560
1558
#endif
1561
1559
 
1562
 
  b->disposition = DISPINLINE;
 
1560
  b->disposition = DISPNONE;
1563
1561
  b->unlink   = 1;
1564
1562
 
1565
1563
  b->noconv = 1;
1573
1571
 
1574
1572
int pgp_send_menu (HEADER *msg, int *redraw)
1575
1573
{
1576
 
  pgp_key_t p;
1577
 
  char input_signas[SHORT_STRING];
1578
 
 
1579
 
  char prompt[LONG_STRING];
 
1574
  int choice;
1580
1575
  
1581
1576
  if (!(WithCrypto & APPLICATION_PGP))
1582
1577
    return msg->security;
1586
1581
      !((msg->security & APPLICATION_PGP) && (msg->security & (SIGN|ENCRYPT))))
1587
1582
    msg->security |= INLINE;
1588
1583
  
1589
 
  snprintf (prompt, sizeof (prompt), 
1590
 
            _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, %s, or (c)lear? "),
1591
 
            (msg->security & INLINE) ? _("PGP/M(i)ME") : _("(i)nline"));
1592
 
  
1593
 
  switch (mutt_multi_choice (prompt, _("esabifc")))
1594
 
  {
1595
 
  case 1: /* (e)ncrypt */
1596
 
    msg->security |= ENCRYPT;
1597
 
    msg->security &= ~SIGN;
1598
 
    break;
 
1584
  /* When the message is not selected for signing or encryption, the toggle
 
1585
   * between PGP/MIME and Traditional doesn't make sense.
 
1586
   */
 
1587
  if (msg->security & (ENCRYPT | SIGN))
 
1588
  {
 
1589
    char prompt[LONG_STRING];
 
1590
 
 
1591
    snprintf (prompt, sizeof (prompt), 
 
1592
        _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, %s format, or (c)lear? "),
 
1593
        (msg->security & INLINE) ? _("PGP/M(i)ME") : _("(i)nline"));
 
1594
 
 
1595
    /* The keys accepted for this prompt *must* match the order in the second
 
1596
     * version in the else clause since the switch statement below depends on
 
1597
     * it.  The 'i' key is appended in this version.
 
1598
     */
 
1599
    choice = mutt_multi_choice (prompt, _("esabfci"));
 
1600
  }
 
1601
  else
 
1602
  {
 
1603
    /* The keys accepted *must* be a prefix of the accepted keys in the "if"
 
1604
     * clause above since the switch statement below depends on it.
 
1605
     */
 
1606
    choice = mutt_multi_choice(_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (c)lear? "),
 
1607
        _("esabfc"));
 
1608
  }
 
1609
 
 
1610
  switch (choice)
 
1611
  {
 
1612
    case 1: /* (e)ncrypt */
 
1613
      msg->security |= ENCRYPT;
 
1614
      msg->security &= ~SIGN;
 
1615
      break;
1599
1616
 
1600
1617
  case 2: /* (s)ign */
1601
1618
    msg->security |= SIGN;
1603
1620
    break;
1604
1621
 
1605
1622
  case 3: /* sign (a)s */
1606
 
    unset_option(OPTPGPCHECKTRUST);
1607
 
 
1608
 
    if ((p = pgp_ask_for_key (_("Sign as: "), NULL, 0, PGP_SECRING)))
1609
1623
    {
1610
 
      snprintf (input_signas, sizeof (input_signas), "0x%s",
1611
 
                pgp_keyid (p));
1612
 
      mutt_str_replace (&PgpSignAs, input_signas);
1613
 
      pgp_free_key (&p);
1614
 
      
1615
 
      msg->security |= SIGN;
1616
 
        
1617
 
      crypt_pgp_void_passphrase ();  /* probably need a different passphrase */
1618
 
    }
 
1624
      pgp_key_t p;
 
1625
      char input_signas[SHORT_STRING];
 
1626
 
 
1627
      unset_option(OPTPGPCHECKTRUST);
 
1628
 
 
1629
      if ((p = pgp_ask_for_key (_("Sign as: "), NULL, 0, PGP_SECRING)))
 
1630
      {
 
1631
        snprintf (input_signas, sizeof (input_signas), "0x%s",
 
1632
            pgp_keyid (p));
 
1633
        mutt_str_replace (&PgpSignAs, input_signas);
 
1634
        pgp_free_key (&p);
 
1635
 
 
1636
        msg->security |= SIGN;
 
1637
 
 
1638
        crypt_pgp_void_passphrase ();  /* probably need a different passphrase */
 
1639
      }
1619
1640
#if 0
1620
 
    else
1621
 
    {
1622
 
      msg->security &= ~SIGN;
1623
 
    }
 
1641
      else
 
1642
      {
 
1643
        msg->security &= ~SIGN;
 
1644
      }
1624
1645
#endif
1625
1646
 
1626
 
    *redraw = REDRAW_FULL;
1627
 
    break;
 
1647
      *redraw = REDRAW_FULL;
 
1648
    } break;
1628
1649
 
1629
1650
  case 4: /* (b)oth */
1630
1651
    msg->security |= (ENCRYPT | SIGN);
1631
1652
    break;
1632
1653
 
1633
 
  case 5: /* (i)nline */
1634
 
    if ((msg->security & (ENCRYPT | SIGN)))
1635
 
      msg->security ^= INLINE;
1636
 
    else
1637
 
      msg->security &= ~INLINE;
1638
 
    break;
1639
 
 
1640
 
  case 6: /* (f)orget it */
1641
 
  case 7: /* (c)lear     */
 
1654
  case 5: /* (f)orget it */
 
1655
  case 6: /* (c)lear     */
1642
1656
    msg->security = 0;
1643
1657
    break;
 
1658
 
 
1659
  case 7: /* toggle (i)nline */
 
1660
    msg->security ^= INLINE;
 
1661
    break;
1644
1662
  }
1645
1663
 
1646
1664
  if (msg->security)