1 /*
2    Copyright (c) 2013, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NAMED_PIPE_CONNECTION_INCLUDED
26 #define NAMED_PIPE_CONNECTION_INCLUDED
27 
28 #include "my_global.h"               // uint
29 
30 #include <string>
31 #include <Windows.h>
32 
33 class Channel_info;
34 class THD;
35 
36 
37 /**
38   This class abstracts Named pipe listener that setups a named pipe
39   handle to listen and receive client connections.
40 */
41 class Named_pipe_listener
42 {
43   std::string m_pipe_name;
44   SECURITY_ATTRIBUTES *mp_sa_pipe_security;
45   HANDLE m_pipe_handle;
46   char m_pipe_path_name[512];
47   HANDLE h_connected_pipe;
48   OVERLAPPED m_connect_overlapped;
49 
50 public:
51   /**
52     Constructor for named pipe listener
53 
54     @param  pipe_name name for pipe used in CreateNamedPipe function.
55   */
Named_pipe_listener(const std::string * pipe_name)56   Named_pipe_listener(const std::string *pipe_name)
57   : m_pipe_name(*pipe_name),
58     m_pipe_handle(INVALID_HANDLE_VALUE),
59     mp_sa_pipe_security(nullptr)
60   { }
61 
62 
63   /**
64     Set up a listener.
65 
66     @retval false listener listener has been setup successfully to listen for connect events
67             true  failure in setting up the listener.
68   */
69   bool setup_listener();
70 
71 
72   /**
73     The body of the event loop that listen for connection events from clients.
74 
75     @retval Channel_info   Channel_info object abstracting the connected client
76                            details for processing this connection.
77   */
78   Channel_info* listen_for_connection_event();
79 
80   /**
81   Set the Windows group name whose users have full access to new instances of
82   the named pipe
83 
84   @retval false access set successfully.
85   true failed to change access.
86   */
87   bool update_named_pipe_full_access_group(const char *new_group_name);
88 
89   /**
90     Close the listener
91   */
92   void close_listener();
93 };
94 
95 #endif // NAMED_PIPE_CONNECTION_INCLUDED.
96