ipa_subdomains.c revision 096a9678919fae460342469989b97fd47d812823
/*
SSSD
IPA Subdomains Module
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2011 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 "providers/ldap/sdap_async.h"
#include "providers/ldap/sdap_idmap.h"
#include "providers/ipa/ipa_subdomains.h"
#include "providers/ipa/ipa_common.h"
#include <ctype.h>
#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
#define RANGE_FILTER "objectclass=ipaIDRange"
#define IPA_CN "cn"
#define IPA_FLATNAME "ipaNTFlatName"
#define IPA_SID "ipaNTSecurityIdentifier"
#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
#define IPA_RANGE_TYPE "ipaRangeType"
#define IPA_BASE_ID "ipaBaseID"
#define IPA_ID_RANGE_SIZE "ipaIDRangeSize"
#define IPA_BASE_RID "ipaBaseRID"
#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
#define OBJECTCLASS "objectClass"
/* do not refresh more often than every 5 seconds for now */
#define IPA_SUBDOMAIN_REFRESH_LIMIT 5
#define IPA_SUBDOMAIN_DISABLED_PERIOD 3600
enum ipa_subdomains_req_type {
IPA_SUBDOMAINS_MAX /* Counter */
};
struct ipa_subdomains_req_params {
const char *filter;
const char *attrs[9];
};
struct ipa_subdomains_ctx {
struct ipa_id_ctx *id_ctx;
struct sdap_id_ctx *sdap_id_ctx;
struct sdap_search_base **search_bases;
struct sdap_search_base **master_search_bases;
struct sdap_search_base **ranges_search_bases;
struct tevent_timer *timer_event;
bool configured_explicit;
};
{
struct ipa_subdomains_ctx *subdom_ctx;
struct ipa_subdomains_ctx);
if (subdom_ctx == NULL) {
return NULL;
}
return subdom_ctx->be_ctx;
}
static errno_t
struct ipa_id_ctx *id_ctx,
struct sss_domain_info *subdom,
struct ad_id_ctx **_ad_id_ctx)
{
struct ad_options *ad_options;
const char *gc_service_name;
struct ad_srv_plugin_ctx *srv_ctx;
char *ad_domain;
struct sdap_domain *sdom;
if (ad_options == NULL) {
return ENOMEM;
}
return ret;
}
return ret;
}
if (gc_service_name == NULL) {
return ENOMEM;
}
/* Set KRB5 realm to same as the one of IPA when IPA
* is able to attach PAC. For testing, use hardcoded. */
return ret;
}
return ENOMEM;
}
/* use AD plugin */
return ENOMEM;
}
return ret;
}
return EFAULT;
}
sdom,
return ret;
}
/* Set up the ID mapping object */
*_ad_id_ctx = ad_id_ctx;
return EOK;
}
static errno_t
struct ipa_id_ctx *id_ctx,
struct sss_domain_info *subdom)
{
struct ipa_ad_server_ctx *trust_ctx;
return ret;
}
return ENOMEM;
}
return EOK;
}
static errno_t
struct ipa_id_ctx *id_ctx,
struct sss_domain_info *parent)
{
struct sss_domain_info *dom;
struct ipa_ad_server_ctx *trust_iter;
IPA_SERVER_MODE) == false) {
return EOK;
}
/* Check if we already have an ID context for this subdomain */
break;
}
}
/* Newly detected trust */
if (trust_iter == NULL) {
"Cannot create ad_id_ctx for subdomain %s\n",
continue;
}
}
}
return EOK;
}
static errno_t
{
return ret;
}
"sss_krb5_write_mappings failed.\n");
/* Just continue */
}
return EOK;
}
static void
struct sss_domain_info *subdom)
{
struct ipa_ad_server_ctx *iter;
struct sdap_domain *sdom;
IPA_SERVER_MODE) == false) {
return;
}
}
return;
}
/* terminate all requests for this subdomain so we can free it */
}
const char *name)
{
struct ipa_subdomains_ctx *ctx;
struct sss_domain_info *dom;
struct ipa_subdomains_ctx);
return NULL;
}
if (dom) {
}
return NULL;
}
char *domain_name,
struct sysdb_attrs **reply,
struct range_info ***_range_list)
{
struct range_info *r;
const char *value;
size_t c;
size_t d;
int ret;
enum idmap_error_code err;
char *name1;
char *name2;
char *sid1;
char *sid2;
struct sss_idmap_range range1;
struct sss_idmap_range range2;
bool mapping1;
bool mapping2;
if (range_list == NULL) {
return ENOMEM;
}
for (c = 0; c < count; c++) {
if (r == NULL) {
goto done;
}
goto done;
}
goto done;
}
if (r->trusted_dom_sid == NULL) {
goto done;
}
goto done;
}
&r->base_id);
goto done;
}
&r->id_range_size);
goto done;
}
&r->base_rid);
goto done;
}
&r->secondary_base_rid);
goto done;
}
if (r->range_type == NULL) {
goto done;
}
/* Older IPA servers might not have the range_type attribute, but
* only support local ranges and trusts with algorithmic mapping. */
if (r->trusted_dom_sid == NULL) {
} else {
}
} else {
goto done;
}
if (r->range_type == NULL) {
goto done;
}
goto done;
}
for (d = 0; d < c; d++) {
("get_idmap_data_from_range failed.\n"));
goto done;
}
if (err != IDMAP_SUCCESS) {
"Collision of ranges [%s] and [%s] detected.\n",
goto done;
}
}
range_list[c] = r;
}
range_list[c] = NULL;
done:
}
return ret;
}
struct sysdb_attrs *attrs,
bool *_enumerates)
{
const char *name;
return ret;
}
return EOK;
}
struct ldb_context *ldb_ctx,
struct sysdb_attrs *attrs,
char **_forest)
{
int ret;
const char *orig_dn;
if (ret) {
goto done;
}
orig_dn);
goto done;
}
if (!ldb_dn_validate(dn)) {
orig_dn);
goto done;
}
/* We are only interested in the member domain objects. In IPA the
* forest root object is stored as e.g.
* cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com. Member domains in the
* forest are children of the forest root object e.g.
* cn=SUB.AD.DOM,cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com. Since
* the forest name is not stored in the member objects we derive it
* from the RDN of the forest root object. */
goto done;
}
"4th component is not 'trust', nothing to do.\n");
goto done;
}
"3rd component is not 'ad', nothing to do.\n");
goto done;
}
goto done;
}
done:
}
return ret;
}
struct sdap_idmap_ctx *sdap_idmap_ctx,
struct sysdb_attrs *attrs,
bool enumerate)
{
const char *name;
char *realm;
const char *flat;
const char *id;
int ret;
bool mpg;
return ENOMEM;
}
goto done;
}
if (!realm) {
goto done;
}
if (ret) {
goto done;
}
if (ret) {
goto done;
}
goto done;
}
if (ret) {
goto done;
}
done:
return ret;
}
bool *changes)
{
const char *value;
int c, h;
int ret;
bool enumerate;
h = 0;
/* check existing subdomains */
for (c = 0; c < count; c++) {
if (handled[c]) {
continue;
}
goto done;
}
break;
}
}
if (c >= count) {
/* ok this subdomain does not exist anymore, let's clean up */
goto done;
}
/* Remove the AD ID ctx from the list of LDAP domains */
} else {
/* ok let's try to update it */
goto done;
}
if (ret) {
/* Nothing we can do about the errorr. Let's at least try
* to reuse the existing domain
*/
"will try to use cached subdomain\n");
}
handled[c] = true;
h++;
}
}
if (count == h) {
/* all domains were already accounted for and have been updated */
goto done;
}
/* if we get here it means we have changes to the subdomains list */
*changes = true;
for (c = 0; c < count; c++) {
if (handled[c]) {
continue;
}
/* Nothing we can do about the errorr. Let's at least try
* to reuse the existing domain.
*/
goto done;
}
if (ret) {
"will try to use cached subdomain\n");
}
}
done:
ctx->last_refreshed = 0;
} else {
}
return ret;
}
struct ipa_subdomains_req_ctx {
struct ipa_subdomains_ctx *sd_ctx;
struct sdap_id_op *sdap_op;
char *current_filter;
struct sdap_search_base **search_bases;
int search_base_iter;
struct sysdb_attrs **reply;
};
static errno_t
enum ipa_subdomains_req_type type);
static struct ipa_subdomains_req_params subdomain_requests[] = {
},
},
{ RANGE_FILTER,
{ OBJECTCLASS, IPA_CN,
}
}
};
{
struct tevent_req *req;
int dp_error = DP_ERR_FATAL;
int ret;
goto done;
}
req_ctx->search_base_iter = 0;
req_ctx->reply_count = 0;
goto done;
}
goto done;
}
return;
done:
}
}
{
int ret;
int dp_error = DP_ERR_FATAL;
struct ipa_subdomains_req_ctx *ctx;
if (ret) {
if (dp_error == DP_ERR_OFFLINE) {
"No IPA server is available, cannot get the "
"subdomain list while offline\n");
} else {
"Failed to connect to IPA server: [%d](%s)\n",
}
goto fail;
}
goto fail;
}
return;
fail:
}
static errno_t
enum ipa_subdomains_req_type type)
{
struct tevent_req *req;
struct sdap_search_base *base;
struct ipa_subdomains_req_params *params;
if (type >= IPA_SUBDOMAINS_MAX) {
return EINVAL;
}
return EOK;
}
return ENOMEM;
}
SDAP_SEARCH_TIMEOUT), false);
return ENOMEM;
}
return EAGAIN;
}
{
int ret;
struct ipa_subdomains_req_ctx *ctx;
struct sss_domain_info *domain;
bool refresh_has_changes = false;
int dp_error = DP_ERR_FATAL;
goto done;
}
if (reply_count) {
goto done;
}
reply_count * sizeof(struct sysdb_attrs *));
}
ctx->search_base_iter++;
return;
goto done;
}
goto done;
}
if (refresh_has_changes) {
goto done;
}
domain);
goto done;
}
}
goto done;
}
ctx->search_base_iter = 0;
return;
goto done;
}
} else {
}
done:
}
}
{
int dp_error = DP_ERR_FATAL;
struct ipa_subdomains_req_ctx *ctx;
struct sss_domain_info *domain;
goto done;
}
"ipa_ranges_parse_results request failed.\n");
goto done;
}
goto done;
}
ctx->search_base_iter = 0;
return;
goto done;
}
done:
}
}
{
int dp_error = DP_ERR_FATAL;
struct ipa_subdomains_req_ctx *ctx;
goto done;
}
if (reply_count) {
goto done;
}
goto done;
}
} else {
ctx->search_base_iter++;
return;
goto done;
}
/* Right now we know there has been an error
* and we don't have the master domain record
*/
}
}
done:
}
}
static void ipa_subdom_online_cb(void *pvt);
struct tevent_timer *te,
struct timeval current_time,
void *pvt)
{
}
const char *errstr)
{
}
static void ipa_subdom_reset_timeouts_cb(void *pvt)
{
struct ipa_subdomains_ctx *ctx;
return;
}
ctx->last_refreshed = 0;
ctx->disabled_until = 0;
}
static void ipa_subdom_online_cb(void *pvt)
{
struct ipa_subdomains_ctx *ctx;
if (!ctx) {
return;
}
ctx->disabled_until = 0;
return;
}
if (!ctx->timer_event) {
}
}
static void ipa_subdom_offline_cb(void *pvt)
{
struct ipa_subdomains_ctx *ctx;
if (ctx) {
}
}
bool *configured_explicit)
{
int ret;
char *tmp_str;
return ENOMEM;
}
&tmp_str);
goto done;
}
*configured_explicit = false;
} else {
*configured_explicit = true;
}
done:
return ret;
}
{
struct ipa_subdomains_ctx *ctx;
struct ipa_subdomains_ctx);
if (!ctx) {
return;
}
return;
}
return;
}
}
struct bet_ops ipa_subdomains_ops = {
};
struct ipa_id_ctx *id_ctx,
void **pvt_data)
{
struct ipa_subdomains_ctx *ctx;
int ret;
bool configured_explicit = false;
return ret;
}
return ENOMEM;
}
ctx->disabled_until = 0;
*ops = &ipa_subdomains_ops;
NULL);
"Failed to add subdom reset timeouts callback");
}
}
}
"Users from trusted domains might not be resolved correctly\n");
}
return EOK;
}
struct ipa_id_ctx *id_ctx)
{
char *realm;
char *hostname;
IPA_SERVER_MODE) == false) {
return EOK;
}
/* The IPA code relies on the default FQDN format to unparse user
* names. Warn loudly if the full_name_format was customized on the
* IPA server
*/
CONFDB_DEFAULT_FULL_NAME_FORMAT_INTERNAL) != 0)) {
"lookups of subdomain users will likely fail!\n",
"lookups of subdomain users will likely fail!\n",
/* Attempt to continue */
}
return EINVAL;
}
return EINVAL;
}
return ENOMEM;
}
return ret;
}
return EOK;
}