diff options
author | scottc <scottc> | 2002-09-19 21:51:21 +0000 |
---|---|---|
committer | scottc <scottc> | 2002-09-19 21:51:21 +0000 |
commit | 5b0334b499b769ce0bf8e28c47fa2382585666f0 (patch) | |
tree | 721ff3567e893df49ac1d3fcb21202157a4b7db3 | |
parent | 5d62df58b0e8f0f9b133c4c73136205c3b38c6cd (diff) | |
download | gdb-5b0334b499b769ce0bf8e28c47fa2382585666f0.tar.gz |
Merged changes from HEAD
-rw-r--r-- | winsup/cygwin/ChangeLog | 8 | ||||
-rw-r--r-- | winsup/cygwin/assert.cc | 6 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_console.cc | 20 | ||||
-rw-r--r-- | winsup/cygwin/fork.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/ntea.cc | 326 | ||||
-rw-r--r-- | winsup/cygwin/shared.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/spawn.cc | 11 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 23 | ||||
-rw-r--r-- | winsup/cygwin/times.cc | 12 |
11 files changed, 377 insertions, 59 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 25044b2c82d..49e2adf1c13 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2002-09-19 Christopher Faylor <cgf@redhat.com> + + Cleanup calls to CreateFile throughout. + * dcrt0.cc (__api_fatal): Correctly check for failing return from CreateFile. + * assert.cc (__assert): Don't check return value from CreateFile for NULL. + * fhandler_console.cc (set_console_state_for_spawn): Ditto. + * fork.cc (fork_parent): Ditto. + 2002-09-18 Christopher Faylor <cgf@redhat.com> * cygthread.cc (cygthread::initialized): Avoid copying on fork or some diff --git a/winsup/cygwin/assert.cc b/winsup/cygwin/assert.cc index fbce8753e8c..063c7b852ba 100644 --- a/winsup/cygwin/assert.cc +++ b/winsup/cygwin/assert.cc @@ -28,9 +28,9 @@ __assert (const char *file, int line, const char *failedexpr) /* If we don't have a console in a Windows program, then bring up a message box for the assertion failure. */ - h = CreateFileA ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE || h == 0) + h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { char *buf; diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 03618310639..701fb140cd2 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1053,10 +1053,10 @@ __api_fatal (const char *fmt, ...) a serious error. */ if (GetFileType (GetStdHandle (STD_ERROR_HANDLE)) != FILE_TYPE_CHAR) { - HANDLE h = CreateFileA ("CONOUT$", GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_WRITE | FILE_SHARE_WRITE, &sec_none, - OPEN_EXISTING, 0, 0); - if (h) + HANDLE h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_WRITE | FILE_SHARE_WRITE, + &sec_none, OPEN_EXISTING, 0, 0); + if (h != INVALID_HANDLE_VALUE) (void) WriteFile (h, buf, len, &done, 0); } diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 0b7bf65eef0..2726a2ab02c 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -436,7 +436,7 @@ fhandler_base::open (path_conv *pc, int flags, mode_t mode) x = CreateFile (get_win32_name (), access, shared, &sa, creation_distribution, file_attributes, 0); - syscall_printf ("%p = CreateFileA (%s, %p, %p, %p, %p, %p, 0)", + syscall_printf ("%p = CreateFile (%s, %p, %p, %p, %p, %p, 0)", x, get_win32_name (), access, shared, &sa, creation_distribution, file_attributes); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 895a98b8b3c..6a997f34ab4 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -135,11 +135,11 @@ tty_list::get_tty (int n) int __stdcall set_console_state_for_spawn () { - HANDLE h = CreateFileA ("CONIN$", GENERIC_READ, FILE_SHARE_WRITE, - &sec_none_nih, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE h = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_WRITE, + &sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, + NULL); - if (h == INVALID_HANDLE_VALUE || h == NULL) + if (h == INVALID_HANDLE_VALUE) return 0; if (shared_console_info != NULL) @@ -547,9 +547,9 @@ fhandler_console::open (path_conv *, int flags, mode_t) set_flags ((flags & ~O_TEXT) | O_BINARY); /* Open the input handle as handle_ */ - h = CreateFileA ("CONIN$", GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, - OPEN_EXISTING, 0, 0); + h = CreateFile ("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, + OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { @@ -559,9 +559,9 @@ fhandler_console::open (path_conv *, int flags, mode_t) set_io_handle (h); set_r_no_interrupt (1); // Handled explicitly in read code - h = CreateFileA ("CONOUT$", GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, - OPEN_EXISTING, 0, 0); + h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, &sec_none, + OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index dab9aced0c8..673d0d0ef5b 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -362,12 +362,12 @@ fork_parent (HANDLE& hParent, dll *&first_dll, /* If we don't have a console, then don't create a console for the child either. */ - HANDLE console_handle = CreateFileA ("CONOUT$", GENERIC_WRITE, - FILE_SHARE_WRITE, &sec_none_nih, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, - NULL); + HANDLE console_handle = CreateFile ("CONOUT$", GENERIC_WRITE, + FILE_SHARE_WRITE, &sec_none_nih, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, + NULL); - if (console_handle != INVALID_HANDLE_VALUE && console_handle != 0) + if (console_handle != INVALID_HANDLE_VALUE) CloseHandle (console_handle); else c_flags |= DETACHED_PROCESS; diff --git a/winsup/cygwin/ntea.cc b/winsup/cygwin/ntea.cc new file mode 100644 index 00000000000..95b5444a3ab --- /dev/null +++ b/winsup/cygwin/ntea.cc @@ -0,0 +1,326 @@ +/* ntea.cc: code for manipulating NTEA information + + Copyright 1997, 1998, 2000, 2001 Red Hat, Inc. + + Written by Sergey S. Okhapkin (sos@prospect.com.ru) + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include "winsup.h" +#include <stdio.h> +#include <stdlib.h> +#include "security.h" + +/* Default to not using NTEA information */ +BOOL allow_ntea; + +/* +From Windows NT DDK: + +FILE_FULL_EA_INFORMATION provides extended attribute information. +This structure is used primarily by network drivers. + +Members + +NextEntryOffset +The offset of the next FILE_FULL_EA_INFORMATION-type entry. This member is +zero if no other entries follow this one. + +Flags +Can be zero or can be set with FILE_NEED_EA, indicating that the file to which +the EA belongs cannot be interpreted without understanding the associated +extended attributes. + +EaNameLength +The length in bytes of the EaName array. This value does not include a +zero-terminator to EaName. + +EaValueLength +The length in bytes of each EA value in the array. + +EaName +An array of characters naming the EA for this entry. + +Comments +This structure is longword-aligned. If a set of FILE_FULL_EA_INFORMATION +entries is buffered, NextEntryOffset value in each entry, except the last, +falls on a longword boundary. +The value(s) associated with each entry follows the EaName array. That is, an +EA's values are located at EaName + (EaNameLength + 1). +*/ + +typedef struct _FILE_FULL_EA_INFORMATION { + ULONG NextEntryOffset; + UCHAR Flags; + UCHAR EaNameLength; + USHORT EaValueLength; + CHAR EaName[1]; +} FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION; + +/* Functions prototypes */ + +int NTReadEA (const char *file, const char *attrname, char *buf, int len); +static PFILE_FULL_EA_INFORMATION NTReadEARaw (HANDLE file, int *len); +BOOL NTWriteEA(const char *file, const char *attrname, char *buf, int len); + +/* + * NTReadEA - read file's Extended Attribute. + * + * Parameters: + * file - pointer to filename + * attrname- pointer to EA name (case insensitivy. EAs are sored in upper + * case). + * attrbuf - pointer to buffer to store EA's value. + * len - length of attrbuf. + * Return value: + * 0 - if file or attribute "attrname" not found. + * N - number of bytes stored in attrbuf if succes. + * -1 - attrbuf too small for EA value. + */ + +int __stdcall +NTReadEA (const char *file, const char *attrname, char *attrbuf, int len) +{ + HANDLE hFileSource; + int eafound = 0; + PFILE_FULL_EA_INFORMATION ea, sea; + int easize; + + hFileSource = CreateFile (file, FILE_READ_EA, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, // sa + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + + if (hFileSource == INVALID_HANDLE_VALUE) + return 0; + + /* Read in raw array of EAs */ + ea = sea = NTReadEARaw (hFileSource, &easize); + + /* Search for requested attribute */ + while (sea) + { + if (strcasematch (ea->EaName, attrname)) /* EA found */ + { + if (ea->EaValueLength > len) + { + eafound = -1; /* buffer too small */ + break; + } + memcpy (attrbuf, ea->EaName + (ea->EaNameLength + 1), + ea->EaValueLength); + eafound = ea->EaValueLength; + break; + } + if ((ea->NextEntryOffset == 0) || ((int) ea->NextEntryOffset > easize)) + break; + ea = (PFILE_FULL_EA_INFORMATION) ((char *) ea + ea->NextEntryOffset); + } + + if (sea) + free (sea); + CloseHandle (hFileSource); + + return eafound; +} + +/* + * NTReadEARaw - internal routine to read EAs array to malloced buffer. The + * caller should free this buffer after usage. + * Parameters: + * hFileSource - handle to file. This handle should have FILE_READ_EA + * rights. + * len - pointer to int variable where length of buffer will + * be stored. + * Return value: + * pointer to buffer with file's EAs, or NULL if any error occured. + */ + +static +PFILE_FULL_EA_INFORMATION +NTReadEARaw (HANDLE hFileSource, int *len) +{ + WIN32_STREAM_ID StreamId; + DWORD dwBytesWritten; + LPVOID lpContext; + DWORD StreamSize; + PFILE_FULL_EA_INFORMATION eafound = NULL; + + lpContext = NULL; + StreamSize = sizeof (WIN32_STREAM_ID) - sizeof (WCHAR**); + + /* Read the WIN32_STREAM_ID in */ + + while (BackupRead (hFileSource, (LPBYTE) &StreamId, StreamSize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + { + DWORD sl,sh; + + if (dwBytesWritten == 0) /* No more Stream IDs */ + break; + /* skip StreamName */ + if (StreamId.dwStreamNameSize) + { + unsigned char *buf; + buf = (unsigned char *) malloc (StreamId.dwStreamNameSize); + + if (buf == NULL) + break; + + if (!BackupRead (hFileSource, buf, // buffer to read + StreamId.dwStreamNameSize, // num bytes to read + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) // Stream name read error + { + free (buf); + break; + } + free (buf); + } + + /* Is it EA stream? */ + if (StreamId.dwStreamId == BACKUP_EA_DATA) + { + unsigned char *buf; + buf = (unsigned char *) malloc (StreamId.Size.LowPart); + + if (buf == NULL) + break; + if (!BackupRead (hFileSource, buf, // buffer to read + StreamId.Size.LowPart, // num bytes to write + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + { + free (buf); /* EA read error */ + break; + } + eafound = (PFILE_FULL_EA_INFORMATION) buf; + *len = StreamId.Size.LowPart; + break; + } + /* Skip current stream */ + if (!BackupSeek (hFileSource, + StreamId.Size.LowPart, + StreamId.Size.HighPart, + &sl, + &sh, + &lpContext)) + break; + } + + /* free context */ + BackupRead ( + hFileSource, + NULL, // buffer to write + 0, // number of bytes to write + &dwBytesWritten, + TRUE, // abort + FALSE, // don't process security + &lpContext); + + return eafound; +} + +/* + * NTWriteEA - write file's Extended Attribute. + * + * Parameters: + * file - pointer to filename + * attrname- pointer to EA name (case insensitivy. EAs are sored in upper + * case). + * buf - pointer to buffer with EA value. + * len - length of buf. + * Return value: + * TRUE if success, FALSE otherwice. + * Note: if len=0 given EA will be deleted. + */ + +BOOL __stdcall +NTWriteEA (const char *file, const char *attrname, const char *buf, int len) +{ + HANDLE hFileSource; + WIN32_STREAM_ID StreamId; + DWORD dwBytesWritten; + LPVOID lpContext; + DWORD StreamSize, easize; + BOOL bSuccess=FALSE; + PFILE_FULL_EA_INFORMATION ea; + + hFileSource = CreateFile (file, FILE_WRITE_EA, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, // sa + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + + if (hFileSource == INVALID_HANDLE_VALUE) + return FALSE; + + lpContext = NULL; + StreamSize = sizeof (WIN32_STREAM_ID) - sizeof (WCHAR**); + + /* FILE_FULL_EA_INFORMATION structure is longword-aligned */ + easize = sizeof (*ea) - sizeof (WCHAR**) + strlen (attrname) + 1 + len + + (sizeof (DWORD) - 1); + easize &= ~(sizeof (DWORD) - 1); + + if ((ea = (PFILE_FULL_EA_INFORMATION) malloc (easize)) == NULL) + goto cleanup; + + memset (ea, 0, easize); + ea->EaNameLength = strlen (attrname); + ea->EaValueLength = len; + strcpy (ea->EaName, attrname); + memcpy (ea->EaName + (ea->EaNameLength + 1), buf, len); + + StreamId.dwStreamId = BACKUP_EA_DATA; + StreamId.dwStreamAttributes = 0; + StreamId.Size.HighPart = 0; + StreamId.Size.LowPart = easize; + StreamId.dwStreamNameSize = 0; + + if (!BackupWrite (hFileSource, (LPBYTE) &StreamId, StreamSize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + goto cleanup; + + if (!BackupWrite (hFileSource, (LPBYTE) ea, easize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + goto cleanup; + + bSuccess = TRUE; + /* free context */ + +cleanup: + BackupRead (hFileSource, + NULL, // buffer to write + 0, // number of bytes to write + &dwBytesWritten, + TRUE, // abort + FALSE, // don't process security + &lpContext); + + CloseHandle (hFileSource); + if (ea) + free (ea); + + return bSuccess; +} diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 3031ae78086..5c3beb999a4 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -60,13 +60,9 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr) TRUE, mapname); } if (!shared_h && - !(shared_h = CreateFileMappingA (INVALID_HANDLE_VALUE, - &sec_all, - PAGE_READWRITE, - 0, - size, - mapname))) - api_fatal ("CreateFileMappingA, %E. Terminating."); + !(shared_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_all, + PAGE_READWRITE, 0, size, mapname))) + api_fatal ("CreateFileMapping, %E. Terminating."); } shared = (shared_info *) MapViewOfFileEx (shared_h, diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 8c1c18adb25..193f593bc92 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -420,13 +420,10 @@ spawn_guts (const char * prog_arg, const char *const *argv, that it is NOT a script file */ while (*ext == '\0') { - HANDLE hnd = CreateFileA (real_path, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0); + HANDLE hnd = CreateFile (real_path, GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, 0); if (hnd == INVALID_HANDLE_VALUE) { __seterrno (); diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 8c2b96b7b3e..650cad80aaf 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -648,15 +648,10 @@ _link (const char *a, const char *b) BOOL bSuccess; - hFileSource = CreateFile ( - real_a, - FILE_WRITE_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE /*| FILE_SHARE_DELETE*/, - &sec_none_nih, // sa - OPEN_EXISTING, - 0, - NULL - ); + hFileSource = CreateFile (real_a, FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE /*| FILE_SHARE_DELETE*/, + &sec_none_nih, // sa + OPEN_EXISTING, 0, NULL); if (hFileSource == INVALID_HANDLE_VALUE) { @@ -2433,12 +2428,10 @@ logout (char *line) return 0; ut_fd = CreateFile (win32_path.get_win32 (), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); if (ut_fd != INVALID_HANDLE_VALUE) { struct utmp *ut; diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index a7dec6a9b94..ed0680235d6 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -471,13 +471,11 @@ utimes (const char *path, struct timeval *tvp) the times of directories. */ /* Note: It's not documented in MSDN that FILE_WRITE_ATTRIBUTES is sufficient to change the timestamps... */ - HANDLE h = CreateFileA (win32.get_win32 (), - FILE_WRITE_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_none_nih, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, - 0); + HANDLE h = CreateFile (win32, FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, + 0); if (h == INVALID_HANDLE_VALUE) { |