1
1
use std:: process:: exit;
2
2
3
- use super :: super :: cli:: SudoRunOptions ;
3
+ use super :: super :: cli:: SudoEditOptions ;
4
4
use crate :: common:: { Context , Error } ;
5
5
use crate :: exec:: ExitReason ;
6
- use crate :: sudo:: env:: environment;
7
- use crate :: sudo:: pam:: pre_exec;
8
6
use crate :: sudoers:: Authorization ;
9
7
10
- pub fn run_edit ( mut cmd_opts : SudoRunOptions ) -> Result < ( ) , Error > {
11
- let mut policy = super :: read_sudoers ( ) ?;
8
+ pub fn run_edit ( edit_opts : SudoEditOptions ) -> Result < ( ) , Error > {
9
+ let policy = super :: read_sudoers ( ) ?;
12
10
13
- let user_requested_env_vars = std:: mem:: take ( & mut cmd_opts. env_var_list ) ;
14
-
15
- let mut context = Context :: from_run_opts ( cmd_opts, & mut policy) ?;
11
+ let mut context = Context :: from_edit_opts ( edit_opts) ?;
16
12
17
13
let policy = super :: judge ( policy, & context) ?;
18
14
@@ -23,48 +19,18 @@ pub fn run_edit(mut cmd_opts: SudoRunOptions) -> Result<(), Error> {
23
19
super :: apply_policy_to_context ( & mut context, & controls) ?;
24
20
let mut pam_context = super :: auth_and_update_record_file ( & context, auth) ?;
25
21
26
- // build environment
27
- let additional_env = pre_exec ( & mut pam_context, & context. target_user . name ) ?;
28
-
29
- let current_env = environment:: system_environment ( ) ;
30
- let ( checked_vars, trusted_vars) = if controls. trust_environment {
31
- ( vec ! [ ] , user_requested_env_vars)
32
- } else {
33
- ( user_requested_env_vars, vec ! [ ] )
34
- } ;
35
-
36
- let mut target_env = environment:: get_target_environment (
37
- current_env,
38
- additional_env,
39
- checked_vars,
40
- & context,
41
- & controls,
42
- ) ?;
43
-
44
- environment:: dangerous_extend ( & mut target_env, trusted_vars) ;
45
-
46
22
let pid = context. process . pid ;
47
23
48
- // prepare switch of apparmor profile
49
- #[ cfg( feature = "apparmor" ) ]
50
- if let Some ( profile) = controls. apparmor_profile {
51
- crate :: apparmor:: set_profile_for_next_exec ( & profile)
52
- . map_err ( |err| Error :: AppArmor ( profile, err) ) ?;
53
- }
54
-
55
24
// run command and return corresponding exit code
56
- let command_exit_reason = if context . command . resolved {
25
+ let command_exit_reason = {
57
26
super :: log_command_execution ( & context) ;
58
27
59
- crate :: exec:: run_command (
60
- context
61
- . try_as_run_options ( )
62
- . map_err ( |io_error| Error :: Io ( Some ( context. command . command . clone ( ) ) , io_error) ) ?,
63
- target_env,
64
- )
65
- . map_err ( |io_error| Error :: Io ( Some ( context. command . command ) , io_error) )
66
- } else {
67
- Err ( Error :: CommandNotFound ( context. command . command ) )
28
+ eprintln_ignore_io_error ! (
29
+ "this would launch sudoedit as requested, to edit the files: {:?}" ,
30
+ context. command. arguments. as_slice( )
31
+ ) ;
32
+
33
+ Ok :: < _ , std:: io:: Error > ( ExitReason :: Code ( 42 ) )
68
34
} ;
69
35
70
36
pam_context. close_session ( ) ;
0 commit comments