seatd-launch: Set socket permissions directly
Instead of relying on seatd's user/group arguments, which require turning our UID back into a username, just chmod/chown the socket ourselves once seatd is ready. We also reduce the permissions to just user access, instead of user and group like seatd specifies.
This commit is contained in:
parent
60c370d4ec
commit
17cdbe0ad2
1 changed files with 26 additions and 20 deletions
|
@ -1,13 +1,12 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -66,29 +65,13 @@ int main(int argc, char *argv[]) {
|
||||||
char pipebuf[8];
|
char pipebuf[8];
|
||||||
sprintf(pipebuf, "%d", fds[1]);
|
sprintf(pipebuf, "%d", fds[1]);
|
||||||
|
|
||||||
struct passwd *user = getpwuid(getuid());
|
execlp("seatd", "seatd", "-n", pipebuf, "-s", sockpath, NULL);
|
||||||
if (!user) {
|
|
||||||
perror("getpwuid failed");
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Make seatd accept the numeric UID
|
|
||||||
execlp("seatd", "seatd", "-n", pipebuf, "-u", user->pw_name, "-s", sockpath, NULL);
|
|
||||||
perror("Could not start seatd");
|
perror("Could not start seatd");
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
|
|
||||||
// Drop privileges
|
// Wait for seatd to be ready
|
||||||
if (setgid(getgid()) == -1) {
|
|
||||||
perror("Could not set gid to drop privileges");
|
|
||||||
goto error_seatd;
|
|
||||||
}
|
|
||||||
if (setuid(getuid()) == -1) {
|
|
||||||
perror("Could not set uid to drop privileges");
|
|
||||||
goto error_seatd;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[1] = {0};
|
char buf[1] = {0};
|
||||||
while (true) {
|
while (true) {
|
||||||
pid_t p = waitpid(seatd_child, NULL, WNOHANG);
|
pid_t p = waitpid(seatd_child, NULL, WNOHANG);
|
||||||
|
@ -127,6 +110,29 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
|
|
||||||
|
uid_t uid = getuid();
|
||||||
|
gid_t gid = getgid();
|
||||||
|
|
||||||
|
// Restrict access to the socket to just us
|
||||||
|
if (chown(sockpath, uid, gid) == -1) {
|
||||||
|
perror("Could not chown seatd socket");
|
||||||
|
goto error_seatd;
|
||||||
|
}
|
||||||
|
if (chmod(sockpath, 0700) == -1) {
|
||||||
|
perror("Could not chmod socket");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop privileges
|
||||||
|
if (setgid(gid) == -1) {
|
||||||
|
perror("Could not set gid to drop privileges");
|
||||||
|
goto error_seatd;
|
||||||
|
}
|
||||||
|
if (setuid(uid) == -1) {
|
||||||
|
perror("Could not set uid to drop privileges");
|
||||||
|
goto error_seatd;
|
||||||
|
}
|
||||||
|
|
||||||
pid_t child = fork();
|
pid_t child = fork();
|
||||||
if (child == -1) {
|
if (child == -1) {
|
||||||
perror("Could not fork target process");
|
perror("Could not fork target process");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue