From c90f8c36322f8e8d9e5368f7005a661fff0a97e1 Mon Sep 17 00:00:00 2001
From: Ondrej Kos <okos@redhat.com>
Date: Mon, 5 Aug 2013 14:44:31 +0200
Subject: [PATCH 1/5] Make subdomain refresh period configurable

Adds following config file options:

ad_subdomain_refresh_period
ipa_subdomain_refresh_period

Both are in seconds and have the same usage - setting the refresh period
of AD/IPA subdomains.
---
 src/config/SSSDConfig/__init__.py.in    |  1 +
 src/config/etc/sssd.api.d/sssd-ad.conf  |  1 +
 src/config/etc/sssd.api.d/sssd-ipa.conf |  1 +
 src/man/sssd-ad.5.xml                   | 13 +++++++++++++
 src/man/sssd-ipa.5.xml                  | 13 +++++++++++++
 src/providers/ad/ad_opts.h              |  1 +
 src/providers/ad/ad_subdomains.c        |  9 +++++----
 src/providers/ipa/ipa_opts.h            |  1 +
 src/providers/ipa/ipa_subdomains.c      |  8 +++++---
 src/providers/ldap/ldap_opts.h          |  1 +
 src/providers/ldap/sdap.h               |  1 +
 11 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/config/SSSDConfig/__init__.py.in b/src/config/SSSDConfig/__init__.py.in
index f073419e9c0aacdaad4343d05e58a6a2c9a732e2..4e7750129443b5ffcf57d94af26dde7cc0f5856c 100644
--- a/src/config/SSSDConfig/__init__.py.in
+++ b/src/config/SSSDConfig/__init__.py.in
@@ -312,6 +312,7 @@ option_strings = {
     'ldap_initgroups_use_matching_rule_in_chain' : _('Use LDAP_MATCHING_RULE_IN_CHAIN for initgroup lookups'),
     'ldap_min_id' : _('Set lower boundary for allowed IDs from the LDAP server'),
     'ldap_max_id' : _('Set upper boundary for allowed IDs from the LDAP server'),
+    'subdomain_refresh_period': _("How often should be subdomains list refreshed"),
 
     # [provider/ldap/auth]
     'ldap_pwd_policy' : _('Policy to evaluate the password expiration'),
diff --git a/src/config/etc/sssd.api.d/sssd-ad.conf b/src/config/etc/sssd.api.d/sssd-ad.conf
index 120c827523d5b103396b3a38bca8cc75b25d0cc2..63bb63ac94348d0a20595cdfdac372442b5cf5b6 100644
--- a/src/config/etc/sssd.api.d/sssd-ad.conf
+++ b/src/config/etc/sssd.api.d/sssd-ad.conf
@@ -42,6 +42,7 @@ ldap_page_size = int, None, false
 ldap_deref_threshold = int, None, false
 ldap_connection_expire_timeout = int, None, false
 ldap_disable_paging = bool, None, false
+subdomain_refresh_period = int, None, false
 
 [provider/ad/id]
 ldap_search_timeout = int, None, false
diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index bc14fbe3d4153bd7a7ca4ffe0351edf0b8c02ee4..e69c9bc934ef88997be598fcb8cc562eda7aeacb 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -51,6 +51,7 @@ ldap_page_size = int, None, false
 ldap_deref_threshold = int, None, false
 ldap_connection_expire_timeout = int, None, false
 ldap_disable_paging = bool, None, false
+subdomain_refresh_period = int, None, false
 
 [provider/ipa/id]
 ldap_search_timeout = int, None, false
diff --git a/src/man/sssd-ad.5.xml b/src/man/sssd-ad.5.xml
index 4a8c60b49e4ac30788d1f07b50ea05274d1686e5..1ae0d0ec4cf86296892f73845d64e3a34d6934db 100644
--- a/src/man/sssd-ad.5.xml
+++ b/src/man/sssd-ad.5.xml
@@ -164,6 +164,19 @@ ldap_id_mapping = False
                 </varlistentry>
 
                 <varlistentry>
+                    <term>subdomain_refresh_period (integer)</term>
+                    <listitem>
+                        <para>
+                            Optional. Specifies how often should SSSD refresh
+                            the list of subdomains.
+                        </para>
+                        <para>
+                            Default: 14400 (seconds)
+                        </para>
+                    </listitem>
+                </varlistentry>
+
+                <varlistentry>
                     <term>dyndns_update (boolean)</term>
                     <listitem>
                         <para>
diff --git a/src/man/sssd-ipa.5.xml b/src/man/sssd-ipa.5.xml
index 28ac252abbeb508d62ca1a94f2440afc6b5b5c88..4be506b1db845f07008b0ee1066be62b6006bede 100644
--- a/src/man/sssd-ipa.5.xml
+++ b/src/man/sssd-ipa.5.xml
@@ -208,6 +208,19 @@
                 </varlistentry>
 
                 <varlistentry>
+                    <term>subdomain_refresh_period (integer)</term>
+                    <listitem>
+                        <para>
+                            Optional. Specifies how often should SSSD refresh
+                            the list of subdomains.
+                        </para>
+                        <para>
+                            Default: 14400 (seconds)
+                        </para>
+                    </listitem>
+                </varlistentry>
+
+                <varlistentry>
                     <term>dyndns_refresh_interval (integer)</term>
                     <listitem>
                         <para>
diff --git a/src/providers/ad/ad_opts.h b/src/providers/ad/ad_opts.h
index f3b6cd61632601ec92a408a6a73cff6446fd48bf..050c35e1ef72af4375e58971014ec0e6fbe6ff57 100644
--- a/src/providers/ad/ad_opts.h
+++ b/src/providers/ad/ad_opts.h
@@ -126,6 +126,7 @@ struct dp_option ad_def_ldap_opts[] = {
     { "ldap_disable_range_retrieval", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ldap_min_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
     { "ldap_max_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
+    { "subdomain_refresh_period", DP_OPT_NUMBER, {.number = 14400}, NULL_NUMBER}, /* 4 hours */
     DP_OPTION_TERMINATOR
 };
 
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index afd2031fe6be557f43555b6dd8b47731d9833585..e6d85541d0f93af4ed7dcabce2236c4d225a326e 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -55,9 +55,6 @@
 /* do not refresh more often than every 5 seconds for now */
 #define AD_SUBDOMAIN_REFRESH_LIMIT 5
 
-/* refresh automatically every 4 hours */
-#define AD_SUBDOMAIN_REFRESH_PERIOD (3600 * 4)
-
 struct ad_subdomains_ctx {
     struct be_ctx *be_ctx;
     struct sdap_id_ctx *sdap_id_ctx;
@@ -714,6 +711,7 @@ static void ad_subdom_online_cb(void *pvt)
     struct ad_subdomains_ctx *ctx;
     struct be_req *be_req;
     struct timeval tv;
+    int refresh_period;
 
     ctx = talloc_get_type(pvt, struct ad_subdomains_ctx);
     if (!ctx) {
@@ -730,7 +728,10 @@ static void ad_subdom_online_cb(void *pvt)
 
     ad_subdomains_retrieve(ctx, be_req);
 
-    tv = tevent_timeval_current_ofs(AD_SUBDOMAIN_REFRESH_PERIOD, 0);
+    refresh_period = dp_opt_get_int(ctx->sdap_id_ctx->opts->basic,
+            SDAP_SUBDOMAIN_REFRESH_PERIOD);
+
+    tv = tevent_timeval_current_ofs(refresh_period, 0);
     ctx->timer_event = tevent_add_timer(ctx->be_ctx->ev, ctx, tv,
                                         ad_subdom_timer_refresh, ctx);
     if (!ctx->timer_event) {
diff --git a/src/providers/ipa/ipa_opts.h b/src/providers/ipa/ipa_opts.h
index 5ec36c550b166e07a9ed2f2c31474c55d0ecdaee..7c5d0102e4a2bc2ae9e74670140083e80d4c4ad9 100644
--- a/src/providers/ipa/ipa_opts.h
+++ b/src/providers/ipa/ipa_opts.h
@@ -151,6 +151,7 @@ struct dp_option ipa_def_ldap_opts[] = {
     { "ldap_disable_range_retrieval", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ldap_min_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
     { "ldap_max_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
+    { "subdomain_refresh_period", DP_OPT_NUMBER, {.number = 14400}, NULL_NUMBER}, /* 4 hours */
     DP_OPTION_TERMINATOR
 };
 
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index c28af0e76a41352b80ab816076de156607243c1d..15d71c6ebfee405ec54e4a5c48e36ee39b9b1c86 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -47,8 +47,6 @@
 /* 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_REFRESH_PERIOD (3600 * 4)
 #define IPA_SUBDOMAIN_DISABLED_PERIOD 3600
 
 enum ipa_subdomains_req_type {
@@ -1018,6 +1016,7 @@ static void ipa_subdom_online_cb(void *pvt)
     struct ipa_subdomains_ctx *ctx;
     struct be_req *be_req;
     struct timeval tv;
+    int refresh_period;
 
     ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
     if (!ctx) {
@@ -1036,7 +1035,10 @@ static void ipa_subdom_online_cb(void *pvt)
 
     ipa_subdomains_retrieve(ctx, be_req);
 
-    tv = tevent_timeval_current_ofs(IPA_SUBDOMAIN_REFRESH_PERIOD, 0);
+    refresh_period = dp_opt_get_int(ctx->sdap_id_ctx->opts->basic,
+            SDAP_SUBDOMAIN_REFRESH_PERIOD);
+
+    tv = tevent_timeval_current_ofs(refresh_period, 0);
     ctx->timer_event = tevent_add_timer(ctx->be_ctx->ev, ctx, tv,
                                         ipa_subdom_timer_refresh, ctx);
     if (!ctx->timer_event) {
diff --git a/src/providers/ldap/ldap_opts.h b/src/providers/ldap/ldap_opts.h
index a6c821f3ac3ad951a3b45168b298b96fefb96b60..fb024cf87aff050e5af03c9e8e3acef1d2e312ee 100644
--- a/src/providers/ldap/ldap_opts.h
+++ b/src/providers/ldap/ldap_opts.h
@@ -117,6 +117,7 @@ struct dp_option default_basic_opts[] = {
     { "ldap_disable_range_retrieval", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ldap_min_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
     { "ldap_max_id", DP_OPT_NUMBER, NULL_NUMBER, NULL_NUMBER},
+    { "subdomain_refresh_period", DP_OPT_NUMBER, {.number = 14400}, NULL_NUMBER}, /* 4 hours */
     DP_OPTION_TERMINATOR
 };
 
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 441ac904bd2d03618376f6770304dc5c4db75923..8f10300fd622a0bc0bec2879d228a970811a8a59 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -221,6 +221,7 @@ enum sdap_basic_opt {
     SDAP_DISABLE_RANGE_RETRIEVAL,
     SDAP_MIN_ID,
     SDAP_MAX_ID,
+    SDAP_SUBDOMAIN_REFRESH_PERIOD,
 
     SDAP_OPTS_BASIC /* opts counter */
 };
-- 
1.8.1.4

