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

« back to all changes in this revision

Viewing changes to g10/gpg.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-11-03 09:18:26 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20061103091826-89kwl8tk1xypbmtk
Tags: upstream-1.4.5
ImportĀ upstreamĀ versionĀ 1.4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
    oNoAutoCheckTrustDB,
334
334
    oPreservePermissions,
335
335
    oDefaultPreferenceList,
 
336
    oDefaultKeyserverURL,
336
337
    oPersonalCipherPreferences,
337
338
    oPersonalDigestPreferences,
338
339
    oPersonalCompressPreferences,
362
363
    oAutoKeyLocate,
363
364
    oNoAutoKeyLocate,
364
365
    oAllowMultisigVerification,
 
366
    oEnableDSA2,
 
367
    oDisableDSA2,
365
368
 
366
369
    oNoop
367
370
  };
665
668
    { aRebuildKeydbCaches, "rebuild-keydb-caches", 256, "@"},
666
669
    { oPreservePermissions, "preserve-permissions", 0, "@"},
667
670
    { oDefaultPreferenceList,  "default-preference-list", 2, "@"},
 
671
    { oDefaultKeyserverURL,  "default-keyserver-url", 2, "@"},
668
672
    { oPersonalCipherPreferences,  "personal-cipher-preferences", 2, "@"},
669
673
    { oPersonalDigestPreferences,  "personal-digest-preferences", 2, "@"},
670
674
    { oPersonalCompressPreferences,  "personal-compress-preferences", 2, "@"},
699
703
    { oDebugCCIDDriver, "debug-ccid-driver", 0, "@"},
700
704
#endif
701
705
    { oAllowMultisigVerification, "allow-multisig-verification", 0, "@"},
 
706
    { oEnableDSA2, "enable-dsa2", 0, "@"},
 
707
    { oDisableDSA2, "disable-dsa2", 0, "@"},
702
708
 
703
709
    /* These two are aliases to help users of the PGP command line
704
710
       product use gpg with minimal pain.  Many commands are common
1621
1627
    log_error("unknown trust model `%s'\n",model);
1622
1628
}
1623
1629
 
 
1630
/* Must be called before we open any files. */
 
1631
static void
 
1632
reopen_std(void)
 
1633
{  
 
1634
#if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM)
 
1635
  struct stat statbuf;
 
1636
  int did_stdin=0,did_stdout=0,did_stderr=0;
 
1637
  FILE *complain;
 
1638
 
 
1639
  if(fstat(STDIN_FILENO,&statbuf)==-1 && errno==EBADF)
 
1640
    {
 
1641
      if(open("/dev/null",O_RDONLY)==STDIN_FILENO)
 
1642
        did_stdin=1;
 
1643
      else
 
1644
        did_stdin=2;
 
1645
    }
 
1646
 
 
1647
  if(fstat(STDOUT_FILENO,&statbuf)==-1 && errno==EBADF)
 
1648
    {
 
1649
      if(open("/dev/null",O_WRONLY)==STDOUT_FILENO)
 
1650
        did_stdout=1;
 
1651
      else
 
1652
        did_stdout=2;
 
1653
    }
 
1654
 
 
1655
  if(fstat(STDERR_FILENO,&statbuf)==-1 && errno==EBADF)
 
1656
    {
 
1657
      if(open("/dev/null",O_WRONLY)==STDERR_FILENO)
 
1658
        did_stderr=1;
 
1659
      else
 
1660
        did_stderr=2;
 
1661
    }
 
1662
 
 
1663
  /* It's hard to log this sort of thing since the filehandle we would
 
1664
     complain to may be closed... */
 
1665
  if(did_stderr==0)
 
1666
    complain=stderr;
 
1667
  else if(did_stdout==0)
 
1668
    complain=stdout;
 
1669
  else
 
1670
    complain=NULL;
 
1671
 
 
1672
  if(complain)
 
1673
    {
 
1674
      if(did_stdin==1)
 
1675
        fprintf(complain,"gpg: WARNING: standard input reopened\n");
 
1676
      if(did_stdout==1)
 
1677
        fprintf(complain,"gpg: WARNING: standard output reopened\n");
 
1678
      if(did_stderr==1)
 
1679
        fprintf(complain,"gpg: WARNING: standard error reopened\n");
 
1680
 
 
1681
      if(did_stdin==2 || did_stdout==2 || did_stderr==2)
 
1682
        fprintf(complain,"gpg: fatal: unable to reopen standard input,"
 
1683
                " output, or error\n");
 
1684
    }
 
1685
 
 
1686
  if(did_stdin==2 || did_stdout==2 || did_stderr==2)
 
1687
    exit(3);
 
1688
#endif /* HAVE_STAT && !HAVE_W32_SYSTEM */
 
1689
}
 
