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.

406 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. catentry
  5. Abstract:
  6. Read & write the relevant registry entries.
  7. Author:
  8. Steve Firebaugh (stevefir) 14-Jan-1995
  9. Revision History:
  10. --*/
  11. #include <windows.h>
  12. #include <commdlg.h>
  13. #include <winsock2.h>
  14. #include <nspapi.h>
  15. #include <stdio.h>
  16. #include "ws2spi.h"
  17. #include "sporder.h"
  18. #include "globals.h"
  19. #define MAX_ENTRIES 1000 // hack, make dynamic
  20. WSAPROTOCOL_INFOW ProtoInfo[MAX_ENTRIES];
  21. //
  22. // keep track of the total number of entries in the list box;
  23. //
  24. int gNumRows = 0;
  25. int CatReadRegistry (HWND hwnd)
  26. /*++
  27. Called once when the dialog first comes up. Read the registry and fill
  28. the listbox with all of the entries.
  29. --*/
  30. {
  31. TCHAR szOutput[MAX_STR];
  32. TCHAR szInput[MAX_STR];
  33. TCHAR szBuffer[MAX_STR];
  34. LONG r;
  35. INT iIndex;
  36. DWORD dwSize;
  37. //
  38. // set a tab stop far off of the screen, so that we can store the original
  39. // index there, and it will stay glued to the string even as the user
  40. // reorders them (unless we are building a debug).
  41. //
  42. #ifndef DEBUG
  43. {
  44. int iTab;
  45. iTab = 300;
  46. SendMessage (HWNDLISTCTL, LB_SETTABSTOPS, 1, (LPARAM) &iTab);
  47. }
  48. #endif
  49. dwSize = sizeof (ProtoInfo);
  50. gNumRows = WSCEnumProtocols (NULL, ProtoInfo, &dwSize, &r);
  51. if (gNumRows==SOCKET_ERROR) {
  52. CatCheckRegErrCode (hwnd, r, TEXT("WSCEnumProtocols"));
  53. return FALSE;
  54. }
  55. for (iIndex = 0; iIndex<gNumRows ;iIndex++) {
  56. //
  57. // Now format a string for display in the list box. Notice that
  58. // we sneak an index in to the far right (not visible) to track
  59. // the string's initial position (for purposes of mapping it to
  60. // the gdwCatEntries later) regardless of re-ordering.
  61. //
  62. wsprintf (szBuffer,
  63. TEXT("%ws \t%d \t%d"),
  64. &ProtoInfo[iIndex].szProtocol,
  65. iIndex,
  66. ProtoInfo[iIndex].dwCatalogEntryId);
  67. ADDSTRING(szBuffer);
  68. } // end for
  69. return TRUE;
  70. }
  71. int CatDoMoreInfo (HWND hwnd, int iSelection)
  72. /*++
  73. Given a dialog handle, and an index into our global array of catalog entries,
  74. fill a listbox with all of the information that we know about it.
  75. --*/
  76. {
  77. TCHAR szBuffer[MAX_STR];
  78. WCHAR szDllName[MAX_PATH];
  79. int iTab;
  80. int r;
  81. DWORD dwSize;
  82. BYTE pb[16];
  83. //
  84. // pick an arbitraty tab number that is far enough to the right to clear
  85. // most of the long strings.
  86. //
  87. iTab = 90;
  88. SendMessage (HWNDLISTCTL, LB_SETTABSTOPS, 1, (LPARAM) &iTab);
  89. dwSize = sizeof (szDllName);
  90. if (WSCGetProviderPath (&ProtoInfo[iSelection].ProviderId,
  91. szDllName,
  92. &dwSize,
  93. &r)==SOCKET_ERROR) {
  94. CatCheckRegErrCode (hwnd, r, TEXT("WSCGetProviderPath"));
  95. return FALSE;
  96. }
  97. wsprintf (szBuffer, TEXT("LibraryPath \t%ls"), szDllName); ADDSTRING (szBuffer);
  98. wsprintf (szBuffer, TEXT("dwServiceFlags1 \t0x%x"), ProtoInfo[iSelection].dwServiceFlags1); ADDSTRING (szBuffer);
  99. wsprintf (szBuffer, TEXT("dwServiceFlags2 \t0x%x"), ProtoInfo[iSelection].dwServiceFlags2); ADDSTRING (szBuffer);
  100. wsprintf (szBuffer, TEXT("dwServiceFlags3 \t0x%x"), ProtoInfo[iSelection].dwServiceFlags3); ADDSTRING (szBuffer);
  101. wsprintf (szBuffer, TEXT("dwServiceFlags4 \t0x%x"), ProtoInfo[iSelection].dwServiceFlags4); ADDSTRING (szBuffer);
  102. wsprintf (szBuffer, TEXT("dwProviderFlags \t0x%x"), ProtoInfo[iSelection].dwProviderFlags); ADDSTRING (szBuffer);
  103. //
  104. // format GUID for display. do byte swapping to match expected format
  105. //
  106. memcpy (pb, (PBYTE) &(ProtoInfo[iSelection].ProviderId), sizeof (GUID));
  107. wsprintf (szBuffer,
  108. TEXT("ProviderId \t%02x%02x%02x%02x - %02x%02x - %02x%02x - %02x%02x - %02x%02x%02x%02x%02x%02x"),
  109. (BYTE)pb[3],
  110. (BYTE)pb[2],
  111. (BYTE)pb[1],
  112. (BYTE)pb[0],
  113. (BYTE)pb[5],
  114. (BYTE)pb[4],
  115. (BYTE)pb[7],
  116. (BYTE)pb[6],
  117. (BYTE)pb[8],
  118. (BYTE)pb[9],
  119. (BYTE)pb[10],
  120. (BYTE)pb[11],
  121. (BYTE)pb[12],
  122. (BYTE)pb[13],
  123. (BYTE)pb[14],
  124. (BYTE)pb[15] );
  125. ADDSTRING (szBuffer);
  126. wsprintf (szBuffer, TEXT("dwCatalogEntryId \t0x%x"), ProtoInfo[iSelection].dwCatalogEntryId); ADDSTRING (szBuffer);
  127. wsprintf (szBuffer, TEXT("ProtocolChain.ChainLen \t%d"), ProtoInfo[iSelection].ProtocolChain.ChainLen); ADDSTRING (szBuffer);
  128. wsprintf (szBuffer, TEXT("iVersion \t0x%x"), ProtoInfo[iSelection].iVersion); ADDSTRING (szBuffer);
  129. wsprintf (szBuffer, TEXT("iAddressFamily \t0x%x"), ProtoInfo[iSelection].iAddressFamily); ADDSTRING (szBuffer);
  130. wsprintf (szBuffer, TEXT("iMaxSockAddr \t0x%x"), ProtoInfo[iSelection].iMaxSockAddr); ADDSTRING (szBuffer);
  131. wsprintf (szBuffer, TEXT("iMinSockAddr \t0x%x"), ProtoInfo[iSelection].iMinSockAddr); ADDSTRING (szBuffer);
  132. wsprintf (szBuffer, TEXT("iSocketType \t0x%x"), ProtoInfo[iSelection].iSocketType); ADDSTRING (szBuffer);
  133. wsprintf (szBuffer, TEXT("iProtocol \t0x%x"), ProtoInfo[iSelection].iProtocol); ADDSTRING (szBuffer);
  134. wsprintf (szBuffer, TEXT("iProtocolMaxOffset \t0x%x"), ProtoInfo[iSelection].iProtocolMaxOffset); ADDSTRING (szBuffer);
  135. wsprintf (szBuffer, TEXT("iNetworkByteOrder \t0x%x"), ProtoInfo[iSelection].iNetworkByteOrder); ADDSTRING (szBuffer);
  136. wsprintf (szBuffer, TEXT("iSecurityScheme \t0x%x"), ProtoInfo[iSelection].iSecurityScheme); ADDSTRING (szBuffer);
  137. wsprintf (szBuffer, TEXT("dwMessageSize \t0x%x"), ProtoInfo[iSelection].dwMessageSize); ADDSTRING (szBuffer);
  138. wsprintf (szBuffer, TEXT("dwProviderReserved \t0x%x"), ProtoInfo[iSelection].dwProviderReserved); ADDSTRING (szBuffer);
  139. wsprintf (szBuffer, TEXT("szProtocol \t%ws"), &ProtoInfo[iSelection].szProtocol); ADDSTRING (szBuffer);
  140. return TRUE;
  141. }
  142. int CatDoWriteEntries (HWND hwnd)
  143. /*++
  144. Here we step through all of the entries in the list box, check to see if
  145. it is out of order, and if it is, write data to the registry key in that
  146. position.
  147. --*/
  148. {
  149. TCHAR szBuffer[MAX_STR];
  150. int iRegKey;
  151. int iIndex;
  152. int iCatID;
  153. LONG r;
  154. DWORD lpdwCatID[MAX_ENTRIES];
  155. //
  156. // Step through all of the registry keys (catalog entries).
  157. // and build array of catalog IDs to be passed to function in sporder.dll
  158. //
  159. for (iRegKey = 0; iRegKey < gNumRows; iRegKey++ ) {
  160. SendMessage (HWNDLISTCTL, LB_GETTEXT, iRegKey, (LPARAM) szBuffer);
  161. ASSERT (CatGetIndex (szBuffer, &iIndex, &iCatID),
  162. TEXT("CatDoWriteEntries, CatGetIndex failed."));
  163. //
  164. // build array of CatalogIDs
  165. //
  166. lpdwCatID[iRegKey] = iCatID;
  167. } // for
  168. r = WSCWriteProviderOrder (lpdwCatID, gNumRows);
  169. CatCheckRegErrCode (hwnd, r, TEXT("WSCWriteProviderOrder"));
  170. return r;
  171. }
  172. int CatCheckRegErrCode (HWND hwnd, LONG r, LPTSTR lpstr)
  173. /*++
  174. Centralize checking the return code for Registry functions.
  175. Here we report the error if any with as helpful a message as we can.
  176. --*/
  177. {
  178. static TCHAR szTitle[] = TEXT("Registry error in service provider tool.");
  179. TCHAR szBuffer[MAX_STR];
  180. switch (r) {
  181. case ERROR_SUCCESS: return TRUE;
  182. break;
  183. case ERROR_ACCESS_DENIED : {
  184. lstrcpy (szBuffer, TEXT("ERROR_ACCESS_DENIED\n"));
  185. lstrcat (szBuffer, TEXT("You do not have the necessary privilege to call:\n"));
  186. lstrcat (szBuffer, lpstr);
  187. lstrcat (szBuffer, TEXT("\nLogon as Administrator."));
  188. MessageBox (hwnd, szBuffer, szTitle, MB_ICONSTOP | MB_OK);
  189. return FALSE;
  190. } break;
  191. //
  192. // As Keith & Intel change the registry format, they rename keys
  193. // to avoid backward compatibility problems. If we can't find
  194. // the registry key, it is likely this EXE old and running against
  195. // a new (incompatible) version of ws2.
  196. //
  197. case ERROR_FILE_NOT_FOUND : {
  198. lstrcpy (szBuffer, TEXT("ERROR_FILE_NOT_FOUND\n"));
  199. lstrcat (szBuffer, TEXT("You probably need an updated version of this tool.\n"));
  200. lstrcat (szBuffer, lpstr);
  201. MessageBox (hwnd, szBuffer, szTitle, MB_ICONSTOP | MB_OK);
  202. return FALSE;
  203. } break;
  204. case WSAEINVAL: {
  205. lstrcpy (szBuffer, TEXT("WinSock2 Registry format doesn't match \n"));
  206. lstrcat (szBuffer, TEXT("sporder [exe/dll]. You need updated tools. \n"));
  207. lstrcat (szBuffer, lpstr);
  208. MessageBox (hwnd, szBuffer, szTitle, MB_ICONSTOP | MB_OK);
  209. return FALSE;
  210. } break;
  211. default: {
  212. FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM,
  213. NULL,
  214. r,
  215. GetUserDefaultLangID(),
  216. szBuffer,
  217. sizeof (szBuffer),
  218. 0);
  219. lstrcat (szBuffer, TEXT("\n"));
  220. lstrcat (szBuffer, lpstr);
  221. MessageBox (hwnd, szBuffer, szTitle, MB_ICONSTOP | MB_OK);
  222. return FALSE;
  223. } break;
  224. }
  225. return TRUE;
  226. }
  227. int CatDoUpDown (HWND hwnd, WPARAM wParam)
  228. /*++
  229. Given a dialog handle, and an up/down identifier, remove the entry, and
  230. reinsert it either one position up or down.
  231. --*/
  232. {
  233. TCHAR szBuffer[MAX_STR];
  234. DWORD iSelection;
  235. iSelection = (DWORD)SendMessage (HWNDLISTCTL, LB_GETCURSEL, 0, 0);
  236. if (iSelection != LB_ERR) {
  237. //
  238. // Read the current selecte string, delete the current selection, ...
  239. //
  240. SendMessage (HWNDLISTCTL, LB_GETTEXT, iSelection, (LPARAM)szBuffer);
  241. SendMessage (HWNDLISTCTL, LB_DELETESTRING, iSelection, 0);
  242. //
  243. // Adjust the position up or down by one, and make sure we are
  244. // still clipped to within the valid range.
  245. //
  246. if (wParam == DID_UP) iSelection--;
  247. else iSelection++;
  248. if ((int) iSelection < 0) iSelection = 0 ;
  249. if ((int) iSelection >= gNumRows) iSelection = gNumRows-1 ;
  250. //
  251. // Re-insert the string and restore the selection
  252. //
  253. SendMessage (HWNDLISTCTL, LB_INSERTSTRING, iSelection, (LPARAM)szBuffer);
  254. SendMessage (HWNDLISTCTL, LB_SETCURSEL, iSelection, 0);
  255. }
  256. return TRUE;
  257. }
  258. BOOL CatGetIndex (LPTSTR szBuffer, LPINT lpIndex, LPINT lpCatID)
  259. /*++
  260. The original index is stored after a tab stop, hidden from view far off
  261. screen to the right. Parse the string for the tab stop, and read the
  262. next value. The catalog ID is stored to the right of the index.
  263. --*/
  264. {
  265. int r;
  266. TCHAR *p;
  267. //
  268. // To get the index, start at the begining of the string, parse
  269. // it for tokens based on tab as a separator, and take the
  270. // second one.
  271. //
  272. #ifdef UNICODE
  273. p = wcstok (szBuffer, TEXT("\t"));
  274. p = wcstok (NULL, TEXT("\t"));
  275. r = swscanf (p, TEXT("%d"), lpIndex);
  276. ASSERT((r == 1), TEXT("#1 ASSERT r == 1"))
  277. p = wcstok (NULL, TEXT("\t"));
  278. r = swscanf (p, TEXT("%d"), lpCatID);
  279. ASSERT((r == 1), TEXT("#2 ASSERT r == 1"))
  280. #else
  281. p = strtok (szBuffer, TEXT("\t"));
  282. p = strtok (NULL, TEXT("\t"));
  283. r = sscanf (p, TEXT("%d"), lpIndex);
  284. ASSERT((r == 1), TEXT("#1 ASSERT r == 1"))
  285. p = strtok (NULL, TEXT("\t"));
  286. r = sscanf (p, TEXT("%d"), lpCatID);
  287. ASSERT((r == 1), TEXT("#2 ASSERT r == 1"))
  288. #endif
  289. return TRUE;
  290. }