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.

307 lines
7.0 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1997
  3. All rights reserved
  4. ***************************************************************************/
  5. #include "pch.h"
  6. #include <commctrl.h>
  7. #include <windowsx.h>
  8. DEFINE_MODULE("Main");
  9. // Globals
  10. HINSTANCE g_hinstance = NULL;
  11. #define BINL_PARAMETERS_KEY L"System\\CurrentControlSet\\Services\\Binlsvc\\Parameters"
  12. #define GUID_SIZE 32
  13. #define MAC_SIZE 12
  14. #define MACHINE_NAME_SIZE 20
  15. //
  16. //
  17. //
  18. DWORD
  19. OscCreateAccount(
  20. LPTSTR GUID,
  21. LPTSTR Name
  22. )
  23. {
  24. DWORD Error;
  25. TCHAR szGUID[ GUID_SIZE + 1 ];
  26. HKEY hkeyParams;
  27. HKEY hkey;
  28. DWORD dw = 0;
  29. Error = RegOpenKeyEx(
  30. HKEY_LOCAL_MACHINE,
  31. BINL_PARAMETERS_KEY,
  32. 0,
  33. KEY_READ | KEY_WRITE,
  34. &hkeyParams );
  35. Assert( Error == ERROR_SUCCESS );
  36. if ( Error != ERROR_SUCCESS )
  37. goto Cleanup;
  38. Error = RegSetValueEx(
  39. hkeyParams,
  40. L"AllowAllClients",
  41. 0,
  42. REG_DWORD,
  43. (LPBYTE) &dw,
  44. sizeof(dw));
  45. Assert( Error == ERROR_SUCCESS );
  46. if ( lstrlen( GUID ) == MAC_SIZE )
  47. {
  48. wsprintf( szGUID, TEXT("%020x%s"), 0, GUID );
  49. }
  50. else
  51. {
  52. lstrcpy( szGUID, GUID );
  53. }
  54. Error = RegCreateKey(
  55. hkeyParams,
  56. szGUID,
  57. &hkey );
  58. Assert( Error == ERROR_SUCCESS );
  59. if ( Error == ERROR_SUCCESS )
  60. {
  61. RegCloseKey( hkey );
  62. }
  63. RegCloseKey( hkeyParams );
  64. Cleanup:
  65. return Error;
  66. }
  67. //
  68. //
  69. //
  70. DWORD
  71. OscDeleteAccount(
  72. LPTSTR GUID,
  73. LPTSTR Name
  74. )
  75. {
  76. DWORD Error;
  77. TCHAR szGUID[ GUID_SIZE + 1 ];
  78. HKEY hkeyParams;
  79. HKEY hkey;
  80. DWORD dw = 0;
  81. Error = RegOpenKeyEx(
  82. HKEY_LOCAL_MACHINE,
  83. BINL_PARAMETERS_KEY,
  84. 0,
  85. KEY_READ | KEY_WRITE,
  86. &hkeyParams );
  87. Assert( Error == ERROR_SUCCESS );
  88. if ( Error != ERROR_SUCCESS )
  89. goto Cleanup;
  90. Error = RegSetValueEx(
  91. hkeyParams,
  92. L"AllowAllClients",
  93. 0,
  94. REG_DWORD,
  95. (LPBYTE) &dw,
  96. sizeof(dw));
  97. Assert( Error == ERROR_SUCCESS );
  98. if ( lstrlen( GUID ) == MAC_SIZE )
  99. {
  100. wsprintf( szGUID, TEXT("%020x%s"), 0, GUID );
  101. }
  102. else
  103. {
  104. lstrcpy( szGUID, GUID );
  105. }
  106. Error = RegDeleteKey(
  107. hkeyParams,
  108. szGUID );
  109. Assert( Error == ERROR_SUCCESS );
  110. RegCloseKey( hkeyParams );
  111. Cleanup:
  112. return Error;
  113. }
  114. //
  115. //
  116. //
  117. BOOL CALLBACK
  118. ClientDlgProc(
  119. HWND hDlg,
  120. UINT uMsg,
  121. WPARAM wParam,
  122. LPARAM lParam )
  123. {
  124. NMHDR FAR *lpnmhdr;
  125. switch ( uMsg )
  126. {
  127. case WM_INITDIALOG:
  128. CenterDialog( hDlg );
  129. SendMessage( GetDlgItem( hDlg, IDC_E_MAC), EM_LIMITTEXT, (WPARAM)32, 0 );
  130. Button_SetCheck( GetDlgItem( hDlg, IDC_ADD ), BST_CHECKED );
  131. break;
  132. case WM_COMMAND:
  133. {
  134. switch ( LOWORD( wParam ) )
  135. {
  136. case IDOK:
  137. {
  138. DWORD dwLen;
  139. TCHAR szGUID[ GUID_SIZE + 1 ];
  140. TCHAR szMachineName[ MACHINE_NAME_SIZE + 1];
  141. GetDlgItemText( hDlg, IDC_E_MAC, szGUID, ARRAYSIZE( szGUID ) );
  142. GetDlgItemText( hDlg, IDC_E_MACHINENAME, szMachineName, ARRAYSIZE( szMachineName ) );
  143. dwLen = lstrlen( szGUID );
  144. if (( dwLen != GUID_SIZE ) && ( dwLen != MAC_SIZE ))
  145. {
  146. MessageBox( hDlg,
  147. TEXT("A valid GUID is 32 digits.\nA valid MAC is 12.\nPlease correct your entry."),
  148. TEXT("Not a valid GUID/MAC"),
  149. MB_OK );
  150. }
  151. else
  152. {
  153. if ( BST_CHECKED == Button_GetCheck( GetDlgItem( hDlg, IDC_ADD ) ) )
  154. {
  155. OscCreateAccount( szGUID, szMachineName );
  156. }
  157. else
  158. {
  159. OscDeleteAccount( szGUID, szMachineName );
  160. }
  161. }
  162. }
  163. Edit_SetText( GetDlgItem( hDlg, IDC_E_MAC), L"" );
  164. break;
  165. case IDCANCEL:
  166. EndDialog( hDlg, IDCANCEL );
  167. break;
  168. case IDC_E_MAC:
  169. {
  170. DWORD dwLen;
  171. TCHAR szGUID[ GUID_SIZE + 1 ];
  172. TCHAR szNumber[ 64 ];
  173. GetDlgItemText( hDlg, IDC_E_MAC, szGUID, ARRAYSIZE( szGUID ));
  174. dwLen = lstrlen( szGUID );
  175. wsprintf( szNumber, TEXT("Digits = %u"), dwLen );
  176. SetWindowText( GetDlgItem( hDlg, IDC_S_NUMBER), szNumber );
  177. }
  178. break;
  179. }
  180. }
  181. break;
  182. default:
  183. return FALSE;
  184. }
  185. return TRUE;
  186. }
  187. //
  188. // WinMain()
  189. //
  190. int APIENTRY
  191. WinMain(
  192. HINSTANCE hInstance,
  193. HINSTANCE hPrevInstance,
  194. LPSTR lpCmdLine,
  195. int nCmdShow)
  196. {
  197. HRESULT hr = S_OK;
  198. HKEY hkey;
  199. DWORD Error;
  200. g_hinstance = hInstance;
  201. INITIALIZE_TRACE_MEMORY;
  202. Error = RegOpenKeyEx(
  203. HKEY_LOCAL_MACHINE,
  204. BINL_PARAMETERS_KEY,
  205. 0,
  206. KEY_QUERY_VALUE,
  207. &hkey );
  208. if( Error != ERROR_SUCCESS ) {
  209. return -2;
  210. }
  211. Error = DialogBox( g_hinstance, MAKEINTRESOURCE( IDD_CLIENT ), NULL, ClientDlgProc );
  212. Assert( Error != -1 );
  213. UNINITIALIZE_TRACE_MEMORY;
  214. RRETURN(hr);
  215. }
  216. // stolen from the CRT, used to shrink our code
  217. int _stdcall ModuleEntry(void)
  218. {
  219. int i;
  220. STARTUPINFOA si;
  221. LPSTR pszCmdLine = GetCommandLineA();
  222. if ( *pszCmdLine == '\"' )
  223. {
  224. /*
  225. * Scan, and skip over, subsequent characters until
  226. * another double-quote or a null is encountered.
  227. */
  228. while ( *++pszCmdLine && (*pszCmdLine != '\"') );
  229. /*
  230. * If we stopped on a double-quote (usual case), skip
  231. * over it.
  232. */
  233. if ( *pszCmdLine == '\"' )
  234. pszCmdLine++;
  235. }
  236. else
  237. {
  238. while (*pszCmdLine > ' ')
  239. pszCmdLine++;
  240. }
  241. /*
  242. * Skip past any white space preceeding the second token.
  243. */
  244. while (*pszCmdLine && (*pszCmdLine <= ' '))
  245. {
  246. pszCmdLine++;
  247. }
  248. si.dwFlags = 0;
  249. GetStartupInfoA(&si);
  250. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  251. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  252. ExitProcess(i);
  253. return i; // We never come here.
  254. }