From: Stefan Fritsch Date: Sun, 28 Mar 2010 14:19:49 +0000 (+0000) Subject: Create new files with APR_OS_DEFAULT permissions. X-Git-Tag: 2.3.6~280 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=592cb37b2afce7210aadc0649af2a2184508cbbe;p=thirdparty%2Fapache%2Fhttpd.git Create new files with APR_OS_DEFAULT permissions. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@928403 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index f60071e1529..02f9a8ac4ef 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -27,6 +27,10 @@ #include /* for sprintf() */ #endif +#if APR_HAVE_UNISTD_H +#include /* for getpid() */ +#endif + #include "httpd.h" #include "http_log.h" #include "http_protocol.h" /* for ap_set_* (in dav_fs_set_headers) */ @@ -143,7 +147,7 @@ enum { /* * prefix for temporary files */ -#define DAV_FS_TMP_PREFIX ".davfs." +#define DAV_FS_TMP_PREFIX ".davfs.tmp" static const dav_liveprop_spec dav_fs_props[] = { @@ -884,6 +888,26 @@ static apr_status_t tmpfile_cleanup(void *data) { return APR_SUCCESS; } +/* custom mktemp that creates the file with APR_OS_DEFAULT permissions */ +static apr_status_t dav_fs_mktemp(apr_file_t **fp, char *templ, apr_pool_t *p) +{ + apr_status_t rv; + int num = ((getpid() << 7) + (int)templ % (1 << 16) ) % ( 1 << 23 ) ; + char *numstr = templ + strlen(templ) - 6; + + ap_assert(numstr >= templ); + + do { + num = (num + 1) % ( 1 << 23 ); + snprintf(numstr, 7, "%06x", num); + rv = apr_file_open(fp, templ, + APR_WRITE | APR_CREATE | APR_BINARY | APR_EXCL, + APR_OS_DEFAULT, p); + } while (APR_STATUS_IS_EEXIST(rv)); + + return rv; +} + static dav_error * dav_fs_open_stream(const dav_resource *resource, dav_stream_mode mode, dav_stream **stream) @@ -914,7 +938,7 @@ static dav_error * dav_fs_open_stream(const dav_resource *resource, if (mode == DAV_MODE_WRITE_TRUNC) { ds->temppath = apr_pstrcat(p, ap_make_dirstr_parent(p, ds->pathname), DAV_FS_TMP_PREFIX "XXXXXX", NULL); - rv = apr_file_mktemp(&ds->f, ds->temppath, flags, ds->p); + rv = dav_fs_mktemp(&ds->f, ds->temppath, ds->p); apr_pool_cleanup_register(p, ds, tmpfile_cleanup, apr_pool_cleanup_null); }