]> granicus.if.org Git - apache/commitdiff
Create new files with APR_OS_DEFAULT permissions.
authorStefan Fritsch <sf@apache.org>
Sun, 28 Mar 2010 14:19:49 +0000 (14:19 +0000)
committerStefan Fritsch <sf@apache.org>
Sun, 28 Mar 2010 14:19:49 +0000 (14:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@928403 13f79535-47bb-0310-9956-ffa450edef68

modules/dav/fs/repos.c

index f60071e1529d9b898ce98c267e225333541f6bb2..02f9a8ac4ef9dc0c63b37d96d11cb05ba988442a 100644 (file)
 #include <stdio.h>              /* for sprintf() */
 #endif
 
+#if APR_HAVE_UNISTD_H
+#include <unistd.h>             /* 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);
     }