1690
 
1624
1691
int
1625
1692
main (int argc, char **argv )
1626
1693
{
1671
1738
    opt.lock_once = 1;
1672
1739
#endif /* __riscos__ */
1673
1740
 
 
1741
    reopen_std();
1674
1742
    trap_unaligned();
1675
1743
    secmem_set_flags( secmem_get_flags() | 2 ); /* suspend warnings */
1676
1744
    /* Please note that we may running SUID(ROOT), so be very CAREFUL
2186
2254
            riscos_not_implemented("run-as-shm-coprocess");
2187
2255
#endif /* __riscos__ */
2188
2256
            break;
2189
 
          case oSetFilename: opt.set_filename = pargs.r.ret_str; break;
 
2257
          case oSetFilename:
 
2258
            if(utf8_strings)
 
2259
              opt.set_filename = pargs.r.ret_str;
 
2260
            else
 
2261
              opt.set_filename = native_to_utf8(pargs.r.ret_str);
 
2262
            break;
2190
2263
          case oForYourEyesOnly: eyes_only = 1; break;
2191
2264
          case oNoForYourEyesOnly: eyes_only = 0; break;
2192
2265
          case oSetPolicyURL:
2212
2285
            opt.verify_options&=~VERIFY_SHOW_POLICY_URLS;
2213
2286
            break;
2214
2287
          case oSigKeyserverURL: add_keyserver_url(pargs.r.ret_str,0); break;
2215
 
          case oUseEmbeddedFilename: opt.use_embedded_filename = 1; break;
2216
 
          case oNoUseEmbeddedFilename: opt.use_embedded_filename = 0; break;
 
2288
          case oUseEmbeddedFilename:
 
2289
            opt.flags.use_embedded_filename=1;
 
2290
            break;
 
2291
          case oNoUseEmbeddedFilename:
 
2292
            opt.flags.use_embedded_filename=0;
 
2293
            break;
2217
2294
          case oComment:
2218
2295
            if(pargs.r.ret_str[0])
2219
2296
              append_to_strlist(&opt.comments,pargs.r.ret_str);
2577
2654
          case oDefaultPreferenceList:
2578
2655
            opt.def_preference_list = pargs.r.ret_str;
2579
2656
            break;
 
2657
          case oDefaultKeyserverURL:
 
2658
            {
 
2659
              struct keyserver_spec *keyserver;
 
2660
              keyserver=parse_keyserver_uri(pargs.r.ret_str,1,
 
2661
                                            configname,configlineno);
 
2662
              if(!keyserver)
 
2663
                log_error(_("could not parse keyserver URL\n"));
 
2664
              else
 
2665
                free_keyserver_spec(keyserver);
 
2666
 
 
2667
              opt.def_keyserver_url = pargs.r.ret_str;
 
2668
            }
 
2669
            break;
2580
2670
          case oPersonalCipherPreferences:
2581
2671
            pers_cipher_list=pargs.r.ret_str;
2582
2672
            break;
2650
2740
            opt.allow_multisig_verification = 1;
2651
2741
            break;
2652
2742
 
 
2743
          case oEnableDSA2: opt.flags.dsa2=1; break;
 
2744
          case oDisableDSA2: opt.flags.dsa2=0; break;
 
2745
 
2653
2746
          case oNoop: break;
2654
2747
 
2655
2748
          default : pargs.err = configfp? 1:2; break;
3095
3188
 
3096
3189
    fname = argc? *argv : NULL;
3097
3190
 
 
3191
    if(fname && utf8_strings)
 
3192
      opt.flags.utf8_filename=1;
 
3193
 
3098
3194
    switch( cmd ) {
3099
3195
      case aPrimegen:
3100
3196
      case aPrintMD:
3399
3495
        import_keys( argc? argv:NULL, argc, NULL, opt.import_options );
3400
3496
        break;
3401
3497
 
 
3498
        /* TODO: There are a number of command that use this same
 
3499
           "make strlist, call function, report error, free strlist"
 
3500
           pattern.  Join them together here and avoid all that
 
3501
           duplicated code. */
 
3502
 
3402
3503
      case aExport:
3403
3504
      case aSendKeys:
3404
3505
      case aRecvKeys:
3405
3506
        sl = NULL;
3406
3507
        for( ; argc; argc--, argv++ )
3407
 
            add_to_strlist2( &sl, *argv, utf8_strings );
 
3508
            append_to_strlist2( &sl, *argv, utf8_strings );
3408
3509
        if( cmd == aSendKeys )
3409
3510
            rc=keyserver_export( sl );
3410
3511
        else if( cmd == aRecvKeys )
3436
3537
      case aRefreshKeys:
3437
3538
        sl = NULL;
3438
3539
        for( ; argc; argc--, argv++ )
3439
 
            add_to_strlist2( &sl, *argv, utf8_strings );
 
3540
            append_to_strlist2( &sl, *argv, utf8_strings );
3440
3541
        rc=keyserver_refresh(sl);
3441
3542
        if(rc)
3442
3543
          log_error(_("keyserver refresh failed: %s\n"),g10_errstr(rc));
3446
3547
      case aFetchKeys:
3447
3548
        sl = NULL;
3448
3549
        for( ; argc; argc--, argv++ )
3449
 
            add_to_strlist2( &sl, *argv, utf8_strings );
 
3550
            append_to_strlist2( &sl, *argv, utf8_strings );
3450
3551
        rc=keyserver_fetch(sl);
3451
3552
        if(rc)
3452
3553
          log_error("key fetch failed: %s\n",g10_errstr(rc));
3914
4015
        md_enable( md, DIGEST_ALGO_SHA1 );
3915
4016
        md_enable( md, DIGEST_ALGO_RMD160 );
3916
4017
#ifdef USE_SHA256
 
4018
        md_enable( md, DIGEST_ALGO_SHA224 );
3917
4019
        md_enable( md, DIGEST_ALGO_SHA256 );
3918
4020
#endif
3919
4021
#ifdef USE_SHA512
3936
4038
                print_hashline( md, DIGEST_ALGO_SHA1, fname );
3937
4039
                print_hashline( md, DIGEST_ALGO_RMD160, fname );
3938
4040
#ifdef USE_SHA256
 
4041
                print_hashline( md, DIGEST_ALGO_SHA224, fname );
3939
4042
                print_hashline( md, DIGEST_ALGO_SHA256, fname );
3940
4043
#endif
3941
4044
#ifdef USE_SHA512
3952
4055
                print_hex( md, DIGEST_ALGO_SHA1, fname );
3953
4056
                print_hex( md, DIGEST_ALGO_RMD160, fname );
3954
4057
#ifdef USE_SHA256
 
4058
                print_hex( md, DIGEST_ALGO_SHA224, fname );
3955
4059
                print_hex( md, DIGEST_ALGO_SHA256, fname );
3956
4060
#endif
3957
4061
#ifdef USE_SHA512