2 #include "heim_threads.h"
8 gss_buffer_desc maj_error
;
9 gss_buffer_desc min_error
;
12 static HEIMDAL_MUTEX context_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
13 static int created_key
;
14 static HEIMDAL_thread_key context_key
;
18 destroy_context(void *ptr
)
20 struct mg_thread_ctx
*mg
= ptr
;
26 gss_release_buffer(&junk
, &mg
->maj_error
);
27 gss_release_buffer(&junk
, &mg
->min_error
);
32 static struct mg_thread_ctx
*
33 _gss_mechglue_thread(void)
35 struct mg_thread_ctx
*ctx
;
38 HEIMDAL_MUTEX_lock(&context_mutex
);
41 HEIMDAL_key_create(&context_key
, destroy_context
, ret
);
43 HEIMDAL_MUTEX_unlock(&context_mutex
);
48 HEIMDAL_MUTEX_unlock(&context_mutex
);
50 ctx
= HEIMDAL_getspecific(context_key
);
53 ctx
= calloc(1, sizeof(*ctx
));
56 HEIMDAL_setspecific(context_key
, ctx
, ret
);
66 _gss_mg_get_error(const gss_OID mech
, OM_uint32 type
,
67 OM_uint32 value
, gss_buffer_t string
)
69 struct mg_thread_ctx
*mg
;
71 mg
= _gss_mechglue_thread();
73 return GSS_S_BAD_STATUS
;
77 * We cant check the mech here since a pseudo-mech might have
78 * called an lower layer and then the mech info is all broken
80 if (mech
!= NULL
&& gss_oid_equal(mg
->mech
, mech
) == 0)
81 return GSS_S_BAD_STATUS
;
85 case GSS_C_GSS_CODE
: {
86 if (value
!= mg
->maj_stat
|| mg
->maj_error
.length
== 0)
88 string
->value
= malloc(mg
->maj_error
.length
);
89 string
->length
= mg
->maj_error
.length
;
90 memcpy(string
->value
, mg
->maj_error
.value
, mg
->maj_error
.length
);
91 return GSS_S_COMPLETE
;
93 case GSS_C_MECH_CODE
: {
94 if (value
!= mg
->min_stat
|| mg
->min_error
.length
== 0)
96 string
->value
= malloc(mg
->min_error
.length
);
97 string
->length
= mg
->min_error
.length
;
98 memcpy(string
->value
, mg
->min_error
.value
, mg
->min_error
.length
);
99 return GSS_S_COMPLETE
;
102 string
->value
= NULL
;
104 return GSS_S_BAD_STATUS
;
108 _gss_mg_error(gssapi_mech_interface m
, OM_uint32 maj
, OM_uint32 min
)
110 OM_uint32 major_status
, minor_status
;
111 OM_uint32 message_content
;
112 struct mg_thread_ctx
*mg
;
115 * Mechs without gss_display_status() does
116 * gss_mg_collect_error() by themself.
118 if (m
->gm_display_status
== NULL
)
121 mg
= _gss_mechglue_thread();
125 gss_release_buffer(&minor_status
, &mg
->maj_error
);
126 gss_release_buffer(&minor_status
, &mg
->min_error
);
128 mg
->mech
= &m
->gm_mech_oid
;
132 major_status
= m
->gm_display_status(&minor_status
,
138 if (GSS_ERROR(major_status
)) {
139 mg
->maj_error
.value
= NULL
;
140 mg
->maj_error
.length
= 0;
142 major_status
= m
->gm_display_status(&minor_status
,
148 if (GSS_ERROR(major_status
)) {
149 mg
->min_error
.value
= NULL
;
150 mg
->min_error
.length
= 0;
155 gss_mg_collect_error(gss_OID mech
, OM_uint32 maj
, OM_uint32 min
)
157 gssapi_mech_interface m
= __gss_get_mechanism(mech
);
160 _gss_mg_error(m
, maj
, min
);