~ubuntu-branches/ubuntu/trusty/gnupg/trusty-updates

« back to all changes in this revision

Viewing changes to g10/gpg.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-12-04 22:26:16 UTC
  • mfrom: (1.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20121204222616-cr0fow26geq90l3y
Tags: 1.4.12-6ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Disable mlock() test since it fails with ulimit 0 (on buildds).
  - Set gpg (or gpg2) and gpgsm to use a passphrase agent by default.
  - Only suggest gnupg-curl and libldap; recommendations are pulled into
    minimal, and we don't need the keyserver utilities in a minimal Ubuntu
    system.
  - Remove the Win32 build.
  - Update config.guess/config.sub for aarch64.
* Dropped patches:
  - Fix udeb build failure on powerpc, building with -O2 instead of -Os.
    (No longer seems to be necessary.)
* Simplify removal of Win32 build, to make this easier to merge in future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* gpg.c - The GnuPG utility (main for gpg)
2
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
 
 *               2007, 2008, 2009 Free Software Foundation, Inc.
 
3
 *               2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
39
39
#ifdef HAVE_W32_SYSTEM
40
40
#include <windows.h>
41
41
#endif
 
42
#ifdef __VMS
 
43
# include "vms.h"
 
44
#endif
42
45
 
43
46
#define INCLUDED_BY_MAIN_MODULE 1
44
47
#include "packet.h"
279
282
    oS2KDigest,
280
283
    oS2KCipher,
281
284
    oS2KCount,
282
 
    oSimpleSKChecksum,                          
 
285
    oSimpleSKChecksum,
283
286
    oDisplayCharset,
284
287
    oNotDashEscaped,
285
288
    oEscapeFrom,
308
311
    oNoAllowNonSelfsignedUID,
309
312
    oAllowFreeformUID,
310
313
    oNoAllowFreeformUID,
311
 
    oAllowSecretKeyImport,                      
 
314
    oAllowSecretKeyImport,
312
315
    oEnableSpecialFilenames,
313
316
    oNoLiteral,
314
317
    oSetFilesize,
992
995
     sensitive information may be retrieved by means of error
993
996
     messages.  */
994
997
  return -1;
995
 
#else 
 
998
#else
996
999
  int fd;
997
1000
 
998
1001
/*   if (is_secured_filename (fname)) */
1015
1018
  if ( fd == -1)
1016
1019
    log_error ( for_write? _("can't create `%s': %s\n")
1017
1020
                         : _("can't open `%s': %s\n"), fname, strerror(errno));
1018
 
  
 
1021
 
1019
1022
  return fd;
1020
1023
#endif
1021
1024
}
1678
1681
/* Must be called before we open any files. */
1679
1682
static void
1680
1683
reopen_std(void)
1681
 
