/*
This file is part of GNUnet.
- Copyright (C) 2001--2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001--2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
GNUNET_DISK_mkdtemp (const char *t)
{
char *fn;
+ mode_t omask;
+ omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
fn = mktemp_name (t);
if (fn != mkdtemp (fn))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdtemp", fn);
GNUNET_free (fn);
+ umask (omask);
return NULL;
}
+ umask (omask);
return fn;
}
{
int fd;
char *fn;
+ mode_t omask;
+ omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
fn = mktemp_name (t);
if (-1 == (fd = mkstemp (fn)))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
GNUNET_free (fn);
+ umask (omask);
return NULL;
}
+ umask (omask);
if (0 != CLOSE (fd))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
/**
- * Create the directory structure for storing
- * a file.
+ * Create the directory structure for storing a file.
*
* @param filename name of a file in the directory
* @returns #GNUNET_OK on success,
char *rdir;
size_t len;
int ret;
+ int eno;
rdir = GNUNET_STRINGS_filename_expand (filename);
- if (rdir == NULL)
+ if (NULL == rdir)
+ {
+ errno = EINVAL;
return GNUNET_SYSERR;
+ }
len = strlen (rdir);
while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
len--;
rdir[len] = '\0';
+ /* The empty path is invalid and in this case refers to / */
+ if (0 == len)
+ {
+ GNUNET_free (rdir);
+ rdir = GNUNET_strdup ("/");
+ }
ret = GNUNET_DISK_directory_create (rdir);
- if ((ret == GNUNET_OK) && (0 != ACCESS (rdir, W_OK)))
+ if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK)))
ret = GNUNET_NO;
+ eno = errno;
GNUNET_free (rdir);
+ errno = eno;
return ret;
}
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
+GNUNET_DISK_fn_write (const char *fn,
+ const void *buffer,
+ size_t n,
enum GNUNET_DISK_AccessPermissions mode)
{
struct GNUNET_DISK_FileHandle *fh;