GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL gss_canonicalize_name(OM_uint32 *minor_status, gss_const_name_t input_name, const gss_OID mech_type, gss_name_t *output_name) { OM_uint32 major_status; struct _gss_name *name = (struct _gss_name *) input_name; struct _gss_mechanism_name *mn; gssapi_mech_interface m; gss_name_t new_canonical_name; *minor_status = 0; *output_name = 0; major_status = _gss_find_mn(minor_status, name, mech_type, &mn); if (major_status) return major_status; m = mn->gmn_mech; major_status = m->gm_canonicalize_name(minor_status, mn->gmn_name, mech_type, &new_canonical_name); if (major_status) { _gss_mg_error(m, major_status, *minor_status); return (major_status); } /* * Now we make a new name and mark it as an MN. */ *minor_status = 0; name = malloc(sizeof(struct _gss_name)); if (!name) { m->gm_release_name(minor_status, &new_canonical_name); *minor_status = ENOMEM; return (GSS_S_FAILURE); } memset(name, 0, sizeof(struct _gss_name)); mn = malloc(sizeof(struct _gss_mechanism_name)); if (!mn) { m->gm_release_name(minor_status, &new_canonical_name); free(name); *minor_status = ENOMEM; return (GSS_S_FAILURE); } HEIM_SLIST_INIT(&name->gn_mn); mn->gmn_mech = m; mn->gmn_mech_oid = &m->gm_mech_oid; mn->gmn_name = new_canonical_name; HEIM_SLIST_INSERT_HEAD(&name->gn_mn, mn, gmn_link); *output_name = (gss_name_t) name; return (GSS_S_COMPLETE); }
/** * This function is not a public interface and is deprecated anyways, do * not use. Use gss_acquire_cred_with_password() instead for now. * * @deprecated */ OM_uint32 _gss_acquire_cred_ext(OM_uint32 *minor_status, gss_const_name_t desired_name, gss_const_OID credential_type, const void *credential_data, OM_uint32 time_req, gss_const_OID desired_mech, gss_cred_usage_t cred_usage, gss_cred_id_t *output_cred_handle) { OM_uint32 major_status; struct _gss_name *name = (struct _gss_name *) desired_name; gssapi_mech_interface m; struct _gss_cred *cred; gss_OID_set_desc set, *mechs; size_t i; *minor_status = 0; if (output_cred_handle == NULL) return GSS_S_CALL_INACCESSIBLE_READ; _gss_load_mech(); if (desired_mech != GSS_C_NO_OID) { int match = 0; gss_test_oid_set_member(minor_status, (gss_OID)desired_mech, _gss_mech_oids, &match); if (!match) return GSS_S_BAD_MECH; set.count = 1; set.elements = (gss_OID)desired_mech; mechs = &set; } else mechs = _gss_mech_oids; cred = calloc(1, sizeof(*cred)); if (cred == NULL) { *minor_status = ENOMEM; return GSS_S_FAILURE; } HEIM_SLIST_INIT(&cred->gc_mc); for (i = 0; i < mechs->count; i++) { struct _gss_mechanism_name *mn = NULL; struct _gss_mechanism_cred *mc = NULL; m = __gss_get_mechanism(&mechs->elements[i]); if (!m) continue; if (desired_name != GSS_C_NO_NAME) { major_status = _gss_find_mn(minor_status, name, &mechs->elements[i], &mn); if (major_status != GSS_S_COMPLETE) continue; } major_status = _gss_acquire_mech_cred(minor_status, m, mn, credential_type, credential_data, time_req, desired_mech, cred_usage, &mc); if (GSS_ERROR(major_status)) { if (mechs->count == 1) _gss_mg_error(m, major_status, *minor_status); continue; } HEIM_SLIST_INSERT_HEAD(&cred->gc_mc, mc, gmc_link); } /* * If we didn't manage to create a single credential, return * an error. */ if (!HEIM_SLIST_FIRST(&cred->gc_mc)) { free(cred); if (mechs->count > 1) *minor_status = 0; return GSS_S_NO_CRED; } *output_cred_handle = (gss_cred_id_t) cred; *minor_status = 0; return GSS_S_COMPLETE; }
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL gss_acquire_cred_with_password(OM_uint32 *minor_status, const gss_name_t desired_name, const gss_buffer_t password, OM_uint32 time_req, const gss_OID_set desired_mechs, gss_cred_usage_t cred_usage, gss_cred_id_t *output_cred_handle, gss_OID_set *actual_mechs, OM_uint32 *time_rec) { OM_uint32 major_status, tmp_minor; if (desired_mechs == GSS_C_NO_OID_SET) { major_status = _gss_acquire_cred_ext(minor_status, desired_name, GSS_C_CRED_PASSWORD, password, time_req, GSS_C_NO_OID, cred_usage, output_cred_handle); if (GSS_ERROR(major_status)) return major_status; } else { size_t i; struct _gss_cred *new_cred; new_cred = calloc(1, sizeof(*new_cred)); if (new_cred == NULL) { *minor_status = ENOMEM; return GSS_S_FAILURE; } HEIM_SLIST_INIT(&new_cred->gc_mc); for (i = 0; i < desired_mechs->count; i++) { struct _gss_cred *tmp_cred = NULL; struct _gss_mechanism_cred *mc; major_status = _gss_acquire_cred_ext(minor_status, desired_name, GSS_C_CRED_PASSWORD, password, time_req, &desired_mechs->elements[i], cred_usage, (gss_cred_id_t *)&tmp_cred); if (GSS_ERROR(major_status)) continue; mc = HEIM_SLIST_FIRST(&tmp_cred->gc_mc); if (mc) { HEIM_SLIST_REMOVE_HEAD(&tmp_cred->gc_mc, gmc_link); HEIM_SLIST_INSERT_HEAD(&new_cred->gc_mc, mc, gmc_link); } gss_release_cred(&tmp_minor, (gss_cred_id_t *)&tmp_cred); } if (!HEIM_SLIST_FIRST(&new_cred->gc_mc)) { free(new_cred); *minor_status = 0; return GSS_S_NO_CRED; } *output_cred_handle = (gss_cred_id_t)new_cred; } if (actual_mechs != NULL || time_rec != NULL) { major_status = gss_inquire_cred(minor_status, *output_cred_handle, NULL, time_rec, NULL, actual_mechs); if (GSS_ERROR(major_status)) { gss_release_cred(&tmp_minor, output_cred_handle); return major_status; } } *minor_status = 0; return GSS_S_COMPLETE; }
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL gss_acquire_cred(OM_uint32 *minor_status, const gss_name_t desired_name, OM_uint32 time_req, const gss_OID_set desired_mechs, gss_cred_usage_t cred_usage, gss_cred_id_t *output_cred_handle, gss_OID_set *actual_mechs, OM_uint32 *time_rec) { OM_uint32 major_status; gss_OID_set mechs = desired_mechs; gss_OID_set_desc set; struct _gss_name *name = (struct _gss_name *) desired_name; gssapi_mech_interface m; struct _gss_cred *cred; struct _gss_mechanism_cred *mc; OM_uint32 min_time, cred_time; int i; *minor_status = 0; if (output_cred_handle == NULL) return GSS_S_CALL_INACCESSIBLE_READ; if (actual_mechs) *actual_mechs = GSS_C_NO_OID_SET; if (time_rec) *time_rec = 0; _gss_load_mech(); /* * First make sure that at least one of the requested * mechanisms is one that we support. */ if (mechs) { for (i = 0; i < mechs->count; i++) { int t; gss_test_oid_set_member(minor_status, &mechs->elements[i], _gss_mech_oids, &t); if (t) break; } if (i == mechs->count) { *minor_status = 0; return (GSS_S_BAD_MECH); } } if (actual_mechs) { major_status = gss_create_empty_oid_set(minor_status, actual_mechs); if (major_status) return (major_status); } cred = malloc(sizeof(struct _gss_cred)); if (!cred) { if (actual_mechs) gss_release_oid_set(minor_status, actual_mechs); *minor_status = ENOMEM; return (GSS_S_FAILURE); } HEIM_SLIST_INIT(&cred->gc_mc); if (mechs == GSS_C_NO_OID_SET) mechs = _gss_mech_oids; set.count = 1; min_time = GSS_C_INDEFINITE; for (i = 0; i < mechs->count; i++) { struct _gss_mechanism_name *mn = NULL; m = __gss_get_mechanism(&mechs->elements[i]); if (!m) continue; if (desired_name != GSS_C_NO_NAME) { major_status = _gss_find_mn(minor_status, name, &mechs->elements[i], &mn); if (major_status != GSS_S_COMPLETE) continue; } mc = malloc(sizeof(struct _gss_mechanism_cred)); if (!mc) { continue; } mc->gmc_mech = m; mc->gmc_mech_oid = &m->gm_mech_oid; /* * XXX Probably need to do something with actual_mechs. */ set.elements = &mechs->elements[i]; major_status = m->gm_acquire_cred(minor_status, (desired_name != GSS_C_NO_NAME ? mn->gmn_name : GSS_C_NO_NAME), time_req, &set, cred_usage, &mc->gmc_cred, NULL, &cred_time); if (major_status) { free(mc); continue; } if (cred_time < min_time) min_time = cred_time; if (actual_mechs) { major_status = gss_add_oid_set_member(minor_status, mc->gmc_mech_oid, actual_mechs); if (major_status) { m->gm_release_cred(minor_status, &mc->gmc_cred); free(mc); continue; } } HEIM_SLIST_INSERT_HEAD(&cred->gc_mc, mc, gmc_link); } /* * If we didn't manage to create a single credential, return * an error. */ if (!HEIM_SLIST_FIRST(&cred->gc_mc)) { free(cred); if (actual_mechs) gss_release_oid_set(minor_status, actual_mechs); *minor_status = 0; return (GSS_S_NO_CRED); } if (time_rec) *time_rec = min_time; *output_cred_handle = (gss_cred_id_t) cred; *minor_status = 0; return (GSS_S_COMPLETE); }