From 222f0840463e0681181b374f8734153d9f23443d Mon Sep 17 00:00:00 2001 From: james Date: Fri, 18 Jul 2008 00:32:40 +0000 Subject: Modified create_temp_filename to create unpredictable filenames. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@3074 e7ae566f-a301-0410-adde-c780ea21d3b5 --- misc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/misc.c b/misc.c index 8eff3d7..97e8049 100644 --- a/misc.c +++ b/misc.c @@ -1086,6 +1086,8 @@ test_file (const char *filename) return ret; } +#ifdef USE_CRYPTO + /* create a temporary filename in directory */ const char * create_temp_filename (const char *directory, const char *prefix, struct gc_arena *gc) @@ -1097,15 +1099,20 @@ create_temp_filename (const char *directory, const char *prefix, struct gc_arena ++counter; mutex_unlock_static (L_CREATE_TEMP); - buf_printf (&fname, PACKAGE "_%s_%u_%u_%u.tmp", - prefix, - openvpn_getpid (), - counter, - (unsigned int)now); + { + uint8_t rndbytes[16]; + const char *rndstr; + + prng_bytes (rndbytes, sizeof (rndbytes)); + rndstr = format_hex_ex (rndbytes, sizeof (rndbytes), 40, 0, NULL, gc); + buf_printf (&fname, PACKAGE "_%s_%s.tmp", prefix, rndstr); + } return gen_path (directory, BSTR (&fname), gc); } +#endif + /* * Put a directory and filename together. */ -- cgit