sss_semanage.c revision 42ec8af02ecf1937e4db9b1ecc6216022634f0f9
/*
SSSD
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2010
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_SEMANAGE
#include <semanage/semanage.h>
#endif
#ifndef DEFAULT_SERANGE
#define DEFAULT_SERANGE "s0"
#endif
#ifdef HAVE_SEMANAGE
/* turn libselinux messages into SSSD DEBUG() calls */
static void sss_semanage_error_callback(void *varg,
const char *fmt, ...)
{
int level = SSSDBG_INVALID;
int ret;
switch (semanage_msg_get_level(handle)) {
case SEMANAGE_MSG_ERR:
break;
case SEMANAGE_MSG_WARN:
break;
case SEMANAGE_MSG_INFO:
break;
}
if (ret < 0) {
/* ENOMEM */
return;
}
if (DEBUG_IS_SET(level))
}
static semanage_handle_t *sss_semanage_init(void)
{
int ret;
if (!handle) {
return NULL;
}
NULL);
if (ret != 1) {
goto fail;
}
if (ret < SEMANAGE_CAN_READ) {
goto fail;
}
if (ret != 0) {
"Cannot estabilish SELinux management connection\n");
goto fail;
}
if (ret != 0) {
goto fail;
}
return handle;
fail:
return NULL;
}
const char *login_name,
const char *seuser_name)
{
int ret;
if (ret != 0) {
"Cannot create SELinux login mapping for %s\n", login_name);
goto done;
}
if (ret != 0) {
goto done;
}
if (ret != 0) {
"Could not set serange for %s\n", login_name);
goto done;
}
if (ret != 0) {
"Could not set SELinux user for %s\n", login_name);
goto done;
}
if (ret != 0) {
"Could not add login mapping for %s\n", login_name);
goto done;
}
done:
return ret;
}
const char *login_name,
const char *seuser_name)
{
int ret;
"Could not query seuser for %s\n", login_name);
goto done;
}
if (ret != 0) {
"Could not set serange for %s\n", login_name);
goto done;
}
if (ret != 0) {
goto done;
}
if (ret != 0) {
("Could not modify login mapping for %s\n"), login_name);
goto done;
}
done:
return ret;
}
{
int ret;
int seuser_exists = 0;
if (seuser_name == NULL) {
/* don't care, just let system pick the defaults */
return EOK;
}
handle = sss_semanage_init();
if (!handle) {
goto done;
}
if (ret != 0) {
goto done;
}
if (ret < 0) {
goto done;
}
if (seuser_exists) {
if (ret != 0) {
goto done;
}
} else {
if (ret != 0) {
goto done;
}
}
if (ret < 0) {
goto done;
}
done:
return ret;
}
int del_seuser(const char *login_name)
{
int ret;
int exists = 0;
handle = sss_semanage_init();
if (!handle) {
goto done;
}
if (ret != 0) {
goto done;
}
if (ret < 0) {
goto done;
}
if (!exists) {
"Login mapping for %s is not defined, OK if default mapping "
"was used\n", login_name);
goto done;
}
if (ret < 0) {
goto done;
}
if (!exists) {
"cannot be deleted", login_name);
goto done;
}
if (ret != 0) {
"Could not delete login mapping for %s", login_name);
goto done;
}
if (ret < 0) {
goto done;
}
done:
return ret;
}
#else /* HAVE_SEMANAGE */
{
return EOK;
}
int del_seuser(const char *login_name)
{
return EOK;
}
#endif /* HAVE_SEMANAGE */