auth: Add cli_credentials_ccache_reinit()
authorAndreas Schneider <asn@samba.org>
Sat, 1 Oct 2016 09:22:58 +0000 (11:22 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Feb 2019 12:39:20 +0000 (13:39 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
auth/credentials/credentials.h
auth/credentials/credentials_krb5.c

index f16c6f98085621fbc4bc9a9044d593d99bdc9b2e..1d5efc4759fa3ceb1a7535c7fecdda785172c5c0 100644 (file)
@@ -166,6 +166,8 @@ NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
 bool cli_credentials_ccache_init(struct cli_credentials *cred,
                                 struct loadparm_context *lp_ctx,
                                 const char *ccache_name);
+bool cli_credentials_ccache_reinit(struct cli_credentials *cred,
+                                  struct loadparm_context *lp_ctx);
 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
                                              struct loadparm_context *lp_ctx,
                                              const char *serviceprincipal);
index ca5fd964933b364a9f0cf8d6a8c15181767ad99a..45528a77e776eb0588d3917572d98a4b77436ef1 100644 (file)
@@ -325,6 +325,56 @@ done:
        return ok;
 }
 
+/**
+ * @brief Reinitialize the Kerberos credential cache
+ *
+ * If the credential cache is a memory credential cache it will be destroyed
+ * and a new clean cache will be allocated. Existing caches will just be
+ * reopened.
+ *
+ * @param[in]  cred     The credential structure
+ *
+ * @param[in]  lp_ctx   The loadparm context.
+ *
+ * @return true on success, false otherwise.
+ */
+_PUBLIC_ bool cli_credentials_ccache_reinit(struct cli_credentials *cred,
+                                           struct loadparm_context *lp_ctx)
+{
+       krb5_context context;
+       krb5_error_code code;
+       char *tmp_name = NULL;
+       const char *ccache_name;
+       bool ok;
+       int cmp;
+
+       if (cred->krb5_ccache_obtained == CRED_UNINITIALISED) {
+               return false;
+       }
+       context = cred->krb5_ccache->smb_krb5_context->krb5_context;
+
+       code = krb5_cc_get_full_name(context,
+                                    cred->krb5_ccache->ccache,
+                                    &tmp_name);
+       if (code != 0) {
+               return false;
+       }
+
+       ccache_name = tmp_name;
+       cmp = strncasecmp_m(ccache_name, "MEMORY:", 7);
+       if (cmp == 0) {
+               ccache_name = NULL;
+       }
+
+       TALLOC_FREE(cred->krb5_ccache);
+       cred->krb5_ccache_obtained = CRED_UNINITIALISED;
+
+       ok = cli_credentials_ccache_init(cred, lp_ctx, ccache_name);
+       krb5_free_string(context, tmp_name);
+
+       return ok;
+}
+
 static int cli_credentials_set_from_ccache(struct cli_credentials *cred, 
                                           struct ccache_container *ccache,
                                           enum credentials_obtained obtained,