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.

103 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. ConfSet.c
  5. Abstract:
  6. This header file defines the function prototypes of the temporary
  7. helper routines to get configuration information from the NT
  8. configuration files.
  9. Author:
  10. John Rogers (JohnRo) 26-Nov-1991
  11. Environment:
  12. Only runs under NT.
  13. Revision History:
  14. 26-Nov-1991 JohnRo
  15. Created.
  16. 13-Feb-1992 JohnRo
  17. Added support for using the real Win32 registry.
  18. Added support for FAKE_PER_PROCESS_RW_CONFIG handling.
  19. 12-Mar-1992 JohnRo
  20. Changed to only store UNICODE strings in registry.
  21. 31-Mar-1992 JohnRo
  22. Flush the registry after each create/_write.
  23. 06-May-1992 JohnRo
  24. REG_SZ now implies a UNICODE string, so we can't use REG_USZ anymore.
  25. --*/
  26. #include <nt.h> // NT definitions
  27. #include <ntrtl.h> // NT Rtl structures
  28. #include <nturtl.h> // NT Rtl structures
  29. #include <windows.h> // Needed by <configp.h> and <winreg.h>
  30. #include <lmcons.h> // NET_API_STATUS.
  31. #include <netdebug.h> // (Needed by config.h)
  32. #include <config.h> // My prototype, LPNET_CONFIG_HANDLE.
  33. #include <configp.h> // NET_CONFIG_HANDLE.
  34. #include <debuglib.h> // IF_DEBUG().
  35. #include <lmapibuf.h> // NetApiBufferFree().
  36. #include <netlib.h> // NetpMemoryAllocate(), etc.
  37. #include <tstring.h> // STRSIZE(), TCHAR_EOS, WCSSIZE(), etc.
  38. #include <stdlib.h> // wcslen().
  39. #include <winerror.h> // ERROR_NOT_SUPPORTED, NO_ERROR, etc.
  40. NET_API_STATUS
  41. NetpSetConfigValue(
  42. IN LPNET_CONFIG_HANDLE ConfigHandle,
  43. IN LPTSTR KeyWanted,
  44. IN LPTSTR Value
  45. )
  46. {
  47. NET_CONFIG_HANDLE * lpnetHandle = ConfigHandle; // conv from opaque type
  48. NetpAssert( lpnetHandle != NULL );
  49. NetpAssert( KeyWanted != NULL );
  50. NetpAssert( *KeyWanted != TCHAR_EOS );
  51. NetpAssert( Value != NULL );
  52. NetpAssert( *Value != TCHAR_EOS );
  53. {
  54. LONG Error;
  55. //
  56. // Set the value in the registry. (In memory, at least.)
  57. //
  58. Error = RegSetValueEx(
  59. lpnetHandle->WinRegKey, // open handle (to section)
  60. KeyWanted, // subkey
  61. 0,
  62. REG_SZ, // type (zero-terminated TCHARs)
  63. (LPVOID) Value, // data
  64. STRSIZE(Value) ); // byte count for data (null char too)
  65. IF_DEBUG(CONFIG) {
  66. NetpKdPrint(( "NetpSetConfigValue: RegSetValueEx(" FORMAT_LPTSTR
  67. ") to TCHAR '" FORMAT_LPTSTR "' returned " FORMAT_LONG
  68. ".\n", KeyWanted, Value, Error ));
  69. }
  70. if ( Error != ERROR_SUCCESS ) {
  71. NetpAssert( Error == ERROR_SUCCESS );
  72. return (Error);
  73. }
  74. //
  75. // Flush the registry to force stuff to disk immediately.
  76. //
  77. Error = RegFlushKey( lpnetHandle->WinRegKey );
  78. NetpAssert( Error == ERROR_SUCCESS );
  79. return (NO_ERROR);
  80. }
  81. }