Windows NT 4.0 source code leak
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.

184 lines
3.8 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. queryval.c
  5. Abstract:
  6. This file implements the RegQueryValue function for dos and win 3.0.
  7. Author:
  8. Dave Steckler (davidst) - 3/28/92
  9. Revision History:
  10. --*/
  11. #include <rpc.h>
  12. #include <regapi.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <rpcreg.h>
  16. #include <globals.h>
  17. long
  18. RPC_ENTRY
  19. RegQueryValue (
  20. HKEY hKey,
  21. LPCSTR lpSubKey,
  22. LPSTR lpValue,
  23. DWORD far * lpcbValue
  24. )
  25. /*++
  26. Routine Description:
  27. This routine sets the value of a key.
  28. Arguments:
  29. hKey Handle to previously opened key. Can be one of the
  30. system defined keys.
  31. lpSubKey Name of subkey whose value we will queried.
  32. lpValue Pointer to where value will be placed.
  33. lpcbValue Pointer to dword containing length of data. On input, this
  34. is the size of the buffer. On output, this is the length
  35. of the output string.
  36. Return Value:
  37. ERROR_SUCCESS
  38. ERROR_BADDB
  39. ERROR_BADKEY
  40. ERROR_CANTREAD
  41. --*/
  42. {
  43. DWORD DataLen;
  44. int State;
  45. int FullKeyNameLen;
  46. #ifdef WIN
  47. static
  48. #endif
  49. char FullKeyName[MAX_KEY_NAME_LEN+1];
  50. #ifdef WIN
  51. static
  52. #endif
  53. char LineInFile[MAX_DATA_FILE_LINE_LEN+1];
  54. char * pParse;
  55. //
  56. // Make sure the key passed in is valid.
  57. //
  58. ConvPreDefinedKey(hKey);
  59. if (!KeyIsValid(hKey))
  60. {
  61. return ERROR_BADKEY;
  62. }
  63. //
  64. // If the registry hasn't been opened yet, then do so.
  65. //
  66. if (!OpenRegistryFileIfNecessary())
  67. {
  68. return ERROR_BADDB;
  69. }
  70. //
  71. // Build the full key name.
  72. //
  73. FullKeyNameLen = BuildFullKeyName(hKey, lpSubKey, FullKeyName);
  74. //
  75. // Scan the file for such a key. If we hit the end of file, then we didn't
  76. // find the key we were looking for.
  77. //
  78. State = STATE_SEARCHING;
  79. for (;;) // return or break from inside loop
  80. {
  81. if (fgets(LineInFile, MAX_DATA_FILE_LINE_LEN+1, RegistryDataFile) ==
  82. NULL)
  83. {
  84. if ( feof(RegistryDataFile) )
  85. {
  86. return ERROR_BADKEY;
  87. }
  88. else
  89. {
  90. return ERROR_CANTREAD;
  91. }
  92. }
  93. pParse = strtok(LineInFile, "=");
  94. ASSERT(pParse != NULL);
  95. if (strcmp(pParse, FullKeyName) == 0)
  96. {
  97. pParse = strtok(NULL, "=");
  98. ASSERT(pParse != NULL);
  99. DataLen = strlen(pParse);
  100. if (pParse[DataLen-1] == '\n')
  101. {
  102. pParse[DataLen-1] = '\0';
  103. DataLen--;
  104. }
  105. if (*lpcbValue < DataLen)
  106. {
  107. strncpy(lpValue, pParse, (size_t)*lpcbValue);
  108. }
  109. else
  110. {
  111. strcpy(lpValue, pParse);
  112. *lpcbValue = DataLen;
  113. }
  114. return ERROR_SUCCESS;
  115. }
  116. else if ( (State != STATE_FOUND_PARENT) &&
  117. (strncmp(pParse, FullKeyName, FullKeyNameLen) == 0) &&
  118. (pParse[FullKeyNameLen]=='\0' || pParse[FullKeyNameLen]=='\\'))
  119. {
  120. State = STATE_FOUND_PARENT;
  121. }
  122. }// for
  123. switch (State)
  124. {
  125. case STATE_SEARCHING:
  126. return ERROR_BADKEY;
  127. case STATE_FOUND_PARENT:
  128. strcpy(lpValue, "");
  129. return ERROR_SUCCESS;
  130. default:
  131. ;
  132. }
  133. }