Skip to content

Commit 4adcf09

Browse files
authored
chore(pedm): clippy fixes (#1354)
This fixes most but not all of the Clippy lints.
1 parent 673a872 commit 4adcf09

8 files changed

Lines changed: 36 additions & 62 deletions

File tree

crates/devolutions-pedm/src/api/launch.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::path::{Path, PathBuf};
2-
use std::sync::Arc;
32

43
use aide::NoApi;
54
use axum::extract::State;
65
use axum::{Extension, Json};
7-
use parking_lot::RwLock;
86
use schemars::JsonSchema;
97
use serde::{Deserialize, Serialize};
108
use tracing::info;
@@ -20,10 +18,8 @@ use win_api_wrappers::token::Token;
2018
use win_api_wrappers::utils::{environment_block, expand_environment_path, CommandLine, WideString};
2119

2220
use crate::api::state::AppState;
23-
use crate::db::DbHandle;
2421
use crate::elevator;
2522
use crate::error::Error;
26-
use crate::policy::Policy;
2723

2824
use super::NamedPipeConnectInfo;
2925

crates/devolutions-pedm/src/api/log.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ async fn get_jit_elevation_log_id(
1414
NoApi(State(_state)): NoApi<State<AppState>>,
1515
NoApi(Db(db)): NoApi<Db>,
1616
) -> Result<Json<JitElevationLogRow>, Error> {
17-
let row = db.get_jit_elevation_log(id.id).await?.ok_or_else(|| Error::NotFound)?;
17+
let row = db.get_jit_elevation_log(id.id).await?.ok_or(Error::NotFound)?;
1818

19-
if row.user.as_ref().map_or(true, |u| u != &named_pipe_info.user) {
20-
if !named_pipe_info.token.is_elevated()? {
21-
return Err(Error::AccessDenied);
22-
}
19+
if row.user.as_ref().map_or(true, |u| u != &named_pipe_info.user) && !named_pipe_info.token.is_elevated()? {
20+
return Err(Error::AccessDenied);
2321
}
2422

2523
Ok(Json(row))
@@ -31,10 +29,10 @@ async fn get_jit_elevation_logs(
3129
NoApi(Db(db)): NoApi<Db>,
3230
Json(query_options): Json<JitElevationLogQueryOptions>,
3331
) -> Result<Json<JitElevationLogPage>, Error> {
34-
if query_options.user.as_ref().map_or(true, |u| u != &named_pipe_info.user) {
35-
if !named_pipe_info.token.is_elevated()? {
36-
return Err(Error::AccessDenied);
37-
}
32+
if query_options.user.as_ref().map_or(true, |u| u != &named_pipe_info.user)
33+
&& !named_pipe_info.token.is_elevated()?
34+
{
35+
return Err(Error::AccessDenied);
3836
}
3937

4038
let page = db.get_jit_elevation_logs(query_options).await?;

crates/devolutions-pedm/src/api/policy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct PathIdParameter {
8888
}
8989

9090
#[derive(Deserialize, JsonSchema)]
91-
pub struct PathIntIdPath {
91+
pub(crate) struct PathIntIdPath {
9292
pub id: i64,
9393
}
9494

@@ -203,7 +203,7 @@ async fn get_users(
203203
let mut users = db.get_users().await?;
204204

205205
if !named_pipe_info.token.is_elevated()? {
206-
users = users.into_iter().filter(|u| u == &named_pipe_info.user).collect();
206+
users.retain(|u| u == &named_pipe_info.user);
207207
}
208208

209209
Ok(Json(users))

crates/devolutions-pedm/src/db/err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ impl fmt::Display for InvalidEnumError {
153153
}
154154
}
155155

156-
impl std::error::Error for InvalidEnumError {}
156+
impl Error for InvalidEnumError {}

crates/devolutions-pedm/src/db/libsql.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl LibsqlConn {
3737

3838
if let Some(row) = rows.next().await? {
3939
let id: i64 = row.get(0)?;
40-
return Ok(Some(id));
40+
Ok(Some(id))
4141
} else {
42-
return Ok(None);
42+
Ok(None)
4343
}
4444
}
4545

@@ -271,10 +271,7 @@ impl Database for LibsqlConn {
271271
}))
272272
}
273273
},
274-
signer: match row.get::<Option<String>>(15)? {
275-
Some(issuer) => Some(Signer { issuer }),
276-
None => None,
277-
},
274+
signer: row.get::<Option<String>>(15)?.map(|issuer| Signer { issuer }),
278275
certificates: None,
279276
}),
280277
None => None,
@@ -329,13 +326,15 @@ impl Database for LibsqlConn {
329326

330327
let where_sql = format!(" WHERE {}", where_clauses.join(" AND "));
331328

332-
let count_sql = format!("SELECT COUNT(*) {}", &base_sql) + &where_sql;
329+
let mut count_sql = format!("SELECT COUNT(*) {}", &base_sql);
330+
count_sql.push_str(&where_sql);
333331
let total_records_row = self
334332
.query_one(&count_sql, libsql::params_from_iter(params.clone()))
335333
.await?;
336334
let total_records: i64 = total_records_row.get(0)?;
337-
let total_pages =
338-
((total_records + query_options.page_size as i64 - 1) / query_options.page_size as i64) as u32;
335+
let total_pages = u32::try_from(
336+
(total_records + i64::from(query_options.page_size) - 1) / i64::from(query_options.page_size),
337+
)?;
339338

340339
let sort_columns = ["success", "timestamp", "target_path", "target_user_id"];
341340
let sort_column = if sort_columns.contains(&query_options.sort_column.as_str()) {
@@ -345,12 +344,14 @@ impl Database for LibsqlConn {
345344
};
346345
let sort_order = if query_options.sort_descending { "DESC" } else { "ASC" };
347346

348-
let limit = query_options.page_size as i64;
349-
let offset = (query_options.page_number.saturating_sub(1) * query_options.page_size) as i64;
347+
let limit = i64::from(query_options.page_size);
348+
let offset = i64::from(query_options.page_number.saturating_sub(1) * query_options.page_size);
350349

350+
base_sql.push_str(&joins);
351+
base_sql.push_str(&where_sql);
351352
let select_sql = format!(
352353
"SELECT jit.id, jit.timestamp, jit.success, jit.target_path, u_display.account_name, u_display.domain_name, u_display.account_sid, u_display.domain_sid {} ORDER BY jit.{} {} LIMIT ? OFFSET ?",
353-
base_sql + &joins + &where_sql,
354+
base_sql,
354355
sort_column,
355356
sort_order
356357
);
@@ -379,8 +380,8 @@ impl Database for LibsqlConn {
379380
}
380381

381382
Ok(JitElevationLogPage {
382-
total_pages: total_pages,
383-
total_records: total_records as u32,
383+
total_pages,
384+
total_records: u32::try_from(total_records)?,
384385
results,
385386
})
386387
}

crates/devolutions-pedm/src/db/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub(crate) struct DbAsyncBridgeTask {
271271
}
272272

273273
impl DbAsyncBridgeTask {
274-
pub fn new(db: Db) -> (DbHandle, Self) {
274+
pub(crate) fn new(db: Db) -> (DbHandle, Self) {
275275
let (tx, rx) = tokio::sync::mpsc::channel(8);
276276
(DbHandle { tx }, Self { db, rx })
277277
}

crates/devolutions-pedm/src/log.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) struct JitElevationLogQueryOptions {
1818
pub sort_descending: bool,
1919
}
2020

21-
#[derive(Serialize, JsonSchema)]
21+
#[derive(Serialize, JsonSchema, Default)]
2222
#[serde(rename_all = "PascalCase")]
2323
pub(crate) struct JitElevationLogRow {
2424
pub id: i64,
@@ -33,23 +33,6 @@ pub(crate) struct JitElevationLogRow {
3333
pub user: Option<User>,
3434
}
3535

36-
impl Default for JitElevationLogRow {
37-
fn default() -> JitElevationLogRow {
38-
JitElevationLogRow {
39-
id: 0,
40-
timestamp: 0,
41-
success: 0,
42-
asker_path: None,
43-
target_path: None,
44-
target_command_line: None,
45-
target_working_directory: None,
46-
target_hash: None,
47-
target_signature: None,
48-
user: None,
49-
}
50-
}
51-
}
52-
5336
#[derive(Serialize, JsonSchema)]
5437
#[serde(rename_all = "PascalCase")]
5538
pub(crate) struct JitElevationLogPage {

crates/devolutions-pedm/src/policy.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,8 @@ impl Policy {
333333
.user_current_profile(&request.asker.user)
334334
.ok_or_else(|| anyhow!(Error::AccessDenied))?;
335335

336-
if profile.target_must_be_signed {
337-
if request.target.signature.status != AuthenticodeSignatureStatus::Valid {
338-
bail!(Error::AccessDenied)
339-
}
336+
if profile.target_must_be_signed && request.target.signature.status != AuthenticodeSignatureStatus::Valid {
337+
bail!(Error::AccessDenied)
340338
}
341339

342340
let elevation_type = profile.default_elevation_kind;
@@ -442,25 +440,23 @@ pub(crate) fn application_from_process(pid: u32) -> anyhow::Result<Application>
442440

443441
pub(crate) fn authenticode_win_to_policy(
444442
win_status: win_api_wrappers::security::crypt::AuthenticodeSignatureStatus,
445-
) -> policy::AuthenticodeSignatureStatus {
443+
) -> AuthenticodeSignatureStatus {
446444
match win_status {
447-
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::Valid => {
448-
policy::AuthenticodeSignatureStatus::Valid
449-
}
445+
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::Valid => AuthenticodeSignatureStatus::Valid,
450446
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::Incompatible => {
451-
policy::AuthenticodeSignatureStatus::Incompatible
447+
AuthenticodeSignatureStatus::Incompatible
452448
}
453449
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::NotSigned => {
454-
policy::AuthenticodeSignatureStatus::NotSigned
450+
AuthenticodeSignatureStatus::NotSigned
455451
}
456452
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::HashMismatch => {
457-
policy::AuthenticodeSignatureStatus::HashMismatch
453+
AuthenticodeSignatureStatus::HashMismatch
458454
}
459455
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::NotSupportedFileFormat => {
460-
policy::AuthenticodeSignatureStatus::NotSupportedFileFormat
456+
AuthenticodeSignatureStatus::NotSupportedFileFormat
461457
}
462458
win_api_wrappers::security::crypt::AuthenticodeSignatureStatus::NotTrusted => {
463-
policy::AuthenticodeSignatureStatus::NotTrusted
459+
AuthenticodeSignatureStatus::NotTrusted
464460
}
465461
}
466462
}

0 commit comments

Comments
 (0)