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.

68 lines
1.8 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // ComputerAPI.CPP
  6. //
  7. //***************************************************************************
  8. #include "precomp.h"
  9. #include "computerAPI.h"
  10. #include "ImpersonateRevert.h"
  11. BOOL ProviderGetComputerName ( LPWSTR lpwcsBuffer, LPDWORD nSize )
  12. {
  13. BOOL bResult = FALSE;
  14. if ( ( bResult = GetComputerNameW(lpwcsBuffer, nSize) ) == FALSE )
  15. {
  16. DWORD dwError = ::GetLastError ();
  17. if ( ERROR_ACCESS_DENIED == dwError )
  18. {
  19. // The GetComputer will need to be called in the process's context.
  20. ProviderImpersonationRevert ir;
  21. if ( ir.Reverted () )
  22. {
  23. bResult = GetComputerNameW(lpwcsBuffer, nSize);
  24. }
  25. else
  26. {
  27. // I was not impersonated or revert failed
  28. // that means call GetComputerName failed with process credentials already
  29. // or will fail as I'm not reverted
  30. ::SetLastError ( dwError );
  31. }
  32. }
  33. }
  34. return bResult;
  35. }
  36. BOOL ProviderGetComputerNameEx ( COMPUTER_NAME_FORMAT NameType, LPWSTR lpwcsBuffer, LPDWORD nSize )
  37. {
  38. BOOL bResult = FALSE;
  39. if ( ( bResult = GetComputerNameExW(NameType, lpwcsBuffer, nSize) ) == FALSE )
  40. {
  41. DWORD dwError = ::GetLastError ();
  42. if ( ERROR_ACCESS_DENIED == dwError )
  43. {
  44. // The GetComputer will need to be called in the process's context.
  45. ProviderImpersonationRevert ir;
  46. if ( ir.Reverted () )
  47. {
  48. bResult = GetComputerNameExW(NameType, lpwcsBuffer, nSize);
  49. }
  50. else
  51. {
  52. // I was not impersonated or revert failed
  53. // that means call GetComputerName failed with process credentials already
  54. // or will fail as I'm not reverted
  55. ::SetLastError ( dwError );
  56. }
  57. }
  58. }
  59. return bResult;
  60. }