Skip to content

Commit

Permalink
Merge pull request #124 from itglob/master
Browse files Browse the repository at this point in the history
corrected Heimdal compatibility
  • Loading branch information
stnoonan authored Oct 31, 2022
2 parents c626163 + 6a88c45 commit bd4e8c3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ngx_http_auth_spnego_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
#define spnego_log_error(fmt, args...) \
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, fmt, ##args)

#ifndef krb5_realm_length
#define krb5_realm_length(r) ((r).length)
#define krb5_realm_data(r) ((r).data)
#endif

/* Module handler */
static ngx_int_t ngx_http_auth_spnego_handler(ngx_http_request_t *);

Expand Down Expand Up @@ -1195,12 +1200,12 @@ static krb5_error_code ngx_http_auth_spnego_verify_server_credentials(
}

size_t tgs_principal_name_size =
(ngx_strlen(KRB5_TGS_NAME) + (principal->realm.length * 2) + 2) + 1;
(ngx_strlen(KRB5_TGS_NAME) + (krb5_realm_length(principal->realm) * 2) + 2) + 1;
tgs_principal_name = (char *)ngx_pcalloc(r->pool, tgs_principal_name_size);
ngx_snprintf((u_char *)tgs_principal_name, tgs_principal_name_size,
"%s/%*s@%*s", KRB5_TGS_NAME, principal->realm.length,
principal->realm.data, principal->realm.length,
principal->realm.data);
"%s/%*s@%*s", KRB5_TGS_NAME, krb5_realm_length(principal->realm),
krb5_realm_data(principal->realm), krb5_realm_length(principal->realm),
krb5_realm_data(principal->realm));

if ((kerr = krb5_parse_name(kcontext, tgs_principal_name,
&match_creds.server))) {
Expand Down Expand Up @@ -1341,13 +1346,13 @@ static ngx_int_t ngx_http_auth_spnego_obtain_server_credentials(
krb5_get_init_creds_opt_set_forwardable(&gicopts, 1);

size_t tgs_principal_name_size =
(ngx_strlen(KRB5_TGS_NAME) + (principal->realm.length * 2) + 2) + 1;
(ngx_strlen(KRB5_TGS_NAME) + (krb5_realm_length(principal->realm) * 2) + 2) + 1;
tgs_principal_name = (char *)ngx_pcalloc(r->pool, tgs_principal_name_size);

ngx_snprintf((u_char *)tgs_principal_name, tgs_principal_name_size,
"%s/%*s@%*s", KRB5_TGS_NAME, principal->realm.length,
principal->realm.data, principal->realm.length,
principal->realm.data);
"%s/%*s@%*s", KRB5_TGS_NAME, krb5_realm_length(principal->realm),
krb5_realm_data(principal->realm), krb5_realm_length(principal->realm),
krb5_realm_data(principal->realm));

kerr = krb5_get_init_creds_keytab(kcontext, &creds, principal, keytab, 0,
tgs_principal_name, &gicopts);
Expand Down

0 comments on commit bd4e8c3

Please sign in to comment.