Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2002-2004 RealVNC Ltd. All Rights Reserved. |
| 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 | // CurrentUser.h |
| 20 | |
| 21 | // Helper class providing the session's logged on username, if |
| 22 | // a user is logged on. Also allows processes running under |
| 23 | // XP/2K3 etc to masquerade as the logged on user for security |
| 24 | // purposes |
| 25 | |
| 26 | #ifndef __RFB_WIN32_CURRENT_USER_H__ |
| 27 | #define __RFB_WIN32_CURRENT_USER_H__ |
| 28 | |
| 29 | #include <rfb_win32/Service.h> |
| 30 | #include <rfb_win32/OSVersion.h> |
| 31 | #include <rfb_win32/Win32Util.h> |
| 32 | |
| 33 | namespace rfb { |
| 34 | |
| 35 | namespace win32 { |
| 36 | |
| 37 | // CurrentUserToken |
| 38 | // h == 0 |
| 39 | // if platform is not NT *or* unable to get token |
| 40 | // *or* if process is hosting service. |
| 41 | // h != 0 |
| 42 | // if process is hosting service *and* |
| 43 | // if platform is NT *and* able to get token. |
| 44 | // isValid() == true |
| 45 | // if platform is not NT *or* token is valid. |
| 46 | |
| 47 | struct CurrentUserToken : public Handle { |
| 48 | CurrentUserToken(); |
| 49 | bool isValid() const {return isValid_;}; |
| 50 | private: |
| 51 | bool isValid_; |
| 52 | }; |
| 53 | |
| 54 | // ImpersonateCurrentUser |
| 55 | // Throws an exception on failure. |
| 56 | // Succeeds (trivially) if process is not running as service. |
| 57 | // Fails if CurrentUserToken is not valid. |
| 58 | // Fails if platform is NT AND cannot impersonate token. |
| 59 | // Succeeds otherwise. |
| 60 | |
| 61 | struct ImpersonateCurrentUser { |
| 62 | ImpersonateCurrentUser(); |
| 63 | ~ImpersonateCurrentUser(); |
| 64 | CurrentUserToken token; |
| 65 | }; |
| 66 | |
| 67 | // UserName |
| 68 | // Returns the name of the user the thread is currently running as. |
| 69 | |
| 70 | struct UserName : public TCharArray { |
| 71 | UserName(); |
| 72 | }; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | |
| 78 | #endif |