74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek/*
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek SSSD
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ad_dyndns.c
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek Authors:
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek Copyright (C) 2013 Red Hat
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek This program is free software; you can redistribute it and/or modify
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek it under the terms of the GNU General Public License as published by
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek the Free Software Foundation; either version 3 of the License, or
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek (at your option) any later version.
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek This program is distributed in the hope that it will be useful,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek GNU General Public License for more details.
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek You should have received a copy of the GNU General Public License
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek*/
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek#include <ctype.h>
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek#include "util/util.h"
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek#include "providers/ldap/sdap_dyndns.h"
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek#include "providers/data_provider.h"
892ddeb5190dd5c1ffa26a95142a10a0034fc5e3Pavel Březina#include "providers/be_dyndns.h"
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek#include "providers/ad/ad_common.h"
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekvoid ad_dyndns_update(void *pvt);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekerrno_t ad_dyndns_init(struct be_ctx *be_ctx,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ad_opts)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek errno_t ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek /* nsupdate is available. Dynamic updates
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek * are supported
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek */
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = ad_get_dyndns_options(be_ctx, ad_opts);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set AD options\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (dp_opt_get_bool(ad_opts->dyndns_ctx->opts,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DP_OPT_DYNDNS_UPDATE) == false) {
b3851e86af91dc1aa6e265d5b2e4279b2611ff43Pavel Březina DEBUG(SSSDBG_CONF_SETTINGS, "Dynamic DNS updates are off.\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Dynamic DNS updates are on. Checking for nsupdate..\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = be_nsupdate_check();
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret == ENOENT) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "DNS updates requested but nsupdate not available\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek } else if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not check for nsupdate\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ad_opts->be_res = be_ctx->be_res;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ad_opts->be_res == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Resolver must be initialized in order "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "to use the AD dynamic DNS updates\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EINVAL;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ret = be_nsupdate_init_timer(ad_opts->dyndns_ctx, be_ctx->ev,
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ad_dyndns_timer, ad_opts);
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up periodic update\n");
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek return ret;
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek }
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = be_add_online_cb(be_ctx, be_ctx,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ad_dyndns_update,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ad_opts, NULL);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up online callback\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_timer_connected(struct tevent_req *req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekvoid ad_dyndns_timer(void *pvt)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ctx = talloc_get_type(pvt, struct ad_options);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct sdap_id_ctx *sdap_ctx = ctx->id_ctx->sdap_id_ctx;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req *req;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek req = sdap_dyndns_timer_conn_send(ctx, sdap_ctx->be->ev, sdap_ctx,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ctx->dyndns_ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek /* Not much we can do. Just attempt to reschedule */
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek be_nsupdate_timer_schedule(sdap_ctx->be->ev, ctx->dyndns_ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_set_callback(req, ad_dyndns_timer_connected, ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_timer_connected(struct tevent_req *req)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek errno_t ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ctx = tevent_req_callback_data(req, struct ad_options);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = sdap_dyndns_timer_conn_recv(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek talloc_zfree(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to connect to AD: [%d](%s)\n", ret, sss_strerror(ret));
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return ad_dyndns_update(ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic struct tevent_req *ad_dyndns_update_send(struct ad_options *ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic errno_t ad_dyndns_update_recv(struct tevent_req *req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_nsupdate_done(struct tevent_req *req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekvoid ad_dyndns_update(void *pvt)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ctx = talloc_get_type(pvt, struct ad_options);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct sdap_id_ctx *sdap_ctx = ctx->id_ctx->sdap_id_ctx;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req *req;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek /* Schedule timer after provider went offline */
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek be_nsupdate_timer_schedule(sdap_ctx->be->ev, ctx->dyndns_ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek req = ad_dyndns_update_send(ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not update DNS\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_set_callback(req, ad_dyndns_nsupdate_done, NULL);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_nsupdate_done(struct tevent_req *req)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek int ret = ad_dyndns_update_recv(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek talloc_free(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Updating DNS entry failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, sss_strerror(ret));
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
35e0d0c2e6c91a7bc392c4fa241d24477e8607f1Lukas Slebodnik DEBUG(SSSDBG_TRACE_FUNC, "DNS update finished\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstruct ad_dyndns_update_state {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ad_ctx;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek};
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_sdap_update_done(struct tevent_req *subreq);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic struct tevent_req *
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekad_dyndns_update_send(struct ad_options *ctx)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek int ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_dyndns_update_state *state;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req *req, *subreq;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct sdap_id_ctx *sdap_ctx = ctx->id_ctx->sdap_id_ctx;
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek LDAPURLDesc *lud;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing update\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek req = tevent_req_create(ctx, &state, struct ad_dyndns_update_state);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (req == NULL) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return NULL;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek state->ad_ctx = ctx;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ctx->dyndns_ctx->last_refresh + 60 > time(NULL) ||
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ctx->dyndns_ctx->timer_in_progress) {
4d69d511ee4843cbdacde2f73ed378182ead83f6Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "Last periodic update ran recently or timer "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "in progress, not scheduling another update\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_done(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_post(req, sdap_ctx->be->ev);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return req;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek state->ad_ctx->dyndns_ctx->last_refresh = time(NULL);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ret = ldap_url_parse(ctx->service->sdap->uri, &lud);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek if (ret != LDAP_SUCCESS) {
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to parse ldap URI (%s)!\n", ctx->service->sdap->uri);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ret = EINVAL;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek goto done;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek if (lud->lud_scheme != NULL &&
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek strcasecmp(lud->lud_scheme, "ldapi") == 0) {
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The LDAP scheme is ldapi://, cannot proceed with update\n");
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ldap_free_urldesc(lud);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ret = EINVAL;
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek goto done;
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek }
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek if (lud->lud_host == NULL) {
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The LDAP URI (%s) did not contain a host name\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ctx->service->sdap->uri);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ldap_free_urldesc(lud);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ret = EINVAL;
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek goto done;
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek }
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek subreq = sdap_dyndns_update_send(state, sdap_ctx->be->ev,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek sdap_ctx->be,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ctx->dyndns_ctx->opts,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek sdap_ctx,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ctx->dyndns_ctx->auth_type,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek dp_opt_get_string(ctx->dyndns_ctx->opts,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DP_OPT_DYNDNS_IFACE),
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek dp_opt_get_string(ctx->basic,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek AD_HOSTNAME),
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek dp_opt_get_string(ctx->basic,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek AD_KRB5_REALM),
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek dp_opt_get_int(ctx->dyndns_ctx->opts,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DP_OPT_DYNDNS_TTL),
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek false);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (!subreq) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = EIO;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sdap_id_op_connect_send failed: [%d](%s)\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, sss_strerror(ret));
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek goto done;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_set_callback(subreq, ad_dyndns_sdap_update_done, req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekdone:
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_error(req, ret);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_post(req, sdap_ctx->be->ev);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return req;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_sdap_update_done(struct tevent_req *subreq)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek errno_t ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek ret = sdap_dyndns_update_recv(subreq);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek talloc_zfree(subreq);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Dynamic DNS update failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, sss_strerror(ret));
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_error(req, ret);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_done(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic errno_t ad_dyndns_update_recv(struct tevent_req *req)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}