6ff25439121644237292e5776f175182ecc8f89a
[platform/upstream/krb5.git] / src / lib / gssapi / krb5 / disp_name.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 1993 by OpenVision Technologies, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software
6  * and its documentation for any purpose is hereby granted without fee,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear in
9  * supporting documentation, and that the name of OpenVision not be used
10  * in advertising or publicity pertaining to distribution of the software
11  * without specific, written prior permission. OpenVision makes no
12  * representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14  *
15  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21  * PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #include "gssapiP_krb5.h"
25
26 OM_uint32 KRB5_CALLCONV
27 krb5_gss_display_name(minor_status, input_name, output_name_buffer,
28                       output_name_type)
29     OM_uint32 *minor_status;
30     gss_name_t input_name;
31     gss_buffer_t output_name_buffer;
32     gss_OID *output_name_type;
33 {
34     krb5_context context;
35     krb5_error_code code;
36     char *str;
37     krb5_gss_name_t k5name = (krb5_gss_name_t) input_name;
38     gss_OID nametype = (gss_OID) gss_nt_krb5_name;
39
40     code = krb5_gss_init_context(&context);
41     if (code) {
42         *minor_status = code;
43         return GSS_S_FAILURE;
44     }
45
46     output_name_buffer->length = 0;
47     output_name_buffer->value = NULL;
48
49     if (krb5_princ_type(context, k5name->princ) == KRB5_NT_WELLKNOWN) {
50         if (krb5_principal_compare(context, k5name->princ,
51                                    krb5_anonymous_principal()))
52             nametype = GSS_C_NT_ANONYMOUS;
53     }
54
55     if ((code = krb5_unparse_name(context,
56                                   ((krb5_gss_name_t) input_name)->princ,
57                                   &str))) {
58         *minor_status = code;
59         save_error_info(*minor_status, context);
60         krb5_free_context(context);
61         return(GSS_S_FAILURE);
62     }
63
64     if (! g_make_string_buffer(str, output_name_buffer)) {
65         krb5_free_unparsed_name(context, str);
66         krb5_free_context(context);
67
68         *minor_status = (OM_uint32) G_BUFFER_ALLOC;
69         return(GSS_S_FAILURE);
70     }
71
72     krb5_free_unparsed_name(context, str);
73     krb5_free_context(context);
74
75     *minor_status = 0;
76     if (output_name_type)
77         *output_name_type = (gss_OID) nametype;
78     return(GSS_S_COMPLETE);
79 }