dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone
Blob Blame History Raw
From f5ef6aa9965fec34c8de9fe2635b0e5c5b8a0ab9 Mon Sep 17 00:00:00 2001
From: Tomas Halman <thalman@redhat.com>
Date: Fri, 19 Jul 2019 15:59:32 +0200
Subject: [PATCH 47/48] BE: Convert be_ptask params to flags
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The be_ptask_create call has a lot of parameters.
Some of them can be converted to flags to simplify
the declaration.

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/providers/ad/ad_dyndns.c             |   9 +-
 src/providers/ad/ad_machine_pw_renewal.c |  10 +-
 src/providers/ad/ad_subdomains.c         |  11 +-
 src/providers/be_ptask.c                 |  74 ++++++---
 src/providers/be_ptask.h                 |  39 ++---
 src/providers/be_ptask_private.h         |   2 -
 src/providers/be_refresh.c               |   9 +-
 src/providers/data_provider_be.c         |   4 +-
 src/providers/ipa/ipa_dyndns.c           |   7 +-
 src/providers/ipa/ipa_subdomains.c       |   7 +-
 src/providers/ldap/ldap_id_cleanup.c     |   5 +-
 src/providers/ldap/ldap_id_enum.c        |   6 +-
 src/providers/ldap/sdap_sudo_shared.c    |  16 +-
 src/tests/cmocka/test_be_ptask.c         | 194 ++++++++++++++++-------
 14 files changed, 251 insertions(+), 142 deletions(-)

diff --git a/src/providers/ad/ad_dyndns.c b/src/providers/ad/ad_dyndns.c
index af765b581..c9763d449 100644
--- a/src/providers/ad/ad_dyndns.c
+++ b/src/providers/ad/ad_dyndns.c
@@ -98,10 +98,13 @@ errno_t ad_dyndns_init(struct be_ctx *be_ctx,
         return EINVAL;
     }
 
-    ret = be_ptask_create(ad_opts, be_ctx, period, ptask_first_delay, 0, 0, period,
-                          BE_PTASK_OFFLINE_DISABLE, BE_PTASK_SCHEDULE_FROM_LAST, 0,
+    ret = be_ptask_create(ad_opts, be_ctx, period, ptask_first_delay, 0, 0,
+                          period, 0,
                           ad_dyndns_update_send, ad_dyndns_update_recv, ad_opts,
-                          "Dyndns update", 0, NULL);
+                          "Dyndns update",
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          NULL);
 
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
diff --git a/src/providers/ad/ad_machine_pw_renewal.c b/src/providers/ad/ad_machine_pw_renewal.c
index 67802c04a..9dc36247a 100644
--- a/src/providers/ad/ad_machine_pw_renewal.c
+++ b/src/providers/ad/ad_machine_pw_renewal.c
@@ -381,14 +381,14 @@ errno_t ad_machine_account_password_renewal_init(struct be_ctx *be_ctx,
         goto done;
     }
 
-    ret = be_ptask_create(be_ctx, be_ctx, period, initial_delay, 0, 0, 60,
-                          BE_PTASK_OFFLINE_DISABLE,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
-                          0,
+    ret = be_ptask_create(be_ctx, be_ctx, period, initial_delay, 0, 0, 60, 0,
                           ad_machine_account_password_renewal_send,
                           ad_machine_account_password_renewal_recv,
                           renewal_data,
-                          "AD machine account password renewal", 0, NULL);
+                          "AD machine account password renewal",
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "be_ptask_create failed.\n");
         goto done;
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index 0f46b46ad..d934e70d6 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -2065,12 +2065,13 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
                   struct ad_subdomains_ctx, struct dp_subdomains_data, struct dp_reply_std);
 
     period = be_ctx->domain->subdomain_refresh_interval;
