stoddard 00/02/15 19:32:50
Modified: src/lib/apr/file_io/win32 open.c Log: APR is creating files by default whenever ap_open is called and the file does not exist (i.e., passing OPEN_ALWAYS by default to CreateFile). This causes .htaccess files to be created all over the place. Submitted by: Tim Costello <[EMAIL PROTECTED]> Reviewed by: Bill Stoddard <[EMAIL PROTECTED]> Revision Changes Path 1.19 +21 -2 apache-2.0/src/lib/apr/file_io/win32/open.c Index: open.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/open.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- open.c 2000/02/15 00:15:44 1.18 +++ open.c 2000/02/16 03:32:49 1.19 @@ -80,6 +80,7 @@ { DWORD oflags = 0; DWORD createflags = 0; + DWORD attributes = 0; (*dafile) = (struct file_t *)ap_palloc(cont, sizeof(struct file_t)); @@ -106,12 +107,25 @@ (*dafile)->demonfname = canonical_filename((*dafile)->cntxt, fname); (*dafile)->lowerdemonfname = strlwr((*dafile)->demonfname); - createflags = OPEN_ALWAYS; if (flag & APR_CREATE) { if (flag & APR_EXCL) { + /* only create new if file does not already exist */ createflags = CREATE_NEW; + } else if (flag & APR_TRUNCATE) { + /* truncate existing file or create new */ + createflags = CREATE_ALWAYS; + } else { + /* open existing but create if necessary */ + createflags = OPEN_ALWAYS; } + } else if (flag & APR_TRUNCATE) { + /* only truncate if file already exists */ + createflags = TRUNCATE_EXISTING; + } else { + /* only open if file already exists */ + createflags = OPEN_EXISTING; } + if ((flag & APR_EXCL) && !(flag & APR_CREATE)) { (*dafile)->filehand = INVALID_HANDLE_VALUE; return APR_EACCES; @@ -128,8 +142,13 @@ createflags = TRUNCATE_EXISTING; } + attributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN; + if (flag & APR_DELONCLOSE) { + attributes |= FILE_FLAG_DELETE_ON_CLOSE; + } + (*dafile)->filehand = CreateFile(fname, oflags, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, createflags, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); + NULL, createflags, attributes, 0); if ((*dafile)->filehand == INVALID_HANDLE_VALUE) { return GetLastError();