1 /*
2  * fiked - a fake IKE PSK+XAUTH daemon based on vpnc
3  * Copyright (C) 2005, Daniel Roethlisberger <daniel@roe.ch>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, see http://www.gnu.org/copyleft/
17  *
18  * $Id: results.c 114 2005-12-24 12:00:33Z roe $
19  */
20 
21 #include "results.h"
22 
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <string.h>
31 #include <errno.h>
32 
33 static FILE* file = NULL;
34 
results_init(char * filename)35 void results_init(char *filename)
36 {
37 	results_cleanup();
38 	file = fopen(filename, "a");
39 	if(!file) {
40 		fprintf(stderr, "FATAL: cannot open file %s: %s\n", filename,
41 			strerror(errno));
42 		exit(-1);
43 	}
44 }
45 
results_add(peer_ctx * ctx)46 void results_add(peer_ctx *ctx)
47 {
48 	if(file) {
49 		char timestamp[1024];
50 		time_t epoch = time(0);
51 		strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S %z",
52 			localtime(&epoch));
53 		fprintf(file, "%s %s %s %s %s %s %s\n", timestamp,
54 			ctx->cfg->gateway, ctx->ipsec_id, ctx->ipsec_secret,
55 			inet_ntoa(ctx->peer_addr.sin_addr),
56 			ctx->xauth_username, ctx->xauth_password);
57 		fflush(file);
58 	}
59 }
60 
results_cleanup()61 void results_cleanup()
62 {
63 	if(file) {
64 		fclose(file);
65 		file = NULL;
66 	}
67 }
68