b097bf0e2181c10db1d76ea02dae887c5020ed1c
[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     output_name_buffer->length = 0;
41     output_name_buffer->value = NULL;
42     if (output_name_type)
43         *output_name_type = GSS_C_NO_OID;
44
45     code = krb5_gss_init_context(&context);
46     if (code) {
47         *minor_status = code;
48         return GSS_S_FAILURE;
49     }
50
51     if (krb5_princ_type(context, k5name->princ) == KRB5_NT_WELLKNOWN) {
52         if (krb5_principal_compare(context, k5name->princ,
53                                    krb5_anonymous_principal()))
54             nametype = GSS_C_NT_ANONYMOUS;
55     }
56
57     if ((code = krb5_unparse_name(context,
58                                   ((krb5_gss_name_t) input_name)->princ,
59                                   &str))) {
60         *minor_status = code;
61         save_error_info(*minor_status, context);
62         krb5_free_context(context);
63         return(GSS_S_FAILURE);
64     }
65
66     if (! g_make_string_buffer(str, output_name_buffer)) {
67         krb5_free_unparsed_name(context, str);
68         krb5_free_context(context);
69
70         *minor_status = (OM_uint32) G_BUFFER_ALLOC;
71         return(GSS_S_FAILURE);
72     }
73
74     krb5_free_unparsed_name(context, str);
75     krb5_free_context(context);
76
77     *minor_status = 0;
78     if (output_name_type)
79         *output_name_type = (gss_OID) nametype;
80     return(GSS_S_COMPLETE);
81 }