1 /* gpg.c - The GnuPG utility (main for gpg)
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 * 2006 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 2 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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
31 #ifdef HAVE_DOSISH_SYSTEM
32 #include <fcntl.h> /* for setmode() */
35 #include <sys/stat.h> /* for stat() */
39 #ifdef HAVE_W32_SYSTEM
43 #define INCLUDED_BY_MAIN_MODULE 1
46 #include "../common/iobuf.h"
57 #include "keyserver-internal.h"
61 #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__)
62 #define MY_O_BINARY O_BINARY
72 enum cmd_and_opt_values
86 oHiddenRecipient
= 'R',
93 aListSecretKeys
= 'K',
117 aDeleteSecretAndPublicKeys
,
213 oBZ2DecompressLowmem
,
251 oUseEmbeddedFilename
,
252 oNoUseEmbeddedFilename
,
297 oAllowNonSelfsignedUID
,
298 oNoAllowNonSelfsignedUID
,
301 oAllowSecretKeyImport
,
302 oEnableSpecialFilenames
,
323 oNoExpensiveTrustChecks
,
329 oPreservePermissions
,
330 oDefaultPreferenceList
,
331 oPersonalCipherPreferences
,
332 oPersonalDigestPreferences
,
333 oPersonalCompressPreferences
,
346 oNoMangleDosFilenames
,
347 oEnableProgressFilter
,
350 oExitOnStatusWriteError
,
351 oLimitCardInsertTries
,
356 oAllowMultisigVerification
,
364 static ARGPARSE_OPTS opts
[] = {
366 { 300, NULL
, 0, N_("@Commands:\n ") },
368 { aSign
, "sign", 256, N_("|[file]|make a signature")},
369 { aClearsign
, "clearsign", 256, N_("|[file]|make a clear text signature")},
370 { aDetachedSign
, "detach-sign", 256, N_("make a detached signature")},
371 { aEncr
, "encrypt", 256, N_("encrypt data")},
372 { aEncrFiles
, "encrypt-files", 256, "@"},
373 { aSym
, "symmetric", 256, N_("encryption only with symmetric cipher")},
374 { aStore
, "store", 256, "@"},
375 { aDecrypt
, "decrypt", 256, N_("decrypt data (default)")},
376 { aDecryptFiles
, "decrypt-files", 256, "@"},
377 { aVerify
, "verify" , 256, N_("verify a signature")},
378 { aVerifyFiles
, "verify-files" , 256, "@" },
379 { aListKeys
, "list-keys", 256, N_("list keys")},
380 { aListKeys
, "list-public-keys", 256, "@" },
381 { aListSigs
, "list-sigs", 256, N_("list keys and signatures")},
382 { aCheckKeys
, "check-sigs",256, N_("list and check key signatures")},
383 { oFingerprint
, "fingerprint", 256, N_("list keys and fingerprints")},
384 { aListSecretKeys
, "list-secret-keys", 256, N_("list secret keys")},
385 { aKeygen
, "gen-key", 256, N_("generate a new key pair")},
386 { aDeleteKeys
,"delete-keys",256,N_("remove keys from the public keyring")},
387 { aDeleteSecretKeys
, "delete-secret-keys",256,
388 N_("remove keys from the secret keyring")},
389 { aSignKey
, "sign-key" ,256, N_("sign a key")},
390 { aLSignKey
, "lsign-key" ,256, N_("sign a key locally")},
391 { aEditKey
, "edit-key" ,256, N_("sign or edit a key")},
392 { aGenRevoke
, "gen-revoke",256, N_("generate a revocation certificate")},
393 { aDesigRevoke
, "desig-revoke",256, "@" },
394 { aExport
, "export" , 256, N_("export keys") },
395 { aSendKeys
, "send-keys" , 256, N_("export keys to a key server") },
396 { aRecvKeys
, "recv-keys" , 256, N_("import keys from a key server") },
397 { aSearchKeys
, "search-keys" , 256,
398 N_("search for keys on a key server") },
399 { aRefreshKeys
, "refresh-keys", 256,
400 N_("update all keys from a keyserver")},
401 { aFetchKeys
, "fetch-keys" , 256, "@" },
402 { aExportSecret
, "export-secret-keys" , 256, "@" },
403 { aExportSecretSub
, "export-secret-subkeys" , 256, "@" },
404 { aImport
, "import", 256 , N_("import/merge keys")},
405 { aFastImport
, "fast-import", 256 , "@"},
406 #ifdef ENABLE_CARD_SUPPORT
407 { aCardStatus
, "card-status", 256, N_("print the card status")},
408 { aCardEdit
, "card-edit", 256, N_("change data on a card")},
409 { aChangePIN
, "change-pin", 256, N_("change a card's PIN")},
411 { aListConfig
, "list-config", 256, "@"},
412 { aGPGConfList
, "gpgconf-list", 256, "@" },
413 { aListPackets
, "list-packets",256, "@"},
414 { aExportOwnerTrust
, "export-ownertrust", 256, "@"},
415 { aImportOwnerTrust
, "import-ownertrust", 256, "@"},
417 "update-trustdb",0 , N_("update the trust database")},
418 { aCheckTrustDB
, "check-trustdb", 0, "@"},
419 { aFixTrustDB
, "fix-trustdb", 0, "@"},
420 { aDeArmor
, "dearmor", 256, "@"},
421 { aDeArmor
, "dearmour", 256, "@"},
422 { aEnArmor
, "enarmor", 256, "@"},
423 { aEnArmor
, "enarmour", 256, "@"},
424 { aPrintMD
, "print-md" , 256, N_("|algo [files]|print message digests")},
425 { aPrimegen
, "gen-prime" , 256, "@" },
426 { aGenRandom
, "gen-random" , 256, "@" },
428 { 301, NULL
, 0, N_("@\nOptions:\n ") },
430 { oArmor
, "armor", 0, N_("create ascii armored output")},
431 { oArmor
, "armour", 0, "@" },
432 { oRecipient
, "recipient", 2, N_("|NAME|encrypt for NAME")},
433 { oHiddenRecipient
, "hidden-recipient", 2, "@" },
434 { oRecipient
, "remote-user", 2, "@"}, /* old option name */
435 { oDefRecipient
, "default-recipient", 2, "@"},
436 { oDefRecipientSelf
, "default-recipient-self", 0, "@"},
437 { oNoDefRecipient
, "no-default-recipient", 0, "@" },
438 { oTempDir
, "temp-directory", 2, "@" },
439 { oExecPath
, "exec-path", 2, "@" },
440 { oEncryptTo
, "encrypt-to", 2, "@" },
441 { oHiddenEncryptTo
, "hidden-encrypt-to", 2, "@" },
442 { oNoEncryptTo
, "no-encrypt-to", 0, "@" },
443 { oLocalUser
, "local-user",2, N_("use this user-id to sign or decrypt")},
444 { oCompress
, NULL
, 1, N_("|N|set compress level N (0 disables)") },
445 { oCompressLevel
, "compress-level", 1, "@" },
446 { oBZ2CompressLevel
, "bzip2-compress-level", 1, "@" },
447 { oBZ2DecompressLowmem
, "bzip2-decompress-lowmem", 0, "@" },
448 { oTextmodeShort
, NULL
, 0, "@"},
449 { oTextmode
, "textmode", 0, N_("use canonical text mode")},
450 { oNoTextmode
, "no-textmode", 0, "@"},
451 { oExpert
, "expert", 0, "@"},
452 { oNoExpert
, "no-expert", 0, "@"},
453 { oDefSigExpire
, "default-sig-expire", 2, "@"},
454 { oAskSigExpire
, "ask-sig-expire", 0, "@"},
455 { oNoAskSigExpire
, "no-ask-sig-expire", 0, "@"},
456 { oDefCertExpire
, "default-cert-expire", 2, "@"},
457 { oAskCertExpire
, "ask-cert-expire", 0, "@"},
458 { oNoAskCertExpire
, "no-ask-cert-expire", 0, "@"},
459 { oDefCertLevel
, "default-cert-level", 1, "@"},
460 { oMinCertLevel
, "min-cert-level", 1, "@"},
461 { oAskCertLevel
, "ask-cert-level", 0, "@"},
462 { oNoAskCertLevel
, "no-ask-cert-level", 0, "@"},
463 { oOutput
, "output", 2, N_("use as output file")},
464 { oMaxOutput
, "max-output", 16|4, "@" },
465 { oVerbose
, "verbose", 0, N_("verbose") },
466 { oQuiet
, "quiet", 0, "@"},
467 { oNoTTY
, "no-tty", 0, "@"},
468 { oForceV3Sigs
, "force-v3-sigs", 0, "@"},
469 { oNoForceV3Sigs
, "no-force-v3-sigs", 0, "@"},
470 { oForceV4Certs
, "force-v4-certs", 0, "@"},
471 { oNoForceV4Certs
, "no-force-v4-certs", 0, "@"},
472 { oForceMDC
, "force-mdc", 0, "@"},
473 { oNoForceMDC
, "no-force-mdc", 0, "@" },
474 { oDisableMDC
, "disable-mdc", 0, "@"},
475 { oNoDisableMDC
, "no-disable-mdc", 0, "@" },
476 { oDryRun
, "dry-run", 0, N_("do not make any changes") },
477 { oInteractive
, "interactive", 0, N_("prompt before overwriting") },
478 { oUseAgent
, "use-agent",0, "@"},
479 { oNoUseAgent
, "no-use-agent",0, "@"},
480 { oGpgAgentInfo
, "gpg-agent-info",2, "@"},
481 { oBatch
, "batch", 0, "@"},
482 { oAnswerYes
, "yes", 0, "@"},
483 { oAnswerNo
, "no", 0, "@"},
484 { oKeyring
, "keyring", 2, "@"},
485 { oPrimaryKeyring
, "primary-keyring",2, "@" },
486 { oSecretKeyring
, "secret-keyring", 2, "@"},
487 { oShowKeyring
, "show-keyring", 0, "@"},
488 { oDefaultKey
, "default-key", 2, "@"},
489 { oKeyServer
, "keyserver", 2, "@"},
490 { oKeyServerOptions
, "keyserver-options",2,"@"},
491 { oImportOptions
, "import-options",2,"@"},
492 { oExportOptions
, "export-options",2,"@"},
493 { oListOptions
, "list-options",2,"@"},
494 { oVerifyOptions
, "verify-options",2,"@"},
495 { oDisplayCharset
, "display-charset", 2, "@"},
496 { oDisplayCharset
, "charset", 2, "@"},
497 { oOptions
, "options", 2, "@"},
498 { oDebug
, "debug" ,4|16, "@"},
499 { oDebugLevel
, "debug-level" ,2, "@"},
500 { oDebugAll
, "debug-all" ,0, "@"},
501 { oStatusFD
, "status-fd" ,1, "@"},
502 { oStatusFile
, "status-file" ,2, "@"},
503 { oAttributeFD
, "attribute-fd" ,1, "@" },
504 { oAttributeFile
, "attribute-file" ,2, "@" },
505 { oNoop
, "sk-comments", 0, "@"},
506 { oNoop
, "no-sk-comments", 0, "@"},
507 { oCompletesNeeded
, "completes-needed", 1, "@"},
508 { oMarginalsNeeded
, "marginals-needed", 1, "@"},
509 { oMaxCertDepth
, "max-cert-depth", 1, "@" },
510 { oTrustedKey
, "trusted-key", 2, "@"},
511 { oLoadExtension
, "load-extension", 2, "@"},
512 { oGnuPG
, "gnupg", 0, "@"},
513 { oGnuPG
, "no-pgp2", 0, "@"},
514 { oGnuPG
, "no-pgp6", 0, "@"},
515 { oGnuPG
, "no-pgp7", 0, "@"},
516 { oGnuPG
, "no-pgp8", 0, "@"},
517 { oRFC1991
, "rfc1991", 0, "@"},
518 { oRFC2440
, "rfc2440", 0, "@" },
519 { oOpenPGP
, "openpgp", 0, N_("use strict OpenPGP behavior")},
520 { oPGP2
, "pgp2", 0, N_("generate PGP 2.x compatible messages")},
521 { oPGP6
, "pgp6", 0, "@"},
522 { oPGP7
, "pgp7", 0, "@"},
523 { oPGP8
, "pgp8", 0, "@"},
524 { oRFC2440Text
, "rfc2440-text", 0, "@"},
525 { oNoRFC2440Text
, "no-rfc2440-text", 0, "@"},
526 { oS2KMode
, "s2k-mode", 1, "@"},
527 { oS2KDigest
, "s2k-digest-algo", 2, "@"},
528 { oS2KCipher
, "s2k-cipher-algo", 2, "@"},
529 { oSimpleSKChecksum
, "simple-sk-checksum", 0, "@"},
530 { oCipherAlgo
, "cipher-algo", 2, "@"},
531 { oDigestAlgo
, "digest-algo", 2, "@"},
532 { oCertDigestAlgo
, "cert-digest-algo", 2 , "@" },
533 { oCompressAlgo
,"compress-algo", 2, "@"},
534 { oCompressAlgo
, "compression-algo", 2, "@"}, /* Alias */
535 { oThrowKeyids
, "throw-keyid", 0, "@"},
536 { oThrowKeyids
, "throw-keyids", 0, "@"},
537 { oNoThrowKeyids
, "no-throw-keyid", 0, "@" },
538 { oNoThrowKeyids
, "no-throw-keyids", 0, "@" },
539 { oShowPhotos
, "show-photos", 0, "@" },
540 { oNoShowPhotos
, "no-show-photos", 0, "@" },
541 { oPhotoViewer
, "photo-viewer", 2, "@" },
542 { oSetNotation
, "set-notation", 2, "@" },
543 { oSetNotation
, "notation-data", 2, "@" }, /* Alias */
544 { oSigNotation
, "sig-notation", 2, "@" },
545 { oCertNotation
, "cert-notation", 2, "@" },
548 "@\n(See the man page for a complete listing of all commands and options)\n"
551 { 303, NULL
, 0, N_("@\nExamples:\n\n"
552 " -se -r Bob [file] sign and encrypt for user Bob\n"
553 " --clearsign [file] make a clear text signature\n"
554 " --detach-sign [file] make a detached signature\n"
555 " --list-keys [names] show keys\n"
556 " --fingerprint [names] show fingerprints\n" ) },
559 { aListOwnerTrust
, "list-ownertrust", 256, "@"}, /* deprecated */
560 { aPrintMDs
, "print-mds" , 256, "@"}, /* old */
561 { aListTrustDB
, "list-trustdb",0 , "@"},
563 /* { aListTrustPath, "list-trust-path",0, "@"}, */
564 { oKOption
, NULL
, 0, "@"},
565 { oPasswd
, "passphrase",2, "@" },
566 { oPasswdFD
, "passphrase-fd",1, "@" },
567 { oPasswdFile
, "passphrase-file",2, "@" },
568 { oCommandFD
, "command-fd",1, "@" },
569 { oCommandFile
, "command-file",2, "@" },
570 { oQuickRandom
, "quick-random", 0, "@"},
571 { oNoVerbose
, "no-verbose", 0, "@"},
572 { oTrustDBName
, "trustdb-name", 2, "@" },
573 { oNoSecmemWarn
, "no-secmem-warning", 0, "@" },
574 { oRequireSecmem
,"require-secmem", 0, "@" },
575 { oNoRequireSecmem
,"no-require-secmem", 0, "@" },
576 { oNoPermissionWarn
, "no-permission-warning", 0, "@" },
577 { oNoMDCWarn
, "no-mdc-warning", 0, "@" },
578 { oNoArmor
, "no-armor", 0, "@"},
579 { oNoArmor
, "no-armour", 0, "@"},
580 { oNoDefKeyring
, "no-default-keyring", 0, "@" },
581 { oNoGreeting
, "no-greeting", 0, "@" },
582 { oNoOptions
, "no-options", 0, "@" }, /* shortcut for --options /dev/null */
583 { oHomedir
, "homedir", 2, "@" }, /* defaults to "~/.gnupg" */
584 { oNoBatch
, "no-batch", 0, "@" },
585 { oWithColons
, "with-colons", 0, "@"},
586 { oWithKeyData
,"with-key-data", 0, "@"},
587 { aListKeys
, "list-key", 0, "@" }, /* alias */
588 { aListSigs
, "list-sig", 0, "@" }, /* alias */
589 { aCheckKeys
, "check-sig",0, "@" }, /* alias */
590 { oSkipVerify
, "skip-verify",0, "@" },
591 { oCompressKeys
, "compress-keys",0, "@"},
592 { oCompressSigs
, "compress-sigs",0, "@"},
593 { oDefCertLevel
, "default-cert-check-level", 1, "@"}, /* Old option */
594 { oAlwaysTrust
, "always-trust", 0, "@"},
595 { oTrustModel
, "trust-model", 2, "@"},
596 { oForceOwnertrust
, "force-ownertrust", 2, "@"},
597 { oSetFilename
, "set-filename", 2, "@" },
598 { oForYourEyesOnly
, "for-your-eyes-only", 0, "@" },
599 { oNoForYourEyesOnly
, "no-for-your-eyes-only", 0, "@" },
600 { oSetPolicyURL
, "set-policy-url", 2, "@" },
601 { oSigPolicyURL
, "sig-policy-url", 2, "@" },
602 { oCertPolicyURL
, "cert-policy-url", 2, "@" },
603 { oShowPolicyURL
, "show-policy-url", 0, "@" },
604 { oNoShowPolicyURL
, "no-show-policy-url", 0, "@" },
605 { oSigKeyserverURL
, "sig-keyserver-url", 2, "@" },
606 { oShowNotation
, "show-notation", 0, "@" },
607 { oNoShowNotation
, "no-show-notation", 0, "@" },
608 { oComment
, "comment", 2, "@" },
609 { oDefaultComment
, "default-comment", 0, "@" },
610 { oNoComments
, "no-comments", 0, "@" },
611 { oEmitVersion
, "emit-version", 0, "@"},
612 { oNoEmitVersion
, "no-emit-version", 0, "@"},
613 { oNoEmitVersion
, "no-version", 0, "@"}, /* alias */
614 { oNotDashEscaped
, "not-dash-escaped", 0, "@" },
615 { oEscapeFrom
, "escape-from-lines", 0, "@" },
616 { oNoEscapeFrom
, "no-escape-from-lines", 0, "@" },
617 { oLockOnce
, "lock-once", 0, "@" },
618 { oLockMultiple
, "lock-multiple", 0, "@" },
619 { oLockNever
, "lock-never", 0, "@" },
620 { oLoggerFD
, "logger-fd",1, "@" },
621 { oLoggerFile
, "log-file",2, "@" },
622 { oUseEmbeddedFilename
, "use-embedded-filename", 0, "@" },
623 { oNoUseEmbeddedFilename
, "no-use-embedded-filename", 0, "@" },
624 { oUtf8Strings
, "utf8-strings", 0, "@" },
625 { oNoUtf8Strings
, "no-utf8-strings", 0, "@" },
626 { oWithFingerprint
, "with-fingerprint", 0, "@" },
627 { oDisableCipherAlgo
, "disable-cipher-algo", 2, "@" },
628 { oDisablePubkeyAlgo
, "disable-pubkey-algo", 2, "@" },
629 { oAllowNonSelfsignedUID
, "allow-non-selfsigned-uid", 0, "@" },
630 { oNoAllowNonSelfsignedUID
, "no-allow-non-selfsigned-uid", 0, "@" },
631 { oAllowFreeformUID
, "allow-freeform-uid", 0, "@" },
632 { oNoAllowFreeformUID
, "no-allow-freeform-uid", 0, "@" },
633 { oNoLiteral
, "no-literal", 0, "@" },
634 { oSetFilesize
, "set-filesize", 20, "@" },
635 { oHonorHttpProxy
,"honor-http-proxy", 0, "@" },
636 { oFastListMode
,"fast-list-mode", 0, "@" },
637 { oFixedListMode
,"fixed-list-mode", 0, "@" },
638 { oListOnly
, "list-only", 0, "@"},
639 { oIgnoreTimeConflict
, "ignore-time-conflict", 0, "@" },
640 { oIgnoreValidFrom
, "ignore-valid-from", 0, "@" },
641 { oIgnoreCrcError
, "ignore-crc-error", 0,"@" },
642 { oIgnoreMDCError
, "ignore-mdc-error", 0,"@" },
643 { oShowSessionKey
, "show-session-key", 0, "@" },
644 { oOverrideSessionKey
, "override-session-key", 2, "@" },
645 { oNoRandomSeedFile
, "no-random-seed-file", 0, "@" },
646 { oAutoKeyRetrieve
, "auto-key-retrieve", 0, "@" },
647 { oNoAutoKeyRetrieve
, "no-auto-key-retrieve", 0, "@" },
648 { oNoSigCache
, "no-sig-cache", 0, "@" },
649 { oNoSigCreateCheck
, "no-sig-create-check", 0, "@" },
650 { oAutoCheckTrustDB
, "auto-check-trustdb", 0, "@"},
651 { oNoAutoCheckTrustDB
, "no-auto-check-trustdb", 0, "@"},
652 { oMergeOnly
, "merge-only", 0, "@" },
653 { oAllowSecretKeyImport
, "allow-secret-key-import", 0, "@" },
654 { oTryAllSecrets
, "try-all-secrets", 0, "@" },
655 { oEnableSpecialFilenames
, "enable-special-filenames", 0, "@" },
656 { oNoExpensiveTrustChecks
, "no-expensive-trust-checks", 0, "@" },
657 { aDeleteSecretAndPublicKeys
, "delete-secret-and-public-keys",256, "@" },
658 { aRebuildKeydbCaches
, "rebuild-keydb-caches", 256, "@"},
659 { oPreservePermissions
, "preserve-permissions", 0, "@"},
660 { oDefaultPreferenceList
, "default-preference-list", 2, "@"},
661 { oPersonalCipherPreferences
, "personal-cipher-preferences", 2, "@"},
662 { oPersonalDigestPreferences
, "personal-digest-preferences", 2, "@"},
663 { oPersonalCompressPreferences
, "personal-compress-preferences", 2, "@"},
664 /* Aliases. I constantly mistype these, and assume other people
666 { oPersonalCipherPreferences
, "personal-cipher-prefs", 2, "@"},
667 { oPersonalDigestPreferences
, "personal-digest-prefs", 2, "@"},
668 { oPersonalCompressPreferences
, "personal-compress-prefs", 2, "@"},
669 { oAgentProgram
, "agent-program", 2 , "@" },
670 { oDisplay
, "display", 2, "@" },
671 { oTTYname
, "ttyname", 2, "@" },
672 { oTTYtype
, "ttytype", 2, "@" },
673 { oLCctype
, "lc-ctype", 2, "@" },
674 { oLCmessages
, "lc-messages", 2, "@" },
675 { oGroup
, "group", 2, "@" },
676 { oUnGroup
, "ungroup", 2, "@" },
677 { oNoGroups
, "no-groups", 0, "@" },
678 { oStrict
, "strict", 0, "@" },
679 { oNoStrict
, "no-strict", 0, "@" },
680 { oMangleDosFilenames
, "mangle-dos-filenames", 0, "@" },
681 { oNoMangleDosFilenames
, "no-mangle-dos-filenames", 0, "@" },
682 { oEnableProgressFilter
, "enable-progress-filter", 0, "@" },
683 { oMultifile
, "multifile", 0, "@" },
684 { oKeyidFormat
, "keyid-format", 2, "@" },
685 { oExitOnStatusWriteError
, "exit-on-status-write-error", 0, "@" },
686 { oLimitCardInsertTries
, "limit-card-insert-tries", 1, "@"},
688 { oAllowMultisigVerification
, "allow-multisig-verification", 0, "@"},
689 { oEnableDSA2
, "enable-dsa2", 0, "@"},
690 { oDisableDSA2
, "disable-dsa2", 0, "@"},
692 /* These two are aliases to help users of the PGP command line
693 product use gpg with minimal pain. Many commands are common
694 already as they seem to have borrowed commands from us. Now
695 I'm returning the favor. */
696 { oLocalUser
, "sign-with", 2, "@" },
697 { oRecipient
, "user", 2, "@" },
698 { oRequireCrossCert
, "require-backsigs", 0, "@"},
699 { oRequireCrossCert
, "require-cross-certification", 0, "@"},
700 { oNoRequireCrossCert
, "no-require-backsigs", 0, "@"},
701 { oNoRequireCrossCert
, "no-require-cross-certification", 0, "@"},
702 { oAutoKeyLocate
, "auto-key-locate", 2, "@"},
703 { oNoAutoKeyLocate
, "no-auto-key-locate", 0, "@"},
708 #ifdef ENABLE_SELINUX_HACKS
709 #define ALWAYS_ADD_KEYRINGS 1
711 #define ALWAYS_ADD_KEYRINGS 0
715 int g10_errors_seen
= 0;
717 static int utf8_strings
= 0;
718 static int maybe_setuid
= 1;
720 static char *build_list( const char *text
, char letter
,
721 const char *(*mapf
)(int), int (*chkf
)(int) );
722 static void set_cmd( enum cmd_and_opt_values
*ret_cmd
,
723 enum cmd_and_opt_values new_cmd
);
724 static void print_mds( const char *fname
, int algo
);
725 static void add_notation_data( const char *string
, int which
);
726 static void add_policy_url( const char *string
, int which
);
727 static void add_keyserver_url( const char *string
, int which
);
728 static void emergency_cleanup (void);
732 my_strusage( int level
)
734 static char *digests
, *pubkeys
, *ciphers
, *zips
;
737 case 11: p
= "gpg (GnuPG)";
739 case 13: p
= VERSION
; break;
740 case 17: p
= PRINTABLE_OS_NAME
; break;
742 _("Please report bugs to <gnupg-bugs@gnu.org>.\n");
745 #ifdef IS_DEVELOPMENT_VERSION
747 p
="NOTE: THIS IS A DEVELOPMENT VERSION!";
750 p
="It is only intended for test purposes and should NOT be";
753 p
="used in a production environment or with production keys!";
759 _("Usage: gpg [options] [files] (-h for help)");
762 _("Syntax: gpg [options] [files]\n"
763 "sign, check, encrypt or decrypt\n"
764 "default operation depends on the input data\n");
767 case 31: p
= "\nHome: "; break;
769 case 32: p
= opt
.homedir
; break;
770 #else /* __riscos__ */
771 case 32: p
= make_filename(opt
.homedir
, NULL
); break;
772 #endif /* __riscos__ */
773 case 33: p
= _("\nSupported algorithms:\n"); break;
776 pubkeys
= build_list (_("Pubkey: "), 0,
778 openpgp_pk_test_algo
);
783 ciphers
= build_list(_("Cipher: "), 'S',
784 gcry_cipher_algo_name
,
785 openpgp_cipher_test_algo
);
790 digests
= build_list(_("Hash: "), 'H',
792 openpgp_md_test_algo
);
797 zips
= build_list(_("Compression: "),'Z',
798 compress_algo_to_string
,
799 check_compress_algo
);
810 build_list( const char *text
, char letter
,
811 const char * (*mapf
)(int), int (*chkf
)(int) )
815 size_t n
=strlen(text
)+2;
816 char *list
, *p
, *line
=NULL
;
819 gcry_control (GCRYCTL_INIT_SECMEM
, 0, 0); /* Drop setuid. */
821 for(i
=0; i
<= 110; i
++ )
822 if( !chkf(i
) && (s
=mapf(i
)) )
823 n
+= strlen(s
) + 7 + 2;
824 list
= xmalloc( 21 + n
); *list
= 0;
825 for(p
=NULL
, i
=0; i
<= 110; i
++ ) {
826 if( !chkf(i
) && (s
=mapf(i
)) ) {
828 p
= stpcpy( list
, text
);
832 p
= stpcpy( p
, ", ");
834 if(strlen(line
)>60) {
835 int spaces
=strlen(text
);
837 list
=xrealloc(list
,n
+spaces
+1);
838 /* realloc could move the block, so find the end again */
845 for(;spaces
;spaces
--)
850 if(opt
.verbose
&& letter
)
853 sprintf(num
," (%c%d)",letter
,i
);
859 p
= stpcpy(p
, "\n" );
867 #ifdef USE_SIMPLE_GETTEXT
868 set_gettext_file (PACKAGE_GT
, "Software\\GNU\\GnuPG");
871 setlocale (LC_ALL
, "");
872 bindtextdomain (PACKAGE_GT
, LOCALEDIR
);
873 textdomain (PACKAGE_GT
);
879 wrong_args( const char *text
)
881 fputs(_("usage: gpg [options] "),stderr
);
889 make_username( const char *string
)
895 p
= native_to_utf8( string
);
900 /* Setup the debugging. With a LEVEL of NULL only the active debug
901 flags are propagated to the subsystems. With LEVEL set, a specific
902 set of debug flags is set; thus overriding all flags already
905 set_debug (const char *level
)
909 else if (!strcmp (level
, "none"))
911 else if (!strcmp (level
, "basic"))
912 opt
.debug
= DBG_MEMSTAT_VALUE
;
913 else if (!strcmp (level
, "advanced"))
914 opt
.debug
= DBG_MEMSTAT_VALUE
|DBG_TRUST_VALUE
|DBG_EXTPROG_VALUE
;
915 else if (!strcmp (level
, "expert"))
916 opt
.debug
= (DBG_MEMSTAT_VALUE
|DBG_TRUST_VALUE
|DBG_EXTPROG_VALUE
917 |DBG_CACHE_VALUE
|DBG_FILTER_VALUE
|DBG_PACKET_VALUE
);
918 else if (!strcmp (level
, "guru"))
922 log_error (_("invalid debug-level `%s' given\n"), level
);
926 if (opt
.debug
& DBG_MEMORY_VALUE
)
927 memory_debug_mode
= 1;
928 if (opt
.debug
& DBG_MEMSTAT_VALUE
)
929 memory_stat_debug_mode
= 1;
930 if (opt
.debug
& DBG_MPI_VALUE
)
931 gcry_control (GCRYCTL_SET_DEBUG_FLAGS
, 2);
932 if (opt
.debug
& DBG_CIPHER_VALUE
)
933 gcry_control (GCRYCTL_SET_DEBUG_FLAGS
, 1);
934 if (opt
.debug
& DBG_IOBUF_VALUE
)
935 iobuf_debug_mode
= 1;
936 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
941 /* We need the home directory also in some other directories, so make
942 sure that both variables are always in sync. */
944 set_homedir (const char *dir
)
952 /* We set the screen dimensions for UI purposes. Do not allow screens
953 smaller than 80x24 for the sake of simplicity. */
955 set_screen_dimensions(void)
957 #ifndef HAVE_W32_SYSTEM
960 str
=getenv("COLUMNS");
962 opt
.screen_columns
=atoi(str
);
966 opt
.screen_lines
=atoi(str
);
969 if(opt
.screen_columns
<80 || opt
.screen_columns
>255)
970 opt
.screen_columns
=80;
972 if(opt
.screen_lines
<24 || opt
.screen_lines
>255)
977 /* Helper to open a file FNAME either for reading or writing to be
978 used with --status-file etc functions. Not generally useful but it
979 avoids the riscos specific functions and well some Windows people
980 might like it too. Prints an error message and returns -1 on
981 error. On success the file descriptor is returned. */
983 open_info_file (const char *fname
, int for_write
)
986 return riscos_fdopenfile (fname
, for_write
);
987 #elif defined (ENABLE_SELINUX_HACKS)
988 /* We can't allow these even when testing for a secured filename
989 because files to be secured might not yet been secured. This is
990 similar to the option file but in that case it is unlikely that
991 sensitive information may be retrieved by means of error
997 /* if (is_secured_filename (fname)) */
1000 /* errno = EPERM; */
1007 fd
= open (fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
1008 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
1010 fd
= open (fname
, O_RDONLY
| MY_O_BINARY
);
1012 while (fd
== -1 && errno
== EINTR
);
1015 log_error ( for_write
? _("can't create `%s': %s\n")
1016 : _("can't open `%s': %s\n"), fname
, strerror(errno
));
1023 set_cmd( enum cmd_and_opt_values
*ret_cmd
, enum cmd_and_opt_values new_cmd
)
1025 enum cmd_and_opt_values cmd
= *ret_cmd
;
1027 if( !cmd
|| cmd
== new_cmd
)
1029 else if( cmd
== aSign
&& new_cmd
== aEncr
)
1031 else if( cmd
== aEncr
&& new_cmd
== aSign
)
1033 else if( cmd
== aSign
&& new_cmd
== aSym
)
1035 else if( cmd
== aSym
&& new_cmd
== aSign
)
1037 else if( cmd
== aSym
&& new_cmd
== aEncr
)
1039 else if( cmd
== aEncr
&& new_cmd
== aSym
)
1041 else if( cmd
== aKMode
&& new_cmd
== aSym
)
1043 else if (cmd
== aSignEncr
&& new_cmd
== aSym
)
1045 else if (cmd
== aSignSym
&& new_cmd
== aEncr
)
1047 else if (cmd
== aEncrSym
&& new_cmd
== aSign
)
1049 else if( ( cmd
== aSign
&& new_cmd
== aClearsign
)
1050 || ( cmd
== aClearsign
&& new_cmd
== aSign
) )
1053 log_error(_("conflicting commands\n"));
1062 add_group(char *string
)
1065 struct groupitem
*item
;
1067 /* Break off the group name */
1068 name
=strsep(&string
,"=");
1071 log_error(_("no = sign found in group definition `%s'\n"),name
);
1075 trim_trailing_ws(name
,strlen(name
));
1077 /* Does this group already exist? */
1078 for(item
=opt
.grouplist
;item
;item
=item
->next
)
1079 if(strcasecmp(item
->name
,name
)==0)
1084 item
=xmalloc(sizeof(struct groupitem
));
1086 item
->next
=opt
.grouplist
;
1091 /* Break apart the values */
1092 while ((value
= strsep(&string
," \t")))
1095 add_to_strlist2(&item
->values
,value
,utf8_strings
);
1101 rm_group(char *name
)
1103 struct groupitem
*item
,*last
=NULL
;
1105 trim_trailing_ws(name
,strlen(name
));
1107 for(item
=opt
.grouplist
;item
;last
=item
,item
=item
->next
)
1109 if(strcasecmp(item
->name
,name
)==0)
1112 last
->next
=item
->next
;
1114 opt
.grouplist
=item
->next
;
1116 free_strlist(item
->values
);
1124 /* We need to check three things.
1126 0) The homedir. It must be x00, a directory, and owned by the
1129 1) The options/gpg.conf file. Okay unless it or its containing
1130 directory is group or other writable or not owned by us. Disable
1133 2) Extensions. Same as #1.
1135 Returns true if the item is unsafe. */
1137 check_permissions(const char *path
,int item
)
1139 #if defined(HAVE_STAT) && !defined(HAVE_DOSISH_SYSTEM)
1140 static int homedir_cache
=-1;
1142 struct stat statbuf
,dirbuf
;
1143 int homedir
=0,ret
=0,checkonly
=0;
1144 int perm
=0,own
=0,enc_dir_perm
=0,enc_dir_own
=0;
1146 if(opt
.no_perm_warn
)
1149 assert(item
==0 || item
==1 || item
==2);
1151 /* extensions may attach a path */
1152 if(item
==2 && path
[0]!=DIRSEP_C
)
1154 if(strchr(path
,DIRSEP_C
))
1155 tmppath
=make_filename(path
,NULL
);
1157 tmppath
=make_filename(GNUPG_LIBDIR
,path
,NULL
);
1160 tmppath
=xstrdup(path
);
1162 /* If the item is located in the homedir, but isn't the homedir,
1163 don't continue if we already checked the homedir itself. This is
1164 to avoid user confusion with an extra options file warning which
1165 could be rectified if the homedir itself had proper
1167 if(item
!=0 && homedir_cache
>-1
1168 && ascii_strncasecmp(opt
.homedir
,tmppath
,strlen(opt
.homedir
))==0)
1174 /* It's okay if the file or directory doesn't exist */
1175 if(stat(tmppath
,&statbuf
)!=0)
1181 /* Now check the enclosing directory. Theoretically, we could walk
1182 this test up to the root directory /, but for the sake of sanity,
1183 I'm stopping at one level down. */
1184 dir
=make_dirname(tmppath
);
1186 if(stat(dir
,&dirbuf
)!=0 || !S_ISDIR(dirbuf
.st_mode
))
1195 /* Assume failure */
1200 /* The homedir must be x00, a directory, and owned by the user. */
1202 if(S_ISDIR(statbuf
.st_mode
))
1204 if(statbuf
.st_uid
==getuid())
1206 if((statbuf
.st_mode
& (S_IRWXG
|S_IRWXO
))==0)
1217 else if(item
==1 || item
==2)
1219 /* The options or extension file. Okay unless it or its
1220 containing directory is group or other writable or not owned
1223 if(S_ISREG(statbuf
.st_mode
))
1225 if(statbuf
.st_uid
==getuid() || statbuf
.st_uid
==0)
1227 if((statbuf
.st_mode
& (S_IWGRP
|S_IWOTH
))==0)
1229 /* it's not writable, so make sure the enclosing
1230 directory is also not writable */
1231 if(dirbuf
.st_uid
==getuid() || dirbuf
.st_uid
==0)
1233 if((dirbuf
.st_mode
& (S_IWGRP
|S_IWOTH
))==0)
1243 /* it's writable, so the enclosing directory had
1244 better not let people get to it. */
1245 if(dirbuf
.st_uid
==getuid() || dirbuf
.st_uid
==0)
1247 if((dirbuf
.st_mode
& (S_IRWXG
|S_IRWXO
))==0)
1250 perm
=enc_dir_perm
=1; /* unclear which one to fix! */
1268 log_info(_("WARNING: unsafe ownership on"
1269 " homedir `%s'\n"),tmppath
);
1271 log_info(_("WARNING: unsafe ownership on"
1272 " configuration file `%s'\n"),tmppath
);
1274 log_info(_("WARNING: unsafe ownership on"
1275 " extension `%s'\n"),tmppath
);
1280 log_info(_("WARNING: unsafe permissions on"
1281 " homedir `%s'\n"),tmppath
);
1283 log_info(_("WARNING: unsafe permissions on"
1284 " configuration file `%s'\n"),tmppath
);
1286 log_info(_("WARNING: unsafe permissions on"
1287 " extension `%s'\n"),tmppath
);
1292 log_info(_("WARNING: unsafe enclosing directory ownership on"
1293 " homedir `%s'\n"),tmppath
);
1295 log_info(_("WARNING: unsafe enclosing directory ownership on"
1296 " configuration file `%s'\n"),tmppath
);
1298 log_info(_("WARNING: unsafe enclosing directory ownership on"
1299 " extension `%s'\n"),tmppath
);
1304 log_info(_("WARNING: unsafe enclosing directory permissions on"
1305 " homedir `%s'\n"),tmppath
);
1307 log_info(_("WARNING: unsafe enclosing directory permissions on"
1308 " configuration file `%s'\n"),tmppath
);
1310 log_info(_("WARNING: unsafe enclosing directory permissions on"
1311 " extension `%s'\n"),tmppath
);
1323 #endif /* HAVE_STAT && !HAVE_DOSISH_SYSTEM */
1330 print_algo_numbers(int (*checker
)(int))
1348 /* In the future, we can do all sorts of interesting configuration
1349 output here. For now, just give "group" as the Enigmail folks need
1350 it, and pubkey, cipher, hash, and compress as they may be useful
1353 list_config(char *items
)
1355 int show_all
=(items
==NULL
);
1358 if(!opt
.with_colons
)
1361 while(show_all
|| (name
=strsep(&items
," ")))
1365 if(show_all
|| ascii_strcasecmp(name
,"group")==0)
1367 struct groupitem
*iter
;
1369 for(iter
=opt
.grouplist
;iter
;iter
=iter
->next
)
1373 printf("cfg:group:");
1374 print_string(stdout
,iter
->name
,strlen(iter
->name
),':');
1377 for(sl
=iter
->values
;sl
;sl
=sl
->next
)
1379 print_string2(stdout
,sl
->d
,strlen(sl
->d
),':',';');
1390 if(show_all
|| ascii_strcasecmp(name
,"version")==0)
1392 printf("cfg:version:");
1393 print_string(stdout
,VERSION
,strlen(VERSION
),':');
1398 if(show_all
|| ascii_strcasecmp(name
,"pubkey")==0)
1400 printf("cfg:pubkey:");
1401 print_algo_numbers (openpgp_pk_test_algo
);
1406 if(show_all
|| ascii_strcasecmp(name
,"cipher")==0)
1408 printf("cfg:cipher:");
1409 print_algo_numbers(openpgp_cipher_test_algo
);
1415 || ascii_strcasecmp(name
,"digest")==0
1416 || ascii_strcasecmp(name
,"hash")==0)
1418 printf("cfg:digest:");
1419 print_algo_numbers(openpgp_md_test_algo
);
1424 if(show_all
|| ascii_strcasecmp(name
,"compress")==0)
1426 printf("cfg:compress:");
1427 print_algo_numbers(check_compress_algo
);
1432 if(show_all
|| ascii_strcasecmp(name
,"ccid-reader-id")==0)
1434 #if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB)
1435 char *p
, *p2
, *list
= ccid_get_reader_list ();
1437 for (p
=list
; p
&& (p2
= strchr (p
, '\n')); p
= p2
+1)
1440 printf("cfg:ccid-reader-id:%s\n", p
);
1451 log_error(_("unknown configuration item `%s'\n"),name
);
1456 /* List options and default values in the GPG Conf format. This is a
1457 new tool distributed with gnupg 1.9.x but we also want some limited
1458 support in older gpg versions. The output is the name of the
1459 configuration file and a list of options available for editing by
1462 gpgconf_list (const char *configfile
)
1464 /* The following definitions are taken from gnupg/tools/gpgconf-comp.c. */
1465 #define GC_OPT_FLAG_NONE 0UL
1466 #define GC_OPT_FLAG_DEFAULT (1UL << 4)
1468 printf ("gpgconf-gpg.conf:%lu:\"%s\n",
1469 GC_OPT_FLAG_DEFAULT
,configfile
?configfile
:"/dev/null");
1470 printf ("verbose:%lu:\n", GC_OPT_FLAG_NONE
);
1471 printf ("quiet:%lu:\n", GC_OPT_FLAG_NONE
);
1472 printf ("keyserver:%lu:\n", GC_OPT_FLAG_NONE
);
1473 printf ("reader-port:%lu:\n", GC_OPT_FLAG_NONE
);
1478 parse_subpacket_list(char *list
)
1481 byte subpackets
[128],i
;
1486 /* No arguments means all subpackets */
1487 memset(subpackets
+1,1,sizeof(subpackets
)-1);
1492 memset(subpackets
,0,sizeof(subpackets
));
1494 /* Merge with earlier copy */
1495 if(opt
.show_subpackets
)
1499 for(in
=opt
.show_subpackets
;*in
;in
++)
1501 if(*in
>127 || *in
<1)
1504 if(!subpackets
[*in
])
1510 while((tok
=strsep(&list
," ,")))
1525 xfree(opt
.show_subpackets
);
1526 opt
.show_subpackets
=xmalloc(count
+1);
1527 opt
.show_subpackets
[count
--]=0;
1529 for(i
=1;i
<128 && count
>=0;i
++)
1531 opt
.show_subpackets
[count
--]=i
;
1538 parse_list_options(char *str
)
1540 char *subpackets
=""; /* something that isn't NULL */
1541 struct parse_options lopts
[]=
1543 {"show-photos",LIST_SHOW_PHOTOS
,NULL
,
1544 N_("display photo IDs during key listings")},
1545 {"show-policy-urls",LIST_SHOW_POLICY_URLS
,NULL
,
1546 N_("show policy URLs during signature listings")},
1547 {"show-notations",LIST_SHOW_NOTATIONS
,NULL
,
1548 N_("show all notations during signature listings")},
1549 {"show-std-notations",LIST_SHOW_STD_NOTATIONS
,NULL
,
1550 N_("show IETF standard notations during signature listings")},
1551 {"show-standard-notations",LIST_SHOW_STD_NOTATIONS
,NULL
,
1553 {"show-user-notations",LIST_SHOW_USER_NOTATIONS
,NULL
,
1554 N_("show user-supplied notations during signature listings")},
1555 {"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS
,NULL
,
1556 N_("show preferred keyserver URLs during signature listings")},
1557 {"show-uid-validity",LIST_SHOW_UID_VALIDITY
,NULL
,
1558 N_("show user ID validity during key listings")},
1559 {"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS
,NULL
,
1560 N_("show revoked and expired user IDs in key listings")},
1561 {"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS
,NULL
,
1562 N_("show revoked and expired subkeys in key listings")},
1563 {"show-keyring",LIST_SHOW_KEYRING
,NULL
,
1564 N_("show the keyring name in key listings")},
1565 {"show-sig-expire",LIST_SHOW_SIG_EXPIRE
,NULL
,
1566 N_("show expiration dates during signature listings")},
1567 {"show-sig-subpackets",LIST_SHOW_SIG_SUBPACKETS
,NULL
,
1572 /* C99 allows for non-constant initializers, but we'd like to
1573 compile everywhere, so fill in the show-sig-subpackets argument
1574 here. Note that if the parse_options array changes, we'll have
1575 to change the subscript here. */
1576 lopts
[12].value
=&subpackets
;
1578 if(parse_options(str
,&opt
.list_options
,lopts
,1))
1580 if(opt
.list_options
&LIST_SHOW_SIG_SUBPACKETS
)
1582 /* Unset so users can pass multiple lists in. */
1583 opt
.list_options
&=~LIST_SHOW_SIG_SUBPACKETS
;
1584 if(!parse_subpacket_list(subpackets
))
1587 else if(subpackets
==NULL
&& opt
.show_subpackets
)
1589 /* User did 'no-show-subpackets' */
1590 xfree(opt
.show_subpackets
);
1591 opt
.show_subpackets
=NULL
;
1601 /* Collapses argc/argv into a single string that must be freed */
1603 collapse_args(int argc
,char *argv
[])
1606 int i
,first
=1,len
=0;
1610 len
+=strlen(argv
[i
])+2;
1611 str
=xrealloc(str
,len
);
1620 strcat(str
,argv
[i
]);
1627 parse_trust_model(const char *model
)
1629 if(ascii_strcasecmp(model
,"pgp")==0)
1630 opt
.trust_model
=TM_PGP
;
1631 else if(ascii_strcasecmp(model
,"classic")==0)
1632 opt
.trust_model
=TM_CLASSIC
;
1633 else if(ascii_strcasecmp(model
,"always")==0)
1634 opt
.trust_model
=TM_ALWAYS
;
1635 else if(ascii_strcasecmp(model
,"direct")==0)
1636 opt
.trust_model
=TM_DIRECT
;
1637 else if(ascii_strcasecmp(model
,"auto")==0)
1638 opt
.trust_model
=TM_AUTO
;
1640 log_error("unknown trust model `%s'\n",model
);
1644 main (int argc
, char **argv
)
1646 ARGPARSE_ARGS pargs
;
1654 STRLIST sl
, remusr
= NULL
, locusr
=NULL
;
1655 STRLIST nrings
=NULL
, sec_nrings
=NULL
;
1656 armor_filter_context_t afx
;
1657 int detached_sig
= 0;
1658 FILE *configfp
= NULL
;
1659 char *configname
= NULL
;
1660 char *save_configname
= NULL
;
1661 unsigned configlineno
;
1662 int parse_debug
= 0;
1663 int default_config
= 1;
1664 int default_keyring
= 1;
1667 char *logfile
= NULL
;
1668 int use_random_seed
= 1;
1669 enum cmd_and_opt_values cmd
= 0;
1670 const char *debug_level
= NULL
;
1671 const char *trustdb_name
= NULL
;
1672 char *def_cipher_string
= NULL
;
1673 char *def_digest_string
= NULL
;
1674 char *compress_algo_string
= NULL
;
1675 char *cert_digest_string
= NULL
;
1676 char *s2k_cipher_string
= NULL
;
1677 char *s2k_digest_string
= NULL
;
1678 char *pers_cipher_list
= NULL
;
1679 char *pers_digest_list
= NULL
;
1680 char *pers_compress_list
= NULL
;
1684 int with_fpr
= 0; /* make an option out of --fingerprint */
1685 int any_explicit_recipient
= 0;
1686 int require_secmem
=0,got_secmem
=0;
1690 #endif /* __riscos__ */
1693 /* Please note that we may running SUID(ROOT), so be very CAREFUL
1694 when adding any stuff between here and the call to
1695 secmem_init() somewhere after the option parsing. */
1698 set_strusage (my_strusage
);
1699 gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN
);
1700 /* We don't need any locking in libgcrypt unless we use any kind of
1702 gcry_control (GCRYCTL_DISABLE_INTERNAL_LOCKING
);
1703 log_set_prefix ("gpg", 1);
1705 /* Check that the libraries are suitable. Do it right here because the
1706 option parsing may need services of the library. */
1707 if (!gcry_check_version (NEED_LIBGCRYPT_VERSION
) )
1709 log_fatal ( _("libgcrypt is too old (need %s, have %s)\n"),
1710 NEED_LIBGCRYPT_VERSION
, gcry_check_version (NULL
) );
1713 /* Put random number into secure memory */
1714 gcry_control (GCRYCTL_USE_SECURE_RNDPOOL
);
1716 may_coredump
= disable_core_dumps();
1718 gnupg_init_signals (0, emergency_cleanup
);
1720 create_dotlock(NULL
); /* Register locking cleanup. */
1724 opt
.command_fd
= -1; /* no command fd */
1725 opt
.compress_level
= -1; /* defaults to standard compress level */
1726 opt
.bz2_compress_level
= -1; /* defaults to standard compress level */
1727 /* note: if you change these lines, look at oOpenPGP */
1728 opt
.def_cipher_algo
= 0;
1729 opt
.def_digest_algo
= 0;
1730 opt
.cert_digest_algo
= 0;
1731 opt
.compress_algo
= -1; /* defaults to DEFAULT_COMPRESS_ALGO */
1732 opt
.s2k_mode
= 3; /* iterated+salted */
1734 opt
.s2k_cipher_algo
= CIPHER_ALGO_CAST5
;
1736 opt
.s2k_cipher_algo
= CIPHER_ALGO_3DES
;
1738 opt
.completes_needed
= 1;
1739 opt
.marginals_needed
= 3;
1740 opt
.max_cert_depth
= 5;
1741 opt
.pgp2_workarounds
= 1;
1742 opt
.force_v3_sigs
= 1;
1743 opt
.escape_from
= 1;
1744 opt
.import_options
=IMPORT_SK2PK
;
1745 opt
.export_options
=EXPORT_ATTRIBUTES
;
1746 opt
.keyserver_options
.import_options
=IMPORT_REPAIR_PKS_SUBKEY_BUG
;
1747 opt
.keyserver_options
.export_options
=EXPORT_ATTRIBUTES
;
1748 opt
.keyserver_options
.options
=
1749 KEYSERVER_HONOR_KEYSERVER_URL
|KEYSERVER_HONOR_PKA_RECORD
;
1751 VERIFY_SHOW_POLICY_URLS
|VERIFY_SHOW_STD_NOTATIONS
|VERIFY_SHOW_KEYSERVER_URLS
;
1752 opt
.trust_model
=TM_AUTO
;
1753 opt
.mangle_dos_filenames
=0;
1754 opt
.min_cert_level
=2;
1755 set_screen_dimensions();
1756 opt
.keyid_format
=KF_SHORT
;
1758 opt
.def_sig_expire
="0";
1759 opt
.def_cert_expire
="0";
1760 set_homedir ( default_homedir () );
1762 /* Check whether we have a config file on the command line. */
1767 pargs
.flags
= 1|(1<<6); /* do not remove the args, ignore version */
1768 while( arg_parse( &pargs
, opts
) ) {
1769 if( pargs
.r_opt
== oDebug
|| pargs
.r_opt
== oDebugAll
)
1771 else if( pargs
.r_opt
== oOptions
) {
1772 /* yes there is one, so we do not try the default one, but
1773 * read the option file when it is encountered at the commandline
1777 else if( pargs
.r_opt
== oNoOptions
)
1778 default_config
= 0; /* --no-options */
1779 else if( pargs
.r_opt
== oHomedir
)
1780 set_homedir ( pargs
.r
.ret_str
);
1781 else if( pargs
.r_opt
== oNoPermissionWarn
)
1783 else if (pargs
.r_opt
== oStrict
)
1788 else if (pargs
.r_opt
== oNoStrict
)
1795 #ifdef HAVE_DOSISH_SYSTEM
1796 if ( strchr (opt
.homedir
,'\\') ) {
1797 char *d
, *buf
= xmalloc (strlen (opt
.homedir
)+1);
1798 const char *s
= opt
.homedir
;
1799 for (d
=buf
,s
=opt
.homedir
; *s
; s
++)
1801 *d
++ = *s
== '\\'? '/': *s
;
1802 #ifdef HAVE_W32_SYSTEM
1803 if (s
[1] && IsDBCSLeadByte (*s
))
1812 /* Initialize the secure memory. */
1813 gcry_control (GCRYCTL_INIT_SECMEM
, 32768, 0);
1814 got_secmem
= 1; /* FIXME: gcry_control should return an indicator. */
1815 #if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
1816 /* There should be no way to get to this spot while still carrying
1817 setuid privs. Just in case, bomb out if we are. */
1818 if(getuid()!=geteuid())
1823 /* Okay, we are now working under our real uid */
1825 /* malloc hooks go here ... */
1826 assuan_set_malloc_hooks (gcry_malloc
, gcry_realloc
, gcry_free
);
1829 set_native_charset (NULL
); /* Try to auto set the character set */
1831 /* Try for a version specific config file first */
1832 if( default_config
)
1834 char *name
=xstrdup("gpg" EXTSEP_S
"conf-" SAFE_VERSION
);
1835 char *ver
=&name
[strlen("gpg" EXTSEP_S
"conf-")];
1846 if((tok
=strrchr(ver
,SAFE_VERSION_DASH
)))
1848 else if((tok
=strrchr(ver
,SAFE_VERSION_DOT
)))
1854 configname
= make_filename(opt
.homedir
,name
,NULL
);
1856 while(access(configname
,R_OK
));
1861 configname
=make_filename(opt
.homedir
, "gpg" EXTSEP_S
"conf", NULL
);
1862 if (!access (configname
, R_OK
))
1863 { /* Print a warning when both config files are present. */
1864 char *p
= make_filename(opt
.homedir
, "options", NULL
);
1865 if (!access (p
, R_OK
))
1866 log_info (_("NOTE: old default options file `%s' ignored\n"), p
);
1870 { /* Keep on using the old default one. */
1872 configname
= make_filename(opt
.homedir
, "options", NULL
);
1879 pargs
.flags
= 1; /* do not remove the args */
1881 /* By this point we have a homedir, and cannot change it. */
1882 check_permissions(opt
.homedir
,0);
1886 if(check_permissions(configname
,1))
1888 /* If any options file is unsafe, then disable any external
1889 programs for keyserver calls or photo IDs. Since the
1890 external program to call is set in the options file, a
1891 unsafe options file can lead to an arbitrary program
1898 configfp
= fopen( configname
, "r" );
1899 if (configfp
&& is_secured_file (fileno (configfp
)))
1906 if( default_config
) {
1908 log_info(_("NOTE: no default option file `%s'\n"),
1912 log_error(_("option file `%s': %s\n"),
1913 configname
, strerror(errno
) );
1916 xfree(configname
); configname
= NULL
;
1918 if( parse_debug
&& configname
)
1919 log_info(_("reading options from `%s'\n"), configname
);
1923 while( optfile_parse( configfp
, configname
, &configlineno
,
1926 switch( pargs
.r_opt
)
1940 set_cmd (&cmd
, pargs
.r_opt
);
1942 case aListKeys
: set_cmd( &cmd
, aListKeys
); break;
1943 case aListSigs
: set_cmd( &cmd
, aListSigs
); break;
1944 case aExportSecret
: set_cmd( &cmd
, aExportSecret
); break;
1945 case aExportSecretSub
: set_cmd( &cmd
, aExportSecretSub
); break;
1946 case aDeleteSecretKeys
:
1947 set_cmd( &cmd
, aDeleteSecretKeys
);
1950 case aDeleteSecretAndPublicKeys
:
1951 set_cmd( &cmd
, aDeleteSecretAndPublicKeys
);
1954 case aDeleteKeys
: set_cmd( &cmd
, aDeleteKeys
); greeting
=1; break;
1956 case aDetachedSign
: detached_sig
= 1; set_cmd( &cmd
, aSign
); break;
1957 case aSym
: set_cmd( &cmd
, aSym
); break;
1959 case aDecryptFiles
: multifile
=1; /* fall through */
1960 case aDecrypt
: set_cmd( &cmd
, aDecrypt
); break;
1962 case aEncrFiles
: multifile
=1; /* fall through */
1963 case aEncr
: set_cmd( &cmd
, aEncr
); break;
1965 case aVerifyFiles
: multifile
=1; /* fall through */
1966 case aVerify
: set_cmd( &cmd
, aVerify
); break;
1968 case aSign
: set_cmd( &cmd
, aSign
); break;
1969 case aKeygen
: set_cmd( &cmd
, aKeygen
); greeting
=1; break;
1970 case aSignKey
: set_cmd( &cmd
, aSignKey
); break;
1971 case aLSignKey
: set_cmd( &cmd
, aLSignKey
); break;
1972 case aStore
: set_cmd( &cmd
, aStore
); break;
1973 case aEditKey
: set_cmd( &cmd
, aEditKey
); greeting
=1; break;
1974 case aClearsign
: set_cmd( &cmd
, aClearsign
); break;
1975 case aGenRevoke
: set_cmd( &cmd
, aGenRevoke
); break;
1976 case aDesigRevoke
: set_cmd( &cmd
, aDesigRevoke
); break;
1977 case aPrimegen
: set_cmd( &cmd
, aPrimegen
); break;
1978 case aGenRandom
: set_cmd( &cmd
, aGenRandom
); break;
1979 case aPrintMD
: set_cmd( &cmd
, aPrintMD
); break;
1980 case aPrintMDs
: set_cmd( &cmd
, aPrintMDs
); break;
1981 case aListTrustDB
: set_cmd( &cmd
, aListTrustDB
); break;
1982 case aCheckTrustDB
: set_cmd( &cmd
, aCheckTrustDB
); break;
1983 case aUpdateTrustDB
: set_cmd( &cmd
, aUpdateTrustDB
); break;
1984 case aFixTrustDB
: set_cmd( &cmd
, aFixTrustDB
); break;
1985 case aListTrustPath
: set_cmd( &cmd
, aListTrustPath
); break;
1986 case aDeArmor
: set_cmd( &cmd
, aDeArmor
); break;
1987 case aEnArmor
: set_cmd( &cmd
, aEnArmor
); break;
1988 case aListOwnerTrust
:
1989 deprecated_warning(configname
,configlineno
,
1990 "--list-ownertrust","--export-ownertrust","");
1991 case aExportOwnerTrust
: set_cmd( &cmd
, aExportOwnerTrust
); break;
1992 case aImportOwnerTrust
: set_cmd( &cmd
, aImportOwnerTrust
); break;
1993 case aRebuildKeydbCaches
: set_cmd( &cmd
, aRebuildKeydbCaches
); break;
1995 case oArmor
: opt
.armor
= 1; opt
.no_armor
=0; break;
1996 case oOutput
: opt
.outfile
= pargs
.r
.ret_str
; break;
1997 case oMaxOutput
: opt
.max_output
= pargs
.r
.ret_ulong
; break;
1998 case oQuiet
: opt
.quiet
= 1; break;
1999 case oNoTTY
: tty_no_terminal(1); break;
2000 case oDryRun
: opt
.dry_run
= 1; break;
2001 case oInteractive
: opt
.interactive
= 1; break;
2004 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
2005 opt
.list_options
|=LIST_SHOW_UNUSABLE_UIDS
;
2006 opt
.list_options
|=LIST_SHOW_UNUSABLE_SUBKEYS
;
2008 case oKOption
: set_cmd( &cmd
, aKMode
); break;
2010 case oBatch
: opt
.batch
= 1; nogreeting
= 1; break;
2014 #else /* __riscos__ */
2016 riscos_not_implemented("use-agent");
2017 #endif /* __riscos__ */
2019 case oNoUseAgent
: opt
.use_agent
= 0; break;
2020 case oGpgAgentInfo
: opt
.gpg_agent_info
= pargs
.r
.ret_str
; break;
2021 case oAnswerYes
: opt
.answer_yes
= 1; break;
2022 case oAnswerNo
: opt
.answer_no
= 1; break;
2023 case oKeyring
: append_to_strlist( &nrings
, pargs
.r
.ret_str
); break;
2024 case oPrimaryKeyring
:
2025 sl
=append_to_strlist( &nrings
, pargs
.r
.ret_str
);
2029 deprecated_warning(configname
,configlineno
,"--show-keyring",
2030 "--list-options ","show-keyring");
2031 opt
.list_options
|=LIST_SHOW_KEYRING
;
2034 case oDebug
: opt
.debug
|= pargs
.r
.ret_ulong
; break;
2035 case oDebugAll
: opt
.debug
= ~0; break;
2036 case oDebugLevel
: debug_level
= pargs
.r
.ret_str
; break;
2039 set_status_fd( iobuf_translate_file_handle (pargs
.r
.ret_int
, 1) );
2042 set_status_fd ( open_info_file (pargs
.r
.ret_str
, 1) );
2045 set_attrib_fd(iobuf_translate_file_handle (pargs
.r
.ret_int
, 1));
2047 case oAttributeFile
:
2048 set_attrib_fd ( open_info_file (pargs
.r
.ret_str
, 1) );
2051 log_set_fd (iobuf_translate_file_handle (pargs
.r
.ret_int
, 1));
2054 logfile
= pargs
.r
.ret_str
;
2057 case oWithFingerprint
:
2058 opt
.with_fingerprint
= 1;
2059 with_fpr
=1; /*fall thru*/
2060 case oFingerprint
: opt
.fingerprint
++; break;
2061 case oSecretKeyring
:
2062 append_to_strlist( &sec_nrings
, pargs
.r
.ret_str
);
2065 /* config files may not be nested (silently ignore them) */
2068 configname
= xstrdup(pargs
.r
.ret_str
);
2072 case oNoArmor
: opt
.no_armor
=1; opt
.armor
=0; break;
2073 case oNoDefKeyring
: default_keyring
= 0; break;
2074 case oNoGreeting
: nogreeting
= 1; break;
2077 gcry_control (GCRYCTL_SET_VERBOSITY
, (int)opt
.verbose
);
2080 /* Disabled for now:
2081 case oQuickRandom: quick_random_gen(1); break;*/
2082 case oEmitVersion
: opt
.no_version
=0; break;
2083 case oNoEmitVersion
: opt
.no_version
=1; break;
2084 case oCompletesNeeded
: opt
.completes_needed
= pargs
.r
.ret_int
; break;
2085 case oMarginalsNeeded
: opt
.marginals_needed
= pargs
.r
.ret_int
; break;
2086 case oMaxCertDepth
: opt
.max_cert_depth
= pargs
.r
.ret_int
; break;
2087 case oTrustDBName
: trustdb_name
= pargs
.r
.ret_str
; break;
2088 case oDefaultKey
: opt
.def_secret_key
= pargs
.r
.ret_str
; break;
2090 if( *pargs
.r
.ret_str
)
2091 opt
.def_recipient
= make_username(pargs
.r
.ret_str
);
2093 case oDefRecipientSelf
:
2094 xfree(opt
.def_recipient
); opt
.def_recipient
= NULL
;
2095 opt
.def_recipient_self
= 1;
2097 case oNoDefRecipient
:
2098 xfree(opt
.def_recipient
); opt
.def_recipient
= NULL
;
2099 opt
.def_recipient_self
= 0;
2101 case oNoOptions
: opt
.no_homedir_creation
= 1; break; /* no-options */
2102 case oHomedir
: break;
2103 case oNoBatch
: opt
.batch
= 0; break;
2104 case oWithKeyData
: opt
.with_key_data
=1; /* fall thru */
2105 case oWithColons
: opt
.with_colons
=':'; break;
2107 case oSkipVerify
: opt
.skip_verify
=1; break;
2108 case oCompressKeys
: opt
.compress_keys
= 1; break;
2109 case aListSecretKeys
: set_cmd( &cmd
, aListSecretKeys
); break;
2110 /* There are many programs (like mutt) that call gpg with
2111 --always-trust so keep this option around for a long
2113 case oAlwaysTrust
: opt
.trust_model
=TM_ALWAYS
; break;
2115 parse_trust_model(pargs
.r
.ret_str
);
2117 case oForceOwnertrust
:
2118 log_info(_("NOTE: %s is not for normal use!\n"),
2119 "--force-ownertrust");
2120 opt
.force_ownertrust
=string_to_trust_value(pargs
.r
.ret_str
);
2121 if(opt
.force_ownertrust
==-1)
2123 log_error("invalid ownertrust `%s'\n",pargs
.r
.ret_str
);
2124 opt
.force_ownertrust
=0;
2127 case oLoadExtension
:
2129 #if defined(USE_DYNAMIC_LINKING) || defined(_WIN32)
2130 if(check_permissions(pargs
.r
.ret_str
,2))
2131 log_info(_("cipher extension `%s' not loaded due to"
2132 " unsafe permissions\n"),pargs
.r
.ret_str
);
2134 register_cipher_extension(orig_argc
? *orig_argv
:NULL
,
2137 #else /* __riscos__ */
2138 riscos_not_implemented("load-extension");
2139 #endif /* __riscos__ */
2142 opt
.compliance
= CO_RFC1991
;
2143 opt
.force_v4_certs
= 0;
2144 opt
.escape_from
= 1;
2148 /* TODO: When 2440bis becomes a RFC, set new values for
2151 opt
.compliance
= CO_RFC2440
;
2152 opt
.allow_non_selfsigned_uid
= 1;
2153 opt
.allow_freeform_uid
= 1;
2154 opt
.pgp2_workarounds
= 0;
2155 opt
.escape_from
= 0;
2156 opt
.force_v3_sigs
= 0;
2157 opt
.compress_keys
= 0; /* not mandated, but we do it */
2158 opt
.compress_sigs
= 0; /* ditto. */
2159 opt
.not_dash_escaped
= 0;
2160 opt
.def_cipher_algo
= 0;
2161 opt
.def_digest_algo
= 0;
2162 opt
.cert_digest_algo
= 0;
2163 opt
.compress_algo
= -1;
2164 opt
.s2k_mode
= 3; /* iterated+salted */
2165 opt
.s2k_digest_algo
= DIGEST_ALGO_SHA1
;
2166 opt
.s2k_cipher_algo
= CIPHER_ALGO_3DES
;
2168 case oPGP2
: opt
.compliance
= CO_PGP2
; break;
2169 case oPGP6
: opt
.compliance
= CO_PGP6
; break;
2170 case oPGP7
: opt
.compliance
= CO_PGP7
; break;
2171 case oPGP8
: opt
.compliance
= CO_PGP8
; break;
2172 case oGnuPG
: opt
.compliance
= CO_GNUPG
; break;
2173 case oCompressSigs
: opt
.compress_sigs
= 1; break;
2174 case oRFC2440Text
: opt
.rfc2440_text
=1; break;
2175 case oNoRFC2440Text
: opt
.rfc2440_text
=0; break;
2178 opt
.set_filename
= pargs
.r
.ret_str
;
2180 opt
.set_filename
= native_to_utf8(pargs
.r
.ret_str
);
2182 case oForYourEyesOnly
: eyes_only
= 1; break;
2183 case oNoForYourEyesOnly
: eyes_only
= 0; break;
2185 add_policy_url(pargs
.r
.ret_str
,0);
2186 add_policy_url(pargs
.r
.ret_str
,1);
2188 case oSigPolicyURL
: add_policy_url(pargs
.r
.ret_str
,0); break;
2189 case oCertPolicyURL
: add_policy_url(pargs
.r
.ret_str
,1); break;
2190 case oShowPolicyURL
:
2191 deprecated_warning(configname
,configlineno
,"--show-policy-url",
2192 "--list-options ","show-policy-urls");
2193 deprecated_warning(configname
,configlineno
,"--show-policy-url",
2194 "--verify-options ","show-policy-urls");
2195 opt
.list_options
|=LIST_SHOW_POLICY_URLS
;
2196 opt
.verify_options
|=VERIFY_SHOW_POLICY_URLS
;
2198 case oNoShowPolicyURL
:
2199 deprecated_warning(configname
,configlineno
,"--no-show-policy-url",
2200 "--list-options ","no-show-policy-urls");
2201 deprecated_warning(configname
,configlineno
,"--no-show-policy-url",
2202 "--verify-options ","no-show-policy-urls");
2203 opt
.list_options
&=~LIST_SHOW_POLICY_URLS
;
2204 opt
.verify_options
&=~VERIFY_SHOW_POLICY_URLS
;
2206 case oSigKeyserverURL
: add_keyserver_url(pargs
.r
.ret_str
,0); break;
2207 case oUseEmbeddedFilename
:
2208 opt
.flags
.use_embedded_filename
=1;
2210 case oNoUseEmbeddedFilename
:
2211 opt
.flags
.use_embedded_filename
=0;
2214 if(pargs
.r
.ret_str
[0])
2215 append_to_strlist(&opt
.comments
,pargs
.r
.ret_str
);
2217 case oDefaultComment
:
2218 deprecated_warning(configname
,configlineno
,
2219 "--default-comment","--no-comments","");
2222 free_strlist(opt
.comments
);
2225 case oThrowKeyids
: opt
.throw_keyid
= 1; break;
2226 case oNoThrowKeyids
: opt
.throw_keyid
= 0; break;
2228 deprecated_warning(configname
,configlineno
,"--show-photos",
2229 "--list-options ","show-photos");
2230 deprecated_warning(configname
,configlineno
,"--show-photos",
2231 "--verify-options ","show-photos");
2232 opt
.list_options
|=LIST_SHOW_PHOTOS
;
2233 opt
.verify_options
|=VERIFY_SHOW_PHOTOS
;
2236 deprecated_warning(configname
,configlineno
,"--no-show-photos",
2237 "--list-options ","no-show-photos");
2238 deprecated_warning(configname
,configlineno
,"--no-show-photos",
2239 "--verify-options ","no-show-photos");
2240 opt
.list_options
&=~LIST_SHOW_PHOTOS
;
2241 opt
.verify_options
&=~VERIFY_SHOW_PHOTOS
;
2243 case oPhotoViewer
: opt
.photo_viewer
= pargs
.r
.ret_str
; break;
2244 case oForceV3Sigs
: opt
.force_v3_sigs
= 1; break;
2245 case oNoForceV3Sigs
: opt
.force_v3_sigs
= 0; break;
2246 case oForceV4Certs
: opt
.force_v4_certs
= 1; break;
2247 case oNoForceV4Certs
: opt
.force_v4_certs
= 0; break;
2248 case oForceMDC
: opt
.force_mdc
= 1; break;
2249 case oNoForceMDC
: opt
.force_mdc
= 0; break;
2250 case oDisableMDC
: opt
.disable_mdc
= 1; break;
2251 case oNoDisableMDC
: opt
.disable_mdc
= 0; break;
2252 case oS2KMode
: opt
.s2k_mode
= pargs
.r
.ret_int
; break;
2253 case oS2KDigest
: s2k_digest_string
= xstrdup(pargs
.r
.ret_str
); break;
2254 case oS2KCipher
: s2k_cipher_string
= xstrdup(pargs
.r
.ret_str
); break;
2255 case oSimpleSKChecksum
: opt
.simple_sk_checksum
= 1; break;
2256 case oNoEncryptTo
: opt
.no_encrypt_to
= 1; break;
2257 case oEncryptTo
: /* store the recipient in the second list */
2258 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2261 case oHiddenEncryptTo
: /* store the recipient in the second list */
2262 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2265 case oRecipient
: /* store the recipient */
2266 add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2267 any_explicit_recipient
= 1;
2269 case oHiddenRecipient
: /* store the recipient with a flag */
2270 sl
= add_to_strlist2( &remusr
, pargs
.r
.ret_str
, utf8_strings
);
2272 any_explicit_recipient
= 1;
2274 case oTextmodeShort
: opt
.textmode
= 2; break;
2275 case oTextmode
: opt
.textmode
=1; break;
2276 case oNoTextmode
: opt
.textmode
=0; break;
2277 case oExpert
: opt
.expert
= 1; break;
2278 case oNoExpert
: opt
.expert
= 0; break;
2280 if(*pargs
.r
.ret_str
!='\0')
2282 if(parse_expire_string(pargs
.r
.ret_str
)==(u32
)-1)
2283 log_error(_("`%s' is not a valid signature expiration\n"),
2286 opt
.def_sig_expire
=pargs
.r
.ret_str
;
2289 case oAskSigExpire
: opt
.ask_sig_expire
= 1; break;
2290 case oNoAskSigExpire
: opt
.ask_sig_expire
= 0; break;
2291 case oDefCertExpire
:
2292 if(*pargs
.r
.ret_str
!='\0')
2294 if(parse_expire_string(pargs
.r
.ret_str
)==(u32
)-1)
2295 log_error(_("`%s' is not a valid signature expiration\n"),
2298 opt
.def_cert_expire
=pargs
.r
.ret_str
;
2301 case oAskCertExpire
: opt
.ask_cert_expire
= 1; break;
2302 case oNoAskCertExpire
: opt
.ask_cert_expire
= 0; break;
2303 case oDefCertLevel
: opt
.def_cert_level
=pargs
.r
.ret_int
; break;
2304 case oMinCertLevel
: opt
.min_cert_level
=pargs
.r
.ret_int
; break;
2305 case oAskCertLevel
: opt
.ask_cert_level
= 1; break;
2306 case oNoAskCertLevel
: opt
.ask_cert_level
= 0; break;
2307 case oLocalUser
: /* store the local users */
2308 add_to_strlist2( &locusr
, pargs
.r
.ret_str
, utf8_strings
);
2311 /* this is the -z command line option */
2312 opt
.compress_level
= opt
.bz2_compress_level
= pargs
.r
.ret_int
;
2314 case oCompressLevel
: opt
.compress_level
= pargs
.r
.ret_int
; break;
2315 case oBZ2CompressLevel
: opt
.bz2_compress_level
= pargs
.r
.ret_int
; break;
2316 case oBZ2DecompressLowmem
: opt
.bz2_decompress_lowmem
=1; break;
2318 set_passphrase_from_string(pargs
.r
.ret_str
);
2321 pwfd
= iobuf_translate_file_handle (pargs
.r
.ret_int
, 0);
2325 pwfd
= open_info_file (pargs
.r
.ret_str
, 0);
2328 opt
.command_fd
= iobuf_translate_file_handle (pargs
.r
.ret_int
, 0);
2331 opt
.command_fd
= open_info_file (pargs
.r
.ret_str
, 0);
2334 def_cipher_string
= xstrdup(pargs
.r
.ret_str
);
2337 def_digest_string
= xstrdup(pargs
.r
.ret_str
);
2340 /* If it is all digits, stick a Z in front of it for
2341 later. This is for backwards compatibility with
2342 versions that took the compress algorithm number. */
2344 char *pt
=pargs
.r
.ret_str
;
2347 if (!isascii (*pt
) || !isdigit (*pt
))
2355 compress_algo_string
=xmalloc(strlen(pargs
.r
.ret_str
)+2);
2356 strcpy(compress_algo_string
,"Z");
2357 strcat(compress_algo_string
,pargs
.r
.ret_str
);
2360 compress_algo_string
= xstrdup(pargs
.r
.ret_str
);
2363 case oCertDigestAlgo
: cert_digest_string
= xstrdup(pargs
.r
.ret_str
); break;
2364 case oNoSecmemWarn
: secmem_set_flags( secmem_get_flags() | 1 ); break;
2365 case oRequireSecmem
: require_secmem
=1; break;
2366 case oNoRequireSecmem
: require_secmem
=0; break;
2367 case oNoPermissionWarn
: opt
.no_perm_warn
=1; break;
2368 case oNoMDCWarn
: opt
.no_mdc_warn
=1; break;
2369 case oDisplayCharset
:
2370 if( set_native_charset( pargs
.r
.ret_str
) )
2371 log_error(_("`%s' is not a valid character set\n"),
2374 case oNotDashEscaped
: opt
.not_dash_escaped
= 1; break;
2375 case oEscapeFrom
: opt
.escape_from
= 1; break;
2376 case oNoEscapeFrom
: opt
.escape_from
= 0; break;
2377 case oLockOnce
: opt
.lock_once
= 1; break;
2384 #else /* __riscos__ */
2385 riscos_not_implemented("lock-multiple");
2386 #endif /* __riscos__ */
2390 struct keyserver_spec
*keyserver
;
2391 keyserver
=parse_keyserver_uri(pargs
.r
.ret_str
,0,
2392 configname
,configlineno
);
2394 log_error(_("could not parse keyserver URL\n"));
2397 keyserver
->next
=opt
.keyserver
;
2398 opt
.keyserver
=keyserver
;
2402 case oKeyServerOptions
:
2403 if(!parse_keyserver_options(pargs
.r
.ret_str
))
2406 log_error(_("%s:%d: invalid keyserver options\n"),
2407 configname
,configlineno
);
2409 log_error(_("invalid keyserver options\n"));
2412 case oImportOptions
:
2413 if(!parse_import_options(pargs
.r
.ret_str
,&opt
.import_options
,1))
2416 log_error(_("%s:%d: invalid import options\n"),
2417 configname
,configlineno
);
2419 log_error(_("invalid import options\n"));
2422 case oExportOptions
:
2423 if(!parse_export_options(pargs
.r
.ret_str
,&opt
.export_options
,1))
2426 log_error(_("%s:%d: invalid export options\n"),
2427 configname
,configlineno
);
2429 log_error(_("invalid export options\n"));
2433 if(!parse_list_options(pargs
.r
.ret_str
))
2436 log_error(_("%s:%d: invalid list options\n"),
2437 configname
,configlineno
);
2439 log_error(_("invalid list options\n"));
2442 case oVerifyOptions
:
2444 struct parse_options vopts
[]=
2446 {"show-photos",VERIFY_SHOW_PHOTOS
,NULL
,
2447 N_("display photo IDs during signature verification")},
2448 {"show-policy-urls",VERIFY_SHOW_POLICY_URLS
,NULL
,
2449 N_("show policy URLs during signature verification")},
2450 {"show-notations",VERIFY_SHOW_NOTATIONS
,NULL
,
2451 N_("show all notations during signature verification")},
2452 {"show-std-notations",VERIFY_SHOW_STD_NOTATIONS
,NULL
,
2453 N_("show IETF standard notations during signature verification")},
2454 {"show-standard-notations",VERIFY_SHOW_STD_NOTATIONS
,NULL
,
2456 {"show-user-notations",VERIFY_SHOW_USER_NOTATIONS
,NULL
,
2457 N_("show user-supplied notations during signature verification")},
2458 {"show-keyserver-urls",VERIFY_SHOW_KEYSERVER_URLS
,NULL
,
2459 N_("show preferred keyserver URLs during signature verification")},
2460 {"show-uid-validity",VERIFY_SHOW_UID_VALIDITY
,NULL
,
2461 N_("show user ID validity during signature verification")},
2462 {"show-unusable-uids",VERIFY_SHOW_UNUSABLE_UIDS
,NULL
,
2463 N_("show revoked and expired user IDs in signature verification")},
2464 {"pka-lookups",VERIFY_PKA_LOOKUPS
,NULL
,
2465 N_("validate signatures with PKA data")},
2466 {"pka-trust-increase",VERIFY_PKA_TRUST_INCREASE
,NULL
,
2467 N_("elevate the trust of signatures with valid PKA data")},
2471 if(!parse_options(pargs
.r
.ret_str
,&opt
.verify_options
,vopts
,1))
2474 log_error(_("%s:%d: invalid verify options\n"),
2475 configname
,configlineno
);
2477 log_error(_("invalid verify options\n"));
2481 case oTempDir
: opt
.temp_dir
=pargs
.r
.ret_str
; break;
2483 if(set_exec_path(pargs
.r
.ret_str
))
2484 log_error(_("unable to set exec-path to %s\n"),pargs
.r
.ret_str
);
2486 opt
.exec_path_set
=1;
2489 add_notation_data( pargs
.r
.ret_str
, 0 );
2490 add_notation_data( pargs
.r
.ret_str
, 1 );
2492 case oSigNotation
: add_notation_data( pargs
.r
.ret_str
, 0 ); break;
2493 case oCertNotation
: add_notation_data( pargs
.r
.ret_str
, 1 ); break;
2495 deprecated_warning(configname
,configlineno
,"--show-notation",
2496 "--list-options ","show-notations");
2497 deprecated_warning(configname
,configlineno
,"--show-notation",
2498 "--verify-options ","show-notations");
2499 opt
.list_options
|=LIST_SHOW_NOTATIONS
;
2500 opt
.verify_options
|=VERIFY_SHOW_NOTATIONS
;
2502 case oNoShowNotation
:
2503 deprecated_warning(configname
,configlineno
,"--no-show-notation",
2504 "--list-options ","no-show-notations");
2505 deprecated_warning(configname
,configlineno
,"--no-show-notation",
2506 "--verify-options ","no-show-notations");
2507 opt
.list_options
&=~LIST_SHOW_NOTATIONS
;
2508 opt
.verify_options
&=~VERIFY_SHOW_NOTATIONS
;
2510 case oUtf8Strings
: utf8_strings
= 1; break;
2511 case oNoUtf8Strings
: utf8_strings
= 0; break;
2512 case oDisableCipherAlgo
:
2514 int algo
= gcry_cipher_map_name (pargs
.r
.ret_str
);
2515 gcry_cipher_ctl (NULL
, GCRYCTL_DISABLE_ALGO
, &algo
, sizeof algo
);
2518 case oDisablePubkeyAlgo
:
2520 int algo
= gcry_pk_map_name (pargs
.r
.ret_str
);
2521 gcry_pk_ctl (GCRYCTL_DISABLE_ALGO
, &algo
, sizeof algo
);
2524 case oNoSigCache
: opt
.no_sig_cache
= 1; break;
2525 case oNoSigCreateCheck
: opt
.no_sig_create_check
= 1; break;
2526 case oAllowNonSelfsignedUID
: opt
.allow_non_selfsigned_uid
= 1; break;
2527 case oNoAllowNonSelfsignedUID
: opt
.allow_non_selfsigned_uid
=0; break;
2528 case oAllowFreeformUID
: opt
.allow_freeform_uid
= 1; break;
2529 case oNoAllowFreeformUID
: opt
.allow_freeform_uid
= 0; break;
2530 case oNoLiteral
: opt
.no_literal
= 1; break;
2531 case oSetFilesize
: opt
.set_filesize
= pargs
.r
.ret_ulong
; break;
2532 case oHonorHttpProxy
:
2533 add_to_strlist(&opt
.keyserver_options
.other
,"http-proxy");
2534 deprecated_warning(configname
,configlineno
,
2535 "--honor-http-proxy",
2536 "--keyserver-options ","http-proxy");
2538 case oFastListMode
: opt
.fast_list_mode
= 1; break;
2539 case oFixedListMode
: opt
.fixed_list_mode
= 1; break;
2540 case oListOnly
: opt
.list_only
=1; break;
2541 case oIgnoreTimeConflict
: opt
.ignore_time_conflict
= 1; break;
2542 case oIgnoreValidFrom
: opt
.ignore_valid_from
= 1; break;
2543 case oIgnoreCrcError
: opt
.ignore_crc_error
= 1; break;
2544 case oIgnoreMDCError
: opt
.ignore_mdc_error
= 1; break;
2545 case oNoRandomSeedFile
: use_random_seed
= 0; break;
2546 case oAutoKeyRetrieve
:
2547 case oNoAutoKeyRetrieve
:
2548 if(pargs
.r_opt
==oAutoKeyRetrieve
)
2549 opt
.keyserver_options
.options
|=KEYSERVER_AUTO_KEY_RETRIEVE
;
2551 opt
.keyserver_options
.options
&=~KEYSERVER_AUTO_KEY_RETRIEVE
;
2553 deprecated_warning(configname
,configlineno
,
2554 pargs
.r_opt
==oAutoKeyRetrieve
?"--auto-key-retrieve":
2555 "--no-auto-key-retrieve","--keyserver-options ",
2556 pargs
.r_opt
==oAutoKeyRetrieve
?"auto-key-retrieve":
2557 "no-auto-key-retrieve");
2559 case oShowSessionKey
: opt
.show_session_key
= 1; break;
2560 case oOverrideSessionKey
:
2561 opt
.override_session_key
= pargs
.r
.ret_str
;
2564 deprecated_warning(configname
,configlineno
,"--merge-only",
2565 "--import-options ","merge-only");
2566 opt
.import_options
|=IMPORT_MERGE_ONLY
;
2568 case oAllowSecretKeyImport
: /* obsolete */ break;
2569 case oTryAllSecrets
: opt
.try_all_secrets
= 1; break;
2570 case oTrustedKey
: register_trusted_key( pargs
.r
.ret_str
); break;
2571 case oEnableSpecialFilenames
:
2572 iobuf_enable_special_filenames (1);
2574 case oNoExpensiveTrustChecks
: opt
.no_expensive_trust_checks
=1; break;
2575 case oAutoCheckTrustDB
: opt
.no_auto_check_trustdb
=0; break;
2576 case oNoAutoCheckTrustDB
: opt
.no_auto_check_trustdb
=1; break;
2577 case oPreservePermissions
: opt
.preserve_permissions
=1; break;
2578 case oDefaultPreferenceList
:
2579 opt
.def_preference_list
= pargs
.r
.ret_str
;
2581 case oPersonalCipherPreferences
:
2582 pers_cipher_list
=pargs
.r
.ret_str
;
2584 case oPersonalDigestPreferences
:
2585 pers_digest_list
=pargs
.r
.ret_str
;
2587 case oPersonalCompressPreferences
:
2588 pers_compress_list
=pargs
.r
.ret_str
;
2590 case oAgentProgram
: opt
.agent_program
= pargs
.r
.ret_str
; break;
2591 case oDisplay
: opt
.display
= pargs
.r
.ret_str
; break;
2592 case oTTYname
: opt
.ttyname
= pargs
.r
.ret_str
; break;
2593 case oTTYtype
: opt
.ttytype
= pargs
.r
.ret_str
; break;
2594 case oLCctype
: opt
.lc_ctype
= pargs
.r
.ret_str
; break;
2595 case oLCmessages
: opt
.lc_messages
= pargs
.r
.ret_str
; break;
2596 case oGroup
: add_group(pargs
.r
.ret_str
); break;
2597 case oUnGroup
: rm_group(pargs
.r
.ret_str
); break;
2599 while(opt
.grouplist
)
2601 struct groupitem
*iter
=opt
.grouplist
;
2602 free_strlist(iter
->values
);
2603 opt
.grouplist
=opt
.grouplist
->next
;
2607 case oStrict
: opt
.strict
=1; log_set_strict(1); break;
2608 case oNoStrict
: opt
.strict
=0; log_set_strict(0); break;
2609 case oMangleDosFilenames
: opt
.mangle_dos_filenames
= 1; break;
2610 case oNoMangleDosFilenames
: opt
.mangle_dos_filenames
= 0; break;
2611 case oEnableProgressFilter
: opt
.enable_progress_filter
= 1; break;
2612 case oMultifile
: multifile
=1; break;
2614 if(ascii_strcasecmp(pargs
.r
.ret_str
,"short")==0)
2615 opt
.keyid_format
=KF_SHORT
;
2616 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"long")==0)
2617 opt
.keyid_format
=KF_LONG
;
2618 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"0xshort")==0)
2619 opt
.keyid_format
=KF_0xSHORT
;
2620 else if(ascii_strcasecmp(pargs
.r
.ret_str
,"0xlong")==0)
2621 opt
.keyid_format
=KF_0xLONG
;
2623 log_error("unknown keyid-format `%s'\n",pargs
.r
.ret_str
);
2626 case oExitOnStatusWriteError
:
2627 opt
.exit_on_status_write_error
= 1;
2630 case oLimitCardInsertTries
:
2631 opt
.limit_card_insert_tries
= pargs
.r
.ret_int
;
2634 case oRequireCrossCert
: opt
.flags
.require_cross_cert
=1; break;
2635 case oNoRequireCrossCert
: opt
.flags
.require_cross_cert
=0; break;
2637 case oAutoKeyLocate
:
2638 if(!parse_auto_key_locate(pargs
.r
.ret_str
))
2641 log_error(_("%s:%d: invalid auto-key-locate list\n"),
2642 configname
,configlineno
);
2644 log_error(_("invalid auto-key-locate list\n"));
2647 case oNoAutoKeyLocate
:
2651 case oAllowMultisigVerification
:
2652 opt
.allow_multisig_verification
= 1;
2655 case oEnableDSA2
: opt
.flags
.dsa2
=1; break;
2656 case oDisableDSA2
: opt
.flags
.dsa2
=0; break;
2660 default : pargs
.err
= configfp
? 1:2; break;
2668 /* Remember the first config file name. */
2669 if (!save_configname
)
2670 save_configname
= configname
;
2676 xfree( configname
); configname
= NULL
;
2677 if( log_get_errorcount(0) )
2680 /* The command --gpgconf-list is pretty simple and may be called
2681 directly after the option parsing. */
2682 if (cmd
== aGPGConfList
)
2684 gpgconf_list (save_configname
);
2687 xfree (save_configname
);
2693 fprintf(stderr
, "%s %s; %s\n",
2694 strusage(11), strusage(13), strusage(14) );
2695 fprintf(stderr
, "%s\n", strusage(15) );
2697 #ifdef IS_DEVELOPMENT_VERSION
2702 if((s
=strusage(20)))
2704 if((s
=strusage(21)))
2706 if((s
=strusage(22)))
2711 /* FIXME: We should use logging to a file only in server mode;
2712 however we have not yet implemetyed that. Thus we try to get
2713 away with --batch as indication for logging to file
2715 if (logfile
&& opt
.batch
)
2717 log_set_file (logfile
);
2718 log_set_prefix (NULL
, 1|2|4);
2721 if (opt
.verbose
> 2)
2722 log_info ("using character set `%s'\n", get_native_charset ());
2724 if( may_coredump
&& !opt
.quiet
)
2725 log_info(_("WARNING: program may create a core file!\n"));
2728 if (opt
.set_filename
)
2729 log_info(_("WARNING: %s overrides %s\n"),
2730 "--for-your-eyes-only","--set-filename");
2732 opt
.set_filename
="_CONSOLE";
2735 if (opt
.no_literal
) {
2736 log_info(_("NOTE: %s is not for normal use!\n"), "--no-literal");
2738 log_error(_("%s not allowed with %s!\n"),
2739 "--textmode", "--no-literal" );
2740 if (opt
.set_filename
)
2741 log_error(_("%s makes no sense with %s!\n"),
2742 eyes_only
?"--for-your-eyes-only":"--set-filename",
2747 if (opt
.set_filesize
)
2748 log_info(_("NOTE: %s is not for normal use!\n"), "--set-filesize");
2752 gcry_control (GCRYCTL_RESUME_SECMEM_WARN
);
2754 if(require_secmem
&& !got_secmem
)
2756 log_info(_("will not run with insecure memory due to %s\n"),
2757 "--require-secmem");
2761 set_debug (debug_level
);
2763 /* Do these after the switch(), so they can override settings. */
2768 if(cmd
==aSign
&& !detached_sig
)
2770 log_info(_("you can only make detached or clear signatures "
2771 "while in --pgp2 mode\n"));
2774 else if(cmd
==aSignEncr
|| cmd
==aSignSym
)
2776 log_info(_("you can't sign and encrypt at the "
2777 "same time while in --pgp2 mode\n"));
2780 else if(argc
==0 && (cmd
==aSign
|| cmd
==aEncr
|| cmd
==aSym
))
2782 log_info(_("you must use files (and not a pipe) when "
2783 "working with --pgp2 enabled.\n"));
2786 else if(cmd
==aEncr
|| cmd
==aSym
)
2788 /* Everything else should work without IDEA (except using
2789 a secret key encrypted with IDEA and setting an IDEA
2790 preference, but those have their own error
2793 if (openpgp_cipher_test_algo(CIPHER_ALGO_IDEA
))
2795 log_info(_("encrypting a message in --pgp2 mode requires "
2796 "the IDEA cipher\n"));
2797 idea_cipher_warn(1);
2802 /* This only sets IDEA for symmetric encryption
2803 since it is set via select_algo_from_prefs for
2805 xfree(def_cipher_string
);
2806 def_cipher_string
= xstrdup("idea");
2809 /* PGP2 can't handle the output from the textmode
2810 filter, so we disable it for anything that could
2811 create a literal packet (only encryption and
2812 symmetric encryption, since we disable signing
2819 compliance_failure();
2822 opt
.force_v4_certs
= 0;
2823 opt
.escape_from
= 1;
2824 opt
.force_v3_sigs
= 1;
2825 opt
.pgp2_workarounds
= 1;
2826 opt
.ask_sig_expire
= 0;
2827 opt
.ask_cert_expire
= 0;
2828 xfree(def_digest_string
);
2829 def_digest_string
= xstrdup("md5");
2830 xfree(s2k_digest_string
);
2831 s2k_digest_string
= xstrdup("md5");
2832 opt
.compress_algo
= COMPRESS_ALGO_ZIP
;
2838 opt
.force_v3_sigs
=1;
2839 opt
.ask_sig_expire
=0;
2844 opt
.force_v3_sigs
=1;
2845 opt
.ask_sig_expire
=0;
2853 if( def_cipher_string
) {
2854 opt
.def_cipher_algo
= gcry_cipher_map_name (def_cipher_string
);
2855 if(opt
.def_cipher_algo
==0 &&
2856 (ascii_strcasecmp(def_cipher_string
,"idea")==0
2857 || ascii_strcasecmp(def_cipher_string
,"s1")==0))
2858 idea_cipher_warn(1);
2859 xfree(def_cipher_string
); def_cipher_string
= NULL
;
2860 if ( openpgp_cipher_test_algo (opt
.def_cipher_algo
) )
2861 log_error(_("selected cipher algorithm is invalid\n"));
2863 if( def_digest_string
) {
2864 opt
.def_digest_algo
= gcry_md_map_name (def_digest_string
);
2865 xfree(def_digest_string
); def_digest_string
= NULL
;
2866 if ( openpgp_md_test_algo (opt
.def_digest_algo
) )
2867 log_error(_("selected digest algorithm is invalid\n"));
2869 if( compress_algo_string
) {
2870 opt
.compress_algo
= string_to_compress_algo(compress_algo_string
);
2871 xfree(compress_algo_string
); compress_algo_string
= NULL
;
2872 if( check_compress_algo(opt
.compress_algo
) )
2873 log_error(_("selected compression algorithm is invalid\n"));
2875 if( cert_digest_string
) {
2876 opt
.cert_digest_algo
= gcry_md_map_name (cert_digest_string
);
2877 xfree(cert_digest_string
); cert_digest_string
= NULL
;
2878 if (openpgp_md_test_algo(opt
.cert_digest_algo
))
2879 log_error(_("selected certification digest algorithm is invalid\n"));
2881 if( s2k_cipher_string
) {
2882 opt
.s2k_cipher_algo
= gcry_cipher_map_name (s2k_cipher_string
);
2883 xfree(s2k_cipher_string
); s2k_cipher_string
= NULL
;
2884 if (openpgp_cipher_test_algo (opt
.s2k_cipher_algo
))
2885 log_error(_("selected cipher algorithm is invalid\n"));
2887 if( s2k_digest_string
) {
2888 opt
.s2k_digest_algo
= gcry_md_map_name (s2k_digest_string
);
2889 xfree(s2k_digest_string
); s2k_digest_string
= NULL
;
2890 if (openpgp_md_test_algo(opt
.s2k_digest_algo
))
2891 log_error(_("selected digest algorithm is invalid\n"));
2893 if( opt
.completes_needed
< 1 )
2894 log_error(_("completes-needed must be greater than 0\n"));
2895 if( opt
.marginals_needed
< 2 )
2896 log_error(_("marginals-needed must be greater than 1\n"));
2897 if( opt
.max_cert_depth
< 1 || opt
.max_cert_depth
> 255 )
2898 log_error(_("max-cert-depth must be in the range from 1 to 255\n"));
2899 if(opt
.def_cert_level
<0 || opt
.def_cert_level
>3)
2900 log_error(_("invalid default-cert-level; must be 0, 1, 2, or 3\n"));
2901 if( opt
.min_cert_level
< 1 || opt
.min_cert_level
> 3 )
2902 log_error(_("invalid min-cert-level; must be 1, 2, or 3\n"));
2903 switch( opt
.s2k_mode
) {
2905 log_info(_("NOTE: simple S2K mode (0) is strongly discouraged\n"));
2907 case 1: case 3: break;
2909 log_error(_("invalid S2K mode; must be 0, 1 or 3\n"));
2912 /* This isn't actually needed, but does serve to error out if the
2913 string is invalid. */
2914 if(opt
.def_preference_list
&&
2915 keygen_set_std_prefs(opt
.def_preference_list
,0))
2916 log_error(_("invalid default preferences\n"));
2918 /* We provide defaults for the personal digest list. This is
2920 if(!pers_digest_list
)
2921 pers_digest_list
="h2";
2923 if(pers_cipher_list
&&
2924 keygen_set_std_prefs(pers_cipher_list
,PREFTYPE_SYM
))
2925 log_error(_("invalid personal cipher preferences\n"));
2927 if(pers_digest_list
&&
2928 keygen_set_std_prefs(pers_digest_list
,PREFTYPE_HASH
))
2929 log_error(_("invalid personal digest preferences\n"));
2931 if(pers_compress_list
&&
2932 keygen_set_std_prefs(pers_compress_list
,PREFTYPE_ZIP
))
2933 log_error(_("invalid personal compress preferences\n"));
2935 /* We don't support all possible commands with multifile yet */
2946 cmdname
="--clearsign";
2949 cmdname
="--detach-sign";
2952 cmdname
="--symmetric";
2955 cmdname
="--symmetric --encrypt";
2966 log_error(_("%s does not yet work with %s\n"),cmdname
,"--multifile");
2969 if( log_get_errorcount(0) )
2972 if(opt
.compress_level
==0)
2973 opt
.compress_algo
=COMPRESS_ALGO_NONE
;
2975 /* Check our chosen algorithms against the list of legal
2980 const char *badalg
=NULL
;
2981 preftype_t badtype
=PREFTYPE_NONE
;
2983 if(opt
.def_cipher_algo
2984 && !algo_available(PREFTYPE_SYM
,opt
.def_cipher_algo
,NULL
))
2986 badalg
= gcry_cipher_algo_name (opt
.def_cipher_algo
);
2987 badtype
= PREFTYPE_SYM
;
2989 else if(opt
.def_digest_algo
2990 && !algo_available(PREFTYPE_HASH
,opt
.def_digest_algo
,NULL
))
2992 badalg
= gcry_md_algo_name (opt
.def_digest_algo
);
2993 badtype
= PREFTYPE_HASH
;
2995 else if(opt
.cert_digest_algo
2996 && !algo_available(PREFTYPE_HASH
,opt
.cert_digest_algo
,NULL
))
2998 badalg
= gcry_md_algo_name (opt
.cert_digest_algo
);
2999 badtype
= PREFTYPE_HASH
;
3001 else if(opt
.compress_algo
!=-1
3002 && !algo_available(PREFTYPE_ZIP
,opt
.compress_algo
,NULL
))
3004 badalg
= compress_algo_to_string(opt
.compress_algo
);
3005 badtype
= PREFTYPE_ZIP
;
3013 log_info(_("you may not use cipher algorithm `%s'"
3014 " while in %s mode\n"),
3015 badalg
,compliance_option_string());
3018 log_info(_("you may not use digest algorithm `%s'"
3019 " while in %s mode\n"),
3020 badalg
,compliance_option_string());
3023 log_info(_("you may not use compression algorithm `%s'"
3024 " while in %s mode\n"),
3025 badalg
,compliance_option_string());
3031 compliance_failure();
3035 /* Set the random seed file. */
3036 if( use_random_seed
) {
3037 char *p
= make_filename(opt
.homedir
, "random_seed", NULL
);
3038 set_random_seed_file(p
);
3039 gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE
, p
);
3040 if (!access (p
, F_OK
))
3041 register_secured_file (p
);
3045 if( !cmd
&& opt
.fingerprint
&& !with_fpr
) {
3046 set_cmd( &cmd
, aListKeys
);
3049 if( cmd
== aKMode
|| cmd
== aKModeC
) { /* kludge to be compatible to pgp */
3050 if( cmd
== aKModeC
) {
3051 opt
.fingerprint
= 1;
3055 if( opt
.verbose
> 2 )
3057 if( opt
.verbose
> 1 )
3060 opt
.verbose
= opt
.verbose
> 1;
3063 /* kludge to let -sat generate a clear text signature */
3064 if( opt
.textmode
== 2 && !detached_sig
&& opt
.armor
&& cmd
== aSign
)
3067 if( opt
.verbose
> 1 )
3068 set_packet_list_mode(1);
3070 /* Add the keyrings, but not for some special commands and not in
3071 case of "-kvv userid keyring". Also avoid adding the secret
3072 keyring for a couple of commands to avoid unneeded access in
3073 case the secrings are stored on a floppy.
3075 We always need to add the keyrings if we are running under
3076 SELinux, this is so that the rings are added to the list of
3078 if( ALWAYS_ADD_KEYRINGS
3079 || (cmd
!= aDeArmor
&& cmd
!= aEnArmor
3080 && !(cmd
== aKMode
&& argc
== 2 )) )
3082 if (ALWAYS_ADD_KEYRINGS
3083 || (cmd
!= aCheckKeys
&& cmd
!= aListSigs
&& cmd
!= aListKeys
3084 && cmd
!= aVerify
&& cmd
!= aSym
))
3086 if (!sec_nrings
|| default_keyring
) /* add default secret rings */
3087 keydb_add_resource ("secring" EXTSEP_S
"gpg", 4, 1);
3088 for (sl
= sec_nrings
; sl
; sl
= sl
->next
)
3089 keydb_add_resource ( sl
->d
, 0, 1 );
3091 if( !nrings
|| default_keyring
) /* add default ring */
3092 keydb_add_resource ("pubring" EXTSEP_S
"gpg", 4, 0);
3093 for(sl
= nrings
; sl
; sl
= sl
->next
)
3094 keydb_add_resource ( sl
->d
, sl
->flags
, 0 );
3096 FREE_STRLIST(nrings
);
3097 FREE_STRLIST(sec_nrings
);
3100 if( pwfd
!= -1 ) /* read the passphrase now. */
3101 read_passphrase_from_fd( pwfd
);
3103 fname
= argc
? *argv
: NULL
;
3105 if(fname
&& utf8_strings
)
3106 opt
.flags
.utf8_filename
=1;
3117 case aExportOwnerTrust
: rc
= setup_trustdb( 0, trustdb_name
); break;
3118 case aListTrustDB
: rc
= setup_trustdb( argc
? 1:0, trustdb_name
); break;
3119 default: rc
= setup_trustdb(1, trustdb_name
); break;
3122 log_error(_("failed to initialize the TrustDB: %s\n"), g10_errstr(rc
));
3132 if (!opt
.quiet
&& any_explicit_recipient
)
3133 log_info (_("WARNING: recipients (-r) given "
3134 "without using public key encryption\n"));
3142 case aStore
: /* only store the file */
3144 wrong_args(_("--store [filename]"));
3145 if( (rc
= encode_store(fname
)) )
3146 log_error ("storing `%s' failed: %s\n",
3147 print_fname_stdin(fname
),g10_errstr(rc
) );
3149 case aSym
: /* encrypt the given file only with the symmetric cipher */
3151 wrong_args(_("--symmetric [filename]"));
3152 if( (rc
= encode_symmetric(fname
)) )
3153 log_error (_("symmetric encryption of `%s' failed: %s\n"),
3154 print_fname_stdin(fname
),g10_errstr(rc
) );
3157 case aEncr
: /* encrypt the given file */
3159 encode_crypt_files(argc
, argv
, remusr
);
3163 wrong_args(_("--encrypt [filename]"));
3164 if( (rc
= encode_crypt(fname
,remusr
,0)) )
3165 log_error("%s: encryption failed: %s\n",
3166 print_fname_stdin(fname
), g10_errstr(rc
) );
3171 /* This works with PGP 8 in the sense that it acts just like a
3172 symmetric message. It doesn't work at all with 2 or 6. It
3173 might work with 7, but alas, I don't have a copy to test
3176 wrong_args(_("--symmetric --encrypt [filename]"));
3177 else if(opt
.s2k_mode
==0)
3178 log_error(_("you cannot use --symmetric --encrypt"
3179 " with --s2k-mode 0\n"));
3180 else if(PGP2
|| PGP6
|| PGP7
|| RFC1991
)
3181 log_error(_("you cannot use --symmetric --encrypt"
3182 " while in %s mode\n"),compliance_option_string());
3185 if( (rc
= encode_crypt(fname
,remusr
,1)) )
3186 log_error("%s: encryption failed: %s\n",
3187 print_fname_stdin(fname
), g10_errstr(rc
) );
3191 case aSign
: /* sign the given file */
3193 if( detached_sig
) { /* sign all files */
3194 for( ; argc
; argc
--, argv
++ )
3195 add_to_strlist( &sl
, *argv
);
3199 wrong_args(_("--sign [filename]"));
3201 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3202 strcpy(sl
->d
, fname
);
3205 if( (rc
= sign_file( sl
, detached_sig
, locusr
, 0, NULL
, NULL
)) )
3206 log_error("signing failed: %s\n", g10_errstr(rc
) );
3210 case aSignEncr
: /* sign and encrypt the given file */
3212 wrong_args(_("--sign --encrypt [filename]"));
3214 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3215 strcpy(sl
->d
, fname
);
3219 if( (rc
= sign_file(sl
, detached_sig
, locusr
, 1, remusr
, NULL
)) )
3220 log_error("%s: sign+encrypt failed: %s\n",
3221 print_fname_stdin(fname
), g10_errstr(rc
) );
3225 case aSignEncrSym
: /* sign and encrypt the given file */
3227 wrong_args(_("--symmetric --sign --encrypt [filename]"));
3228 else if(opt
.s2k_mode
==0)
3229 log_error(_("you cannot use --symmetric --sign --encrypt"
3230 " with --s2k-mode 0\n"));
3231 else if(PGP2
|| PGP6
|| PGP7
|| RFC1991
)
3232 log_error(_("you cannot use --symmetric --sign --encrypt"
3233 " while in %s mode\n"),compliance_option_string());
3238 sl
= xmalloc_clear( sizeof *sl
+ strlen(fname
));
3239 strcpy(sl
->d
, fname
);
3243 if( (rc
= sign_file(sl
, detached_sig
, locusr
, 2, remusr
, NULL
)) )
3244 log_error("%s: symmetric+sign+encrypt failed: %s\n",
3245 print_fname_stdin(fname
), g10_errstr(rc
) );
3250 case aSignSym
: /* sign and conventionally encrypt the given file */
3252 wrong_args(_("--sign --symmetric [filename]"));
3253 rc
= sign_symencrypt_file (fname
, locusr
);
3255 log_error("%s: sign+symmetric failed: %s\n",
3256 print_fname_stdin(fname
), g10_errstr(rc
) );
3259 case aClearsign
: /* make a clearsig */
3261 wrong_args(_("--clearsign [filename]"));
3262 if( (rc
= clearsign_file(fname
, locusr
, NULL
)) )
3263 log_error("%s: clearsign failed: %s\n",
3264 print_fname_stdin(fname
), g10_errstr(rc
) );
3270 if( (rc
= verify_files( argc
, argv
) ))
3271 log_error("verify files failed: %s\n", g10_errstr(rc
) );
3275 if( (rc
= verify_signatures( argc
, argv
) ))
3276 log_error("verify signatures failed: %s\n", g10_errstr(rc
) );
3282 decrypt_messages(argc
, argv
);
3286 wrong_args(_("--decrypt [filename]"));
3287 if( (rc
= decrypt_message( fname
) ))
3288 log_error("decrypt_message failed: %s\n", g10_errstr(rc
) );
3294 wrong_args(_("--sign-key user-id"));
3298 wrong_args(_("--lsign-key user-id"));
3304 append_to_strlist(&sl
,"sign");
3305 else if(cmd
==aLSignKey
)
3306 append_to_strlist(&sl
,"lsign");
3310 append_to_strlist( &sl
, "save" );
3311 username
= make_username( fname
);
3312 keyedit_menu(fname
, locusr
, sl
, 0, 0 );
3317 case aEditKey
: /* Edit a key signature */
3319 wrong_args(_("--edit-key user-id [commands]"));
3320 username
= make_username( fname
);
3323 for( argc
--, argv
++ ; argc
; argc
--, argv
++ )
3324 append_to_strlist( &sl
, *argv
);
3325 keyedit_menu( username
, locusr
, sl
, 0, 1 );
3329 keyedit_menu(username
, locusr
, NULL
, 0, 1 );
3334 case aDeleteSecretKeys
:
3335 case aDeleteSecretAndPublicKeys
:
3337 /* I'm adding these in reverse order as add_to_strlist2
3338 reverses them again, and it's easier to understand in the
3340 for( ; argc
; argc
-- )
3341 add_to_strlist2( &sl
, argv
[argc
-1], utf8_strings
);
3342 delete_keys(sl
,cmd
==aDeleteSecretKeys
,cmd
==aDeleteSecretAndPublicKeys
);
3352 for( ; argc
; argc
--, argv
++ )
3353 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3354 public_key_list( sl
);
3357 case aListSecretKeys
:
3359 for( ; argc
; argc
--, argv
++ )
3360 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3361 secret_key_list( sl
);
3365 case aKMode
: /* list keyring -- NOTE: This will be removed soon */
3366 if( argc
< 2 ) { /* -kv [userid] */
3369 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3370 public_key_list( sl
);
3373 else if( argc
== 2 ) { /* -kv userid keyring */
3374 if( access( argv
[1], R_OK
) ) {
3375 log_error(_("can't open `%s': %s\n"),
3376 print_fname_stdin(argv
[1]), strerror(errno
));
3379 /* add keyring (default keyrings are not registered in this
3381 keydb_add_resource( argv
[1], 0, 0 );
3384 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3385 public_key_list( sl
);
3390 wrong_args(_("-k[v][v][v][c] [user-id] [keyring]") );
3393 case aKeygen
: /* generate a key */
3396 wrong_args("--gen-key [parameterfile]");
3397 generate_keypair( argc
? *argv
: NULL
, NULL
, NULL
);
3401 wrong_args("--gen-key");
3402 generate_keypair(NULL
, NULL
, NULL
);
3407 opt
.import_options
|= IMPORT_FAST
;
3409 import_keys( argc
? argv
:NULL
, argc
, NULL
, opt
.import_options
);
3412 /* TODO: There are a number of command that use this same
3413 "make strlist, call function, report error, free strlist"
3414 pattern. Join them together here and avoid all that
3421 for( ; argc
; argc
--, argv
++ )
3422 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3423 if( cmd
== aSendKeys
)
3424 rc
=keyserver_export( sl
);
3425 else if( cmd
== aRecvKeys
)
3426 rc
=keyserver_import( sl
);
3428 rc
=export_pubkeys( sl
, opt
.export_options
);
3432 log_error(_("keyserver send failed: %s\n"),g10_errstr(rc
));
3433 else if(cmd
==aRecvKeys
)
3434 log_error(_("keyserver receive failed: %s\n"),g10_errstr(rc
));
3436 log_error(_("key export failed: %s\n"),g10_errstr(rc
));
3443 for( ; argc
; argc
--, argv
++ )
3444 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3445 rc
=keyserver_search( sl
);
3447 log_error(_("keyserver search failed: %s\n"),g10_errstr(rc
));
3453 for( ; argc
; argc
--, argv
++ )
3454 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3455 rc
=keyserver_refresh(sl
);
3457 log_error(_("keyserver refresh failed: %s\n"),g10_errstr(rc
));
3463 for( ; argc
; argc
--, argv
++ )
3464 append_to_strlist2( &sl
, *argv
, utf8_strings
);
3465 rc
=keyserver_fetch(sl
);
3467 log_error("key fetch failed: %s\n",g10_errstr(rc
));
3473 for( ; argc
; argc
--, argv
++ )
3474 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3475 export_seckeys( sl
);
3479 case aExportSecretSub
:
3481 for( ; argc
; argc
--, argv
++ )
3482 add_to_strlist2( &sl
, *argv
, utf8_strings
);
3483 export_secsubkeys( sl
);
3489 wrong_args("--gen-revoke user-id");
3490 username
= make_username(*argv
);
3491 gen_revoke( username
);
3497 wrong_args("--desig-revoke user-id");
3498 username
= make_username(*argv
);
3499 gen_desig_revoke( username
, locusr
);
3505 wrong_args("--dearmor [file]");
3506 rc
= dearmor_file( argc
? *argv
: NULL
);
3508 log_error(_("dearmoring failed: %s\n"), g10_errstr(rc
));
3513 wrong_args("--enarmor [file]");
3514 rc
= enarmor_file( argc
? *argv
: NULL
);
3516 log_error(_("enarmoring failed: %s\n"), g10_errstr(rc
));
3522 { int mode
= argc
< 2 ? 0 : atoi(*argv
);
3524 if( mode
== 1 && argc
== 2 ) {
3525 mpi_print( stdout
, generate_public_prime( atoi(argv
[1]) ), 1);
3527 else if( mode
== 2 && argc
== 3 ) {
3528 mpi_print( stdout
, generate_elg_prime(
3530 atoi(argv
[2]), NULL
,NULL
), 1);
3532 else if( mode
== 3 && argc
== 3 ) {
3534 mpi_print( stdout
, generate_elg_prime(
3536 atoi(argv
[2]), NULL
,&factors
), 1);
3538 mpi_print( stdout
, factors
[0], 1 ); /* print q */
3540 else if( mode
== 4 && argc
== 3 ) {
3541 MPI g
= mpi_alloc(1);
3542 mpi_print( stdout
, generate_elg_prime(
3544 atoi(argv
[2]), g
, NULL
), 1);
3546 mpi_print( stdout
, g
, 1 );
3550 wrong_args("--gen-prime mode bits [qbits] ");
3554 wrong_args("--gen-prime not yet supported ");
3559 int level
= argc
? atoi(*argv
):0;
3560 int count
= argc
> 1 ? atoi(argv
[1]): 0;
3561 int endless
= !count
;
3563 if( argc
< 1 || argc
> 2 || level
< 0 || level
> 2 || count
< 0 )
3564 wrong_args("--gen-random 0|1|2 [count]");
3566 while( endless
|| count
) {
3568 /* Wee need a multiple of 3, so that in case of
3569 armored output we get a correct string. No
3570 linefolding is done, as it is best to levae this to
3572 size_t n
= !endless
&& count
< 99? count
: 99;
3574 p
= gcry_random_bytes (n
, level
);
3575 #ifdef HAVE_DOSISH_SYSTEM
3576 setmode ( fileno(stdout
), O_BINARY
);
3579 char *tmp
= make_radix64_string (p
, n
);
3580 fputs (tmp
, stdout
);
3587 fwrite( p
, n
, 1, stdout
);
3600 wrong_args("--print-md algo [files]");
3602 int all_algos
= (**argv
=='*' && !(*argv
)[1]);
3603 int algo
= all_algos
? 0 : gcry_md_map_name (*argv
);
3605 if( !algo
&& !all_algos
)
3606 log_error(_("invalid hash algorithm `%s'\n"), *argv
);
3610 print_mds(NULL
, algo
);
3612 for(; argc
; argc
--, argv
++ )
3613 print_mds(*argv
, algo
);
3619 case aPrintMDs
: /* old option */
3623 for(; argc
; argc
--, argv
++ )
3632 for( ; argc
; argc
--, argv
++ )
3633 list_trustdb( *argv
);
3637 case aUpdateTrustDB
:
3639 wrong_args("--update-trustdb");
3644 /* Old versions allowed for arguments - ignore them */
3649 log_error("this command is not yet implemented.\n");
3650 log_error("A workaround is to use \"--export-ownertrust\", remove\n");
3651 log_error("the trustdb file and do an \"--import-ownertrust\".\n" );
3654 case aListTrustPath
:
3656 wrong_args("--list-trust-path <user-ids>");
3657 for( ; argc
; argc
--, argv
++ ) {
3658 username
= make_username( *argv
);
3659 list_trust_path( username
);
3664 case aExportOwnerTrust
:
3666 wrong_args("--export-ownertrust");
3667 export_ownertrust();
3670 case aImportOwnerTrust
:
3672 wrong_args("--import-ownertrust [file]");
3673 import_ownertrust( argc
? *argv
:NULL
);
3676 case aRebuildKeydbCaches
:
3678 wrong_args ("--rebuild-keydb-caches");
3679 keydb_rebuild_caches (1);
3682 #ifdef ENABLE_CARD_SUPPORT
3685 wrong_args ("--card-status");
3686 card_status (stdout
, NULL
, 0);
3692 for (argc
--, argv
++ ; argc
; argc
--, argv
++)
3693 append_to_strlist (&sl
, *argv
);
3705 change_pin (atoi (*argv
),1);
3707 wrong_args ("--change-pin [no]");
3709 #endif /* ENABLE_CARD_SUPPORT*/
3713 char *str
=collapse_args(argc
,argv
);
3723 wrong_args(_("[filename]"));
3724 /* Issue some output for the unix newbie */
3725 if( !fname
&& !opt
.outfile
&& isatty( fileno(stdin
) )
3726 && isatty( fileno(stdout
) ) && isatty( fileno(stderr
) ) )
3727 log_info(_("Go ahead and type your message ...\n"));
3729 a
= iobuf_open(fname
);
3730 if (a
&& is_secured_file (iobuf_get_fd (a
)))
3737 log_error(_("can't open `%s'\n"), print_fname_stdin(fname
));
3740 if( !opt
.no_armor
) {
3741 if( use_armor_filter( a
) ) {
3742 memset( &afx
, 0, sizeof afx
);
3743 iobuf_push_filter( a
, armor_filter
, &afx
);
3746 if( cmd
== aListPackets
) {
3747 set_packet_list_mode(1);
3750 rc
= proc_packets(NULL
, a
);
3752 log_error("processing message failed: %s\n", g10_errstr(rc
) );
3759 FREE_STRLIST(remusr
);
3760 FREE_STRLIST(locusr
);
3762 return 8; /*NEVER REACHED*/
3766 /* Note: This function is used by signal handlers!. */
3768 emergency_cleanup (void)
3770 gcry_control (GCRYCTL_TERM_SECMEM
);
3777 #ifdef ENABLE_CARD_SUPPORT
3781 gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE
);
3782 if ( (opt
.debug
& DBG_MEMSTAT_VALUE
) )
3784 gcry_control (GCRYCTL_DUMP_MEMORY_STATS
);
3785 gcry_control (GCRYCTL_DUMP_RANDOM_STATS
);
3788 gcry_control (GCRYCTL_DUMP_SECMEM_STATS
);
3790 emergency_cleanup ();
3792 rc
= rc
? rc
: log_get_errorcount(0)? 2 : g10_errors_seen
? 1 : 0;
3797 /* Pretty-print hex hashes. This assumes at least an 80-character
3798 display, but there are a few other similar assumptions in the
3801 print_hex( gcry_md_hd_t md
, int algo
, const char *fname
)
3803 int i
,n
,count
,indent
=0;
3807 indent
=printf("%s: ",fname
);
3815 if(algo
==DIGEST_ALGO_RMD160
)
3816 indent
+=printf("RMD160 = ");
3818 indent
+=printf("%6s = ", gcry_md_algo_name (algo
));
3824 p
= gcry_md_read (md
, algo
);
3825 n
= gcry_md_get_algo_dlen (algo
);
3827 count
+= printf ("%02X",*p
++);
3829 for(i
=1;i
<n
;i
++,p
++)
3835 printf("\n%*s",indent
," ");
3850 printf("\n%*s",indent
," ");
3866 printf("\n%*s",indent
," ");
3874 count
+=printf("%02X",*p
);
3881 print_hashline( gcry_md_hd_t md
, int algo
, const char *fname
)
3887 for (p
= fname
; *p
; p
++ ) {
3888 if ( *p
<= 32 || *p
> 127 || *p
== ':' || *p
== '%' )
3889 printf("%%%02X", *p
);
3895 printf("%d:", algo
);
3896 p
= gcry_md_read (md
, algo
);
3897 n
= gcry_md_get_algo_dlen (algo
);
3898 for(i
=0; i
< n
; i
++, p
++ )
3899 printf("%02X", *p
);
3905 print_mds( const char *fname
, int algo
)
3914 #ifdef HAVE_DOSISH_SYSTEM
3915 setmode ( fileno(fp
) , O_BINARY
);
3919 fp
= fopen( fname
, "rb" );
3920 if (fp
&& is_secured_file (fileno (fp
)))
3928 log_error("%s: %s\n", fname
?fname
:"[stdin]", strerror(errno
) );
3932 gcry_md_open (&md
, 0, 0);
3934 gcry_md_enable (md
, algo
);
3936 gcry_md_enable (md
, GCRY_MD_MD5
);
3937 gcry_md_enable (md
, GCRY_MD_SHA1
);
3938 gcry_md_enable (md
, GCRY_MD_RMD160
);
3940 gcry_md_enable (md
, DIGEST_ALGO_SHA224
);
3941 gcry_md_enable (md
, GCRY_MD_SHA256
);
3944 gcry_md_enable (md
, GCRY_MD_SHA384
);
3945 gcry_md_enable (md
, GCRY_MD_SHA512
);
3949 while( (n
=fread( buf
, 1, DIM(buf
), fp
)) )
3950 gcry_md_write (md
, buf
, n
);
3952 log_error("%s: %s\n", fname
?fname
:"[stdin]", strerror(errno
) );
3955 if ( opt
.with_colons
) {
3957 print_hashline( md
, algo
, fname
);
3959 print_hashline( md
, GCRY_MD_MD5
, fname
);
3960 print_hashline( md
, GCRY_MD_SHA1
, fname
);
3961 print_hashline( md
, GCRY_MD_RMD160
, fname
);
3963 if (!gcry_md_test_algo (DIGEST_ALGO_SHA224
)
3964 print_hashline (md
, DIGEST_ALGO_SHA224
, fname
);
3965 print_hashline( md
, GCRY_MD_SHA256
, fname
);
3968 print_hashline( md
, GCRY_MD_SHA384
, fname
);
3969 print_hashline( md
, GCRY_MD_SHA512
, fname
);
3975 print_hex(md
,-algo
,fname
);
3977 print_hex( md
, GCRY_MD_MD5
, fname
);
3978 print_hex( md
, GCRY_MD_SHA1
, fname
);
3979 print_hex( md
, GCRY_MD_RMD160
, fname
);
3981 if (!gcry_md_test_algo (DIGEST_ALGO_SHA224
)
3982 print_hex (md
, DIGEST_ALGO_SHA224
, fname
);
3983 print_hex( md
, GCRY_MD_SHA256
, fname
);
3986 print_hex( md
, GCRY_MD_SHA384
, fname
);
3987 print_hex( md
, GCRY_MD_SHA512
, fname
);
4000 * Check the supplied name,value string and add it to the notation
4001 * data to be used for signatures. which==0 for sig notations, and 1
4002 * for cert notations.
4005 add_notation_data( const char *string
, int which
)
4007 struct notation
*notation
;
4009 notation
=string_to_notation(string
,utf8_strings
);
4014 notation
->next
=opt
.cert_notations
;
4015 opt
.cert_notations
=notation
;
4019 notation
->next
=opt
.sig_notations
;
4020 opt
.sig_notations
=notation
;
4026 add_policy_url( const char *string
, int which
)
4028 unsigned int i
,critical
=0;
4037 for(i
=0;i
<strlen(string
);i
++)
4038 if( !isascii (string
[i
]) || iscntrl(string
[i
]))
4041 if(i
==0 || i
<strlen(string
))
4044 log_error(_("the given certification policy URL is invalid\n"));
4046 log_error(_("the given signature policy URL is invalid\n"));
4050 sl
=add_to_strlist( &opt
.cert_policy_url
, string
);
4052 sl
=add_to_strlist( &opt
.sig_policy_url
, string
);
4059 add_keyserver_url( const char *string
, int which
)
4061 unsigned int i
,critical
=0;
4070 for(i
=0;i
<strlen(string
);i
++)
4071 if( !isascii (string
[i
]) || iscntrl(string
[i
]))
4074 if(i
==0 || i
<strlen(string
))
4079 log_error(_("the given preferred keyserver URL is invalid\n"));
4085 sl
=add_to_strlist( &opt
.sig_keyserver_url
, string
);