mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-06-17 18:16:07 -05:00
Windows: simplify favorite mount batch results
Return a structured internal result for favorite mount batches instead of combining a BOOL return value with optional out parameters. Keep the public MountFavoriteVolumes API unchanged and preserve favorite-on-arrival cancellation and drive-letter handling semantics.
This commit is contained in:
+47
-42
@@ -209,6 +209,15 @@ typedef struct
|
|||||||
volatile LONG nCurrentMountDriveNo;
|
volatile LONG nCurrentMountDriveNo;
|
||||||
} MountBatchContext;
|
} MountBatchContext;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
BOOL Success;
|
||||||
|
BOOL MountedAny;
|
||||||
|
/* Reason the batch stopped early. Non-terminal per-favorite failures are
|
||||||
|
reflected by Success == FALSE while StopReason remains MountResultSucceeded. */
|
||||||
|
MountResult StopReason;
|
||||||
|
} MountFavoriteVolumesResult;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
BOOL systemFavorites;
|
BOOL systemFavorites;
|
||||||
@@ -220,7 +229,7 @@ typedef struct
|
|||||||
} mountFavoriteVolumeThreadParam;
|
} mountFavoriteVolumeThreadParam;
|
||||||
|
|
||||||
static void __cdecl mountFavoriteVolumeThreadFunction (void *pArg);
|
static void __cdecl mountFavoriteVolumeThreadFunction (void *pArg);
|
||||||
static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount, MountBatchContext* pMountBatch, MountResult* pBatchResult);
|
static MountFavoriteVolumesResult MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount, MountBatchContext* pMountBatch);
|
||||||
|
|
||||||
|
|
||||||
static void MountBatchInitialize (MountBatchContext* pMountBatch)
|
static void MountBatchInitialize (MountBatchContext* pMountBatch)
|
||||||
@@ -8453,23 +8462,22 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
|
|
||||||
if (!mountedAndNotDisconnected)
|
if (!mountedAndNotDisconnected)
|
||||||
{
|
{
|
||||||
BOOL mounted = FALSE;
|
MountFavoriteVolumesResult favoriteMountResult;
|
||||||
MountResult mountResult = MountResultFailed;
|
|
||||||
MountBatchContext mountBatch;
|
MountBatchContext mountBatch;
|
||||||
MountBatchInitialize (&mountBatch);
|
MountBatchInitialize (&mountBatch);
|
||||||
{
|
{
|
||||||
FavoriteMountOnArrivalInProgress = TRUE;
|
FavoriteMountOnArrivalInProgress = TRUE;
|
||||||
finally_do ({ FavoriteMountOnArrivalInProgress = FALSE; });
|
finally_do ({ FavoriteMountOnArrivalInProgress = FALSE; });
|
||||||
SetLastError (ERROR_SUCCESS);
|
SetLastError (ERROR_SUCCESS);
|
||||||
mounted = MountFavoriteVolumesWithAbort (hwndDlg, FALSE, FALSE, FALSE, favorite, &mountBatch, &mountResult);
|
favoriteMountResult = MountFavoriteVolumesWithAbort (hwndDlg, FALSE, FALSE, FALSE, favorite, &mountBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted)
|
if (favoriteMountResult.Success)
|
||||||
{
|
{
|
||||||
ResumeFavoriteVolumeArrivalMount (SuppressedFavoritesOnArrivalMount, favorite);
|
ResumeFavoriteVolumeArrivalMount (SuppressedFavoritesOnArrivalMount, favorite);
|
||||||
FavoritesMountedOnArrivalStillConnected.push_back (favorite);
|
FavoritesMountedOnArrivalStillConnected.push_back (favorite);
|
||||||
}
|
}
|
||||||
else if (mountResult == MountResultCancelled || mountResult == MountResultArrivalPasswordPromptDeclined)
|
else if (favoriteMountResult.StopReason == MountResultCancelled || favoriteMountResult.StopReason == MountResultArrivalPasswordPromptDeclined)
|
||||||
{
|
{
|
||||||
SuppressFavoriteVolumeArrivalMount (SuppressedFavoritesOnArrivalMount, favorite);
|
SuppressFavoriteVolumeArrivalMount (SuppressedFavoritesOnArrivalMount, favorite);
|
||||||
break;
|
break;
|
||||||
@@ -11386,33 +11394,31 @@ skipMount:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Applies a single favorite's mount result to the running batch state. Updates *pbRet
|
/* Applies a single favorite's mount result to the running batch state. Returns FALSE
|
||||||
(overall success), *pbMountedAny (whether any volume mounted, for token-session cleanup)
|
if the batch must stop after this favorite. pResult must be valid. */
|
||||||
and *pBatchResult (the reason a batch stopped). Returns FALSE if the batch must stop
|
static BOOL HandleFavoriteMountResult (MountResult mountResult, MountBatchContext* pMountBatch, MountFavoriteVolumesResult* pResult)
|
||||||
after this favorite. All out-pointers must be valid. */
|
|
||||||
static BOOL HandleFavoriteMountResult (MountResult mountResult, MountBatchContext* pMountBatch, BOOL* pbRet, BOOL* pbMountedAny, MountResult* pBatchResult)
|
|
||||||
{
|
{
|
||||||
switch (mountResult)
|
switch (mountResult)
|
||||||
{
|
{
|
||||||
case MountResultSucceeded:
|
case MountResultSucceeded:
|
||||||
*pbMountedAny = TRUE;
|
pResult->MountedAny = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case MountResultFailed:
|
case MountResultFailed:
|
||||||
*pbRet = FALSE;
|
pResult->Success = FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
case MountResultCancelled:
|
case MountResultCancelled:
|
||||||
/* Wait-dialog/driver abort: stop the whole batch. */
|
/* Wait-dialog/driver abort: stop the whole batch. */
|
||||||
MountBatchRequestAbort (pMountBatch);
|
MountBatchRequestAbort (pMountBatch);
|
||||||
*pBatchResult = mountResult;
|
pResult->StopReason = mountResult;
|
||||||
*pbRet = FALSE;
|
pResult->Success = FALSE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
case MountResultArrivalPasswordPromptDeclined:
|
case MountResultArrivalPasswordPromptDeclined:
|
||||||
/* Arrival password-prompt cancel suppresses this favorite without aborting the batch. */
|
/* Arrival password-prompt cancel suppresses this favorite without aborting the batch. */
|
||||||
*pBatchResult = mountResult;
|
pResult->StopReason = mountResult;
|
||||||
*pbRet = FALSE;
|
pResult->Success = FALSE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
case MountResultDriveLetterUnavailable:
|
case MountResultDriveLetterUnavailable:
|
||||||
@@ -11429,15 +11435,17 @@ static BOOL HandleFavoriteMountResult (MountResult mountResult, MountBatchContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount, MountBatchContext* pMountBatch, MountResult* pBatchResult)
|
static MountFavoriteVolumesResult MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount, MountBatchContext* pMountBatch)
|
||||||
{
|
{
|
||||||
BOOL bRet = TRUE;
|
MountFavoriteVolumesResult batchResult;
|
||||||
BOOL bMountedAny = FALSE;
|
|
||||||
MountResult mountResult = MountResultSkipped;
|
MountResult mountResult = MountResultSkipped;
|
||||||
MountResult batchResult = MountResultSucceeded;
|
|
||||||
BOOL lastbExplore;
|
BOOL lastbExplore;
|
||||||
BOOL userForcedReadOnly = FALSE;
|
BOOL userForcedReadOnly = FALSE;
|
||||||
|
|
||||||
|
batchResult.Success = TRUE;
|
||||||
|
batchResult.MountedAny = FALSE;
|
||||||
|
batchResult.StopReason = MountResultSucceeded;
|
||||||
|
|
||||||
if (ServiceMode)
|
if (ServiceMode)
|
||||||
{
|
{
|
||||||
// in service case, intialize some global variable here.
|
// in service case, intialize some global variable here.
|
||||||
@@ -11492,7 +11500,7 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
{
|
{
|
||||||
if (ServiceMode)
|
if (ServiceMode)
|
||||||
SystemFavoritesServiceLogError (wstring (L"An error occured while reading System Favorites XML file"));
|
SystemFavoritesServiceLogError (wstring (L"An error occured while reading System Favorites XML file"));
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11505,8 +11513,8 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
{
|
{
|
||||||
if (MountBatchAbortRequested (pMountBatch))
|
if (MountBatchAbortRequested (pMountBatch))
|
||||||
{
|
{
|
||||||
batchResult = MountResultCancelled;
|
batchResult.StopReason = MountResultCancelled;
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11528,7 +11536,7 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
|
|
||||||
SetLastError (ERROR_SUCCESS);
|
SetLastError (ERROR_SUCCESS);
|
||||||
mountResult = MountFavoriteVolumeBase (hwnd, favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, pMountBatch);
|
mountResult = MountFavoriteVolumeBase (hwnd, favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, pMountBatch);
|
||||||
if (!HandleFavoriteMountResult (mountResult, pMountBatch, &bRet, &bMountedAny, &batchResult))
|
if (!HandleFavoriteMountResult (mountResult, pMountBatch, &batchResult))
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11542,8 +11550,8 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
{
|
{
|
||||||
if (MountBatchAbortRequested (pMountBatch))
|
if (MountBatchAbortRequested (pMountBatch))
|
||||||
{
|
{
|
||||||
batchResult = MountResultCancelled;
|
batchResult.StopReason = MountResultCancelled;
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11551,8 +11559,8 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
|
|
||||||
if (MountBatchAbortRequested (pMountBatch))
|
if (MountBatchAbortRequested (pMountBatch))
|
||||||
{
|
{
|
||||||
batchResult = MountResultCancelled;
|
batchResult.StopReason = MountResultCancelled;
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11567,8 +11575,8 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
{
|
{
|
||||||
if (MountBatchAbortRequested (pMountBatch))
|
if (MountBatchAbortRequested (pMountBatch))
|
||||||
{
|
{
|
||||||
batchResult = MountResultCancelled;
|
batchResult.StopReason = MountResultCancelled;
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11598,7 +11606,7 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
|
|
||||||
SetLastError (ERROR_SUCCESS);
|
SetLastError (ERROR_SUCCESS);
|
||||||
mountResult = MountFavoriteVolumeBase (hwnd, *favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, pMountBatch);
|
mountResult = MountFavoriteVolumeBase (hwnd, *favorite, lastbExplore, userForcedReadOnly, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, pMountBatch);
|
||||||
if (!HandleFavoriteMountResult (mountResult, pMountBatch, &bRet, &bMountedAny, &batchResult))
|
if (!HandleFavoriteMountResult (mountResult, pMountBatch, &batchResult))
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11618,8 +11626,8 @@ static BOOL MountFavoriteVolumesWithAbort (HWND hwnd, BOOL systemFavorites, BOOL
|
|||||||
ret:
|
ret:
|
||||||
if (MountBatchAbortRequested (pMountBatch))
|
if (MountBatchAbortRequested (pMountBatch))
|
||||||
{
|
{
|
||||||
batchResult = MountResultCancelled;
|
batchResult.StopReason = MountResultCancelled;
|
||||||
bRet = FALSE;
|
batchResult.Success = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultipleMountOperationInProgress = FALSE;
|
MultipleMountOperationInProgress = FALSE;
|
||||||
@@ -11627,16 +11635,13 @@ ret:
|
|||||||
burn (&VolumePkcs5, sizeof (VolumePkcs5));
|
burn (&VolumePkcs5, sizeof (VolumePkcs5));
|
||||||
burn (&VolumePim, sizeof (VolumePim));
|
burn (&VolumePim, sizeof (VolumePim));
|
||||||
|
|
||||||
if ((bRet || ((batchResult == MountResultCancelled || batchResult == MountResultArrivalPasswordPromptDeclined) && bMountedAny)) && CloseSecurityTokenSessionsAfterMount)
|
if ((batchResult.Success || ((batchResult.StopReason == MountResultCancelled || batchResult.StopReason == MountResultArrivalPasswordPromptDeclined) && batchResult.MountedAny)) && CloseSecurityTokenSessionsAfterMount)
|
||||||
SecurityToken::CloseAllSessions(); // TODO Use Token
|
SecurityToken::CloseAllSessions(); // TODO Use Token
|
||||||
|
|
||||||
if (batchResult == MountResultCancelled)
|
if (batchResult.StopReason == MountResultCancelled)
|
||||||
SetLastError (ERROR_CANCELLED);
|
SetLastError (ERROR_CANCELLED);
|
||||||
|
|
||||||
if (pBatchResult)
|
return batchResult;
|
||||||
*pBatchResult = batchResult;
|
|
||||||
|
|
||||||
return bRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
|
BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
|
||||||
@@ -11644,7 +11649,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO
|
|||||||
MountBatchContext mountBatch;
|
MountBatchContext mountBatch;
|
||||||
MountBatchInitialize (&mountBatch);
|
MountBatchInitialize (&mountBatch);
|
||||||
|
|
||||||
return MountFavoriteVolumesWithAbort (hwnd, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, &mountBatch, NULL);
|
return MountFavoriteVolumesWithAbort (hwnd, systemFavorites, logOnMount, hotKeyMount, favoriteVolumeToMount, &mountBatch).Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CALLBACK mountFavoriteVolumeCallbackFunction (void *pArg, HWND hwnd)
|
static void CALLBACK mountFavoriteVolumeCallbackFunction (void *pArg, HWND hwnd)
|
||||||
@@ -11656,7 +11661,7 @@ static void CALLBACK mountFavoriteVolumeCallbackFunction (void *pArg, HWND hwnd)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const FavoriteVolume& favoriteVolumeToMount = pParam->favoriteVolumeToMount ? *(pParam->favoriteVolumeToMount) : FavoriteVolume();
|
const FavoriteVolume& favoriteVolumeToMount = pParam->favoriteVolumeToMount ? *(pParam->favoriteVolumeToMount) : FavoriteVolume();
|
||||||
MountFavoriteVolumesWithAbort (hwnd, pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount, favoriteVolumeToMount, &pParam->mountBatch, NULL);
|
MountFavoriteVolumesWithAbort (hwnd, pParam->systemFavorites, pParam->logOnMount, pParam->hotKeyMount, favoriteVolumeToMount, &pParam->mountBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CALLBACK mountFavoriteVolumeCancelProc(void* pArg, HWND )
|
BOOL CALLBACK mountFavoriteVolumeCancelProc(void* pArg, HWND )
|
||||||
|
|||||||
Reference in New Issue
Block a user