(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
This commit is contained in:
@@ -236,11 +236,13 @@ connect_local_xsocket (unsigned dnr)
|
|||||||
|
|
||||||
int
|
int
|
||||||
create_and_write_cookie (char *xauthfile,
|
create_and_write_cookie (char *xauthfile,
|
||||||
|
size_t size,
|
||||||
u_char *cookie,
|
u_char *cookie,
|
||||||
size_t sz)
|
size_t sz)
|
||||||
{
|
{
|
||||||
Xauth auth;
|
Xauth auth;
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
|
int fd;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char hostname[MaxHostNameLen];
|
char hostname[MaxHostNameLen];
|
||||||
struct in_addr loopback;
|
struct in_addr loopback;
|
||||||
@@ -261,9 +263,16 @@ create_and_write_cookie (char *xauthfile,
|
|||||||
auth.data = (char*)cookie;
|
auth.data = (char*)cookie;
|
||||||
des_rand_data (cookie, sz);
|
des_rand_data (cookie, sz);
|
||||||
|
|
||||||
f = fopen(xauthfile, "w");
|
strncpy(xauthfile, "/tmp/AXXXXX", size);
|
||||||
if (f == NULL)
|
xauthfile[size-1] = 0;
|
||||||
return 1;
|
fd = mkstemp(xauthfile);
|
||||||
|
if(fd < 0)
|
||||||
|
return 1;
|
||||||
|
f = fdopen(fd, "r+");
|
||||||
|
if(f == NULL){
|
||||||
|
close(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if(XauWriteAuth(f, &auth) == 0) {
|
if(XauWriteAuth(f, &auth) == 0) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user