diff options
Diffstat (limited to 'g10/keyserver.c')
-rw-r--r-- | g10/keyserver.c | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/g10/keyserver.c b/g10/keyserver.c index 908f510b5..89f2c68ad 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -41,6 +41,10 @@ #include "main.h" #include "hkp.h" +#ifndef HAVE_MKDTEMP +char *mkdtemp(char *template); +#endif + #if !(defined(HAVE_FORK) && defined(HAVE_PIPE)) #define KEYSERVER_TEMPFILE_ONLY #endif @@ -296,39 +300,20 @@ keyserver_spawn(int action,STRLIST list,u32 (*kidlist)[2],int count) if(opt.keyserver_options.use_temp_files) { - int attempts; const char *tmp=get_temp_dir(); - byte *randombits; - - tempdir=m_alloc(strlen(tmp)+1+12+1); - - /* Try 4 times to make the temp directory */ - for(attempts=0;attempts<4;attempts++) - { - /* Using really random bits is probably overkill here. The - worst thing that can happen with a directory name collision - is that the user will get an error message. */ - randombits=get_random_bits(8*4,0,0); - - sprintf(tempdir,"%s" DIRSEP_S "gpg-%02X%02X%02X%02X",tmp, - randombits[0],randombits[1],randombits[2],randombits[3]); - m_free(randombits); + tempdir=m_alloc(strlen(tmp)+1+10+1); + sprintf(tempdir,"%s" DIRSEP_S "gpg-XXXXXX",tmp); - if(mkdir(tempdir,0700)==0) - { - madedir=1; - break; - } - } - - if(!madedir) + if(mkdtemp(tempdir)==NULL) { - log_error(_("%s: can't create temp directory after %d tries: %s\n"), - tempdir,attempts,strerror(errno)); + log_error(_("%s: can't create temp directory: %s\n"), + tempdir,strerror(errno)); goto fail; } + madedir=1; + tempfile_in=m_alloc(strlen(tempdir)+1+10+1); sprintf(tempfile_in,"%s" DIRSEP_S "ksrvin" EXTSEP_S "txt",tempdir); |