lib/cmdline: skip the password prompt if we have a valid krb5 ccache
authorStefan Metzmacher <metze@samba.org>
Thu, 14 Apr 2022 11:34:37 +0000 (13:34 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 7 May 2024 11:30:33 +0000 (11:30 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15018

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/cmdline/cmdline.c

index 6f081324e64c3758486fd779e838d0a66be6edc4..be729107f4047cb43a4f44089d9a98dd20eef0ec 100644 (file)
@@ -837,6 +837,25 @@ static void popt_common_credentials_callback(poptContext popt_ctx,
                                                     CRED_SPECIFIED);
                }
 
+               if (cli_credentials_get_kerberos_state(creds) ==
+                   CRED_USE_KERBEROS_REQUIRED)
+               {
+                       enum credentials_obtained ccache_obtained =
+                               CRED_UNINITIALISED;
+                       enum credentials_obtained principal_obtained =
+                               CRED_UNINITIALISED;
+                       bool ccache_valid;
+
+                       principal_obtained =
+                               cli_credentials_get_principal_obtained(creds);
+                       ccache_valid = cli_credentials_get_ccache_name_obtained(
+                               creds, NULL, NULL, &ccache_obtained);
+                       if (ccache_valid &&
+                           ccache_obtained == principal_obtained)
+                       {
+                               skip_password_callback = true;
+                       }
+               }
                if (!skip_password_callback) {
                        (void)cli_credentials_get_password_and_obtained(creds,
                                                                        &password_obtained);