{  
 
1684
{
1682
1685
#if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM)
1683
1686
  struct stat statbuf;
1684
1687
  int did_stdin=0,did_stdout=0,did_stderr=0;
1775
1778
      if (configname)
1776
1779
        {
1777
1780
          char *tok;
1778
 
          
 
1781
 
1779
1782
          xfree (configname);
1780
1783
          configname = NULL;
1781
1784
 
1786
1789
          else
1787
1790
            break;
1788
1791
        }
1789
 
      
 
1792
 
1790
1793
      configname = make_filename (opt.homedir, name, NULL);
1791
1794
    }
1792
1795
  while (access (configname, R_OK));
1793
1796
 
1794
1797
  xfree(name);
1795
 
  
 
1798
 
1796
1799
  if (! configname)
1797
1800
    configname = make_filename (opt.homedir, "gpg" EXTSEP_S "conf", NULL);
1798
1801
  if (! access (configname, R_OK))
1872
1875
    opt.lock_once = 1;
1873
1876
#endif /* __riscos__ */
1874
1877
 
 
1878
#ifdef __VMS
 
1879
    /* On VMS, set the default value of the "--[no-]batch" flag
 
1880
     * according to the actual process mode.  The user can override
 
1881
     * this with an explicit command-line "--[no-]batch" option.  This
 
1882
     * avoids that the process stops while trying to initialize the
 
1883
     * tty in batch mode.  */
 
1884
    opt.batch = batch_mode_vms();
 
1885
#endif
 
1886
 
1875
1887
    reopen_std();
1876
1888
    trap_unaligned();
1877
1889
    secmem_set_flags( secmem_get_flags() | 2 ); /* suspend warnings */
1883
1895
    secure_randoxmalloc(); /* put random number into secure memory */
1884
1896
    may_coredump = disable_core_dumps();
1885
1897
    init_signals();
1886
 
    create_dotlock(NULL); /* register locking cleanup */
 
1898
    dotlock_create (NULL, 0); /* Register locking cleanup.  */
1887
1899
    i18n_init();
1888
1900
    opt.command_fd = -1; /* no command fd */
1889
1901
    opt.compress_level = -1; /* defaults to standard compress level */
1930
1942
#elif defined(__APPLE__)
1931
1943
    opt.pcsc_driver = "/System/Library/Frameworks/PCSC.framework/PCSC";
1932
1944
#elif defined(__GLIBC__)
1933
 
    opt.pcsc_driver = "libpcsclite.so.1"; 
 
1945
    opt.pcsc_driver = "libpcsclite.so.1";
1934
1946
#else
1935
 
    opt.pcsc_driver = "libpcsclite.so"; 
 
1947
    opt.pcsc_driver = "libpcsclite.so";
1936
1948
#endif
1937
1949
    opt.disable_keypad = 1;  /* No keypad support; use gpg2 instead.  */
1938
1950
#endif /*ENABLE_CARD_SUPPORT*/
2079
2091
      {
2080
2092
        switch( pargs.r_opt )
2081
2093
          {
2082
 
          case aCheckKeys: 
 
2094
          case aCheckKeys:
2083
2095
          case aListConfig:
2084
2096
          case aGPGConfList:
2085
2097
          case aGPGConfTest:
2086
2098
          case aListPackets:
2087
 
          case aImport: 
2088
 
          case aFastImport: 
2089
 
          case aSendKeys: 
2090
 
          case aRecvKeys: 
 
2099
          case aImport:
 
2100
          case aFastImport:
 
2101
          case aSendKeys:
 
2102
          case aRecvKeys:
2091
2103
          case aSearchKeys:
2092
2104
          case aRefreshKeys:
2093
2105
          case aFetchKeys:
2094
 
          case aExport: 
 
2106
          case aExport:
2095
2107
            set_cmd (&cmd, pargs.r_opt);
2096
2108
            break;
2097
2109
          case aListKeys: set_cmd( &cmd, aListKeys); break;
2104
2116
            break;
2105
2117
          case aDeleteSecretAndPublicKeys:
2106
2118
            set_cmd( &cmd, aDeleteSecretAndPublicKeys);
2107
 
            greeting=1; 
 
2119
            greeting=1;
2108
2120
            break;
2109
2121
          case aDeleteKeys: set_cmd( &cmd, aDeleteKeys); greeting=1; break;
2110
2122
 
2205
2217
          case oDebug: opt.debug |= pargs.r.ret_ulong; break;
2206
2218
          case oDebugAll: opt.debug = ~0; break;
2207
2219
          case oDebugLevel: break; /* Not supported.  */
2208
 
          case oDebugCCIDDriver: 
 
2220
          case oDebugCCIDDriver:
2209
2221
#if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB)
2210
2222
            ccid_set_debug_level (ccid_set_debug_level (1)+1);
2211
2223
#endif
2549
2561
          case oCommandFile:
2550
2562
            opt.command_fd = open_info_file (pargs.r.ret_str, 0);
2551
2563
            break;
2552
 
          case oCipherAlgo: 
 
2564
          case oCipherAlgo:
2553
2565
            def_cipher_string = xstrdup(pargs.r.ret_str);
2554
2566
            break;
2555
2567
          case oDigestAlgo:
2595
2607
          case oNoEscapeFrom: opt.escape_from = 0; break;
2596
2608
          case oLockOnce: opt.lock_once = 1; break;
2597
2609
          case oLockNever:
2598
 
            disable_dotlock ();
 
2610
            dotlock_disable ();
2599
2611
            random_disable_locking ();
2600
2612
            break;
2601
2613
          case oLockMultiple:
2855
2867
            opt.exit_on_status_write_error = 1;
2856
2868
            break;
2857
2869
 
2858
 
          case oLimitCardInsertTries: 
2859
 
            opt.limit_card_insert_tries = pargs.r.ret_int; 
 
2870
          case oLimitCardInsertTries:
 
2871
            opt.limit_card_insert_tries = pargs.r.ret_int;
2860
2872
            break;
2861
2873
 
2862
2874
          case oRequireCrossCert: opt.flags.require_cross_cert=1; break;
2967
2979
                        "--no-literal" );
2968
2980
    }
2969
2981
 
2970
 
#ifndef ENABLE_AGENT_SUPPORT   
 
2982
#ifndef ENABLE_AGENT_SUPPORT
2971
2983
    if (opt.use_agent) {
2972
2984
      log_info(_("NOTE: %s is not available in this version\n"),
2973
2985
               "--use-agent");
3088
3100
        if(opt.def_cipher_algo==0 &&
3089
3101
           (ascii_strcasecmp(def_cipher_string,"idea")==0
3090
3102
            || ascii_strcasecmp(def_cipher_string,"s1")==0))
3091
 
          idea_cipher_warn(1);
 
3103
          {
 
3104
            idea_cipher_warn(1);
 
3105
          }
3092
3106
        xfree(def_cipher_string); def_cipher_string = NULL;
3093
3107
        if( check_cipher_algo(opt.def_cipher_algo) )
3094
3108
            log_error(_("selected cipher algorithm is invalid\n"));
3148
3162
        keygen_set_std_prefs(opt.def_preference_list,0))
3149
3163
      log_error(_("invalid default preferences\n"));
3150
3164
 
3151
 
    /* We provide defaults for the personal digest list.  This is
3152
 
       SHA-1. */
3153
 
    if(!pers_digest_list)
3154
 
      pers_digest_list="h2";
3155
 
 
3156
3165
    if(pers_cipher_list &&
3157
3166
       keygen_set_std_prefs(pers_cipher_list,PREFTYPE_SYM))
3158
3167
      log_error(_("invalid personal cipher preferences\n"));
3310
3319
       case of "-kvv userid keyring".  Also avoid adding the secret
3311
3320
       keyring for a couple of commands to avoid unneeded access in
3312
3321
       case the secrings are stored on a floppy.
3313
 
       
 
3322
 
3314
3323
       We always need to add the keyrings if we are running under
3315
3324
       SELinux, this is so that the rings are added to the list of
3316
3325
       secured files. */
3317
 
    if( ALWAYS_ADD_KEYRINGS 
 
3326
    if( ALWAYS_ADD_KEYRINGS
3318
3327
        || (cmd != aDeArmor && cmd != aEnArmor
3319
 
            && !(cmd == aKMode && argc == 2 )) ) 
 
3328
            && !(cmd == aKMode && argc == 2 )) )
