* 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:
Corinna Vinschen 2004-04-20 15:51:24 +00:00
parent 4cc12c5630
commit c8daf9983b
5 changed files with 66 additions and 46 deletions

View File

@ -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> 2004-04-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::open): Remove special DEV_FLOPPY_MAJOR * fhandler.cc (fhandler_base::open): Remove special DEV_FLOPPY_MAJOR

View File

@ -152,7 +152,6 @@ fhandler_base::set_name (path_conv &in_pc)
{ {
memcpy (&pc, &in_pc, in_pc.size ()); memcpy (&pc, &in_pc, in_pc.size ());
pc.set_normalized_path (in_pc.normalized_path); 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 /* 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 shared;
int creation_distribution; int creation_distribution;
SECURITY_ATTRIBUTES sa = sec_none; SECURITY_ATTRIBUTES sa = sec_none;
security_descriptor sd;
syscall_printf ("(%s, %p)", get_win32_name (), flags); 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))) if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
file_attributes |= FILE_ATTRIBUTE_READONLY; 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, x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution,
file_attributes, 0); file_attributes, 0);
if (x == INVALID_HANDLE_VALUE) 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)) if (flags & (O_CREAT | O_EXCL) == (O_CREAT | O_EXCL))
set_errno (EEXIST); set_errno (EEXIST);

View File

@ -217,7 +217,7 @@ class fhandler_base
bool has_attribute (DWORD x) const {return pc.has_attribute (x);} bool has_attribute (DWORD x) const {return pc.has_attribute (x);}
const char *get_name () const { return pc.normalized_path; } const char *get_name () const { return pc.normalized_path; }
const char *get_win32_name () { return pc.get_win32 (); } 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 hclose (HANDLE h) {CloseHandle (h);}
virtual void set_no_inheritance (HANDLE &h, int not_inheriting); virtual void set_no_inheritance (HANDLE &h, int not_inheriting);

View File

@ -387,16 +387,19 @@ fhandler_disk_file::fchmod (mode_t mode)
if (!(oret = open_fs (O_BINARY, 0))) if (!(oret = open_fs (O_BINARY, 0)))
return -1; return -1;
} }
}
if (!allow_ntsec && allow_ntea) /* Not necessary when manipulating SD. */ if (!allow_ntsec && allow_ntea) /* Not necessary when manipulating SD. */
SetFileAttributes (pc, (DWORD) pc & ~FILE_ATTRIBUTE_READONLY); SetFileAttributes (pc, (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
if (pc.isdir ()) if (pc.isdir ())
mode |= S_IFDIR; mode |= S_IFDIR;
if (!set_file_attribute (pc.has_acls (), get_io_handle (), pc, if (!set_file_attribute (pc.has_acls (), get_io_handle (), pc,
ILLEGAL_UID, ILLEGAL_GID, mode) ILLEGAL_UID, ILLEGAL_GID, mode)
&& allow_ntsec) && allow_ntsec)
res = 0; res = 0;
if (oret)
close_fs ();
}
/* if the mode we want has any write bits set, we can't be read only. */ /* if the mode we want has any write bits set, we can't be read only. */
if (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) if (mode & (S_IWUSR | S_IWGRP | S_IWOTH))
@ -404,18 +407,12 @@ fhandler_disk_file::fchmod (mode_t mode)
else else
(DWORD) pc |= FILE_ATTRIBUTE_READONLY; (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)) if (!SetFileAttributes (pc, pc))
__seterrno (); __seterrno ();
else if (!allow_ntsec) else if (!allow_ntsec)
/* Correct NTFS security attributes have higher priority */ /* Correct NTFS security attributes have higher priority */
res = 0; res = 0;
if (oret)
close_fs ();
return res; return res;
} }
@ -424,6 +421,13 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid)
{ {
int oret = 0; 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 (); enable_restore_privilege ();
if (!get_io_handle ()) if (!get_io_handle ())
{ {
@ -439,12 +443,6 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid)
if (!res) if (!res)
res = set_file_attribute (pc.has_acls (), get_io_handle (), pc, res = set_file_attribute (pc.has_acls (), get_io_handle (), pc,
uid, gid, attrib); 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) if (oret)
close_fs (); close_fs ();
@ -587,7 +585,7 @@ fhandler_base::open_fs (int flags, mode_t mode)
if (flags & O_CREAT if (flags & O_CREAT
&& GetLastError () != ERROR_ALREADY_EXISTS && GetLastError () != ERROR_ALREADY_EXISTS
&& !allow_ntsec && allow_ntea) && !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 ()); set_fs_flags (pc.fs_flags ());

View File

@ -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 return 0; // return zero (and do nothing) under Windows 9x
int res = -1; int res = -1;
fhandler_base *fh = build_fh_name (name, NULL, fmode | PC_FULL, fhandler_base *fh;
stat_suffixes);
if (!(fh = build_fh_name (name, NULL, fmode, stat_suffixes)))
goto error;
if (fh->error ()) if (fh->error ())
{ {
debug_printf ("got %d error from build_fh_name", 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); res = fh->fchown (uid, gid);
delete fh; delete fh;
error:
syscall_printf ("%d = %schown (%s,...)", syscall_printf ("%d = %schown (%s,...)",
res, (fmode & PC_SYM_NOFOLLOW) ? "l" : "", name); res, (fmode & PC_SYM_NOFOLLOW) ? "l" : "", name);
return res; return res;
@ -916,8 +920,10 @@ extern "C" int
chmod (const char *path, mode_t mode) chmod (const char *path, mode_t mode)
{ {
int res = -1; int res = -1;
fhandler_base *fh = build_fh_name (path, NULL, PC_SYM_FOLLOW | PC_FULL, fhandler_base *fh;
stat_suffixes); if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW, stat_suffixes)))
goto error;
if (fh->error ()) if (fh->error ())
{ {
debug_printf ("got %d error from build_fh_name", 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); res = fh->fchmod (mode);
delete fh; delete fh;
error:
syscall_printf ("%d = chmod (%s, %p)", res, path, mode); syscall_printf ("%d = chmod (%s, %p)", res, path, mode);
return res; return res;
} }
@ -1056,17 +1063,18 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow)
fhandler_base *fh = NULL; fhandler_base *fh = NULL;
if (check_null_invalid_struct_errno (buf)) if (check_null_invalid_struct_errno (buf))
goto done; goto error;
fh = build_fh_name (name, NULL, (nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW) if (!(fh = build_fh_name (name, NULL, nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW,
| PC_FULL, stat_suffixes); stat_suffixes)))
goto error;
if (fh->error ()) if (fh->error ())
{ {
debug_printf ("got %d error from build_fh_name", fh->error ()); debug_printf ("got %d error from build_fh_name", fh->error ());
set_errno (fh->error ()); set_errno (fh->error ());
} }
else else if (fh->exists ())
{ {
debug_printf ("(%s, %p, %d, %p), file_attributes %d", name, buf, nofollow, debug_printf ("(%s, %p, %d, %p), file_attributes %d", name, buf, nofollow,
fh, (DWORD) *fh); fh, (DWORD) *fh);
@ -1082,10 +1090,11 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow)
buf->st_rdev = buf->st_dev; buf->st_rdev = buf->st_dev;
} }
} }
else
set_errno (ENOENT);
done: delete fh;
if (fh) error:
delete fh;
MALLOC_CHECK; MALLOC_CHECK;
syscall_printf ("%d = (%s, %p)", res, name, buf); syscall_printf ("%d = (%s, %p)", res, name, buf);
return res; return res;
@ -1158,9 +1167,12 @@ access (const char *fn, int flags)
set_errno (EINVAL); set_errno (EINVAL);
else else
{ {
fhandler_base *fh = build_fh_name (fn, NULL, PC_SYM_FOLLOW | PC_FULL, stat_suffixes); fhandler_base *fh = build_fh_name (fn, NULL, PC_SYM_FOLLOW, stat_suffixes);
res = fh->fhaccess (flags); if (fh)
delete fh; {
res = fh->fhaccess (flags);
delete fh;
}
} }
debug_printf ("returning %d", res); debug_printf ("returning %d", res);
return res; return res;