-    ret = be_ptask_create(sd_ctx, be_ctx, period, 0, 0, 0, period,
-                          BE_PTASK_OFFLINE_DISABLE,
+    ret = be_ptask_create(sd_ctx, be_ctx, period, 0, 0, 0, period, 0,
+                          ad_subdomains_ptask_send, ad_subdomains_ptask_recv,
+                          sd_ctx,
+                          "Subdomains Refresh",
+                          BE_PTASK_OFFLINE_DISABLE |
                           BE_PTASK_SCHEDULE_FROM_LAST,
-                          0,
-                          ad_subdomains_ptask_send, ad_subdomains_ptask_recv, sd_ctx,
-                          "Subdomains Refresh", 0, NULL);
+                          NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/be_ptask.c b/src/providers/be_ptask.c
index 56c9c82fe..9a432c948 100644
--- a/src/providers/be_ptask.c
+++ b/src/providers/be_ptask.c
@@ -38,7 +38,7 @@ enum be_ptask_delay {
 
 static void be_ptask_schedule(struct be_ptask *task,
                               enum be_ptask_delay delay_type,
-                              enum be_ptask_schedule from);
+                              uint32_t from);
 
 static int be_ptask_destructor(void *pvt)
 {
@@ -107,21 +107,20 @@ static void be_ptask_execute(struct tevent_context *ev,
 
     if (be_is_offline(task->be_ctx)) {
         DEBUG(SSSDBG_TRACE_FUNC, "Back end is offline\n");
-        switch (task->offline) {
-        case BE_PTASK_OFFLINE_SKIP:
+        if (task->flags & BE_PTASK_OFFLINE_SKIP) {
             be_ptask_schedule(task, BE_PTASK_PERIOD,
                               BE_PTASK_SCHEDULE_FROM_NOW);
             return;
-        case BE_PTASK_OFFLINE_DISABLE:
+        }
+        else if(task->flags & BE_PTASK_OFFLINE_DISABLE) {
             /* This case is normally handled by offline callback but we
              * should handle it here as well since we can get here in some
              * special cases for example unit tests or tevent events order. */
             be_ptask_disable(task);
             return;
-        case BE_PTASK_OFFLINE_EXECUTE:
-            /* continue */
-            break;
         }
+        /* BE_PTASK_OFFLINE_EXECUTE */
+        /* continue */
     }
 
     DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: executing task, timeout %lu "
@@ -177,7 +176,7 @@ static void be_ptask_done(struct tevent_req *req)
         DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: finished successfully\n",
                                   task->name);
 
-        be_ptask_schedule(task, BE_PTASK_PERIOD, task->success_schedule_type);
+        be_ptask_schedule(task, BE_PTASK_PERIOD, task->flags);
         break;
     default:
         DEBUG(SSSDBG_OP_FAILURE, "Task [%s]: failed with [%d]: %s\n",
@@ -190,7 +189,7 @@ static void be_ptask_done(struct tevent_req *req)
 
 static void be_ptask_schedule(struct be_ptask *task,
                               enum be_ptask_delay delay_type,
-                              enum be_ptask_schedule from)
+                              uint32_t from)
 {
     struct timeval tv = { 0, };
     time_t delay = 0;
@@ -228,20 +227,18 @@ static void be_ptask_schedule(struct be_ptask *task,
         delay = delay + (rand_r(&task->ro_seed) % task->random_offset);
     }
 
-    switch (from) {
-    case BE_PTASK_SCHEDULE_FROM_NOW:
+    if(from | BE_PTASK_SCHEDULE_FROM_NOW) {
         tv = tevent_timeval_current_ofs(delay, 0);
 
         DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: scheduling task %lu seconds "
               "from now [%lu]\n", task->name, delay, tv.tv_sec);
-        break;
-    case BE_PTASK_SCHEDULE_FROM_LAST:
+    }
+    else if (from | BE_PTASK_SCHEDULE_FROM_LAST) {
         tv = tevent_timeval_set(task->last_execution + delay, 0);
 
         DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: scheduling task %lu seconds "
                                   "from last execution time [%lu]\n",
                                   task->name, delay, tv.tv_sec);
-        break;
     }
 
     if (task->timer != NULL) {
@@ -261,6 +258,36 @@ static void be_ptask_schedule(struct be_ptask *task,
     task->next_execution = tv.tv_sec;
 }
 
+static unsigned int be_ptask_flag_bits(uint32_t flags)
+{
+    unsigned int cnt = 0;
+    while (flags != 0) {
+        cnt += flags & 1;
+        flags >>= 1;
+    }
+    return cnt;
+}
+
+static int be_ptask_flag_check(uint32_t flags)
+{
+    uint32_t tmpflags;
+
+    tmpflags = flags & (BE_PTASK_SCHEDULE_FROM_LAST |
+                        BE_PTASK_SCHEDULE_FROM_NOW);
+    if (be_ptask_flag_bits(tmpflags) != 1) {
+        return EINVAL;
+    }
+
+    tmpflags = flags & (BE_PTASK_OFFLINE_SKIP |
+                        BE_PTASK_OFFLINE_DISABLE |
+                        BE_PTASK_OFFLINE_EXECUTE);
+    if (be_ptask_flag_bits(tmpflags) != 1) {
+        return EINVAL;
+    }
+
+    return EOK;
+}
+
 errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                         struct be_ctx *be_ctx,
                         time_t period,
@@ -268,8 +295,6 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                         time_t enabled_delay,
                         time_t random_offset,
                         time_t timeout,
-                        enum be_ptask_offline offline,
-                        enum be_ptask_schedule success_schedule_type,
                         time_t max_backoff,
                         be_ptask_send_t send_fn,
                         be_ptask_recv_t recv_fn,
@@ -290,6 +315,12 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
         return EINVAL;
     }
 
+    /* check flags, some of them are exclusive, some must be present */
+    ret = be_ptask_flag_check(flags);
+    if (ret != EOK) {
+        return ret;
+    }
+
     task = talloc_zero(mem_ctx, struct be_ptask);
     if (task == NULL) {
         ret = ENOMEM;
@@ -306,8 +337,6 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
     task->ro_seed = time(NULL) * getpid();
     task->max_backoff = max_backoff;
     task->timeout = timeout;
-    task->offline = offline;
-    task->success_schedule_type = success_schedule_type;
     task->send_fn = send_fn;
     task->recv_fn = recv_fn;
     task->pvt = pvt;
@@ -322,7 +351,7 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
 
     talloc_set_destructor((TALLOC_CTX*)task, be_ptask_destructor);
 
-    if (offline == BE_PTASK_OFFLINE_DISABLE) {
+    if (flags & BE_PTASK_OFFLINE_DISABLE) {
         /* install offline and online callbacks */
         ret = be_add_online_cb(task, be_ctx, be_ptask_online_cb, task, NULL);
         if (ret != EOK) {
@@ -458,7 +487,6 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
                              time_t enabled_delay,
                              time_t random_offset,
                              time_t timeout,
-                             enum be_ptask_offline offline,
                              time_t max_backoff,
                              be_ptask_sync_t fn,
                              void *pvt,
@@ -479,10 +507,10 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
     ctx->pvt = pvt;
 
     ret = be_ptask_create(mem_ctx, be_ctx, period, first_delay,
-                          enabled_delay, random_offset, timeout, offline,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          enabled_delay, random_offset, timeout,
                           max_backoff, be_ptask_sync_send, be_ptask_sync_recv,
-                          ctx, name, flags, _task);
+                          ctx, name, flags | BE_PTASK_SCHEDULE_FROM_LAST,
+                          _task);
     if (ret != EOK) {
         goto done;
     }
diff --git a/src/providers/be_ptask.h b/src/providers/be_ptask.h
index a33443965..640c8570a 100644
--- a/src/providers/be_ptask.h
+++ b/src/providers/be_ptask.h
@@ -39,33 +39,23 @@ struct be_ptask;
 #define BE_PTASK_NO_PERIODIC         0x0001
 
 /**
- * Defines how should task behave when back end is offline.
+ * Flags defining the starting point for scheduling a task
  */
-enum be_ptask_offline {
-    /* current request will be skipped and rescheduled to 'now + period' */
-    BE_PTASK_OFFLINE_SKIP,
-
-    /* An offline and online callback is registered. The task is disabled
-     * immediately when back end goes offline and then enabled again
-     * when back end goes back online */
-    BE_PTASK_OFFLINE_DISABLE,
-
-    /* current request will be executed as planned */
-    BE_PTASK_OFFLINE_EXECUTE
-};
+/* Schedule starting from now, typically this is used when scheduling
+ * relative to the finish time */
+#define BE_PTASK_SCHEDULE_FROM_NOW   0x0002
+/* Schedule relative to the start time of the task */
+#define BE_PTASK_SCHEDULE_FROM_LAST  0x0004
 
 /**
- * Defines the starting point for scheduling a task
+ * Flags defining how should task behave when back end is offline.
  */
-enum be_ptask_schedule {
-    /* Schedule starting from now, typically this is used when scheduling
-     * relative to the finish time
-     */
-    BE_PTASK_SCHEDULE_FROM_NOW,
-    /* Schedule relative to the start time of the task
-     */
-    BE_PTASK_SCHEDULE_FROM_LAST
-};
+/* current request will be skipped and rescheduled to 'now + period' */
+#define BE_PTASK_OFFLINE_SKIP        0x0008
+/* An offline and online callback is registered. The task is disabled */
+#define BE_PTASK_OFFLINE_DISABLE     0x0010
+/* current request will be executed as planned */
+#define BE_PTASK_OFFLINE_EXECUTE     0x0020
 
 typedef struct tevent_req *
 (*be_ptask_send_t)(TALLOC_CTX *mem_ctx,
@@ -128,8 +118,6 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                         time_t enabled_delay,
                         time_t random_offset,
                         time_t timeout,
-                        enum be_ptask_offline offline,
-                        enum be_ptask_schedule success_schedule_type,
                         time_t max_backoff,
                         be_ptask_send_t send_fn,
                         be_ptask_recv_t recv_fn,
@@ -145,7 +133,6 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
                              time_t enabled_delay,
                              time_t random_offset,
                              time_t timeout,
-                             enum be_ptask_offline offline,
                              time_t max_backoff,
                              be_ptask_sync_t fn,
                              void *pvt,
diff --git a/src/providers/be_ptask_private.h b/src/providers/be_ptask_private.h
index 496a2f9ae..f3e5beec7 100644
--- a/src/providers/be_ptask_private.h
+++ b/src/providers/be_ptask_private.h
@@ -31,8 +31,6 @@ struct be_ptask {
     unsigned int ro_seed;
     time_t timeout;
     time_t max_backoff;
-    enum be_ptask_offline offline;
-    enum be_ptask_schedule success_schedule_type;
     be_ptask_send_t send_fn;
     be_ptask_recv_t recv_fn;
     void *pvt;
diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
index 687d3f022..6cce38390 100644
--- a/src/providers/be_refresh.c
+++ b/src/providers/be_refresh.c
@@ -173,11 +173,12 @@ static errno_t be_refresh_ctx_init(struct be_ctx *be_ctx,
     refresh_interval = be_ctx->domain->refresh_expired_interval;
     if (refresh_interval > 0) {
         ret = be_ptask_create(be_ctx, be_ctx, refresh_interval, 30, 5, 0,
-                              refresh_interval, BE_PTASK_OFFLINE_SKIP,
-                              BE_PTASK_SCHEDULE_FROM_NOW,
-                              0,
+                              refresh_interval, 0,
                               be_refresh_send, be_refresh_recv,
-                              ctx, "Refresh Records", 0, NULL);
+                              ctx, "Refresh Records",
+                              BE_PTASK_OFFLINE_SKIP |
+                              BE_PTASK_SCHEDULE_FROM_NOW,
+                              NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_FATAL_FAILURE,
                   "Unable to initialize refresh periodic task [%d]: %s\n",
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index f21669b8c..ce00231ff 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -130,10 +130,10 @@ void be_mark_offline(struct be_ctx *ctx)
         ret = be_ptask_create_sync(ctx, ctx,
                                    offline_timeout, offline_timeout,
                                    offline_timeout, 30, offline_timeout,
-                                   BE_PTASK_OFFLINE_EXECUTE,
                                    3600 /* max_backoff */,
                                    try_to_go_online,
-                                   ctx, "Check if online (periodic)", 0,
+                                   ctx, "Check if online (periodic)",
+                                   BE_PTASK_OFFLINE_EXECUTE,
                                    &ctx->check_if_online_ptask);
         if (ret != EOK) {
             DEBUG(SSSDBG_FATAL_FAILURE,
diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c
index 27852c2e2..f8831287a 100644
--- a/src/providers/ipa/ipa_dyndns.c
+++ b/src/providers/ipa/ipa_dyndns.c
@@ -74,11 +74,12 @@ errno_t ipa_dyndns_init(struct be_ctx *be_ctx,
     }
 
     ret = be_ptask_create(ctx, be_ctx, period, ptask_first_delay, 0, 0, period,
-                          BE_PTASK_OFFLINE_DISABLE,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
                           0,
                           ipa_dyndns_update_send, ipa_dyndns_update_recv, ctx,
-                          "Dyndns update", 0, NULL);
+                          "Dyndns update",
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index 13e49c5c0..d000f1230 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -3134,11 +3134,12 @@ errno_t ipa_subdomains_init(TALLOC_CTX *mem_ctx,
 
     period = be_ctx->domain->subdomain_refresh_interval;
     ret = be_ptask_create(sd_ctx, be_ctx, period, ptask_first_delay, 0, 0, period,
-                          BE_PTASK_OFFLINE_DISABLE,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
                           0,
                           ipa_subdomains_ptask_send, ipa_subdomains_ptask_recv, sd_ctx,
-                          "Subdomains Refresh", 0, NULL);
+                          "Subdomains Refresh",
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c
index df56f4da4..a62060337 100644
--- a/src/providers/ldap/ldap_id_cleanup.c
+++ b/src/providers/ldap/ldap_id_cleanup.c
@@ -87,8 +87,9 @@ errno_t ldap_setup_cleanup(struct sdap_id_ctx *id_ctx,
 
     ret = be_ptask_create_sync(sdom, id_ctx->be, period, first_delay,
                                5 /* enabled delay */, 0 /* random offset */,
-                               period /* timeout */, BE_PTASK_OFFLINE_SKIP, 0,
-                               ldap_cleanup_task, cleanup_ctx, name, 0,
+                               period /* timeout */, 0,
+                               ldap_cleanup_task, cleanup_ctx, name,
+                               BE_PTASK_OFFLINE_SKIP,
                                &sdom->cleanup_task);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize cleanup periodic "
diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c
index 2137f6821..009d9d275 100644
--- a/src/providers/ldap/ldap_id_enum.c
+++ b/src/providers/ldap/ldap_id_enum.c
@@ -98,11 +98,11 @@ errno_t ldap_setup_enumeration(struct be_ctx *be_ctx,
                           5,                        /* enabled delay */
                           0,                        /* random offset */
                           period,                   /* timeout */
-                          BE_PTASK_OFFLINE_SKIP,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
                           0,                        /* max_backoff */
                           send_fn, recv_fn,
-                          ectx, "enumeration", 0, &sdom->enum_task);
+                          ectx, "enumeration",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &sdom->enum_task);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE,
               "Unable to initialize enumeration periodic task\n");
diff --git a/src/providers/ldap/sdap_sudo_shared.c b/src/providers/ldap/sdap_sudo_shared.c
index 59356bd44..062a95ab6 100644
--- a/src/providers/ldap/sdap_sudo_shared.c
+++ b/src/providers/ldap/sdap_sudo_shared.c
@@ -90,11 +90,12 @@ sdap_sudo_ptask_setup_generic(struct be_ctx *be_ctx,
      * when offline. */
     if (full > 0) {
         ret = be_ptask_create(be_ctx, be_ctx, full, delay, 0, 0, full,
-                              BE_PTASK_OFFLINE_DISABLE,
-                              BE_PTASK_SCHEDULE_FROM_LAST,
                               0,
                               full_send_fn, full_recv_fn, pvt,
-                              "SUDO Full Refresh", 0, NULL);
+                              "SUDO Full Refresh",
+                              BE_PTASK_OFFLINE_DISABLE |
+                              BE_PTASK_SCHEDULE_FROM_LAST,
+                              NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup full refresh ptask "
                   "[%d]: %s\n", ret, sss_strerror(ret));
@@ -109,11 +110,12 @@ sdap_sudo_ptask_setup_generic(struct be_ctx *be_ctx,
      * when offline. */
     if (smart > 0) {
         ret = be_ptask_create(be_ctx, be_ctx, smart, delay + smart, smart, 0,
-                              smart, BE_PTASK_OFFLINE_DISABLE,
-                              BE_PTASK_SCHEDULE_FROM_LAST,
-                              0,
+                              smart,                              0,
                               smart_send_fn, smart_recv_fn, pvt,
-                              "SUDO Smart Refresh", 0, NULL);
+                              "SUDO Smart Refresh",
+                              BE_PTASK_OFFLINE_DISABLE |
+                              BE_PTASK_SCHEDULE_FROM_LAST,
+                              NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup smart refresh ptask "
                   "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/tests/cmocka/test_be_ptask.c b/src/tests/cmocka/test_be_ptask.c
index ac8c0767f..b30775306 100644
--- a/src/tests/cmocka/test_be_ptask.c
+++ b/src/tests/cmocka/test_be_ptask.c
@@ -304,9 +304,10 @@ void test_be_ptask_create_einval_be(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, NULL, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -318,9 +319,10 @@ void test_be_ptask_create_einval_period(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, 0, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -332,9 +334,10 @@ void test_be_ptask_create_einval_send(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, NULL,
-                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -346,9 +349,10 @@ void test_be_ptask_create_einval_recv(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          NULL, NULL, "Test ptask", 0, &ptask);
+                          NULL, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -360,9 +364,72 @@ void test_be_ptask_create_einval_name(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, NULL, 0, &ptask);
+                          test_be_ptask_recv, NULL, NULL,
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
+    assert_int_equal(ret, EINVAL);
+    assert_null(ptask);
+}
+
+void test_be_ptask_mixed_from_flags_einval(void **state)
+{
+    struct test_ctx *test_ctx = (struct test_ctx *)(*state);
+    struct be_ptask *ptask = NULL;
+    errno_t ret;
+
+    ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
+                          0, test_be_ptask_send,
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP |
+                          BE_PTASK_SCHEDULE_FROM_LAST |
+                          BE_PTASK_SCHEDULE_FROM_NOW,
+                          &ptask);
+    assert_int_equal(ret, EINVAL);
+    assert_null(ptask);
+}
+
+void test_be_ptask_no_from_flags_einval(void **state)
+{
+    struct test_ctx *test_ctx = (struct test_ctx *)(*state);
+    struct be_ptask *ptask = NULL;
+    errno_t ret;
+
+    ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
+                          0, test_be_ptask_send,
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP,
+                          &ptask);
+    assert_int_equal(ret, EINVAL);
+    assert_null(ptask);
+}
+void test_be_ptask_mixed_offline_flags_einval(void **state)
+{
+    struct test_ctx *test_ctx = (struct test_ctx *)(*state);
+    struct be_ptask *ptask = NULL;
+    errno_t ret;
+
+    ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
+                          0, test_be_ptask_send,
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP |
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_NOW,
+                          &ptask);
+    assert_int_equal(ret, EINVAL);
+    assert_null(ptask);
+}
+void test_be_ptask_no_offline_flags_einval(void **state)
+{
+    struct test_ctx *test_ctx = (struct test_ctx *)(*state);
+    struct be_ptask *ptask = NULL;
+    errno_t ret;
+
+    ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
+                          0, test_be_ptask_send,
+                          test_be_ptask_recv, NULL, "Test ptask",
+                          BE_PTASK_SCHEDULE_FROM_NOW,
+                          &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -376,9 +443,10 @@ void test_be_ptask_create_no_delay(void **state)
 
     now = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -404,9 +472,10 @@ void test_be_ptask_create_first_delay(void **state)
 
     now = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, DELAY, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -430,9 +499,10 @@ void test_be_ptask_disable(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -455,9 +525,10 @@ void test_be_ptask_enable(void **state)
 
     now = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -488,9 +559,10 @@ void test_be_ptask_enable_delay(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, DELAY, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -528,9 +600,10 @@ void test_be_ptask_offline_skip(void **state)
 
     now = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -562,10 +635,11 @@ void test_be_ptask_offline_disable(void **state)
     will_return(be_add_offline_cb, test_ctx);
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_DISABLE,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_DISABLE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -594,10 +668,11 @@ void test_be_ptask_offline_execute(void **state)
     mark_offline(test_ctx);
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_EXECUTE,
-                          BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_EXECUTE |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -623,9 +698,10 @@ void test_be_ptask_reschedule_ok(void **state)
 
     now = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -655,9 +731,9 @@ void test_be_ptask_reschedule_null(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_null_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0,
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -683,9 +759,9 @@ void test_be_ptask_reschedule_error(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_error_recv, test_ctx, "Test ptask", 0,
+                          test_be_ptask_error_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -711,9 +787,9 @@ void test_be_ptask_reschedule_timeout(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 1,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_timeout_send,
-                          test_be_ptask_error_recv, test_ctx, "Test ptask", 0,
+                          test_be_ptask_error_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -749,9 +825,10 @@ void test_be_ptask_reschedule_backoff(void **state)
 
     now_first = get_current_time();
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           PERIOD*2, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -804,9 +881,10 @@ void test_be_ptask_get_period(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
 
@@ -825,9 +903,10 @@ void test_be_ptask_get_timeout(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, TIMEOUT,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_OFFLINE_SKIP | BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
 
@@ -845,10 +924,12 @@ void test_be_ptask_no_periodic(void **state)
     errno_t ret;
 
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, 0, 0, DELAY, 0, 0,
-                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
                           test_be_ptask_recv, test_ctx, "Test ptask",
-                          BE_PTASK_NO_PERIODIC, &ptask);
+                          BE_PTASK_NO_PERIODIC |
+                          BE_PTASK_OFFLINE_SKIP |
+                          BE_PTASK_SCHEDULE_FROM_LAST,
+                          &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
 
@@ -865,8 +946,8 @@ void test_be_ptask_create_sync(void **state)
 
     now = get_current_time();
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                               BE_PTASK_OFFLINE_SKIP, 0, test_be_ptask_sync,
-                               test_ctx, "Test ptask", 0, &ptask);
+                               0, test_be_ptask_sync, test_ctx, "Test ptask",
+                               BE_PTASK_OFFLINE_SKIP, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -893,8 +974,8 @@ void test_be_ptask_sync_reschedule_ok(void **state)
 
     now = get_current_time();
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                               BE_PTASK_OFFLINE_SKIP, 0, test_be_ptask_sync,
-                               test_ctx, "Test ptask", 0, &ptask);
+                               0, test_be_ptask_sync, test_ctx, "Test ptask",
+                               BE_PTASK_OFFLINE_SKIP, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -924,9 +1005,9 @@ void test_be_ptask_sync_reschedule_error(void **state)
     errno_t ret;
 
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                               BE_PTASK_OFFLINE_SKIP, 0,
-                               test_be_ptask_sync_error,
-                               test_ctx, "Test ptask", 0, &ptask);
+                               0, test_be_ptask_sync_error,
+                               test_ctx, "Test ptask",
+                               BE_PTASK_OFFLINE_SKIP, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -953,10 +1034,11 @@ void test_be_ptask_sync_reschedule_backoff(void **state)
     errno_t ret;
 
     now_first = get_current_time();
-    ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
-                               BE_PTASK_OFFLINE_SKIP, PERIOD*2,
+    ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD,
+                               0, 0, 0, 0, PERIOD*2,
                                test_be_ptask_sync_error,
-                               test_ctx, "Test ptask", 0, &ptask);
+                               test_ctx, "Test ptask",
+                               BE_PTASK_OFFLINE_SKIP, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -1017,6 +1099,10 @@ int main(int argc, const char *argv[])
         new_test(be_ptask_create_einval_send),
         new_test(be_ptask_create_einval_recv),
         new_test(be_ptask_create_einval_name),
+        new_test(be_ptask_mixed_from_flags_einval),
+        new_test(be_ptask_no_from_flags_einval),
+        new_test(be_ptask_mixed_offline_flags_einval),
+        new_test(be_ptask_no_offline_flags_einval),
         new_test(be_ptask_create_no_delay),
         new_test(be_ptask_create_first_delay),
         new_test(be_ptask_disable),
-- 
2.20.1