4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 00:07:36 +08:00

* dir.cc (rmdir): Streamline. Detect attempts to remove directories from

"read-only" virtual devices.  (Suggested by Pavel Tsekov)
* syscalls.cc (unlink): Detect attempts to remove directories from "read-only"
virtual devices.  (From Pavel Tsekov)
This commit is contained in:
Christopher Faylor 2002-06-05 16:01:55 +00:00
parent 2bb6b3e506
commit ea4e6ec8f9
3 changed files with 34 additions and 26 deletions

View File

@ -1,3 +1,10 @@
2002-06-05 Christopher Faylor <cgf@redhat.com>
* dir.cc (rmdir): Streamline. Detect attempts to remove directories
from "read-only" virtual devices. (Suggested by Pavel Tsekov)
* syscalls.cc (unlink): Detect attempts to remove directories
from "read-only" virtual devices. (From Pavel Tsekov)
2002-06-05 Christopher Faylor <cgf@redhat.com> 2002-06-05 Christopher Faylor <cgf@redhat.com>
* dtable.cc (handle_to_fn): Check error return value from NtQueryObject * dtable.cc (handle_to_fn): Check error return value from NtQueryObject
@ -61,7 +68,7 @@
2002-06-04 Christopher Faylor <cgf@redhat.com> 2002-06-04 Christopher Faylor <cgf@redhat.com>
* dtable.cc (handle_to_fn): Correct placement and length of name * dtable.cc (handle_to_fn): Correct placement and length of name
buffer. (Suggested by Pavel Tsekov) buffer. (Suggested by Pavel Tsekov)
2002-06-04 Christopher Faylor <cgf@redhat.com> 2002-06-04 Christopher Faylor <cgf@redhat.com>

View File

@ -273,24 +273,19 @@ extern "C" int
rmdir (const char *dir) rmdir (const char *dir)
{ {
int res = -1; int res = -1;
DWORD devn;
path_conv real_dir (dir, PC_SYM_NOFOLLOW); path_conv real_dir (dir, PC_SYM_NOFOLLOW);
if (real_dir.error) if (real_dir.error)
{ set_errno (real_dir.error);
set_errno (real_dir.error); else if ((devn = real_dir.get_devn ()) == FH_PROC || devn == FH_REGISTRY
res = -1; || devn == FH_PROCESS)
} set_errno (EROFS);
else if (!real_dir.exists ()) else if (!real_dir.exists ())
{ set_errno (ENOENT);
set_errno (ENOENT);
res = -1;
}
else if (!real_dir.isdir ()) else if (!real_dir.isdir ())
{ set_errno (ENOTDIR);
set_errno (ENOTDIR);
res = -1;
}
else else
{ {
/* Even own directories can't be removed if R/O attribute is set. */ /* Even own directories can't be removed if R/O attribute is set. */
@ -330,22 +325,20 @@ rmdir (const char *dir)
else if ((res = rmdir (dir))) else if ((res = rmdir (dir)))
SetCurrentDirectory (cygheap->cwd.win32); SetCurrentDirectory (cygheap->cwd.win32);
} }
if (GetLastError () == ERROR_ACCESS_DENIED) if (res)
{ {
if (GetLastError () != ERROR_ACCESS_DENIED
/* On 9X ERROR_ACCESS_DENIED is returned if you try to remove || !wincap.access_denied_on_delete ())
a non-empty directory. */
if (wincap.access_denied_on_delete ())
set_errno (ENOTEMPTY);
else
__seterrno (); __seterrno ();
} else
else set_errno (ENOTEMPTY); /* On 9X ERROR_ACCESS_DENIED is
__seterrno (); returned if you try to remove a
non-empty directory. */
/* If directory still exists, restore R/O attribute. */ /* If directory still exists, restore R/O attribute. */
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY)) if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
SetFileAttributes (real_dir, real_dir); SetFileAttributes (real_dir, real_dir);
}
} }
} }

View File

@ -94,6 +94,7 @@ extern "C" int
_unlink (const char *ourname) _unlink (const char *ourname)
{ {
int res = -1; int res = -1;
DWORD devn;
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
path_conv win32_name (ourname, PC_SYM_NOFOLLOW | PC_FULL); path_conv win32_name (ourname, PC_SYM_NOFOLLOW | PC_FULL);
@ -104,6 +105,13 @@ _unlink (const char *ourname)
goto done; goto done;
} }
if ((devn = win32_name.get_devn ()) == FH_PROC || devn == FH_REGISTRY
|| devn == FH_PROCESS)
{
set_errno (EROFS);
goto done;
}
syscall_printf ("_unlink (%s)", win32_name.get_win32 ()); syscall_printf ("_unlink (%s)", win32_name.get_win32 ());
if (!win32_name.exists ()) if (!win32_name.exists ())