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.

111 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. getconfg.c
  5. Abstract:
  6. This routine calls GetComputerName[A,W] to obtain the computer name
  7. in both Ansi and Unicode
  8. Author:
  9. Dan Lafferty (danl) 09-Apr-1991
  10. Environment:
  11. User Mode -Win32 (also uses nt RTL routines)
  12. Revision History:
  13. 09-Apr-1991 danl
  14. created
  15. --*/
  16. #include <nt.h> // DbgPrint prototype
  17. #include <ntrtl.h> // DbgPrint prototype
  18. #include <nturtl.h>
  19. #include <ntdef.h>
  20. #include <windef.h>
  21. #include <winbase.h> // LocalAlloc
  22. DWORD
  23. ElfpGetComputerName (
  24. OUT LPSTR *ComputerNamePtrA,
  25. OUT LPWSTR *ComputerNamePtrW
  26. )
  27. /*++
  28. Routine Description:
  29. This routine obtains the computer name from a persistent database,
  30. by calling the GetcomputerName[A,W] Win32 Base APIs
  31. This routine assumes the length of the computername is no greater
  32. than MAX_COMPUTERNAME_LENGTH, space for which it allocates using
  33. LocalAlloc. It is necessary for the user to free that space using
  34. LocalFree when finished.
  35. Arguments:
  36. ComputerNamePtrA - Pointer to the location of the Ansi computer name
  37. ComputerNamePtrW - Pointer to the location of the Unicode computer name
  38. Return Value:
  39. NO_ERROR - If the operation was successful.
  40. Any other Win32 error if unsuccessful
  41. --*/
  42. {
  43. DWORD dwError = NO_ERROR;
  44. DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
  45. //
  46. // Allocate a buffer to hold the largest possible computer name.
  47. //
  48. *ComputerNamePtrA = LocalAlloc(LMEM_ZEROINIT, nSize);
  49. *ComputerNamePtrW = LocalAlloc(LMEM_ZEROINIT, nSize * sizeof(WCHAR));
  50. if (*ComputerNamePtrA == NULL || *ComputerNamePtrW == NULL) {
  51. goto CleanExit;
  52. }
  53. //
  54. // Get the computer name string into the locally allocated buffers
  55. // by calling the Win32 GetComputerName[A,W] APIs.
  56. //
  57. if (!GetComputerNameA(*ComputerNamePtrA, &nSize)) {
  58. goto CleanExit;
  59. }
  60. //
  61. // GetComputerName always updates nSize
  62. //
  63. nSize = MAX_COMPUTERNAME_LENGTH + 1;
  64. if (!GetComputerNameW(*ComputerNamePtrW, &nSize)) {
  65. goto CleanExit;
  66. }
  67. return (NO_ERROR);
  68. CleanExit:
  69. dwError = GetLastError();
  70. LocalFree(*ComputerNamePtrA);
  71. LocalFree(*ComputerNamePtrW);
  72. *ComputerNamePtrA = NULL;
  73. *ComputerNamePtrW = NULL;
  74. return (dwError);
  75. }