74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek Copyright (C) 2013 Red Hat
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 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 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 /* nsupdate is available. Dynamic updates
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek * are supported
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set AD options\n");
b3851e86af91dc1aa6e265d5b2e4279b2611ff43Pavel Březina DEBUG(SSSDBG_CONF_SETTINGS, "Dynamic DNS updates are off.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Dynamic DNS updates are on. Checking for nsupdate..\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "DNS updates requested but nsupdate not available\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not check for nsupdate\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Resolver must be initialized in order "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "to use the AD dynamic DNS updates\n");
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ret = be_nsupdate_init_timer(ad_opts->dyndns_ctx, be_ctx->ev,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up periodic update\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up online callback\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_timer_connected(struct tevent_req *req);
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 req = sdap_dyndns_timer_conn_send(ctx, sdap_ctx->be->ev, sdap_ctx,
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 tevent_req_set_callback(req, ad_dyndns_timer_connected, ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_timer_connected(struct tevent_req *req)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ctx = tevent_req_callback_data(req, struct ad_options);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to connect to AD: [%d](%s)\n", ret, sss_strerror(ret));
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 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 /* Schedule timer after provider went offline */
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek be_nsupdate_timer_schedule(sdap_ctx->be->ev, ctx->dyndns_ctx);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not update DNS\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_set_callback(req, ad_dyndns_nsupdate_done, NULL);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_nsupdate_done(struct tevent_req *req)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Updating DNS entry failed [%d]: %s\n",
35e0d0c2e6c91a7bc392c4fa241d24477e8607f1Lukas Slebodnik DEBUG(SSSDBG_TRACE_FUNC, "DNS update finished\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_sdap_update_done(struct tevent_req *subreq);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic struct tevent_req *
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct sdap_id_ctx *sdap_ctx = ctx->id_ctx->sdap_id_ctx;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing update\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek req = tevent_req_create(ctx, &state, struct ad_dyndns_update_state);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ctx->dyndns_ctx->last_refresh + 60 > time(NULL) ||
4d69d511ee4843cbdacde2f73ed378182ead83f6Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "Last periodic update ran recently or timer "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "in progress, not scheduling another update\n");
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek state->ad_ctx->dyndns_ctx->last_refresh = time(NULL);
2338eef6ec830dcbbc7e9f7bcebf31656e8742ecJakub Hrozek ret = ldap_url_parse(ctx->service->sdap->uri, &lud);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to parse ldap URI (%s)!\n", ctx->service->sdap->uri);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The LDAP scheme is ldapi://, cannot proceed with update\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The LDAP URI (%s) did not contain a host name\n",
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek subreq = sdap_dyndns_update_send(state, sdap_ctx->be->ev,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sdap_id_op_connect_send failed: [%d](%s)\n",
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek tevent_req_set_callback(subreq, ad_dyndns_sdap_update_done, req);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekstatic void ad_dyndns_sdap_update_done(struct tevent_req *subreq)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Dynamic DNS update failed [%d]: %s\n",