Source code of Windows XP (NT5)
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.

353 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. ConfStub.c
  5. Abstract:
  6. This module contains stubs for the NetConfig APIs.
  7. Author:
  8. John Rogers (JohnRo) 23-Oct-1991
  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. 23-Oct-1991 JohnRo
  14. Created.
  15. 28-Oct-1991 JohnRo
  16. Use <winerror.h> if <lmerr.h> isn't needed.
  17. 20-Nov-1991 JohnRo
  18. Work with old or new lmconfig.h for now (based on REVISED_CONFIG_APIS).
  19. 02-Dec-1991 JohnRo
  20. Implement local NetConfig APIs.
  21. 11-Mar-1992 JohnRo
  22. Fixed bug in get all where array wasn't terminated.
  23. Added real NetConfigSet() handling.
  24. 21-Oct-1992 JohnRo
  25. RAID 9357: server mgr: can't add to alerts list on downlevel.
  26. --*/
  27. // These must be included first:
  28. #include <nt.h> // IN, etc. (Only needed by temporary config.h)
  29. #include <ntrtl.h> // (Only needed by temporary config.h)
  30. #include <windef.h> // IN, DWORD, etc.
  31. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  32. #include <netdebug.h> // (Needed by config.h)
  33. // These may be included in any order:
  34. #include <config.h> // NetpOpenConfigData(), etc.
  35. #include <lmapibuf.h> // NetApiBufferFree().
  36. #include <lmerr.h> // NERR_ and ERROR_ equates.
  37. #include <lmconfig.h> // NetConfig APIs.
  38. #include <netlib.h> // NetpMemoryReallocate().
  39. #include <rxconfig.h> // RxNetConfig APIs.
  40. #include <tstring.h> // STRSIZE(), TCHAR_EOS, etc.
  41. #define INITIAL_ALLOC_AMOUNT 512 // arbitrary
  42. #define INCR_ALLOC_AMOUNT 512 // arbitrary
  43. NET_API_STATUS NET_API_FUNCTION
  44. NetConfigGet (
  45. IN LPCWSTR UncServerName OPTIONAL,
  46. IN LPCWSTR Component,
  47. IN LPCWSTR Parameter,
  48. #ifdef REVISED_CONFIG_APIS
  49. OUT LPBYTE *BufPtr
  50. #else
  51. OUT LPBYTE *BufPtr,
  52. OUT LPDWORD TotalAvailable
  53. #endif
  54. )
  55. {
  56. NET_API_STATUS Status;
  57. LPNET_CONFIG_HANDLE ConfigHandle;
  58. BOOL TryDownLevel;
  59. #ifndef REVISED_CONFIG_APIS
  60. UNREFERENCED_PARAMETER(TotalAvailable);
  61. #endif
  62. *BufPtr = NULL; // Check caller and make error handling easier.
  63. Status = NetpOpenConfigData(
  64. & ConfigHandle,
  65. (LPWSTR)UncServerName,
  66. (LPWSTR)Component,
  67. TRUE); // just want read-only access
  68. if (Status != NERR_Success) {
  69. Status = NetpHandleConfigFailure(
  70. "NetConfigGet", // debug name
  71. Status, // result of NetpOpenConfigData
  72. (LPWSTR)UncServerName,
  73. & TryDownLevel);
  74. if (TryDownLevel) {
  75. return (RxNetConfigGet(
  76. (LPWSTR)UncServerName,
  77. (LPWSTR)Component,
  78. (LPWSTR)Parameter,
  79. BufPtr));
  80. } else {
  81. return (Status); // result of NetpHandleConfigFailure
  82. }
  83. }
  84. Status = NetpGetConfigValue(
  85. ConfigHandle,
  86. (LPWSTR)Parameter, // keyword
  87. (LPTSTR *) (LPVOID) BufPtr); // alloc and set ptr
  88. if (Status == NERR_Success) {
  89. Status = NetpCloseConfigData( ConfigHandle );
  90. NetpAssert(Status == NERR_Success);
  91. } else {
  92. NetpAssert(*BufPtr == NULL);
  93. (void) NetpCloseConfigData( ConfigHandle );
  94. }
  95. return (Status);
  96. } // NetConfigGet
  97. NET_API_STATUS NET_API_FUNCTION
  98. NetConfigGetAll (
  99. IN LPCWSTR UncServerName OPTIONAL,
  100. IN LPCWSTR Component,
  101. #ifdef REVISED_CONFIG_APIS
  102. OUT LPBYTE *BufPtr
  103. #else
  104. OUT LPBYTE *BufPtr,
  105. OUT LPDWORD TotalAvailable
  106. #endif
  107. )
  108. {
  109. DWORD BufSize; // Bytes allocated at *BufPtr (so far).
  110. DWORD BufUsed; // Bytes used at *BufPtr (so far).
  111. LPNET_CONFIG_HANDLE ConfigHandle;
  112. BOOL FirstTime;
  113. LPVOID NewBuffPtr;
  114. NET_API_STATUS Status;
  115. BOOL TryDownLevel;
  116. #ifndef REVISED_CONFIG_APIS
  117. UNREFERENCED_PARAMETER(TotalAvailable);
  118. #endif
  119. *BufPtr = NULL; // Check caller and make error handling easier.
  120. Status = NetpOpenConfigData(
  121. & ConfigHandle,
  122. (LPWSTR)UncServerName,
  123. (LPWSTR)Component,
  124. TRUE); // just want read-only access
  125. if (Status != NERR_Success) {
  126. Status = NetpHandleConfigFailure(
  127. "NetConfigGetAll", // debug name
  128. Status, // result of NetpOpenConfigData
  129. (LPWSTR)UncServerName,
  130. & TryDownLevel);
  131. if (TryDownLevel) {
  132. return (RxNetConfigGetAll(
  133. (LPWSTR)UncServerName,
  134. (LPWSTR)Component,
  135. BufPtr));
  136. } else {
  137. return (Status); // result of NetpHandleConfigFailure
  138. }
  139. }
  140. // Even if there aren't any entries, we'll need to store a null at
  141. // end of array. So allocate initial one now.
  142. BufSize = INITIAL_ALLOC_AMOUNT;
  143. NewBuffPtr = NetpMemoryReallocate(
  144. (LPVOID) *BufPtr, // old address
  145. BufSize); // new size
  146. if (NewBuffPtr == NULL) { // out of memory
  147. (void) NetpCloseConfigData( ConfigHandle );
  148. return (ERROR_NOT_ENOUGH_MEMORY);
  149. }
  150. *BufPtr = NewBuffPtr;
  151. BufUsed = 0;
  152. // Loop once per entry (at least once if no entries).
  153. FirstTime = TRUE;
  154. do {
  155. LPTSTR KeywordBuffer;
  156. LPTSTR ValueBuffer;
  157. Status = NetpEnumConfigSectionValues(
  158. ConfigHandle,
  159. & KeywordBuffer, // Alloc and set ptr.
  160. & ValueBuffer, // Alloc and set ptr.
  161. FirstTime);
  162. FirstTime = FALSE;
  163. if (Status == NERR_Success) {
  164. DWORD SrcSize =
  165. (STRLEN(KeywordBuffer) + 1 + STRLEN(ValueBuffer) + 1)
  166. * sizeof(TCHAR);
  167. if (BufSize < (BufUsed+SrcSize) ) {
  168. if (SrcSize <= INCR_ALLOC_AMOUNT) {
  169. BufSize += INCR_ALLOC_AMOUNT;
  170. } else {
  171. BufSize += SrcSize;
  172. }
  173. NewBuffPtr = NetpMemoryReallocate(
  174. (LPVOID) *BufPtr, /* old address */
  175. BufSize); /* new size */
  176. if (NewBuffPtr == NULL) { /* out of memory */
  177. (void) NetpCloseConfigData( ConfigHandle );
  178. return (ERROR_NOT_ENOUGH_MEMORY);
  179. }
  180. *BufPtr = NewBuffPtr;
  181. }
  182. #define AddString( lptstrSrc, CharCount ) \
  183. { \
  184. LPTSTR lptstrDest; \
  185. NetpAssert( CharCount > 0 ); \
  186. lptstrDest = (LPTSTR)NetpPointerPlusSomeBytes( *BufPtr, BufUsed); \
  187. NetpAssert( lptstrDest != NULL ); \
  188. (void) STRNCPY( lptstrDest, lptstrSrc, CharCount ); \
  189. BufUsed += (CharCount * sizeof(TCHAR) ); \
  190. NetpAssert( BufUsed <= BufSize ); \
  191. }
  192. AddString( KeywordBuffer, STRLEN(KeywordBuffer) );
  193. (void) NetApiBufferFree( KeywordBuffer );
  194. AddString( TEXT("="), 1 );
  195. AddString( ValueBuffer, STRLEN(ValueBuffer) );
  196. (void) NetApiBufferFree( ValueBuffer );
  197. #define AddNullChar( ) \
  198. { \
  199. AddString( TEXT(""), 1 ); \
  200. }
  201. AddNullChar(); // Terminate this entry.
  202. }
  203. } while (Status == NERR_Success);
  204. if (Status == NERR_CfgParamNotFound) {
  205. AddNullChar(); // Terminate the array.
  206. Status = NetpCloseConfigData( ConfigHandle );
  207. NetpAssert(Status == NERR_Success);
  208. } else {
  209. NetpAssert( Status != NO_ERROR );
  210. NetpAssert( *BufPtr != NULL );
  211. NetpMemoryFree( *BufPtr );
  212. *BufPtr = NULL;
  213. (void) NetpCloseConfigData( ConfigHandle );
  214. }
  215. return (Status);
  216. } // NetConfigGetAll
  217. NET_API_STATUS NET_API_FUNCTION
  218. NetConfigSet (
  219. IN LPCWSTR UncServerName OPTIONAL,
  220. IN LPCWSTR Reserved1 OPTIONAL,
  221. IN LPCWSTR Component,
  222. IN DWORD Level,
  223. IN DWORD Reserved2,
  224. IN LPBYTE Buf,
  225. IN DWORD Reserved3
  226. )
  227. {
  228. LPCONFIG_INFO_0 Info = (LPVOID) Buf;
  229. LPNET_CONFIG_HANDLE ConfigHandle;
  230. NET_API_STATUS Status;
  231. BOOL TryDownLevel;
  232. if (Buf == NULL) {
  233. return (ERROR_INVALID_PARAMETER);
  234. } else if (Level != 0) {
  235. return (ERROR_INVALID_LEVEL);
  236. } else if (Info->cfgi0_key == NULL) {
  237. return (ERROR_INVALID_PARAMETER);
  238. } else if (Info->cfgi0_data == NULL) {
  239. return (ERROR_INVALID_PARAMETER);
  240. } else if (Reserved1 != NULL) {
  241. return (ERROR_INVALID_PARAMETER);
  242. } else if (Reserved2 != 0) {
  243. return (ERROR_INVALID_PARAMETER);
  244. } else if (Reserved3 != 0) {
  245. return (ERROR_INVALID_PARAMETER);
  246. }
  247. Status = NetpOpenConfigData(
  248. & ConfigHandle,
  249. (LPWSTR)UncServerName,
  250. (LPWSTR)Component,
  251. FALSE); // don't want _read-only _access
  252. if (Status != NERR_Success) {
  253. Status = NetpHandleConfigFailure(
  254. "NetConfigSet", // debug name
  255. Status, // result of NetpOpenConfigData
  256. (LPWSTR)UncServerName,
  257. & TryDownLevel);
  258. if (TryDownLevel) {
  259. return (RxNetConfigSet(
  260. (LPWSTR)UncServerName,
  261. (LPWSTR)Reserved1,
  262. (LPWSTR)Component,
  263. Level,
  264. Reserved2,
  265. Buf,
  266. Reserved3));
  267. } else {
  268. return (Status); // result of NetpHandleConfigFailure
  269. }
  270. }
  271. Status = NetpSetConfigValue(
  272. ConfigHandle,
  273. Info->cfgi0_key, // keyword
  274. Info->cfgi0_data); // new value
  275. if (Status == NERR_Success) {
  276. Status = NetpCloseConfigData( ConfigHandle );
  277. NetpAssert(Status == NERR_Success);
  278. } else {
  279. (void) NetpCloseConfigData( ConfigHandle );
  280. }
  281. return (Status);
  282. } // NetConfigSet