summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/syscalls.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/syscalls.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/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc87
1 files changed, 16 insertions, 71 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 11c47fd02..ed8b902d6 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -71,6 +71,13 @@ details. */
#undef _lseek64
#undef _fstat64
+suffix_info stat_suffixes[] =
+{
+ suffix_info ("", 1),
+ suffix_info (".exe", 1),
+ suffix_info (NULL)
+};
+
SYSTEM_INFO system_info;
static int __stdcall mknod_worker (const char *, mode_t, mode_t, _major_t,
@@ -849,8 +856,8 @@ chown_worker (const char *name, unsigned fmode, __uid32_t uid, __gid32_t gid)
res = get_file_attribute (win32_path.has_acls (), NULL,
win32_path.get_win32 (), &attrib);
if (!res)
- res = set_file_attribute (win32_path.has_acls (), win32_path, uid,
- gid, attrib);
+ res = set_file_attribute (win32_path.has_acls (), NULL, win32_path,
+ uid, gid, attrib);
if (res != 0 && (!win32_path.has_acls () || !allow_ntsec))
{
/* fake - if not supported, pretend we're like win95
@@ -943,60 +950,16 @@ extern "C" int
chmod (const char *path, mode_t mode)
{
int res = -1;
-
- path_conv win32_path (path);
-
- if (win32_path.error)
- {
- set_errno (win32_path.error);
- goto done;
- }
-
- /* FIXME: This makes chmod on a device succeed always. Someday we'll want
- to actually allow chmod to work properly on devices. */
- if (win32_path.is_auto_device ())
- {
- res = 0;
- goto done;
- }
- if (win32_path.is_fs_special ())
+ fhandler_base *fh = build_fh_name (path, NULL, PC_SYM_FOLLOW | PC_FULL,
+ stat_suffixes);
+ if (fh->error ())
{
- res = chmod_device (win32_path, mode);
- goto done;
+ debug_printf ("got %d error from build_fh_name", fh->error ());
+ set_errno (fh->error ());
}
-
- if (!win32_path.exists ())
- __seterrno ();
else
- {
- /* temporary erase read only bit, to be able to set file security */
- SetFileAttributes (win32_path, (DWORD) win32_path & ~FILE_ATTRIBUTE_READONLY);
+ res = fh->fchmod (mode);
- if (win32_path.isdir ())
- mode |= S_IFDIR;
- if (!set_file_attribute (win32_path.has_acls (), win32_path,
- 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) win32_path &= ~FILE_ATTRIBUTE_READONLY;
- else
- (DWORD) win32_path |= FILE_ATTRIBUTE_READONLY;
-
- if (!win32_path.is_lnk_symlink () && S_ISLNK (mode) || S_ISSOCK (mode))
- (DWORD) win32_path |= FILE_ATTRIBUTE_SYSTEM;
-
- if (!SetFileAttributes (win32_path, win32_path))
- __seterrno ();
- else if (!allow_ntsec)
- /* Correct NTFS security attributes have higher priority */
- res = 0;
- }
-
-done:
syscall_printf ("%d = chmod (%s, %p)", res, path, mode);
return res;
}
@@ -1013,18 +976,7 @@ fchmod (int fd, mode_t mode)
return -1;
}
- const char *path = cfd->get_name ();
-
- if (path == NULL)
- {
- syscall_printf ("-1 = fchmod (%d, 0%o) (no name)", fd, mode);
- set_errno (ENOSYS);
- return -1;
- }
-
- syscall_printf ("fchmod (%d, 0%o): calling chmod (%s, 0%o)",
- fd, mode, path, mode);
- return chmod (path, mode);
+ return cfd->fchmod (mode);
}
static void
@@ -1129,13 +1081,6 @@ sync ()
{
}
-suffix_info stat_suffixes[] =
-{
- suffix_info ("", 1),
- suffix_info (".exe", 1),
- suffix_info (NULL)
-};
-
/* Cygwin internal */
static int __stdcall
stat_worker (const char *name, struct __stat64 *buf, int nofollow)