xref: /freebsd/crypto/krb5/src/lib/gssapi/krb5/disp_name.c (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
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
krb5_gss_display_name(OM_uint32 * minor_status,gss_name_t input_name,gss_buffer_t output_name_buffer,gss_OID * output_name_type)27 krb5_gss_display_name(OM_uint32 *minor_status, gss_name_t input_name,
28                       gss_buffer_t output_name_buffer,
29                       gss_OID *output_name_type)
30 {
31     krb5_context context;
32     krb5_error_code code;
33     char *str;
34     krb5_gss_name_t k5name = (krb5_gss_name_t) input_name;
35     gss_OID nametype = (gss_OID) gss_nt_krb5_name;
36 
37     output_name_buffer->length = 0;
38     output_name_buffer->value = NULL;
39     if (output_name_type)
40         *output_name_type = GSS_C_NO_OID;
41 
42     code = krb5_gss_init_context(&context);
43     if (code) {
44         *minor_status = code;
45         return GSS_S_FAILURE;
46     }
47 
48     if (krb5_princ_type(context, k5name->princ) == KRB5_NT_WELLKNOWN) {
49         if (krb5_principal_compare(context, k5name->princ,
50                                    krb5_anonymous_principal()))
51             nametype = GSS_C_NT_ANONYMOUS;
52     }
53 
54     if ((code = krb5_unparse_name(context,
55                                   ((krb5_gss_name_t) input_name)->princ,
56                                   &str))) {
57         *minor_status = code;
58         save_error_info(*minor_status, context);
59         krb5_free_context(context);
60         return(GSS_S_FAILURE);
61     }
62 
63     if (! g_make_string_buffer(str, output_name_buffer)) {
64         krb5_free_unparsed_name(context, str);
65         krb5_free_context(context);
66 
67         *minor_status = (OM_uint32) G_BUFFER_ALLOC;
68         return(GSS_S_FAILURE);
69     }
70 
71     krb5_free_unparsed_name(context, str);
72     krb5_free_context(context);
73 
74     *minor_status = 0;
75     if (output_name_type)
76         *output_name_type = (gss_OID) nametype;
77     return(GSS_S_COMPLETE);
78 }
79