+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>
* Makefile.in (CXXFLAGS): Allow override.
/* 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>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
+#include <wchar.h>
+#include <sys/cygwin.h>
#include "cygerrno.h"
#include "transport.h"
#ifndef __INSIDE_CYGWIN__
transport_layer_pipes::transport_layer_pipes (const HANDLE hPipe)
- : _pipe_name (""),
- _hPipe (hPipe),
+ : _hPipe (hPipe),
_is_accepted_endpoint (true),
_is_listening_endpoint (false)
{
assert (_hPipe);
assert (_hPipe != INVALID_HANDLE_VALUE);
-
+ _pipe_name[0] = L'\0';
}
#endif /* !__INSIDE_CYGWIN__ */
transport_layer_pipes::transport_layer_pipes ()
- : _pipe_name ("\\\\.\\pipe\\cygwin_lpc"),
- _hPipe (NULL),
+ : _hPipe (NULL),
_is_accepted_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 ()
const bool first_instance = (pipe_instance == 0);
const HANDLE accept_pipe =
- CreateNamedPipe (_pipe_name,
+ CreateNamedPipeW (_pipe_name,
(PIPE_ACCESS_DUPLEX
| (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0)),
(PIPE_TYPE_BYTE | PIPE_WAIT),
while (rc)
{
- _hPipe = CreateFile (_pipe_name,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- &sec_all_nih,
- OPEN_EXISTING,
- SECURITY_IMPERSONATION,
- NULL);
+ _hPipe = CreateFileW (_pipe_name,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ &sec_all_nih,
+ OPEN_EXISTING,
+ SECURITY_IMPERSONATION,
+ NULL);
if (_hPipe != INVALID_HANDLE_VALUE)
{
* with ERROR_FILE_NOT_FOUND.
*/
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)
Sleep (0); // Give the server a chance.
#ifndef _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 */
class transport_layer_pipes : public transport_layer_base
{
virtual ~transport_layer_pipes ();
private:
- const char *const _pipe_name;
+ wchar_t _pipe_name[40];
HANDLE _hPipe;
const bool _is_accepted_endpoint;
bool _is_listening_endpoint;