1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
+ #[ cfg( windows) ]
4
5
use authenticode:: check_authenticode;
5
- use std:: { path:: Path , sync:: LazyLock } ;
6
+ use std:: path:: Path ;
7
+ #[ cfg( windows) ]
8
+ use std:: sync:: LazyLock ;
6
9
7
10
use crate :: dscerror:: DscError ;
8
11
9
12
#[ cfg( windows) ]
10
13
mod authenticode;
11
14
15
+ #[ cfg( windows) ]
12
16
static CHECKED_FILES : LazyLock < std:: sync:: Mutex < Vec < String > > > = LazyLock :: new ( || std:: sync:: Mutex :: new ( vec ! [ ] ) ) ;
13
17
18
+ #[ cfg( windows) ]
14
19
fn add_file_as_checked ( file_path : & Path ) {
15
20
let file_str = file_path. to_string_lossy ( ) . to_string ( ) ;
16
21
let mut checked_files = CHECKED_FILES . lock ( ) . unwrap ( ) ;
@@ -19,6 +24,7 @@ fn add_file_as_checked(file_path: &Path) {
19
24
}
20
25
}
21
26
27
+ #[ cfg( windows) ]
22
28
fn is_file_checked ( file_path : & Path ) -> bool {
23
29
let file_str = file_path. to_string_lossy ( ) . to_string ( ) ;
24
30
let checked_files = CHECKED_FILES . lock ( ) . unwrap ( ) ;
@@ -28,26 +34,25 @@ fn is_file_checked(file_path: &Path) -> bool {
28
34
/// Check the security of a file.
29
35
///
30
36
/// # Arguments
31
- ///
37
+ ///
32
38
/// * `file_path` - The path to the file to check.
33
- ///
39
+ ///
34
40
/// # Returns
35
- ///
41
+ ///
36
42
/// * `Ok(())` if the file passes the security checks.
37
43
/// * `Err(DscError)` if the file fails the security checks.
38
- ///
44
+ ///
39
45
/// # Errors
40
- ///
46
+ ///
41
47
/// This function will return an error if the Authenticode check fails on Windows.
48
+ #[ cfg( windows) ]
42
49
pub fn check_file_security ( file_path : & Path ) -> Result < ( ) , DscError > {
43
- #[ cfg( windows) ]
44
- {
45
- check_authenticode ( file_path) ?;
46
- Ok ( ( ) )
47
- }
48
- #[ cfg( not( windows) ) ]
49
- {
50
- // On non-Windows platforms, we skip the Authenticode check.
51
- Ok ( ( ) )
52
- }
50
+ check_authenticode ( file_path) ?;
51
+ Ok ( ( ) )
52
+ }
53
+
54
+ /// On non-Windows platforms, this function is a no-op.
55
+ #[ cfg( not( windows) ) ]
56
+ pub fn check_file_security ( _file_path : & Path ) -> Result < ( ) , DscError > {
57
+ Ok ( ( ) )
53
58
}
0 commit comments