⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 args.c

📁 PGP—Pretty Good Privacy
💻 C
📖 第 1 页 / 共 5 页
字号:
                tryRingFileExtensions (filebPtr, ringfilename);

                err = PGPNewFileSpecFromFullPath( context, ringfilename,
                        &ringfilespec);

                pgpAssertNoErr(err);

                /* If a second 'v' (keyChar = V), show signatures too */
                status = viewKeyring(mainbPtr, argsPrivbPtr->mcguffin,
						argsPrivbPtr->myArgc == 4 ? ringfilespec : NULL,
						origRingFileName,
                        (keyChar == 'V' ? kShow_Sigs | kShow_Subkeys : 0)
                        | (argsPrivbPtr->cFlag ? kShow_Hashes : 0)
                        /*| (verbose ? kShow_Subkeys : 0)*/
                                    );

                PGPFreeFileSpec(ringfilespec);
            }

            if( status < 0 ) {
                fprintf(filebPtr->pgpout, LANG("\007Keyring view error. "));
                *perrorLvl = KEYRING_VIEW_ERROR;
            }
            goto out;
        }   /* view key ring entries, with userid match */

    default:
        argError(filebPtr,perrorLvl);
        status=-1;
        goto out;
    }
    status=0;

out:
    PGPFreeFileSpec( pubringSpec );
    PGPFreeFileSpec( secringSpec );
    PGPFreeData( pubringName );
    PGPFreeData( secringName );
    return status;
}

/* We had to process the config file first to possibly select the
   foreign language to translate the sign-on line that follows... */

void signonMsg(struct pgpmainBones *mainbPtr)
{
    struct pgpenvBones  *envbPtr = mainbPtr->envbPtr;
    struct pgpfileBones *filebPtr = mainbPtr->filebPtr;
    PGPTime tstamp;
    PGPEnv *env = envbPtr->m_env; PGPInt32  pri; PGPError err;
    /* display message only once to allow calling multiple times */
    static PGPBoolean printed = FALSE;
    PGPBoolean compatible = envbPtr->compatible;

    if ( pgpenvGetInt( env, PGPENV_NOOUT, &pri, &err ) || printed )
        return;
    printed = TRUE;

    fprintf(stderr,
LANG("Pretty Good Privacy(tm) Version %s"),
            mainbPtr->relVersion);

    if (compatible) fprintf(stderr,
LANG("- Public-key encryption for the masses."));

    fprintf(stderr, "\n");

#if PGP_DEBUG
    fputs( LANG(
"Internal development version only - not for general release.\n"),
        stderr);
#endif
    fprintf(stderr, LANG("(c) 1999 Network Associates Inc.\n"));
	fputs( LANG(mainbPtr->signonLegalese), stderr);
    fprintf(stderr, "\n");

    fputs(
LANG("Export of this software may be restricted by the U.S. government.\n"),
          stderr);

    if (compatible) {
        tstamp = PGPGetTime();
        fprintf(filebPtr->pgpout, LANG("Current time: %s\n\n"),
           ctdate(&tstamp));
    }
	else
	{
		fputs("\n", stderr);
	}

}

/* -f means act as a unix-style filter */
/* -i means internalize extended file attribute information, only supported
 *          between like (or very compatible) operating systems. */
/* -l means show longer more descriptive diagnostic messages */
/* -m means display plaintext output on screen, like unix "more" */
/* -d means decrypt only, leaving inner signature wrapping intact */
/* -t means treat as pure text and convert to canonical text format */

/* Used by getopt function... */
#define OPTIONS "abcdefghiklmn:o:prstu:vwxz:ABCDEFGHIKLMN:O:PRSTU:VWX?"

/* unused option flags: j, q, y*/

