blob: 74509e7175c25e5660f007ea66a653431c993f64 [file] [log] [blame]
Adam Tkacdfe19cf2010-04-23 14:14:11 +00001/* Copyright (C) 2005 Martin Koegler
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <rfb/SSecurityStack.h>
20
21using namespace rfb;
22
Pierre Ossmanad2b3c42018-09-21 15:31:11 +020023SSecurityStack::SSecurityStack(SConnection* sc, int Type,
24 SSecurity* s0, SSecurity* s1)
25 : SSecurity(sc), state(0), state0(s0), state1(s1), type(Type)
26{
27}
Adam Tkacdfe19cf2010-04-23 14:14:11 +000028
29SSecurityStack::~SSecurityStack()
30{
31 if (state0)
32 delete state0;
33 if (state1)
34 delete state1;
35}
36
Pierre Ossmanad2b3c42018-09-21 15:31:11 +020037bool SSecurityStack::processMsg()
Adam Tkacdfe19cf2010-04-23 14:14:11 +000038{
39 bool res = true;
40
41 if (state == 0) {
42 if (state0)
Pierre Ossmanad2b3c42018-09-21 15:31:11 +020043 res = state0->processMsg();
Adam Tkacdfe19cf2010-04-23 14:14:11 +000044 if (!res)
45 return res;
46 state++;
47 }
48
49 if (state == 1) {
50 if (state1)
Pierre Ossmanad2b3c42018-09-21 15:31:11 +020051 res = state1->processMsg();
Adam Tkacdfe19cf2010-04-23 14:14:11 +000052 if (!res)
53 return res;
54 state++;
55 }
56
57 return res;
58}
59
60const char* SSecurityStack::getUserName() const
61{
62 const char* c = 0;
63
64 if (state1 && !c)
65 c = state1->getUserName();
66 if (state0 && !c)
67 c = state0->getUserName();
68
69 return c;
70}
Pierre Ossman555815a2014-12-02 15:13:22 +010071
72SConnection::AccessRights SSecurityStack::getAccessRights() const
73{
74 SConnection::AccessRights accessRights;
75
76 if (!state0 && !state1)
77 return SSecurity::getAccessRights();
78
79 accessRights = SConnection::AccessFull;
80
81 if (state0)
82 accessRights &= state0->getAccessRights();
83 if (state1)
84 accessRights &= state1->getAccessRights();
85
86 return accessRights;
87}