4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-03-02 04:55:35 +08:00

* transport_pipes.h (PIPE_NAME_PREFIX): New define.

(PIPE_NAME_SUFFIX): Ditto.
	(class transport_layer_pipes): Convert _pipe_name from char pointer
	to wchar_t array.
	* transport_pipes.cc (transport_layer_pipes::transport_layer_pipes):
	Accommodate the fact that _pipe_name is a wchar_t array, rather than
	a char pointer.
	(transport_layer_pipes::transport_layer_pipes): Initialize _pipe_name
	with variable pipe name based in installation key fetched from Cygwin
	DLL.
	(transport_layer_pipes::accept): Call CreateNamedPipeW explicitely.
	(transport_layer_pipes::connect): Call CreateFileW and WaitNamedPipeW
	explicitely.
This commit is contained in:
Corinna Vinschen 2009-10-31 13:24:43 +00:00
parent 526b0fbca3
commit b079a89e25
3 changed files with 46 additions and 16 deletions

View File

@ -1,3 +1,19 @@
2009-10-31 Corinna Vinschen <corinna@vinschen.de>
* transport_pipes.h (PIPE_NAME_PREFIX): New define.
(PIPE_NAME_SUFFIX): Ditto.
(class transport_layer_pipes): Convert _pipe_name from char pointer
to wchar_t array.
* transport_pipes.cc (transport_layer_pipes::transport_layer_pipes):
Accommodate the fact that _pipe_name is a wchar_t array, rather than
a char pointer.
(transport_layer_pipes::transport_layer_pipes): Initialize _pipe_name
with variable pipe name based in installation key fetched from Cygwin
DLL.
(transport_layer_pipes::accept): Call CreateNamedPipeW explicitely.
(transport_layer_pipes::connect): Call CreateFileW and WaitNamedPipeW
explicitely.
2009-08-18 Corinna Vinschen <corinna@vinschen.de> 2009-08-18 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (CXXFLAGS): Allow override. * Makefile.in (CXXFLAGS): Allow override.

View File

@ -1,6 +1,6 @@
/* transport_pipes.cc /* transport_pipes.cc
Copyright 2001, 2002, 2003, 2004 Red Hat Inc. Copyright 2001, 2002, 2003, 2004, 2009 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -23,6 +23,8 @@ details. */
#include <netdb.h> #include <netdb.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h>
#include <sys/cygwin.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "transport.h" #include "transport.h"
@ -65,24 +67,33 @@ initialise_pipe_instance_lock ()
#ifndef __INSIDE_CYGWIN__ #ifndef __INSIDE_CYGWIN__
transport_layer_pipes::transport_layer_pipes (const HANDLE hPipe) transport_layer_pipes::transport_layer_pipes (const HANDLE hPipe)
: _pipe_name (""), : _hPipe (hPipe),
_hPipe (hPipe),
_is_accepted_endpoint (true), _is_accepted_endpoint (true),
_is_listening_endpoint (false) _is_listening_endpoint (false)
{ {
assert (_hPipe); assert (_hPipe);
assert (_hPipe != INVALID_HANDLE_VALUE); assert (_hPipe != INVALID_HANDLE_VALUE);
_pipe_name[0] = L'\0';
} }
#endif /* !__INSIDE_CYGWIN__ */ #endif /* !__INSIDE_CYGWIN__ */
transport_layer_pipes::transport_layer_pipes () transport_layer_pipes::transport_layer_pipes ()
: _pipe_name ("\\\\.\\pipe\\cygwin_lpc"), : _hPipe (NULL),
_hPipe (NULL),
_is_accepted_endpoint (false), _is_accepted_endpoint (false),
_is_listening_endpoint (false) _is_listening_endpoint (false)
{ {
#ifdef __INSIDE_CYGWIN__
extern WCHAR installation_key_buf[18];
wcpcpy (wcpcpy (wcpcpy (_pipe_name, PIPE_NAME_PREFIX), installation_key_buf),
PIPE_NAME_SUFFIX);
#else
wchar_t cyg_instkey[18];
wchar_t *p = wcpcpy (_pipe_name, PIPE_NAME_PREFIX);
if (cygwin_internal (CW_GET_INSTKEY, cyg_instkey))
wcpcpy (wcpcpy (p, cyg_instkey), PIPE_NAME_SUFFIX);
#endif
} }
transport_layer_pipes::~transport_layer_pipes () transport_layer_pipes::~transport_layer_pipes ()
@ -124,7 +135,7 @@ transport_layer_pipes::accept (bool *const recoverable)
const bool first_instance = (pipe_instance == 0); const bool first_instance = (pipe_instance == 0);
const HANDLE accept_pipe = const HANDLE accept_pipe =
CreateNamedPipe (_pipe_name, CreateNamedPipeW (_pipe_name,
(PIPE_ACCESS_DUPLEX (PIPE_ACCESS_DUPLEX
| (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0)), | (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0)),
(PIPE_TYPE_BYTE | PIPE_WAIT), (PIPE_TYPE_BYTE | PIPE_WAIT),
@ -270,13 +281,13 @@ transport_layer_pipes::connect ()
while (rc) while (rc)
{ {
_hPipe = CreateFile (_pipe_name, _hPipe = CreateFileW (_pipe_name,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_all_nih, &sec_all_nih,
OPEN_EXISTING, OPEN_EXISTING,
SECURITY_IMPERSONATION, SECURITY_IMPERSONATION,
NULL); NULL);
if (_hPipe != INVALID_HANDLE_VALUE) if (_hPipe != INVALID_HANDLE_VALUE)
{ {
@ -302,7 +313,7 @@ transport_layer_pipes::connect ()
* with ERROR_FILE_NOT_FOUND. * with ERROR_FILE_NOT_FOUND.
*/ */
while (retries != MAX_WAIT_NAMED_PIPE_RETRY while (retries != MAX_WAIT_NAMED_PIPE_RETRY
&& !(rc = WaitNamedPipe (_pipe_name, WAIT_NAMED_PIPE_TIMEOUT))) && !(rc = WaitNamedPipeW (_pipe_name, WAIT_NAMED_PIPE_TIMEOUT)))
{ {
if (GetLastError () == ERROR_FILE_NOT_FOUND) if (GetLastError () == ERROR_FILE_NOT_FOUND)
Sleep (0); // Give the server a chance. Sleep (0); // Give the server a chance.

View File

@ -13,6 +13,9 @@ details. */
#ifndef _TRANSPORT_PIPES_H #ifndef _TRANSPORT_PIPES_H
#define _TRANSPORT_PIPES_H #define _TRANSPORT_PIPES_H
#define PIPE_NAME_PREFIX L"\\\\.\\pipe\\cygwin-"
#define PIPE_NAME_SUFFIX L"-lpc"
/* Named pipes based transport, for security on NT */ /* Named pipes based transport, for security on NT */
class transport_layer_pipes : public transport_layer_base class transport_layer_pipes : public transport_layer_base
{ {
@ -36,7 +39,7 @@ public:
virtual ~transport_layer_pipes (); virtual ~transport_layer_pipes ();
private: private:
const char *const _pipe_name; wchar_t _pipe_name[40];
HANDLE _hPipe; HANDLE _hPipe;
const bool _is_accepted_endpoint; const bool _is_accepted_endpoint;
bool _is_listening_endpoint; bool _is_listening_endpoint;