6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce/*
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce Authors:
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce Simo Sorce <simo@redhat.com>
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce Copyright (C) 2016 Red Hat
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce This program is free software; you can redistribute it and/or modify
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce it under the terms of the GNU General Public License as published by
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce the Free Software Foundation; either version 3 of the License, or
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce (at your option) any later version.
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce This program is distributed in the hope that it will be useful,
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce but WITHOUT ANY WARRANTY; without even the implied warranty of
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce GNU General Public License for more details.
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce You should have received a copy of the GNU General Public License
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce along with this program. If not, see <http://www.gnu.org/licenses/>.
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce*/
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#ifndef __SSSD_UTIL_CREDS_H__
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define __SSSD_UTIL_CREDS_H__
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce/* following code comes from gss-proxy's gp_selinux.h file */
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#ifdef HAVE_SELINUX
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#include <selinux/context.h>
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_CTX context_t
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#include <selinux/selinux.h>
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SEC_CTX security_context_t
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_new context_new
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_free context_free
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_str context_str
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_type_get context_type_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_user_get context_user_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_role_get context_role_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_range_get context_range_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_getpeercon getpeercon
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_freecon freecon
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#else /* not HAVE_SELINUX */
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_CTX void *
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SEC_CTX void *
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_new(x) NULL
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_free(x) (x) = NULL
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_dummy_get(x) "<SELinux not compiled in>"
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_str SELINUX_context_dummy_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_type_get SELINUX_context_dummy_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_user_get SELINUX_context_dummy_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_role_get SELINUX_context_dummy_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_context_range_get SELINUX_context_dummy_get
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#include <errno.h>
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_getpeercon(x, y) -1; do { \
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce *(y) = NULL; \
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce errno = ENOTSUP; \
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce} while(0)
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define SELINUX_freecon(x) (x) = NULL
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#endif /* done HAVE_SELINUX */
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#ifdef HAVE_UCRED
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#include <sys/socket.h>
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorcestruct cli_creds {
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce struct ucred ucred;
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce SELINUX_CTX selinux_ctx;
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce};
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define cli_creds_get_uid(x) x->ucred.uid
4f511a4c5f0084e22ce4c7613f1b279533c68cc5Jakub Hrozek#define cli_creds_get_gid(x) x->ucred.gid
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#else /* not HAVE_UCRED */
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorcestruct cli_creds {
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce SELINUX_CTX selinux_ctx;
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce};
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#define cli_creds_get_uid(x) -1
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#endif /* done HAVE_UCRED */
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce
6499d0b915209b670f8e337c4fe76a8be9fa6576Simo Sorce#endif /* __SSSD_UTIL_CREDS_H__ */