Adam Tkac | dfe19cf | 2010-04-23 14:14:11 +0000 | [diff] [blame] | 1 | /* 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 | |
| 21 | using namespace rfb; |
| 22 | |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 23 | SSecurityStack::SSecurityStack(SConnection* sc, int Type, |
| 24 | SSecurity* s0, SSecurity* s1) |
| 25 | : SSecurity(sc), state(0), state0(s0), state1(s1), type(Type) |
| 26 | { |
| 27 | } |
Adam Tkac | dfe19cf | 2010-04-23 14:14:11 +0000 | [diff] [blame] | 28 | |
| 29 | SSecurityStack::~SSecurityStack() |
| 30 | { |
| 31 | if (state0) |
| 32 | delete state0; |
| 33 | if (state1) |
| 34 | delete state1; |
| 35 | } |
| 36 | |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 37 | bool SSecurityStack::processMsg() |
Adam Tkac | dfe19cf | 2010-04-23 14:14:11 +0000 | [diff] [blame] | 38 | { |
| 39 | bool res = true; |
| 40 | |
| 41 | if (state == 0) { |
| 42 | if (state0) |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 43 | res = state0->processMsg(); |
Adam Tkac | dfe19cf | 2010-04-23 14:14:11 +0000 | [diff] [blame] | 44 | if (!res) |
| 45 | return res; |
| 46 | state++; |
| 47 | } |
| 48 | |
| 49 | if (state == 1) { |
| 50 | if (state1) |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 51 | res = state1->processMsg(); |
Adam Tkac | dfe19cf | 2010-04-23 14:14:11 +0000 | [diff] [blame] | 52 | if (!res) |
| 53 | return res; |
| 54 | state++; |
| 55 | } |
| 56 | |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | const 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 Ossman | 555815a | 2014-12-02 15:13:22 +0100 | [diff] [blame] | 71 | |
| 72 | SConnection::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 | } |