You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CurrentUser.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* 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. // CurrentUser.h
  19. // Helper class providing the session's logged on username, if
  20. // a user is logged on. Also allows processes running under
  21. // XP/2K3 etc to masquerade as the logged on user for security
  22. // purposes
  23. #ifndef __RFB_WIN32_CURRENT_USER_H__
  24. #define __RFB_WIN32_CURRENT_USER_H__
  25. #include <rfb_win32/Handle.h>
  26. #include <rfb_win32/Security.h>
  27. namespace rfb {
  28. namespace win32 {
  29. // CurrentUserToken
  30. // CurrentUserToken is a Handle containing the security token
  31. // for the currently logged-on user, or null if no user is
  32. // logged on.
  33. //
  34. // canImpersonate() tests whether there is a user token that is safe
  35. // to impersonate.
  36. //
  37. // noUserLoggedOn() tests whether there is *definitely* no user logged on.
  38. struct CurrentUserToken : public Handle {
  39. CurrentUserToken();
  40. bool canImpersonate() const { return h; }
  41. bool noUserLoggedOn() const { return !h; }
  42. };
  43. // ImpersonateCurrentUser
  44. // Throws an exception on failure.
  45. // Succeeds (trivially) if process is not running as service.
  46. // Fails if CurrentUserToken is not valid.
  47. // Fails if cannot impersonate token.
  48. // Succeeds otherwise.
  49. struct ImpersonateCurrentUser {
  50. ImpersonateCurrentUser();
  51. ~ImpersonateCurrentUser();
  52. CurrentUserToken token;
  53. };
  54. // UserName
  55. // Returns the name of the user the thread is currently running as.
  56. // Raises a SystemException in case of error.
  57. struct UserName : public TCharArray {
  58. UserName();
  59. };
  60. // UserSID
  61. // Returns the SID of the currently logged-on user (i.e. the session user)
  62. struct UserSID : public Sid {
  63. UserSID();
  64. };
  65. }
  66. }
  67. #endif