commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r813475 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Date Thu, 10 Sep 2009 15:21:48 GMT
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);



Mime
View raw message