ipa_subdomains.c revision 03713859dffacc7142393e53c73d8d4cf7dee8d5
/*
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/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_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
/* refresh automatically every 4 hours */
#define IPA_SUBDOMAIN_DISABLED_PERIOD 3600
/* the directory domain - realm mappings are written to */
enum ipa_subdomains_req_type {
IPA_SUBDOMAINS_MAX /* Counter */
};
struct ipa_subdomains_req_params {
const char *filter;
const char *attrs[8];
};
struct ipa_subdomains_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;
}
const char *name)
{
struct ipa_subdomains_ctx *ctx;
struct sss_domain_info *dom;
struct ipa_subdomains_ctx);
return NULL;
}
if (dom) {
}
return NULL;
}
struct sysdb_attrs **reply,
struct range_info ***_range_list)
{
const char *value;
size_t c;
int ret;
if (range_list == NULL) {
return ENOMEM;
}
for (c = 0; c < count; c++) {
if (range_list[c] == NULL) {
goto done;
}
goto done;
}
goto done;
}
value);
goto done;
}
goto done;
}
&range_list[c]->base_id);
goto done;
}
&range_list[c]->id_range_size);
goto done;
}
&range_list[c]->base_rid);
goto done;
}
&range_list[c]->secondary_base_rid);
goto done;
}
}
range_list[c] = NULL;
done:
}
return ret;
}
struct sysdb_attrs *attrs)
{
const char *name;
char *realm;
const char *flat;
const char *id;
int ret;
return ENOMEM;
}
goto done;
}
if (!realm) {
goto done;
}
if (ret) {
goto done;
}
if (ret) {
goto done;
}
if (ret) {
goto done;
}
done:
return ret;
}
static errno_t
{
struct sss_domain_info *dom;
const char *mapping_file;
char *sanitized_domain;
int fd = -1;
int i;
return EINVAL;
}
if (sanitized_domain == NULL) {
return ENOMEM;
}
/* only alpha-numeric chars, dashes and underscores are allowed in
* krb5 include directory */
for (i = 0; sanitized_domain[i] != '\0'; i++) {
if (!isalnum(sanitized_domain[i])
sanitized_domain[i] = '_';
}
}
if (!mapping_file) {
goto done;
}
goto done;
}
if (fd < 0) {
"mappings failed.", tmp_file));
goto done;
}
if (!fstream) {
if (ret != 0) {
/* Nothing to do here, just report the failure */
}
goto done;
}
if (ret < 0) {
goto done;
}
if (ret < 0) {
goto done;
}
}
if (ret != 0) {
goto done;
}
if (ret == -1) {
goto done;
}
if (ret == -1) {
goto done;
}
/* touch krb5.conf to ensure that new mappings are loaded */
ret = sss_krb5_touch_config();
"of krb5.conf. Created mappings may not be loaded.\n"));
/* just continue */
}
done:
if (fstream) {
if (err != 0) {
/* Nothing to do here, just report the failure */
}
}
if (tmp_file) {
if (err < 0) {
("Could not remove file [%s]: [%d]: %s",
}
}
return ret;
}
bool *changes)
{
const char *value;
int c, h;
int ret;
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;
}
} else {
/* ok let's try to update it */
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.
*/
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"));
/* FIXME: return saved results ?? */
} 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;
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;
}
("ipa_subdomains_write_mappings failed.\n"));
}
}
ctx->search_base_iter = 0;
return;
goto done;
}
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;
}
goto done;
}
ctx->search_base_iter = 0;
return;
goto done;
}
} else {
}
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_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;
}
}
return EOK;
}