From: Theodore Tso Date: Sat, 24 Feb 1996 05:05:48 +0000 (+0000) Subject: g_imp_name.c (gss_import_name): If the user passes in a name-type X-Git-Tag: krb5-1.0-beta6~482 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=80529f62e54f94b1b956e39b589818e31f1a37d3;p=krb5.git g_imp_name.c (gss_import_name): If the user passes in a name-type which is mechanism specific, then import it immediately; don't lazy evaluate it. g_mechname.c (gss_add_mech_name_type): New file for maintaining a registry of name-types which are mechanism specific. g_dsp_name.c (gss_display_name): If there is a mechanism specific name, use it when displaying the name. oid_ops.c (generic_gss_copy_oid): New function used to copy an OID object. g_rel_name.c (gss_release_name): Release the OID in the mechanism name, as it is now allocated. Release the mechanism-specific name if it is present. g_imp_name.c (gss_import_name): Copy the input OID, so we don't have to worry about memory allocation problems later. oid_ops.c (generic_gss_copy_oid): Added new function to copy OIDs. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7513 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/gssapi/mechglue/ChangeLog b/src/lib/gssapi/mechglue/ChangeLog index 9e1eb87be..7ec33e136 100644 --- a/src/lib/gssapi/mechglue/ChangeLog +++ b/src/lib/gssapi/mechglue/ChangeLog @@ -1,4 +1,35 @@ -======= +Sat Feb 24 00:00:27 1996 Theodore Y. Ts'o + + * g_imp_name.c (gss_import_name): If the user passes in a + name-type which is mechanism specific, then import it + immediately; don't lazy evaluate it. + + * g_mechname.c (gss_add_mech_name_type): New file for maintaining + a registry of name-types which are mechanism specific. + + * g_dsp_name.c (gss_display_name): If there is a mechanism + specific name, use it when displaying the name. + + * oid_ops.c (generic_gss_copy_oid): New function used to copy an + OID object. + +Fri Feb 23 18:27:20 1996 Theodore Y. Ts'o + + * g_rel_name.c (gss_release_name): Release the OID in the + mechanism name, as it is now allocated. Release the + mechanism-specific name if it is present. + + * g_imp_name.c (gss_import_name): Copy the input OID, so we don't + have to worry about memory allocation problems later. + Initialize mech_type and mech_name in the union name to be + zero. (for now) + + * oid_ops.c (generic_gss_copy_oid): Added new function to copy OIDs. + +Thu Feb 22 21:48:44 1996 Theodore Y. Ts'o + + * mglueP.h: Add space for the mechanism name in gss_union_name. + Sat Feb 10 18:38:43 1996 Tom Yu * g_glue.c: grab stdlib.h to get NULL diff --git a/src/lib/gssapi/mechglue/Makefile.in b/src/lib/gssapi/mechglue/Makefile.in index 0ac0e59b9..82e6429bf 100644 --- a/src/lib/gssapi/mechglue/Makefile.in +++ b/src/lib/gssapi/mechglue/Makefile.in @@ -43,7 +43,8 @@ SRCS = $(srcdir)/g_acquire_cred.c \ $(srcdir)/g_glue.c \ $(srcdir)/gssd_pname_to_uid.c \ $(srcdir)/gen_oids.c \ - $(srcdir)/oid_ops.c + $(srcdir)/oid_ops.c \ + $(srcdir)/g_mechname.c OBJS = g_acquire_cred.$(OBJEXT) \ g_rel_cred.$(OBJEXT) \ @@ -74,7 +75,8 @@ OBJS = g_acquire_cred.$(OBJEXT) \ g_glue.$(OBJEXT) \ gssd_pname_to_uid.$(OBJEXT) \ gen_oids.$(OBJEXT) \ - oid_ops.$(OBJEXT) + oid_ops.$(OBJEXT) \ + g_mechname.$(OBJEXT) EHDRDIR= $(BUILDTOP)$(S)include$(S)gssapi EXPORTED_HEADERS = mechglue.h diff --git a/src/lib/gssapi/mechglue/g_dsp_name.c b/src/lib/gssapi/mechglue/g_dsp_name.c index 4ae8d2c0c..86d1ec19b 100644 --- a/src/lib/gssapi/mechglue/g_dsp_name.c +++ b/src/lib/gssapi/mechglue/g_dsp_name.c @@ -45,23 +45,39 @@ gss_buffer_t output_name_buffer; gss_OID * output_name_type; { + OM_uint32 major_status; gss_union_name_t union_name; - /* - * copy the value of the external_name component of the union - * name into the output_name_buffer and point the output_name_type - * to the name_type component of union_name - */ - if (input_name == 0) return GSS_S_BAD_NAME; union_name = (gss_union_name_t) input_name; + + if (union_name->mech_type) { + /* + * OK, we have a mechanism-specific name; let's use it! + */ + return (__gss_display_internal_name(minor_status, + union_name->mech_type, + union_name->mech_name, + output_name_buffer, + output_name_type)); + } - if(output_name_type != NULL) - *output_name_type = union_name->name_type; + /* + * copy the value of the external_name component of the union + * name into the output_name_buffer and point the output_name_type + * to the name_type component of union_name + */ + if (output_name_type != NULL) { + major_status = generic_gss_copy_oid(minor_status, + union_name->name_type, + output_name_type); + if (major_status) + return (major_status); + } - if(output_name_buffer != NULL) { + if (output_name_buffer != NULL) { output_name_buffer->length = union_name->external_name->length; output_name_buffer->value = diff --git a/src/lib/gssapi/mechglue/g_imp_name.c b/src/lib/gssapi/mechglue/g_imp_name.c index 654b0459b..637acfa57 100644 --- a/src/lib/gssapi/mechglue/g_imp_name.c +++ b/src/lib/gssapi/mechglue/g_imp_name.c @@ -32,6 +32,7 @@ #include #endif #include +#include OM_uint32 gss_import_name(minor_status, @@ -46,6 +47,10 @@ gss_name_t * output_name; { gss_union_name_t union_name; + OM_uint32 tmp, major_status = GSS_S_FAILURE; + gss_OID mech; + + gss_initialize(); if (minor_status) *minor_status = 0; @@ -55,6 +60,8 @@ gss_name_t * output_name; if(output_name == NULL) return (GSS_S_COMPLETE); + *output_name = 0; + if (input_name_buffer == GSS_C_NO_BUFFER) return (GSS_S_BAD_NAME); @@ -64,6 +71,14 @@ gss_name_t * output_name; */ union_name = (gss_union_name_t) malloc (sizeof(gss_union_name_desc)); + if (!union_name) { + *minor_status = ENOMEM; + goto allocation_failure; + } + union_name->mech_type = 0; + union_name->mech_name = 0; + union_name->name_type = 0; + union_name->external_name = 0; /* * All we do here is record the external name and name_type. @@ -72,25 +87,68 @@ gss_name_t * output_name; * is assumed to be constant, so only a pointer to it is stored in * union_name */ - union_name->external_name = (gss_buffer_t) malloc(sizeof(gss_buffer_desc)); + if (!union_name->external_name) { + *minor_status = ENOMEM; + goto allocation_failure; + } + union_name->external_name->length = input_name_buffer->length; /* we malloc length+1 to stick a NULL on the end, just in case */ /* Note that this NULL is not included in ->length for a reason! */ union_name->external_name->value = (void *) malloc(input_name_buffer->length+1); + if (!union_name->external_name->value) { + *minor_status = ENOMEM; + goto allocation_failure; + } + memcpy(union_name->external_name->value, input_name_buffer->value, input_name_buffer->length); /* add NULL to end of external_name->value, just in case... */ - ((char *)union_name->external_name->value) [input_name_buffer->length] = '\0'; - union_name->name_type = (gss_OID) input_name_type; + major_status = generic_gss_copy_oid(minor_status, input_name_type, + &union_name->name_type); + if (major_status != GSS_S_COMPLETE) + goto allocation_failure; + + mech = gss_find_mechanism_from_name_type(input_name_type); + if (mech) { + major_status = generic_gss_copy_oid(minor_status, mech, + &union_name->mech_type); + if (major_status != GSS_S_COMPLETE) + goto allocation_failure; + + major_status = __gss_import_internal_name(minor_status, mech, + union_name, + &union_name->mech_name); + if (major_status) + goto allocation_failure; + } *output_name = (gss_name_t) union_name; return(GSS_S_COMPLETE); + +allocation_failure: + if (union_name) { + if (union_name->external_name) { + if (union_name->external_name->value) + free(union_name->external_name->value); + free(union_name->external_name); + } + if (union_name->name_type) + generic_gss_release_oid(&tmp, &union_name->name_type); + if (union_name->mech_name) + __gss_release_internal_name(minor_status, union_name->mech_type, + &union_name->mech_name); + if (union_name->mech_type) + generic_gss_release_oid(&tmp, &union_name->mech_type); + free(union_name); + } + return (major_status); } diff --git a/src/lib/gssapi/mechglue/g_rel_name.c b/src/lib/gssapi/mechglue/g_rel_name.c index dd6358af0..493266e7c 100644 --- a/src/lib/gssapi/mechglue/g_rel_name.c +++ b/src/lib/gssapi/mechglue/g_rel_name.c @@ -58,9 +58,19 @@ gss_name_t * input_name; if (union_name == NULL) return GSS_S_BAD_NAME; + + if (union_name->name_type) + generic_gss_release_oid(minor_status, &union_name->name_type); free(union_name->external_name->value); free(union_name->external_name); + + if (union_name->mech_type) { + __gss_release_internal_name(minor_status, union_name->mech_type, + &union_name->mech_name); + generic_gss_release_oid(minor_status, &union_name->mech_type); + } + free(union_name); return(GSS_S_COMPLETE); diff --git a/src/lib/gssapi/mechglue/mglueP.h b/src/lib/gssapi/mechglue/mglueP.h index cd881d060..d4a271534 100644 --- a/src/lib/gssapi/mechglue/mglueP.h +++ b/src/lib/gssapi/mechglue/mglueP.h @@ -21,13 +21,29 @@ typedef struct gss_union_ctx_id_t { } gss_union_ctx_id_desc, *gss_union_ctx_id_t; /* - * Array of names typed by the name OID (XXX - mechanism OID?) + * Generic GSSAPI names. A name can either be a generic name, or a + * mechanism specific name.... */ typedef struct gss_union_name_t { gss_OID name_type; gss_buffer_t external_name; + /* + * These last two fields are only filled in for mechanism + * names. + */ + gss_OID mech_type; + gss_name_t mech_name; } gss_union_name_desc, *gss_union_name_t; +/* + * Structure for holding list of mechanism-specific name types + */ +typedef struct gss_mech_spec_name_t { + gss_OID name_type; + gss_OID mech; + struct gss_mech_spec_name_t *next, *prev; +} gss_mech_spec_name_desc, *gss_mech_spec_name; + /* * Credential auxiliary info, used in the credential structure */ @@ -332,6 +348,12 @@ PROTOTYPE( (OM_uint32 *, /* minor_status */ gss_OID * /* oid */ )); +OM_uint32 generic_gss_copy_oid +PROTOTYPE( (OM_uint32 *, /* minor_status */ + gss_OID, /* oid */ + gss_OID * /* new_oid */ + )); + OM_uint32 generic_gss_create_empty_oid_set PROTOTYPE( (OM_uint32 *, /* minor_status */ gss_OID_set * /* oid_set */ @@ -363,5 +385,14 @@ PROTOTYPE( (OM_uint32 *, /* minor_status */ )); +gss_OID gss_find_mechanism_from_name_type +PROTOTYPE ( (gss_OID /* name_type */ + )); + +OM_uint32 gss_add_mech_name_type +PROTOTYPE ( (OM_uint32 *, /* minor_status */ + gss_OID, /* name_type */ + gss_OID /* mech */ + )); #endif /* _GSS_MECHGLUEP_H */ diff --git a/src/lib/gssapi/mechglue/oid_ops.c b/src/lib/gssapi/mechglue/oid_ops.c index 2db42af67..a30019858 100644 --- a/src/lib/gssapi/mechglue/oid_ops.c +++ b/src/lib/gssapi/mechglue/oid_ops.c @@ -69,6 +69,31 @@ generic_gss_release_oid(minor_status, oid) return(GSS_S_COMPLETE); } +OM_uint32 +generic_gss_copy_oid(minor_status, oid, new_oid) + OM_uint32 *minor_status; + gss_OID oid, *new_oid; +{ + gss_OID p; + + p = (gss_OID) malloc(sizeof(gss_OID_desc)); + if (!p) { + *minor_status = ENOMEM; + return GSS_S_FAILURE; + } + p->length = oid->length; + p->elements = malloc(p->length); + if (!p->elements) { + free(p); + *minor_status = ENOMEM; + return GSS_S_FAILURE; + } + memcpy(p->elements, oid->elements, p->length); + *new_oid = p; + return(GSS_S_COMPLETE); +} + + OM_uint32 generic_gss_create_empty_oid_set(minor_status, oid_set) OM_uint32 *minor_status;