>From 4f6d042e39cee30bca754196e12e04a643936f95 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 21 Aug 2013 12:44:47 -0400
Subject: [PATCH 5/7] KRB5: Add new #define for collection cache types

Kerberos now supports multiple types of collection caches, not just
DIR: caches. We should add a macro for generic collection behavior
and use that where appropriate.
---
 src/providers/krb5/krb5_child.c  | 16 ++++++++--------
 src/providers/krb5/krb5_common.c |  4 ++--
 src/providers/krb5/krb5_utils.c  | 12 ++++++------
 src/providers/krb5/krb5_utils.h  |  4 ++--
 src/tests/krb5_child-test.c      |  4 ++--
 src/tests/krb5_utils-tests.c     |  8 ++++----
 src/util/sss_krb5.c              | 16 ++++++++--------
 src/util/sss_krb5.h              |  6 +++---
 8 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/providers/krb5/krb5_child.c b/src/providers/krb5/krb5_child.c
index 4ba0f366078cd00bf0d935757f902ff3d64e6f04..8fce600fe0fb8904f9652c7128c614c58d612e6d 100644
--- a/src/providers/krb5/krb5_child.c
+++ b/src/providers/krb5/krb5_child.c
@@ -436,7 +436,7 @@ done:
     return kerr;
 }
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
 static bool need_switch_to_principal(krb5_context ctx, krb5_principal princ)
 {
     krb5_error_code kerr;
@@ -497,7 +497,7 @@ done:
 
     return ret;
 }
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
 static krb5_error_code
 store_creds_in_ccache(krb5_context ctx, krb5_principal princ,
@@ -528,7 +528,7 @@ store_creds_in_ccache(krb5_context ctx, krb5_principal princ,
         goto done;
     }
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     if (need_switch_to_principal(ctx, princ)) {
         kerr = krb5_cc_switch(ctx, cc);
         if (kerr != 0) {
@@ -536,7 +536,7 @@ store_creds_in_ccache(krb5_context ctx, krb5_principal princ,
             goto done;
         }
     }
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
     kerr = krb5_cc_close(ctx, cc);
     if (kerr != 0) {
@@ -654,7 +654,7 @@ done:
     return kerr;
 }
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
 
 static errno_t
 create_ccdir(const char *dirname, uid_t uid, gid_t gid)
@@ -781,7 +781,7 @@ done:
     return kerr;
 }
 
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
 static krb5_error_code
 create_ccache(uid_t uid, gid_t gid, krb5_context ctx,
@@ -793,10 +793,10 @@ create_ccache(uid_t uid, gid_t gid, krb5_context ctx,
     switch (cctype) {
         case SSS_KRB5_TYPE_FILE:
             return create_ccache_file(ctx, princ, ccname, creds);
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
         case SSS_KRB5_TYPE_DIR:
             return create_ccache_in_dir(uid, gid, ctx, princ, ccname, creds);
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
         default:
             DEBUG(SSSDBG_CRIT_FAILURE, ("Unknown cache type\n"));
             return EINVAL;
diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c
index 0e1c10becf177051282a99685dadbf37e0b61e7b..e56dc6245dd6f334a510459f31332ac3dfdad52d 100644
--- a/src/providers/krb5/krb5_common.c
+++ b/src/providers/krb5/krb5_common.c
@@ -210,12 +210,12 @@ errno_t check_and_export_options(struct dp_option *opts,
         }
         break;
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     case SSS_KRB5_TYPE_DIR:
         DEBUG(SSSDBG_CONF_SETTINGS, ("ccache is of type DIR\n"));
         krb5_ctx->cc_be = &dir_cc;
         break;
-#endif
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
     default:
         DEBUG(SSSDBG_OP_FAILURE, ("Unknown ccname database\n"));
diff --git a/src/providers/krb5/krb5_utils.c b/src/providers/krb5/krb5_utils.c
index 883a3980077610dd0569a00438ed051da510227f..13ba9b5f9c1c4d4c40f125f451a4ba6e41baa961 100644
--- a/src/providers/krb5/krb5_utils.c
+++ b/src/providers/krb5/krb5_utils.c
@@ -769,11 +769,11 @@ get_cc_be_ops(enum sss_krb5_cc_type type)
             be = &file_cc;
             break;
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
         case SSS_KRB5_TYPE_DIR:
             be = &dir_cc;
             break;
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
         case SSS_KRB5_TYPE_UNKNOWN:
             be = NULL;
@@ -846,11 +846,11 @@ cc_residual_is_used(uid_t uid, const char *ccname,
     }
 
     switch (type) {
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
         case SSS_KRB5_TYPE_DIR:
             ret = S_ISDIR(stat_buf.st_mode);
             break;
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
         case SSS_KRB5_TYPE_FILE:
             ret = S_ISREG(stat_buf.st_mode);
             break;
@@ -984,7 +984,7 @@ struct sss_krb5_cc_be file_cc = {
     .remove             = cc_file_remove,
 };
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
 /*======== Operations on the DIR: back end ========*/
 errno_t
 cc_dir_create(const char *location, pcre *illegal_re,
@@ -1187,7 +1187,7 @@ struct sss_krb5_cc_be dir_cc = {
     .remove             = cc_dir_remove
 };
 
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
 errno_t get_domain_or_subdomain(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
                                 char *domain_name,
diff --git a/src/providers/krb5/krb5_utils.h b/src/providers/krb5/krb5_utils.h
index 2e1bec717ac7c3ac1c9bb87392d011eb854f21be..4a5904cd7270e5e22c8f9647f5c5cd3b31272a10 100644
--- a/src/providers/krb5/krb5_utils.h
+++ b/src/providers/krb5/krb5_utils.h
@@ -84,14 +84,14 @@ errno_t become_user(uid_t uid, gid_t gid);
 errno_t get_ccache_file_data(const char *ccache_file, const char *client_name,
                              struct tgt_times *tgtt);
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
 
 extern struct sss_krb5_cc_be dir_cc;
 
 errno_t cc_dir_create(const char *location, pcre *illegal_re,
                       uid_t uid, gid_t gid, bool private_path);
 
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
 errno_t get_domain_or_subdomain(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
                                 char *domain_name,
diff --git a/src/tests/krb5_child-test.c b/src/tests/krb5_child-test.c
index 423f8bb8427df8e8c1be25113f1406cff8def2c4..24d077289d64d52488a3419ffc4494f59d6bc5df 100644
--- a/src/tests/krb5_child-test.c
+++ b/src/tests/krb5_child-test.c
@@ -267,11 +267,11 @@ create_dummy_req(TALLOC_CTX *mem_ctx, const char *user,
     case SSS_KRB5_TYPE_FILE:
         kr->krb5_ctx->cc_be = &file_cc;
         break;
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     case SSS_KRB5_TYPE_DIR:
         kr->krb5_ctx->cc_be = &dir_cc;
         break;
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
     default:
         if (tmpl[0] != '/') {
             DEBUG(SSSDBG_OP_FAILURE, ("Unkown ccname database\n"));
diff --git a/src/tests/krb5_utils-tests.c b/src/tests/krb5_utils-tests.c
index fdfe00ac2e2ab8e0ed099d4aea43d610210426a7..4be3ad04eff73b9f27a05efcfa6a93f57ec8105f 100644
--- a/src/tests/krb5_utils-tests.c
+++ b/src/tests/krb5_utils-tests.c
@@ -357,7 +357,7 @@ START_TEST(test_illegal_patterns)
 }
 END_TEST
 
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
 START_TEST(test_cc_dir_create)
 {
     char *residual;
@@ -408,7 +408,7 @@ START_TEST(test_cc_dir_create)
     free(cwd);
 }
 END_TEST
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 
 
 void setup_talloc_context(void)
@@ -744,9 +744,9 @@ Suite *krb5_utils_suite (void)
     tcase_add_checked_fixture (tc_create_dir, setup_create_dir,
                                teardown_create_dir);
     tcase_add_test (tc_create_dir, test_illegal_patterns);
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     tcase_add_test (tc_create_dir, test_cc_dir_create);
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
     if (getuid() == 0) {
         tcase_add_test (tc_create_dir, test_priv_ccache_dir);
         tcase_add_test (tc_create_dir, test_private_ccache_dir_in_user_dir);
diff --git a/src/util/sss_krb5.c b/src/util/sss_krb5.c
index b871b13c33e601513d3d9ea49cfa2c7aca0cf886..77234b9898be1dac95b310f045243e3916e85203 100644
--- a/src/util/sss_krb5.c
+++ b/src/util/sss_krb5.c
@@ -939,12 +939,12 @@ sss_krb5_get_type(const char *full_location)
                 sizeof(SSS_KRB5_FILE)-1) == 0) {
         return SSS_KRB5_TYPE_FILE;
     }
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     else if (strncmp(full_location, SSS_KRB5_DIR,
                sizeof(SSS_KRB5_DIR)-1) == 0) {
         return SSS_KRB5_TYPE_DIR;
     }
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
     else if (full_location[0] == '/') {
         return SSS_KRB5_TYPE_FILE;
     }
@@ -968,11 +968,11 @@ sss_krb5_residual_by_type(const char *full_location,
                 offset = sizeof(SSS_KRB5_FILE)-1;
             }
             break;
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
         case SSS_KRB5_TYPE_DIR:
             offset = sizeof(SSS_KRB5_DIR)-1;
             break;
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
         default:
             return NULL;
     }
@@ -992,14 +992,14 @@ sss_krb5_cc_file_path(const char *full_location)
     switch(cc_type) {
         case SSS_KRB5_TYPE_FILE:
             return residual;
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
         case SSS_KRB5_TYPE_DIR:
             /* DIR::/run/user/tkt_foo */
             if (residual[0] == ':') {
                 ++residual;
             }
             return residual;
-#endif
+#endif /* HAVE_KRB5_CC_COLLECTION */
         case SSS_KRB5_TYPE_UNKNOWN:
             break;
     }
@@ -1185,7 +1185,7 @@ char * sss_get_ccache_name_for_principal(TALLOC_CTX *mem_ctx,
                                          krb5_principal principal,
                                          const char *location)
 {
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     krb5_error_code kerr;
     krb5_ccache tmp_cc = NULL;
     char *tmp_ccname = NULL;
@@ -1229,5 +1229,5 @@ done:
     return ret_ccname;
 #else
     return NULL;
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
 }
diff --git a/src/util/sss_krb5.h b/src/util/sss_krb5.h
index 601a8acf90d9784d064d078cc158b07531cbcd8f..1c10d471336d871909c6d5312b2fce53ba5091c7 100644
--- a/src/util/sss_krb5.h
+++ b/src/util/sss_krb5.h
@@ -45,7 +45,7 @@
 #define KEYTAB_CLEAN_NAME keytab_name ? keytab_name : "default"
 
 #if defined HAVE_KRB5_CC_CACHE_MATCH && defined HAVE_KRB5_CC_GET_FULL_NAME
-#define HAVE_KRB5_DIRCACHE 1
+#define HAVE_KRB5_CC_COLLECTION 1
 #endif
 
 const char * KRB5_CALLCONV sss_krb5_get_error_message (krb5_context,
@@ -145,9 +145,9 @@ void sss_krb5_get_init_creds_opt_set_canonicalize(krb5_get_init_creds_opt *opts,
 
 enum sss_krb5_cc_type {
     SSS_KRB5_TYPE_FILE,
-#ifdef HAVE_KRB5_DIRCACHE
+#ifdef HAVE_KRB5_CC_COLLECTION
     SSS_KRB5_TYPE_DIR,
-#endif /* HAVE_KRB5_DIRCACHE */
+#endif /* HAVE_KRB5_CC_COLLECTION */
     SSS_KRB5_TYPE_UNKNOWN
 };
 
-- 
1.8.3.1

