Skip to content

Commit

Permalink
use exit_program() function to clean up values when racoon exits.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakane committed Aug 24, 2004
1 parent 14048cd commit 0d055d4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 18 deletions.
8 changes: 7 additions & 1 deletion kame/kame/racoon/crypto_openssl.c
@@ -1,4 +1,4 @@
/* $KAME: crypto_openssl.c,v 1.87 2004/08/24 05:37:36 sakane Exp $ */
/* $KAME: crypto_openssl.c,v 1.88 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -982,6 +982,12 @@ eay_init_error()
ERR_load_crypto_strings();
}

void
eay_close_error()
{
ERR_free_strings();
}

/*
* DES-CBC
*/
Expand Down
3 changes: 2 additions & 1 deletion kame/kame/racoon/crypto_openssl.h
@@ -1,4 +1,4 @@
/* $KAME: crypto_openssl.h,v 1.30 2004/06/16 11:55:36 sakane Exp $ */
/* $KAME: crypto_openssl.h,v 1.31 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -67,6 +67,7 @@ extern vchar_t *eay_get_pkcs1pubkey __P((char *));
/* string error */
extern char *eay_strerror __P((void));
extern void eay_init_error __P((void));
extern void eay_close_error __P((void));

/* DES */
extern vchar_t *eay_des_encrypt __P((vchar_t *, vchar_t *, vchar_t *));
Expand Down
18 changes: 9 additions & 9 deletions kame/kame/racoon/main.c
@@ -1,4 +1,4 @@
/* $KAME: main.c,v 1.48 2002/11/20 02:06:07 itojun Exp $ */
/* $KAME: main.c,v 1.49 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -127,7 +127,7 @@ usage()
printf(" -f: pathname for configuration file.\n");
printf(" -l: pathname for log file.\n");
printf(" -p: port number for isakmp (default: %d).\n", PORT_ISAKMP);
exit(1);
exit_program(1, NULL);
}

int
Expand Down Expand Up @@ -177,7 +177,7 @@ main(ac, av)
"\n", eay_version());

if (pfkey_init() < 0) {
errx(1, "something error happened "
exit_program(1, "something error happened "
"while pfkey initializing.");
/* NOTREACHED*/
}
Expand All @@ -189,7 +189,7 @@ main(ac, av)
save_params();
error = cfparse();
if (error != 0)
errx(1, "failed to parse configuration file.");
exit_program(1, "failed to parse configuration file.");
restore_params();

/*
Expand All @@ -198,7 +198,7 @@ main(ac, av)
*/
if (loading_sa && !f_local) {
if (backupsa_from_file() != 0)
errx(1, "something error happened "
exit_program(1, "something error happened "
"SA recovering.");
}

Expand All @@ -209,7 +209,7 @@ main(ac, av)
FILE *fp;

if (daemon(0, 0) < 0) {
errx(1, "failed to be daemon. (%s)",
exit_program(1, "failed to be daemon. (%s)",
strerror(errno));
}
/*
Expand All @@ -226,10 +226,10 @@ main(ac, av)
fp = fopen(pid_file, "w");
if (fp) {
if (fchmod(fileno(fp),
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) {
syslog(LOG_ERR, "%s", strerror(errno));
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) {
fclose(fp);
exit(1);
exit_program(1, "%s", strerror(errno));
}
fprintf(fp, "%ld\n", (long)racoon_pid);
fclose(fp);
Expand All @@ -249,7 +249,7 @@ main(ac, av)

session();

exit(0);
exit_program(0, NULL);
}

#if 0
Expand Down
15 changes: 14 additions & 1 deletion kame/kame/racoon/oakley.c
@@ -1,4 +1,4 @@
/* $KAME: oakley.c,v 1.119 2004/08/24 06:47:27 sakane Exp $ */
/* $KAME: oakley.c,v 1.120 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -147,6 +147,19 @@ oakley_dhinit()
return 0;
}

void
oakley_dhclean()
{
vfree(dh_modp768.prime);
vfree(dh_modp1024.prime);
vfree(dh_modp1536.prime);
vfree(dh_modp2048.prime);
vfree(dh_modp3072.prime);
vfree(dh_modp4096.prime);
vfree(dh_modp6144.prime);
vfree(dh_modp8192.prime);
}

void
oakley_dhgrp_free(dhgrp)
struct dhgroup *dhgrp;
Expand Down
3 changes: 2 additions & 1 deletion kame/kame/racoon/oakley.h
@@ -1,4 +1,4 @@
/* $KAME: oakley.h,v 1.30 2003/12/14 04:13:11 itojun Exp $ */
/* $KAME: oakley.h,v 1.31 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -143,6 +143,7 @@ struct isakmp_ivm;
extern int oakley_get_defaultlifetime __P((void));

extern int oakley_dhinit __P((void));
extern void oakley_dhclean __P((void));
extern void oakley_dhgrp_free __P((struct dhgroup *));
extern int oakley_dh_compute __P((const struct dhgroup *,
vchar_t *, vchar_t *, vchar_t *, vchar_t **));
Expand Down
28 changes: 24 additions & 4 deletions kame/kame/racoon/session.c
@@ -1,4 +1,4 @@
/* $KAME: session.c,v 1.32 2003/09/24 02:01:17 jinmei Exp $ */
/* $KAME: session.c,v 1.33 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -65,6 +65,7 @@
#include "vmbuf.h"
#include "plog.h"
#include "debug.h"
#include "err.h"

#include "schedule.h"
#include "session.h"
Expand All @@ -77,6 +78,7 @@
#include "handler.h"
#include "localconf.h"
#include "remoteconf.h"
#include "crypto_openssl.h"
#include "backupsa.h"

static void close_session __P((void));
Expand Down Expand Up @@ -109,13 +111,13 @@ session(void)
#ifdef ENABLE_ADMINPORT
/* debug port has no authentication, do not open it */
if (admin_init() < 0)
exit(1);
return -1;
#endif

initmyaddr();

if (isakmp_init() < 0)
exit(1);
return -1;

initfds();

Expand Down Expand Up @@ -167,6 +169,7 @@ session(void)
initfds();
}
}
/*NOTREACHED*/
}

/* clear all status and exit program. */
Expand All @@ -178,7 +181,24 @@ close_session()
backupsa_clean();

plog(LLV_INFO, LOCATION, NULL, "racoon shutdown\n");
exit(0);
exit_program(0, NULL);
}

void
exit_program(int code, const char *fmt, ...)
{
va_list ap;

eay_close_error();
oakley_dhclean();

if (fmt == NULL)
exit(code);
else {
va_start(ap, fmt);
verrx(code, fmt, ap);
va_end(ap);
}
}

static void
Expand Down
3 changes: 2 additions & 1 deletion kame/kame/racoon/session.h
@@ -1,4 +1,4 @@
/* $KAME: session.h,v 1.4 2000/10/04 17:41:04 itojun Exp $ */
/* $KAME: session.h,v 1.5 2004/08/24 06:52:41 sakane Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -31,3 +31,4 @@

extern int session __P((void));
extern RETSIGTYPE signal_handler __P((int));
extern void exit_program __P((int, const char *, ...));

0 comments on commit 0d055d4

Please sign in to comment.