mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-21 00:07:36 +08:00
* fhandler_disk_file.cc (fhandler_base::open_fs): Change
set_file_attribute call to indicate that NT security isn't used. (fhandler_disk_file::fchmod): Rearrange to isolate 9x related statements. Do not set FILE_ATTRIBUTE_SYSTEM. (fhandler_disk_file::fchown): Check noop case first. * fhandler.cc (fhandler_base::open9x): Remove ntsec related statements. (fhandler_base::set_name): Do not set namehash. * fhandler.h (fhandler_base::get_namehash): Compute and set namehash if needed. * syscalls.cc (access): Verify that fh is not NULL. Do not set PC_FULL. (chmod): Ditto. (chown_worker): Ditto. (stat_worker): Ditto. Verify if the path exists.
This commit is contained in:
parent
4cc12c5630
commit
c8daf9983b
@ -1,3 +1,20 @@
|
||||
2004-04-20 Pierre Humblet <pierre.humblet@ieee.org>
|
||||
|
||||
* fhandler_disk_file.cc (fhandler_base::open_fs): Change
|
||||
set_file_attribute call to indicate that NT security isn't used.
|
||||
(fhandler_disk_file::fchmod): Rearrange to isolate 9x related
|
||||
statements.
|
||||
Do not set FILE_ATTRIBUTE_SYSTEM.
|
||||
(fhandler_disk_file::fchown): Check noop case first.
|
||||
* fhandler.cc (fhandler_base::open9x): Remove ntsec related statements.
|
||||
(fhandler_base::set_name): Do not set namehash.
|
||||
* fhandler.h (fhandler_base::get_namehash): Compute and set namehash if
|
||||
needed.
|
||||
* syscalls.cc (access): Verify that fh is not NULL. Do not set PC_FULL.
|
||||
(chmod): Ditto.
|
||||
(chown_worker): Ditto.
|
||||
(stat_worker): Ditto. Verify if the path exists.
|
||||
|
||||
2004-04-20 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* fhandler.cc (fhandler_base::open): Remove special DEV_FLOPPY_MAJOR
|
||||
|
@ -152,7 +152,6 @@ fhandler_base::set_name (path_conv &in_pc)
|
||||
{
|
||||
memcpy (&pc, &in_pc, in_pc.size ());
|
||||
pc.set_normalized_path (in_pc.normalized_path);
|
||||
namehash = hash_path_name (0, get_win32_name ());
|
||||
}
|
||||
|
||||
/* Detect if we are sitting at EOF for conditions where Windows
|
||||
@ -435,7 +434,6 @@ fhandler_base::open_9x (int flags, mode_t mode)
|
||||
int shared;
|
||||
int creation_distribution;
|
||||
SECURITY_ATTRIBUTES sa = sec_none;
|
||||
security_descriptor sd;
|
||||
|
||||
syscall_printf ("(%s, %p)", get_win32_name (), flags);
|
||||
|
||||
@ -492,17 +490,12 @@ fhandler_base::open_9x (int flags, mode_t mode)
|
||||
if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
||||
file_attributes |= FILE_ATTRIBUTE_READONLY;
|
||||
|
||||
/* If the file should actually be created and ntsec is on,
|
||||
set files attributes. */
|
||||
if (flags & O_CREAT && get_device () == FH_FS && allow_ntsec && has_acls ())
|
||||
set_security_attribute (mode, &sa, sd);
|
||||
|
||||
x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution,
|
||||
file_attributes, 0);
|
||||
|
||||
if (x == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!wincap.can_open_directories () && pc.isdir ())
|
||||
if (pc.isdir ())
|
||||
{
|
||||
if (flags & (O_CREAT | O_EXCL) == (O_CREAT | O_EXCL))
|
||||
set_errno (EEXIST);
|
||||
|
@ -217,7 +217,7 @@ class fhandler_base
|
||||
bool has_attribute (DWORD x) const {return pc.has_attribute (x);}
|
||||
const char *get_name () const { return pc.normalized_path; }
|
||||
const char *get_win32_name () { return pc.get_win32 (); }
|
||||
__ino64_t get_namehash () { return namehash; }
|
||||
__ino64_t get_namehash () { return namehash ?: namehash = hash_path_name (0, get_win32_name ()); }
|
||||
|
||||
virtual void hclose (HANDLE h) {CloseHandle (h);}
|
||||
virtual void set_no_inheritance (HANDLE &h, int not_inheriting);
|
||||
|
@ -387,16 +387,19 @@ fhandler_disk_file::fchmod (mode_t mode)
|
||||
if (!(oret = open_fs (O_BINARY, 0)))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allow_ntsec && allow_ntea) /* Not necessary when manipulating SD. */
|
||||
SetFileAttributes (pc, (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
|
||||
if (pc.isdir ())
|
||||
mode |= S_IFDIR;
|
||||
if (!set_file_attribute (pc.has_acls (), get_io_handle (), pc,
|
||||
ILLEGAL_UID, ILLEGAL_GID, mode)
|
||||
&& allow_ntsec)
|
||||
res = 0;
|
||||
if (!allow_ntsec && allow_ntea) /* Not necessary when manipulating SD. */
|
||||
SetFileAttributes (pc, (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
|
||||
if (pc.isdir ())
|
||||
mode |= S_IFDIR;
|
||||
if (!set_file_attribute (pc.has_acls (), get_io_handle (), pc,
|
||||
ILLEGAL_UID, ILLEGAL_GID, mode)
|
||||
&& allow_ntsec)
|
||||
res = 0;
|
||||
|
||||
if (oret)
|
||||
close_fs ();
|
||||
}
|
||||
|
||||
/* if the mode we want has any write bits set, we can't be read only. */
|
||||
if (mode & (S_IWUSR | S_IWGRP | S_IWOTH))
|
||||
@ -404,18 +407,12 @@ fhandler_disk_file::fchmod (mode_t mode)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -424,6 +421,13 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid)
|
||||
{
|
||||
int oret = 0;
|
||||
|
||||
if (!pc.has_acls () || !allow_ntsec)
|
||||
{
|
||||
/* fake - if not supported, pretend we're like win95
|
||||
where it just works */
|
||||
return 0;
|
||||
}
|
||||
|
||||
enable_restore_privilege ();
|
||||
if (!get_io_handle ())
|
||||
{
|
||||
@ -439,12 +443,6 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid)
|
||||
if (!res)
|
||||
res = set_file_attribute (pc.has_acls (), get_io_handle (), pc,
|
||||
uid, gid, attrib);
|
||||
if (res && (!pc.has_acls () || !allow_ntsec))
|
||||
{
|
||||
/* fake - if not supported, pretend we're like win95
|
||||
where it just works */
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (oret)
|
||||
close_fs ();
|
||||
@ -587,7 +585,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 (), NULL, get_win32_name (), mode);
|
||||
set_file_attribute (false, NULL, get_win32_name (), mode);
|
||||
|
||||
set_fs_flags (pc.fs_flags ());
|
||||
|
||||
|
@ -827,8 +827,11 @@ chown_worker (const char *name, unsigned fmode, __uid32_t uid, __gid32_t gid)
|
||||
return 0; // return zero (and do nothing) under Windows 9x
|
||||
|
||||
int res = -1;
|
||||
fhandler_base *fh = build_fh_name (name, NULL, fmode | PC_FULL,
|
||||
stat_suffixes);
|
||||
fhandler_base *fh;
|
||||
|
||||
if (!(fh = build_fh_name (name, NULL, fmode, stat_suffixes)))
|
||||
goto error;
|
||||
|
||||
if (fh->error ())
|
||||
{
|
||||
debug_printf ("got %d error from build_fh_name", fh->error ());
|
||||
@ -838,6 +841,7 @@ chown_worker (const char *name, unsigned fmode, __uid32_t uid, __gid32_t gid)
|
||||
res = fh->fchown (uid, gid);
|
||||
|
||||
delete fh;
|
||||
error:
|
||||
syscall_printf ("%d = %schown (%s,...)",
|
||||
res, (fmode & PC_SYM_NOFOLLOW) ? "l" : "", name);
|
||||
return res;
|
||||
@ -916,8 +920,10 @@ extern "C" int
|
||||
chmod (const char *path, mode_t mode)
|
||||
{
|
||||
int res = -1;
|
||||
fhandler_base *fh = build_fh_name (path, NULL, PC_SYM_FOLLOW | PC_FULL,
|
||||
stat_suffixes);
|
||||
fhandler_base *fh;
|
||||
if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW, stat_suffixes)))
|
||||
goto error;
|
||||
|
||||
if (fh->error ())
|
||||
{
|
||||
debug_printf ("got %d error from build_fh_name", fh->error ());
|
||||
@ -927,6 +933,7 @@ chmod (const char *path, mode_t mode)
|
||||
res = fh->fchmod (mode);
|
||||
|
||||
delete fh;
|
||||
error:
|
||||
syscall_printf ("%d = chmod (%s, %p)", res, path, mode);
|
||||
return res;
|
||||
}
|
||||
@ -1056,17 +1063,18 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow)
|
||||
fhandler_base *fh = NULL;
|
||||
|
||||
if (check_null_invalid_struct_errno (buf))
|
||||
goto done;
|
||||
|
||||
fh = build_fh_name (name, NULL, (nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW)
|
||||
| PC_FULL, stat_suffixes);
|
||||
goto error;
|
||||
|
||||
if (!(fh = build_fh_name (name, NULL, nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW,
|
||||
stat_suffixes)))
|
||||
goto error;
|
||||
|
||||
if (fh->error ())
|
||||
{
|
||||
debug_printf ("got %d error from build_fh_name", fh->error ());
|
||||
set_errno (fh->error ());
|
||||
}
|
||||
else
|
||||
else if (fh->exists ())
|
||||
{
|
||||
debug_printf ("(%s, %p, %d, %p), file_attributes %d", name, buf, nofollow,
|
||||
fh, (DWORD) *fh);
|
||||
@ -1082,10 +1090,11 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow)
|
||||
buf->st_rdev = buf->st_dev;
|
||||
}
|
||||
}
|
||||
else
|
||||
set_errno (ENOENT);
|
||||
|
||||
done:
|
||||
if (fh)
|
||||
delete fh;
|
||||
delete fh;
|
||||
error:
|
||||
MALLOC_CHECK;
|
||||
syscall_printf ("%d = (%s, %p)", res, name, buf);
|
||||
return res;
|
||||
@ -1158,9 +1167,12 @@ access (const char *fn, int flags)
|
||||
set_errno (EINVAL);
|
||||
else
|
||||
{
|
||||
fhandler_base *fh = build_fh_name (fn, NULL, PC_SYM_FOLLOW | PC_FULL, stat_suffixes);
|
||||
res = fh->fhaccess (flags);
|
||||
delete fh;
|
||||
fhandler_base *fh = build_fh_name (fn, NULL, PC_SYM_FOLLOW, stat_suffixes);
|
||||
if (fh)
|
||||
{
|
||||
res = fh->fhaccess (flags);
|
||||
delete fh;
|
||||
}
|
||||
}
|
||||
debug_printf ("returning %d", res);
|
||||
return res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user