📄 config.c
字号:
/*____________________________________________________________________________
config.c
Copyright(C) 1998,1999 Network Associates, Inc.
All rights reserved.
PGP 6.5 Command Line
Parses config file for PGP
Modified 24 Jun 92 - HAJK
Misc fixes for VAX C restrictions
Updated by Peter Gutmann to only warn about unrecognized options,
so future additions to the config file will give old versions a
chance to still run. A number of code cleanups, too.
$Id: config.c,v 1.14.6.1 1999/06/11 17:51:02 sluu Exp $
____________________________________________________________________________*/
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "usuals.h"
#include "pgp.h"
#include "config.h"
#include "globals.h"
#include "fileio.h"
#include "language.h"
/*#include "charset.h"*/
/* from the SDK....*/
#include "pgpSDKPrefs.h"
#include "pgpEnv.h"
#include "pgpContext.h"
/*
* Set Integer and String configuration parameters. Strings are
* copied by the environment; the caller need not preserve them.
* (They must, of course, be null-terminated.)
*/
static struct pgpenvBones _envBones;
void initEnvBones(struct pgpmainBones *mainbPtr)
{
PGPEnv *env = pgpContextGetEnvironment( mainbPtr->pgpContext );
PGPContextRef context = mainbPtr->pgpContext;
struct pgpenvBones *envbPtr = &_envBones;
char version[256];
envbPtr->m_env = env;
pgpenvSetInt( env, PGPENV_ARMOR, FALSE, PGPENV_PRI_PUBDEFAULT );
/* armorlines */
/* max_cert_depth */
pgpenvSetString( env, PGPENV_CHARSET, "noconv", PGPENV_PRI_PUBDEFAULT);
/* charset */
pgpenvSetInt( env, PGPENV_CLEARSIG, TRUE, PGPENV_PRI_PUBDEFAULT );
/* comment */ /*pgpenvGetCString( env, PGPENV_COMMENT, &pri )[128];*/
/* compl_min */
pgpenvSetInt( env, PGPENV_COMPRESS, TRUE, PGPENV_PRI_PUBDEFAULT );
/* attempt compression before encryption */
/* companykey */
pgpenvSetInt( env, PGPENV_ENCRYPTTOSELF, FALSE, PGPENV_PRI_PUBDEFAULT);
/* should I encrypt messages to myself? */
envbPtr->interactiveAdd = FALSE; /* Ask for each key separately if
it should be added to the keyring */
pgpenvSetString( env, PGPENV_LANGUAGE, "en", PGPENV_PRI_PUBDEFAULT );
/* language */
/* marg_min */
/* my_name is substring of default userid for secret key to make
signatures */
pgpenvSetString( env, PGPENV_MYNAME, "", PGPENV_PRI_PUBDEFAULT );
/* null my_name means take first userid in ring */
/* pager */
{
char *p=getenv("PAGER");
strncpy( envbPtr->pager, p ? p : "", MAX_PATH );
envbPtr->pager[MAX_PATH]='\0';
}
/* pkcs_compat */
/* pgp_mime */
/* pgp_mimeparse */
/* randomdevice */
#if PGP_UNIX
/* randsource */
#endif
envbPtr->bShowpass = FALSE;
#ifdef VMS
/* kludge for those stupid VMS variable-length text records.
this probably doesn't work anymore. */
pgpenvSetInt( env, PGPENV_TEXTMODE, TRUE, PGPENV_PRI_PUBDEFAULT );
/* MODE_TEXT (TRUE) or MODE_BINARY (FALSE) for literal packet */
#else /* not VMS */
pgpenvSetInt( env, PGPENV_TEXTMODE, FALSE, PGPENV_PRI_PUBDEFAULT );
/* MODE_TEXT or MODE_BINARY for literal packet */
#endif /* not VMS */
/* tmp */
/* trusted */
pgpenvSetInt( env, PGPENV_TZFIX, 0L, PGPENV_PRI_PUBDEFAULT );
/* seconds from GMT timezone */
pgpenvSetInt( env, PGPENV_VERBOSE, FALSE, PGPENV_PRI_PUBDEFAULT );
/* -l option: display maximum information */
pgpenvSetInt( env, PGPENV_VERSION, VERSION_BYTE_NEW,
PGPENV_PRI_PUBDEFAULT );
/* ciphernum */
/* hashnum */
/* fastkeygen */
pgpenvSetInt( env, PGPENV_BATCHMODE, FALSE, PGPENV_PRI_PUBDEFAULT );
/* if TRUE: don't ask questions */
pgpenvSetInt( env, PGPENV_FORCE, FALSE, PGPENV_PRI_PUBDEFAULT );
/* overwrite existing file without asking */
/* magic */
pgpenvSetInt( env, PGPENV_NOOUT, FALSE, PGPENV_PRI_PUBDEFAULT );
envbPtr->moreFlag = FALSE; /* for your eyes only */
envbPtr->filterMode = FALSE;
envbPtr->passThrough = FALSE;
envbPtr->noManual = TRUE;
/* at the request of Jon Callas, nomanual is disabled. */
/* If non-zero, initialize file to this many random bytes */
envbPtr->makeRandom = 0;
#ifdef USER_INTERFACE_COMPATIBLE
/*
If PGP is running in an environment where you want user interface
compatibility with older PGP versions, use this compile-time
switch To make compatible the default.
Note that you can specify a value to override this in the config
file or as a long option on the command line.
*/
envbPtr->compatible = TRUE;
#else
envbPtr->compatible = FALSE;
#endif
pgpNewPassphraseList( context, &envbPtr->passwds );
sprintf(version, "PGP %s",mainbPtr->relVersion);
pgpenvSetString( env, PGPENV_VERSION_STRING, version,
PGPENV_PRI_PUBDEFAULT);
envbPtr->mainbPtr = mainbPtr;
mainbPtr->envbPtr = envbPtr;
}
/* Various maximum/minimum allowable settings for config options */
#define MIN_MARGINALS 1
#define MIN_COMPLETE 1
#define MAX_COMPLETE 4
#define MIN_CERT_DEPTH 0
#define MAX_CERT_DEPTH 8
/* Prototypes for local functions */
static int lookup( char *key,
unsigned int keyLength,
char *keyWords[],
unsigned int range );
static int extractToken( char *buffer, int *endIndex, int *length );
static int getaString( char *buffer, int *endIndex );
static int getAssignment( char *buffer, int *endIndex, INPUT_TYPE
settingType );
static void processAssignment( struct pgpenvBones *envbPtr, int
intrinsicIndex, PGPInt32 pri);
/* The external config variables we can set here are referenced in pgp.h */
/* Return values */
#define ERROR -1
#define OK 0
/* The types of error we check for */
enum { NO_ERROR, ILLEGAL_CHAR_ERROR, LINELENGTH_ERROR };
#define CPM_EOF 0x1A /* ^Z = CPM EOF char */
#define MAX_ERRORS 3 /* Max.no.errors before we give up */
#define LINEBUF_SIZE 100 /* Size of input buffer */
static int line; /* The line on which an error occurred */
static int errCount; /* Total error count */
static PGPBoolean hasError; /* Whether this line has an error in it */
/* The settings parsed out by getAssignment() */
static char str[ LINEBUF_SIZE ];
static int value;
static char *errtag; /* Prefix for printing error messages */
static char optstr[ 100 ]; /* Option being processed */
/* A .CFG file roughly follows the format used in the world-famous HPACK
archiver and is as follows:
- Leading spaces/tabs (whitespace) are ignored.
- Lines with a '#' as the first non-whitespace character are treated
as comment lines.
- All other lines are treated as config options for the program.
- Lines may be terminated by either linefeeds, carriage returns, or
carriage return/linefeed pairs (the latter being the DOS default
method of storing text files).
- Config options have the form:
<option> '=' <setting>
where <setting> may be 'on', 'off', a numeric value, or a string
value.
- If strings have spaces or the '#' character inside them they must be
surrounded by quote marks '"' */
/* Intrinsic variables */
#define NO_INTRINSICS (sizeof(intrinsics) / sizeof(intrinsics[0]))
#define CONFIG_INTRINSICS BATCHMODE
enum {
ARMOR, COMPRESS, SHOWPASS, KEEPBINARY, LANGUAGE,
MYNAME, TEXTMODE, TMP, TZFIX, VERBOSE, BAKRING,
ARMORLINES, COMPLETES_NEEDED, MARGINALS_NEEDED, PAGER,
CERT_DEPTH, CHARSET, CLEAR, SELF_ENCRYPT,
INTERACTIVE, PUBRING, SECRING, RANDSEED, RANDOMDEVICE,
GROUPSFILE, COMPATIBLE, KEYSERVER_URL, PGP_MIME,
PGP_MIMEPARSE, COMMENT,
TRUSTED, VERSION, CIPHERNUM, HASHNUM, FASTKEYGEN,
/* options below this line can only be used as command line
* "long" options */
BATCHMODE, FORCE, PASSTHROUGH, NOMANUAL, MAKERANDOM
};
static char *intrinsics[] = {
"ARMOR", "COMPRESS", "SHOWPASS", "KEEPBINARY", "LANGUAGE",
"MYNAME", "TEXTMODE", "TMP", "TZFIX", "VERBOSE", "BAKRING",
"ARMORLINES", "COMPLETES_NEEDED", "MARGINALS_NEEDED", "PAGER",
"CERT_DEPTH", "CHARSET", "CLEARSIG", "ENCRYPTTOSELF",
"INTERACTIVE", "PUBRING", "SECRING", "RANDSEED", "RANDOMDEVICE",
"GROUPSFILE", "COMPATIBLE", "KEYSERVER_URL", "PGP_MIME",
"PGP_MIMEPARSE", "COMMENT",
"TRUSTED", "VERSION", "CIPHERNUM", "HASHNUM", "FASTKEYGEN",
/* command line only */
"BATCHMODE", "FORCE", "PASSTHROUGH", "NOMANUAL", "MAKERANDOM"
};
static INPUT_TYPE intrinsicType[] = {
BOOLE, BOOLE, BOOLE, BOOLE, STRING,
STRING, BOOLE, STRING, NUMERIC, NUMERIC, STRING,
NUMERIC, NUMERIC, NUMERIC, STRING,
NUMERIC, STRING, BOOLE, BOOLE,
BOOLE, STRING, STRING, STRING, STRING,
STRING, BOOLE, STRING, BOOLE,
BOOLE, STRING,
NUMERIC, NUMERIC, NUMERIC, NUMERIC, BOOLE,
/* command line only */
BOOLE, BOOLE, BOOLE, BOOLE, NUMERIC
};
/* Possible settings for variables */
#define NO_SETTINGS 2
static char *settings[] = { "OFF", "ON" };
/* Search a list of keywords for a match */
static int lookup( char *key,
unsigned int keyLength,
char *keyWords[],
unsigned int range )
{
unsigned int index;
int position = 0, noMatches = 0;
strncpy( optstr, key, keyLength );
optstr[ keyLength ] = '\0';
/* Make the search case insensitive */
for( index = 0; index < keyLength; index++ )
key[ index ] = toUpper( key[ index ] );
for( index = 0; index < range; index++ )
if( !strncmp( key, keyWords[ index ], keyLength ) )
{
if( strlen( keyWords[ index ] ) == keyLength )
return index; /* exact match */
position = index;
noMatches++;
}
switch( noMatches )
{
case 0:
fprintf( stderr, LANG("%s: unknown keyword: \"%s\"\n"),
errtag, optstr );
break;
case 1:
return( position ); /* Match succeeded */
default:
fprintf( stderr, LANG("%s: \"%s\" is ambiguous\n"),
errtag, optstr );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -