Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute commands using a pseudoterminal #235

Merged
merged 11 commits into from
May 9, 2023
Merged

Execute commands using a pseudoterminal #235

merged 11 commits into from
May 9, 2023

Conversation

pvdrz
Copy link
Collaborator

@pvdrz pvdrz commented Apr 21, 2023

This replaces the old behavior based around exec_nopty and uses exec_pty instead. The rough logic described in man sudo is implemented but some details are missing:

  1. Allocate a new pseudoterminal
  2. Create a monitor process
  3. Create a new terminal session with the monitor as the leader and the follower end of the pseudoterminal as the controlling terminal.
  4. Spawn the command from the monitor.
  5. Relay signals between sudo and the monitor and between the monitor and the command.
  6. Propagate the exit status of the command to sudo.

@codecov
Copy link

codecov bot commented Apr 21, 2023

Codecov Report

Patch coverage: 4.05% and project coverage change: -2.55 ⚠️

Comparison is base (da23204) 77.37% compared to head (f7088ef) 74.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #235      +/-   ##
==========================================
- Coverage   77.37%   74.83%   -2.55%     
==========================================
  Files          38       40       +2     
  Lines        4738     4903     +165     
==========================================
+ Hits         3666     3669       +3     
- Misses       1072     1234     +162     
Impacted Files Coverage Δ
lib/sudo-exec/src/lib.rs 1.25% <0.00%> (+0.13%) ⬆️
lib/sudo-exec/src/monitor.rs 0.00% <0.00%> (ø)
lib/sudo-exec/src/pty.rs 0.00% <0.00%> (ø)
sudo/src/main.rs 1.13% <0.00%> (+0.04%) ⬆️
lib/sudo-system/src/lib.rs 71.32% <20.45%> (-6.37%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pvdrz pvdrz force-pushed the exec-pty branch 2 times, most recently from 6566386 to 29495ca Compare April 25, 2023 20:34
@pvdrz pvdrz marked this pull request as ready for review April 25, 2023 20:46
@hartwork hartwork mentioned this pull request Apr 27, 2023
@pvdrz pvdrz linked an issue Apr 27, 2023 that may be closed by this pull request
@squell squell linked an issue May 5, 2023 that may be closed by this pull request
pvdrz and others added 10 commits May 5, 2023 12:24
This replaces the old behavior based around `exec_nopty` and uses
`exec_pty` instead. The rough logic described in `man sudo` is
implemented but some details are missing:

1. Allocate a new pseudoterminal
2. Create a monitor process
3. Create a new terminal session with the monitor as the leader and the
   follower end of the pseudoterminal as the controlling terminal.
4. Spawn the command from the monitor.
5. Relay signals between sudo and the monitor and between the monitor
   and the command.
6. Propagate the exit status of the command to sudo.
(the 'wait' calls are guaranteed to exit when we get SIGCHLD)
@github-actions
Copy link

github-actions bot commented May 5, 2023

Number of dependencies and binary size impact report

Metric main PR #235 Delta
Direct dependencies 8 8 -
Total dependencies 135 134 -0.7%
Binary size 2.4 MiB 2.2 MiB -4.8%
Text size 1.1 MiB 1.1 MiB -5.7%
Dependencies diff
 └─ sudo [v0.1.0-alpha.1]
    ├─ sudo-cli [v0.1.0-alpha.1]
 
-    |  └─ clap [v4.2.7]
-    |     ├─ clap_builder [v4.2.7]
-    |     |  ├─ anstream [v0.3.2]
-    |     |  |  ├─ anstyle [v1.0.0]
-    |     |  |  ├─ anstyle-parse [v0.2.0]
-    |     |  |  |  └─ utf8parse [v0.2.1]
-    |     |  |  ├─ anstyle-query [v1.0.0]
-    |     |  |  ├─ colorchoice [v1.0.0]
-    |     |  |  ├─ is-terminal [v0.4.7]
-    |     |  |  |  ├─ io-lifetimes [v1.0.10]
-    |     |  |  |  |  └─ libc [v0.2.144]
-    |     |  |  |  └─ rustix [v0.37.19]
-    |     |  |  |     ├─ bitflags [v1.3.2]
-    |     |  |  |     ├─ io-lifetimes [v1.0.10]
-    |     |  |  |     ├─ libc [v0.2.144]
-    |     |  |  |     └─ linux-raw-sys [v0.3.7]
-    |     |  |  └─ utf8parse [v0.2.1]
-    |     |  ├─ anstyle [v1.0.0]
- 
+    |  └─ clap [v4.1.14]
+    |     ├─ clap_builder [v4.1.14]
+ 
    |     |  ├─ bitflags [v1.3.2]
 
-    |     |  ├─ clap_lex [v0.4.1]
- 
+    |     |  ├─ clap_lex [v0.4.0]
+    |     |  ├─ is-terminal [v0.4.5]
+    |     |  |  ├─ io-lifetimes [v1.0.9]
+    |     |  |  |  └─ libc [v0.2.140]
+    |     |  |  └─ rustix [v0.36.11]
+    |     |  |     ├─ bitflags [v1.3.2]
+    |     |  |     ├─ io-lifetimes [v1.0.9]
+    |     |  |     ├─ libc [v0.2.140]
+    |     |  |     └─ linux-raw-sys [v0.1.4]
+ 
    |     |  ├─ once_cell [v1.17.1]
 
-    |     |  └─ strsim [v0.10.0]
-    |     ├─ clap_derive [v4.2.0]
- 
+    |     |  ├─ strsim [v0.10.0]
+    |     |  └─ termcolor [v1.2.0]
+    |     ├─ clap_derive [v4.1.14]
+ 
    |     |  ├─ heck [v0.4.1]
 
-    |     |  ├─ proc-macro2 [v1.0.56]
- 
+    |     |  ├─ proc-macro2 [v1.0.54]
+ 
    |     |  |  └─ unicode-ident [v1.0.8]
 
-    |     |  ├─ quote [v1.0.27]
-    |     |  |  └─ proc-macro2 [v1.0.56]
-    |     |  └─ syn [v2.0.15]
-    |     |     ├─ proc-macro2 [v1.0.56]
-    |     |     ├─ quote [v1.0.27]
- 
+    |     |  ├─ quote [v1.0.26]
+    |     |  |  └─ proc-macro2 [v1.0.54]
+    |     |  └─ syn [v2.0.11]
+    |     |     ├─ proc-macro2 [v1.0.54]
+    |     |     ├─ quote [v1.0.26]
+ 
    |     |     └─ unicode-ident [v1.0.8]
    |     └─ once_cell [v1.17.1]
    ├─ sudo-common [v0.1.0-alpha.1]
 
-    |  ├─ libc [v0.2.144]
- 
+    |  ├─ libc [v0.2.140]
+ 
    |  ├─ sudo-cli [v0.1.0-alpha.1]
    |  ├─ sudo-pam [v0.1.0-alpha.1]
 
-    |  |  ├─ libc [v0.2.144]
- 
+    |  |  ├─ libc [v0.2.140]
+ 
    |  |  ├─ sudo-cutils [v0.1.0-alpha.1]
 
-    |  |  |  └─ libc [v0.2.144]
-    |  |  └─ sudo-pam-sys [v0.1.0-alpha.1]
-    |  |     ├─ libc [v0.2.144]
-    |  |     └─ bindgen [v0.63.0]
-    |  |        ├─ bitflags [v1.3.2]
-    |  |        ├─ cexpr [v0.6.0]
-    |  |        |  └─ nom [v7.1.3]
-    |  |        |     ├─ memchr [v2.5.0]
-    |  |        |     └─ minimal-lexical [v0.2.1]
-    |  |        ├─ clang-sys [v1.6.1]
-    |  |        |  ├─ glob [v0.3.1]
-    |  |        |  ├─ libc [v0.2.144]
-    |  |        |  ├─ libloading [v0.7.4]
-    |  |        |  |  └─ cfg-if [v1.0.0]
-    |  |        |  └─ glob [v0.3.1]
-    |  |        ├─ lazy_static [v1.4.0]
-    |  |        ├─ lazycell [v1.3.0]
- 
+    |  |  |  └─ libc [v0.2.140]
+    |  |  ├─ sudo-pam-sys [v0.1.0-alpha.1]
+    |  |  |  ├─ libc [v0.2.140]
+    |  |  |  └─ bindgen [v0.63.0]
+    |  |  |     ├─ bitflags [v1.3.2]
+    |  |  |     ├─ cexpr [v0.6.0]
+    |  |  |     |  └─ nom [v7.1.3]
+    |  |  |     |     ├─ memchr [v2.5.0]
+    |  |  |     |     └─ minimal-lexical [v0.2.1]
+    |  |  |     ├─ clang-sys [v1.6.0]
+    |  |  |     |  ├─ glob [v0.3.1]
+    |  |  |     |  ├─ libc [v0.2.140]
+    |  |  |     |  ├─ libloading [v0.7.4]
+    |  |  |     |  |  └─ cfg-if [v1.0.0]
+    |  |  |     |  └─ glob [v0.3.1]
+    |  |  |     ├─ lazy_static [v1.4.0]
+    |  |  |     ├─ lazycell [v1.3.0]
+    |  |  |     ├─ log [v0.4.17]
+    |  |  |     |  └─ cfg-if [v1.0.0]
+    |  |  |     ├─ peeking_take_while [v0.1.2]
+    |  |  |     ├─ proc-macro2 [v1.0.54]
+    |  |  |     ├─ quote [v1.0.26]
+    |  |  |     ├─ regex [v1.7.3]
+    |  |  |     |  ├─ aho-corasick [v0.7.20]
+    |  |  |     |  |  └─ memchr [v2.5.0]
+    |  |  |     |  ├─ memchr [v2.5.0]
+    |  |  |     |  └─ regex-syntax [v0.6.29]
+    |  |  |     ├─ rustc-hash [v1.1.0]
+    |  |  |     ├─ shlex [v1.1.0]
+    |  |  |     ├─ syn [v1.0.109]
+    |  |  |     |  ├─ proc-macro2 [v1.0.54]
+    |  |  |     |  ├─ quote [v1.0.26]
+    |  |  |     |  └─ unicode-ident [v1.0.8]
+    |  |  |     └─ which [v4.4.0]
+    |  |  |        ├─ either [v1.8.1]
+    |  |  |        └─ libc [v0.2.140]
+    |  |  └─ thiserror [v1.0.40]
+    |  |     └─ thiserror-impl [v1.0.40]
+    |  |        ├─ proc-macro2 [v1.0.54]
+    |  |        ├─ quote [v1.0.26]
+    |  |        └─ syn [v2.0.11]
+    |  ├─ sudo-system [v0.1.0-alpha.1]
+    |  |  ├─ libc [v0.2.140]
+    |  |  ├─ sudo-cutils [v0.1.0-alpha.1]
+    |  |  └─ sudo-log [v0.1.0-alpha.1]
+    |  |     ├─ env_logger [v0.9.3]
+    |  |     |  ├─ atty [v0.2.14]
+    |  |     |  |  └─ libc [v0.2.140]
+    |  |     |  ├─ humantime [v2.1.0]
+    |  |     |  ├─ log [v0.4.17]
+    |  |     |  ├─ regex [v1.7.3]
+    |  |     |  └─ termcolor [v1.2.0]
+    |  |     ├─ log [v0.4.17]
+    |  |     └─ syslog [v6.0.1]
+    |  |        ├─ error-chain [v0.12.4]
+    |  |        |  └─ version_check [v0.9.4]
+    |  |        ├─ hostname [v0.3.1]
+    |  |        |  ├─ libc [v0.2.140]
+    |  |        |  └─ match_cfg [v0.1.0]
+    |  |        ├─ libc [v0.2.140]
+ 
    |  |        ├─ log [v0.4.17]
 
-    |  |        |  └─ cfg-if [v1.0.0]
-    |  |        ├─ peeking_take_while [v0.1.2]
-    |  |        ├─ proc-macro2 [v1.0.56]
-    |  |        ├─ quote [v1.0.27]
-    |  |        ├─ regex [v1.8.1]
-    |  |        |  ├─ aho-corasick [v1.0.1]
-    |  |        |  |  └─ memchr [v2.5.0]
-    |  |        |  ├─ memchr [v2.5.0]
-    |  |        |  └─ regex-syntax [v0.7.1]
-    |  |        ├─ rustc-hash [v1.1.0]
-    |  |        ├─ shlex [v1.1.0]
-    |  |        ├─ syn [v1.0.109]
-    |  |        |  ├─ proc-macro2 [v1.0.56]
-    |  |        |  ├─ quote [v1.0.27]
-    |  |        |  └─ unicode-ident [v1.0.8]
-    |  |        └─ which [v4.4.0]
-    |  |           ├─ either [v1.8.1]
-    |  |           └─ libc [v0.2.144]
-    |  └─ sudo-system [v0.1.0-alpha.1]
-    |     ├─ libc [v0.2.144]
-    |     ├─ sudo-cutils [v0.1.0-alpha.1]
-    |     └─ sudo-log [v0.1.0-alpha.1]
-    |        ├─ env_logger [v0.9.3]
-    |        |  ├─ atty [v0.2.14]
-    |        |  |  └─ libc [v0.2.144]
-    |        |  ├─ humantime [v2.1.0]
-    |        |  ├─ log [v0.4.17]
-    |        |  ├─ regex [v1.8.1]
-    |        |  └─ termcolor [v1.2.0]
-    |        ├─ log [v0.4.17]
-    |        └─ syslog [v6.1.0]
-    |           ├─ error-chain [v0.12.4]
-    |           |  └─ version_check [v0.9.4]
-    |           ├─ hostname [v0.3.1]
-    |           |  ├─ libc [v0.2.144]
-    |           |  └─ match_cfg [v0.1.0]
-    |           ├─ libc [v0.2.144]
-    |           ├─ log [v0.4.17]
-    |           └─ time [v0.3.21]
-    |              ├─ itoa [v1.0.6]
-    |              ├─ libc [v0.2.144]
-    |              ├─ num_threads [v0.1.6]
-    |              └─ time-core [v0.1.1]
- 
+    |  |        └─ time [v0.3.20]
+    |  |           ├─ itoa [v1.0.6]
+    |  |           ├─ libc [v0.2.140]
+    |  |           ├─ num_threads [v0.1.6]
+    |  |           └─ time-core [v0.1.0]
+    |  └─ thiserror [v1.0.40]
+ 
    ├─ sudo-env [v0.1.0-alpha.1]
    |  ├─ sudo-common [v0.1.0-alpha.1]
    |  ├─ sudo-system [v0.1.0-alpha.1]
    |  └─ sudoers [v0.1.0-alpha.1]
    |     ├─ digest [v0.10.6]
    |     |  ├─ block-buffer [v0.10.4]
    |     |  |  └─ generic-array [v0.14.7]
    |     |  |     ├─ typenum [v1.16.0]
    |     |  |     └─ version_check [v0.9.4]
    |     |  └─ crypto-common [v0.1.6]
    |     |     ├─ generic-array [v0.14.7]
    |     |     └─ typenum [v1.16.0]
    |     ├─ glob [v0.3.1]
    |     ├─ sha2 [v0.10.6]
    |     |  ├─ cfg-if [v1.0.0]
 
-    |     |  ├─ cpufeatures [v0.2.7]
- 
+    |     |  ├─ cpufeatures [v0.2.6]
+ 
    |     |  └─ digest [v0.10.6]
    |     ├─ sudo-defaults [v0.1.0-alpha.1]
    |     ├─ sudo-log [v0.1.0-alpha.1]
    |     └─ sudo-system [v0.1.0-alpha.1]
    ├─ sudo-exec [v0.1.0-alpha.1]
    |  ├─ signal-hook [v0.3.15]
 
-    |  |  ├─ libc [v0.2.144]
- 
+    |  |  ├─ libc [v0.2.140]
+ 
    |  |  ├─ signal-hook-registry [v1.4.1]
 
-    |  |  |  └─ libc [v0.2.144]
- 
+    |  |  |  └─ libc [v0.2.140]
+ 
    |  |  └─ cc [v1.0.79]
    |  ├─ sudo-common [v0.1.0-alpha.1]
    |  ├─ sudo-log [v0.1.0-alpha.1]
    |  └─ sudo-system [v0.1.0-alpha.1]
    ├─ sudo-log [v0.1.0-alpha.1]
    ├─ sudo-pam [v0.1.0-alpha.1]
    ├─ sudo-system [v0.1.0-alpha.1]
    └─ sudoers [v0.1.0-alpha.1]

@marlonbaeten marlonbaeten added this pull request to the merge queue May 9, 2023
Merged via the queue into main with commit e76a285 May 9, 2023
@japaric japaric deleted the exec-pty branch May 24, 2023 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High CPU load when opening htop with sudo-rs Add use_pty support
3 participants