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.

76 lines
1.8 KiB

  1. /*
  2. * islocal.c
  3. *
  4. * Determine if a user is local.
  5. *
  6. * Copyright (c) Microsoft Corporation. All rights reserved.
  7. *
  8. * TimF 20010226
  9. */
  10. #include <windows.h>
  11. #include "common.h"
  12. #include "clipsrv.h"
  13. #include "security.h"
  14. #include "debugout.h"
  15. /*
  16. * IsUserLocal
  17. *
  18. * Purpose: Determine if the user context we're running in is
  19. * interactive or remote.
  20. *
  21. * Parameters: None.
  22. *
  23. * Returns: TRUE if this is a locally logged-on user.
  24. */
  25. BOOL
  26. IsUserLocal(
  27. HCONV hConv
  28. )
  29. {
  30. BOOL fRet = FALSE;
  31. PSID sidInteractive;
  32. SID_IDENTIFIER_AUTHORITY NTAuthority = SECURITY_NT_AUTHORITY;
  33. if (!AllocateAndInitializeSid(&NTAuthority,
  34. 1,
  35. SECURITY_INTERACTIVE_RID,
  36. 0,
  37. 0,
  38. 0,
  39. 0,
  40. 0,
  41. 0,
  42. 0,
  43. &sidInteractive)) {
  44. PERROR(TEXT("IsUserLocal: Couldn't get interactive SID\r\n"));
  45. } else {
  46. if (!DdeImpersonateClient(hConv)) {
  47. PERROR(TEXT("IsUserLocal: DdeImpersonateClient failed\r\n"));
  48. } else {
  49. BOOL IsMember;
  50. if (!CheckTokenMembership(NULL,
  51. sidInteractive,
  52. &IsMember)) {
  53. PERROR(TEXT("IsUserLocal: CheckTokenMembership failed.\r\n"));
  54. } else {
  55. fRet = IsMember;
  56. }
  57. RevertToSelf();
  58. }
  59. FreeSid(sidInteractive);
  60. }
  61. return fRet;
  62. }