Skip to content

Commit

Permalink
feat(pedm): desktop agent refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
thenextman committed Nov 5, 2024
1 parent f86e114 commit 7ebd452
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 136 deletions.
5 changes: 4 additions & 1 deletion crates/devolutions-pedm-shared/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use win_api_wrappers::raw::Win32::Security::TOKEN_QUERY;
use windows_registry::LOCAL_MACHINE;

pub fn install_dir() -> Result<PathBuf> {
// TODO: lookup from registry only works when installed by MSI
Ok(PathBuf::from_str(
&LOCAL_MACHINE
.open(r"SOFTWARE\Devolutions\Agent")?
Expand All @@ -17,7 +18,8 @@ pub fn install_dir() -> Result<PathBuf> {
pub fn desktop_exe() -> Result<PathBuf> {
let mut exe = install_dir()?;

exe.push("desktop/DevolutionsPedmDesktop.exe");
exe.push("desktop");
exe.push("DevolutionsDesktopAgent.exe");

Ok(exe)
}
Expand All @@ -28,6 +30,7 @@ pub enum DesktopMode {

pub fn launch(mode: &DesktopMode) -> Result<()> {
let mut base_command = Command::new(desktop_exe()?);
base_command.arg(desktop_exe()?);
base_command.arg(
Process::current_process()
.token(TOKEN_QUERY)?
Expand Down
2 changes: 1 addition & 1 deletion crates/devolutions-pedm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use camino::Utf8PathBuf;
use win_api_wrappers::process::Module;
use win_api_wrappers::raw::Win32::Foundation::LUID;

pub(crate) static PEDM_DESKTOP_RELPATH: &str = r"desktop/DevolutionsPedmDesktop.exe";
pub(crate) static PEDM_DESKTOP_RELPATH: &str = r"desktop/DevolutionsDesktopAgent.exe";

pub(crate) static PIPE_NAME: &str = r"\\.\pipe\DevolutionsPEDM";

Expand Down
113 changes: 0 additions & 113 deletions crates/devolutions-pedm/src/desktop.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/devolutions-pedm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
pub mod api;
mod config;
mod desktop;
mod elevations;
mod elevator;
mod error;
Expand Down
13 changes: 1 addition & 12 deletions crates/devolutions-pedm/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use win_api_wrappers::utils::CommandLine;
use anyhow::{anyhow, bail, Result};

use crate::config;
use crate::desktop::launch_consent;
use crate::error::Error;
use crate::utils::{ensure_protected_directory, file_hash, AccountExt, MultiHasher};
use devolutions_pedm_shared::policy;
Expand Down Expand Up @@ -324,17 +323,7 @@ impl Policy {

match elevation_type {
policy::ElevationKind::AutoApprove => Ok(()),
policy::ElevationKind::Confirm => {
if !launch_consent(
session_id,
&Sid::try_from(request.asker.user.account_sid.as_str())?,
&request.target.path,
)? {
bail!(Error::Cancelled);
}

Ok(())
}
policy::ElevationKind::Confirm => bail!(Error::InvalidParameter),
policy::ElevationKind::ReasonApproval => bail!(Error::InvalidParameter),
policy::ElevationKind::Deny => bail!(Error::AccessDenied),
}
Expand Down
9 changes: 9 additions & 0 deletions dotnet/DesktopAgent/DesktopAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<RootNamespace>Devolutions.Agent.Desktop</RootNamespace>
<AssemblyName>DevolutionsDesktopAgent</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>latest</LangVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
Expand All @@ -24,6 +25,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -40,6 +42,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -84,5 +87,11 @@
<ItemGroup>
<Content Include="Resources\AppIcon.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\crates\devolutions-pedm\openapi\dotnet-client\src\Devolutions.Pedm.Client\Devolutions.Pedm.Client.csproj">
<Project>{2d633ac7-9fdc-4cda-bbb8-7fd33493d79f}</Project>
<Name>Devolutions.Pedm.Client</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions dotnet/DesktopAgent/DesktopAgent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.10.35201.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesktopAgent", "DesktopAgent.csproj", "{6DFAA3D7-4F38-4329-8CEE-D6968959A701}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Devolutions.Pedm.Client", "..\..\crates\devolutions-pedm\openapi\dotnet-client\src\Devolutions.Pedm.Client\Devolutions.Pedm.Client.csproj", "{2D633AC7-9FDC-4CDA-BBB8-7FD33493D79F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{6DFAA3D7-4F38-4329-8CEE-D6968959A701}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DFAA3D7-4F38-4329-8CEE-D6968959A701}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DFAA3D7-4F38-4329-8CEE-D6968959A701}.Release|Any CPU.Build.0 = Release|Any CPU
{2D633AC7-9FDC-4CDA-BBB8-7FD33493D79F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D633AC7-9FDC-4CDA-BBB8-7FD33493D79F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D633AC7-9FDC-4CDA-BBB8-7FD33493D79F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D633AC7-9FDC-4CDA-BBB8-7FD33493D79F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 7ebd452

Please sign in to comment.