mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
server: add drop_permissions() (issue #5)
This commit is contained in:
parent
aab7b71520
commit
f459fed4a8
1 changed files with 27 additions and 0 deletions
27
src/server.c
27
src/server.c
|
|
@ -9,6 +9,7 @@
|
|||
#include <wlr/types/wlr_gamma_control_v1.h>
|
||||
#include <wlr/types/wlr_primary_selection_v1.h>
|
||||
#include <wlr/types/wlr_screencopy_v1.h>
|
||||
#include "common/log.h"
|
||||
#include "layers.h"
|
||||
|
||||
static struct wlr_compositor *compositor;
|
||||
|
|
@ -35,6 +36,22 @@ handle_signal(int signal, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drop_permissions(void)
|
||||
{
|
||||
if (getuid() != geteuid() || getgid() != getegid()) {
|
||||
if (setgid(getgid())) {
|
||||
die("unable to drop root group");
|
||||
}
|
||||
if (setuid(getuid())) {
|
||||
die("unable to drop root user");
|
||||
}
|
||||
}
|
||||
if (setgid(0) != -1 || setuid(0) != -1) {
|
||||
die("unable to drop root");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
server_init(struct server *server)
|
||||
{
|
||||
|
|
@ -62,6 +79,16 @@ server_init(struct server *server)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* The wlroots library makes use of systemd's logind to handle sessions
|
||||
* and to allow compositors to run without elevated privileges.
|
||||
* If running without logind or elogind, users may choose to set the
|
||||
* setuid bit on the labwc executable despite associated security
|
||||
* implications. In order to support this, but limit the elevated
|
||||
* privileges as much as possible, we drop permissions at this point.
|
||||
*/
|
||||
drop_permissions();
|
||||
|
||||
/*
|
||||
* If we don't provide a renderer, autocreate makes a GLES2 renderer
|
||||
* for us. The renderer is responsible for defining the various pixel
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue