auth: Add new cli_credentials_ccache_destroy() function
authorAndreas Schneider <asn@samba.org>
Sat, 1 Oct 2016 09:37:39 +0000 (11:37 +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 1d5efc4759fa3ceb1a7535c7fecdda785172c5c0..5a5bbb2c3bd1d5d2df443d5c76460b7d16b0f423 100644 (file)
@@ -168,6 +168,7 @@ bool cli_credentials_ccache_init(struct cli_credentials *cred,
                                 const char *ccache_name);
 bool cli_credentials_ccache_reinit(struct cli_credentials *cred,
                                   struct loadparm_context *lp_ctx);
+bool cli_credentials_ccache_destroy(struct cli_credentials *cred);
 NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
                                              struct loadparm_context *lp_ctx,
                                              const char *serviceprincipal);
index 45528a77e776eb0588d3917572d98a4b77436ef1..46a7b05fe682ada1f3435bb9ea6cfa0ca7de65a8 100644 (file)
@@ -325,6 +325,33 @@ done:
        return ok;
 }
 
+/**
+ * @brief Destroy a Kerberos credential cache.
+ *
+ * This function destroys any existing contents of a cache and closes it.
+ *
+ * @param[in]  cred     The cli_credentials structure.
+ *
+ * @return true on success, false otherwise.
+ */
+_PUBLIC_ bool cli_credentials_ccache_destroy(struct cli_credentials *cred)
+{
+       struct ccache_container *ccc = cred->krb5_ccache;
+       krb5_error_code code;
+
+       code = krb5_cc_destroy(ccc->smb_krb5_context->krb5_context,
+                              ccc->ccache);
+       if (code != 0) {
+               return false;
+       }
+       ccc->ccache = NULL;
+
+       TALLOC_FREE(cred->krb5_ccache);
+       cred->krb5_ccache_obtained = CRED_UNINITIALISED;
+
+       return true;
+}
+
 /**
  * @brief Reinitialize the Kerberos credential cache
  *