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