DEBUG(daemon->ctx, "Authenticating as: %s\n", name);
- // Create a new credentials cache
- r = krb5_cc_resolve(daemon->krb5.ctx, KRB5_CREDENTIALS_CACHE, &daemon->krb5.ccache);
- if (r) {
- error = krb5_get_error_message(daemon->krb5.ctx, r);
-
- ERROR(daemon->ctx, "Could not resolve the credentials cache: %s\n", error);
- goto ERROR;
- }
-
- // Initialize the cache for the principal
- r = krb5_cc_initialize(daemon->krb5.ctx, daemon->krb5.ccache, daemon->krb5.principal);
- if (r) {
- error = krb5_get_error_message(daemon->krb5.ctx, r);
-
- ERROR(daemon->ctx, "Could not initialize the credentials cache: %s\n", error);
- goto ERROR;
- }
-
// Set the credentials cache environment variable
r = setenv("KRB5CCNAME", KRB5_CREDENTIALS_CACHE, 1);
if (r < 0) {
DEBUG(daemon->ctx, "Successfully fetched credentials\n");
DEBUG(daemon->ctx, " Expires: %s\n", time);
- // Remove any previous credentials
- r = krb5_cc_remove_cred(daemon->krb5.ctx, daemon->krb5.ccache, 0, &creds);
+ // Destroy the content of the cache
+ if (daemon->krb5.ccache) {
+ r = krb5_cc_destroy(daemon->krb5.ctx, daemon->krb5.ccache);
+ if (r) {
+ error = krb5_get_error_message(daemon->krb5.ctx, r);
+
+ ERROR(daemon->ctx, "Failed to destroy the credentials cache: %s\n", error);
+ r = -ENOTSUP;
+ goto ERROR;
+ }
+ }
+
+ // Create a new credentials cache
+ r = krb5_cc_resolve(daemon->krb5.ctx, KRB5_CREDENTIALS_CACHE, &daemon->krb5.ccache);
if (r) {
error = krb5_get_error_message(daemon->krb5.ctx, r);
- ERROR(daemon->ctx, "Failed to remove credentials: %s\n", error);
+ ERROR(daemon->ctx, "Could not resolve the credentials cache: %s\n", error);
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Initialize the cache for the principal
+ r = krb5_cc_initialize(daemon->krb5.ctx, daemon->krb5.ccache, daemon->krb5.principal);
+ if (r) {
+ error = krb5_get_error_message(daemon->krb5.ctx, r);
+
+ ERROR(daemon->ctx, "Could not initialize the credentials cache: %s\n", error);
+ r = -EINVAL;
goto ERROR;
}
error = krb5_get_error_message(daemon->krb5.ctx, r);
ERROR(daemon->ctx, "Could not store credentials: %s\n", error);
+ r = -EINVAL;
goto ERROR;
}
if (daemon->krb5.principal)
krb5_free_principal(daemon->krb5.ctx, daemon->krb5.principal);
if (daemon->krb5.ccache)
- krb5_cc_close(daemon->krb5.ctx, daemon->krb5.ccache);
+ krb5_cc_destroy(daemon->krb5.ctx, daemon->krb5.ccache);
if (daemon->krb5.ctx)
krb5_free_context(daemon->krb5.ctx);