diff options
-rw-r--r-- | src/Mount/Mount.c | 89 |
1 files changed, 81 insertions, 8 deletions
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index 0ec43d45..212a5d39 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -8095,8 +8095,21 @@ static void SystemFavoritesServiceLogError (const string &errorMessage) DeregisterEventSource (eventSource);
}
}
+static void SystemFavoritesServiceLogInfo (const string &errorMessage)
+{
+ HANDLE eventSource = RegisterEventSource (NULL, TC_SYSTEM_FAVORITES_SERVICE_NAME);
+
+ if (eventSource)
+ {
+ LPCTSTR strings[] = { TC_SYSTEM_FAVORITES_SERVICE_NAME, errorMessage.c_str() };
+ ReportEvent (eventSource, EVENTLOG_INFORMATION_TYPE, 0, 0xC0000002, NULL, array_capacity (strings), 0, strings, NULL);
+
+ DeregisterEventSource (eventSource);
+ }
+}
+
static void SystemFavoritesServiceSetStatus (DWORD status, DWORD waitHint = 0)
{
SystemFavoritesServiceStatus.dwCurrentState = status;
@@ -8117,23 +8130,35 @@ static VOID WINAPI SystemFavoritesServiceCtrlHandler (DWORD control) static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv)
{
+ BOOL status = FALSE;
memset (&SystemFavoritesServiceStatus, 0, sizeof (SystemFavoritesServiceStatus));
SystemFavoritesServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
SystemFavoritesServiceStatusHandle = RegisterServiceCtrlHandler (TC_SYSTEM_FAVORITES_SERVICE_NAME, SystemFavoritesServiceCtrlHandler);
if (!SystemFavoritesServiceStatusHandle)
return;
- SystemFavoritesServiceSetStatus (SERVICE_START_PENDING, 60000);
+ SystemFavoritesServiceSetStatus (SERVICE_START_PENDING, 120000);
+
+ SystemFavoritesServiceLogInfo (string ("Starting System Favorites mounting process"));
try
{
- MountFavoriteVolumes (TRUE);
+ status = MountFavoriteVolumes (TRUE);
}
catch (...) { }
+ if (status)
+ {
+ SystemFavoritesServiceLogInfo (string ("System Favorites mounting process finished"));
+ }
+ else
+ {
+ SystemFavoritesServiceLogError (string ("System Favorites mounting process failed."));
+ }
+
SystemFavoritesServiceSetStatus (SERVICE_RUNNING);
SystemFavoritesServiceSetStatus (SERVICE_STOPPED);
}
@@ -8390,12 +8415,19 @@ void DismountIdleVolumes () BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
{
- BOOL status = TRUE;
+ BOOL bRet = TRUE;
BOOL lastbExplore;
BOOL userForcedReadOnly = FALSE;
+ if (ServiceMode)
+ {
+ // in service case, intialize some global variable here.
+ LastKnownMountList.ulMountedDrives = 0;
+ LoadDriveLetters (MainDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
+ }
+
mountOptions = defaultMountOptions;
VolumePassword.Length = 0;
MultipleMountOperationInProgress = (favoriteVolumeToMount.Path.empty() || FavoriteMountOnArrivalInProgress);
@@ -8405,12 +8437,23 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou if (systemFavorites)
{
try
{
+ if (ServiceMode)
+ SystemFavoritesServiceLogInfo (string ("Reading System Favorites XML file"));
LoadFavoriteVolumes (favorites, true);
+
+ if (ServiceMode)
+ {
+ char szTmp[32];
+ StringCbPrintf (szTmp, sizeof(szTmp), "%d", (int) favorites.size());
+ SystemFavoritesServiceLogInfo (string ("Loaded %d favorites from the file") + szTmp);
+ }
}
catch (...)
{
+ if (ServiceMode)
+ SystemFavoritesServiceLogError (string ("An error occured while reading System Favorites XML file"));
return false;
}
}
else if (!favoriteVolumeToMount.Path.empty())
@@ -8419,18 +8462,24 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou favorites = FavoriteVolumes;
foreach (const FavoriteVolume &favorite, favorites)
{
+ if (ServiceMode && systemFavorites && favorite.DisconnectedDevice)
+ {
+ SystemFavoritesServiceLogError (string ("Favorite \"") + favorite.Path + "\" is disconnected. It will be ignored.");
+ }
+
if (favorite.DisconnectedDevice
|| (logOnMount && !favorite.MountOnLogOn)
|| (hotKeyMount && favorite.DisableHotkeyMount))
{
continue;
}
+ BOOL status = TRUE;
int drive;
drive = toupper (favorite.MountPoint[0]) - 'A';
-
+
mountOptions.ReadOnly = favorite.ReadOnly || userForcedReadOnly;
mountOptions.Removable = favorite.Removable;
if (favorite.SystemEncryption)
@@ -8488,10 +8537,27 @@ BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMou }
BOOL prevReadOnly = mountOptions.ReadOnly;
- if (!Mount (MainDlg, drive, (char *) favorite.Path.c_str(), favorite.Pim))
- status = FALSE;
+ if (ServiceMode)
+ SystemFavoritesServiceLogInfo (string ("Mounting system favorite \"") + favorite.Path + "\"");
+
+ status = Mount (MainDlg, drive, (char *) favorite.Path.c_str(), favorite.Pim);
+
+ if (ServiceMode)
+ {
+ if (status)
+ {
+ SystemFavoritesServiceLogInfo (string ("Favorite \"") + favorite.Path + string ("\" mounted successfully as ") + (char) (drive + 'A') + ":");
+ }
+ else
+ {
+ SystemFavoritesServiceLogError (string ("Favorite \"") + favorite.Path + "\" failed to mount");
+ // Update the service status to avoid being killed
+ SystemFavoritesServiceStatus.dwCheckPoint++;
+ SystemFavoritesServiceSetStatus (SERVICE_START_PENDING, 120000);
+ }
+ }
if (status && mountOptions.ReadOnly != prevReadOnly)
userForcedReadOnly = mountOptions.ReadOnly;
@@ -8523,23 +8589,30 @@ skipMount: DeviceIoControl (hDriver, TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY, NULL, 0, NULL, 0, &bytesOut, NULL);
SystemFavoritesServiceLogError (string ("The filesystem of the volume mounted as ") + (char) (drive + 'A') + ": was not cleanly dismounted and needs to be checked for errors.");
}
+
+ if (!status)
+ bRet = FALSE;
}
else if (!systemFavorites && !favoriteVolumeToMount.Path.empty())
Error ("DRIVE_LETTER_UNAVAILABLE", MainDlg);
+ else if (ServiceMode && systemFavorites)
+ {
+ SystemFavoritesServiceLogError (string ("The drive letter ") + (char) (drive + 'A') + string (" used by favorite \"") + favorite.Path + "\" is already taken.\nThis system favorite will not be mounted");
+ }
}
MultipleMountOperationInProgress = FALSE;
burn (&VolumePassword, sizeof (VolumePassword));
burn (&VolumePkcs5, sizeof (VolumePkcs5));
burn (&VolumePim, sizeof (VolumePim));
burn (&VolumeTrueCryptMode, sizeof (VolumeTrueCryptMode));
- if (status && CloseSecurityTokenSessionsAfterMount)
+ if (bRet && CloseSecurityTokenSessionsAfterMount)
SecurityToken::CloseAllSessions();
- return status;
+ return bRet;
}
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg)
{
|