diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2004-04-14 10:20:26 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2004-04-14 10:20:26 +0000 |
commit | f4ae6dc62cfb0cfac135d4e810fef592a401e26b (patch) | |
tree | 097e624c71735f25b1ec85fce0d456ba6f0eaa32 | |
parent | 93d66ddc2095c19a19df0f7d32cfda0560b3dfe6 (diff) | |
download | newlib-f4ae6dc62cfb0cfac135d4e810fef592a401e26b.zip newlib-f4ae6dc62cfb0cfac135d4e810fef592a401e26b.tar.gz newlib-f4ae6dc62cfb0cfac135d4e810fef592a401e26b.tar.bz2 |
* autoload.cc (NtSetSecurityObject): Add.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Only request
READ_CONTROL rights when opening the file.
* ntdll.h (NtSetSecurityObject): Add declaration.
* security.cc (write_sd): Call NtSetSecurityObject instead of
BackupWrite.
(get_nt_object_security): Don't free security descriptor here.
* syscalls.cc (ttyname): Use buffer of length TTY_NAME_MAX + 1.
* sysconf.cc (sysconf): Handle _SC_TTY_NAME_MAX request.
* include/limits.h: Define TTY_NAME_MAX and _POSIX_TTY_NAME_MAX.
-rw-r--r-- | winsup/cygwin/ChangeLog | 16 | ||||
-rw-r--r-- | winsup/cygwin/autoload.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/include/limits.h | 5 | ||||
-rw-r--r-- | winsup/cygwin/ntdll.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/security.cc | 68 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/sysconf.cc | 2 |
8 files changed, 48 insertions, 53 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index db6a4c7..18fc018 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,21 @@ 2004-04-14 Corinna Vinschen <corinna@vinschen.de> + * autoload.cc (NtSetSecurityObject): Add. + * fhandler_disk_file.cc (fhandler_disk_file::fchmod): Only request + READ_CONTROL rights when opening the file. + * ntdll.h (NtSetSecurityObject): Add declaration. + * security.cc (write_sd): Call NtSetSecurityObject instead of + BackupWrite. + (get_nt_object_security): Don't free security descriptor here. + +2004-04-14 Corinna Vinschen <corinna@vinschen.de> + + * syscalls.cc (ttyname): Use buffer of length TTY_NAME_MAX + 1. + * sysconf.cc (sysconf): Handle _SC_TTY_NAME_MAX request. + * include/limits.h: Define TTY_NAME_MAX and _POSIX_TTY_NAME_MAX. + +2004-04-14 Corinna Vinschen <corinna@vinschen.de> + * cygwin.din: Export rand_r and ttyname_r. * syscalls.cc (ttyname_r): New function. (ttyname): Move functionality to ttyname_r. Call it from here. diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index c8916fe..dc4ef96 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -394,6 +394,7 @@ LoadDLLfuncEx2 (NtQueryObject, 20, ntdll, 1, 1) LoadDLLfuncEx (NtQuerySystemInformation, 16, ntdll, 1) LoadDLLfuncEx (NtQuerySecurityObject, 20, ntdll, 1) LoadDLLfuncEx (NtQueryVirtualMemory, 24, ntdll, 1) +LoadDLLfuncEx (NtSetSecurityObject, 12, ntdll, 1) LoadDLLfuncEx (NtUnmapViewOfSection, 8, ntdll, 1) LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1) LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1) diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 0dce470..28f9306 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -377,7 +377,8 @@ fhandler_disk_file::fchmod (mode_t mode) if (pc.is_fs_special ()) return chmod_device (pc, mode); - if (!get_io_handle () && !(oret = open_fs (O_RDONLY | O_BINARY, 0))) + query_open (query_read_control); + if (!get_io_handle () && !(oret = open_fs (O_BINARY, 0))) return -1; SetFileAttributes (get_win32_name (), (DWORD) pc & ~FILE_ATTRIBUTE_READONLY); diff --git a/winsup/cygwin/include/limits.h b/winsup/cygwin/include/limits.h index f32cf53..579dc9c 100644 --- a/winsup/cygwin/include/limits.h +++ b/winsup/cygwin/include/limits.h @@ -151,6 +151,10 @@ details. */ #undef TIMER_MAX #define TIMER_MAX 32 +/* Maximum number of characters in a tty name. */ +#undef TTY_NAME_MAX +#define TTY_NAME_MAX 12 + /* POSIX values */ /* These should never vary from one system type to another */ /* They represent the minimum values that POSIX systems must support. @@ -170,6 +174,7 @@ details. */ #define _POSIX_TZNAME_MAX 3 #define _POSIX_RTSIG_MAX 8 #define _POSIX_TIMER_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 #define RTSIG_MAX _POSIX_RTSIG_MAX diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h index 1548443..d82ce49 100644 --- a/winsup/cygwin/ntdll.h +++ b/winsup/cygwin/ntdll.h @@ -412,6 +412,8 @@ extern "C" PSECURITY_DESCRIPTOR, ULONG, PULONG); NTSTATUS NTAPI NtQueryVirtualMemory (HANDLE, PVOID, MEMORY_INFORMATION_CLASS, PVOID, ULONG, PULONG); + NTSTATUS NTAPI NtSetSecurityObject (HANDLE, SECURITY_INFORMATION, + PSECURITY_DESCRIPTOR); NTSTATUS NTAPI NtUnmapViewOfSection (HANDLE, PVOID); VOID NTAPI RtlInitUnicodeString (PUNICODE_STRING, PCWSTR); ULONG NTAPI RtlNtStatusToDosError (NTSTATUS); diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index bbe409b..c932c24 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -1141,64 +1141,33 @@ write_sd (const char *file, security_descriptor &sd) else res = saved_res; if (res == 1 && owner != cygheap->user.sid ()) - return -1; - - HANDLE fh; - fh = CreateFile (file, - WRITE_OWNER | WRITE_DAC, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, - NULL); - - if (fh == INVALID_HANDLE_VALUE) { - __seterrno (); + set_errno (EPERM); return -1; } - - LPVOID context = NULL; - DWORD bytes_written = 0; - WIN32_STREAM_ID header; - - memset (&header, 0, sizeof (header)); - /* write new security info header */ - header.dwStreamId = BACKUP_SECURITY_DATA; - header.dwStreamAttributes = STREAM_CONTAINS_SECURITY; - header.Size.HighPart = 0; - header.Size.LowPart = sd.size (); - header.dwStreamNameSize = 0; - if (!BackupWrite (fh, (LPBYTE) &header, - 3 * sizeof (DWORD) + sizeof (LARGE_INTEGER), - &bytes_written, FALSE, TRUE, &context)) + HANDLE fh; + if ((fh = CreateFile (file, + WRITE_OWNER | WRITE_DAC, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, + NULL)) == INVALID_HANDLE_VALUE) { __seterrno (); - CloseHandle (fh); return -1; } - - /* write new security descriptor */ - if (!BackupWrite (fh, (LPBYTE) (PSECURITY_DESCRIPTOR) sd, - header.Size.LowPart + header.dwStreamNameSize, - &bytes_written, FALSE, TRUE, &context)) + NTSTATUS ret = NtSetSecurityObject (fh, + DACL_SECURITY_INFORMATION + | GROUP_SECURITY_INFORMATION + | OWNER_SECURITY_INFORMATION, + sd); + CloseHandle (fh); + if (ret != STATUS_SUCCESS) { - /* Samba returns ERROR_NOT_SUPPORTED. - FAT returns ERROR_INVALID_SECURITY_DESCR. - This shouldn't return as error, but better be ignored. */ - DWORD ret = GetLastError (); - if (ret != ERROR_NOT_SUPPORTED && ret != ERROR_INVALID_SECURITY_DESCR) - { - __seterrno (); - BackupWrite (fh, NULL, 0, &bytes_written, TRUE, TRUE, &context); - CloseHandle (fh); - return -1; - } + __seterrno_from_win_error (RtlNtStatusToDosError (ret)); + return -1; } - - /* terminate the restore process */ - BackupWrite (fh, NULL, 0, &bytes_written, TRUE, TRUE, &context); - CloseHandle (fh); return 0; } @@ -1391,7 +1360,6 @@ get_nt_object_security (HANDLE handle, SE_OBJECT_TYPE object_type, } if (ret != STATUS_SUCCESS) { - sd_ret.free (); __seterrno_from_win_error (RtlNtStatusToDosError (ret)); return -1; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index daae8a3..237e537 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1536,8 +1536,8 @@ ttyname_r (int fd, char *buf, size_t buflen) extern "C" char * ttyname (int fd) { - static char name[CYG_MAX_PATH]; - int ret = ttyname_r (fd, name, CYG_MAX_PATH); + static char name[TTY_NAME_MAX + 1]; + int ret = ttyname_r (fd, name, TTY_NAME_MAX + 1); if (ret) { set_errno (ret); diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc index 1e0f912..2f24cd2 100644 --- a/winsup/cygwin/sysconf.cc +++ b/winsup/cygwin/sysconf.cc @@ -122,6 +122,8 @@ sysconf (int in) } case _SC_RTSIG_MAX: return RTSIG_MAX; + case _SC_TTY_NAME_MAX: + return TTY_NAME_MAX; } /* Invalid input or unimplemented sysconf name */ |