summaryrefslogtreecommitdiffstats
path: root/src/providers/dp_dyndns.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-04-09 17:40:40 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-05-03 20:25:46 +0200
commit5a4239490c7fb7d732180a9d40f27f0247c56631 (patch)
tree5d118934b4a922a1c549f1cc96b31c09ee60be64 /src/providers/dp_dyndns.c
parent04868f1573f4b26ef34610b6d7069172f93bd8ab (diff)
downloadsssd-5a4239490c7fb7d732180a9d40f27f0247c56631.tar.gz
sssd-5a4239490c7fb7d732180a9d40f27f0247c56631.tar.xz
sssd-5a4239490c7fb7d732180a9d40f27f0247c56631.zip
dyndns: new option dyndns_refresh_interval
This new options adds the possibility of updating the DNS entries periodically regardless if they have changed or not. This feature will be useful mainly in AD environments where the Windows clients periodically update their DNS records.
Diffstat (limited to 'src/providers/dp_dyndns.c')
-rw-r--r--src/providers/dp_dyndns.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/providers/dp_dyndns.c b/src/providers/dp_dyndns.c
index 81228d5cf..337817fc7 100644
--- a/src/providers/dp_dyndns.c
+++ b/src/providers/dp_dyndns.c
@@ -879,6 +879,45 @@ be_nsupdate_recv(struct tevent_req *req, int *child_status)
return EOK;
}
+static void be_nsupdate_timer(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval current_time,
+ void *pvt)
+{
+ struct be_nsupdate_ctx *ctx = talloc_get_type(pvt, struct be_nsupdate_ctx);
+
+ talloc_zfree(ctx->refresh_timer);
+ ctx->timer_callback(ctx->timer_pvt);
+
+ /* timer_callback is responsible for calling be_nsupdate_timer_schedule
+ * again */
+}
+
+void be_nsupdate_timer_schedule(struct tevent_context *ev,
+ struct be_nsupdate_ctx *ctx)
+{
+ int refresh;
+ struct timeval tv;
+
+ if (ctx->refresh_timer) {
+ DEBUG(SSSDBG_FUNC_DATA, ("Timer already scheduled\n"));
+ return;
+ }
+
+ refresh = dp_opt_get_int(ctx->opts, DP_OPT_DYNDNS_REFRESH_INTERVAL);
+ if (refresh == 0) return;
+ DEBUG(SSSDBG_FUNC_DATA, ("Scheduling timer in %d seconds\n", refresh));
+
+ tv = tevent_timeval_current_ofs(refresh, 0);
+ ctx->refresh_timer = tevent_add_timer(ev, ctx, tv,
+ be_nsupdate_timer, ctx);
+
+ if (!ctx->refresh_timer) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ ("Failed to add dyndns refresh timer event\n"));
+ }
+}
+
errno_t
be_nsupdate_check(void)
{
@@ -906,6 +945,7 @@ be_nsupdate_check(void)
static struct dp_option default_dyndns_opts[] = {
{ "dyndns_update", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
+ { "dyndns_refresh_interval", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER },
{ "dyndns_iface", DP_OPT_STRING, NULL_STRING, NULL_STRING },
{ "dyndns_ttl", DP_OPT_NUMBER, { .number = 1200 }, NULL_NUMBER },
@@ -914,13 +954,16 @@ static struct dp_option default_dyndns_opts[] = {
errno_t
be_nsupdate_init(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
- struct dp_option *defopts, struct be_nsupdate_ctx **_ctx)
+ struct dp_option *defopts,
+ nsupdate_timer_fn_t timer_callback,
+ void *timer_pvt,
+ struct be_nsupdate_ctx **_ctx)
{
errno_t ret;
struct dp_option *src_opts;
struct be_nsupdate_ctx *ctx;
- ctx = talloc(mem_ctx, struct be_nsupdate_ctx);
+ ctx = talloc_zero(mem_ctx, struct be_nsupdate_ctx);
if (ctx == NULL) return ENOMEM;
src_opts = defopts ? defopts : default_dyndns_opts;
@@ -932,6 +975,10 @@ be_nsupdate_init(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
return ret;
}
+ ctx->timer_callback = timer_callback;
+ ctx->timer_pvt = timer_pvt;
+ be_nsupdate_timer_schedule(be_ctx->ev, ctx);
+
*_ctx = ctx;
- return EOK;
+ return ERR_OK;
}