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.

340 lines
9.6 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <dbt.h>
  6. #include <initguid.h>
  7. #include <devguid.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sfcapip.h>
  11. #include "resource.h"
  12. BOOL
  13. CALLBACK
  14. SfcNotificationCallback(
  15. IN PFILEINSTALL_STATUS FileInstallStatus,
  16. IN DWORD_PTR Context
  17. )
  18. {
  19. wprintf( L"file=[%s], version=[%I64x], ec=[%d]\n", FileInstallStatus->FileName, FileInstallStatus->Version, FileInstallStatus->Win32Error );
  20. return TRUE;
  21. }
  22. PWSTR
  23. addstr(
  24. PWSTR s1,
  25. PWSTR s2
  26. )
  27. {
  28. wcscpy( s1, s2 );
  29. return s1 + wcslen(s1) + 1;
  30. }
  31. #define MemAlloc malloc
  32. #define MemFree free
  33. BOOL
  34. MakeDirectory(
  35. PCWSTR Dir
  36. )
  37. /*++
  38. Routine Description:
  39. Attempt to create all of the directories in the given path.
  40. Arguments:
  41. Dir - Directory path to create
  42. Return Value:
  43. TRUE for success, FALSE on error
  44. --*/
  45. {
  46. LPTSTR p, NewDir;
  47. BOOL retval;
  48. NewDir = p = MemAlloc( (wcslen(Dir) + 1) *sizeof(WCHAR) );
  49. if (p) {
  50. wcscpy(p, Dir);
  51. } else {
  52. return(FALSE);
  53. }
  54. if (*p != '\\') p += 2;
  55. while( *++p ) {
  56. while(*p && *p != TEXT('\\')) p++;
  57. if (!*p) {
  58. retval = CreateDirectory( NewDir, NULL );
  59. MemFree(NewDir);
  60. return(retval);
  61. }
  62. *p = 0;
  63. retval = CreateDirectory( NewDir, NULL );
  64. if (!retval && GetLastError() != ERROR_ALREADY_EXISTS) {
  65. MemFree(NewDir);
  66. return(retval);
  67. }
  68. *p = TEXT('\\');
  69. }
  70. MemFree( NewDir );
  71. return(TRUE);
  72. }
  73. PVOID
  74. RegisterForDevChange(
  75. HWND hDlg
  76. )
  77. {
  78. PVOID hNotifyDevNode;
  79. DEV_BROADCAST_DEVICEINTERFACE FilterData;
  80. FilterData.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
  81. FilterData.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
  82. FilterData.dbcc_classguid = GUID_DEVCLASS_CDROM;
  83. hNotifyDevNode = RegisterDeviceNotification( hDlg, &FilterData, DEVICE_NOTIFY_WINDOW_HANDLE );
  84. if (hNotifyDevNode == NULL) {
  85. }
  86. return hNotifyDevNode;
  87. }
  88. INT_PTR
  89. CALLBACK
  90. PromptForMediaDialogProc(
  91. HWND hwndDlg,
  92. UINT uMsg,
  93. WPARAM wParam,
  94. LPARAM lParam
  95. )
  96. {
  97. DEV_BROADCAST_VOLUME *dbv;
  98. static UINT QueryCancelAutoPlay = 0;
  99. static PVOID hNotifyDevNode = NULL;
  100. if (uMsg == WM_INITDIALOG) {
  101. hNotifyDevNode = RegisterForDevChange( hwndDlg );
  102. QueryCancelAutoPlay = RegisterWindowMessage( L"QueryCancelAutoPlay" );
  103. }
  104. if (uMsg == WM_COMMAND && LOWORD(wParam) == IDCANCEL) {
  105. UnregisterDeviceNotification( hNotifyDevNode );
  106. EndDialog( hwndDlg, 0 );
  107. }
  108. if (uMsg == QueryCancelAutoPlay) {
  109. SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, 1 );
  110. return 1;
  111. }
  112. if (uMsg == WM_DEVICECHANGE) {
  113. if (wParam == DBT_DEVICEARRIVAL) {
  114. dbv = (DEV_BROADCAST_VOLUME*)lParam;
  115. if (dbv->dbcv_devicetype == DBT_DEVTYP_VOLUME) {
  116. //
  117. // look for the cd
  118. //
  119. DWORD mask,i;
  120. WCHAR Path[16];
  121. WCHAR SourcePath[MAX_PATH];
  122. Path[1] = L':';
  123. Path[2] = L'\\';
  124. Path[3] = 0;
  125. Path[4] = 0;
  126. for (i=0,mask=dbv->dbcv_unitmask; i<26; i++) {
  127. if (mask&1) {
  128. Path[0] = (WCHAR)(L'A' + i);
  129. Path[3] = 0;
  130. if (dbv->dbcv_flags == DBTF_MEDIA) {
  131. if (GetDriveType( Path ) == DRIVE_CDROM) {
  132. MessageBox( hwndDlg, L"CD was inserted, YEA BABY!", L"Windows File Protection", MB_OK );
  133. UnregisterDeviceNotification( hNotifyDevNode );
  134. EndDialog( hwndDlg, 1 );
  135. }
  136. }
  137. }
  138. mask = mask >> 1;
  139. }
  140. }
  141. }
  142. }
  143. return FALSE;
  144. }
  145. int __cdecl wmain( int argc, WCHAR *argv[] )
  146. {
  147. HANDLE RpcHandle = NULL;
  148. PROTECTED_FILE_DATA FileData;
  149. PWSTR fnames;
  150. PWSTR s;
  151. BOOL b;
  152. PROTECTED_FILE_DATA ProtFileData;
  153. DWORD starttype;
  154. DWORD quota;
  155. WCHAR Path[MAX_PATH];
  156. #if 0
  157. GetPrivateProfileString(L"test",
  158. L"path",
  159. L"c:\\winnt\\system32",
  160. Path,
  161. sizeof(Path),
  162. L"test.ini");
  163. return MakeDirectory( Path );
  164. #endif
  165. if (argc == 2 && _wcsicmp(argv[1],L"/i")==0) {
  166. RpcHandle = SfcConnectToServer( NULL );
  167. s = fnames = (PWSTR) LocalAlloc( LPTR, 8192 );
  168. s = addstr( s, L"%windir%\\system32\\admwprox.dll" );
  169. s = addstr( s, L"%windir%\\system32\\adsiis.dll" );
  170. s = addstr( s, L"%windir%\\system32\\inetsrv\\certmap.ocx" );
  171. s = addstr( s, L"%windir%\\system32\\inetsrv\\certwiz.ocx" );
  172. s = addstr( s, L"%windir%\\system32\\inetsrv\\cnfgprts.ocx" );
  173. s = addstr( s, L"%windir%\\system32\\inetsrv\\coadmin.dll" );
  174. s = addstr( s, L"%windir%\\system32\\inetsrv\\dt_ctrl.dll" );
  175. s = addstr( s, L"%windir%\\system32\\inetsrv\\fscfg.dll" );
  176. s = addstr( s, L"%windir%\\system32\\ftpsapi2.dll" );
  177. s = addstr( s, L"%windir%\\system32\\iisext.dll" );
  178. s = addstr( s, L"%windir%\\system32\\iismap.dll" );
  179. s = addstr( s, L"%windir%\\system32\\iisreset.exe" );
  180. s = addstr( s, L"%windir%\\system32\\iisrstap.dll" );
  181. s = addstr( s, L"%windir%\\system32\\inetsrv\\iisrstas.exe" );
  182. s = addstr( s, L"%windir%\\system32\\iisrtl.dll" );
  183. s = addstr( s, L"%windir%\\system32\\inetsrv\\iisui.dll" );
  184. s = addstr( s, L"%windir%\\system32\\inetsrv\\inetmgr.dll" );
  185. s = addstr( s, L"%windir%\\system32\\inetsrv\\inetmgr.exe" );
  186. s = addstr( s, L"%windir%\\system32\\inetsloc.dll" );
  187. s = addstr( s, L"%windir%\\system32\\infoadmn.dll" );
  188. s = addstr( s, L"%windir%\\system32\\inetsrv\\isatq.dll" );
  189. s = addstr( s, L"%windir%\\system32\\inetsrv\\logui.ocx" );
  190. s = addstr( s, L"%windir%\\system32\\inetsrv\\nntpadm.dll" );
  191. s = addstr( s, L"%windir%\\system32\\inetsrv\\nntpsnap.dll" );
  192. s = addstr( s, L"%windir%\\system32\\inetsrv\\smtpadm.dll" );
  193. s = addstr( s, L"%windir%\\system32\\inetsrv\\smtpsnap.dll" );
  194. s = addstr( s, L"%windir%\\system32\\staxmem.dll" );
  195. s = addstr( s, L"%windir%\\system32\\inetsrv\\w3scfg.dll" );
  196. s = addstr( s, L"%windir%\\system32\\wamregps.dll" );
  197. SfcInstallProtectedFiles( RpcHandle, fnames, TRUE, NULL, NULL, SfcNotificationCallback, 0 );
  198. return 0;
  199. }
  200. if (argc == 2 && _wcsicmp(argv[1],L"/t")==0) {
  201. RpcHandle = SfcConnectToServer( NULL );
  202. b = SfcIsFileProtected( RpcHandle, L"%systemroot%\\system32\\kernel32.dll" );
  203. return 0;
  204. }
  205. if (argc == 2 && _wcsicmp(argv[1],L"/x")==0) {
  206. //RpcHandle = SfcConnectToServer( NULL );
  207. ZeroMemory( &ProtFileData, sizeof(PROTECTED_FILE_DATA) );
  208. ProtFileData.FileNumber = 24;
  209. b = SfcGetNextProtectedFile( RpcHandle, &ProtFileData );
  210. if (b) {
  211. wprintf( L"%ws\n", ProtFileData.FileName );
  212. }
  213. return 0;
  214. }
  215. if (argc == 2 && _wcsicmp(argv[1],L"/c")==0) {
  216. DialogBoxParam(
  217. GetModuleHandle(NULL),
  218. MAKEINTRESOURCE(IDD_SFC_CD_PROMPT),
  219. NULL,
  220. PromptForMediaDialogProc,
  221. 0
  222. );
  223. return 0;
  224. }
  225. if (argc == 2 && _wcsicmp(argv[1],L"/p")==0) {
  226. TCHAR DllPath[MAX_PATH];
  227. HMODULE DllMod;
  228. ExpandEnvironmentStrings(argv[2],DllPath,sizeof(DllPath)/sizeof(TCHAR));
  229. DllMod = LoadLibrary(DllPath);
  230. MoveFileEx(DllPath,NULL,MOVEFILE_DELAY_UNTIL_REBOOT);
  231. FreeLibrary(DllMod);
  232. }
  233. starttype = GetPrivateProfileInt(L"test",
  234. L"starttype",
  235. 0,
  236. L"test.ini");
  237. quota = GetPrivateProfileInt(L"test",
  238. L"quota",
  239. 0,
  240. L"test.ini");
  241. SfcInitProt( SFC_REGISTRY_OVERRIDE,
  242. starttype,
  243. SFC_SCAN_NORMAL,
  244. quota,
  245. NULL,
  246. NULL,
  247. NULL);
  248. while (TRUE) {
  249. if (WaitForSingleObject( NtCurrentProcess(), 1000 * 10 ) == WAIT_OBJECT_0) {
  250. break;
  251. }
  252. if (GetPrivateProfileInt(L"test",
  253. L"shutdown",
  254. 0,
  255. L"test.ini")) {
  256. break;
  257. }
  258. }
  259. SfcTerminateWatcherThread();
  260. return 0;
  261. RpcHandle = SfcConnectToServer( NULL );
  262. SfcInitiateScan( RpcHandle, 0 );
  263. return 0;
  264. RpcHandle = SfcConnectToServer( NULL );
  265. SfcFileException( RpcHandle, argv[1], FILE_ACTION_REMOVED );
  266. return 0;
  267. RpcHandle = SfcConnectToServer( NULL );
  268. FileData.FileNumber = 0;
  269. while(SfcGetNextProtectedFile(RpcHandle,&FileData)) {
  270. if (GetFileAttributes(FileData.FileName) != 0xffffffff) {
  271. wprintf( L"File = %ws\n", FileData.FileName );
  272. }
  273. }
  274. return 0;
  275. }