ipa_access.c revision d8d877a5fcde1defdd1a438df020e087339873a0
/*
SSSD
IPA Backend Module -- Access control
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2009 Red Hat
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 <security/pam_modules.h>
#include "providers/ldap/sdap_async.h"
#include "providers/ipa/ipa_common.h"
#include "providers/ipa/ipa_access.h"
#include "providers/ipa/ipa_timerules.h"
#define IPA_HOST_MEMBEROF "memberOf"
#define IPA_HOST_SERVERHOSTNAME "serverHostName"
#define IPA_HOST_FQDN "fqdn"
#define IPA_ACCESS_RULE_TYPE "accessRuleType"
#define IPA_MEMBER_USER "memberUser"
#define IPA_USER_CATEGORY "userCategory"
#define IPA_SERVICE_NAME "serviceName"
#define IPA_SOURCE_HOST "sourceHost"
#define IPA_SOURCE_HOST_CATEGORY "sourceHostCategory"
#define IPA_EXTERNAL_HOST "externalHost"
#define IPA_ACCESS_TIME "accessTime"
#define IPA_UNIQUE_ID "ipauniqueid"
#define IPA_ENABLED_FLAG "ipaenabledflag"
#define IPA_MEMBER_HOST "memberHost"
#define IPA_HOST_CATEGORY "hostCategory"
#define IPA_CN "cn"
#define IPA_HOST_BASE_TMPL "cn=computers,cn=accounts,%s"
#define IPA_HBAC_BASE_TMPL "cn=hbac,%s"
#define HBAC_RULES_SUBDIR "hbac_rules"
#define HBAC_HOSTS_SUBDIR "hbac_hosts"
struct ldb_message **msgs,
struct sysdb_attrs ***attrs)
{
int i;
struct sysdb_attrs **a;
if (a == NULL) {
return ENOMEM;
}
for (i = 0; i < count; i++) {
a[i] = talloc(a, struct sysdb_attrs);
if (a[i] == NULL) {
talloc_free(a);
return ENOMEM;
}
}
*attrs = a;
return EOK;
}
{
if (pam_status == PAM_SUCCESS) {
} else {
}
}
const char *user,
const char **user_dn,
const char ***_groups)
{
struct ldb_message *user_msg;
const char *user_orig_dn;
struct ldb_message **msgs;
const char **groups;
int ret;
int i;
if (!tmpctx) {
return ENOMEM;
}
goto fail;
}
if (user_orig_dn == NULL) {
goto fail;
}
user_orig_dn, user));
goto fail;
}
if (count == 0) {
goto fail;
}
*groups_count = 0;
return EOK;
}
goto fail;
}
for(i = 0; i < count; i++) {
goto fail;
}
goto fail;
}
goto fail;
}
}
goto fail;
}
*groups_count = count;
return EOK;
fail:
return ret;
}
struct hbac_get_host_info_state {
struct tevent_context *ev;
struct sdap_id_ctx *sdap_ctx;
struct sysdb_handle *handle;
bool offline;
char *host_filter;
char *host_search_base;
const char **host_attrs;
struct sysdb_attrs **host_reply_list;
struct hbac_host_info **hbac_host_info;
};
struct ldb_message **msgs);
struct tevent_context *ev,
bool offline,
struct sdap_id_ctx *sdap_ctx,
const char *basedn,
const char **hostnames)
{
struct hbac_get_host_info_state *state;
int ret;
int i;
return NULL;
}
return NULL;
}
state->host_reply_count = 0;
state->current_item = 0;
goto fail;
}
"(&(objectclass=ipaHost)"
"(|(fqdn=%s)(serverhostname=%s)))",
goto fail;
}
}
goto fail;
}
basedn);
goto fail;
}
goto fail;
}
if (offline) {
struct ldb_message **msgs;
if (ret) {
goto fail;
}
return req;
}
}
if (!subreq) {
goto fail;
}
return req;
}
NULL, 0);
goto fail;
}
return req;
fail:
return req;
}
{
struct tevent_req);
struct hbac_get_host_info_state);
int ret;
NULL);
if (ret) {
return;
}
NULL, 0);
goto fail;
}
return;
fail:
return;
}
{
struct tevent_req);
struct hbac_get_host_info_state);
int ret;
&state->host_reply_list);
return;
}
}
struct ldb_message **msgs)
{
struct hbac_get_host_info_state *state =
bool in_transaction = false;
int ret;
int i;
int v;
struct ldb_message_element *el;
struct hbac_host_info **hhi;
char *object_name;
if (state->host_reply_count == 0) {
goto fail;
}
&state->host_reply_list);
goto fail;
}
}
goto fail;
}
for (i = 0; i < state->host_reply_count; i++) {
goto fail;
}
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
goto fail;
}
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
goto fail;
}
IPA_HOST_FQDN, &el);
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
goto fail;
}
&el);
goto fail;
}
goto fail;
}
for(v = 0; v < el->num_values; v++) {
goto fail;
}
}
}
return;
}
return;
}
in_transaction = true;
for (i = 0; i < state->host_reply_count; i++) {
IPA_HOST_FQDN, &el);
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
if (object_name == NULL) {
goto fail;
}
goto fail;
}
state->host_reply_list[i]);
if (ret) {
goto fail;
}
}
if (ret) {
goto fail;
}
in_transaction = false;
return;
fail:
if (in_transaction) {
}
return;
}
struct hbac_host_info ***hhi)
{
struct hbac_get_host_info_state);
return EOK;
}
struct hbac_get_rules_state {
struct tevent_context *ev;
struct sdap_id_ctx *sdap_ctx;
struct sysdb_handle *handle;
bool offline;
const char *host_dn;
const char **memberof;
char *hbac_filter;
char *hbac_search_base;
const char **hbac_attrs;
struct ldb_message *old_rules;
struct sysdb_attrs **hbac_reply_list;
int current_item;
};
struct ldb_message **msgs);
struct tevent_context *ev,
bool offline,
struct sdap_id_ctx *sdap_ctx,
const char *basedn,
const char *host_dn,
const char **memberof)
{
struct hbac_get_rules_state *state;
int ret;
int i;
return NULL;
}
return NULL;
}
state->hbac_reply_count = 0;
state->current_item = 0;
basedn);
goto fail;
}
goto fail;
}
"(&(objectclass=ipaHBACRule)"
"(|(%s=%s)(%s=%s)",
IPA_HOST_CATEGORY, "all",
goto fail;
}
"(%s=%s)",
memberof[i]);
goto fail;
}
}
goto fail;
}
if (offline) {
struct ldb_message **msgs;
if (ret) {
goto fail;
}
return req;
}
}
if (!subreq) {
goto fail;
}
return req;
}
NULL, 0);
goto fail;
}
return req;
fail:
return req;
}
{
struct tevent_req);
struct hbac_get_rules_state);
int ret;
NULL);
if (ret) {
return;
}
NULL, 0);
goto fail;
}
return;
fail:
return;
}
{
struct tevent_req);
struct hbac_get_rules_state);
int ret;
&state->hbac_reply_list);
return;
}
}
struct ldb_message **msgs)
{
struct hbac_get_rules_state *state =
bool in_transaction = false;
int ret;
int i;
struct ldb_message_element *el;
struct ldb_dn *hbac_base_dn;
char *object_name;
&state->hbac_reply_list);
goto fail;
}
}
for (i = 0; i < state->hbac_reply_count; i++) {
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
}
return;
}
return;
}
in_transaction = true;
if (hbac_base_dn == NULL) {
goto fail;
}
if (ret) {
goto fail;
}
for (i = 0; i < state->hbac_reply_count; i++) {
IPA_UNIQUE_ID, &el);
goto fail;
}
if (el->num_values == 0) {
goto fail;
}
if (object_name == NULL) {
goto fail;
}
state->hbac_reply_list[i]);
if (ret) {
goto fail;
}
}
if (ret) {
goto fail;
}
in_transaction = false;
return;
fail:
if (in_transaction) {
}
return;
}
struct sysdb_attrs ***hbac_rule_list)
{
struct hbac_get_rules_state);
int i;
for (i = 0; i < state->hbac_reply_count; i++) {
}
return EOK;
}
enum hbac_result {
HBAC_ALLOW = 1,
};
enum check_result {
RULE_APPLICABLE = 0,
};
struct sysdb_attrs *rule_attrs)
{
int ret;
int i;
struct ldb_message_element *el;
return RULE_ERROR;
}
return RULE_ERROR;
}
if (el->num_values == 0) {
return RULE_APPLICABLE;
} else {
for (i = 0; i < el->num_values; i++) {
return RULE_APPLICABLE;
}
}
return RULE_NOT_APPLICABLE;
}
return RULE_ERROR;
}
struct sysdb_attrs *rule_attrs)
{
int ret;
int i;
struct ldb_message_element *el;
char *rule;
bool result;
return RULE_ERROR;
}
return RULE_ERROR;
}
if (el->num_values == 0) {
return RULE_APPLICABLE;
} else {
return RULE_ERROR;
}
for (i = 0; i < el->num_values; i++) {
ret = RULE_ERROR;
goto done;
}
if (result) {
goto done;
}
}
}
done:
return ret;
}
struct sysdb_attrs *rule_attrs)
{
int ret;
int i;
int g;
struct ldb_message_element *el;
return RULE_ERROR;
}
return RULE_ERROR;
}
if (el->num_values == 0) {
} else {
for (i = 0; i < el->num_values; i++) {
return RULE_APPLICABLE;
}
}
}
return RULE_ERROR;
}
if (el->num_values == 0) {
return RULE_APPLICABLE;
} else {
for (i = 0; i < el->num_values; i++) {
return RULE_APPLICABLE;
}
for (g = 0; g < hbac_ctx->groups_count; g++) {
return RULE_APPLICABLE;
}
}
}
return RULE_NOT_APPLICABLE;
}
return RULE_ERROR;
}
struct hbac_host_info *hhi,
struct sysdb_attrs *rule_attrs)
{
int ret;
int i;
int m;
struct ldb_message_element *cat_el;
struct ldb_message_element *src_el;
struct ldb_message_element *ext_el;
return RULE_ERROR;
}
return RULE_ERROR;
}
if (cat_el->num_values == 0) {
} else {
for(i = 0; i < cat_el->num_values; i++) {
"rule applies.\n"));
return RULE_APPLICABLE;
}
}
}
return RULE_ERROR;
}
return RULE_ERROR;
}
return RULE_NOT_APPLICABLE;
} else {
for (i = 0; i < src_el->num_values; i++) {
return RULE_APPLICABLE;
}
return RULE_APPLICABLE;
}
}
}
}
for (i = 0; i < ext_el->num_values; i++) {
rhost));
return RULE_APPLICABLE;
}
}
}
return RULE_NOT_APPLICABLE;
}
return RULE_ERROR;
}
struct sysdb_attrs *rule_attrs) {
int ret;
struct ldb_message_element *el;
enum hbac_result rule_type;
char *rule_name;
return ret;
}
if (el->num_values == 0) {
} else {
}
return ENOMEM;
}
/* rule type */
return ret;
}
if (el->num_values == 0) {
} else {
}
} else {
el->num_values));
return EINVAL;
}
if (ret != RULE_APPLICABLE) {
goto not_applicable;
}
if (ret != RULE_APPLICABLE) {
goto not_applicable;
}
if (ret != RULE_APPLICABLE) {
goto not_applicable;
}
if (ret != RULE_APPLICABLE) {
goto not_applicable;
}
return EOK;
if (ret == RULE_NOT_APPLICABLE) {
} else {
}
return EOK;
}
bool *access_allowed)
{
bool allow_matched = false;
enum hbac_result result;
int ret;
int i;
*access_allowed = false;
for (i = 0; i < hbac_ctx->hbac_rule_count ; i++) {
hbac_ctx->hbac_rule_list[i]);
return ret;
}
switch (result) {
case HBAC_DENY:
return EOK;
break;
case HBAC_ALLOW:
allow_matched = true;
break;
default:
}
}
return EOK;
}
{
struct tevent_req *req;
int pam_status = PAM_SYSTEM_ERR;
struct ipa_access_ctx *ipa_access_ctx;
const char *hostlist[3];
int ret;
goto fail;
}
struct ipa_access_ctx);
&hbac_ctx->ldap_basedn);
goto fail;
}
"online"));
goto fail;
}
} else {
goto fail;
}
}
hostlist);
goto fail;
}
return;
fail:
}
{
int ret;
int pam_status = PAM_SYSTEM_ERR;
const char *ipa_hostname;
int i;
goto fail;
}
if (ipa_hostname == NULL) {
goto fail;
}
ipa_hostname) == 0) {
}
}
}
}
goto fail;
}
goto fail;
}
return;
fail:
}
{
int ret;
int pam_status = PAM_SYSTEM_ERR;
bool access_allowed = false;
goto failed;
}
goto failed;
}
goto failed;
}
if (access_allowed) {
} else {
}
}