summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_disk_file.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2004-04-13 20:36:58 +0000
committerCorinna Vinschen <corinna@vinschen.de>2004-04-13 20:36:58 +0000
commit854c870051c471f7f8d8dcf36e1ee3263eb9218f (patch)
treedc35c3cf6348a145df91402fd8441819ab1559b9 /winsup/cygwin/fhandler_disk_file.cc
parent8107364bdbebca0cd008ea9071d4a9aa48318c29 (diff)
downloadcygnal-854c870051c471f7f8d8dcf36e1ee3263eb9218f.tar.gz
cygnal-854c870051c471f7f8d8dcf36e1ee3263eb9218f.tar.bz2
cygnal-854c870051c471f7f8d8dcf36e1ee3263eb9218f.zip
* dir.cc (mkdir): Call set_file_attribute with additional handle
argument. * fhandler.cc (fhandler_base::fchmod): New method. * fhandler.h: Declare fchmod method in fhandler_base, fhandler_disk_file and fhandler_virtual. * fhandler_disk_file.cc (fhandler_disk_file::fchmod): New method. (fhandler_base::open_fs): Call set_file_attribute with additional handle argument. * fhandler_virtual.cc (fhandler_virtual::fchmod): New method. * path.cc (symlink_worker): Call set_file_attribute with additional handle argument. * security.cc (get_nt_object_security): New function. (get_nt_object_attribute): Call get_nt_object_security. (set_nt_attribute): Add handle argument. Call get_nt_object_security first, read_sd only if that fails. (set_file_attribute): Add handle argument. * security.h (set_file_attribute): Declare with additional handle argument. * syscalls.cc (stat_suffixes): Move to beginning of file. (chown_worker): Call set_file_attribute with additional handle argument. (chmod): Reorganize to call fhandler's fchmod method eventually. (fchmod): Ditto.
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc44
1 files changed, 43 insertions, 1 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 62c4605a2..587f32314 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -366,6 +366,48 @@ fhandler_disk_file::fstat (struct __stat64 *buf)
return fstat_fs (buf);
}
+int __stdcall
+fhandler_disk_file::fchmod (mode_t mode)
+{
+ extern int chmod_device (path_conv& pc, mode_t mode);
+ int res = -1;
+ int oret = 0;
+
+ if (pc.is_fs_special ())
+ return chmod_device (pc, mode);
+
+ if (!get_io_handle () && !(oret = open_fs (O_RDONLY | O_BINARY, 0)))
+ return -1;
+
+ SetFileAttributes (get_win32_name (), (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
+ if (pc.isdir ())
+ mode |= S_IFDIR;
+ if (!set_file_attribute (pc.has_acls (), get_io_handle (), get_win32_name (),
+ ILLEGAL_UID, ILLEGAL_GID, mode)
+ && allow_ntsec)
+ res = 0;
+
+ /* if the mode we want has any write bits set, we can't be read only. */
+ if (mode & (S_IWUSR | S_IWGRP | S_IWOTH))
+ (DWORD) pc &= ~FILE_ATTRIBUTE_READONLY;
+ else
+ (DWORD) pc |= FILE_ATTRIBUTE_READONLY;
+
+ if (!pc.is_lnk_symlink () && S_ISLNK (mode) || S_ISSOCK (mode))
+ (DWORD) pc |= FILE_ATTRIBUTE_SYSTEM;
+
+ if (!SetFileAttributes (pc, pc))
+ __seterrno ();
+ else if (!allow_ntsec)
+ /* Correct NTFS security attributes have higher priority */
+ res = 0;
+
+ if (oret)
+ close_fs ();
+
+ return res;
+}
+
fhandler_disk_file::fhandler_disk_file () :
fhandler_base ()
{
@@ -411,7 +453,7 @@ fhandler_base::open_fs (int flags, mode_t mode)
if (flags & O_CREAT
&& GetLastError () != ERROR_ALREADY_EXISTS
&& !allow_ntsec && allow_ntea)
- set_file_attribute (has_acls (), get_win32_name (), mode);
+ set_file_attribute (has_acls (), NULL, get_win32_name (), mode);
set_fs_flags (pc.fs_flags ());