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.

142 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ConfName.c
  5. Abstract:
  6. This module contains NetpAllocConfigName().
  7. Author:
  8. John Rogers (JohnRo) 14-May-1992
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 14-May-1992 JohnRo
  14. Extracted and generalized this code from NetLib/ConfOpen.c.
  15. --*/
  16. // These must be included first:
  17. #include <windows.h>
  18. #include <winsvc.h> // SERVICES_ equates, etc.
  19. #include <lmcons.h> // LAN Manager common definitions
  20. #include <netdebug.h> // (Needed by config.h)
  21. // These may be included in any order:
  22. #include <confname.h> // My prototype.
  23. #include <debuglib.h> // IF_DEBUG().
  24. #include <lmerr.h> // LAN Manager network error definitions
  25. #include <netlib.h> // NetpMemoryAllocate(), etc.
  26. #include <prefix.h> // PREFIX_ equates.
  27. #include <tstring.h> // NetpAlloc{type}From{type}, STRICMP(), etc.
  28. #define SUBKEY_SERVICES_ACTIVE \
  29. TEXT("System\\CurrentControlSet\\Services\\")
  30. #define DEFAULT_AREA_UNDER_SERVICE TEXT("Parameters")
  31. NET_API_STATUS
  32. NetpAllocConfigName(
  33. IN LPTSTR DatabaseName, // SERVICES_xxx_DATABASE from winsvc.h.
  34. IN LPTSTR ServiceName, // SERVICE_ name equate from lmsname.h
  35. IN LPTSTR AreaUnderServiceName OPTIONAL, // defaults to "Parameters"
  36. OUT LPTSTR *FullConfigName // free with NetApiBufferFree.
  37. )
  38. /*++
  39. Routine Description:
  40. Allocates a buffer for and builds up the path to the Parameters subkey for
  41. the given service's key under HKLM\System\CurrentControlSet\Services
  42. Return Value:
  43. NET_API_STATUS - NO_ERROR or reason for failure.
  44. --*/
  45. {
  46. LPTSTR AreaToUse;
  47. DWORD FullPathSize;
  48. LPTSTR FullPath;
  49. LPTSTR SubkeyUnderLocalMachine;
  50. //
  51. // Check for caller errors and set defaults.
  52. //
  53. if ( (ServiceName == NULL) || (*ServiceName == TCHAR_EOS) ) {
  54. return (ERROR_INVALID_PARAMETER);
  55. } else if (FullConfigName == NULL) {
  56. return (ERROR_INVALID_PARAMETER);
  57. }
  58. if (AreaUnderServiceName != NULL) {
  59. AreaToUse = AreaUnderServiceName;
  60. } else {
  61. AreaToUse = DEFAULT_AREA_UNDER_SERVICE;
  62. }
  63. if (DatabaseName == NULL) {
  64. SubkeyUnderLocalMachine = SUBKEY_SERVICES_ACTIVE;
  65. } else if (STRICMP(DatabaseName, SERVICES_ACTIVE_DATABASE) == 0) {
  66. SubkeyUnderLocalMachine = SUBKEY_SERVICES_ACTIVE;
  67. } else {
  68. return (ERROR_INVALID_PARAMETER);
  69. }
  70. //
  71. // Compute size of name.
  72. //
  73. FullPathSize = ( STRLEN(SubkeyUnderLocalMachine)
  74. + STRLEN(ServiceName)
  75. + 1 // backslash
  76. + STRLEN(AreaToUse)
  77. + 1 ) // trailing null
  78. * sizeof(TCHAR);
  79. //
  80. // Allocate space for the name.
  81. //
  82. FullPath = NetpMemoryAllocate( FullPathSize );
  83. if (FullPath == NULL) {
  84. return (ERROR_NOT_ENOUGH_MEMORY);
  85. }
  86. //
  87. // Build the name.
  88. //
  89. STRCPY( FullPath, SubkeyUnderLocalMachine ); // ends w/ backslash.
  90. STRCAT( FullPath, ServiceName );
  91. STRCAT( FullPath, TEXT("\\") ); // one backslash to separate.
  92. STRCAT( FullPath, AreaToUse );
  93. //
  94. // Tell caller how things went.
  95. //
  96. *FullConfigName = FullPath;
  97. IF_DEBUG( CONFIG ) {
  98. NetpKdPrint(( PREFIX_NETLIB
  99. "NetpAllocConfigName: built name '" FORMAT_LPTSTR "'.\n",
  100. FullPath ));
  101. }
  102. return (NO_ERROR);
  103. }