aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-12-23 23:54:53 -0800
committerTrumeet <yuuta@yuuta.moe>2022-12-23 23:54:53 -0800
commit53360dc1458f6b56bf6e939f1a8dc1645a3a141b (patch)
treee2e8945434c904b84a0d944959a02c37a83fb78c
parent213ef024f69c2509a774540d5a3e2d5a28c47dac (diff)
downloadsecdesk-53360dc1458f6b56bf6e939f1a8dc1645a3a141b.tar
secdesk-53360dc1458f6b56bf6e939f1a8dc1645a3a141b.tar.gz
secdesk-53360dc1458f6b56bf6e939f1a8dc1645a3a141b.tar.bz2
secdesk-53360dc1458f6b56bf6e939f1a8dc1645a3a141b.zip
Add a naive remote detection
-rw-r--r--README.md3
-rw-r--r--main.c33
2 files changed, 23 insertions, 13 deletions
diff --git a/README.md b/README.md
index dec9818..575d2e8 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,8 @@ terminal is insecure, which is what Windows RDP does regarding remote UAC consen
mkdir build
cd build
cmake ..
-sudo ./secdesktop password test # mode prompt
+chown root ./secdesk && chmod 4755 ./secdesk
+./secdesktop password test # mode prompt
```
The code is ugly: it is written in 4 hours. I will try to make it pretty.
diff --git a/main.c b/main.c
index a05f0a1..0d3a52e 100644
--- a/main.c
+++ b/main.c
@@ -5,6 +5,7 @@
#include <string.h>
#include <signal.h>
#include <errno.h>
+#include <stdlib.h>
#include <sys/wait.h>
struct auth_env a_env;
@@ -70,21 +71,29 @@ int main(int argc, char **argv) {
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
- int r = sd_setup();
- if (r == -1) {
- sd_cleanup();
- return 13;
- }
- if (r) {
- sd_cleanup();
+ int r;
+ /* Very naive way to determine console and remote sessions.
+ * Better to use PAM_RHOST, ConsoleKit, or systemd-logind. */
+ if (getenv("SSH_CONNECTION")) {
r = main_consent(0);
} else {
- dprintf(p_env.err, "Complete authorization on TTY %d by running `chvt %d`.\n",
- p_env.vt,
- p_env.vt);
- r = main_consent(1);
- sd_cleanup();
+ r = sd_setup();
+ if (r == -1) {
+ sd_cleanup();
+ return 13;
+ }
+ if (r) {
+ sd_cleanup();
+ r = main_consent(0);
+ } else {
+ dprintf(p_env.err, "Complete authorization on TTY %d by running `chvt %d`.\n",
+ p_env.vt,
+ p_env.vt);
+ r = main_consent(1);
+ sd_cleanup();
+ }
}
+
return r;
}
if (chld == -1) {