int pgpParseArgs(struct pgpmainBones *mainbPtr, int argc, char *argv[],
        int *perrorLvl)
{
    PGPContextRef context = mainbPtr->pgpContext;
    int opt;
    char *p;
    struct pgpenvBones   *envbPtr = mainbPtr->envbPtr;
    struct pgpargsBones  *argsbPtr = mainbPtr->argsbPtr;
    struct pgpargsPBones *argsPrivbPtr = argsbPtr->argsPrivbPtr;
    struct pgpfileBones  *filebPtr = mainbPtr->filebPtr;
    PGPEnv *env = envbPtr->m_env;
    PGPError err;
    extern int optind;
    extern char *optarg;

    /* Initial messages to stderr */
    filebPtr->pgpout = stderr;

#ifdef DEBUG1
    pgpenvSetInt( env, PGPENV_VERBOSE,  TRUE, PGPENV_PRI_FORCE );
    /*filebPtr->verbose = TRUE;*/
#endif		  

	/* set FASTKEYGEN to TRUE */
	pgpenvSetInt( env, PGPENV_FASTKEYGEN, TRUE, PGPENV_PRI_PRIVDEFAULT);

    /* The various places one can get passwords from.
     * We accumulate them all into two lists.  One is
     * to try on keys only, and is stored in no particular
     * order, while the other is of unknown purpose so
     * far (they may be used for conventional encryption
     * or decryption as well), and are kept in a specific
     * order.  If any password in the general list is found
     * to decode a key, it is moved to the key list.
     * The general list is not grown after initialization,
     * so the tail pointer is not used after this.
     */

    if ((p = getenv("PGPPASS")) != NULL) {
        if((err = pgpAppendToPassphraseList( envbPtr->passwds, p )) != 0) {
            *perrorLvl = OUT_OF_MEM;
            return -1;
        }
    }

    /* The -z "password" option should be used instead of PGPPASS if
     * the environment can be displayed with the ps command (eg. BSD).
     * If the system does not allow overwriting of the command line
     * argument list but if it has a "hidden" environment, PGPPASS
     * should be used.
     */
    for (opt = 1; opt < argc; ++opt) {
        p = argv[opt];
        if (p[0] != '-' || p[1] != 'z')
            continue;
        /* Accept either "-zpassword" or "-z password" */
        p += 2;
        if (!*p)
            p = argv[++opt];
        /* p now points to password */
        if (!p)
            break;  /* End of arg list - ignore */

        if((err = pgpAppendToPassphraseList( envbPtr->passwds, p )) != 0) {
            *perrorLvl = OUT_OF_MEM;
            return -1;
        }
        /* Wipe password */
        while (*p)
            *p++ = ' ';
    }
    /*
     * If PGPPASSFD is set in the environment try to read the password
     * from this file descriptor.  If you set PGPPASSFD to 0 pgp will
     * use the first line read from stdin as password.
     */
    if ((p = getenv("PGPPASSFD")) != NULL) {
        int passfd;
        if (*p && (passfd = atoi(p)) >= 0) {
            char pwbuf[256];
            p = pwbuf;
            while (read(passfd, p, 1) == 1 && *p != '\n')
                ++p;
            *p='\0';

            if((err = pgpAppendToPassphraseList( envbPtr->passwds,
                    pwbuf )) != 0) {
                *perrorLvl = OUT_OF_MEM;
                return -1;
            }
            memset(pwbuf, 0, p - pwbuf);
        }
    }
    /* Process the config file.  The following override each other:
       - Hard-coded defaults
       - The system config file
       - Hard-coded defaults for security-critical things
       - The user's config file
       - Environment variables
       - Command-line options.
     */
    opt = 0;   /* Number of config files read */
#ifdef PGP_SYSTEM_DIR
    strcpy(argsPrivbPtr->mcguffin, PGP_SYSTEM_DIR);
    strcat(argsPrivbPtr->mcguffin, "config.txt");
    if (access(argsPrivbPtr->mcguffin, 0) == 0) {
        opt++;
        /*
         * Note: errors here are NOT fatal, so that people
         * can use PGP with a corrputed system file.
         */
        processConfigFile( envbPtr, argsPrivbPtr->mcguffin,
                PGPENV_PRI_SYSCONF);

    }
#endif


    /*
       This new Preferences interface seems problematic for us.  It is
       somewhat inflexible, being a binary file that is difficult
       for users to edit; and it is incompatible with the system of
       overrides established by the Config file processing.

       A command-line user still ought to be able to set preferences
       by editing her config file and using the names
           PUBRING, SECRING, RANDSEED, MYNAME, and GROUPSFILE

       In fact, if the user specifies on the command line
           +pubring=pathtothepubring
       then PGP is likely to set the pubring preference to that and
       leave it that way, unless it's also set in the config file.
       I guess that's acceptible.
     */

    {
        PGPByte *keyIDData = NULL;
        PGPSize  keyIDSize = 0;
        PGPKeyID keyID;
        char myname[ kPGPMaxKeyIDStringSize ];

        /* set myname based on default signing key in prefs*/
        err = PGPsdkPrefGetData( context, kPGPsdkPref_DefaultKeyID,
                (void **)&keyIDData, &keyIDSize );

        switch(err)
        {
            case kPGPError_PrefNotFound:
                myname[0]='\0';
                break;
            case kPGPError_NoErr:
                err = PGPImportKeyID( keyIDData, &keyID );
                pgpAssertNoErr(err);
                err = PGPGetKeyIDString( &keyID, kPGPKeyIDString_Full,
                        myname );
                pgpAssertNoErr(err);
                PGPFreeData( keyIDData );
                break;
            default:
                break;
        }
        if ( IsntPGPError(err) )
            pgpenvSetString( env, PGPENV_MYNAME, myname,
                    PGPENV_PRI_PRIVDEFAULT );

    }


    /* Process the config file first.  Any command-line arguments will
       override the config file settings */
#if defined(PGP_UNIX) || defined(MSDOS) || defined(WIN32) || defined(OS2)
    /* Try "pgp.ini" on MS-DOS or ".pgprc" on Unix */
 #ifdef PGP_UNIX
    buildFileName(argsPrivbPtr->mcguffin, "pgp.cfg");
    /* look for a 5.0i config file */

    if(access(argsPrivbPtr->mcguffin, 0) != 0)
       buildFileName(argsPrivbPtr->mcguffin, ".pgprc");
 #elif PGP_WIN32
    buildFileName(argsPrivbPtr->mcguffin, "pgp.cfg");
 #else
    buildFileName(argsPrivbPtr->mcguffin, "pgp.ini");
 #endif
    if (access(argsPrivbPtr->mcguffin, 0) != 0)
        buildFileName(argsPrivbPtr->mcguffin, "config.txt");
#else
    buildFileName(argsPrivbPtr->mcguffin, "config.txt");
#endif
    if (access(argsPrivbPtr->mcguffin, 0) == 0) {
        opt++;
        if (processConfigFile( envbPtr, argsPrivbPtr->mcguffin,
                PGPENV_PRI_CONFIG) < 0) {

            *perrorLvl=BAD_ARG_ERROR;
            /*exit(BAD_ARG_ERROR);*/
            return -1;
        }
    }
    if (!opt)
        fprintf(filebPtr->pgpout,
                LANG("\007No configuration file found.\n"));

    init_charset();

#ifdef MSDOS   /* only on MSDOS systems */
    if ((p = getenv("TZ")) == NULL || *p == '\0') {
		if (_timezone == 0) {
			fprintf(filebPtr->pgpout,LANG(
	"\007WARNING: Environmental variable TZ is not \
	defined, so GMT timestamps\n\
	may be wrong.  See the PGP User's Guide to properly define TZ\n"));
	    }
	}
#endif    /* MSDOS */

#ifdef VMS
#define TEMP "SYS$SCRATCH"
#else
#define TEMP "TMP"
#endif    /* VMS */
    if ((p = getenv(TEMP)) != NULL && *p != '\0')
        setTempDir( filebPtr, p );

    if ((argsPrivbPtr->myArgv = (char **) malloc(
            (argc + 2) * sizeof(char **))) == NULL) {

        fprintf(stderr, LANG("\n\007Out of memory.\n"));
        *perrorLvl = 7;
        return -1;
    }
    argsPrivbPtr->myArgv[0] = NULL;
    argsPrivbPtr->myArgv[1] = NULL;

    /* Process all the command-line option switches: */
    while (optind < argc) {
        /*
         * Allow random order of options and arguments (like GNU getopt)
         * NOTE: this does not work with GNU getopt, use getopt.c from
         * the PGP distribution.
         */
        if ((opt = pgpGetOpt(argc, argv, OPTIONS)) == EOF) {
            if (optind == argc) /* -- at end */
                break;
            argsPrivbPtr->myArgv[argsPrivbPtr->myArgc++] = argv[optind++];
            continue;
        }
        opt = toLower(opt);
        if (argsbPtr->keyFlag && (argsbPtr->keyChar == '\0' ||
                (argsbPtr->keyChar == 'v' && opt == 'v'))) {

            if (argsbPtr->keyChar == 'v')
                argsbPtr->keyChar = 'V';
            else
                argsbPtr->keyChar = opt;
            continue;
        }
        if (argsbPtr->groupFlag && (argsbPtr->groupChar == '\0' ||
                (argsbPtr->groupChar == 'v' && opt == 'v'))) {

            if (argsbPtr->groupChar == 'v')
                argsbPtr->groupChar = 'V';
            else
                argsbPtr->groupChar = opt;
            continue;
        }

        switch (opt) {
        case 'a':
            argsbPtr->armorFlag = TRUE;
            pgpenvSetInt( env, PGPENV_ARMOR,  1, PGPENV_PRI_CMDLINE );
            break;
        case 'b':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -