From c99460c09c864cd793da7b4ce5b1d10628f6fdc3 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sun, 9 Nov 1997 11:13:21 +0000 Subject: [PATCH] (create_and_write_cookie) Create temp file with mkstemp. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3876 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/kx/common.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/appl/kx/common.c b/appl/kx/common.c index 3700dad7e..d1c5fb815 100644 --- a/appl/kx/common.c +++ b/appl/kx/common.c @@ -236,11 +236,13 @@ connect_local_xsocket (unsigned dnr) int create_and_write_cookie (char *xauthfile, + size_t size, u_char *cookie, size_t sz) { Xauth auth; char tmp[64]; + int fd; FILE *f; char hostname[MaxHostNameLen]; struct in_addr loopback; @@ -261,9 +263,16 @@ create_and_write_cookie (char *xauthfile, auth.data = (char*)cookie; des_rand_data (cookie, sz); - f = fopen(xauthfile, "w"); - if (f == NULL) - return 1; + strncpy(xauthfile, "/tmp/AXXXXX", size); + xauthfile[size-1] = 0; + fd = mkstemp(xauthfile); + if(fd < 0) + return 1; + f = fdopen(fd, "r+"); + if(f == NULL){ + close(fd); + return 1; + } if(XauWriteAuth(f, &auth) == 0) { fclose(f); return 1;