@@ -1928,30 +1928,40 @@ tgs_build_reply(krb5_context context,
19281928 if (ret )
19291929 goto out ;
19301930
1931+ ret = _kdc_db_fetch (context , config , tp , HDB_F_GET_CLIENT | flags ,
1932+ NULL , & s4u2self_impersonated_clientdb ,
1933+ & s4u2self_impersonated_client );
1934+ if (ret ) {
1935+ const char * msg ;
1936+
1937+ /*
1938+ * If the client belongs to the same realm as our krbtgt, it
1939+ * should exist in the local database.
1940+ *
1941+ */
1942+
1943+ if (ret == HDB_ERR_NOENTRY )
1944+ ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN ;
1945+ msg = krb5_get_error_message (context , ret );
1946+ kdc_log (context , config , 2 ,
1947+ "S4U2Self principal to impersonate %s not found in database: %s" ,
1948+ tpn , msg );
1949+ krb5_free_error_message (context , msg );
1950+ goto out ;
1951+ }
1952+
1953+ free (s4u2self_impersonated_client -> entry .pw_end );
1954+ s4u2self_impersonated_client -> entry .pw_end = NULL ;
1955+
1956+ ret = kdc_check_flags (context , config , s4u2self_impersonated_client , tpn ,
1957+ NULL , NULL , FALSE);
1958+ if (ret )
1959+ goto out ;
1960+
19311961 /* If we were about to put a PAC into the ticket, we better fix it to be the right PAC */
19321962 if (rspac .data ) {
19331963 krb5_pac p = NULL ;
19341964 krb5_data_free (& rspac );
1935- ret = _kdc_db_fetch (context , config , tp , HDB_F_GET_CLIENT | flags ,
1936- NULL , & s4u2self_impersonated_clientdb , & s4u2self_impersonated_client );
1937- if (ret ) {
1938- const char * msg ;
1939-
1940- /*
1941- * If the client belongs to the same realm as our krbtgt, it
1942- * should exist in the local database.
1943- *
1944- */
1945-
1946- if (ret == HDB_ERR_NOENTRY )
1947- ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN ;
1948- msg = krb5_get_error_message (context , ret );
1949- kdc_log (context , config , 1 ,
1950- "S2U4Self principal to impersonate %s not found in database: %s" ,
1951- tpn , msg );
1952- krb5_free_error_message (context , msg );
1953- goto out ;
1954- }
19551965 ret = _kdc_pac_generate (context , s4u2self_impersonated_client , & p );
19561966 if (ret ) {
19571967 kdc_log (context , config , 0 , "PAC generation failed for -- %s" ,
@@ -1987,10 +1997,12 @@ tgs_build_reply(krb5_context context,
19871997
19881998 /*
19891999 * If the service isn't trusted for authentication to
1990- * delegation, remove the forward flag.
2000+ * delegation or if the impersonate client is disallowed
2001+ * forwardable, remove the forwardable flag.
19912002 */
19922003
1993- if (client -> entry .flags .trusted_for_delegation ) {
2004+ if (client -> entry .flags .trusted_for_delegation &&
2005+ s4u2self_impersonated_client -> entry .flags .forwardable ) {
19942006 str = "[forwardable]" ;
19952007 } else {
19962008 b -> kdc_options .forwardable = 0 ;
0 commit comments