implemented user access control in NamedPipeListener
[public/netxms.git] / src / libnetxms / nxproc.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** NetXMS Foundation Library
4 ** Copyright (C) 2003-2017 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: nxproc.cpp
21 **
22 **/
23
24 #include "libnetxms.h"
25 #include <nxproc.h>
26
27 /**
28 * Named pipe listener constructor
29 */
30 NamedPipeListener::NamedPipeListener(const TCHAR *name, HPIPE handle, NamedPipeRequestHandler reqHandler, void *userArg, const TCHAR *user)
31 {
32 nx_strncpy(m_name, name, MAX_PIPE_NAME_LEN);
33 m_handle = handle;
34 m_reqHandler = reqHandler;
35 m_userArg = userArg;
36 m_serverThread = INVALID_THREAD_HANDLE;
37 m_stop = false;
38 nx_strncpy(m_user, CHECK_NULL_EX(user), 64);
39 }
40
41 /**
42 * Start named pipe server
43 */
44 void NamedPipeListener::start()
45 {
46 if (m_serverThread != INVALID_THREAD_HANDLE)
47 return; // already started
48
49 m_stop = false;
50 m_serverThread = ThreadCreateEx(NamedPipeListener::serverThreadStarter, 0, this);
51 }
52
53 /**
54 * Stop named pipe server
55 */
56 void NamedPipeListener::stop()
57 {
58 m_stop = true;
59 ThreadJoin(m_serverThread);
60 m_serverThread = INVALID_THREAD_HANDLE;
61 }
62
63 /**
64 * Named pipe server thread starter
65 */
66 THREAD_RESULT THREAD_CALL NamedPipeListener::serverThreadStarter(void *arg)
67 {
68 static_cast<NamedPipeListener*>(arg)->serverThread();
69 return THREAD_OK;
70 }
71
72 /**
73 * Named pipe constructor
74 */
75 NamedPipe::NamedPipe(const TCHAR *name, HPIPE handle, const TCHAR *user)
76 {
77 nx_strncpy(m_name, name, MAX_PIPE_NAME_LEN);
78 m_handle = handle;
79 m_writeLock = MutexCreate();
80 nx_strncpy(m_user, CHECK_NULL_EX(user), 64);
81 }