1 #include "mech/mech_locl.h"
2 #include "heim_threads.h"
10 gss_buffer_desc maj_error
;
11 gss_buffer_desc min_error
;
14 static HEIMDAL_MUTEX context_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
15 static int created_key
;
16 static HEIMDAL_thread_key context_key
;
20 destroy_context(void *ptr
)
22 struct mg_thread_ctx
*mg
= ptr
;
28 gss_release_buffer(&junk
, &mg
->maj_error
);
29 gss_release_buffer(&junk
, &mg
->min_error
);
34 static struct mg_thread_ctx
*
35 _gss_mechglue_thread(void)
37 struct mg_thread_ctx
*ctx
;
40 HEIMDAL_MUTEX_lock(&context_mutex
);
43 HEIMDAL_key_create(&context_key
, destroy_context
, ret
);
45 HEIMDAL_MUTEX_unlock(&context_mutex
);
50 HEIMDAL_MUTEX_unlock(&context_mutex
);
52 ctx
= HEIMDAL_getspecific(context_key
);
55 ctx
= calloc(1, sizeof(*ctx
));
58 HEIMDAL_setspecific(context_key
, ctx
, ret
);
68 _gss_mg_get_error(const gss_OID mech
, OM_uint32 type
,
69 OM_uint32 value
, gss_buffer_t string
)
71 struct mg_thread_ctx
*mg
;
73 mg
= _gss_mechglue_thread();
75 return GSS_S_BAD_STATUS
;
77 if (mech
!= NULL
&& gss_oid_equal(mg
->mech
, mech
) == 0)
78 return GSS_S_BAD_STATUS
;
81 case GSS_C_GSS_CODE
: {
82 if (value
!= mg
->maj_stat
|| mg
->maj_error
.length
== 0)
84 string
->value
= malloc(mg
->maj_error
.length
);
85 string
->length
= mg
->maj_error
.length
;
86 memcpy(string
->value
, mg
->maj_error
.value
, mg
->maj_error
.length
);
87 return GSS_S_COMPLETE
;
89 case GSS_C_MECH_CODE
: {
90 if (value
!= mg
->min_stat
|| mg
->min_error
.length
== 0)
92 string
->value
= malloc(mg
->min_error
.length
);
93 string
->length
= mg
->min_error
.length
;
94 memcpy(string
->value
, mg
->min_error
.value
, mg
->min_error
.length
);
95 return GSS_S_COMPLETE
;
100 return GSS_S_BAD_STATUS
;
104 _gss_mg_error(gssapi_mech_interface m
, OM_uint32 maj
, OM_uint32 min
)
106 OM_uint32 major_status
, minor_status
;
107 OM_uint32 message_content
;
108 struct mg_thread_ctx
*mg
;
111 * Mechs without gss_display_status() does
112 * gss_mg_collect_error() by themself.
114 if (m
->gm_display_status
== NULL
)
117 mg
= _gss_mechglue_thread();
121 gss_release_buffer(&minor_status
, &mg
->maj_error
);
122 gss_release_buffer(&minor_status
, &mg
->min_error
);
124 mg
->mech
= &m
->gm_mech_oid
;
128 major_status
= m
->gm_display_status(&minor_status
,
134 if (GSS_ERROR(major_status
)) {
135 mg
->maj_error
.value
= NULL
;
136 mg
->maj_error
.length
= 0;
138 major_status
= m
->gm_display_status(&minor_status
,
144 if (GSS_ERROR(major_status
)) {
145 mg
->min_error
.value
= NULL
;
146 mg
->min_error
.length
= 0;
151 gss_mg_collect_error(gss_OID mech
, OM_uint32 maj
, OM_uint32 min
)
153 gssapi_mech_interface m
= __gss_get_mechanism(mech
);
156 _gss_mg_error(m
, maj
, min
);