You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/10 17:21:48 UTC
svn commit: r813475 -
/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk
Date: Thu Sep 10 15:21:47 2009
New Revision: 813475
URL: http://svn.apache.org/viewvc?rev=813475&view=rev
Log:
Update attributes with perms as well
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=813475&r1=813474&r2=813475&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Thu Sep 10 15:21:47 2009
@@ -602,13 +602,21 @@
ACR_DECLARE(int) ACR_FileProtectionSet(JNIEnv *_E, wchar_t *fname, int prot)
{
int protection = 0;
- PSID user = NULL, group = NULL;
- PACL dacl = NULL;
- PACL eacl = NULL;
+ PSID user = NULL, group = NULL;
+ PACL dacl = NULL;
+ PACL eacl = NULL;
+ DWORD attr = 0;
+ DWORD aorg;
PSECURITY_DESCRIPTOR ppsd = NULL;
int fix = 0;
int rc;
+ attr = GetFileAttributesW(fname);
+ if (attr == 0xFFFFFFFF) {
+ rc = ACR_GET_OS_ERROR();
+ goto failed;
+ }
+ aorg = attr;
rc = GetNamedSecurityInfoW(fname,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
@@ -618,12 +626,13 @@
NULL,
&ppsd);
if (rc != ERROR_SUCCESS) {
+ rc = ACR_TO_OS_ERROR(rc);
goto failed;
}
eacl = update_prot(user, group, dacl, prot);
if (!eacl) {
- rc = GetLastError();
+ rc = ACR_GET_OS_ERROR();
goto failed;
}
rc = SetNamedSecurityInfoW(fname,
@@ -635,6 +644,18 @@
NULL);
if (rc != ERROR_SUCCESS) {
+ rc = ACR_TO_OS_ERROR(rc);
+ goto failed;
+ }
+ /* We can only update the readonly and hidden attribute */
+ if ((prot & (ACR_FPROT_UWRITE | ACR_FPROT_GWRITE | ACR_FPROT_WWRITE)))
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ else
+ attr |= FILE_ATTRIBUTE_READONLY;
+ if ((prot & (ACR_FPROT_UEXECUTE | ACR_FPROT_GEXECUTE | ACR_FPROT_WEXECUTE)))
+ attr &= ~FILE_ATTRIBUTE_HIDDEN;
+ if (aorg != attr && !SetFileAttributesW(fname, attr)) {
+ rc = ACR_GET_OS_ERROR();
goto failed;
}
LocalFree((HLOCAL)ppsd);