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.

320 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. tacc.c
  5. Abstract:
  6. Test for accounts.
  7. Author:
  8. Rita Wong (ritaw) 02-May-1992
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #ifndef UNICODE
  19. #define UNICODE
  20. #endif
  21. #include <windows.h>
  22. #include <nwsnames.h>
  23. DWORD
  24. TestOpenSCManager(
  25. OUT LPSC_HANDLE hScManager,
  26. IN LPWSTR DatabaseName,
  27. IN DWORD DesiredAccess,
  28. IN DWORD ExpectedError
  29. );
  30. DWORD
  31. TestCreateService(
  32. IN SC_HANDLE hScManager,
  33. IN LPWSTR ServiceName,
  34. IN DWORD ServiceType,
  35. IN LPWSTR BinaryPath,
  36. IN LPWSTR Dependencies
  37. );
  38. void __cdecl
  39. main(
  40. void
  41. )
  42. {
  43. DWORD status;
  44. SC_HANDLE hScManager;
  45. SC_HANDLE hService;
  46. LONG RegError;
  47. HKEY ServiceKey;
  48. HKEY LinkageKey;
  49. DWORD Disposition;
  50. DWORD Type = 0x00000007;
  51. PWCHAR Dependencies = L"MSIPX\0Streams\0Mup\0";
  52. //
  53. // Valid desired access
  54. //
  55. if (TestOpenSCManager(
  56. &hScManager,
  57. NULL,
  58. SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE,
  59. NO_ERROR
  60. ) == NO_ERROR) {
  61. //
  62. // Install NwRdr file system driver
  63. //
  64. status = TestCreateService(
  65. hScManager,
  66. L"NwRdr",
  67. SERVICE_FILE_SYSTEM_DRIVER,
  68. L"\\SystemRoot\\System32\\Drivers\\nwrdr.sys",
  69. NULL
  70. );
  71. if (status != NO_ERROR) {
  72. (void) CloseServiceHandle(hScManager);
  73. return;
  74. }
  75. //
  76. // Install NWCWorkstation service own process
  77. //
  78. status = TestCreateService(
  79. hScManager,
  80. NW_SERVICE_WORKSTATION,
  81. SERVICE_WIN32_SHARE_PROCESS,
  82. L"%SystemRoot%\\System32\\nwsvc.exe",
  83. Dependencies
  84. );
  85. (void) CloseServiceHandle(hScManager);
  86. if (status != NO_ERROR) {
  87. return;
  88. }
  89. //
  90. // Write the linkage key under the NWCWorkstation key
  91. //
  92. RegError = RegOpenKeyExW(
  93. HKEY_LOCAL_MACHINE,
  94. L"System\\CurrentControlSet\\Services\\NWCWorkstation",
  95. REG_OPTION_NON_VOLATILE,
  96. KEY_READ | KEY_CREATE_SUB_KEY,
  97. &ServiceKey
  98. );
  99. if (RegError != ERROR_SUCCESS) {
  100. printf("RegOpenKeyExW failed %ld\n", RegError);
  101. return;
  102. }
  103. RegError = RegCreateKeyExW(
  104. ServiceKey,
  105. L"Linkage",
  106. 0,
  107. WIN31_CLASS,
  108. REG_OPTION_NON_VOLATILE, // options
  109. KEY_WRITE,
  110. NULL,
  111. &LinkageKey,
  112. &Disposition
  113. );
  114. RegCloseKey(ServiceKey);
  115. if (RegError != ERROR_SUCCESS) {
  116. printf("RegCreateKeyExW failed %ld\n", RegError);
  117. return;
  118. }
  119. RegError = RegSetValueExW(
  120. LinkageKey,
  121. L"Bind",
  122. 0,
  123. REG_MULTI_SZ,
  124. L"\\Device\\Streams\\IPX\0",
  125. (wcslen(L"\\Device\\Streams\\IPX\0") + 1)
  126. * sizeof(WCHAR)
  127. );
  128. RegCloseKey(LinkageKey);
  129. if (RegError != ERROR_SUCCESS) {
  130. printf("RegSetValueEx failed %ld\n", RegError);
  131. return;
  132. }
  133. //
  134. // Add a system event entry for the NetWare workstation
  135. //
  136. RegError = RegCreateKeyExW(
  137. HKEY_LOCAL_MACHINE,
  138. L"System\\CurrentControlSet\\Services\\Eventlog\\System\\NWCWorkstation",
  139. 0,
  140. WIN31_CLASS,
  141. REG_OPTION_NON_VOLATILE,
  142. KEY_WRITE,
  143. NULL,
  144. &ServiceKey,
  145. &Disposition
  146. );
  147. if (RegError != ERROR_SUCCESS) {
  148. printf("RegCreateKeyExW of eventlog entry failed %ld\n", RegError);
  149. return;
  150. }
  151. RegError = RegSetValueExW(
  152. ServiceKey,
  153. L"EventMessageFile",
  154. 0,
  155. REG_EXPAND_SZ,
  156. L"%SystemRoot%\\System32\\nwevent.dll",
  157. wcslen(L"%SystemRoot%\\System32\\nwevent.dll")
  158. * sizeof(WCHAR)
  159. );
  160. if (RegError != ERROR_SUCCESS) {
  161. printf("RegSetValueExW of EventMessageFile value failed %ld\n", RegError);
  162. RegCloseKey(ServiceKey);
  163. return;
  164. }
  165. RegError = RegSetValueExW(
  166. ServiceKey,
  167. L"TypesSupported",
  168. 0,
  169. REG_DWORD,
  170. &Type,
  171. sizeof(DWORD)
  172. );
  173. RegCloseKey(ServiceKey);
  174. if (RegError != ERROR_SUCCESS) {
  175. printf("RegSetValueExW of TypesSupported value failed %ld\n", RegError);
  176. return;
  177. }
  178. printf("Successfully installed transport for NWCWorkstation\n");
  179. }
  180. }
  181. DWORD
  182. TestOpenSCManager(
  183. OUT LPSC_HANDLE hScManager,
  184. IN LPWSTR DatabaseName,
  185. IN DWORD DesiredAccess,
  186. IN DWORD ExpectedError
  187. )
  188. {
  189. DWORD status = NO_ERROR;
  190. if (DatabaseName != NULL) {
  191. printf("OpenSCManager: DatabaseName=%ws, DesiredAccess=%08lx\n",
  192. DatabaseName, DesiredAccess);
  193. }
  194. else {
  195. printf("OpenSCManager: DatabaseName=(null), DesiredAccess=%08lx\n",
  196. DesiredAccess);
  197. }
  198. *hScManager = OpenSCManager(
  199. NULL,
  200. DatabaseName,
  201. DesiredAccess
  202. );
  203. if (*hScManager == (SC_HANDLE) NULL) {
  204. status = GetLastError();
  205. if (ExpectedError != status) {
  206. printf(" FAILED. Expected %lu, got %lu\n",
  207. ExpectedError, status);
  208. return status;
  209. }
  210. }
  211. else {
  212. if (ExpectedError != NO_ERROR) {
  213. printf(" FAILED. Expected %lu, got NO_ERROR\n",
  214. ExpectedError);
  215. return NO_ERROR;
  216. }
  217. }
  218. printf(" Got %lu as expected\n", status);
  219. return status;
  220. }
  221. DWORD
  222. TestCreateService(
  223. IN SC_HANDLE hScManager,
  224. IN LPWSTR ServiceName,
  225. IN DWORD ServiceType,
  226. IN LPWSTR BinaryPath,
  227. IN LPWSTR Dependencies
  228. )
  229. {
  230. DWORD status = NO_ERROR;
  231. SC_HANDLE hService;
  232. hService = CreateService(
  233. hScManager,
  234. ServiceName,
  235. NULL,
  236. 0,
  237. ServiceType,
  238. SERVICE_DEMAND_START,
  239. SERVICE_ERROR_NORMAL,
  240. BinaryPath,
  241. NULL,
  242. NULL,
  243. Dependencies,
  244. NULL,
  245. NULL
  246. );
  247. if (hService == (SC_HANDLE) NULL) {
  248. status = GetLastError();
  249. printf("CreateService: %ws failed %lu\n", ServiceName, status);
  250. return status;
  251. }
  252. printf("CreateService: Successfully created %ws\n", ServiceName);
  253. (void) CloseServiceHandle(hService);
  254. return status;
  255. }