]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - common/privileges.c
Load all users only when really needed
[sojka/lightdm.git] / common / privileges.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  * 
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 /* for setres*id() */
13 #define _GNU_SOURCE
14
15 #include <config.h>
16 #include <glib.h>
17 #include <unistd.h>
18 #include "privileges.h"
19
20 void
21 privileges_drop (uid_t uid, gid_t gid)
22 {
23 #ifdef HAVE_SETRESGID
24     g_assert (setresgid (gid, gid, -1) == 0);
25 #else
26     g_assert (setgid (gid) == 0);
27     g_assert (setegid (gid) == 0);
28 #endif
29 #ifdef HAVE_SETRESUID
30     g_assert (setresuid (uid, uid, -1) == 0);
31 #else
32     g_assert (setuid (uid) == 0);
33     g_assert (seteuid (uid) == 0);
34 #endif
35 }
36
37 void
38 privileges_reclaim (void)
39 {
40 #ifdef HAVE_SETRESUID
41     g_assert (setresuid (0, 0, -1) == 0);
42 #else
43     g_assert (setuid (0) == 0);
44     g_assert (seteuid (0) == 0);
45 #endif
46 #ifdef HAVE_SETRESGID
47     g_assert (setresgid (0, 0, -1) == 0);
48 #else
49     g_assert (setgid (0) == 0);
50     g_assert (setegid (0) == 0);
51 #endif
52 }