Leaked source code of windows server 2003
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.

99 lines
2.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: token.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <common.hxx>
  11. #include <usertok.h>
  12. extern "C"
  13. {
  14. HANDLE
  15. GetCurrentUserTokenW(
  16. WCHAR Winsta[],
  17. DWORD DesiredAccess
  18. );
  19. HANDLE
  20. GetCurrentUserTokenA(
  21. char Winsta[],
  22. DWORD DesiredAccess
  23. );
  24. }
  25. HANDLE
  26. GetCurrentUserTokenW(
  27. WCHAR Winsta[],
  28. DWORD DesiredAccess
  29. )
  30. {
  31. unsigned long handle = 0;
  32. error_status_t status;
  33. handle_t binding;
  34. status = BindToLRpcService(binding, L"ncalrpc:[IUserProfile]");
  35. if (status)
  36. {
  37. SetLastError(status);
  38. return 0;
  39. }
  40. status = SecpGetCurrentUserToken( binding, Winsta, &handle, DesiredAccess);
  41. if (status)
  42. {
  43. RpcBindingFree( &binding );
  44. if (status == RPC_S_UNKNOWN_AUTHN_SERVICE ||
  45. status == RPC_S_SERVER_UNAVAILABLE ||
  46. status == RPC_S_CALL_FAILED )
  47. {
  48. status = ERROR_NOT_LOGGED_ON;
  49. }
  50. SetLastError(status);
  51. return 0;
  52. }
  53. RpcBindingFree( &binding );
  54. return ULongToPtr(handle);
  55. }
  56. HANDLE
  57. GetCurrentUserTokenA(
  58. char Winsta[],
  59. DWORD DesiredAccess
  60. )
  61. {
  62. HANDLE hToken = 0;
  63. PWSTR UnicodeWinsta;
  64. unsigned Length;
  65. Length = MultiByteToWideChar(CP_ACP, 0, Winsta, -1, 0, 0);
  66. UnicodeWinsta = (PWSTR)HeapAlloc(GetProcessHeap(), 0, Length*sizeof(WCHAR));
  67. if (!UnicodeWinsta)
  68. {
  69. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  70. return hToken;
  71. }
  72. if (MultiByteToWideChar( CP_ACP,
  73. 0, // no special flags
  74. Winsta,
  75. -1,
  76. UnicodeWinsta,
  77. Length
  78. ) != 0)
  79. {
  80. hToken = GetCurrentUserTokenW( UnicodeWinsta, DesiredAccess );
  81. }
  82. // else LastError() set by MultiByteToWideChar
  83. HeapFree(GetProcessHeap(), 0, UnicodeWinsta);
  84. return hToken;
  85. }