#include "portable.h"
#include <stdio.h>
+#include <sys/stat.h>
#include <ac/stdlib.h>
#include <ac/wait.h>
#include <ac/unistd.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
static int ovalues( char *attr );
static void write_entry( void );
-static char *entry_temp_file;
+static char entry_temp_file[L_tmpnam];
void
{
FILE *fp;
char *cp, *editor = UD_DEFAULT_EDITOR;
- static char template[MED_BUF_SIZE];
+ int tmpfd;
#ifndef HAVE_SPAWNLP
int pid;
int status;
#endif
/* write the entry into a temp file */
- (void) strcpy(template, "/tmp/udEdit.XXXXXX");
- if ((entry_temp_file = mktemp(template)) == NULL) {
- perror("mktemp");
- return(-1);
+ if (tmpnam(entry_temp_file) == NULL) {
+ perror("tmpnam");
+ return -1;
}
- if ((fp = fopen(entry_temp_file, "w")) == NULL) {
- perror("fopen");
+ if ((tmpfd = open(entry_temp_file, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
+ perror(entry_temp_file);
+ return -1;
+ }
+ if ((fp = fdopen(tmpfd, "w")) == NULL) {
+ perror("fdopen");
return(-1);
}
fprintf(fp, "## Directory entry of %s\n", Entry.name);
strcpy( tmpname, "/tmp/dbtestXXXXXX" );
#ifndef HAVE_MKSTEMP
- if ( (fd = open( mktemp( tmpname ), O_RDWR, 0600 )) == -1 ) {
+ if ( (fd = open( mktemp( tmpname ), O_RDWR|O_CREAT|O_EXCL, 0600 )) == -1 ) {
perror( tmpname );
return;
}
#include "portable.h"
#include <stdio.h>
+#include <sys/stat.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h> /* get ftruncate() */
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
#include "slurp.h"
#include "globals.h"
{
Re *re;
FILE *fp;
+ int tmpfd;
if ( rq == NULL ) {
Debug( LDAP_DEBUG_ANY, "Rq_dump: rq is NULL!\n", 0, 0, 0 );
return;
}
- if (( fp = fopen( SLURPD_DUMPFILE, "w" )) == NULL ) {
+ if (unlink(SLURPD_DUMPFILE) == -1 && errno != ENOENT) {
+ Debug( LDAP_DEBUG_ANY, "Rq_dump: \"%s\" exists, and cannot unlink\n",
+ SLURPD_DUMPFILE, 0, 0 );
+ return;
+ }
+ if (( tmpfd = open(SLURPD_DUMPFILE, O_CREAT|O_RDWR|O_EXCL, 0600)) == -1) {
Debug( LDAP_DEBUG_ANY, "Rq_dump: cannot open \"%s\" for write\n",
SLURPD_DUMPFILE, 0, 0 );
return;
}
+ if (( fp = fdopen( tmpfd, "w" )) == NULL ) {
+ Debug( LDAP_DEBUG_ANY, "Rq_dump: cannot fdopen \"%s\" for write\n",
+ SLURPD_DUMPFILE, 0, 0 );
+ return;
+ }
rq->rq_lock( rq );
for ( re = rq->rq_gethead( rq ); re != NULL; re = rq->rq_getnext( re )) {