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.

185 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. getconfg.c
  5. Abstract:
  6. This module contains routines for manipulating configuration
  7. information. The following functions available are:
  8. NetpGetComputerName
  9. NetpGetDomainId
  10. Currently configuration information is kept in NT.CFG.
  11. Later it will be kept by the configuration manager.
  12. Author:
  13. Dan Lafferty (danl) 09-Apr-1991
  14. Environment:
  15. User Mode -Win32
  16. Revision History:
  17. 09-Apr-1991 danl
  18. created
  19. 27-Sep-1991 JohnRo
  20. Fixed somebody's attempt to do UNICODE.
  21. 20-Mar-1992 JohnRo
  22. Get rid of old config helper callers.
  23. Fixed NTSTATUS vs. NET_API_STATUS bug.
  24. 07-May-1992 JohnRo
  25. Enable win32 registry for NET tree by calling GetComputerName().
  26. Avoid DbgPrint if possible.
  27. 08-May-1992 JohnRo
  28. Use <prefix.h> equates.
  29. 08-May-1992 JohnRo
  30. Added conditional debug output of computer name.
  31. --*/
  32. // These must be included first:
  33. #include <nt.h> // (temporary for config.h)
  34. #include <ntrtl.h> // (temporary for config.h)
  35. #include <nturtl.h> // (temporary for config.h)
  36. #include <windef.h> // IN, VOID, etc.
  37. #include <lmcons.h> // NET_API_STATUS.
  38. // These may be included in any order:
  39. #include <config.h> // LPNET_CONFIG_HANDLE, NetpOpenConfigData, etc.
  40. #include <confname.h> // SECT_NT_WKSTA, etc.
  41. #include <debuglib.h> // IF_DEBUG().
  42. #include <lmapibuf.h> // NetApiBufferFree().
  43. #include <lmerr.h> // NO_ERROR, NERR_ and ERROR_ equates.
  44. #include <netdebug.h> // NetpAssert().
  45. #include <netlib.h> // LOCAL_DOMAIN_TYPE_PRIMARY
  46. #include <prefix.h> // PREFIX_ equates.
  47. #include <tstr.h> // ATOL(), STRLEN(), TCHAR_SPACE, etc.
  48. #include <winbase.h> // LocalAlloc().
  49. /****************************************************************************/
  50. NET_API_STATUS
  51. NetpGetComputerName (
  52. IN LPWSTR *ComputerNamePtr
  53. )
  54. /*++
  55. Routine Description:
  56. This routine obtains the computer name from a persistent database.
  57. Currently that database is the NT.CFG file.
  58. This routine makes no assumptions on the length of the computername.
  59. Therefore, it allocates the storage for the name using NetApiBufferAllocate.
  60. It is necessary for the user to free that space using NetApiBufferFree when
  61. finished.
  62. Arguments:
  63. ComputerNamePtr - This is a pointer to the location where the pointer
  64. to the computer name is to be placed.
  65. Return Value:
  66. NERR_Success - If the operation was successful.
  67. It will return assorted Net or Win32 error messages if not.
  68. --*/
  69. {
  70. return NetpGetComputerNameEx( ComputerNamePtr, FALSE );
  71. }
  72. /****************************************************************************/
  73. NET_API_STATUS
  74. NetpGetComputerNameEx (
  75. IN LPWSTR *ComputerNamePtr,
  76. IN BOOL PhysicalNetbiosName
  77. )
  78. /*++
  79. Routine Description:
  80. This routine obtains the computer name from a persistent database.
  81. Currently that database is the NT.CFG file.
  82. This routine makes no assumptions on the length of the computername.
  83. Therefore, it allocates the storage for the name using NetApiBufferAllocate.
  84. It is necessary for the user to free that space using NetApiBufferFree when
  85. finished.
  86. Arguments:
  87. ComputerNamePtr - This is a pointer to the location where the pointer
  88. to the computer name is to be placed.
  89. Return Value:
  90. NERR_Success - If the operation was successful.
  91. It will return assorted Net or Win32 error messages if not.
  92. --*/
  93. {
  94. NET_API_STATUS ApiStatus;
  95. DWORD NameSize = MAX_COMPUTERNAME_LENGTH + 1; // updated by win32 API.
  96. //
  97. // Check for caller's errors.
  98. //
  99. if (ComputerNamePtr == NULL) {
  100. return (ERROR_INVALID_PARAMETER);
  101. }
  102. //
  103. // Allocate space for computer name.
  104. //
  105. ApiStatus = NetApiBufferAllocate(
  106. (MAX_COMPUTERNAME_LENGTH + 1) * sizeof(WCHAR),
  107. (LPVOID *) ComputerNamePtr);
  108. if (ApiStatus != NO_ERROR) {
  109. return (ApiStatus);
  110. }
  111. NetpAssert( *ComputerNamePtr != NULL );
  112. //
  113. // Ask system what current computer name is.
  114. //
  115. if ( !GetComputerNameEx(
  116. PhysicalNetbiosName ?
  117. ComputerNamePhysicalNetBIOS :
  118. ComputerNameNetBIOS,
  119. *ComputerNamePtr,
  120. &NameSize ) ) {
  121. ApiStatus = (NET_API_STATUS) GetLastError();
  122. NetpAssert( ApiStatus != NO_ERROR );
  123. (VOID) NetApiBufferFree( *ComputerNamePtr );
  124. *ComputerNamePtr = NULL;
  125. return (ApiStatus);
  126. }
  127. NetpAssert( STRLEN( *ComputerNamePtr ) <= MAX_COMPUTERNAME_LENGTH );
  128. //
  129. // All done.
  130. //
  131. IF_DEBUG( CONFIG ) {
  132. NetpKdPrint(( PREFIX_NETLIB "NetpGetComputerName: name is "
  133. FORMAT_LPWSTR ".\n", *ComputerNamePtr ));
  134. }
  135. return (NO_ERROR);
  136. }