1 /* gpg.c - The GnuPG utility (main for gpg)
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 * 2006, 2007, 2008 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
30 #include <sys/stat.h> /* for stat() */
34 #ifdef HAVE_W32_SYSTEM
38 #define INCLUDED_BY_MAIN_MODULE 1
41 #include "../common/iobuf.h"
53 #include "keyserver-internal.h"
55 #include "gc-opt-flags.h"
57 #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__)
58 #define MY_O_BINARY O_BINARY
68 enum cmd_and_opt_values
82 oHiddenRecipient
= 'R',
89 aListSecretKeys
= 'K',
114 aDeleteSecretAndPublicKeys
,
209 oBZ2DecompressLowmem
,
250 oUseEmbeddedFilename
,
251 oNoUseEmbeddedFilename
,
297 oAllowNonSelfsignedUID
,
298 oNoAllowNonSelfsignedUID
,
301 oAllowSecretKeyImport
,
302 oEnableSpecialFilenames
,
323 oNoExpensiveTrustChecks
,
329 oPreservePermissions
,
330 oDefaultPreferenceList
,
331 oDefaultKeyserverURL
,
332 oPersonalCipherPreferences
,
333 oPersonalDigestPreferences
,
334 oPersonalCompressPreferences
,
348 oNoMangleDosFilenames
,
349 oEnableProgressFilter
,
352 oExitOnStatusWriteError
,
353 oLimitCardInsertTries
,
358 oAllowMultisigVerification
,
361 oAllowMultipleMessages
,
362 oNoAllowMultipleMessages
,
368 static ARGPARSE_OPTS opts
[] = {
370 ARGPARSE_group (300, N_("@Commands:\n ")),
372 ARGPARSE_c (aSign
, "sign", N_("make a signature")),
373 ARGPARSE_c (aClearsign
, "clearsign", N_("make a clear text signature")),
374 ARGPARSE_c (aDetachedSign
, "detach-sign", N_("make a detached signature")),
375 ARGPARSE_c (aEncr
, "encrypt", N_("encrypt data")),
376 ARGPARSE_c (aEncrFiles
, "encrypt-files", "@"),
377 ARGPARSE_c (aSym
, "symmetric", N_("encryption only with symmetric cipher")),
378 ARGPARSE_c (aStore
, "store", "@"),
379 ARGPARSE_c (aDecrypt
, "decrypt", N_("decrypt data (default)")),
380 ARGPARSE_c (aDecryptFiles
, "decrypt-files", "@"),
381 ARGPARSE_c (aVerify
, "verify" , N_("verify a signature")),
382 ARGPARSE_c (aVerifyFiles
, "verify-files" , "@" ),
383 ARGPARSE_c (aListKeys
, "list-keys", N_("list keys")),
384 ARGPARSE_c (aListKeys
, "list-public-keys", "@" ),
385 ARGPARSE_c (aListSigs
, "list-sigs", N_("list keys and signatures")),
386 ARGPARSE_c (aCheckKeys
, "check-sigs",N_("list and check key signatures")),
387 ARGPARSE_c (oFingerprint
, "fingerprint", N_("list keys and fingerprints")),
388 ARGPARSE_c (aListSecretKeys
, "list-secret-keys", N_("list secret keys")),
389 ARGPARSE_c (aKeygen
, "gen-key", N_("generate a new key pair")),
390 ARGPARSE_c (aDeleteKeys
,"delete-keys",
391 N_("remove keys from the public keyring")),
392 ARGPARSE_c (aDeleteSecretKeys
, "delete-secret-keys",
393 N_("remove keys from the secret keyring")),
394 ARGPARSE_c (aSignKey
, "sign-key" ,N_("sign a key")),
395 ARGPARSE_c (aLSignKey
, "lsign-key" ,N_("sign a key locally")),
396 ARGPARSE_c (aEditKey
, "edit-key" ,N_("sign or edit a key")),
397 ARGPARSE_c (aGenRevoke
, "gen-revoke",N_("generate a revocation certificate")),
398 ARGPARSE_c (aDesigRevoke
, "desig-revoke","@" ),
399 ARGPARSE_c (aExport
, "export" , N_("export keys") ),
400 ARGPARSE_c (aSendKeys
, "send-keys" , N_("export keys to a key server") ),
401 ARGPARSE_c (aRecvKeys
, "recv-keys" , N_("import keys from a key server") ),
402 ARGPARSE_c (aSearchKeys
, "search-keys" ,
403 N_("search for keys on a key server") ),
404 ARGPARSE_c (aRefreshKeys
, "refresh-keys",
405 N_("update all keys from a keyserver")),
406 ARGPARSE_c (aLocateKeys
, "locate-keys", "@"),
407 ARGPARSE_c (aFetchKeys
, "fetch-keys" , "@" ),
408 ARGPARSE_c (aExportSecret
, "export-secret-keys" , "@" ),
409 ARGPARSE_c (aExportSecretSub
, "export-secret-subkeys" , "@" ),
410 ARGPARSE_c (aImport
, "import", N_("import/merge keys")),
411 ARGPARSE_c (aFastImport
, "fast-import", "@"),
412 #ifdef ENABLE_CARD_SUPPORT
413 ARGPARSE_c (aCardStatus
, "card-status", N_("print the card status")),
414 ARGPARSE_c (aCardEdit
, "card-edit", N_("change data on a card")),
415 ARGPARSE_c (aChangePIN
, "change-pin", N_("change a card's PIN")),
417 ARGPARSE_c (aListConfig
, "list-config", "@"),
418 ARGPARSE_c (aGPGConfList
, "gpgconf-list", "@" ),
419 ARGPARSE_c (aGPGConfTest
, "gpgconf-test", "@" ),
420 ARGPARSE_c (aListPackets
, "list-packets","@"),
421 ARGPARSE_c (aExportOwnerTrust
, "export-ownertrust", "@"),
422 ARGPARSE_c (aImportOwnerTrust
, "import-ownertrust", "@"),
423 ARGPARSE_c (aUpdateTrustDB
,"update-trustdb",
424 N_("update the trust database")),
425 ARGPARSE_c (aCheckTrustDB
, "check-trustdb", "@"),
426 ARGPARSE_c (aFixTrustDB
, "fix-trustdb", "@"),
427 ARGPARSE_c (aDeArmor
, "dearmor", "@"),
428 ARGPARSE_c (aDeArmor
, "dearmour", "@"),
429 ARGPARSE_c (aEnArmor
, "enarmor", "@"),
430 ARGPARSE_c (aEnArmor
, "enarmour", "@"),
431 ARGPARSE_c (aPrintMD
, "print-md", N_("print message digests")),
432 ARGPARSE_c (aPrimegen
, "gen-prime", "@" ),
433 ARGPARSE_c (aGenRandom
,"gen-random", "@" ),
434 ARGPARSE_c (aServer
, "server", N_("run in server mode")),
436 ARGPARSE_group (301, N_("@\nOptions:\n ")),
438 ARGPARSE_s_n (oArmor
, "armor", N_("create ascii armored output")),
439 ARGPARSE_s_n (oArmor
, "armour", "@"),
441 ARGPARSE_s_s (oRecipient
, "recipient", N_("|USER-ID|encrypt for USER-ID")),
442 ARGPARSE_s_s (oHiddenRecipient
, "hidden-recipient", "@"),
443 ARGPARSE_s_s (oRecipient
, "remote-user", "@"), /* (old option name) */
444 ARGPARSE_s_s (oDefRecipient
, "default-recipient", "@"),
445 ARGPARSE_s_n (oDefRecipientSelf
, "default-recipient-self", "@"),
446 ARGPARSE_s_n (oNoDefRecipient
, "no-default-recipient", "@"),
448 ARGPARSE_s_s (oTempDir
, "temp-directory", "@"),
449 ARGPARSE_s_s (oExecPath
, "exec-path", "@"),
450 ARGPARSE_s_s (oEncryptTo
, "encrypt-to", "@"),
451 ARGPARSE_s_n (oNoEncryptTo
, "no-encrypt-to", "@"),
452 ARGPARSE_s_s (oHiddenEncryptTo
, "hidden-encrypt-to", "@"),
453 ARGPARSE_s_s (oLocalUser
, "local-user",
454 N_("|USER-ID|use USER-ID to sign or decrypt")),
456 ARGPARSE_s_i (oCompress
, NULL
,
457 N_("|N|set compress level to N (0 disables)")),
458 ARGPARSE_s_i (oCompressLevel
, "compress-level", "@"),
459 ARGPARSE_s_i (oBZ2CompressLevel
, "bzip2-compress-level", "@"),
460 ARGPARSE_s_n (oBZ2DecompressLowmem
, "bzip2-decompress-lowmem", "@"),
462 ARGPARSE_s_n (oTextmodeShort
, NULL
, "@"),
463 ARGPARSE_s_n (oTextmode
, "textmode", N_("use canonical text mode")),
464 ARGPARSE_s_n (oNoTextmode
, "no-textmode", "@"),
466 ARGPARSE_s_n (oExpert
, "expert", "@"),
467 ARGPARSE_s_n (oNoExpert
, "no-expert", "@"),
469 ARGPARSE_s_s (oDefSigExpire
, "default-sig-expire", "@"),
470 ARGPARSE_s_n (oAskSigExpire
, "ask-sig-expire", "@"),
471 ARGPARSE_s_n (oNoAskSigExpire
, "no-ask-sig-expire", "@"),
472 ARGPARSE_s_s (oDefCertExpire
, "default-cert-expire", "@"),
473 ARGPARSE_s_n (oAskCertExpire
, "ask-cert-expire", "@"),
474 ARGPARSE_s_n (oNoAskCertExpire
, "no-ask-cert-expire", "@"),
475 ARGPARSE_s_i (oDefCertLevel
, "default-cert-level", "@"),
476 ARGPARSE_s_i (oMinCertLevel
, "min-cert-level", "@"),
477 ARGPARSE_s_n (oAskCertLevel
, "ask-cert-level", "@"),
478 ARGPARSE_s_n (oNoAskCertLevel
, "no-ask-cert-level", "@"),
480 ARGPARSE_s_s (oOutput
, "output", N_("|FILE|write output to FILE")),
481 ARGPARSE_p_u (oMaxOutput
, "max-output", "@"),
483 ARGPARSE_s_n (oVerbose
, "verbose", N_("verbose")),
484 ARGPARSE_s_n (oQuiet
, "quiet", "@"),
485 ARGPARSE_s_n (oNoTTY
, "no-tty", "@"),
487 ARGPARSE_s_n (oForceV3Sigs
, "force-v3-sigs", "@"),
488 ARGPARSE_s_n (oNoForceV3Sigs
, "no-force-v3-sigs", "@"),
489 ARGPARSE_s_n (oForceV4Certs
, "force-v4-certs", "@"),
490 ARGPARSE_s_n (oNoForceV4Certs
, "no-force-v4-certs", "@"),
491 ARGPARSE_s_n (oForceMDC
, "force-mdc", "@"),
492 ARGPARSE_s_n (oNoForceMDC
, "no-force-mdc", "@"),
493 ARGPARSE_s_n (oDisableMDC
, "disable-mdc", "@"),
494 ARGPARSE_s_n (oNoDisableMDC
, "no-disable-mdc", "@"),
496 ARGPARSE_s_n (oDryRun
, "dry-run", N_("do not make any changes")),
497 ARGPARSE_s_n (oInteractive
, "interactive", N_("prompt before overwriting")),
499 ARGPARSE_s_n (oUseAgent
, "use-agent", "@"),
500 ARGPARSE_s_n (oNoUseAgent
, "no-use-agent", "@"),
501 ARGPARSE_s_s (oGpgAgentInfo
, "gpg-agent-info", "@"),
503 ARGPARSE_s_n (oBatch
, "batch", "@"),
504 ARGPARSE_s_n (oAnswerYes
, "yes", "@"),
505 ARGPARSE_s_n (oAnswerNo
, "no", "@"),
506 ARGPARSE_s_s (oKeyring
, "keyring", "@"),
507 ARGPARSE_s_s (oPrimaryKeyring
, "primary-keyring", "@"),
508 ARGPARSE_s_s (oSecretKeyring
, "secret-keyring", "@"),
509 ARGPARSE_s_n (oShowKeyring
, "show-keyring", "@"),
510 ARGPARSE_s_s (oDefaultKey
, "default-key", "@"),
512 ARGPARSE_s_s (oKeyServer
, "keyserver", "@"),
513 ARGPARSE_s_s (oKeyServerOptions
, "keyserver-options", "@"),
514 ARGPARSE_s_s (oImportOptions
, "import-options", "@"),
515 ARGPARSE_s_s (oExportOptions
, "export-options", "@"),
516 ARGPARSE_s_s (oListOptions
, "list-options", "@"),
517 ARGPARSE_s_s (oVerifyOptions
, "verify-options", "@"),
519 ARGPARSE_s_s (oDisplayCharset
, "display-charset", "@"),
520 ARGPARSE_s_s (oDisplayCharset
, "charset", "@"),
521 ARGPARSE_s_s (oOptions
, "options", "@"),
523 ARGPARSE_p_u (oDebug
, "debug", "@"),
524 ARGPARSE_s_s (oDebugLevel
, "debug-level", "@"),
525 ARGPARSE_s_n (oDebugAll
, "debug-all", "@"),
526 ARGPARSE_s_i (oStatusFD
, "status-fd", "@"),
527 ARGPARSE_s_s (oStatusFile
, "status-file", "@"),
528 ARGPARSE_s_i (oAttributeFD
, "attribute-fd", "@"),
529 ARGPARSE_s_s (oAttributeFile
, "attribute-file", "@"),
531 ARGPARSE_s_n (oNoop
, "sk-comments", "@"),
532 ARGPARSE_s_n (oNoop
, "no-sk-comments", "@"),
534 ARGPARSE_s_i (oCompletesNeeded
, "completes-needed", "@"),
535 ARGPARSE_s_i (oMarginalsNeeded
, "marginals-needed", "@"),
536 ARGPARSE_s_i (oMaxCertDepth
, "max-cert-depth", "@" ),
537 ARGPARSE_s_s (oTrustedKey
, "trusted-key", "@"),
539 ARGPARSE_s_s (oLoadExtension
, "load-extension", "@"), /* Dummy. */
541 ARGPARSE_s_n (oGnuPG
, "gnupg", "@"),
542 ARGPARSE_s_n (oGnuPG
, "no-pgp2", "@"),
543 ARGPARSE_s_n (oGnuPG
, "no-pgp6", "@"),
544 ARGPARSE_s_n (oGnuPG
, "no-pgp7", "@"),
545 ARGPARSE_s_n (oGnuPG
, "no-pgp8", "@"),
546 ARGPARSE_s_n (oRFC1991
, "rfc1991", "@"),
547 ARGPARSE_s_n (oRFC2440
, "rfc2440", "@"),
548 ARGPARSE_s_n (oRFC4880
, "rfc4880", "@"),
549 ARGPARSE_s_n (oOpenPGP
, "openpgp", N_("use strict OpenPGP behavior")),
550 ARGPARSE_s_n (oPGP2
, "pgp2", "@"),
551 ARGPARSE_s_n (oPGP6
, "pgp6", "@"),
552 ARGPARSE_s_n (oPGP7
, "pgp7", "@"),
553 ARGPARSE_s_n (oPGP8
, "pgp8", "@"),
555 ARGPARSE_s_n (oRFC2440Text
, "rfc2440-text", "@"),
556 ARGPARSE_s_n (oNoRFC2440Text
, "no-rfc2440-text", "@"),
557 ARGPARSE_s_i (oS2KMode
, "s2k-mode", "@"),
558 ARGPARSE_s_s (oS2KDigest
, "s2k-digest-algo", "@"),
559 ARGPARSE_s_s (oS2KCipher
, "s2k-cipher-algo", "@"),
560 ARGPARSE_s_i (oS2KCount
, "s2k-count", "@"),
561 ARGPARSE_s_n (oSimpleSKChecksum
, "simple-sk-checksum", "@"),
562 ARGPARSE_s_s (oCipherAlgo
, "cipher-algo", "@"),
563 ARGPARSE_s_s (oDigestAlgo
, "digest-algo", "@"),
564 ARGPARSE_s_s (oCertDigestAlgo
, "cert-digest-algo", "@"),
565 ARGPARSE_s_s (oCompressAlgo
,"compress-algo", "@"),
566 ARGPARSE_s_s (oCompressAlgo
, "compression-algo", "@"), /* Alias */
567 ARGPARSE_s_n (oThrowKeyids
, "throw-keyid", "@"),
568 ARGPARSE_s_n (oThrowKeyids
, "throw-keyids", "@"),
569 ARGPARSE_s_n (oNoThrowKeyids
, "no-throw-keyid", "@"),
570 ARGPARSE_s_n (oNoThrowKeyids
, "no-throw-keyids", "@"),
571 ARGPARSE_s_n (oShowPhotos
, "show-photos", "@"),
572 ARGPARSE_s_n (oNoShowPhotos
, "no-show-photos", "@"),
573 ARGPARSE_s_s (oPhotoViewer
, "photo-viewer", "@"),
574 ARGPARSE_s_s (oSetNotation
, "set-notation", "@"),
575 ARGPARSE_s_s (oSetNotation
, "notation-data", "@"), /* Alias */
576 ARGPARSE_s_s (oSigNotation
, "sig-notation", "@"),
577 ARGPARSE_s_s (oCertNotation
, "cert-notation", "@"),
579 ARGPARSE_group (302, N_(
580 "@\n(See the man page for a complete listing of all commands and options)\n"
583 ARGPARSE_group (303, N_("@\nExamples:\n\n"
584 " -se -r Bob [file] sign and encrypt for user Bob\n"
585 " --clearsign [file] make a clear text signature\n"
586 " --detach-sign [file] make a detached signature\n"
587 " --list-keys [names] show keys\n"
588 " --fingerprint [names] show fingerprints\n")),
590 /* More hidden commands and options. */
591 ARGPARSE_c (aPrintMDs
, "print-mds", "@"), /* old */
592 ARGPARSE_c (aListTrustDB
, "list-trustdb", "@"),
594 ARGPARSE_c (aListTrustPath, "list-trust-path", "@"), */
595 ARGPARSE_c (aDeleteSecretAndPublicKeys
,
596 "delete-secret-and-public-keys", "@"),
597 ARGPARSE_c (aRebuildKeydbCaches
, "rebuild-keydb-caches", "@"),
599 ARGPARSE_s_s (oPasswd
, "passphrase", "@"),
600 ARGPARSE_s_i (oPasswdFD
, "passphrase-fd", "@"),
601 ARGPARSE_s_s (oPasswdFile
, "passphrase-file", "@"),
602 ARGPARSE_s_i (oPasswdRepeat
, "passphrase-repeat", "@"),
603 ARGPARSE_s_i (oCommandFD
, "command-fd", "@"),
604 ARGPARSE_s_s (oCommandFile
, "command-file", "@"),
605 ARGPARSE_s_n (oQuickRandom
, "debug-quick-random", "@"),
606 ARGPARSE_s_n (oNoVerbose
, "no-verbose", "@"),
607 ARGPARSE_s_s (oTrustDBName
, "trustdb-name", "@"),
608 ARGPARSE_s_n (oNoSecmemWarn
, "no-secmem-warning", "@"),
609 ARGPARSE_s_n (oRequireSecmem
, "require-secmem", "@"),
610 ARGPARSE_s_n (oNoRequireSecmem
, "no-require-secmem", "@"),
611 ARGPARSE_s_n (oNoPermissionWarn
, "no-permission-warning", "@"),
612 ARGPARSE_s_n (oNoMDCWarn
, "no-mdc-warning", "@"),
613 ARGPARSE_s_n (oNoArmor
, "no-armor", "@"),
614 ARGPARSE_s_n (oNoArmor
, "no-armour", "@"),
615 ARGPARSE_s_n (oNoDefKeyring
, "no-default-keyring", "@"),
616 ARGPARSE_s_n (oNoGreeting
, "no-greeting", "@"),
617 ARGPARSE_s_n (oNoOptions
, "no-options", "@"),
618 ARGPARSE_s_s (oHomedir
, "homedir", "@"),
619 ARGPARSE_s_n (oNoBatch
, "no-batch", "@"),
620 ARGPARSE_s_n (oWithColons
, "with-colons", "@"),
621 ARGPARSE_s_n (oWithKeyData
,"with-key-data", "@"),
622 ARGPARSE_s_n (oWithSigList
,"with-sig-list", "@"),
623 ARGPARSE_s_n (oWithSigCheck
,"with-sig-check", "@"),
624 ARGPARSE_s_n (aListKeys
, "list-key", "@"), /* alias */
625 ARGPARSE_s_n (aListSigs
, "list-sig", "@"), /* alias */
626 ARGPARSE_s_n (aCheckKeys
, "check-sig", "@"), /* alias */
627 ARGPARSE_s_n (oSkipVerify
, "skip-verify", "@"),
628 ARGPARSE_s_n (oCompressKeys
, "compress-keys", "@"),
629 ARGPARSE_s_n (oCompressSigs
, "compress-sigs", "@"),
630 ARGPARSE_s_i (oDefCertLevel
, "default-cert-check-level", "@"), /* old */
631 ARGPARSE_s_n (oAlwaysTrust
, "always-trust", "@"),
632 ARGPARSE_s_s (oTrustModel
, "trust-model", "@"),
633 ARGPARSE_s_s (oForceOwnertrust
, "force-ownertrust", "@"),
634 ARGPARSE_s_s (oSetFilename
, "set-filename", "@"),
635 ARGPARSE_s_n (oForYourEyesOnly
, "for-your-eyes-only", "@"),
636 ARGPARSE_s_n (oNoForYourEyesOnly
, "no-for-your-eyes-only", "@"),
637 ARGPARSE_s_s (oSetPolicyURL
, "set-policy-url", "@"),
638 ARGPARSE_s_s (oSigPolicyURL
, "sig-policy-url", "@"),
639 ARGPARSE_s_s (oCertPolicyURL
, "cert-policy-url", "@"),
640 ARGPARSE_s_n (oShowPolicyURL
, "show-policy-url", "@"),
641 ARGPARSE_s_n (oNoShowPolicyURL
, "no-show-policy-url", "@"),
642 ARGPARSE_s_s (oSigKeyserverURL
, "sig-keyserver-url", "@"),
643 ARGPARSE_s_n (oShowNotation
, "show-notation", "@"),
644 ARGPARSE_s_n (oNoShowNotation
, "no-show-notation", "@"),
645 ARGPARSE_s_s (oComment
, "comment", "@"),
646 ARGPARSE_s_n (oDefaultComment
, "default-comment", "@"),
647 ARGPARSE_s_n (oNoComments
, "no-comments", "@"),
648 ARGPARSE_s_n (oEmitVersion
, "emit-version", "@"),
649 ARGPARSE_s_n (oNoEmitVersion
, "no-emit-version", "@"),
650 ARGPARSE_s_n (oNoEmitVersion
, "no-version", "@"), /* alias */
651 ARGPARSE_s_n (oNotDashEscaped
, "not-dash-escaped", "@"),
652 ARGPARSE_s_n (oEscapeFrom
, "escape-from-lines", "@"),
653 ARGPARSE_s_n (oNoEscapeFrom
, "no-escape-from-lines", "@"),
654 ARGPARSE_s_n (oLockOnce
, "lock-once", "@"),
655 ARGPARSE_s_n (oLockMultiple
, "lock-multiple", "@"),
656 ARGPARSE_s_n (oLockNever
, "lock-never", "@"),
657 ARGPARSE_s_i (oLoggerFD
, "logger-fd", "@"),
658 ARGPARSE_s_s (oLoggerFile
, "log-file", "@"),
659 ARGPARSE_s_s (oLoggerFile
, "logger-file", "@"), /* 1.4 compatibility. */
660 ARGPARSE_s_n (oUseEmbeddedFilename
, "use-embedded-filename", "@"),
661 ARGPARSE_s_n (oNoUseEmbeddedFilename
, "no-use-embedded-filename", "@"),
662 ARGPARSE_s_n (oUtf8Strings
, "utf8-strings", "@"),
663 ARGPARSE_s_n (oNoUtf8Strings
, "no-utf8-strings", "@"),
664 ARGPARSE_s_n (oWithFingerprint
, "with-fingerprint", "@"),
665 ARGPARSE_s_s (oDisableCipherAlgo
, "disable-cipher-algo", "@"),
666 ARGPARSE_s_s (oDisablePubkeyAlgo
, "disable-pubkey-algo", "@"),
667 ARGPARSE_s_n (oAllowNonSelfsignedUID
, "allow-non-selfsigned-uid", "@"),
668 ARGPARSE_s_n (oNoAllowNonSelfsignedUID
, "no-allow-non-selfsigned-uid", "@"),
669 ARGPARSE_s_n (oAllowFreeformUID
, "allow-freeform-uid", "@"),
670 ARGPARSE_s_n (oNoAllowFreeformUID
, "no-allow-freeform-uid", "@"),
671 ARGPARSE_s_n (oNoLiteral
, "no-literal", "@"),
672 ARGPARSE_p_u (oSetFilesize
, "set-filesize", "@"),
673 ARGPARSE_s_n (oHonorHttpProxy
, "honor-http-proxy", "@"),
674 ARGPARSE_s_n (oFastListMode
, "fast-list-mode", "@"),
675 ARGPARSE_s_n (oFixedListMode
, "fixed-list-mode", "@"),
676 ARGPARSE_s_n (oListOnly
, "list-only", "@"),
677 ARGPARSE_s_n (oIgnoreTimeConflict
, "ignore-time-conflict", "@"),
678 ARGPARSE_s_n (oIgnoreValidFrom
, "ignore-valid-from", "@"),
679 ARGPARSE_s_n (oIgnoreCrcError
, "ignore-crc-error", "@"),
680 ARGPARSE_s_n (oIgnoreMDCError
, "ignore-mdc-error", "@"),
681 ARGPARSE_s_n (oShowSessionKey
, "show-session-key", "@"),
682 ARGPARSE_s_s (oOverrideSessionKey
, "override-session-key", "@"),
683 ARGPARSE_s_n (oNoRandomSeedFile
, "no-random-seed-file", "@"),
684 ARGPARSE_s_n (oAutoKeyRetrieve
, "auto-key-retrieve", "@"),
685 ARGPARSE_s_n (oNoAutoKeyRetrieve
, "no-auto-key-retrieve", "@"),
686 ARGPARSE_s_n (oNoSigCache
, "no-sig-cache", "@"),
687 ARGPARSE_s_n (oNoSigCreateCheck
, "no-sig-create-check", "@"),
688 ARGPARSE_s_n (oAutoCheckTrustDB
, "auto-check-trustdb", "@"),
689 ARGPARSE_s_n (oNoAutoCheckTrustDB
, "no-auto-check-trustdb", "@"),
690 ARGPARSE_s_n (oMergeOnly
, "merge-only", "@" ),
691 ARGPARSE_s_n (oAllowSecretKeyImport
, "allow-secret-key-import", "@"),
692 ARGPARSE_s_n (oTryAllSecrets
, "try-all-secrets", "@"),
693 ARGPARSE_s_n (oEnableSpecialFilenames
, "enable-special-filenames", "@"),
694 ARGPARSE_s_n (oNoExpensiveTrustChecks
, "no-expensive-trust-checks", "@"),
695 ARGPARSE_s_n (oPreservePermissions
, "preserve-permissions", "@"),
696 ARGPARSE_s_s (oDefaultPreferenceList
, "default-preference-list", "@"),
697 ARGPARSE_s_s (oDefaultKeyserverURL
, "default-keyserver-url", "@"),
698 ARGPARSE_s_s (oPersonalCipherPreferences
, "personal-cipher-preferences","@"),
699 ARGPARSE_s_s (oPersonalDigestPreferences
, "personal-digest-preferences","@"),
700 ARGPARSE_s_s (oPersonalCompressPreferences
,
701 "personal-compress-preferences", "@"),
703 /* Aliases. I constantly mistype these, and assume other people do
705 ARGPARSE_s_s (oPersonalCipherPreferences
, "personal-cipher-prefs", "@"),
706 ARGPARSE_s_s (oPersonalDigestPreferences
, "personal-digest-prefs", "@"),
707 ARGPARSE_s_s (oPersonalCompressPreferences
, "personal-compress-prefs", "@"),
708 ARGPARSE_s_s (oAgentProgram
, "agent-program", "@"),
709 ARGPARSE_s_s (oDisplay
, "display", "@"),
710 ARGPARSE_s_s (oTTYname
, "ttyname", "@"),
711 ARGPARSE_s_s (oTTYtype
, "ttytype", "@"),
712 ARGPARSE_s_s (oLCctype
, "lc-ctype", "@"),
713 ARGPARSE_s_s (oLCmessages
, "lc-messages","@"),
714 ARGPARSE_s_s (oXauthority
, "xauthority", "@"),
715 ARGPARSE_s_s (oGroup
, "group", "@"),
716 ARGPARSE_s_s (oUnGroup
, "ungroup", "@"),
717 ARGPARSE_s_n (oNoGroups
, "no-groups", "@"),
718 ARGPARSE_s_n (oStrict
, "strict", "@"),
719 ARGPARSE_s_n (oNoStrict
, "no-strict", "@"),
720 ARGPARSE_s_n (oMangleDosFilenames
, "mangle-dos-filenames", "@"),
721 ARGPARSE_s_n (oNoMangleDosFilenames
, "no-mangle-dos-filenames", "@"),
722 ARGPARSE_s_n (oEnableProgressFilter
, "enable-progress-filter", "@"),
723 ARGPARSE_s_n (oMultifile
, "multifile", "@"),
724 ARGPARSE_s_s (oKeyidFormat
, "keyid-format", "@"),
725 ARGPARSE_s_n (oExitOnStatusWriteError
, "exit-on-status-write-error", "@"),
726 ARGPARSE_s_i (oLimitCardInsertTries
, "limit-card-insert-tries", "@"),
728 ARGPARSE_s_n (oAllowMultisigVerification
,
729 "allow-multisig-verification", "@"),
730 ARGPARSE_s_n (oEnableDSA2
, "enable-dsa2", "@"),
731 ARGPARSE_s_n (oDisableDSA2
, "disable-dsa2", "@"),
732 ARGPARSE_s_n (oAllowMultipleMessages
, "allow-multiple-messages", "@"),
733 ARGPARSE_s_n (oNoAllowMultipleMessages
, "no-allow-multiple-messages", "@"),
735 /* These two are aliases to help users of the PGP command line
736 product use gpg with minimal pain. Many commands are common
737 already as they seem to have borrowed commands from us. Now I'm
738 returning the favor. */
739 ARGPARSE_s_s (oLocalUser
, "sign-with", "@"),
740 ARGPARSE_s_s (oRecipient
, "user", "@"),
742 ARGPARSE_s_n (oRequireCrossCert
, "require-backsigs", "@"),
743 ARGPARSE_s_n (oRequireCrossCert
, "require-cross-certification", "@"),
744 ARGPARSE_s_n (oNoRequireCrossCert
, "no-require-backsigs", "@"),
745 ARGPARSE_s_n (oNoRequireCrossCert
, "no-require-cross-certification", "@"),
747 /* New options. Fixme: Should go more to the top. */
748 ARGPARSE_s_s (oAutoKeyLocate
, "auto-key-locate", "@"),
749 ARGPARSE_s_n (oNoAutoKeyLocate
, "no-auto-key-locate", "@"),
755 #ifdef ENABLE_SELINUX_HACKS
756 #define ALWAYS_ADD_KEYRINGS 1
758 #define ALWAYS_ADD_KEYRINGS 0
762 int g10_errors_seen
= 0;
764 static int utf8_strings
= 0;
765 static int maybe_setuid
= 1;
767 static char *build_list( const char *text
, char letter
,
768 const char *(*mapf
)(int), int (*chkf
)(int) );
769 static void set_cmd( enum cmd_and_opt_values
*ret_cmd
,
770 enum cmd_and_opt_values new_cmd
);
771 static void print_mds( const char *fname
, int algo
);
772 static void add_notation_data( const char *string
, int which
);
773 static void add_policy_url( const char *string
, int which
);
774 static void add_keyserver_url( const char *string
, int which
);
775 static void emergency_cleanup (void);
779 make_libversion (const char *libname
, const char *(*getfnc
)(const char*))
786 gcry_control (GCRYCTL_INIT_SECMEM
, 0, 0); /* Drop setuid. */
790 result
= xmalloc (strlen (libname
) + 1 + strlen (s
) + 1);
791 strcpy (stpcpy (stpcpy (result
, libname
), " "), s
);
797 my_strusage( int level
)
799 static char *digests
, *pubkeys
, *ciphers
, *zips
, *ver_gcry
;
803 case 11: p
= "gpg (GnuPG)";
805 case 13: p
= VERSION
; break;
806 case 17: p
= PRINTABLE_OS_NAME
; break;
808 _("Please report bugs to <gnupg-bugs@gnu.org>.\n");
813 ver_gcry
= make_libversion ("libgcrypt", gcry_check_version
);
817 #ifdef IS_DEVELOPMENT_VERSION
819 p
="NOTE: THIS IS A DEVELOPMENT VERSION!";
822 p
="It is only intended for test purposes and should NOT be";
825 p
="used in a production environment or with production keys!";
831 _("Usage: gpg [options] [files] (-h for help)");
834 _("Syntax: gpg [options] [files]\n"
835 "sign, check, encrypt or decrypt\n"
836 "default operation depends on the input data\n");
839 case 31: p
= "\nHome: "; break;
841 case 32: p
= opt
.homedir
; break;
842 #else /* __riscos__ */
843 case 32: p
= make_filename(opt
.homedir
, NULL
); break;
844 #endif /* __riscos__ */
845 case 33: p
= _("\nSupported algorithms:\n"); break;
848 pubkeys
= build_list (_("Pubkey: "), 0,
850 openpgp_pk_test_algo
);
855 ciphers
= build_list(_("Cipher: "), 'S',
856 openpgp_cipher_algo_name
,
857 openpgp_cipher_test_algo
);
862 digests
= build_list(_("Hash: "), 'H',
864 openpgp_md_test_algo
);
869 zips
= build_list(_("Compression: "),'Z',
870 compress_algo_to_string
,
871 check_compress_algo
);
882 build_list( const char *text
, char letter
,
883 const char * (*mapf
)(int), int (*chkf
)(int) )
887 size_t n
=strlen(text
)+2;
888 char *list
, *p
, *line
=NULL
;
891 gcry_control (GCRYCTL_INIT_SECMEM
, 0, 0); /* Drop setuid. */
893 for(i
=0; i
<= 110; i
++ )
894 if( !chkf(i
) && (s
=mapf(i
)) )
895 n
+= strlen(s
) + 7 + 2;
896 list
= xmalloc( 21 + n
); *list
= 0;
897 for(p
=NULL
, i
=0; i
<= 110; i
++ ) {
898 if( !chkf(i
) && (s
=mapf(i
)) ) {
900 p
= stpcpy( list
, text
);
904 p
= stpcpy( p
, ", ");
906 if(strlen(line
)>60) {
907 int spaces
=strlen(text
);
909 list
=xrealloc(list
,n
+spaces
+1);
910 /* realloc could move the block, so find the end again */
917 for(;spaces
;spaces
--)
922 if(opt
.verbose
&& letter
)
925 sprintf(num
," (%c%d)",letter
,i
);
931 p
= stpcpy(p
, "\n" );
937 wrong_args( const char *text
)
939 fputs(_("usage: gpg [options] "),stderr
);
947 make_username( const char *string
)
953 p
= native_to_utf8( string
);
958 /* Setup the debugging. With a LEVEL of NULL only the active debug
959 flags are propagated to the subsystems. With LEVEL set, a specific
960 set of debug flags is set; thus overriding all flags already
963 set_debug (const char *level
)
967 else if (!strcmp (level
, "none"))
969 else if (!strcmp (level
, "basic"))
970 opt
.debug
= DBG_MEMSTAT_VALUE
;
971 else if (!strcmp (level
, "advanced"))
972 opt
.debug
= DBG_MEMSTAT_VALUE
|DBG_TRUST_VALUE
|DBG_EXTPROG_VALUE
;
973 else if (!strcmp (level
, "expert"))
974 opt
.debug
= (DBG_MEMSTAT_VALUE
|DBG_TRUST_VALUE
|DBG_EXTPROG_VALUE
975 |DBG_CACHE_VALUE
|DBG_FILTER_VALUE
|DBG_PACKET_VALUE
);
976 else if (!strcmp (level
, "guru"))
980 log_error (_("invalid debug-level `%s' given\n"), level
);
984 if (opt
.debug
& DBG_MEMORY_VALUE
)
985 memory_debug_mode
= 1;
986 if (opt
.debug
& DBG_MEMSTAT_VALUE
)
987 memory_stat_debug_mode
= 1;
988 if (opt
.debug
& DBG_MPI_VALUE
)
989 gcry_control (GCRYCTL_SET_DEBUG_FLAGS
, 2);
990 if (opt
.debug
& DBG_CIPHER_VALUE
)
991 gcry_control (GCRYCTL_SET_DEBUG_FLAGS
, 1);
992 if (opt
.debug
& DBG_IOBUF_VALUE
)
993 iobuf_debug_mode
= 1;
994 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
999 /* We need the home directory also in some other directories, so make
1000 sure that both variables are always in sync. */
1002 set_homedir (const char *dir
)
1010 /* We set the screen dimensions for UI purposes. Do not allow screens
1011 smaller than 80x24 for the sake of simplicity. */
1013 set_screen_dimensions(void)
1015 #ifndef HAVE_W32_SYSTEM
1018 str
=getenv("COLUMNS");
1020 opt
.screen_columns
=atoi(str
);
1022 str
=getenv("LINES");
1024 opt
.screen_lines
=atoi(str
);
1027 if(opt
.screen_columns
<80 || opt
.screen_columns
>255)
1028 opt
.screen_columns
=80;
1030 if(opt
.screen_lines
<24 || opt
.screen_lines
>255)
1031 opt
.screen_lines
=24;
1035 /* Helper to open a file FNAME either for reading or writing to be
1036 used with --status-file etc functions. Not generally useful but it
1037 avoids the riscos specific functions and well some Windows people
1038 might like it too. Prints an error message and returns -1 on
1039 error. On success the file descriptor is returned. */
1041 open_info_file (const char *fname
, int for_write
, int binary
)
1044 return riscos_fdopenfile (fname
, for_write
);
1045 #elif defined (ENABLE_SELINUX_HACKS)
1046 /* We can't allow these even when testing for a secured filename
1047 because files to be secured might not yet been secured. This is
1048 similar to the option file but in that case it is unlikely that
1049 sensitive information may be retrieved by means of error
1059 binary
= MY_O_BINARY
;
1061 /* if (is_secured_filename (fname)) */
1064 /* errno = EPERM; */
1071 fd
= open (fname
, O_CREAT
| O_TRUNC
| O_WRONLY
| binary
,
1072 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
1074 fd
= open (fname
, O_RDONLY
| binary
);
1076 while (fd
== -1 && errno
== EINTR
);
1079 log_error ( for_write
? _("can't create `%s': %s\n")
1080 : _("can't open `%s': %s\n"), fname
, strerror(errno
));
1087 set_cmd( enum cmd_and_opt_values
*ret_cmd
, enum cmd_and_opt_values new_cmd
)
1089 enum cmd_and_opt_values cmd
= *ret_cmd
;
1091 if( !cmd
|| cmd
== new_cmd
)
1093 else if( cmd
== aSign
&& new_cmd
== aEncr
)
1095 else if( cmd
== aEncr
&& new_cmd
== aSign
)
1097 else if( cmd
== aSign
&& new_cmd
== aSym
)
1099 else if( cmd
== aSym
&& new_cmd
== aSign
)
1101 else if( cmd
== aSym
&& new_cmd
== aEncr
)
1103 else if( cmd
== aEncr
&& new_cmd
== aSym
)
1105 else if (cmd
== aSignEncr
&& new_cmd
== aSym
)
1107 else if (cmd
== aSignSym
&& new_cmd
== aEncr
)
1109 else if (cmd
== aEncrSym
&& new_cmd
== aSign
)
1111 else if( ( cmd
== aSign
&& new_cmd
== aClearsign
)
1112 || ( cmd
== aClearsign
&& new_cmd
== aSign
) )
1115 log_error(_("conflicting commands\n"));
1124 add_group(char *string
)
1127 struct groupitem
*item
;
1129 /* Break off the group name */
1130 name
=strsep(&string
,"=");
1133 log_error(_("no = sign found in group definition `%s'\n"),name
);
1137 trim_trailing_ws(name
,strlen(name
));
1139 /* Does this group already exist? */
1140 for(item
=opt
.grouplist
;item
;item
=item
->next
)
1141 if(strcasecmp(item
->name
,name
)==0)
1146 item
=xmalloc(sizeof(struct groupitem
));
1148 item
->next
=opt
.grouplist
;
1153 /* Break apart the values */
1154 while ((value
= strsep(&string
," \t")))
1157 add_to_strlist2(&item
->values
,value
,utf8_strings
);
1163 rm_group(char *name
)
1165 struct groupitem
*item
,*last
=NULL
;
1167 trim_trailing_ws(name
,strlen(name
));
1169 for(item
=opt
.grouplist
;item
;last
=item
,item
=item
->next
)
1171 if(strcasecmp(item
->name
,name
)==0)
1174 last
->next
=item
->next
;
1176 opt
.grouplist
=item
->next
;
1178 free_strlist(item
->values
);
1186 /* We need to check three things.
1188 0) The homedir. It must be x00, a directory, and owned by the
1191 1) The options/gpg.conf file. Okay unless it or its containing
1192 directory is group or other writable or not owned by us. Disable
1195 2) Extensions. Same as #1.
1197 Returns true if the item is unsafe. */
1199 check_permissions(const char *path
,int item
)
1201 #if defined(HAVE_STAT) && !defined(HAVE_DOSISH_SYSTEM)
1202 static int homedir_cache
=-1;
1204 struct stat statbuf
,dirbuf
;
1205 int homedir
=0,ret
=0,checkonly
=0;
1206 int perm
=0,own
=0,enc_dir_perm
=0,enc_dir_own
=0;
1208 if(opt
.no_perm_warn
)
1211 assert(item
==0 || item
==1 || item
==2);
1213 /* extensions may attach a path */
1214 if(item
==2 && path
[0]!=DIRSEP_C
)
1216 if(strchr(path
,DIRSEP_C
))
1217 tmppath
=make_filename(path
,NULL
);
1219 tmppath
=make_filename(gnupg_libdir (),path
,NULL
);
1222 tmppath
=xstrdup(path
);
1224 /* If the item is located in the homedir, but isn't the homedir,
1225 don't continue if we already checked the homedir itself. This is
1226 to avoid user confusion with an extra options file warning which
1227 could be rectified if the homedir itself had proper
1229 if(item
!=0 && homedir_cache
>-1
1230 && ascii_strncasecmp(opt
.homedir
,tmppath
,strlen(opt
.homedir
))==0)
1236 /* It's okay if the file or directory doesn't exist */
1237 if(stat(tmppath
,&statbuf
)!=0)
1243 /* Now check the enclosing directory. Theoretically, we could walk
1244 this test up to the root directory /, but for the sake of sanity,
1245 I'm stopping at one level down. */
1246 dir
=make_dirname(tmppath
);
1248 if(stat(dir
,&dirbuf
)!=0 || !S_ISDIR(dirbuf
.st_mode
))
1257 /* Assume failure */
1262 /* The homedir must be x00, a directory, and owned by the user. */
1264 if(S_ISDIR(statbuf
.st_mode
))
1266 if(statbuf
.st_uid
==getuid())
1268 if((statbuf
.st_mode
& (S_IRWXG
|S_IRWXO
))==0)
1279 else if(item
==1 || item
==2)
1281 /* The options or extension file. Okay unless it or its
1282 containing directory is group or other writable or not owned
1285 if(S_ISREG(statbuf
.st_mode
))
1287 if(statbuf
.st_uid
==getuid() || statbuf
.st_uid
==0)
1289 if((statbuf
.st_mode
& (S_IWGRP
|S_IWOTH
))==0)
1291 /* it's not writable, so make sure the enclosing
1292 directory is also not writable */
1293 if(dirbuf
.st_uid
==getuid() || dirbuf
.st_uid
==0)
1295 if((dirbuf
.st_mode
& (S_IWGRP
|S_IWOTH
))==0)
1305 /* it's writable, so the enclosing directory had
1306 better not let people get to it. */
1307 if(dirbuf
.st_uid
==getuid() || dirbuf
.st_uid
==0)
1309 if((dirbuf
.st_mode
& (S_IRWXG
|S_IRWXO
))==0)
1312 perm
=enc_dir_perm
=1; /* unclear which one to fix! */
1330 log_info(_("WARNING: unsafe ownership on"
1331 " homedir `%s'\n"),tmppath
);
1333 log_info(_("WARNING: unsafe ownership on"
1334 " configuration file `%s'\n"),tmppath
);
1336 log_info(_("WARNING: unsafe ownership on"
1337 " extension `%s'\n"),tmppath
);
1342 log_info(_("WARNING: unsafe permissions on"
1343 " homedir `%s'\n"),tmppath
);
1345 log_info(_("WARNING: unsafe permissions on"
1346 " configuration file `%s'\n"),tmppath
);
1348 log_info(_("WARNING: unsafe permissions on"
1349 " extension `%s'\n"),tmppath
);
1354 log_info(_("WARNING: unsafe enclosing directory ownership on"
1355 " homedir `%s'\n"),tmppath
);
1357 log_info(_("WARNING: unsafe enclosing directory ownership on"
1358 " configuration file `%s'\n"),tmppath
);
1360 log_info(_("WARNING: unsafe enclosing directory ownership on"
1361 " extension `%s'\n"),tmppath
);
1366 log_info(_("WARNING: unsafe enclosing directory permissions on"
1367 " homedir `%s'\n"),tmppath
);
1369 log_info(_("WARNING: unsafe enclosing directory permissions on"
1370 " configuration file `%s'\n"),tmppath
);
1372 log_info(_("WARNING: unsafe enclosing directory permissions on"
1373 " extension `%s'\n"),tmppath
);
1385 #endif /* HAVE_STAT && !HAVE_DOSISH_SYSTEM */
1392 print_algo_numbers(int (*checker
)(int))
1411 print_algo_names(int (*checker
)(int),const char *(*mapper
)(int))
1423 printf("%s",mapper(i
));
1428 /* In the future, we can do all sorts of interesting configuration
1429 output here. For now, just give "group" as the Enigmail folks need
1430 it, and pubkey, cipher, hash, and compress as they may be useful
1433 list_config(char *items
)
1435 int show_all
=(items
==NULL
);
1438 if(!opt
.with_colons
)
1441 while(show_all
|| (name
=strsep(&items
," ")))
1445 if(show_all
|| ascii_strcasecmp(name
,"group")==0)
1447 struct groupitem
*iter
;
1449 for(iter
=opt
.grouplist
;iter
;iter
=iter
->next
)
1453 printf("cfg:group:");
1454 print_string(stdout
,iter
->name
,strlen(iter
->name
),':');
1457 for(sl
=iter
->values
;sl
;sl
=sl
->next
)
1459 print_sanitized_string2 (stdout
, sl
->d
, ':',';');
1470 if(show_all
|| ascii_strcasecmp(name
,"version")==0)
1472 printf("cfg:version:");
1473 print_string(stdout
,VERSION
,strlen(VERSION
),':');
1478 if(show_all
|| ascii_strcasecmp(name
,"pubkey")==0)
1480 printf("cfg:pubkey:");
1481 print_algo_numbers (openpgp_pk_test_algo
);
1486 if(show_all
|| ascii_strcasecmp(name
,"cipher")==0)
1488 printf("cfg:cipher:");
1489 print_algo_numbers(openpgp_cipher_test_algo
);
1494 if (show_all
|| !ascii_strcasecmp (name
,"ciphername"))
1496 printf ("cfg:ciphername:");
1497 print_algo_names (openpgp_cipher_test_algo
,openpgp_cipher_algo_name
);
1503 || ascii_strcasecmp(name
,"digest")==0
1504 || ascii_strcasecmp(name
,"hash")==0)
1506 printf("cfg:digest:");
1507 print_algo_numbers(openpgp_md_test_algo
);
1513 || !ascii_strcasecmp(name
,"digestname")
1514 || !ascii_strcasecmp(name
,"hashname"))
1516 printf ("cfg:digestname:");
1517 print_algo_names (openpgp_md_test_algo
, gcry_md_algo_name
);
1522 if(show_all
|| ascii_strcasecmp(name
,"compress")==0)
1524 printf("cfg:compress:");
1525 print_algo_numbers(check_compress_algo
);
1530 if(show_all
|| ascii_strcasecmp(name
,"ccid-reader-id")==0)
1532 #if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB) \
1533 && GNUPG_MAJOR_VERSION == 1
1535 char *p
, *p2
, *list
= ccid_get_reader_list ();
1537 for (p
=list
; p
&& (p2
= strchr (p
, '\n')); p
= p2
+1)
1540 printf("cfg:ccid-reader-id:%s\n", p
);
1551 log_error(_("unknown configuration item `%s'\n"),name
);
1556 /* List options and default values in the GPG Conf format. This is a
1557 new tool distributed with gnupg 1.9.x but we also want some limited
1558 support in older gpg versions. The output is the name of the
1559 configuration file and a list of options available for editing by
1562 gpgconf_list (const char *configfile
)
1564 char *configfile_esc
= percent_escape (configfile
, NULL
);
1566 printf ("gpgconf-gpg.conf:%lu:\"%s\n",
1567 GC_OPT_FLAG_DEFAULT
, configfile_esc
? configfile_esc
: "/dev/null");
1568 printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE
);
1569 printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE
);
1570 printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE
);
1571 printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE
);
1572 printf ("default-key:%lu:\n", GC_OPT_FLAG_NONE
);
1573 printf ("encrypt-to:%lu:\n", GC_OPT_FLAG_NONE
);
1574 printf ("auto-key-locate:%lu:\n", GC_OPT_FLAG_NONE
);
1575 printf ("allow-pka-lookup:%lu:\n", GC_OPT_FLAG_NONE
);
1576 printf ("log-file:%lu:\n", GC_OPT_FLAG_NONE
);
1577 printf ("debug-level:%lu:\"none:\n", GC_OPT_FLAG_DEFAULT
);
1578 printf ("group:%lu:\n", GC_OPT_FLAG_NONE
);
1580 xfree (configfile_esc
);
1585 parse_subpacket_list(char *list
)
1588 byte subpackets
[128],i
;
1593 /* No arguments means all subpackets */
1594 memset(subpackets
+1,1,sizeof(subpackets
)-1);
1599 memset(subpackets
,0,sizeof(subpackets
));
1601 /* Merge with earlier copy */
1602 if(opt
.show_subpackets
)
1606 for(in
=opt
.show_subpackets
;*in
;in
++)
1608 if(*in
>127 || *in
<1)
1611 if(!subpackets
[*in
])
1617 while((tok
=strsep(&list
," ,")))
1632 xfree(opt
.show_subpackets
);
1633 opt
.show_subpackets
=xmalloc(count
+1);
1634 opt
.show_subpackets
[count
--]=0;
1636 for(i
=1;i
<128 && count
>=0;i
++)
1638 opt
.show_subpackets
[count
--]=i
;
1645 parse_list_options(char *str
)
1647 char *subpackets
=""; /* something that isn't NULL */
1648 struct parse_options lopts
[]=
1650 {"show-photos",LIST_SHOW_PHOTOS
,NULL
,
1651 N_("display photo IDs during key listings")},
1652 {"show-policy-urls",LIST_SHOW_POLICY_URLS
,NULL
,
1653 N_("show policy URLs during signature listings")},
1654 {"show-notations",LIST_SHOW_NOTATIONS
,NULL
,
1655 N_("show all notations during signature listings")},
1656 {"show-std-notations",LIST_SHOW_STD_NOTATIONS
,NULL
,
1657 N_("show IETF standard notations during signature listings")},
1658 {"show-standard-notations",LIST_SHOW_STD_NOTATIONS
,NULL
,
1660 {"show-user-notations",LIST_SHOW_USER_NOTATIONS
,NULL
,
1661 N_("show user-supplied notations during signature listings")},
1662 {"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS
,NULL
,
1663 N_("show preferred keyserver URLs during signature listings")},
1664 {"show-uid-validity",LIST_SHOW_UID_VALIDITY
,NULL
,
1665 N_("show user ID validity during key listings")},
1666 {"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS
,NULL
,
1667 N_("show revoked and expired user IDs in key listings")},
1668 {"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS
,NULL
,
1669 N_("show revoked and expired subkeys in key listings")},
1670 {"show-keyring",LIST_SHOW_KEYRING
,NULL
,
1671 N_("show the keyring name in key listings")},
1672 {"show-sig-expire",LIST_SHOW_SIG_EXPIRE
,NULL
,
1673 N_("show expiration dates during signature listings")},
1674 {"show-sig-subpackets",LIST_SHOW_SIG_SUBPACKETS
,NULL
,
1679 /* C99 allows for non-constant initializers, but we'd like to
1680 compile everywhere, so fill in the show-sig-subpackets argument
1681 here. Note that if the parse_options array changes, we'll have
1682 to change the subscript here. */
1683 lopts
[12].value
=&subpackets
;
1685 if(parse_options(str
,&opt
.list_options
,lopts
,1))
1687 if(opt
.list_options
&LIST_SHOW_SIG_SUBPACKETS
)
1689 /* Unset so users can pass multiple lists in. */
1690 opt
.list_options
&=~LIST_SHOW_SIG_SUBPACKETS
;
1691 if(!parse_subpacket_list(subpackets
))
1694 else if(subpackets
==NULL
&& opt
.show_subpackets
)
1696 /* User did 'no-show-subpackets' */
1697 xfree(opt
.show_subpackets
);
1698 opt
.show_subpackets
=NULL
;
1708 /* Collapses argc/argv into a single string that must be freed */
1710 collapse_args(int argc
,char *argv
[])
1713 int i
,first
=1,len
=0;
1717 len
+=strlen(argv
[i
])+2;
1718 str
=xrealloc(str
,len
);
1727 strcat(str
,argv
[i
]);
1734 parse_trust_model(const char *model
)
1736 if(ascii_strcasecmp(model
,"pgp")==0)
1737 opt
.trust_model
=TM_PGP
;
1738 else if(ascii_strcasecmp(model
,"classic")==0)
1739 opt
.trust_model
=TM_CLASSIC
;
1740 else if(ascii_strcasecmp(model
,"always")==0)
1741 opt
.trust_model
=TM_ALWAYS
;
1742 else if(ascii_strcasecmp(model
,"direct")==0)
1743 opt
.trust_model
=TM_DIRECT
;
1744 else if(ascii_strcasecmp(model
,"auto")==0)
1745 opt
.trust_model
=TM_AUTO
;
1747 log_error("unknown trust model `%s'\n",model
);
1751 /* Pack an s2k iteration count into the form specified in 2440. If
1752 we're in between valid values, round up. */
1753 static unsigned char
1754 encode_s2k_iterations(int iterations
)
1756 unsigned char c
=0,result
;
1759 if(iterations
<=1024)
1762 if(iterations
>=65011712)
1765 /* Need count to be in the range 16-31 */
1766 for(count
=iterations
>>6;count
>=32;count
>>=1)
1769 result
=(c
<<4)|(count
-16);
1771 if(S2K_DECODE_COUNT(result
)<iterations
)
1778 /* This fucntion called to initialized a new control object. It is
1779 assumed that this object has been zeroed out before calling this
1782 gpg_init_default_ctrl (ctrl_t ctrl
)
1788 /* This function is called to deinitialize a control object. It is
1791 gpg_deinit_default_ctrl (ctrl_t ctrl
)
1798 get_default_configname (void)
1800 char *configname
= NULL
;
1801 char *name
= xstrdup ("gpg" EXTSEP_S
"conf-" SAFE_VERSION
);
1802 char *ver
= &name
[strlen ("gpg" EXTSEP_S
"conf-")];
1813 if ((tok
= strrchr (ver
, SAFE_VERSION_DASH
)))
1815 else if ((tok
= strrchr (ver
, SAFE_VERSION_DOT
)))
1821 configname
= make_filename (opt
.homedir
, name
, NULL
);
1823 while (access (configname
, R_OK
));
1828 configname
= make_filename (opt
.homedir
, "gpg" EXTSEP_S
"conf", NULL
);
1829 if (! access (configname
, R_OK
))
1831 /* Print a warning when both config files are present. */
1832 char *p
= make_filename (opt
.homedir
, "options", NULL
);
1833 if (! access (p
, R_OK
))
1834 log_info (_("NOTE: old default options file `%s' ignored\n"), p
);
1839 /* Use the old default only if it exists. */
1840 char *p
= make_filename (opt
.homedir
, "options", NULL
);
1841 if (!access (p
, R_OK
))
1855 main (int argc
, char **argv
)
1857 ARGPARSE_ARGS pargs
;
1865 strlist_t sl
, remusr
= NULL
, locusr
=NULL
;
1866 strlist_t nrings
=NULL
, sec_nrings
=NULL
;
1867 armor_filter_context_t
*afx
= NULL
;
1868 int detached_sig
= 0;
1869 FILE *configfp
= NULL
;
1870 char *configname
= NULL
;
1871 char *save_configname
= NULL
;
1872 char *default_configname
= NULL
;
1873 unsigned configlineno
;
1874 int parse_debug
= 0;
1875 int default_config
= 1;
1876 int default_keyring
= 1;
1879 char *logfile
= NULL
;
1880 int use_random_seed
= 1;
1881 enum cmd_and_opt_values cmd
= 0;
1882 const char *debug_level
= NULL
;
1883 const char *trustdb_name
= NULL
;
1884 char *def_cipher_string
= NULL
;
1885 char *def_digest_string
= NULL
;
1886 char *compress_algo_string
= NULL
;
1887 char *cert_digest_string
= NULL
;
1888 char *s2k_cipher_string
= NULL
;
1889 char *s2k_digest_string
= NULL
;
1890 char *pers_cipher_list
= NULL
;
1891 char *pers_digest_list
= NULL
;
1892 char *pers_compress_list
= NULL
;
1896 int with_fpr
= 0; /* make an option out of --fingerprint */
1897 int any_explicit_recipient
= 0;
1898 int require_secmem
=0,got_secmem
=0;
1902 #endif /* __riscos__ */
1905 /* Please note that we may running SUID(ROOT), so be very CAREFUL
1906 when adding any stuff between here and the call to
1907 secmem_init() somewhere after the option parsing. */
1908 gnupg_reopen_std ("gpg");
1910 gnupg_rl_initialize ();
1911 set_strusage (my_strusage
);
1912 gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN
);
1913 /* We don't need any locking in libgcrypt unless we use any kind of
1915 gcry_control (GCRYCTL_DISABLE_INTERNAL_LOCKING
);
1916 log_set_prefix ("gpg", 1);
1918 /* Make sure that our subsystems are ready. */
1920 init_common_subsystems ();
1922 /* Check that the libraries are suitable. Do it right here because the
1923 option parsing may need services of the library. */
1924 if (!gcry_check_version (NEED_LIBGCRYPT_VERSION
) )
1926 log_fatal ( _("libgcrypt is too old (need %s, have %s)\n"),
1927 NEED_LIBGCRYPT_VERSION
, gcry_check_version (NULL
) );
1930 /* Put random number into secure memory */
1931 gcry_control (GCRYCTL_USE_SECURE_RNDPOOL
);
1933 may_coredump
= disable_core_dumps();
1935 gnupg_init_signals (0, emergency_cleanup
);
1937 create_dotlock(NULL
); /* Register locking cleanup. */
1940 opt
.command_fd
= -1; /* no command fd */
1941 opt
.compress_level
= -1; /* defaults to standard compress level */
1942 opt
.bz2_compress_level
= -1; /* defaults to standard compress level */
1943 /* note: if you change these lines, look at oOpenPGP */
1944 opt
.def_cipher_algo
= 0;
1945 opt
.def_digest_algo
= 0;
1946 opt
.cert_digest_algo
= 0;
1947 opt
.compress_algo
= -1; /* defaults to DEFAULT_COMPRESS_ALGO */
1948 opt
.s2k_mode
= 3; /* iterated+salted */
1949 opt
.s2k_count
= 96; /* 65536 iterations */
1951 opt
.s2k_cipher_algo
= CIPHER_ALGO_CAST5
;
1953 opt
.s2k_cipher_algo
= CIPHER_ALGO_3DES
;
1955 opt
.completes_needed
= 1;
1956 opt
.marginals_needed
= 3;
1957 opt
.max_cert_depth
= 5;
1958 opt
.pgp2_workarounds
= 1;
1959 opt
.escape_from
= 1;
1960 opt
.flags
.require_cross_cert
= 1;
1961 opt
.import_options
=IMPORT_SK2PK
;
1962 opt
.export_options
=EXPORT_ATTRIBUTES
;
1963 opt
.keyserver_options
.import_options
=IMPORT_REPAIR_PKS_SUBKEY_BUG
;
1964 opt
.keyserver_options
.export_options
=EXPORT_ATTRIBUTES
;
1965 opt
.keyserver_options
.options
=
1966 KEYSERVER_HONOR_KEYSERVER_URL
|KEYSERVER_HONOR_PKA_RECORD
;
1968 VERIFY_SHOW_POLICY_URLS
|VERIFY_SHOW_STD_NOTATIONS
|VERIFY_SHOW_KEYSERVER_URLS
;
1969 opt
.trust_model
=TM_AUTO
;
1970 opt
.mangle_dos_filenames
=0;
1971 opt
.min_cert_level
=2;
1972 set_screen_dimensions();
1973 opt
.keyid_format
=KF_SHORT
;
1974 opt
.def_sig_expire
="0";
1975 opt
.def_cert_expire
="0";
1976 set_homedir ( default_homedir () );
1977 opt
.passwd_repeat
=1;
1979 /* Check whether we have a config file on the command line. */
1984 pargs
.flags
= 1|(1<<6); /* do not remove the args, ignore version */
1985 while( arg_parse( &pargs
, opts
) ) {
1986 if( pargs
.r_opt
== oDebug
|| pargs
.r_opt
== oDebugAll
)
1988 else if( pargs
.r_opt
== oOptions
) {
1989 /* yes there is one, so we do not try the default one, but
1990 * read the option file when it is encountered at the commandline
1994 else if( pargs
.r_opt
== oNoOptions
)
1996 default_config
= 0; /* --no-options */
1997 opt
.no_homedir_creation
= 1;
1999 else if( pargs
.r_opt
== oHomedir
)
2000 set_homedir ( pargs
.r
.ret_str
);
2001 else if( pargs
.r_opt
== oNoPermissionWarn
)
2003 else if (pargs
.r_opt
== oStrict
)
2007 else if (pargs
.r_opt
== oNoStrict
)
2013 #ifdef HAVE_DOSISH_SYSTEM
2014 if ( strchr (opt
.homedir
,'\\') ) {
2015 char *d
, *buf
= xmalloc (strlen (opt
.homedir
)+1);
2016 const char *s
= opt
.homedir
;
2017 for (d
=buf
,s
=opt
.homedir
; *s
; s
++)
2019 *d
++ = *s
== '\\'? '/': *s
;
2020 #ifdef HAVE_W32_SYSTEM
2021 if (s
[1] && IsDBCSLeadByte (*s
))
2030 /* Initialize the secure memory. */
2031 if (!gcry_control (GCRYCTL_INIT_SECMEM
, 32768, 0))
2033 #if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
2034 /* There should be no way to get to this spot while still carrying
2035 setuid privs. Just in case, bomb out if we are. */
2036 if ( getuid () != geteuid () )
2041 /* Okay, we are now working under our real uid */
2043 /* malloc hooks go here ... */
2044 assuan_set_malloc_hooks (gcry_malloc
, gcry_realloc
, gcry_free
);
2045 assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT
);
2048 /* Try for a version specific config file first */
2049 default_configname
= get_default_configname ();
2051 configname
= xstrdup (default_configname
);
2057 pargs
.flags
= 1; /* do not remove the args */
2059 /* By this point we have a homedir, and cannot change it. */
2060 check_permissions(opt
.homedir
,0);
2064 if(check_permissions(configname
,1))
2066 /* If any options file is unsafe, then disable any external
2067 programs for keyserver calls or photo IDs. Since the
2068 external program to call is set in the options file, a
2069 unsafe options file can lead to an arbitrary program
2076 configfp
= fopen( configname
, "r" );
2077 if (configfp
&& is_secured_file (fileno (configfp
)))
2084 if( default_config
) {
2086 log_info(_("NOTE: no default option file `%s'\n"),
2090 log_error(_("option file `%s': %s\n"),
2091 configname
, strerror(errno
) );
2094 xfree(configname
); configname
= NULL
;
2096 if( parse_debug
&& configname
)
2097 log_info(_("reading options from `%s'\n"), configname
);
2101 while( optfile_parse( configfp
, configname
, &configlineno
,
2104 switch( pargs
.r_opt
)
2119 #ifdef ENABLE_CARD_SUPPORT
2123 #endif /* ENABLE_CARD_SUPPORT*/
2128 case aExportSecretSub
:
2139 case aUpdateTrustDB
:
2141 case aListTrustPath
:
2148 case aExportOwnerTrust
:
2149 case aImportOwnerTrust
:
2150 case aRebuildKeydbCaches
:
2151 set_cmd (&cmd
, pargs
.r_opt
);
2156 case aDeleteSecretKeys
:
2157 case aDeleteSecretAndPublicKeys
:
2159 set_cmd (&cmd
, pargs
.r_opt
);
2163 case aDetachedSign
: detached_sig
= 1; set_cmd( &cmd
, aSign
); break;
2165 case aDecryptFiles
: multifile
=1; /* fall through */
2166 case aDecrypt
: set_cmd( &cmd
, aDecrypt
); break;
2168 case aEncrFiles
: multifile
=1; /* fall through */
2169 case aEncr
: set_cmd( &cmd
, aEncr
); break;
2171 case aVerifyFiles
: multifile
=1; /* fall through */
2172 case aVerify
: set_cmd( &cmd
, aVerify
); break;
2175 set_cmd (&cmd
, pargs
.r_opt
);
2179 case oArmor
: opt
.armor
= 1; opt
.no_armor
=0; break;
2180 case oOutput
: opt
.outfile
= pargs
.r
.ret_str
; break;
2181 case oMaxOutput
: opt
.max_output
= pargs
.r
.ret_ulong
; break;
2182 case oQuiet
: opt
.quiet
= 1; break;
2183 case oNoTTY
: tty_no_terminal(1); break;
2184 case oDryRun
: opt
.dry_run
= 1; break;
2185 case oInteractive
: opt
.interactive
= 1; break;
2188 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
2189 opt
.list_options
|=LIST_SHOW_UNUSABLE_UIDS
;
2190 opt
.list_options
|=LIST_SHOW_UNUSABLE_SUBKEYS
;
2198 case oUseAgent
: /* Dummy. */
2201 obsolete_option (configname
, configlineno
, "--no-use-agent");
2204 obsolete_option (configname
, configlineno
, "--gpg-agent-info");
2207 case oAnswerYes
: opt
.answer_yes
= 1; break;
2208 case oAnswerNo
: opt
.answer_no
= 1; break;
2209 case oKeyring
: append_to_strlist( &nrings
, pargs
.r
.ret_str
); break;
2210 case oPrimaryKeyring
:
2211 sl
=append_to_strlist( &nrings
, pargs
.r
.ret_str
);
2215 deprecated_warning(configname
,configlineno
,"--show-keyring",
2216 "--list-options ","show-keyring");
2217 opt
.list_options
|=LIST_SHOW_KEYRING
;
2220 case oDebug
: opt
.debug
|= pargs
.r
.ret_ulong
; break;
2221 case oDebugAll
: opt
.debug
= ~0; break;
2222 case oDebugLevel
: debug_level
= pargs
.r
.ret_str
; break;
2225 set_status_fd ( translate_sys2libc_fd_int (pargs
.r
.ret_int
, 1) );
2228 set_status_fd ( open_info_file (pargs
.r
.ret_str
, 1, 0) );
2231 set_attrib_fd ( translate_sys2libc_fd_int (pargs
.r
.ret_int
, 1) );
2233 case oAttributeFile
:
2234 set_attrib_fd ( open_info_file (pargs
.r
.ret_str
, 1, 1) );
2237 log_set_fd (translate_sys2libc_fd_int (pargs
.r
.ret_int
, 1));
2240 logfile
= pargs
.r
.ret_str
;
2243 case oWithFingerprint
:
2244 opt
.with_fingerprint
= 1;
2245 with_fpr
=1; /*fall thru*/
2246 case oFingerprint
: opt
.fingerprint
++; break;
2247 case oSecretKeyring
:
2248 append_to_strlist( &sec_nrings
, pargs
.r
.ret_str
);
2251 /* config files may not be nested (silently ignore them) */
2254 configname
= xstrdup(pargs
.r
.ret_str
);
2258 case oNoArmor
: opt
.no_armor
=1; opt
.armor
=0; break;
2259 case oNoDefKeyring
: default_keyring
= 0; break;
2260 case oNoGreeting
: nogreeting
= 1; break;
2263 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
2267 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM
, 0);
2269 case oEmitVersion
: opt
.no_version
=0; break;
2270 case oNoEmitVersion
: opt
.no_version
=1; break;
2271 case oCompletesNeeded
: opt
.completes_needed
= pargs
.r
.ret_int
; break;
2272 case oMarginalsNeeded
: opt
.marginals_needed
= pargs
.r
.ret_int
; break;
2273 case oMaxCertDepth
: opt
.max_cert_depth
= pargs
.r
.ret_int
; break;
2274 case oTrustDBName
: trustdb_name
= pargs
.r
.ret_str
; break;
2275 case oDefaultKey
: opt
.def_secret_key
= pargs
.r
.ret_str
; break;
2277 if( *pargs
.r
.ret_str
)
2278 opt
.def_recipient
= make_username(pargs
.r
.ret_str
);
2280 case oDefRecipientSelf
:
2281 xfree(opt
.def_recipient
); opt
.def_recipient
= NULL
;
2282 opt
.def_recipient_self
= 1;
2284 case oNoDefRecipient
:
2285 xfree(opt
.def_recipient
); opt
.def_recipient
= NULL
;
2286 opt
.def_recipient_self
= 0;
2288 case oNoOptions
: opt
.no_homedir_creation
= 1; break; /* no-options */
2289 case oHomedir
: break;
2290 case oNoBatch
: opt
.batch
= 0; break;
2292 case oWithKeyData
: opt
.with_key_data
=1; /*FALLTHRU*/
2293 case oWithColons
: opt
.with_colons
=':'; break;
2295 case oWithSigCheck
: opt
.check_sigs
= 1; /*FALLTHRU*/
2296 case oWithSigList
: opt
.list_sigs
= 1; break;
2298 case oSkipVerify
: opt
.skip_verify
=1; break;
2299 case oCompressKeys
: opt
.compress_keys
= 1; break;
2300 case aListSecretKeys
: set_cmd( &cmd
, aListSecretKeys
); break;
2301 /* There are many programs (like mutt) that call gpg with
2302 --always-trust so keep this option around for a long
2304 case oAlwaysTrust
: opt
.trust_model
=TM_ALWAYS
; break;
2306 parse_trust_model(pargs
.r
.ret_str
);
2308 case oForceOwnertrust
:
2309 log_info(_("NOTE: %s is not for normal use!\n"),
2310 "--force-ownertrust");
2311 opt
.force_ownertrust
=string_to_trust_value(pargs
.r
.ret_str
);
2312 if(opt
.force_ownertrust
==-1)
2314 log_error("invalid ownertrust `%s'\n",pargs
.r
.ret_str
);
2315 opt
.force_ownertrust
=0;
2318 case oLoadExtension
:
2319 /* Dummy so that gpg 1.4 conf files can work. Should
2320 eventually be removed. */
2323 opt
.compliance
= CO_RFC1991
;
2324 opt
.force_v4_certs
= 0;
2325 opt
.escape_from
= 1;
2329 /* This is effectively the same as RFC2440, but with
2330 "--enable-dsa2 --no-rfc2440-text --escape-from-lines
2331 --require-cross-certification". */
2332 opt
.compliance
= CO_RFC4880
;
2334 opt
.flags
.require_cross_cert
= 1;
2335 opt
.rfc2440_text
= 0;
2336 opt
.allow_non_selfsigned_uid
= 1;
2337 opt
.allow_freeform_uid
= 1;
2338 opt
.pgp2_workarounds
= 0;
2339 opt
.escape_from
= 1;
2340 opt
.force_v3_sigs
= 0;
2341 opt
.compress_keys
= 0; /* not mandated, but we do it */
2342 opt
.compress_sigs
= 0; /* ditto. */
2343 opt
.not_dash_escaped
= 0;
2344 opt
.def_cipher_algo
= 0;
2345 opt
.def_digest_algo
= 0;
2346 opt
.cert_digest_algo
= 0;
2347 opt
.compress_algo
= -1;
2348 opt
.s2k_mode
= 3; /* iterated+salted */
2349 opt
.s2k_digest_algo
= DIGEST_ALGO_SHA1
;
2350 opt
.s2k_cipher_algo
= CIPHER_ALGO_3DES
;
2353 opt
.compliance
= CO_RFC2440
;
2355 opt
.rfc2440_text
= 1;
2356 opt
.allow_non_selfsigned_uid
= 1;
2357 opt
.allow_freeform_uid
= 1;
2358 opt
.pgp2_workarounds
= 0;
2359 opt
.escape_from
= 0;
2360 opt
.force_v3_sigs
= 0;
2361 opt
.compress_keys
= 0; /* not mandated, but we do it */
2362 opt
.compress_sigs
= 0; /* ditto. */
2363 opt
.not_dash_escaped
= 0;
2364 opt
.def_cipher_algo
= 0;
2365 opt
.def_digest_algo
= 0;
2366 opt
.cert_digest_algo
= 0;
2367 opt
.compress_algo
= -1;
2368 opt
.s2k_mode
= 3; /* iterated+salted */
2369 opt
.s2k_digest_algo
= DIGEST_ALGO_SHA1
;
2370 opt
.s2k_cipher_algo
= CIPHER_ALGO_3DES
;
2372 case oPGP2
: opt
.compliance
= CO_PGP2
; break;
2373 case oPGP6
: opt
.compliance
= CO_PGP6
; break;
2374 case oPGP7
: opt
.compliance
= CO_PGP7
; break;
2375 case oPGP8
: opt
.compliance
= CO_PGP8
; break;
2376 case oGnuPG
: opt
.compliance
= CO_GNUPG
; break;
2377 case oCompressSigs
: opt
.compress_sigs
= 1; break;
2378 case oRFC2440Text
: opt
.rfc2440_text
=1; break;
2379 case oNoRFC2440Text
: opt
.rfc2440_text
=0; break;
2382 opt
.set_filename
= pargs
.r
.ret_str
;
2384 opt
.set_filename
= native_to_utf8(pargs
.r
.ret_str
);
2386 case oForYourEyesOnly
: eyes_only
= 1; break;
2387 case oNoForYourEyesOnly
: eyes_only
= 0; break;
2389 add_policy_url(pargs
.r
.ret_str
,0);
2390 add_policy_url(pargs
.r
.ret_str
,1);
2392 case oSigPolicyURL
: add_policy_url(pargs
.r
.ret_str
,0); break;
2393 case oCertPolicyURL
: add_policy_url(pargs
.r
.ret_str
,1); break;
2394 case oShowPolicyURL
:
2395 deprecated_warning(configname
,configlineno
,"--show-policy-url",
2396 "--list-options ","show-policy-urls");
2397 deprecated_warning(configname
,configlineno
,"--show-policy-url",
2398 "--verify-options ","show-policy-urls");
2399 opt
.list_options
|=LIST_SHOW_POLICY_URLS
;
2400 opt
.verify_options
|=VERIFY_SHOW_POLICY_URLS
;
2402 case oNoShowPolicyURL
:
2403 deprecated_warning(configname
,configlineno
,"--no-show-policy-url",
2404 "--list-options ","no-show-policy-urls");
2405 deprecated_warning(configname
,configlineno
,"--no-show-policy-url",
2406 "--verify-options ","no-show-policy-urls");
2407 opt
.list_options
&=~LIST_SHOW_POLICY_URLS
;
2408 opt
.verify_options
&=~VERIFY_SHOW_POLICY_URLS
;
2410 case oSigKeyserverURL
: add_keyserver_url(pargs
.r
.ret_str
,0); break;
2411 case oUseEmbeddedFilename
:
2412 opt
.flags
.use_embedded_filename
=1;
2414 case oNoUseEmbeddedFilename
:
2415 opt
.flags
.use_embedded_filename
=0;
2418 if(pargs
.r
.ret_str
[0])
2419 append_to_strlist(&opt
.comments
,pargs
.r
.ret_str
);
2421 case oDefaultComment
:
2422 deprecated_warning(configname
,configlineno
,
2423 "--default-comment","--no-comments","");
2426 free_strlist(opt
.comments
);
2429 case oThrowKeyids
: opt
.throw_keyid
= 1; break;
2430 case oNoThrowKeyids
: opt
.throw_keyid
= 0; break;
2432 deprecated_warning(configname
,configlineno
,"--show-photos",
2433 "--list-options ","show-photos");
2434 deprecated_warning(configname
,configlineno
,"--show-photos",
2435 "--verify-options ","show-photos");
2436 opt
.list_options
|=LIST_SHOW_PHOTOS
;
2437 opt
.verify_options
|=VERIFY_SHOW_PHOTOS
;
2440 deprecated_warning(configname
,configlineno
,"--no-show-photos",
2441 "--list-options ","no-show-photos");
2442 deprecated_warning(configname
,configlineno
,"--no-show-photos",
2443 "--verify-options ","no-show-photos");
2444 opt
.list_options
&=~LIST_SHOW_PHOTOS
;
2445 opt
.verify_options
&=~VERIFY_SHOW_PHOTOS
;
2447 case oPhotoViewer
: opt
.photo_viewer
= pargs
.r
.ret_str
; break;
2448 case oForceV3Sigs
: opt
.force_v3_sigs
= 1; break;
2449 case oNoForceV3Sigs
: opt
.force_v3_sigs
= 0; break;
2450 case oForceV4Certs
: opt
.force_v4_certs
= 1; break;
2451 case oNoForceV4Certs
: opt
.force_v4_certs
= 0; break;
2452 case oForceMDC
: opt
.force_mdc
= 1; break;
2453 case oNoForceMDC
: opt
.force_mdc
= 0; break;
2454 case oDisableMDC
: opt
.disable_mdc
= 1; break;
2455 case oNoDisableMDC
: opt
.disable_mdc
= 0; break;
2456 case oS2KMode
: opt
.s2k_mode
= pargs
.r
.ret_int
; break;
2457 case oS2KDigest
: s2k_digest_string
= xstrdup(pargs
.r
.ret_str
); break;
2458 case oS2KCipher
: s2k_cipher_string
= xstrdup(pargs
.r
.ret_str
); break;
2460 opt
.s2k_count
=encode_s2k_iterations(pargs
.r
.ret_int
);
2462 case oSimpleSKChecksum
: opt
.simple_sk_checksum
= 1; break;
2463 case oNoEncryptTo
: opt
.no_encrypt_to
= 1; break;
2464 case oEncryptTo
: /* store the recipient in the second list */
2465 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2468 case oHiddenEncryptTo
: /* store the recipient in the second list */
2469 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2472 case oRecipient
: /* store the recipient */
2473 add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2474 any_explicit_recipient
= 1;
2476 case oHiddenRecipient
: /* store the recipient with a flag */
2477 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2479 any_explicit_recipient
= 1;
2481 case oTextmodeShort
: opt
.textmode
= 2; break;
2482 case oTextmode
: opt
.textmode
=1; break;
2483 case oNoTextmode
: opt
.textmode
=0; break;
2484 case oExpert
: opt
.expert
= 1; break;
2485 case oNoExpert
: opt
.expert
= 0; break;
2487 if(*pargs
.r
.ret_str
!='\0')
2489 if(parse_expire_string(pargs
.r
.ret_str
)==(u32
)-1)
2490 log_error(_("`%s' is not a valid signature expiration\n"),
2493 opt
.def_sig_expire
=pargs
.r
.ret_str
;
2496 case oAskSigExpire
: opt
.ask_sig_expire
= 1; break;
2497 case oNoAskSigExpire
: opt
.ask_sig_expire
= 0; break;
2498 case oDefCertExpire
:
2499 if(*pargs
.r
.ret_str
!='\0')
2501 if(parse_expire_string(pargs
.r
.ret_str
)==(u32
)-1)
2502 log_error(_("`%s' is not a valid signature expiration\n"),
2505 opt
.def_cert_expire
=pargs
.r
.ret_str
;
2508 case oAskCertExpire
: opt
.ask_cert_expire
= 1; break;
2509 case oNoAskCertExpire
: opt
.ask_cert_expire
= 0; break;
2510 case oDefCertLevel
: opt
.def_cert_level
=pargs
.r
.ret_int
; break;
2511 case oMinCertLevel
: opt
.min_cert_level
=pargs
.r
.ret_int
; break;
2512 case oAskCertLevel
: opt
.ask_cert_level
= 1; break;
2513 case oNoAskCertLevel
: opt
.ask_cert_level
= 0; break;
2514 case oLocalUser
: /* store the local users */
2515 add_to_strlist2( &locusr
, pargs
.r
.ret_str
, utf8_strings
);
2518 /* this is the -z command line option */
2519 opt
.compress_level
= opt
.bz2_compress_level
= pargs
.r
.ret_int
;
2521 case oCompressLevel
: opt
.compress_level
= pargs
.r
.ret_int
; break;
2522 case oBZ2CompressLevel
: opt
.bz2_compress_level
= pargs
.r
.ret_int
; break;
2523 case oBZ2DecompressLowmem
: opt
.bz2_decompress_lowmem
=1; break;
2525 set_passphrase_from_string(pargs
.r
.ret_str
);
2528 pwfd
= translate_sys2libc_fd_int (pargs
.r
.ret_int
, 0);
2531 pwfd
= open_info_file (pargs
.r
.ret_str
, 0, 1);
2533 case oPasswdRepeat
: opt
.passwd_repeat
=pargs
.r
.ret_int
; break;
2535 opt
.command_fd
= translate_sys2libc_fd_int (pargs
.r
.ret_int
, 0);
2538 opt
.command_fd
= open_info_file (pargs
.r
.ret_str
, 0, 1);
2541 def_cipher_string
= xstrdup(pargs
.r
.ret_str
);
2544 def_digest_string
= xstrdup(pargs
.r
.ret_str
);
2547 /* If it is all digits, stick a Z in front of it for
2548 later. This is for backwards compatibility with
2549 versions that took the compress algorithm number. */
2551 char *pt
=pargs
.r
.ret_str
;
2554 if (!isascii (*pt
) || !isdigit (*pt
))
2562 compress_algo_string
=xmalloc(strlen(pargs
.r
.ret_str
)+2);
2563 strcpy(compress_algo_string
,"Z");
2564 strcat(compress_algo_string
,pargs
.r
.ret_str
);
2567 compress_algo_string
= xstrdup(pargs
.r
.ret_str
);
2570 case oCertDigestAlgo
:
2571 cert_digest_string
= xstrdup(pargs
.r
.ret_str
);
2575 gcry_control (GCRYCTL_DISABLE_SECMEM_WARN
);
2578 case oRequireSecmem
: require_secmem
=1; break;
2579 case oNoRequireSecmem
: require_secmem
=0; break;
2580 case oNoPermissionWarn
: opt
.no_perm_warn
=1; break;
2581 case oNoMDCWarn
: opt
.no_mdc_warn
=1; break;
2582 case oDisplayCharset
:
2583 if( set_native_charset( pargs
.r
.ret_str
) )
2584 log_error(_("`%s' is not a valid character set\n"),
2587 case oNotDashEscaped
: opt
.not_dash_escaped
= 1; break;
2588 case oEscapeFrom
: opt
.escape_from
= 1; break;
2589 case oNoEscapeFrom
: opt
.escape_from
= 0; break;
2590 case oLockOnce
: opt
.lock_once
= 1; break;
2597 #else /* __riscos__ */
2598 riscos_not_implemented("lock-multiple");
2599 #endif /* __riscos__ */
2603 struct keyserver_spec
*keyserver
;
2604 keyserver
=parse_keyserver_uri(pargs
.r
.ret_str
,0,
2605 configname
,configlineno
);
2607 log_error(_("could not parse keyserver URL\n"));
2610 keyserver
->next
=opt
.keyserver
;
2611 opt
.keyserver
=keyserver
;
2615 case oKeyServerOptions
:
2616 if(!parse_keyserver_options(pargs
.r
.ret_str
))
2619 log_error(_("%s:%d: invalid keyserver options\n"),
2620 configname
,configlineno
);
2622 log_error(_("invalid keyserver options\n"));
2625 case oImportOptions
:
2626 if(!parse_import_options(pargs
.r
.ret_str
,&opt
.import_options
,1))
2629 log_error(_("%s:%d: invalid import options\n"),
2630 configname
,configlineno
);
2632 log_error(_("invalid import options\n"));
2635 case oExportOptions
:
2636 if(!parse_export_options(pargs
.r
.ret_str
,&opt
.export_options
,1))
2639 log_error(_("%s:%d: invalid export options\n"),
2640 configname
,configlineno
);
2642 log_error(_("invalid export options\n"));
2646 if(!parse_list_options(pargs
.r
.ret_str
))
2649 log_error(_("%s:%d: invalid list options\n"),
2650 configname
,configlineno
);
2652 log_error(_("invalid list options\n"));
2655 case oVerifyOptions
:
2657 struct parse_options vopts
[]=
2659 {"show-photos",VERIFY_SHOW_PHOTOS
,NULL
,
2660 N_("display photo IDs during signature verification")},
2661 {"show-policy-urls",VERIFY_SHOW_POLICY_URLS
,NULL
,
2662 N_("show policy URLs during signature verification")},
2663 {"show-notations",VERIFY_SHOW_NOTATIONS
,NULL
,
2664 N_("show all notations during signature verification")},
2665 {"show-std-notations",VERIFY_SHOW_STD_NOTATIONS
,NULL
,
2666 N_("show IETF standard notations during signature verification")},
2667 {"show-standard-notations",VERIFY_SHOW_STD_NOTATIONS
,NULL
,
2669 {"show-user-notations",VERIFY_SHOW_USER_NOTATIONS
,NULL
,
2670 N_("show user-supplied notations during signature verification")},
2671 {"show-keyserver-urls",VERIFY_SHOW_KEYSERVER_URLS
,NULL
,
2672 N_("show preferred keyserver URLs during signature verification")},
2673 {"show-uid-validity",VERIFY_SHOW_UID_VALIDITY
,NULL
,
2674 N_("show user ID validity during signature verification")},
2675 {"show-unusable-uids",VERIFY_SHOW_UNUSABLE_UIDS
,NULL
,
2676 N_("show revoked and expired user IDs in signature verification")},
2677 {"show-primary-uid-only",VERIFY_SHOW_PRIMARY_UID_ONLY
,NULL
,
2678 N_("show only the primary user ID in signature verification")},
2679 {"pka-lookups",VERIFY_PKA_LOOKUPS
,NULL
,
2680 N_("validate signatures with PKA data")},
2681 {"pka-trust-increase",VERIFY_PKA_TRUST_INCREASE
,NULL
,
2682 N_("elevate the trust of signatures with valid PKA data")},
2686 if(!parse_options(pargs
.r
.ret_str
,&opt
.verify_options
,vopts
,1))
2689 log_error(_("%s:%d: invalid verify options\n"),
2690 configname
,configlineno
);
2692 log_error(_("invalid verify options\n"));
2696 case oTempDir
: opt
.temp_dir
=pargs
.r
.ret_str
; break;
2698 if(set_exec_path(pargs
.r
.ret_str
))
2699 log_error(_("unable to set exec-path to %s\n"),pargs
.r
.ret_str
);
2701 opt
.exec_path_set
=1;
2704 add_notation_data( pargs
.r
.ret_str
, 0 );
2705 add_notation_data( pargs
.r
.ret_str
, 1 );
2707 case oSigNotation
: add_notation_data( pargs
.r
.ret_str
, 0 ); break;
2708 case oCertNotation
: add_notation_data( pargs
.r
.ret_str
, 1 ); break;
2710 deprecated_warning(configname
,configlineno
,"--show-notation",
2711 "--list-options ","show-notations");
2712 deprecated_warning(configname
,configlineno
,"--show-notation",
2713 "--verify-options ","show-notations");
2714 opt
.list_options
|=LIST_SHOW_NOTATIONS
;
2715 opt
.verify_options
|=VERIFY_SHOW_NOTATIONS
;
2717 case oNoShowNotation
:
2718 deprecated_warning(configname
,configlineno
,"--no-show-notation",
2719 "--list-options ","no-show-notations");
2720 deprecated_warning(configname
,configlineno
,"--no-show-notation",
2721 "--verify-options ","no-show-notations");
2722 opt
.list_options
&=~LIST_SHOW_NOTATIONS
;
2723 opt
.verify_options
&=~VERIFY_SHOW_NOTATIONS
;
2725 case oUtf8Strings
: utf8_strings
= 1; break;
2726 case oNoUtf8Strings
: utf8_strings
= 0; break;
2727 case oDisableCipherAlgo
:
2729 int algo
= string_to_cipher_algo (pargs
.r
.ret_str
);
2730 gcry_cipher_ctl (NULL
, GCRYCTL_DISABLE_ALGO
, &algo
, sizeof algo
);
2733 case oDisablePubkeyAlgo
:
2735 int algo
= gcry_pk_map_name (pargs
.r
.ret_str
);
2736 gcry_pk_ctl (GCRYCTL_DISABLE_ALGO
, &algo
, sizeof algo
);
2739 case oNoSigCache
: opt
.no_sig_cache
= 1; break;
2740 case oNoSigCreateCheck
: opt
.no_sig_create_check
= 1; break;
2741 case oAllowNonSelfsignedUID
: opt
.allow_non_selfsigned_uid
= 1; break;
2742 case oNoAllowNonSelfsignedUID
: opt
.allow_non_selfsigned_uid
=0; break;
2743 case oAllowFreeformUID
: opt
.allow_freeform_uid
= 1; break;
2744 case oNoAllowFreeformUID
: opt
.allow_freeform_uid
= 0; break;
2745 case oNoLiteral
: opt
.no_literal
= 1; break;
2746 case oSetFilesize
: opt
.set_filesize
= pargs
.r
.ret_ulong
; break;
2747 case oHonorHttpProxy
:
2748 add_to_strlist(&opt
.keyserver_options
.other
,"http-proxy");
2749 deprecated_warning(configname
,configlineno
,
2750 "--honor-http-proxy",
2751 "--keyserver-options ","http-proxy");
2753 case oFastListMode
: opt
.fast_list_mode
= 1; break;
2754 case oFixedListMode
: /* Dummy */ break;
2755 case oListOnly
: opt
.list_only
=1; break;
2756 case oIgnoreTimeConflict
: opt
.ignore_time_conflict
= 1; break;
2757 case oIgnoreValidFrom
: opt
.ignore_valid_from
= 1; break;
2758 case oIgnoreCrcError
: opt
.ignore_crc_error
= 1; break;
2759 case oIgnoreMDCError
: opt
.ignore_mdc_error
= 1; break;
2760 case oNoRandomSeedFile
: use_random_seed
= 0; break;
2761 case oAutoKeyRetrieve
:
2762 case oNoAutoKeyRetrieve
:
2763 if(pargs
.r_opt
==oAutoKeyRetrieve
)
2764 opt
.keyserver_options
.options
|=KEYSERVER_AUTO_KEY_RETRIEVE
;
2766 opt
.keyserver_options
.options
&=~KEYSERVER_AUTO_KEY_RETRIEVE
;
2768 deprecated_warning(configname
,configlineno
,
2769 pargs
.r_opt
==oAutoKeyRetrieve
?"--auto-key-retrieve":
2770 "--no-auto-key-retrieve","--keyserver-options ",
2771 pargs
.r_opt
==oAutoKeyRetrieve
?"auto-key-retrieve":
2772 "no-auto-key-retrieve");
2774 case oShowSessionKey
: opt
.show_session_key
= 1; break;
2775 case oOverrideSessionKey
:
2776 opt
.override_session_key
= pargs
.r
.ret_str
;
2779 deprecated_warning(configname
,configlineno
,"--merge-only",
2780 "--import-options ","merge-only");
2781 opt
.import_options
|=IMPORT_MERGE_ONLY
;
2783 case oAllowSecretKeyImport
: /* obsolete */ break;
2784 case oTryAllSecrets
: opt
.try_all_secrets
= 1; break;
2785 case oTrustedKey
: register_trusted_key( pargs
.r
.ret_str
); break;
2786 case oEnableSpecialFilenames
:
2787 iobuf_enable_special_filenames (1);
2789 case oNoExpensiveTrustChecks
: opt
.no_expensive_trust_checks
=1; break;
2790 case oAutoCheckTrustDB
: opt
.no_auto_check_trustdb
=0; break;
2791 case oNoAutoCheckTrustDB
: opt
.no_auto_check_trustdb
=1; break;
2792 case oPreservePermissions
: opt
.preserve_permissions
=1; break;
2793 case oDefaultPreferenceList
:
2794 opt
.def_preference_list
= pargs
.r
.ret_str
;
2796 case oDefaultKeyserverURL
:
2798 struct keyserver_spec
*keyserver
;
2799 keyserver
=parse_keyserver_uri(pargs
.r
.ret_str
,1,
2800 configname
,configlineno
);
2802 log_error(_("could not parse keyserver URL\n"));
2804 free_keyserver_spec(keyserver
);
2806 opt
.def_keyserver_url
= pargs
.r
.ret_str
;
2809 case oPersonalCipherPreferences
:
2810 pers_cipher_list
=pargs
.r
.ret_str
;
2812 case oPersonalDigestPreferences
:
2813 pers_digest_list
=pargs
.r
.ret_str
;
2815 case oPersonalCompressPreferences
:
2816 pers_compress_list
=pargs
.r
.ret_str
;
2818 case oAgentProgram
: opt
.agent_program
= pargs
.r
.ret_str
; break;
2819 case oDisplay
: opt
.display
= pargs
.r
.ret_str
; break;
2820 case oTTYname
: opt
.ttyname
= pargs
.r
.ret_str
; break;
2821 case oTTYtype
: opt
.ttytype
= pargs
.r
.ret_str
; break;
2822 case oLCctype
: opt
.lc_ctype
= pargs
.r
.ret_str
; break;
2823 case oLCmessages
: opt
.lc_messages
= pargs
.r
.ret_str
; break;
2824 case oXauthority
: opt
.xauthority
= pargs
.r
.ret_str
; break;
2825 case oGroup
: add_group(pargs
.r
.ret_str
); break;
2826 case oUnGroup
: rm_group(pargs
.r
.ret_str
); break;
2828 while(opt
.grouplist
)
2830 struct groupitem
*iter
=opt
.grouplist
;
2831 free_strlist(iter
->values
);
2832 opt
.grouplist
=opt
.grouplist
->next
;
2842 case oMangleDosFilenames
: opt
.mangle_dos_filenames
= 1; break;
2843 case oNoMangleDosFilenames
: opt
.mangle_dos_filenames
= 0; break;
2844 case oEnableProgressFilter
: opt
.enable_progress_filter
= 1; break;
2845 case oMultifile
: multifile
=1; break;
2847 if(ascii_strcasecmp(pargs
.r
.ret_str
,"short")==0)
2848 opt
.keyid_format
=KF_SHORT
;
2849 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"long")==0)
2850 opt
.keyid_format
=KF_LONG
;
2851 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"0xshort")==0)
2852 opt
.keyid_format
=KF_0xSHORT
;
2853 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"0xlong")==0)
2854 opt
.keyid_format
=KF_0xLONG
;
2856 log_error("unknown keyid-format `%s'\n",pargs
.r
.ret_str
);
2859 case oExitOnStatusWriteError
:
2860 opt
.exit_on_status_write_error
= 1;
2863 case oLimitCardInsertTries
:
2864 opt
.limit_card_insert_tries
= pargs
.r
.ret_int
;
2867 case oRequireCrossCert
: opt
.flags
.require_cross_cert
=1; break;
2868 case oNoRequireCrossCert
: opt
.flags
.require_cross_cert
=0; break;
2870 case oAutoKeyLocate
:
2871 if(!parse_auto_key_locate(pargs
.r
.ret_str
))
2874 log_error(_("%s:%d: invalid auto-key-locate list\n"),
2875 configname
,configlineno
);
2877 log_error(_("invalid auto-key-locate list\n"));
2880 case oNoAutoKeyLocate
:
2884 case oEnableDSA2
: opt
.flags
.dsa2
=1; break;
2885 case oDisableDSA2
: opt
.flags
.dsa2
=0; break;
2887 case oAllowMultisigVerification
:
2888 case oAllowMultipleMessages
:
2889 opt
.flags
.allow_multiple_messages
=1;
2892 case oNoAllowMultipleMessages
:
2893 opt
.flags
.allow_multiple_messages
=0;
2899 pargs
.err
= configfp
? ARGPARSE_PRINT_WARNING
:ARGPARSE_PRINT_ERROR
;
2908 /* Remember the first config file name. */
2909 if (!save_configname
)
2910 save_configname
= configname
;
2916 xfree( configname
); configname
= NULL
;
2917 if( log_get_errorcount(0) )
2920 /* The command --gpgconf-list is pretty simple and may be called
2921 directly after the option parsing. */
2922 if (cmd
== aGPGConfList
)
2924 gpgconf_list (save_configname
? save_configname
: default_configname
);
2927 xfree (save_configname
);
2928 xfree (default_configname
);
2934 fprintf(stderr
, "%s %s; %s\n",
2935 strusage(11), strusage(13), strusage(14) );
2936 fprintf(stderr
, "%s\n", strusage(15) );
2938 #ifdef IS_DEVELOPMENT_VERSION
2943 if((s
=strusage(25)))
2945 if((s
=strusage(26)))
2947 if((s
=strusage(27)))
2952 /* FIXME: We should use logging to a file only in server mode;
2953 however we have not yet implemetyed that. Thus we try to get
2954 away with --batch as indication for logging to file
2956 if (logfile
&& opt
.batch
)
2958 log_set_file (logfile
);
2959 log_set_prefix (NULL
, 1|2|4);
2963 /* We better also print a runtime warning if people build it with
2964 support for Camellia (which is not yet defined by OpenPGP). */
2965 log_info ("WARNING: This version has been built with support for the "
2966 "Camellia cipher.\n");
2967 log_info (" It is for testing only and is NOT for production "
2971 /* Older Libgcrypts fail with an assertion during DSA key
2972 generation. Better disable DSA2 entirely. */
2973 if (opt
.flags
.dsa2
&& !gcry_check_version ("1.4.0") )
2975 log_info ("WARNING: "
2976 "DSA2 is only available with Libgcrypt 1.4 and later\n");
2980 if (opt
.verbose
> 2)
2981 log_info ("using character set `%s'\n", get_native_charset ());
2983 if( may_coredump
&& !opt
.quiet
)
2984 log_info(_("WARNING: program may create a core file!\n"));
2987 if (opt
.set_filename
)
2988 log_info(_("WARNING: %s overrides %s\n"),
2989 "--for-your-eyes-only","--set-filename");
2991 opt
.set_filename
="_CONSOLE";
2994 if (opt
.no_literal
) {
2995 log_info(_("NOTE: %s is not for normal use!\n"), "--no-literal");
2997 log_error(_("%s not allowed with %s!\n"),
2998 "--textmode", "--no-literal" );
2999 if (opt
.set_filename
)
3000 log_error(_("%s makes no sense with %s!\n"),
3001 eyes_only
?"--for-your-eyes-only":"--set-filename",
3006 if (opt
.set_filesize
)
3007 log_info(_("NOTE: %s is not for normal use!\n"), "--set-filesize");
3011 gcry_control (GCRYCTL_RESUME_SECMEM_WARN
);
3013 if(require_secmem
&& !got_secmem
)
3015 log_info(_("will not run with insecure memory due to %s\n"),
3016 "--require-secmem");
3020 set_debug (debug_level
);
3022 /* Do these after the switch(), so they can override settings. */
3027 if(cmd
==aSign
&& !detached_sig
)
3029 log_info(_("you can only make detached or clear signatures "
3030 "while in --pgp2 mode\n"));
3033 else if(cmd
==aSignEncr
|| cmd
==aSignSym
)
3035 log_info(_("you can't sign and encrypt at the "
3036 "same time while in --pgp2 mode\n"));
3039 else if(argc
==0 && (cmd
==aSign
|| cmd
==aEncr
|| cmd
==aSym
))
3041 log_info(_("you must use files (and not a pipe) when "
3042 "working with --pgp2 enabled.\n"));
3045 else if(cmd
==aEncr
|| cmd
==aSym
)
3047 /* Everything else should work without IDEA (except using
3048 a secret key encrypted with IDEA and setting an IDEA
3049 preference, but those have their own error
3052 if (openpgp_cipher_test_algo(CIPHER_ALGO_IDEA
))
3054 log_info(_("encrypting a message in --pgp2 mode requires "
3055 "the IDEA cipher\n"));
3056 idea_cipher_warn(1);
3061 /* This only sets IDEA for symmetric encryption
3062 since it is set via select_algo_from_prefs for
3064 xfree(def_cipher_string
);
3065 def_cipher_string
= xstrdup("idea");
3068 /* PGP2 can't handle the output from the textmode
3069 filter, so we disable it for anything that could
3070 create a literal packet (only encryption and
3071 symmetric encryption, since we disable signing
3078 compliance_failure();
3081 opt
.force_v4_certs
= 0;
3082 opt
.escape_from
= 1;
3083 opt
.force_v3_sigs
= 1;
3084 opt
.pgp2_workarounds
= 1;
3085 opt
.ask_sig_expire
= 0;
3086 opt
.ask_cert_expire
= 0;
3087 xfree(def_digest_string
);
3088 def_digest_string
= xstrdup("md5");
3089 xfree(s2k_digest_string
);
3090 s2k_digest_string
= xstrdup("md5");
3091 opt
.compress_algo
= COMPRESS_ALGO_ZIP
;
3097 opt
.force_v3_sigs
=1;
3098 opt
.ask_sig_expire
=0;
3103 opt
.force_v3_sigs
=1;
3104 opt
.ask_sig_expire
=0;
3112 if( def_cipher_string
) {
3113 opt
.def_cipher_algo
= string_to_cipher_algo (def_cipher_string
);
3114 if(opt
.def_cipher_algo
==0 &&
3115 (ascii_strcasecmp(def_cipher_string
,"idea")==0
3116 || ascii_strcasecmp(def_cipher_string
,"s1")==0))
3117 idea_cipher_warn(1);
3118 xfree(def_cipher_string
); def_cipher_string
= NULL
;
3119 if ( openpgp_cipher_test_algo (opt
.def_cipher_algo
) )
3120 log_error(_("selected cipher algorithm is invalid\n"));
3122 if( def_digest_string
) {
3123 opt
.def_digest_algo
= string_to_digest_algo (def_digest_string
);
3124 xfree(def_digest_string
); def_digest_string
= NULL
;
3125 if ( openpgp_md_test_algo (opt
.def_digest_algo
) )
3126 log_error(_("selected digest algorithm is invalid\n"));
3128 if( compress_algo_string
) {
3129 opt
.compress_algo
= string_to_compress_algo(compress_algo_string
);
3130 xfree(compress_algo_string
); compress_algo_string
= NULL
;
3131 if( check_compress_algo(opt
.compress_algo
) )
3132 log_error(_("selected compression algorithm is invalid\n"));
3134 if( cert_digest_string
) {
3135 opt
.cert_digest_algo
= string_to_digest_algo (cert_digest_string
);
3136 xfree(cert_digest_string
); cert_digest_string
= NULL
;
3137 if (openpgp_md_test_algo(opt
.cert_digest_algo
))
3138 log_error(_("selected certification digest algorithm is invalid\n"));
3140 if( s2k_cipher_string
) {
3141 opt
.s2k_cipher_algo
= string_to_cipher_algo (s2k_cipher_string
);
3142 xfree(s2k_cipher_string
); s2k_cipher_string
= NULL
;
3143 if (openpgp_cipher_test_algo (opt
.s2k_cipher_algo
))
3144 log_error(_("selected cipher algorithm is invalid\n"));
3146 if( s2k_digest_string
) {
3147 opt
.s2k_digest_algo
= string_to_digest_algo (s2k_digest_string
);
3148 xfree(s2k_digest_string
); s2k_digest_string
= NULL
;
3149 if (openpgp_md_test_algo(opt
.s2k_digest_algo
))
3150 log_error(_("selected digest algorithm is invalid\n"));
3152 if( opt
.completes_needed
< 1 )
3153 log_error(_("completes-needed must be greater than 0\n"));
3154 if( opt
.marginals_needed
< 2 )
3155 log_error(_("marginals-needed must be greater than 1\n"));
3156 if( opt
.max_cert_depth
< 1 || opt
.max_cert_depth
> 255 )
3157 log_error(_("max-cert-depth must be in the range from 1 to 255\n"));
3158 if(opt
.def_cert_level
<0 || opt
.def_cert_level
>3)
3159 log_error(_("invalid default-cert-level; must be 0, 1, 2, or 3\n"));
3160 if( opt
.min_cert_level
< 1 || opt
.min_cert_level
> 3 )
3161 log_error(_("invalid min-cert-level; must be 1, 2, or 3\n"));
3162 switch( opt
.s2k_mode
) {
3164 log_info(_("NOTE: simple S2K mode (0) is strongly discouraged\n"));
3166 case 1: case 3: break;
3168 log_error(_("invalid S2K mode; must be 0, 1 or 3\n"));
3171 /* This isn't actually needed, but does serve to error out if the
3172 string is invalid. */
3173 if(opt
.def_preference_list
&&
3174 keygen_set_std_prefs(opt
.def_preference_list
,0))
3175 log_error(_("invalid default preferences\n"));
3177 /* We provide defaults for the personal digest list. This is
3179 if(!pers_digest_list
)
3180 pers_digest_list
="h2";
3182 if(pers_cipher_list
&&
3183 keygen_set_std_prefs(pers_cipher_list
,PREFTYPE_SYM
))
3184 log_error(_("invalid personal cipher preferences\n"));
3186 if(pers_digest_list
&&
3187 keygen_set_std_prefs(pers_digest_list
,PREFTYPE_HASH
))
3188 log_error(_("invalid personal digest preferences\n"));
3190 if(pers_compress_list
&&
3191 keygen_set_std_prefs(pers_compress_list
,PREFTYPE_ZIP
))
3192 log_error(_("invalid personal compress preferences\n"));
3194 /* We don't support all possible commands with multifile yet */
3205 cmdname
="--clearsign";
3208 cmdname
="--detach-sign";
3211 cmdname
="--symmetric";
3214 cmdname
="--symmetric --encrypt";
3225 log_error(_("%s does not yet work with %s\n"),cmdname
,"--multifile");
3228 if( log_get_errorcount(0) )
3231 if(opt
.compress_level
==0)
3232 opt
.compress_algo
=COMPRESS_ALGO_NONE
;
3234 /* Check our chosen algorithms against the list of legal
3239 const char *badalg
=NULL
;
3240 preftype_t badtype
=PREFTYPE_NONE
;
3242 if(opt
.def_cipher_algo
3243 && !algo_available(PREFTYPE_SYM
,opt
.def_cipher_algo
,NULL
))
3245 badalg
= openpgp_cipher_algo_name (opt
.def_cipher_algo
);
3246 badtype
= PREFTYPE_SYM
;
3248 else if(opt
.def_digest_algo
3249 && !algo_available(PREFTYPE_HASH
,opt
.def_digest_algo
,NULL
))
3251 badalg
= gcry_md_algo_name (opt
.def_digest_algo
);
3252 badtype
= PREFTYPE_HASH
;
3254 else if(opt
.cert_digest_algo
3255 && !algo_available(PREFTYPE_HASH
,opt
.cert_digest_algo
,NULL
))
3257 badalg
= gcry_md_algo_name (opt
.cert_digest_algo
);
3258 badtype
= PREFTYPE_HASH
;
3260 else if(opt
.compress_algo
!=-1
3261 && !algo_available(PREFTYPE_ZIP
,opt
.compress_algo
,NULL
))
3263 badalg
= compress_algo_to_string(opt
.compress_algo
);
3264 badtype
= PREFTYPE_ZIP
;
3272 log_info(_("you may not use cipher algorithm `%s'"
3273 " while in %s mode\n"),
3274 badalg
,compliance_option_string());
3277 log_info(_("you may not use digest algorithm `%s'"
3278 " while in %s mode\n"),
3279 badalg
,compliance_option_string());
3282 log_info(_("you may not use compression algorithm `%s'"
3283 " while in %s mode\n"),
3284 badalg
,compliance_option_string());
3290 compliance_failure();
3294 /* Set the random seed file. */
3295 if( use_random_seed
) {
3296 char *p
= make_filename(opt
.homedir
, "random_seed", NULL
);
3297 gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE
, p
);
3298 if (!access (p
, F_OK
))
3299 register_secured_file (p
);
3303 if( !cmd
&& opt
.fingerprint
&& !with_fpr
) {
3304 set_cmd( &cmd
, aListKeys
);
3308 if( opt
.verbose
> 1 )
3309 set_packet_list_mode(1);
3311 /* Add the keyrings, but not for some special commands. Also
3312 avoid adding the secret keyring for a couple of commands to
3313 avoid unneeded access in case the secrings are stored on a
3316 We always need to add the keyrings if we are running under
3317 SELinux, this is so that the rings are added to the list of
3319 if( ALWAYS_ADD_KEYRINGS
3320 || (cmd
!= aDeArmor
&& cmd
!= aEnArmor
&& cmd
!= aGPGConfTest
) )
3322 if (ALWAYS_ADD_KEYRINGS
3323 || (cmd
!= aCheckKeys
&& cmd
!= aListSigs
&& cmd
!= aListKeys
3324 && cmd
!= aVerify
&& cmd
!= aSym
&& cmd
!= aLocateKeys
))
3326 if (!sec_nrings
|| default_keyring
) /* add default secret rings */
3327 keydb_add_resource ("secring" EXTSEP_S
"gpg", 4, 1);
3328 for (sl
= sec_nrings
; sl
; sl
= sl
->next
)
3329 keydb_add_resource ( sl
->d
, 0, 1 );
3331 if( !nrings
|| default_keyring
) /* add default ring */
3332 keydb_add_resource ("pubring" EXTSEP_S
"gpg", 4, 0);
3333 for(sl
= nrings
; sl
; sl
= sl
->next
)
3334 keydb_add_resource ( sl
->d
, sl
->flags
, 0 );
3336 FREE_STRLIST(nrings
);
3337 FREE_STRLIST(sec_nrings
);
3339 if (cmd
== aGPGConfTest
)
3343 if( pwfd
!= -1 ) /* Read the passphrase now. */
3344 read_passphrase_from_fd( pwfd
);
3346 fname
= argc
? *argv
: NULL
;
3348 if(fname
&& utf8_strings
)
3349 opt
.flags
.utf8_filename
=1;
3360 case aExportOwnerTrust
: rc
= setup_trustdb( 0, trustdb_name
); break;
3361 case aListTrustDB
: rc
= setup_trustdb( argc
? 1:0, trustdb_name
); break;
3362 default: rc
= setup_trustdb(1, trustdb_name
); break;
3365 log_error(_("failed to initialize the TrustDB: %s\n"), g10_errstr(rc
));
3375 if (!opt
.quiet
&& any_explicit_recipient
)
3376 log_info (_("WARNING: recipients (-r) given "
3377 "without using public key encryption\n"));
3387 ctrl_t ctrl
= xtrycalloc (1, sizeof *ctrl
);
3388 gpg_init_default_ctrl (ctrl
);
3390 gpg_deinit_default_ctrl (ctrl
);
3395 case aStore
: /* only store the file */
3397 wrong_args(_("--store [filename]"));
3398 if( (rc
= encode_store(fname
)) )
3399 log_error ("storing `%s' failed: %s\n",
3400 print_fname_stdin(fname
),g10_errstr(rc
) );
3402 case aSym
: /* encrypt the given file only with the symmetric cipher */
3404 wrong_args(_("--symmetric [filename]"));
3405 if( (rc
= encode_symmetric(fname
)) )
3406 log_error (_("symmetric encryption of `%s' failed: %s\n"),
3407 print_fname_stdin(fname
),g10_errstr(rc
) );
3410 case aEncr
: /* encrypt the given file */
3412 encode_crypt_files(argc
, argv
, remusr
);
3416 wrong_args(_("--encrypt [filename]"));
3417 if( (rc
= encode_crypt(fname
,remusr
,0)) )
3418 log_error("%s: encryption failed: %s\n",
3419 print_fname_stdin(fname
), g10_errstr(rc
) );
3424 /* This works with PGP 8 in the sense that it acts just like a
3425 symmetric message. It doesn't work at all with 2 or 6. It
3426 might work with 7, but alas, I don't have a copy to test
3429 wrong_args(_("--symmetric --encrypt [filename]"));
3430 else if(opt
.s2k_mode
==0)
3431 log_error(_("you cannot use --symmetric --encrypt"
3432 " with --s2k-mode 0\n"));
3433 else if(PGP2
|| PGP6
|| PGP7
|| RFC1991
)
3434 log_error(_("you cannot use --symmetric --encrypt"
3435 " while in %s mode\n"),compliance_option_string());
3438 if( (rc
= encode_crypt(fname
,remusr
,1)) )
3439 log_error("%s: encryption failed: %s\n",
3440 print_fname_stdin(fname
), g10_errstr(rc
) );
3444 case aSign
: /* sign the given file */
3446 if( detached_sig
) { /* sign all files */
3447 for( ; argc
; argc
--, argv
++ )
3448 add_to_strlist( &sl
, *argv
);
3452 wrong_args(_("--sign [filename]"));
3454 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3455 strcpy(sl
->d
, fname
);
3458 if( (rc
= sign_file( sl
, detached_sig
, locusr
, 0, NULL
, NULL
)) )
3459 log_error("signing failed: %s\n", g10_errstr(rc
) );
3463 case aSignEncr
: /* sign and encrypt the given file */
3465 wrong_args(_("--sign --encrypt [filename]"));
3467 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3468 strcpy(sl
->d
, fname
);
3472 if( (rc
= sign_file(sl
, detached_sig
, locusr
, 1, remusr
, NULL
)) )
3473 log_error("%s: sign+encrypt failed: %s\n",
3474 print_fname_stdin(fname
), g10_errstr(rc
) );
3478 case aSignEncrSym
: /* sign and encrypt the given file */
3480 wrong_args(_("--symmetric --sign --encrypt [filename]"));
3481 else if(opt
.s2k_mode
==0)
3482 log_error(_("you cannot use --symmetric --sign --encrypt"
3483 " with --s2k-mode 0\n"));
3484 else if(PGP2
|| PGP6
|| PGP7
|| RFC1991
)
3485 log_error(_("you cannot use --symmetric --sign --encrypt"
3486 " while in %s mode\n"),compliance_option_string());
3491 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3492 strcpy(sl
->d
, fname
);
3496 if( (rc
= sign_file(sl
, detached_sig
, locusr
, 2, remusr
, NULL
)) )
3497 log_error("%s: symmetric+sign+encrypt failed: %s\n",
3498 print_fname_stdin(fname
), g10_errstr(rc
) );
3503 case aSignSym
: /* sign and conventionally encrypt the given file */
3505 wrong_args(_("--sign --symmetric [filename]"));
3506 rc
= sign_symencrypt_file (fname
, locusr
);
3508 log_error("%s: sign+symmetric failed: %s\n",
3509 print_fname_stdin(fname
), g10_errstr(rc
) );
3512 case aClearsign
: /* make a clearsig */
3514 wrong_args(_("--clearsign [filename]"));
3515 if( (rc
= clearsign_file(fname
, locusr
, NULL
)) )
3516 log_error("%s: clearsign failed: %s\n",
3517 print_fname_stdin(fname
), g10_errstr(rc
) );
3523 if( (rc
= verify_files( argc
, argv
) ))
3524 log_error("verify files failed: %s\n", g10_errstr(rc
) );
3528 if( (rc
= verify_signatures( argc
, argv
) ))
3529 log_error("verify signatures failed: %s\n", g10_errstr(rc
) );
3535 decrypt_messages(argc
, argv
);
3539 wrong_args(_("--decrypt [filename]"));
3540 if( (rc
= decrypt_message( fname
) ))
3541 log_error("decrypt_message failed: %s\n", g10_errstr(rc
) );
3547 wrong_args(_("--sign-key user-id"));
3551 wrong_args(_("--lsign-key user-id"));
3557 append_to_strlist(&sl
,"sign");
3558 else if(cmd
==aLSignKey
)
3559 append_to_strlist(&sl
,"lsign");
3563 append_to_strlist( &sl
, "save" );
3564 username
= make_username( fname
);
3565 keyedit_menu (username
, locusr
, sl
, 0, 0 );
3570 case aEditKey
: /* Edit a key signature */
3572 wrong_args(_("--edit-key user-id [commands]"));
3573 username
= make_username( fname
);
3576 for( argc
--, argv
++ ; argc
; argc
--, argv
++ )
3577 append_to_strlist( &sl
, *argv
);
3578 keyedit_menu( username
, locusr
, sl
, 0, 1 );
3582 keyedit_menu(username
, locusr
, NULL
, 0, 1 );
3587 case aDeleteSecretKeys
:
3588 case aDeleteSecretAndPublicKeys
:
3590 /* I'm adding these in reverse order as add_to_strlist2
3591 reverses them again, and it's easier to understand in the
3593 for( ; argc
; argc
-- )
3594 add_to_strlist2( &sl
, argv
[argc
-1], utf8_strings
);
3595 delete_keys(sl
,cmd
==aDeleteSecretKeys
,cmd
==aDeleteSecretAndPublicKeys
);
3605 for( ; argc
; argc
--, argv
++ )
3606 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3607 public_key_list( sl
, 0 );
3610 case aListSecretKeys
:
3612 for( ; argc
; argc
--, argv
++ )
3613 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3614 secret_key_list( sl
);
3619 for (; argc
; argc
--, argv
++)
3620 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3621 public_key_list (sl
, 1);
3625 case aKeygen
: /* generate a key */
3628 wrong_args("--gen-key [parameterfile]");
3629 generate_keypair( argc
? *argv
: NULL
, NULL
, NULL
);
3633 wrong_args("--gen-key");
3634 generate_keypair(NULL
, NULL
, NULL
);
3639 opt
.import_options
|= IMPORT_FAST
;
3641 import_keys( argc
? argv
:NULL
, argc
, NULL
, opt
.import_options
);
3644 /* TODO: There are a number of command that use this same
3645 "make strlist, call function, report error, free strlist"
3646 pattern. Join them together here and avoid all that
3653 for( ; argc
; argc
--, argv
++ )
3654 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3655 if( cmd
== aSendKeys
)
3656 rc
=keyserver_export( sl
);
3657 else if( cmd
== aRecvKeys
)
3658 rc
=keyserver_import( sl
);
3660 rc
=export_pubkeys( sl
, opt
.export_options
);
3664 log_error(_("keyserver send failed: %s\n"),g10_errstr(rc
));
3665 else if(cmd
==aRecvKeys
)
3666 log_error(_("keyserver receive failed: %s\n"),g10_errstr(rc
));
3668 log_error(_("key export failed: %s\n"),g10_errstr(rc
));
3675 for( ; argc
; argc
--, argv
++ )
3676 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3677 rc
=keyserver_search( sl
);
3679 log_error(_("keyserver search failed: %s\n"),g10_errstr(rc
));
3685 for( ; argc
; argc
--, argv
++ )
3686 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3687 rc
=keyserver_refresh(sl
);
3689 log_error(_("keyserver refresh failed: %s\n"),g10_errstr(rc
));
3695 for( ; argc
; argc
--, argv
++ )
3696 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3697 rc
=keyserver_fetch(sl
);
3699 log_error("key fetch failed: %s\n",g10_errstr(rc
));
3705 for( ; argc
; argc
--, argv
++ )
3706 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3707 export_seckeys( sl
);
3711 case aExportSecretSub
:
3713 for( ; argc
; argc
--, argv
++ )
3714 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3715 export_secsubkeys( sl
);
3721 wrong_args("--gen-revoke user-id");
3722 username
= make_username(*argv
);
3723 gen_revoke( username
);
3729 wrong_args("--desig-revoke user-id");
3730 username
= make_username(*argv
);
3731 gen_desig_revoke( username
, locusr
);
3737 wrong_args("--dearmor [file]");
3738 rc
= dearmor_file( argc
? *argv
: NULL
);
3740 log_error(_("dearmoring failed: %s\n"), g10_errstr(rc
));
3745 wrong_args("--enarmor [file]");
3746 rc
= enarmor_file( argc
? *argv
: NULL
);
3748 log_error(_("enarmoring failed: %s\n"), g10_errstr(rc
));
3754 { int mode
= argc
< 2 ? 0 : atoi(*argv
);
3756 if( mode
== 1 && argc
== 2 ) {
3757 mpi_print( stdout
, generate_public_prime( atoi(argv
[1]) ), 1);
3759 else if( mode
== 2 && argc
== 3 ) {
3760 mpi_print( stdout
, generate_elg_prime(
3762 atoi(argv
[2]), NULL
,NULL
), 1);
3764 else if( mode
== 3 && argc
== 3 ) {
3766 mpi_print( stdout
, generate_elg_prime(
3768 atoi(argv
[2]), NULL
,&factors
), 1);
3770 mpi_print( stdout
, factors
[0], 1 ); /* print q */
3772 else if( mode
== 4 && argc
== 3 ) {
3773 MPI g
= mpi_alloc(1);
3774 mpi_print( stdout
, generate_elg_prime(
3776 atoi(argv
[2]), g
, NULL
), 1);
3778 mpi_print( stdout
, g
, 1 );
3782 wrong_args("--gen-prime mode bits [qbits] ");
3786 wrong_args("--gen-prime not yet supported ");
3791 int level
= argc
? atoi(*argv
):0;
3792 int count
= argc
> 1 ? atoi(argv
[1]): 0;
3793 int endless
= !count
;
3795 if( argc
< 1 || argc
> 2 || level
< 0 || level
> 2 || count
< 0 )
3796 wrong_args("--gen-random 0|1|2 [count]");
3798 while( endless
|| count
) {
3800 /* Wee need a multiple of 3, so that in case of
3801 armored output we get a correct string. No
3802 linefolding is done, as it is best to levae this to
3804 size_t n
= !endless
&& count
< 99? count
: 99;
3806 p
= gcry_random_bytes (n
, level
);
3807 #ifdef HAVE_DOSISH_SYSTEM
3808 setmode ( fileno(stdout
), O_BINARY
);
3811 char *tmp
= make_radix64_string (p
, n
);
3812 fputs (tmp
, stdout
);
3819 fwrite( p
, n
, 1, stdout
);
3832 wrong_args("--print-md algo [files]");
3834 int all_algos
= (**argv
=='*' && !(*argv
)[1]);
3835 int algo
= all_algos
? 0 : gcry_md_map_name (*argv
);
3837 if( !algo
&& !all_algos
)
3838 log_error(_("invalid hash algorithm `%s'\n"), *argv
);
3842 print_mds(NULL
, algo
);
3844 for(; argc
; argc
--, argv
++ )
3845 print_mds(*argv
, algo
);
3851 case aPrintMDs
: /* old option */
3855 for(; argc
; argc
--, argv
++ )
3864 for( ; argc
; argc
--, argv
++ )
3865 list_trustdb( *argv
);
3869 case aUpdateTrustDB
:
3871 wrong_args("--update-trustdb");
3876 /* Old versions allowed for arguments - ignore them */
3881 log_error("this command is not yet implemented.\n");
3882 log_error("A workaround is to use \"--export-ownertrust\", remove\n");
3883 log_error("the trustdb file and do an \"--import-ownertrust\".\n" );
3886 case aListTrustPath
:
3888 wrong_args("--list-trust-path <user-ids>");
3889 for( ; argc
; argc
--, argv
++ ) {
3890 username
= make_username( *argv
);
3891 list_trust_path( username
);
3896 case aExportOwnerTrust
:
3898 wrong_args("--export-ownertrust");
3899 export_ownertrust();
3902 case aImportOwnerTrust
:
3904 wrong_args("--import-ownertrust [file]");
3905 import_ownertrust( argc
? *argv
:NULL
);
3908 case aRebuildKeydbCaches
:
3910 wrong_args ("--rebuild-keydb-caches");
3911 keydb_rebuild_caches (1);
3914 #ifdef ENABLE_CARD_SUPPORT
3917 wrong_args ("--card-status");
3918 card_status (stdout
, NULL
, 0);
3924 for (argc
--, argv
++ ; argc
; argc
--, argv
++)
3925 append_to_strlist (&sl
, *argv
);
3937 change_pin (atoi (*argv
),1);
3939 wrong_args ("--change-pin [no]");
3941 #endif /* ENABLE_CARD_SUPPORT*/
3945 char *str
=collapse_args(argc
,argv
);
3955 wrong_args(_("[filename]"));
3956 /* Issue some output for the unix newbie */
3957 if( !fname
&& !opt
.outfile
&& isatty( fileno(stdin
) )
3958 && isatty( fileno(stdout
) ) && isatty( fileno(stderr
) ) )
3959 log_info(_("Go ahead and type your message ...\n"));
3961 a
= iobuf_open(fname
);
3962 if (a
&& is_secured_file (iobuf_get_fd (a
)))
3969 log_error(_("can't open `%s'\n"), print_fname_stdin(fname
));
3972 if( !opt
.no_armor
) {
3973 if( use_armor_filter( a
) ) {
3974 afx
= new_armor_context ();
3975 push_armor_filter (afx
, a
);
3978 if( cmd
== aListPackets
) {
3979 set_packet_list_mode(1);
3982 rc
= proc_packets(NULL
, a
);
3984 log_error("processing message failed: %s\n", g10_errstr(rc
) );
3991 release_armor_context (afx
);
3992 FREE_STRLIST(remusr
);
3993 FREE_STRLIST(locusr
);
3995 return 8; /*NEVER REACHED*/
3999 /* Note: This function is used by signal handlers!. */
4001 emergency_cleanup (void)
4003 gcry_control (GCRYCTL_TERM_SECMEM
);
4010 gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE
);
4011 if ( (opt
.debug
& DBG_MEMSTAT_VALUE
) )
4013 gcry_control (GCRYCTL_DUMP_MEMORY_STATS
);
4014 gcry_control (GCRYCTL_DUMP_RANDOM_STATS
);
4017 gcry_control (GCRYCTL_DUMP_SECMEM_STATS
);
4019 emergency_cleanup ();
4021 rc
= rc
? rc
: log_get_errorcount(0)? 2 : g10_errors_seen
? 1 : 0;
4026 /* Pretty-print hex hashes. This assumes at least an 80-character
4027 display, but there are a few other similar assumptions in the
4030 print_hex( gcry_md_hd_t md
, int algo
, const char *fname
)
4032 int i
,n
,count
,indent
=0;
4036 indent
=printf("%s: ",fname
);
4044 if(algo
==DIGEST_ALGO_RMD160
)
4045 indent
+=printf("RMD160 = ");
4047 indent
+=printf("%6s = ", gcry_md_algo_name (algo
));
4053 p
= gcry_md_read (md
, algo
);
4054 n
= gcry_md_get_algo_dlen (algo
);
4056 count
+= printf ("%02X",*p
++);
4058 for(i
=1;i
<n
;i
++,p
++)
4064 printf("\n%*s",indent
," ");
4079 printf("\n%*s",indent
," ");
4095 printf("\n%*s",indent
," ");
4103 count
+=printf("%02X",*p
);
4110 print_hashline( gcry_md_hd_t md
, int algo
, const char *fname
)
4116 for (p
= fname
; *p
; p
++ ) {
4117 if ( *p
<= 32 || *p
> 127 || *p
== ':' || *p
== '%' )
4118 printf("%%%02X", *p
);
4124 printf("%d:", algo
);
4125 p
= gcry_md_read (md
, algo
);
4126 n
= gcry_md_get_algo_dlen (algo
);
4127 for(i
=0; i
< n
; i
++, p
++ )
4128 printf("%02X", *p
);
4134 print_mds( const char *fname
, int algo
)
4143 #ifdef HAVE_DOSISH_SYSTEM
4144 setmode ( fileno(fp
) , O_BINARY
);
4148 fp
= fopen( fname
, "rb" );
4149 if (fp
&& is_secured_file (fileno (fp
)))
4157 log_error("%s: %s\n", fname
?fname
:"[stdin]", strerror(errno
) );
4161 gcry_md_open (&md
, 0, 0);
4163 gcry_md_enable (md
, algo
);
4165 gcry_md_enable (md
, GCRY_MD_MD5
);
4166 gcry_md_enable (md
, GCRY_MD_SHA1
);
4167 gcry_md_enable (md
, GCRY_MD_RMD160
);
4168 if (!openpgp_md_test_algo (GCRY_MD_SHA224
))
4169 gcry_md_enable (md
, GCRY_MD_SHA224
);
4170 if (!openpgp_md_test_algo (GCRY_MD_SHA256
))
4171 gcry_md_enable (md
, GCRY_MD_SHA256
);
4172 if (!openpgp_md_test_algo (GCRY_MD_SHA384
))
4173 gcry_md_enable (md
, GCRY_MD_SHA384
);
4174 if (!openpgp_md_test_algo (GCRY_MD_SHA512
))
4175 gcry_md_enable (md
, GCRY_MD_SHA512
);
4178 while( (n
=fread( buf
, 1, DIM(buf
), fp
)) )
4179 gcry_md_write (md
, buf
, n
);
4181 log_error("%s: %s\n", fname
?fname
:"[stdin]", strerror(errno
) );
4184 if ( opt
.with_colons
) {
4186 print_hashline( md
, algo
, fname
);
4188 print_hashline( md
, GCRY_MD_MD5
, fname
);
4189 print_hashline( md
, GCRY_MD_SHA1
, fname
);
4190 if (!gcry_md_test_algo (GCRY_MD_RMD160
))
4191 print_hashline( md
, GCRY_MD_RMD160
, fname
);
4192 if (!gcry_md_test_algo (GCRY_MD_SHA224
))
4193 print_hashline (md
, GCRY_MD_SHA224
, fname
);
4194 if (!gcry_md_test_algo (GCRY_MD_SHA256
))
4195 print_hashline( md
, GCRY_MD_SHA256
, fname
);
4196 if (!gcry_md_test_algo (GCRY_MD_SHA384
))
4197 print_hashline ( md
, GCRY_MD_SHA384
, fname
);
4198 if (!gcry_md_test_algo (GCRY_MD_SHA512
))
4199 print_hashline ( md
, GCRY_MD_SHA512
, fname
);
4204 print_hex(md
,-algo
,fname
);
4206 print_hex( md
, GCRY_MD_MD5
, fname
);
4207 print_hex( md
, GCRY_MD_SHA1
, fname
);
4208 if (!gcry_md_test_algo (GCRY_MD_RMD160
))
4209 print_hex( md
, GCRY_MD_RMD160
, fname
);
4210 if (!gcry_md_test_algo (GCRY_MD_SHA224
))
4211 print_hex (md
, GCRY_MD_SHA224
, fname
);
4212 if (!gcry_md_test_algo (GCRY_MD_SHA256
))
4213 print_hex( md
, GCRY_MD_SHA256
, fname
);
4214 if (!gcry_md_test_algo (GCRY_MD_SHA384
))
4215 print_hex( md
, GCRY_MD_SHA384
, fname
);
4216 if (!gcry_md_test_algo (GCRY_MD_SHA512
))
4217 print_hex( md
, GCRY_MD_SHA512
, fname
);
4229 * Check the supplied name,value string and add it to the notation
4230 * data to be used for signatures. which==0 for sig notations, and 1
4231 * for cert notations.
4234 add_notation_data( const char *string
, int which
)
4236 struct notation
*notation
;
4238 notation
=string_to_notation(string
,utf8_strings
);
4243 notation
->next
=opt
.cert_notations
;
4244 opt
.cert_notations
=notation
;
4248 notation
->next
=opt
.sig_notations
;
4249 opt
.sig_notations
=notation
;
4255 add_policy_url( const char *string
, int which
)
4257 unsigned int i
,critical
=0;
4266 for(i
=0;i
<strlen(string
);i
++)
4267 if( !isascii (string
[i
]) || iscntrl(string
[i
]))
4270 if(i
==0 || i
<strlen(string
))
4273 log_error(_("the given certification policy URL is invalid\n"));
4275 log_error(_("the given signature policy URL is invalid\n"));
4279 sl
=add_to_strlist( &opt
.cert_policy_url
, string
);
4281 sl
=add_to_strlist( &opt
.sig_policy_url
, string
);
4288 add_keyserver_url( const char *string
, int which
)
4290 unsigned int i
,critical
=0;
4299 for(i
=0;i
<strlen(string
);i
++)
4300 if( !isascii (string
[i
]) || iscntrl(string
[i
]))
4303 if(i
==0 || i
<strlen(string
))
4308 log_error(_("the given preferred keyserver URL is invalid\n"));
4314 sl
=add_to_strlist( &opt
.sig_keyserver_url
, string
);