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.

384 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. Main module of the jetconv.exe process
  7. Author:
  8. Sanjay Anand (SanjayAn) Nov. 14, 1995
  9. Environment:
  10. User mode
  11. Revision History:
  12. Sanjay Anand (SanjayAn) Nov. 14, 1995
  13. Created
  14. Shreedhar Madhavapeddi (ShreeM) Mar 23, 1997
  15. * Added code to convert from Jet500 to Jet600 too
  16. * additional cmdline option to specify the final database format.
  17. --*/
  18. #include "defs.h"
  19. TCHAR SystemDrive[4];
  20. LONG JCDebugLevel = 1;
  21. PSHARED_MEM shrdMemPtr = NULL;
  22. HANDLE hMutex=NULL;
  23. HANDLE hFileMapping = NULL;
  24. BOOLEAN Jet200 = FALSE;
  25. void _cdecl
  26. main(
  27. INT argc,
  28. CHAR *argv[]
  29. )
  30. /*++
  31. Routine Description:
  32. Main routine in the jetconv process.
  33. Arguments:
  34. argc - 1 or 2
  35. argv - If called from any of the services, we get the name of the
  36. service as the parameter, else if it is invoked from the command
  37. line, no parameter is passed in.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. DWORD error, mutexerr, bConvert;
  43. SERVICES i, thisServiceId = NUM_SERVICES;
  44. SERVICE_INFO pServiceInfo[NUM_SERVICES] = {
  45. {"DHCPServer", FALSE, TRUE, TRUE, FALSE, FALSE, DEFAULT_DHCP_DBFILE_PATH,
  46. DEFAULT_DHCP_SYSTEM_PATH, DEFAULT_DHCP_LOGFILE_PATH, DEFAULT_DHCP_BACKUP_PATH,
  47. DEFAULT_DHCP_BACKUP_PATH_ESE, DEFAULT_DHCP_PRESERVE_PATH_ESE, 0 },
  48. {"WINS", FALSE, TRUE, TRUE, FALSE, FALSE, DEFAULT_WINS_DBFILE_PATH,
  49. DEFAULT_WINS_SYSTEM_PATH, DEFAULT_WINS_LOGFILE_PATH, DEFAULT_WINS_BACKUP_PATH,
  50. DEFAULT_WINS_BACKUP_PATH_ESE, DEFAULT_WINS_PRESERVE_PATH_ESE, 0 },
  51. {"Remoteboot", FALSE, TRUE, TRUE, FALSE, FALSE, DEFAULT_RPL_DBFILE_PATH,
  52. DEFAULT_RPL_SYSTEM_PATH, DEFAULT_RPL_LOGFILE_PATH, DEFAULT_RPL_BACKUP_PATH,
  53. DEFAULT_RPL_BACKUP_PATH_ESE, DEFAULT_RPL_PRESERVE_PATH_ESE, 0 }
  54. };
  55. TCHAR val[2];
  56. LPVOID lpMsgBuf;
  57. ULONG MsgLen = 0;
  58. if (GetEnvironmentVariable(TEXT("JetConvDebug"), val, 2*sizeof(TCHAR))) {
  59. if (strcmp(val, "1")==0) {
  60. JCDebugLevel = 1;
  61. } else {
  62. JCDebugLevel = 2;
  63. }
  64. }
  65. //
  66. // Invoked only from the three services - WINS/DHCP/RPL with two args - servicename and "/@"
  67. //
  68. if ((argc != 4) ||
  69. ((argc == 4) && _stricmp(argv[3], "/@"))) {
  70. //
  71. // Probably called from command line
  72. //
  73. LPVOID lpMsgBuf;
  74. if (FormatMessage(
  75. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  76. NULL,
  77. JC_NOT_ALLOWED_FROM_CMD,
  78. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  79. (LPTSTR) &lpMsgBuf,
  80. 0,
  81. NULL
  82. ))
  83. {
  84. CharToOemA(lpMsgBuf, lpMsgBuf);
  85. printf("%s", lpMsgBuf);
  86. LocalFree(lpMsgBuf);
  87. }
  88. exit (1);
  89. } else {
  90. MYDEBUG(("Service passed in: %s\n", argv[1]));
  91. for ( i=0; i < NUM_SERVICES; i++) {
  92. if (_stricmp(pServiceInfo[i].ServiceName, argv[1]) == 0) {
  93. thisServiceId = i;
  94. }
  95. }
  96. if (thisServiceId == NUM_SERVICES) {
  97. MYDEBUG(("Error: Bad service Id passed in\n"));
  98. exit(1);
  99. }
  100. //
  101. // now find out which database they want to convert to
  102. //
  103. if (_stricmp("/200", argv[2]) == 0) {
  104. Jet200 = TRUE; // start from jet200
  105. MYDEBUG(("Converting from Jet200\n"));
  106. } else if (_stricmp("/500", argv[2]) == 0) {
  107. Jet200 = FALSE; // start from jet500
  108. MYDEBUG(("Converting from Jet500\n"));
  109. } else {
  110. MYDEBUG(("Invalid database conversion format parameter: has to be /200 or /500 \n"));
  111. exit(1);
  112. }
  113. }
  114. if ((hMutex = CreateMutex( NULL,
  115. FALSE,
  116. JCONVMUTEXNAME)) == NULL) {
  117. error = GetLastError();
  118. MYDEBUG(("CreateMutex returned error: %lx\n", error));
  119. exit (1);
  120. }
  121. mutexerr = GetLastError();
  122. JCGetMutex(hMutex, INFINITE);
  123. hFileMapping = OpenFileMapping( FILE_MAP_WRITE,
  124. FALSE,
  125. JCONVSHAREDMEMNAME );
  126. if (hFileMapping) {
  127. //
  128. // Another instance of JCONV was already running.
  129. // Write our service name and exit
  130. //
  131. if ((shrdMemPtr = (PSHARED_MEM)MapViewOfFile( hFileMapping,
  132. FILE_MAP_WRITE,
  133. 0L,
  134. 0L,
  135. sizeof(SHARED_MEM))) == NULL) {
  136. MYDEBUG(("MapViewOfFile returned error: %lx\n", GetLastError()));
  137. JCFreeMutex(hMutex);
  138. exit(1);
  139. }
  140. if (thisServiceId < NUM_SERVICES) {
  141. shrdMemPtr->InvokedByService[thisServiceId] = TRUE;
  142. }
  143. MYDEBUG(("shrdMemPtr->InvokedByService[i]: %x, %x, %x\n", shrdMemPtr->InvokedByService[0], shrdMemPtr->InvokedByService[1], shrdMemPtr->InvokedByService[2]));
  144. JCFreeMutex(hMutex);
  145. exit (1);
  146. } else {
  147. if (mutexerr == ERROR_ALREADY_EXISTS) {
  148. //
  149. // Upg351Db was running; log an entry and scram.
  150. //
  151. MYDEBUG(("Upg351Db already running\n"));
  152. JCFreeMutex(hMutex);
  153. exit(1);
  154. }
  155. //
  156. // Create the file mapping.
  157. //
  158. hFileMapping = CreateFileMapping( INVALID_HANDLE_VALUE,
  159. NULL,
  160. PAGE_READWRITE,
  161. 0L,
  162. sizeof(SHARED_MEM),
  163. JCONVSHAREDMEMNAME );
  164. if (hFileMapping) {
  165. //
  166. // Write our service name in the shared memory and clear the others.
  167. //
  168. if ((shrdMemPtr = (PSHARED_MEM)MapViewOfFile( hFileMapping,
  169. FILE_MAP_WRITE,
  170. 0L,
  171. 0L,
  172. sizeof(SHARED_MEM))) == NULL) {
  173. MYDEBUG(("MapViewOfFile returned error: %lx\n", GetLastError()));
  174. JCFreeMutex(hMutex);
  175. exit(1);
  176. }
  177. for (i = 0; i < NUM_SERVICES; i++) {
  178. shrdMemPtr->InvokedByService[i] = (i == thisServiceId) ? TRUE : FALSE;
  179. MYDEBUG(("shrdMemPtr->InvokedByService[i]: %x\n", shrdMemPtr->InvokedByService[i]));
  180. }
  181. }
  182. else
  183. {
  184. MYDEBUG(("CreateFileMapping returned error: %lx\n", GetLastError()));
  185. JCFreeMutex(hMutex);
  186. exit(1);
  187. }
  188. }
  189. JCFreeMutex(hMutex);
  190. //
  191. // Find out which services are installed in the system. Fill in the paths
  192. // to their database files.
  193. //
  194. JCReadRegistry(pServiceInfo);
  195. //
  196. // Get the sizes of the dbase files; if there is enough disk space, call convert
  197. // for each service.
  198. //
  199. bConvert = JCConvert(pServiceInfo);
  200. (VOID)JCDeRegisterEventSrc();
  201. //
  202. // Destroy the mutex too.
  203. //
  204. CloseHandle(hMutex);
  205. MYDEBUG(("The conversion was OK\n"));
  206. if (ERROR_SUCCESS == bConvert) {
  207. DWORD Error;
  208. TCHAR DeleteDBFile[MAX_PATH];
  209. TCHAR DeleteDBFileName[MAX_PATH];
  210. INT size;
  211. //
  212. // Popup a dialog and tell the user that it was completed successfully.
  213. //
  214. MYDEBUG(("The conversion was OK - 1\n"));
  215. MsgLen = FormatMessage(
  216. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  217. NULL,
  218. (Jet200 ? JC_CONVERTED_FROM_NT351 : JC_CONVERTED_FROM_NT40),
  219. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  220. (LPTSTR) &lpMsgBuf,
  221. 0,
  222. NULL
  223. );
  224. if (!MsgLen) {
  225. Error = GetLastError();
  226. MYDEBUG(("FormatMessage failed with error = (%d)\n", Error ));
  227. goto Cleanup;
  228. } else {
  229. MYDEBUG(("FormatMessage : %d size\n", MsgLen));
  230. }
  231. #if 0
  232. //
  233. // since dhcp and wins don't throw popups anymore, don't need
  234. // popups in jetconv as well
  235. //
  236. if(MessageBoxEx(NULL,
  237. lpMsgBuf,
  238. __TEXT("Jet Conversion Process"),
  239. MB_SYSTEMMODAL | MB_OK | MB_SETFOREGROUND | MB_SERVICE_NOTIFICATION | MB_ICONINFORMATION,
  240. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)) == 0) {
  241. Error = GetLastError();
  242. MYDEBUG(("MessageBoxEx failed with error = (%d)\n", Error ));
  243. }
  244. #endif
  245. LocalFree(lpMsgBuf);
  246. //
  247. // Delete the edb500.dll, we dont need it anymore
  248. //
  249. //
  250. // Removed code that deleted edb500.dll (trade 500K disk space for support calls).
  251. // This was in response to bug # 192149
  252. } else {
  253. DWORD Error;
  254. //
  255. // Popup the error dialog
  256. //
  257. MYDEBUG(("The conversion was NOT OK\n"));
  258. MsgLen = FormatMessage(
  259. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  260. NULL,
  261. JC_EVERYTHING_FAILED,
  262. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  263. (LPTSTR) &lpMsgBuf,
  264. 0,
  265. NULL
  266. );
  267. if (!MsgLen) {
  268. Error = GetLastError();
  269. MYDEBUG(("FormatMessage failed with error = (%d)\n", Error ));
  270. goto Cleanup;
  271. } else {
  272. MYDEBUG(("The String is - %s\n", lpMsgBuf));
  273. MYDEBUG(("FormatMessage : %d size\n", MsgLen));
  274. }
  275. if(MessageBoxEx(NULL,
  276. lpMsgBuf,
  277. __TEXT("Jet Conversion Process"),
  278. MB_SYSTEMMODAL | MB_OK | MB_SETFOREGROUND | MB_SERVICE_NOTIFICATION | MB_ICONSTOP,
  279. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)) == 0) {
  280. DWORD Error;
  281. Error = GetLastError();
  282. MYDEBUG(("MessageBoxEx failed with error = (%d)\n", Error ));
  283. }
  284. LocalFree(lpMsgBuf);
  285. }
  286. Cleanup:
  287. MYDEBUG(("There was a failure in the MessageBoxEx code\n"));
  288. }