Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

cf.c File Reference

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Include dependency graph for cf.c:

Include dependency graph

Go to the source code of this file.

Functions

int main (int, char **)
void doone (FILE *, FILE *)
volatile void usage (void)

Variables

const char copyright []
const char rcsid []
char * argv0
char * optarg
int optind
int opterr
int preserve = 0
int strict = 0
int utc = 0
char * fmt = "%b %e %H:%M:%S"
char * lfmt = "%b %e %H:%M:%S %Y"


Function Documentation

void doone FILE *  ,
FILE * 
 

Definition at line 124 of file cf.c.

References fmt, fputs(), preserve, strftime(), strict, and utc.

00126 {
00127         time_t t;
00128         register char *bp, *dotbp;
00129         register struct tm *tp;
00130         register int dot_count;
00131         char buf[1024], ts[128];
00132 
00133         while (fgets(buf, sizeof(buf), fin)) {
00134                 bp = buf;
00135                 dotbp = NULL;
00136                 if (isdigit(*bp)) {
00137                         t = atol(bp);
00138                         ++bp;
00139                         dot_count = 0;
00140                         while (isdigit(*bp) || *bp == '.') {
00141                                 if (*bp == '.') {
00142                                         dotbp = bp;
00143                                         ++dot_count;
00144                                 }
00145                                 ++bp;
00146                         }
00147                         if (strict && (bp - buf < 9 || dot_count > 1 ||
00148                             (bp - buf > 10 && dot_count != 1))) {
00149                                 /* Doesn't look like a genuine timestamp -
00150                                  * skip it.
00151                                  */
00152                                 fputs(buf, fout);
00153                                 continue;
00154                         }
00155                         if (!utc)
00156                                 tp = localtime(&t);
00157                         else
00158                                 tp = gmtime(&t);
00159                         (void)strftime(ts, sizeof(ts), fmt, tp);
00160                         fputs(ts, fout);
00161                         if (preserve && dotbp != NULL)
00162                                 bp = dotbp;
00163                 }
00164                 fputs(bp, fout);
00165         }
00166 }

int main int  ,
char ** 
 

Definition at line 109 of file bdcat.cc.

00110         {
00111         char* keyfile = getenv("BDCAT_KEY");
00112 
00113         // Read options.
00114         char op;
00115         while ( (op = getopt(argc, argv, "k:")) >= 0 )
00116                 {
00117                 if ( op == 'k' )
00118                         keyfile = optarg;
00119                 else
00120                         Usage();
00121                 }
00122 
00123         if ( ! keyfile )
00124                 {
00125                 fputs("no keyfile given\n", stderr);
00126                 exit(1);
00127                 }
00128 
00129         // Init crypto.
00130 
00131         ERR_load_crypto_strings();
00132         OpenSSL_add_all_algorithms();
00133 
00134         FILE* f = fopen(keyfile, "r");
00135         if ( ! f )
00136                 {
00137                 fprintf(stderr, "can't open key file %s: %s\n",
00138                                 keyfile, strerror(errno));
00139                 exit(1);
00140                 }
00141 
00142         SecKey = PEM_read_PrivateKey(f, 0, 0, 0);
00143         if ( ! SecKey )
00144                 {
00145                 fprintf(stderr, "can't read key from %s: %s\n", keyfile,
00146                                 ERR_error_string(ERR_get_error(), 0));
00147                 exit(1);
00148                 }
00149 
00150         fclose(f);
00151 
00152         // Depending on the OpenSSL version, EVP_*_cbc()
00153         // returns a const or a non-const.
00154         CipherType = (EVP_CIPHER*) EVP_bf_cbc();
00155 
00156         // Decrypt the files.
00157         if ( optind == argc )
00158                 cryptcat(stdin);
00159         else
00160                 {
00161                 while ( optind < argc )
00162                         {
00163                         FILE* f = fopen(argv[optind], "r");
00164                         if ( ! f )
00165                                 {
00166                                 fprintf(stderr, "can't open %s: %s\n",
00167                                                 argv[optind], strerror(errno));
00168                                 exit(1);
00169                                 }
00170 
00171                         cryptcat(f);
00172                         ++optind;
00173                         }
00174                 }
00175         }

void usage void   ) 
 

Definition at line 169 of file cf.c.

References argv0, and version.

Referenced by main().

00170 {
00171         extern char version[];
00172 
00173         (void)fprintf(stderr, "%s version %s\n", argv0, version);
00174         (void)fprintf(stderr, "usage: %s [-f fmt] [-lpsu] [file ...]\n", argv0);
00175         exit(1);
00176 }


Variable Documentation

char* argv0 [static]
 

Definition at line 39 of file cf.c.

Referenced by usage().

const char copyright[] [static]
 

Initial value:

    "@(#) Copyright (c) 1991, 1994, 1995, 1996, 1998, 1999, 2001, 2004\n\
The Regents of the University of California.  All rights reserved.\n"

Definition at line 23 of file cf.c.

char* fmt = "%b %e %H:%M:%S"
 

Definition at line 47 of file cf.c.

Referenced by bpf_error(), bpf_image(), debug_msg(), doone(), dotted_addr(), gripe(), internal_error(), key_kprint(), TraceState::LogTrace(), Number::Number(), Output::print(), Output::println(), and run_time().

char* lfmt = "%b %e %H:%M:%S %Y"
 

Definition at line 48 of file cf.c.

char* optarg
 

Definition at line 41 of file cf.c.

int opterr
 

Definition at line 42 of file cf.c.

int optind
 

Definition at line 42 of file cf.c.

int preserve = 0
 

Definition at line 44 of file cf.c.

Referenced by doone().

const char rcsid[] [static]
 

Initial value:

    "@(#) $Id: cf.c,v 1.1 2004/12/09 04:25:29 jason Exp $ (LBL)"

Definition at line 26 of file cf.c.

int strict = 0
 

Definition at line 45 of file cf.c.

Referenced by doone().

int utc = 0
 

Definition at line 46 of file cf.c.

Referenced by doone().


Generated on Wed Sep 14 02:57:35 2005 for bro_docs by doxygen 1.3.5