Windows global stuff:
[krb5.git] / src / lib / gssapi / krb5 / gssapi_krb5.c
1 /*
2  * Copyright 1993 by OpenVision Technologies, Inc.
3  * 
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appears in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of OpenVision not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission. OpenVision makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  * 
14  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "gssapiP_krb5.h"
24
25 /** exported constants defined in gssapi_krb5.h **/
26
27 /* these are bogus, but will compile */
28
29 /*
30  * The OID of the krb5 mechanism, assigned by IETF, is:
31  *      1.3.5.1.5.2
32  * The OID of the krb5_name type is:
33  *      iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
34  *      krb5(2) krb5_name(1) = 1.2.840.113554.2.1.2.1
35  * The OID of the krb5_principal type is:
36  *      iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
37  *      krb5(2) krb5_principal(2) = 1.2.840.113554.2.1.2.2
38  */
39
40 /*
41  * Encoding rules: The first two values are encoded in one byte as 40
42  * * value1 + value2.  Subsequent values are encoded base 128, most
43  * significant digit first, with the high bit set on all octets except
44  * the last in each value's encoding.
45  */
46
47 static const gss_OID_desc oids[] = {
48    /* this OID is from Ted.  It's not official yet, but it's close. */
49    {5, "\053\005\001\005\002"},
50    {10, "\052\206\110\206\367\022\001\002\002\001"},
51    {10, "\052\206\110\206\367\022\001\002\002\002"},
52 };
53
54 const_gss_OID gss_mech_krb5 = oids+0;
55 const_gss_OID gss_nt_krb5_name = oids+1;
56 const_gss_OID gss_nt_krb5_principal = oids+2;
57
58 static const gss_OID_set_desc oidsets[] = {
59    {1, (gss_OID) oids},
60 };
61
62 const gss_OID_set_desc * const gss_mech_set_krb5 = oidsets+0;
63
64 krb5_context kg_context;
65
66 void *kg_vdb = NULL;
67
68 /** default credential support */
69
70 /* default credentials */
71
72 static gss_cred_id_t defcred = GSS_C_NO_CREDENTIAL;
73
74 /* XXX what happens when the default credentials expire or are invalidated? */
75
76 OM_uint32
77 kg_get_defcred(minor_status, cred)
78      OM_uint32 *minor_status;
79      gss_cred_id_t *cred;
80 {
81    if (defcred == GSS_C_NO_CREDENTIAL) {
82       OM_uint32 major;
83
84       if (!kg_context && kg_get_context())
85               return GSS_S_FAILURE;
86
87       if ((major = krb5_gss_acquire_cred(kg_context, minor_status, 
88                                          GSS_C_NO_NAME, GSS_C_INDEFINITE, 
89                                          GSS_C_NULL_OID_SET, GSS_C_INITIATE, 
90                                          &defcred, NULL, NULL)) &&
91           GSS_ERROR(major)) {
92          defcred = GSS_C_NO_CREDENTIAL;
93          return(major);
94       }
95    }
96
97    *cred = defcred;
98    *minor_status = 0;
99    return(GSS_S_COMPLETE);
100 }
101
102 OM_uint32
103 kg_release_defcred(minor_status)
104      OM_uint32 *minor_status;
105 {
106    if (defcred == GSS_C_NO_CREDENTIAL) {
107       *minor_status = 0;
108       return(GSS_S_COMPLETE);
109    }
110
111    if (!kg_context && kg_get_context())
112            return GSS_S_FAILURE;
113    
114    return(krb5_gss_release_cred(kg_context, minor_status, &defcred));
115 }
116
117 OM_uint32
118 kg_get_context()
119 {
120         if (kg_context)
121                 return GSS_S_COMPLETE;
122         if (krb5_init_context(&kg_context))
123                 return GSS_S_FAILURE;
124         return GSS_S_COMPLETE;
125 }