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

📄 config.c

📁 加密解密,安全工具!很有意思的代码
💻 C
字号:
/*********************************************************************      Copyright (c) 1994-1999 Jetico, Inc., Finland*      All rights reserved.**      File: bccreate.c*      Revision: $Id: config.c,v 1.4 2002/10/29 07:11:31 crypt Rel-1.6-3 $*      Created:*      Description: implementation of config reading routine********************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <malloc.h>#include <ctype.h>#include "config.h"char config_c[]="$Id: config.c,v 1.4 2002/10/29 07:11:31 crypt Rel-1.6-3 $";alg_info *first=NULL;struct status{    char    *prefix;                /* bc device name prefix  */    int     alg_num;                /* total algorithms       */    int     lineno;                 /* last line read         */} runtime;int alloc_info_struct (alg_info **p){    *p = (alg_info *)malloc(sizeof(alg_info));       if ( !*p ) return NO_MEM;    if ( first==NULL )    {        first=*p;        first->next=first;    };    (*p)->next=first->next;    first->next=*p;    (*p)->key_size=0;    return NO_ERROR;}int read_token(FILE *file, char *buf, int buflen){    int c, error, len = 1, got_it = 0;    error = TOKEN_EMPTY;    while ( 1 )    {        if ( (c = fgetc(file)) < 0 ) goto end;        switch ( c )        {            case '\n':                runtime.lineno++;                if ( !got_it ) break;            case EOF:                error = TOKEN_OK;                goto end;            case '#':            case ';':                error = TOKEN_OK;                while ( 1 )                    if ( (c = fgetc(file)) < 0 ) goto end;                    else if ( c == '\n' ) break;                runtime.lineno++;                if ( !got_it ) break;                else goto end;            case ' ':            case '\t':                error = TOKEN_OK;                if ( !got_it ) break;                else goto end;                      case '\\':                if ( (c = fgetc(file)) < 0 ) goto end;            default:                got_it = 1;                *buf++ = tolower(c);                if ( ++len >= buflen )                {                    error = TOKEN_TRUNC;                    goto end;                }                else break;                           }           }    end:    *buf++ = 0;    return error;}void init_runtime_status(){    runtime.prefix  = 0;    runtime.alg_num = 0;    runtime.lineno  = 1;}int add_string(FILE *file, char **where_to){    char buf[1024];    if ( !file )        return FATAL_ERROR;    if ( read_token(file, buf, sizeof(buf)) != 0 )        return CONF_BAD_FILE;    *where_to = (char *)malloc(strlen(buf)+1);      if ( !*where_to )        return NO_MEM;    strcpy(*where_to, buf);    return 0;}int add_number(FILE *file, int *where_to){    char *err;    char buf[1024];    if ( !file )        return FATAL_ERROR;    if ( read_token(file, buf, sizeof(buf)) != 0 )        return CONF_BAD_FILE;    *where_to = strtol(buf, &err, 0);    if ( *err != '\0' )        return TOKEN_BAD;    else        return 0; }int read_conf(){    FILE    *file;    int i, rc;    char    buf[1024];    alg_info *ptr;//	if (!filename) return CONF_BAD_FNAME;    file = fopen(CONFIG_FILE, "r");    if ( !file ) return CONF_FOPEN_ERR;    init_runtime_status();    i = 0;    while ( !feof(file) )    {        rc = read_token(file, buf, sizeof(buf));        if ( TOKEN_EMPTY == rc )            return NO_ERROR;        if ( 0 > rc )            return CONF_BAD_FILE;        if ( !strcmp(buf, "module") )        {            if ( alloc_info_struct(&ptr) )                return NO_MEM;            if ( add_string(file, &ptr->mod_name) < 0 )                return CONF_BAD_FILE;            if ( add_number(file, &ptr->id) < 0 )                return CONF_BAD_FILE;            if ( add_number(file, &ptr->key_size) < 0 )                return CONF_BAD_FILE;            if ( add_string(file, &ptr->alg_name) < 0 )                return CONF_BAD_FILE;            i++;                }        if ( !strcmp(buf, "prefix") )        {            if ( add_string(file, &runtime.prefix) < 0 )                return CONF_BAD_FILE;        }        runtime.alg_num = i;    }    fclose(file);    return NO_ERROR;}alg_info *GetInfoById(int id){    alg_info *p;    p=first;    do    {        if ( p->id==id ) return p;        p=p->next;    }while ( p!=first );    return NULL;}alg_info *GetInfoByName(char *name){    alg_info *p;    p=first;    do    {        if ( !strcmp(p->alg_name, name) ) return p;        p=p->next;    }while ( p!=first );    return NULL;}char *GetPrefix(){    return runtime.prefix;} 

⌨️ 快捷键说明

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