~ubuntu-branches/ubuntu/raring/gnupg2/raring-security

« back to all changes in this revision

Viewing changes to g10/gpg.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-05-25 14:27:35 UTC
  • mfrom: (1.1.15 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110525142735-jccyw0fopnyv728q
Tags: 2.0.17-2ubuntu1
* Merge from debian unstable. Remaining changes:
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
    . debian/gnupg2.dev: udev rules to set ACLs on SCM smartcard readers.
    . debian/rules: Call dh_installudev.
  - debian/control: Rename Vcs-* to XS-Debian-Vcs-*.

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,
3
 
 *               2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
3
 *               2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
30
30
#include <sys/stat.h> /* for stat() */
31
31
#endif
32
32
#include <fcntl.h>
33
 
#include <assuan.h>
34
33
#ifdef HAVE_W32_SYSTEM
35
34
#include <windows.h>
36
35
#endif
37
36
 
38
37
#define INCLUDED_BY_MAIN_MODULE 1
39
38
#include "gpg.h"
 
39
#include <assuan.h>
40
40
#include "packet.h"
41
41
#include "../common/iobuf.h"
42
42
#include "util.h"
146
146
    aCardStatus,
147
147
    aCardEdit,
148
148
    aChangePIN,
 
149
    aPasswd,
149
150
    aServer,
150
151
 
151
152
    oTextmode,
207
208
    oCompressLevel,
208
209
    oBZ2CompressLevel,
209
210
    oBZ2DecompressLowmem,
210
 
    oPasswd,
211
 
    oPasswdFD,
212
 
    oPasswdFile,
213
 
    oPasswdRepeat,
 
211
    oPassphrase,
 
212
    oPassphraseFD,
 
213
    oPassphraseFile,
 
214
    oPassphraseRepeat,
214
215
    oCommandFD,
215
216
    oCommandFile,
216
217
    oQuickRandom,
389
390
  ARGPARSE_c (oFingerprint, "fingerprint", N_("list keys and fingerprints")),
390
391
  ARGPARSE_c (aListSecretKeys, "list-secret-keys", N_("list secret keys")),
391
392
  ARGPARSE_c (aKeygen,     "gen-key",  N_("generate a new key pair")),
 
393
  ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")),
392
394
  ARGPARSE_c (aDeleteKeys,"delete-keys", 
393
395
              N_("remove keys from the public keyring")),
394
396
  ARGPARSE_c (aDeleteSecretKeys, "delete-secret-keys",
397
399
  ARGPARSE_c (aLSignKey, "lsign-key"  ,N_("sign a key locally")),
398
400
  ARGPARSE_c (aEditKey,  "edit-key"   ,N_("sign or edit a key")),
399
401
  ARGPARSE_c (aEditKey,  "key-edit"   ,"@"),
400
 
  ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")),
 
402
  ARGPARSE_c (aPasswd,   "passwd",     N_("change a passphrase")),
401
403
  ARGPARSE_c (aDesigRevoke, "desig-revoke","@" ),
402
404
  ARGPARSE_c (aExport, "export"           , N_("export keys") ),
403
405
  ARGPARSE_c (aSendKeys, "send-keys"     , N_("export keys to a key server") ),
599
601
              "delete-secret-and-public-keys", "@"),
600
602
  ARGPARSE_c (aRebuildKeydbCaches, "rebuild-keydb-caches", "@"),
601
603
 
602
 
  ARGPARSE_s_s (oPasswd, "passphrase", "@"),
603
 
  ARGPARSE_s_i (oPasswdFD, "passphrase-fd", "@"),
604
 
  ARGPARSE_s_s (oPasswdFile, "passphrase-file", "@"),
605
 
  ARGPARSE_s_i (oPasswdRepeat, "passphrase-repeat", "@"),
 
604
  ARGPARSE_s_s (oPassphrase,      "passphrase", "@"),
 
605
  ARGPARSE_s_i (oPassphraseFD,    "passphrase-fd", "@"),
 
606
  ARGPARSE_s_s (oPassphraseFile,  "passphrase-file", "@"),
 
607
  ARGPARSE_s_i (oPassphraseRepeat,"passphrase-repeat", "@"),
606
608
  ARGPARSE_s_i (oCommandFD, "command-fd", "@"),
607
609
  ARGPARSE_s_s (oCommandFile, "command-file", "@"),
608
610
  ARGPARSE_s_n (oQuickRandom, "debug-quick-random", "@"),
628
630
  ARGPARSE_s_n (aListSigs, "list-sig", "@"),   /* alias */
629
631
  ARGPARSE_s_n (aCheckKeys, "check-sig", "@"), /* alias */
630
632
  ARGPARSE_s_n (oSkipVerify, "skip-verify", "@"),
631
 
  ARGPARSE_s_n (oSkipVerify, "skip-verify", "@"),
632
633
  ARGPARSE_s_n (oSkipHiddenRecipients, "skip-hidden-recipients", "@"),
633
634
  ARGPARSE_s_n (oNoSkipHiddenRecipients, "no-skip-hidden-recipients", "@"),
634
635
  ARGPARSE_s_n (oCompressKeys, "compress-keys", "@"),
1430
1431
}
1431
1432
 
1432
1433
 
 
1434
/* Print the OpenPGP defined algo numbers.  */
1433
1435
static void
1434
1436
print_algo_numbers(int (*checker)(int))
1435
1437
{
1915
1917
    int fpr_maybe_cmd = 0; /* --fingerprint maybe a command.  */
1916
1918
    int any_explicit_recipient = 0;
1917
1919
    int require_secmem=0,got_secmem=0;
 
1920
    struct assuan_malloc_hooks malloc_hooks;
1918
1921
 
1919
1922
#ifdef __riscos__
1920
1923
    opt.lock_once = 1;
1970
1973
    opt.compress_algo = -1; /* defaults to DEFAULT_COMPRESS_ALGO */
1971
1974
    opt.s2k_mode = 3; /* iterated+salted */
1972
1975
    opt.s2k_count = 0; /* Auto-calibrate when needed.  */
1973
 
#ifdef USE_CAST5
1974
1976
    opt.s2k_cipher_algo = CIPHER_ALGO_CAST5;
1975
 
#else
1976
 
    opt.s2k_cipher_algo = CIPHER_ALGO_3DES;
1977
 
#endif
1978
1977
    opt.completes_needed = 1;
1979
1978
    opt.marginals_needed = 3;
1980
1979
    opt.max_cert_depth = 5;
1997
1996
    opt.def_sig_expire="0";
1998
1997
    opt.def_cert_expire="0";
1999
1998
    set_homedir ( default_homedir () );
2000
 
    opt.passwd_repeat=1;
 
1999
    opt.passphrase_repeat=1;
2001
2000
 
2002
2001
    /* Check whether we have a config file on the command line.  */
2003
2002
    orig_argc = argc;
2064
2063
    /* Okay, we are now working under our real uid */
2065
2064
 
2066
2065
    /* malloc hooks go here ... */
2067
 
    assuan_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free);
2068
 
    assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);
 
2066
    malloc_hooks.malloc = gcry_malloc;
 
2067
    malloc_hooks.realloc = gcry_realloc;
 
2068
    malloc_hooks.free = gcry_free;
 
2069
    assuan_set_malloc_hooks (&malloc_hooks);
 
2070
    assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
2069
2071
 
2070
2072
 
2071
2073
    /* Try for a version specific config file first */
2179
2181
          case aDeleteSecretKeys:
2180
2182
          case aDeleteSecretAndPublicKeys:
2181
2183
          case aDeleteKeys:
 
2184
          case aPasswd:
2182
2185
            set_cmd (&cmd, pargs.r_opt);
2183
2186
            greeting=1;
2184
2187
            break;
2558
2561
          case oCompressLevel: opt.compress_level = pargs.r.ret_int; break;
2559
2562
          case oBZ2CompressLevel: opt.bz2_compress_level = pargs.r.ret_int; break;
2560
2563
          case oBZ2DecompressLowmem: opt.bz2_decompress_lowmem=1; break;
2561
 
          case oPasswd:
 
2564
          case oPassphrase:
2562
2565
            set_passphrase_from_string(pargs.r.ret_str);
2563
2566
            break;
2564
 
          case oPasswdFD:
 
2567
          case oPassphraseFD:
2565
2568
            pwfd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
2566
2569
            break;
2567
 
          case oPasswdFile:
 
2570
          case oPassphraseFile:
2568
2571
            pwfd = open_info_file (pargs.r.ret_str, 0, 1);
2569
2572
            break;
2570
 
          case oPasswdRepeat: opt.passwd_repeat=pargs.r.ret_int; break;
 
2573
          case oPassphraseRepeat: opt.passphrase_repeat=pargs.r.ret_int; break;
2571
2574
          case oCommandFD:
2572
2575
            opt.command_fd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
2573
2576
            break;
3621
3624
        xfree(username);
3622
3625
        break;
3623
3626
 
 
3627
      case aPasswd:
 
3628
        if (argc != 1)
 
3629
          wrong_args (_("--passwd <user-id>"));
 
3630
        else
 
3631
          {
 
3632
            username = make_username (fname);
 
3633
            keyedit_passwd (username);
 
3634
            xfree (username);
 
3635
          }
 
3636
        break;
 
3637
 
3624
3638
      case aDeleteKeys:
3625
3639
      case aDeleteSecretKeys:
3626
3640
      case aDeleteSecretAndPublicKeys: