Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions src/modules/MouseWithoutBorders/App/Core/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,32 +574,73 @@ internal static void ReceiveAndProcessClipboardData(string remoteMachine, Socket
}
else
{
// Create received files in the same context that the destination folder is created
// in. For per-user storage (the user's Desktop) that means as the logged-on user, so
// the file ends up owned by that user and inherits the folder's permissions. On the
// logon/screen-saver desktop the storage lives under Program Files where there is no
// interactive user to impersonate, so create the file directly.
void CreateDestinationFile(string path)
{
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
m = new FileStream(path, FileMode.Create);
}
else
{
bool success = Launch.ImpersonateLoggedOnUserAndDoSomething(() =>
{
m = new FileStream(path, FileMode.Create);
});

if (!success || m == null)
{
Logger.Log("Impersonation failed for file creation, falling back to direct creation.");
m = new FileStream(path, FileMode.Create);
}
}
Comment thread
MuyuanMS marked this conversation as resolved.
}

if (postAct.Equals("desktop", StringComparison.OrdinalIgnoreCase))
{
_ = Launch.ImpersonateLoggedOnUserAndDoSomething(() =>
// Create the folder and open the file in a single impersonated scope so both
// are owned by the logged-on user. This branch always targets the user's Desktop.
bool success = Launch.ImpersonateLoggedOnUserAndDoSomething(() =>
Comment thread
MuyuanMS marked this conversation as resolved.
{
savingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MouseWithoutBorders\\";

if (!Directory.Exists(savingFolder))
{
_ = Directory.CreateDirectory(savingFolder);
}

tempFile = savingFolder + Path.GetFileName(fileName);
m = new FileStream(tempFile, FileMode.Create);
});
Comment thread
MuyuanMS marked this conversation as resolved.

tempFile = savingFolder + Path.GetFileName(fileName);
m = new FileStream(tempFile, FileMode.Create);
if (!success || m == null)
{
Logger.Log("Impersonation failed for desktop file creation, falling back to direct creation.");
savingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MouseWithoutBorders\\";
if (!Directory.Exists(savingFolder))
{
_ = Directory.CreateDirectory(savingFolder);
}

tempFile = savingFolder + Path.GetFileName(fileName);
m = new FileStream(tempFile, FileMode.Create);
}
}
else if (postAct.Contains("mspaint"))
{
tempFile = Common.GetMyStorageDir() + @"ScreenCapture-" +
remoteMachine + ".png";
m = new FileStream(tempFile, FileMode.Create);
CreateDestinationFile(tempFile);
}
else
{
tempFile = Common.GetMyStorageDir();
tempFile += Path.GetFileName(fileName);
m = new FileStream(tempFile, FileMode.Create);
CreateDestinationFile(tempFile);
}

Logger.Log("==> " + tempFile);
Expand Down
Loading