diff options
author | Arnaud Charlet <charlet@gcc.gnu.org> | 2008-08-05 15:42:47 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2008-08-05 15:42:47 +0200 |
commit | 43540ec65f8139e1470ce00a649dc10252ab7c1e (patch) | |
tree | 4e86e711b7bdbc2a81cc940dffd1219d6013d0f7 /gcc/ada/adaint.c | |
parent | 486fd7f5d7da98d37a02887cfbb2d178ee6191bb (diff) | |
download | gcc-43540ec65f8139e1470ce00a649dc10252ab7c1e.zip gcc-43540ec65f8139e1470ce00a649dc10252ab7c1e.tar.gz gcc-43540ec65f8139e1470ce00a649dc10252ab7c1e.tar.bz2 |
adaint.c, [...]: Add support for the readable attribute.
2008-08-05 Pascal Obry <obry@adacore.com>
* adaint.c, adaint.h, s-os_lib.adb, s-os_lib.ads: Add support for the
readable attribute.
From-SVN: r138709
Diffstat (limited to 'gcc/ada/adaint.c')
-rw-r--r-- | gcc/ada/adaint.c | 78 |
1 files changed, 51 insertions, 27 deletions
diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index c1afe1e..242b82bd 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -1760,33 +1760,20 @@ __gnat_set_OWNER_ACL TCHAR username [100]; DWORD unsize = 100; - HANDLE file = CreateFile - (wname, READ_CONTROL | WRITE_DAC, 0, NULL, - OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - - if (file == INVALID_HANDLE_VALUE) - return; - /* Get current user, he will act as the owner */ if (!GetUserName (username, &unsize)) return; - if (GetSecurityInfo - (file, + if (GetNamedSecurityInfo + (wname, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pOldDACL, NULL, &pSD) != ERROR_SUCCESS) return; - ZeroMemory (&ea, sizeof (EXPLICIT_ACCESS)); - - ea.grfAccessMode = AccessMode; - ea.grfAccessPermissions = AccessPermissions; - ea.grfInheritance = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE; - ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME; - ea.Trustee.TrusteeType = TRUSTEE_IS_USER; - ea.Trustee.ptstrName = username; + BuildExplicitAccessWithName + (&ea, username, AccessPermissions, AccessMode, NO_INHERITANCE); if (AccessMode == SET_ACCESS) { @@ -1799,14 +1786,13 @@ __gnat_set_OWNER_ACL if (SetEntriesInAcl (1, &ea, pOldDACL, &pNewDACL) != ERROR_SUCCESS) return; - if (SetSecurityInfo - (file, SE_FILE_OBJECT, + if (SetNamedSecurityInfo + (wname, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, pNewDACL, NULL) != ERROR_SUCCESS) return; LocalFree (pSD); LocalFree (pNewDACL); - CloseHandle (file); } #endif /* defined (_WIN32) && !defined (RTX) */ @@ -1892,7 +1878,7 @@ __gnat_set_writable (char *name) S2WSU (wname, name, GNAT_MAX_PATH_LEN + 2); - __gnat_set_OWNER_ACL (wname, GRANT_ACCESS, GENERIC_WRITE); + __gnat_set_OWNER_ACL (wname, GRANT_ACCESS, FILE_GENERIC_WRITE); SetFileAttributes (wname, GetFileAttributes (wname) & ~FILE_ATTRIBUTE_READONLY); #elif ! defined (__vxworks) && ! defined(__nucleus__) @@ -1914,7 +1900,7 @@ __gnat_set_executable (char *name) S2WSU (wname, name, GNAT_MAX_PATH_LEN + 2); - __gnat_set_OWNER_ACL (wname, GRANT_ACCESS, GENERIC_EXECUTE); + __gnat_set_OWNER_ACL (wname, GRANT_ACCESS, FILE_GENERIC_EXECUTE); #elif ! defined (__vxworks) && ! defined(__nucleus__) struct stat statbuf; @@ -1934,17 +1920,55 @@ __gnat_set_non_writable (char *name) S2WSU (wname, name, GNAT_MAX_PATH_LEN + 2); - __gnat_set_OWNER_ACL (wname, REVOKE_ACCESS, GENERIC_WRITE); + __gnat_set_OWNER_ACL (wname, DENY_ACCESS, FILE_GENERIC_WRITE); SetFileAttributes (wname, GetFileAttributes (wname) | FILE_ATTRIBUTE_READONLY); #elif ! defined (__vxworks) && ! defined(__nucleus__) struct stat statbuf; if (stat (name, &statbuf) == 0) - { - statbuf.st_mode = statbuf.st_mode & 07577; - chmod (name, statbuf.st_mode); - } + { + statbuf.st_mode = statbuf.st_mode & 07577; + chmod (name, statbuf.st_mode); + } +#endif +} + +void +__gnat_set_readable (char *name) +{ +#if defined (_WIN32) && !defined (RTX) + TCHAR wname [GNAT_MAX_PATH_LEN + 2]; + + S2WSU (wname, name, GNAT_MAX_PATH_LEN + 2); + + __gnat_set_OWNER_ACL (wname, GRANT_ACCESS, FILE_GENERIC_READ); +#else + struct stat statbuf; + + if (stat (name, &statbuf) == 0) + { + chmod (name, statbuf.st_mode | S_IREAD); + } +#endif +} + +void +__gnat_set_non_readable (char *name) +{ +#if defined (_WIN32) && !defined (RTX) + TCHAR wname [GNAT_MAX_PATH_LEN + 2]; + + S2WSU (wname, name, GNAT_MAX_PATH_LEN + 2); + + __gnat_set_OWNER_ACL (wname, DENY_ACCESS, FILE_GENERIC_READ); +#else + struct stat statbuf; + + if (stat (name, &statbuf) == 0) + { + chmod (name, statbuf.st_mode & (~S_IREAD)); + } #endif } |