z-auth/z-auth-wrapper.c
2026-01-20 21:14:47 +02:00

27 lines
766 B
C

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char *argv[]) {
/*
FIX: Bash drops privileges if Real UID != Effective UID.
We are running setuid root (EUID=0), but Real UID is the user.
We must promote ourselves to full root (Real UID = E-UID = 0)
so Bash treats us as root and allows reading the 0700 script.
*/
if (setuid(0) != 0) {
perror("Failed to setuid(0)");
return 1;
}
char *script_path = "/usr/lib/z-auth/core.sh";
char *new_argv[] = { "/bin/bash", script_path, NULL };
extern char **environ;
execve("/bin/bash", new_argv, environ);
perror("Failed to exec z-auth core script");
return 1;
}