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

📄 config.c

📁 PGP—Pretty Good Privacy
💻 C
📖 第 1 页 / 共 3 页
字号:

                break;

            case RANDSEED:
                pgpenvSetString( env, PGPENV_RANDSEEDnolongerused, str,
                        pri );

                if( pri >= PGPENV_PRI_CONFIG )
                {
                    PGPFileSpecRef rndfilespec;
                    char rndfile[MAX_PATH+1];
                    strcpy(rndfile,str);
                    /*force_extension( rndfile, ".pkr", filebPtr);*/
                    err = PGPNewFileSpecFromFullPath( context, rndfile,
                            &rndfilespec );

                    pgpAssertNoErr(err);
                    err = PGPsdkPrefSetFileSpec( context,
                            kPGPsdkPref_RandomSeedFile, rndfilespec);

                    pgpAssertNoErr(err);
                    PGPFreeFileSpec( rndfilespec );
                }
                break;

            case RANDOMDEVICE:
                pgpenvSetString( env, PGPENV_RANDOMDEVICE, str, pri );
                break;

            case SECRING:
                pgpenvSetString( env, PGPENV_SECRINGnolongerused, str, pri );

                if( pri >= PGPENV_PRI_CONFIG )
                {
                    PGPFileSpecRef secfilespec;
                    char secring[MAX_PATH+1];
                    strcpy(secring,str);
                    /*force_extension( secring, ".skr", filebPtr);*/
                    err = PGPNewFileSpecFromFullPath( context, secring,
                            &secfilespec );

                    pgpAssertNoErr(err);
                    err = PGPsdkPrefSetFileSpec( context,
                            kPGPsdkPref_PrivateKeyring, secfilespec);

                    pgpAssertNoErr(err);
                    PGPFreeFileSpec( secfilespec );
                }
                break;

            case GROUPSFILE:

                if( pri >= PGPENV_PRI_CONFIG )
                {
                    PGPFileSpecRef grpfilespec;
                    char grpfile[MAX_PATH+1];
                    strcpy(grpfile,str);
                    /*force_extension( grpfile, ".skr", filebPtr);*/
                    err = PGPNewFileSpecFromFullPath( context, grpfile,
                            &grpfilespec );

                    pgpAssertNoErr(err);
                    err = PGPsdkPrefSetFileSpec( context,
                            kPGPsdkPref_GroupsFile, grpfilespec);

                    pgpAssertNoErr(err);
                    PGPFreeFileSpec( grpfilespec );
                }
                break;

            case SELF_ENCRYPT:
                pgpenvSetInt( env, PGPENV_ENCRYPTTOSELF,  value, pri );
                break;

            case SHOWPASS:
				envbPtr->bShowpass = value;
				break;

            case TEXTMODE:
                if( value )
                    pgpenvSetInt( env, PGPENV_TEXTMODE,  TRUE, pri );
                else
                    pgpenvSetInt( env, PGPENV_TEXTMODE,  FALSE, pri );
                break;

            case TMP:
                /* directory pathname to store temp files */
                pgpAssertAddrValid( envbPtr->mainbPtr, struct pgpmainBones);
                setTempDir( envbPtr->mainbPtr->filebPtr, str );
                break;

            case TRUSTED:
                pgpenvSetInt( env, PGPENV_TRUSTED, value, pri );
                break;

            case CIPHERNUM:
                pgpenvSetInt( env, PGPENV_CIPHER, value, pri );
                break;

            case HASHNUM:
                pgpenvSetInt( env, PGPENV_HASH, value, pri );
                break;

            case TZFIX:
                /* How many hours to add to time() to get GMT.
                   We just compute the seconds from hours to
                   get the GMT shift */
                pgpenvSetInt( env, PGPENV_TZFIX,  3600L * ( long ) value,
                        pri );

                break;

            case VERBOSE:
                if( value < 1 )
                {
                    pgpenvSetInt( env, PGPENV_NOOUT,  TRUE, pri );
                    pgpenvSetInt( env, PGPENV_VERBOSE,  FALSE, pri );
                }
                else
                    if( value == 1 )
                    {
                        pgpenvSetInt( env, PGPENV_NOOUT,  FALSE, pri );
                        pgpenvSetInt( env, PGPENV_VERBOSE,  FALSE, pri );
                    }
                    else
                    {
                        /* Value > 1 */
                        pgpenvSetInt( env, PGPENV_NOOUT,  FALSE, pri );
                        pgpenvSetInt( env, PGPENV_VERBOSE,  TRUE, pri );
                    }
                break;

            case VERSION:
                pgpenvSetInt( env, PGPENV_VERSION, value, pri );
                break;

        }
}

/* Process an option on a line by itself.  This expects options which are
   taken from the command-line, and is less finicky about errors than the
   config-file version */

