From 77c597c3986a729ca75a26676ed6a38815e9b16b Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Tue, 30 Aug 2011 10:51:19 -0400
Subject: [PATCH] Add option to specify the kerberos replay cache dir

Adds a configure option to set the distribution default as well as
an sssd.conf option to override it.

https://fedorahosted.org/sssd/ticket/980
---
 configure.ac            |    1 +
 src/conf_macros.m4      |   15 +++++++++++++++
 src/confdb/confdb.h     |    1 +
 src/man/sssd.conf.5.xml |   14 ++++++++++++++
 src/monitor/monitor.c   |   23 +++++++++++++++++++++++
 5 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index 770371d54a9d6e29833ecc92f4c4ae7d7c4073e5..230afa21dbfd902ecdeb855051d774eaedbe81e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,7 @@ WITH_TEST_DIR
 WITH_MANPAGES
 WITH_XML_CATALOG
 WITH_KRB5_PLUGIN_PATH
+WITH_KRB5_RCACHE_DIR
 WITH_PYTHON_BINDINGS
 WITH_SELINUX
 WITH_NSCD
diff --git a/src/conf_macros.m4 b/src/conf_macros.m4
index 1e503b3e397dd5e7e29763713a72d0e6bcdf92b6..6e9ba019016a6df97549ed37000bf656c5a302b1 100644
--- a/src/conf_macros.m4
+++ b/src/conf_macros.m4
@@ -204,6 +204,21 @@ AC_DEFUN([WITH_KRB5_PLUGIN_PATH],
     AC_SUBST(krb5pluginpath)
   ])
 
+AC_DEFUN([WITH_KRB5_RCACHE_DIR],
+  [ AC_ARG_WITH([krb5-rcache-dir],
+                [AC_HELP_STRING([--with-krb5-rcache-dir=PATH],
+                                [Path to store Kerberos replay caches [/var/cache/krb5rcache]]
+                               )
+                ]
+               )
+    krb5rcachedir="${localstatedir}/cache/krb5rcache"
+    if test x"$with_krb5_rcache_dir" != x; then
+        krb5rcachedir=$with_krb5_rcache_dir
+    fi
+    AC_SUBST(krb5rcachedir)
+    AC_DEFINE_UNQUOTED(KRB5_RCACHE_DIR, "$krb5rcachedir", [Directory used for storing Kerberos replay caches])
+  ])
+
 AC_DEFUN([WITH_PYTHON_BINDINGS],
   [ AC_ARG_WITH([python-bindings],
                 [AC_HELP_STRING([--with-python-bindings],
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index 5e50991f3014019b0c8fd065f4728827d959f06b..e982d17983eb68b3cde4d58b4289a447c723f90e 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -63,6 +63,7 @@
 #define CONFDB_MONITOR_NAME_REGEX   "re_expression"
 #define CONFDB_MONITOR_FULL_NAME_FORMAT "full_name_format"
 #define CONFDB_MONITOR_TRY_INOTIFY "try_inotify"
+#define CONFDB_MONITOR_KRB5_RCACHEDIR "krb5_rcachedir"
 
 /* NSS */
 #define CONFDB_NSS_CONF_ENTRY "config/nss"
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
index 6f85dda9e38a99bde3886666dfeefc9312592d2c..5b7ad1202d9b9b84593c4e3b2eb279e52042954a 100644
--- a/src/man/sssd.conf.5.xml
+++ b/src/man/sssd.conf.5.xml
@@ -185,6 +185,20 @@
                             </para>
                         </listitem>
                     </varlistentry>
+                    <varlistentry>
+                        <term>krb5_rcache_dir (string)</term>
+                        <listitem>
+                            <para>
+                                Directory on the filesystem where SSSD should
+                                store Kerberos replay cache files.
+                            </para>
+                            <para>
+                                Default: Distribution-specific and specified
+                                at build-time. (/var/cache/krb5rcache on
+                                Fedora)
+                            </para>
+                        </listitem>
+                    </varlistentry>
                 </variablelist>
             </para>
         </refsect2>
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index dd099841815b1620b1a64014c92a221d38cb5c4f..ff3dff2b989ec286cb78da37f548f6d86244f2e1 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -1926,8 +1926,31 @@ int monitor_process_init(struct mt_ctx *ctx,
     struct sysdb_ctx_list *db_list;
     struct tevent_signal *tes;
     struct sss_domain_info *dom;
+    char *rcachedir;
     int num_providers;
     int ret;
+    int error;
+
+    /* Set up the environment variable for the Kerberos Replay Cache */
+    ret = confdb_get_string(ctx->cdb, ctx,
+                            CONFDB_MONITOR_CONF_ENTRY,
+                            CONFDB_MONITOR_KRB5_RCACHEDIR,
+                            KRB5_RCACHE_DIR,
+                            &rcachedir);
+    if (ret != EOK) {
+        return ret;
+    }
+
+    errno = 0;
+    ret = setenv("KRB5RCACHEDIR", rcachedir, 1);
+    if (ret < 0) {
+        error = errno;
+        DEBUG(1,
+              ("Unable to set KRB5RCACHEDIR: %s."
+               "Will attempt to use libkrb5 defaults\n",
+               strerror(error)));
+    }
+    talloc_zfree(rcachedir);
 
     /* Set up an event handler for a SIGHUP */
     tes = tevent_add_signal(ctx->ev, ctx, SIGHUP, 0,
-- 
1.7.6

