s3:winbind: Create service principal inside add_ccache_to_list()
authorSamuel Cabrero <scabrero@samba.org>
Thu, 7 Jul 2022 09:22:05 +0000 (11:22 +0200)
committerJule Anger <janger@samba.org>
Mon, 18 Jul 2022 09:45:11 +0000 (09:45 +0000)
The function can build the service principal itself, there is no
need to do it in the caller. This removes code duplication.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14979

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit 8bef8e3de9fc96ff45319f80529e878977563f3a)

source3/winbindd/winbindd_cred_cache.c
source3/winbindd/winbindd_pam.c
source3/winbindd/winbindd_proto.h

index 6c65db6a73f2e10ffa194d6854ba7d9b83754753..2fbef1ec8a94c4c0a8c3608da8e944ac7e6ea5df 100644 (file)
@@ -493,7 +493,6 @@ bool ccache_entry_identical(const char *username,
 
 NTSTATUS add_ccache_to_list(const char *princ_name,
                            const char *ccname,
-                           const char *service,
                            const char *username,
                            const char *pass,
                            const char *realm,
@@ -613,12 +612,6 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
                        goto no_mem;
                }
        }
-       if (service) {
-               entry->service = talloc_strdup(entry, service);
-               if (!entry->service) {
-                       goto no_mem;
-               }
-       }
        if (canon_principal != NULL) {
                entry->canon_principal = talloc_strdup(entry, canon_principal);
                if (entry->canon_principal == NULL) {
@@ -642,6 +635,15 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
                goto no_mem;
        }
 
+       entry->service = talloc_asprintf(entry,
+                                        "%s/%s@%s",
+                                        KRB5_TGS_NAME,
+                                        realm,
+                                        realm);
+       if (entry->service == NULL) {
+               goto no_mem;
+       }
+
        entry->create_time = create_time;
        entry->renew_until = renew_until;
        entry->uid = uid;
index 5505220335f6c4f63f859828d3d7e866a06c0568..d574834ba946812196c2e097c47305ebc71e9767 100644 (file)
@@ -672,7 +672,6 @@ static NTSTATUS winbindd_raw_kerberos_login(TALLOC_CTX *mem_ctx,
        krb5_error_code krb5_ret;
        const char *cc = NULL;
        const char *principal_s = NULL;
-       const char *service = NULL;
        char *realm = NULL;
        fstring name_namespace, name_domain, name_user;
        time_t ticket_lifetime = 0;
@@ -755,11 +754,6 @@ static NTSTATUS winbindd_raw_kerberos_login(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       service = talloc_asprintf(mem_ctx, "%s/%s@%s", KRB5_TGS_NAME, realm, realm);
-       if (service == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
        local_service = talloc_asprintf(mem_ctx, "%s$@%s",
                                        lp_netbios_name(), lp_realm());
        if (local_service == NULL) {
@@ -848,7 +842,6 @@ static NTSTATUS winbindd_raw_kerberos_login(TALLOC_CTX *mem_ctx,
 
                result = add_ccache_to_list(principal_s,
                                            cc,
-                                           service,
                                            user,
                                            pass,
                                            realm,
@@ -1180,7 +1173,6 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
                        const char *cc = NULL;
                        char *realm = NULL;
                        const char *principal_s = NULL;
-                       const char *service = NULL;
                        const char *user_ccache_file;
 
                        if (domain->alt_name == NULL) {
@@ -1215,11 +1207,6 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
                                return NT_STATUS_NO_MEMORY;
                        }
 
-                       service = talloc_asprintf(state->mem_ctx, "%s/%s@%s", KRB5_TGS_NAME, realm, realm);
-                       if (service == NULL) {
-                               return NT_STATUS_NO_MEMORY;
-                       }
-
                        if (user_ccache_file != NULL) {
 
                                fstrcpy(state->response->data.auth.krb5ccname,
@@ -1227,7 +1214,6 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
 
                                result = add_ccache_to_list(principal_s,
                                                            cc,
-                                                           service,
                                                            state->request->data.auth.user,
                                                            state->request->data.auth.pass,
                                                            realm,
index 16c23f3de401c2a355ebe3d81208a6eff1f46cfa..c685fab2606126de92729ab529b5ba8b57c4678a 100644 (file)
@@ -228,7 +228,6 @@ void ccache_remove_all_after_fork(void);
 void ccache_regain_all_now(void);
 NTSTATUS add_ccache_to_list(const char *princ_name,
                            const char *ccname,
-                           const char *service,
                            const char *username,
                            const char *password,
                            const char *realm,