+
+OM_uint32
+gssEapCanonicalizeName(OM_uint32 *minor,
+ const gss_name_t input_name,
+ const gss_OID mech_type,
+ gss_name_t *dest_name)
+{
+ OM_uint32 major, tmpMinor;
+ krb5_context krbContext;
+ gss_name_t name;
+ gss_OID mech_used;
+
+ if (input_name == GSS_C_NO_NAME) {
+ *minor = EINVAL;
+ return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME;
+ }
+
+ GSSEAP_KRB_INIT(&krbContext);
+
+ major = gssEapAllocName(minor, &name);
+ if (GSS_ERROR(major)) {
+ return major;
+ }
+
+ if (mech_type != GSS_C_NO_OID)
+ mech_used = mech_type;
+ else
+ mech_used = input_name->mechanismUsed;
+
+ major = gssEapCanonicalizeOid(minor,
+ mech_used,
+ OID_FLAG_NULL_VALID,
+ &name->mechanismUsed);
+ if (GSS_ERROR(major))
+ goto cleanup;
+
+ name->flags = input_name->flags;
+
+ *minor = krb5_copy_principal(krbContext, input_name->krbPrincipal,
+ &name->krbPrincipal);
+ if (*minor != 0) {
+ major = GSS_S_FAILURE;
+ goto cleanup;
+ }
+
+ if (input_name->attrCtx != NULL) {
+ major = gssEapDuplicateAttrContext(minor, input_name, name);
+ if (GSS_ERROR(major))
+ goto cleanup;
+ }
+
+ *dest_name = name;
+
+cleanup:
+ if (GSS_ERROR(major)) {
+ gssEapReleaseName(&tmpMinor, &name);
+ }
+
+ return major;
+}
+
+OM_uint32
+gssEapDuplicateName(OM_uint32 *minor,
+ const gss_name_t input_name,
+ gss_name_t *dest_name)
+{
+ return gssEapCanonicalizeName(minor, input_name,
+ GSS_C_NO_OID, dest_name);
+}
+
+OM_uint32
+gssEapDisplayName(OM_uint32 *minor,
+ gss_name_t name,
+ gss_buffer_t output_name_buffer,
+ gss_OID *output_name_type)
+{
+ OM_uint32 major;
+ krb5_context krbContext;
+ char *krbName;
+ gss_OID name_type;
+ int flags = 0;
+
+ GSSEAP_KRB_INIT(&krbContext);
+
+ output_name_buffer->length = 0;
+ output_name_buffer->value = NULL;
+
+ if (name == GSS_C_NO_NAME) {
+ *minor = EINVAL;
+ return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_BAD_NAME;
+ }
+
+ /*
+ * According to draft-ietf-abfab-gss-eap-01, when the realm is
+ * absent the trailing '@' is not included.
+ */
+#ifdef HAVE_HEIMDAL_VERSION
+ if (KRB_PRINC_REALM(name->krbPrincipal) == NULL ||
+ KRB_PRINC_REALM(name->krbPrincipal)[0] == '\0')
+#else
+ if (KRB_PRINC_REALM(name->krbPrincipal)->length == 0)
+#endif
+ flags |= KRB5_PRINCIPAL_UNPARSE_NO_REALM;
+
+ *minor = krb5_unparse_name_flags(krbContext, name->krbPrincipal,
+ flags, &krbName);
+ if (*minor != 0) {
+ return GSS_S_FAILURE;
+ }
+
+ major = makeStringBuffer(minor, krbName, output_name_buffer);
+ if (GSS_ERROR(major)) {
+ krb5_free_unparsed_name(krbContext, krbName);
+ return major;
+ }
+
+ krb5_free_unparsed_name(krbContext, krbName);
+
+ if (output_name_buffer->length == 0) {
+ name_type = GSS_C_NT_ANONYMOUS;
+ } else if (name->flags & NAME_FLAG_NAI) {
+ name_type = GSS_C_NT_USER_NAME;
+ } else {
+ name_type = GSS_EAP_NT_EAP_NAME;
+ }
+
+ if (output_name_type != NULL)
+ *output_name_type = name_type;
+
+ return GSS_S_COMPLETE;
+}
+
+OM_uint32
+gssEapCompareName(OM_uint32 *minor,
+ gss_name_t name1,
+ gss_name_t name2,
+ int *name_equal)
+{
+ krb5_context krbContext;
+
+ *minor = 0;
+
+ if (name1 == GSS_C_NO_NAME && name2 == GSS_C_NO_NAME) {
+ *name_equal = 1;
+ } else if (name1 != GSS_C_NO_NAME && name2 != GSS_C_NO_NAME) {
+ GSSEAP_KRB_INIT(&krbContext);
+
+ /* krbPrincipal is immutable, so lock not required */
+ *name_equal = krb5_principal_compare(krbContext,
+ name1->krbPrincipal,
+ name2->krbPrincipal);
+ }
+
+ return GSS_S_COMPLETE;
+}