3320
3329
      {
3321
3330
        if (ALWAYS_ADD_KEYRINGS
3322
3331
            || (cmd != aCheckKeys && cmd != aListSigs && cmd != aListKeys
3363
3372
 
3364
3373
    switch (cmd)
3365
3374
      {
3366
 
      case aStore: 
3367
 
      case aSym:  
3368
 
      case aSign: 
3369
 
      case aSignSym: 
3370
 
      case aClearsign: 
 
3375
      case aStore:
 
3376
      case aSym:
 
3377
      case aSign:
 
3378
      case aSignSym:
 
3379
      case aClearsign:
3371
3380
        if (!opt.quiet && any_explicit_recipient)
3372
3381
          log_info (_("WARNING: recipients (-r) given "
3373
3382
                      "without using public key encryption\n"));
3527
3536
              log_error("decrypt_message failed: %s\n", g10_errstr(rc) );
3528
3537
          }
3529
3538
        break;
3530
 
            
 
3539
 
3531
3540
      case aSignKey:
3532
3541
        if( argc != 1 )
3533
3542
          wrong_args(_("--sign-key user-id"));
3906
3915
            wrong_args("--import-ownertrust [file]");
3907
3916
        import_ownertrust( argc? *argv:NULL );
3908
3917
        break;
3909
 
      
 
3918
 
3910
3919
      case aPipeMode:
3911
3920
        if ( argc )
3912
3921
            wrong_args ("--pipemode");
4111
4120
{
4112
4121
    int i, n;
4113
4122
    const byte *p;
4114
 
    
 
4123
 
4115
4124
    if ( fname ) {
4116
4125
        for (p = fname; *p; p++ ) {
4117
4126
            if ( *p <= 32 || *p > 127 || *p == ':' || *p == '%' )
4118
4127
                printf("%%%02X", *p );
4119
 
            else 
 
4128
            else
4120
4129
                putchar( *p );
4121
4130
        }
4122
4131
    }
4124
4133
    printf("%d:", algo );
4125
4134
    p = md_read( md, algo );
4126
4135
    n = md_digest_length(algo);
4127
 
    for(i=0; i < n ; i++, p++ ) 
 
4136
    for(i=0; i < n ; i++, p++ )
4128
4137
        printf("%02X", *p );
4129
4138
    putchar(':');
4130
4139
    putchar('\n');
4182
4191
    else {
4183
4192
        md_final(md);
4184
4193
        if ( opt.with_colons ) {
4185
 
            if ( algo ) 
 
4194
            if ( algo )
4186
4195
                print_hashline( md, algo, fname );
4187
4196
            else {
4188
4197
                print_hashline( md, DIGEST_ALGO_MD5, fname );
4279
4288
    sl=add_to_strlist( &opt.sig_policy_url, string );
4280
4289
 
4281
4290
  if(critical)
4282
 
    sl->flags |= 1;    
 
4291
    sl->flags |= 1;
4283
4292
}
4284
4293
 
4285
4294
static void
4312
4321
    sl=add_to_strlist( &opt.sig_keyserver_url, string );
4313
4322
 
4314
4323
  if(critical)
4315
 
    sl->flags |= 1;    
 
4324
    sl->flags |= 1;
4316
4325
}