diff options
Diffstat (limited to 'lib/krb5_wrap')
-rw-r--r-- | lib/krb5_wrap/krb5_samba.c | 44 | ||||
-rw-r--r-- | lib/krb5_wrap/krb5_samba.h | 4 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index d5c0b37d28..8d91e1c074 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -2313,6 +2313,50 @@ char *smb_krb5_principal_get_realm(krb5_context context, #endif } +/* + * smb_krb5_principal_set_realm + * + * @brief Get realm of a principal + * + * @param[in] context The krb5_context + * @param[in] principal The principal + * @param[in] realm The realm + * @return 0 on success, a krb5_error_code on error. + * + */ + +krb5_error_code smb_krb5_principal_set_realm(krb5_context context, + krb5_principal principal, + const char *realm) +{ +#ifdef HAVE_KRB5_PRINCIPAL_SET_REALM /* Heimdal */ + return krb5_principal_set_realm(context, principal, realm); +#elif defined(krb5_princ_realm) && defined(krb5_princ_set_realm) /* MIT */ + krb5_error_code ret; + krb5_data data; + krb5_data *old_data; + + old_data = krb5_princ_realm(context, principal); + + data.magic = 0; + data.length = strlen(realm); + data.data = malloc(data.length); + if (data.data == NULL) { + return ENOMEM; + } + + /* free realm before setting */ + free(old_data->data); + + krb5_princ_set_realm(context, principal, &data); + + return ret; +#else +#error UNKNOWN_PRINC_SET_REALM_FUNCTION +#endif +} + + /************************************************************************ Routine to get the default realm from the kerberos credentials cache. Caller must free if the return value is not NULL. diff --git a/lib/krb5_wrap/krb5_samba.h b/lib/krb5_wrap/krb5_samba.h index 36b60feebe..03246fd028 100644 --- a/lib/krb5_wrap/krb5_samba.h +++ b/lib/krb5_wrap/krb5_samba.h @@ -254,6 +254,10 @@ krb5_error_code smb_krb5_make_pac_checksum(TALLOC_CTX *mem_ctx, char *smb_krb5_principal_get_realm(krb5_context context, krb5_const_principal principal); +krb5_error_code smb_krb5_principal_set_realm(krb5_context context, + krb5_principal principal, + const char *realm); + char *kerberos_get_principal_from_service_hostname(TALLOC_CTX *mem_ctx, const char *service, const char *remote_name, |