int processConfigLine( struct pgpenvBones *envbPtr, char *option,
        PGPInt32 pri )
{
    unsigned int index;
	int intrinsicIndex;
    char ch;

    /* Give it a pseudo-linenumber of 0 */
    line = 0;

    errtag = "pgp";
    errCount = 0;
    for( index = 0;
            index < LINEBUF_SIZE && ( ch = option[ index ] ) != '\0' &&
            ch != ' ' && ch != '\t' && ch != '=';
            index++ );
    if( ( intrinsicIndex = lookup( ( char * ) option, index, intrinsics,
            NO_INTRINSICS ) ) == ERROR )
        return -1;
    if( option[ index ] == '\0' && intrinsicType[ intrinsicIndex ] == BOOLE)
    {
        /* Boolean option, no '=' means TRUE */
        value = TRUE;
        processAssignment( envbPtr, intrinsicIndex, pri );
    }
    else
        /* Get the value to set to, either as a string, a numeric
           value, or a PGPBoolean flag */
        if( getAssignment( ( char * ) option + index,
                &index, intrinsicType[ intrinsicIndex ] ) != ERROR )
            processAssignment( envbPtr, intrinsicIndex, pri );

    return errCount ? -1 : 0;
}

/* Process a configuration file */

int processConfigFile( struct pgpenvBones *envbPtr, char *configFileName,
        PGPInt32 pri )
{
    FILE *configFilePtr;
    int ch = 0, theChar;
    int errType, errPos = 0, lineBufCount, intrinsicIndex;
    unsigned int index;
    char inBuffer[ LINEBUF_SIZE ];

    line = 1;
    errCount = 0;
    errtag = fileTail( configFileName );

    if( ( configFilePtr = fopen( configFileName, FOPRTXT ) ) == NULL )
    {
        fprintf( stderr, LANG("Cannot open configuration file %s\n"),
                configFileName );
        return OK; /* Treat it as if it were an empty file */
    }

    /* Process each line in the configFile */
    while( ch != EOF )
    {
        /* Skip whitespace */
        while( ( ( ch = getc( configFilePtr ) ) == ' ' || ch == '\t' )
                && ch != EOF )
            ;

        /* Get a line into the inBuffer */
        hasError = FALSE;
        lineBufCount = 0;
        errType = NO_ERROR;
        while( ch != '\r' && ch != '\n' && ch != CPM_EOF && ch != EOF )
        {
            /* Check for an illegal char in the data */
            if( ( ch < ' ' || ch > '~' ) &&
                    ch != '\r' && ch != '\n' &&
                    ch != ' ' && ch != '\t' && ch != CPM_EOF &&
                    ch != EOF )
            {
                if( errType == NO_ERROR )
                    /* Save pos of first illegal char */
                    errPos = lineBufCount;
                errType = ILLEGAL_CHAR_ERROR;
            }

            /* Make sure the path is of the correct length.  Note
               that the code is ordered so that a LINELENGTH_ERROR
               takes precedence over an ILLEGAL_CHAR_ERROR */
            if( lineBufCount > LINEBUF_SIZE )
                errType = LINELENGTH_ERROR;
            else
                inBuffer[ lineBufCount++ ] = ch;

            if( ( ch = getc( configFilePtr ) ) == '#' )
            {
                /* Skip comment section and trailing
                   whitespace */
                while( ch != '\r' && ch != '\n' &&
                        ch != CPM_EOF && ch != EOF )
                    ch = getc( configFilePtr );
                break;
            }
        }

        /* Skip trailing whitespace and add der terminador */
        while( lineBufCount &&
                ( ( theChar = inBuffer[ lineBufCount - 1 ] ) == ' ' ||
                  theChar == '\t' ) )
            lineBufCount--;
        inBuffer[ lineBufCount ] = '\0';

        /* Process the line unless its a blank or comment line */
        if( lineBufCount && *inBuffer != '#' )
        {
            switch( errType )
            {
                case LINELENGTH_ERROR:
                    fprintf( stderr,
                            LANG("%s: line '%.30s...' too long\n"),
                            errtag, inBuffer );
                    errCount++;
                    break;

                case ILLEGAL_CHAR_ERROR:
                    fprintf( stderr, "> %s\n  ", inBuffer );
                    fprintf( stderr, "%*s^\n", errPos, "" );
                    fprintf( stderr, LANG(
                            "%s: bad character in command on line %d\n"),
                            errtag, line );
                    errCount++;
                    break;

                default:
                    for( index = 0;
                            index < LINEBUF_SIZE &&
                            ( ch = inBuffer[ index ] ) != '\0'
                            && ch != ' ' && ch != '\t'
                            && ch != '=';
                            index++ )
                        /*Do nothing*/ ;

                        /* Try and find the intrinsic.  We
                           don't treat unknown intrinsics as
                           an error to allow older versions to
                           be used with new config files */
                        intrinsicIndex = lookup(inBuffer,
                                index, intrinsics,
                                CONFIG_INTRINSICS );

                    if( intrinsicIndex == ERROR )
                        break;

                    /* Get the value to set to, either as
                       a string, a numeric value, or a
                       PGPBoolean flag */
                    getAssignment( inBuffer + index, &index,
                            intrinsicType[ intrinsicIndex ] );
                    processAssignment( envbPtr, intrinsicIndex, pri );
                    break;
            }
        }

        /* Handle special-case of ^Z if configFile came off an
           MSDOS system */
        if( ch == CPM_EOF )
            ch = EOF;

        /* Exit if there are too many errors */
        if( errCount >= MAX_ERRORS )
            break;

        line++;
    }

    fclose( configFilePtr );

    /* Exit if there were errors */
    if( errCount )
    {
        fprintf( stderr, LANG("%s: %s%d error(s) detected\n\n"),
                configFileName, ( errCount >= MAX_ERRORS ) ?
                LANG("Maximum level of ") : "", errCount );
        return ERROR;
    }

    return OK;
}

⌨️ 快捷键说明

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