blob: 9c0208873a50627d3856b3f4c0869962071bfde2 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 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/Handle.h>
30#include <rfb_win32/Security.h>
31
32namespace rfb {
33
34 namespace win32 {
35
36 // CurrentUserToken
37 // CurrentUserToken is a Handle containing the security token
38 // for the currently logged-on user, or null if no user is
39 // logged on.
40 //
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000041 // canImpersonate() tests whether there is a user token that is safe
42 // to impersonate.
43 //
44 // noUserLoggedOn() tests whether there is *definitely* no user logged on.
45
46 struct CurrentUserToken : public Handle {
47 CurrentUserToken();
Pierre Ossmanfc08bee2016-01-12 12:32:15 +010048 bool canImpersonate() const { return h; }
49 bool noUserLoggedOn() const { return !h; }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000050 };
51
52 // ImpersonateCurrentUser
53 // Throws an exception on failure.
54 // Succeeds (trivially) if process is not running as service.
55 // Fails if CurrentUserToken is not valid.
Pierre Ossmanfc08bee2016-01-12 12:32:15 +010056 // Fails if cannot impersonate token.
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000057 // Succeeds otherwise.
58
59 struct ImpersonateCurrentUser {
60 ImpersonateCurrentUser();
61 ~ImpersonateCurrentUser();
62 CurrentUserToken token;
63 };
64
65 // UserName
66 // Returns the name of the user the thread is currently running as.
67 // Raises a SystemException in case of error.
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000068
69 struct UserName : public TCharArray {
70 UserName();
71 };
72
73 // UserSID
74 // Returns the SID of the currently logged-on user (i.e. the session user)
75
76 struct UserSID : public Sid {
77 UserSID();
78 };
79
80 }
81
82}
83
84#endif