From: Ben Collins Date: Mon, 24 Apr 2000 16:41:36 +0000 (+0000) Subject: with the -t option (writing to /tmp) open files with O_CREAT|O_EXCL to overcome race... X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~3092 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=97493c34041f218d658ca0f9dfbc87817fb5fdd7;p=openldap with the -t option (writing to /tmp) open files with O_CREAT|O_EXCL to overcome race conditions --- diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 2603107e43..f7d050422b 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -14,7 +14,15 @@ #include #include #include +#include +#include +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif #ifdef HAVE_IO_H #include #endif @@ -794,6 +802,7 @@ print_entry( if ( vals2tmp > 1 || ( vals2tmp && ldif_is_not_printable( bvals[i]->bv_val, bvals[i]->bv_len ) )) { + int tmpfd; /* write value to file */ sprintf( tmpfname, "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX", tmpdir, a ); @@ -804,7 +813,12 @@ print_entry( continue; } - if (( tmpfp = fopen( tmpfname, "w")) == NULL ) { + if (( tmpfd = open( tmpfname, O_WRONLY|O_CREAT|O_EXCL, 0600 )) == -1 ) { + perror( tmpfname ); + continue; + } + + if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) { perror( tmpfname ); continue; }