From: bharathsm.hsk@gmail.com
To: linux-cifs@vger.kernel.org, sfrench@samba.org, metze@samba.org,
jlayton@samba.org, pshilovsky@samba.org, pc@manguebit.com,
dhowells@redhat.com, sprasad@microsoft.com,
rbudhiraja@microsoft.com
Cc: Bharath SM <bharathsm@microsoft.com>
Subject: [PATCH] cifs-utils: Skip TGT check if valid service ticket is already available
Date: Tue, 26 Nov 2024 22:57:44 +0530 [thread overview]
Message-ID: <20241126172744.25894-1-bharathsm.hsk@gmail.com> (raw)
From: Bharath SM <bharathsm@microsoft.com>
When handling upcalls from the kernel for SMB session setup requests using
Kerberos authentication, if the credential cache already contains a valid
service ticket, it can be used directly without checking for the TGT again.
Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
cifs.upcall.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 6 deletions(-)
diff --git a/cifs.upcall.c b/cifs.upcall.c
index ff6f2bd..4ad0c8e 100644
--- a/cifs.upcall.c
+++ b/cifs.upcall.c
@@ -552,11 +552,6 @@ get_existing_cc(const char *env_cachename)
syslog(LOG_DEBUG, "%s: default ccache is %s\n", __func__, cachename);
krb5_free_string(context, cachename);
}
-
- if (!get_tgt_time(cc)) {
- krb5_cc_close(context, cc);
- cc = NULL;
- }
return cc;
}
@@ -638,6 +633,49 @@ icfk_cleanup:
#define CIFS_SERVICE_NAME "cifs"
+static krb5_error_code check_service_ticket_exists(krb5_ccache ccache,
+ const char *hostname) {
+
+ krb5_error_code rc;
+ krb5_creds mcreds, out_creds;
+
+ memset(&mcreds, 0, sizeof(mcreds));
+
+ rc = krb5_cc_get_principal(context, ccache, &mcreds.client);
+ if (rc) {
+ syslog(LOG_DEBUG, "%s: unable to get client principal from cache: %s",
+ __func__, krb5_get_error_message(context, rc));
+ return rc;
+ }
+
+ rc = krb5_sname_to_principal(context, hostname, CIFS_SERVICE_NAME,
+ KRB5_NT_UNKNOWN, &mcreds.server);
+ if (rc) {
+ syslog(LOG_DEBUG, "%s: unable to convert service name (%s) to principal: %s",
+ __func__, hostname, krb5_get_error_message(context, rc));
+ krb5_free_principal(context, mcreds.client);
+ return rc;
+ }
+
+ rc = krb5_timeofday(context, &mcreds.times.endtime);
+ if (rc) {
+ syslog(LOG_DEBUG, "%s: unable to get time: %s",
+ __func__, krb5_get_error_message(context, rc));
+ goto out_free_principal;
+ }
+
+ rc = krb5_cc_retrieve_cred(context, ccache, KRB5_TC_MATCH_TIMES, &mcreds, &out_creds);
+
+ if (!rc)
+ krb5_free_cred_contents(context, &out_creds);
+
+out_free_principal:
+ krb5_free_principal(context, mcreds.server);
+ krb5_free_principal(context, mcreds.client);
+
+ return rc;
+}
+
static int
cifs_krb5_get_req(const char *host, krb5_ccache ccache,
DATA_BLOB * mechtoken, DATA_BLOB * sess_key)
@@ -1516,12 +1554,26 @@ int main(const int argc, char *const argv[])
goto out;
}
+ host = arg->hostname;
ccache = get_existing_cc(env_cachename);
+ if (ccache != NULL) {
+ rc = check_service_ticket_exists(ccache, host);
+ if(rc == 0) {
+ syslog(LOG_DEBUG, "%s: valid service ticket exists in credential cache",
+ __func__);
+ } else {
+ if (!get_tgt_time(ccache)) {
+ syslog(LOG_DEBUG, "%s: valid TGT is not present in credential cache",
+ __func__);
+ krb5_cc_close(context, ccache);
+ ccache = NULL;
+ }
+ }
+ }
/* Couldn't find credcache? Try to use keytab */
if (ccache == NULL && arg->username[0] != '\0')
ccache = init_cc_from_keytab(keytab_name, arg->username);
- host = arg->hostname;
// do mech specific authorization
switch (arg->sec) {
--
2.43.0
next reply other threads:[~2024-11-26 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 17:27 bharathsm.hsk [this message]
2024-12-05 5:47 ` [PATCH] cifs-utils: Skip TGT check if valid service ticket is already available Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241126172744.25894-1-bharathsm.hsk@gmail.com \
--to=bharathsm.hsk@gmail.com \
--cc=bharathsm@microsoft.com \
--cc=dhowells@redhat.com \
--cc=jlayton@samba.org \
--cc=linux-cifs@vger.kernel.org \
--cc=metze@samba.org \
--cc=pc@manguebit.com \
--cc=pshilovsky@samba.org \
--cc=rbudhiraja@microsoft.com \
--cc=sfrench@samba.org \
--cc=sprasad@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox