#include "mysccs.h"
SCCSID("@(#)$Id: //tools/src/freeware/gsskrb5/dsp_name.c#1 $")

/************************************************************************
 * $Id: //tools/src/freeware/gsskrb5/dsp_name.c#1 $
 ************************************************************************
 *
 * Copyright (c) 1997-2000  SAP AG.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by SAP AG"
 *
 * 4. The name "SAP AG" must not be used to endorse or promote products
 *    derived from this software without prior written permission.
 *    For written permission, please contact www.press@sap.com
 *
 * 5. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by SAP AG"
 *
 * THIS SOFTWARE IS PROVIDED BY SAP AG ``AS IS'' AND ANY EXPRESSED
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. SAP AG SHALL BE LIABLE FOR ANY DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE ONLY IF CAUSED BY SAP AG'S
 * INTENT OR GROSS NEGLIGENCE. IN CASE SAP AG IS LIABLE UNDER THIS
 * AGREEMENT FOR DAMAGES CAUSED BY SAP AG'S GROSS NEGLIGENCE SAP AG
 * FURTHER SHALL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT, AND SHALL NOT BE LIABLE IN EXCESS OF THE AMOUNT OF
 * DAMAGES TYPICALLY FORESEEABLE FOR SAP AG, WHICH SHALL IN NO EVENT
 * EXCEED US$ 500.000.- 
 *
 ************************************************************************/


#include "gssmaini.h"


/*
 * gn_gss_display_name()
 *
 *
 */
OM_uint32
gn_gss_display_name(
	OM_uint32	FAR *	pp_min_stat,	/* minor_status		*/
	gss_name_t		p_input_name,	/* input_name		*/
	gss_buffer_t		p_out_printable,/* output_name_buffer	*/
	gss_OID		FAR *	pp_out_oid	/* output_name_type	*/
     )
{
   char          * this_Call = " gn_gss_display_name(): ";
   gn_name_desc  * name;
   OM_uint32       maj_stat;

   (*pp_min_stat) = 0;
   if ( pp_out_oid!=NULL ) {
      (*pp_out_oid) = GSS_C_NO_OID;
   }

   if ( p_out_printable==NULL ) {
      RETURN_MIN_MAJ( MINOR_INVALID_BUFFER,
		      GSS_S_CALL_INACCESSIBLE_WRITE | GSS_S_FAILURE );
   }

   p_out_printable->length = 0;
   p_out_printable->value  = NULL;
   name = (gn_name_desc *) p_input_name;

   /* Does p_input_name reference a valid internal name ? */
   if ( name==NULL  ||  name->magic_cookie != COOKIE_NAME ) {
      DEBUG_ACTION((tf, "%sp_input_name is not a valid internal name\n",
		        this_Call ))
      RETURN_MIN_MAJ( MINOR_NO_ERROR, GSS_S_BAD_NAME );
   }

   if ( name->first != name ) {
      DEBUG_STRANGE((tf, "  S:%sthis is not an exposed internal name\n",
		         this_Call ))
      RETURN_MIN_MAJ( MINOR_INTERNAL_ERROR, GSS_S_BAD_NAME );
   }

   if ( name->prname==NULL ) {

      if ( name->mech_tag==MECH_INVALID_TAG ) {
         DEBUG_STRANGE((tf, "  S:%sp_input_name is missing its mech_tag\n",
			this_Call ))
	 RETURN_MIN_MAJ( MINOR_INTERNAL_ERROR, GSS_S_FAILURE );
      }
      /* We don't have a printable version of this name around, */
      /* so we need to get one generated by the mechanism       */
      maj_stat = (gn_mech[name->mech_tag]
		      ->fp_display_name)( pp_min_stat, (name->nt_tag),
					  (name->name), (name->name_len),
					  &(name->prname),
					  &(name->prname_len) );
      if (maj_stat!=GSS_S_COMPLETE) {
         return(maj_stat);
      }

   } /* name->prname==NULL */

   /* Xerox a gss_buffer_t object from the printable name */
   maj_stat = gn_alloc_buffer( pp_min_stat, p_out_printable,
			       name->prname, name->prname_len, TRUE );
   if ( maj_stat!=GSS_S_COMPLETE ) {
      return(maj_stat);
   }

   if ( pp_out_oid!=NULL ) {
      if ( name->nt_tag==NT_DEFAULT ) {
	 (*pp_out_oid) = GSS_C_NO_OID;
      } else {
	 (*pp_out_oid) = gn_nt_tag_to_oid( name->nt_tag );
      }
   } /* pp_out_oid!=NULL */

   return(GSS_S_COMPLETE);

} /* gn_gss_display_name() */
