summaryrefslogtreecommitdiff
path: root/shadow.c
diff options
context:
space:
mode:
authorConnor E <38229097+c-edw@users.noreply.github.com>2019-01-18 13:52:17 +0000
committerConnor E <38229097+c-edw@users.noreply.github.com>2019-01-18 13:52:17 +0000
commit648b0ccd64c45f6a37c8b6c49a39416a78230a2f (patch)
treedb73cef3b6fcf820a17b5eaa9129b29e2e80526e /shadow.c
parentccefa54bb7d00f1ea923f283434b6af86e27708d (diff)
Make setuid error clearer.
Diffstat (limited to 'shadow.c')
-rw-r--r--shadow.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/shadow.c b/shadow.c
index f98301e..70d00a8 100644
--- a/shadow.c
+++ b/shadow.c
@@ -12,6 +12,32 @@
#include "log.h"
#include "swaylock.h"
+void initialize_pw_backend(int argc, char **argv) {
+ if (geteuid() != 0) {
+ swaylock_log(LOG_ERROR,
+ "swaylock needs to be setuid to read /etc/shadow");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!spawn_comm_child()) {
+ exit(EXIT_FAILURE);
+ }
+
+ if (setgid(getgid()) != 0) {
+ swaylock_log_errno(LOG_ERROR, "Unable to drop root");
+ exit(EXIT_FAILURE);
+ }
+ if (setuid(getuid()) != 0) {
+ swaylock_log_errno(LOG_ERROR, "Unable to drop root");
+ exit(EXIT_FAILURE);
+ }
+ if (setuid(0) != -1) {
+ swaylock_log_errno(LOG_ERROR, "Unable to drop root (we shouldn't be "
+ "able to restore it after setuid)");
+ exit(EXIT_FAILURE);
+ }
+}
+
void run_pw_backend_child(void) {
/* This code runs as root */
struct passwd *pwent = getpwuid(getuid());
@@ -72,30 +98,4 @@ void run_pw_backend_child(void) {
clear_buffer(encpw, strlen(encpw));
exit(EXIT_SUCCESS);
-}
-
-void initialize_pw_backend(void) {
- if (geteuid() != 0) {
- swaylock_log(LOG_ERROR,
- "swaylock needs to be setuid to read /etc/shadow");
- exit(EXIT_FAILURE);
- }
-
- if (!spawn_comm_child()) {
- exit(EXIT_FAILURE);
- }
-
- if (setgid(getgid()) != 0) {
- swaylock_log_errno(LOG_ERROR, "Unable to drop root");
- exit(EXIT_FAILURE);
- }
- if (setuid(getuid()) != 0) {
- swaylock_log_errno(LOG_ERROR, "Unable to drop root");
- exit(EXIT_FAILURE);
- }
- if (setuid(0) != -1) {
- swaylock_log_errno(LOG_ERROR, "Unable to drop root (we shouldn't be "
- "able to restore it after setuid)");
- exit(EXIT_FAILURE);
- }
-}
+} \ No newline at end of file