| 1 |
/* |
| 2 |
* Copyright (c) 2010 Kungliga Tekniska Högskolan |
| 3 |
* (Royal Institute of Technology, Stockholm, Sweden). |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Portions Copyright (c) 2010 Apple Inc. All rights reserved. |
| 7 |
* Portions Copyright (c) 2010 PADL Software Pty Ltd. All rights reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted provided that the following conditions |
| 11 |
* are met: |
| 12 |
* |
| 13 |
* 1. Redistributions of source code must retain the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer. |
| 15 |
* |
| 16 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 17 |
* notice, this list of conditions and the following disclaimer in the |
| 18 |
* documentation and/or other materials provided with the distribution. |
| 19 |
* |
| 20 |
* 3. Neither the name of the Institute nor the names of its contributors |
| 21 |
* may be used to endorse or promote products derived from this software |
| 22 |
* without specific prior written permission. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 25 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 28 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 29 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 30 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 31 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 33 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 |
* SUCH DAMAGE. |
| 35 |
*/ |
| 36 |
|
| 37 |
#include "mech_locl.h" |
| 38 |
|
| 39 |
#include <crypto-headers.h> |
| 40 |
|
| 41 |
static int |
| 42 |
get_option_def(int def, gss_const_OID mech, gss_mo_desc *mo, gss_buffer_t value) |
| 43 |
{ |
| 44 |
return def; |
| 45 |
} |
| 46 |
|
| 47 |
int |
| 48 |
_gss_mo_get_option_1(gss_const_OID mech, gss_mo_desc *mo, gss_buffer_t value) |
| 49 |
{ |
| 50 |
return get_option_def(1, mech, mo, value); |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
_gss_mo_get_option_0(gss_const_OID mech, gss_mo_desc *mo, gss_buffer_t value) |
| 55 |
{ |
| 56 |
return get_option_def(0, mech, mo, value); |
| 57 |
} |
| 58 |
|
| 59 |
int |
| 60 |
_gss_mo_get_ctx_as_string(gss_const_OID mech, gss_mo_desc *mo, gss_buffer_t value) |
| 61 |
{ |
| 62 |
if (value) { |
| 63 |
value->value = strdup((char *)mo->ctx); |
| 64 |
if (value->value == NULL) |
| 65 |
return GSS_S_FAILURE; |
| 66 |
value->length = strlen((char *)mo->ctx); |
| 67 |
} |
| 68 |
return GSS_S_COMPLETE; |
| 69 |
} |
| 70 |
|
| 71 |
GSSAPI_LIB_FUNCTION int GSSAPI_LIB_CALL |
| 72 |
gss_mo_set(gss_const_OID mech, gss_const_OID option, |
| 73 |
int enable, gss_buffer_t value) |
| 74 |
{ |
| 75 |
gssapi_mech_interface m; |
| 76 |
size_t n; |
| 77 |
|
| 78 |
if ((m = __gss_get_mechanism(mech)) == NULL) |
| 79 |
return GSS_S_BAD_MECH; |
| 80 |
|
| 81 |
for (n = 0; n < m->gm_mo_num; n++) |
| 82 |
if (gss_oid_equal(option, m->gm_mo[n].option) && m->gm_mo[n].set) |
| 83 |
return m->gm_mo[n].set(mech, &m->gm_mo[n], enable, value); |
| 84 |
|
| 85 |
return GSS_S_UNAVAILABLE; |
| 86 |
} |
| 87 |
|
| 88 |
GSSAPI_LIB_FUNCTION int GSSAPI_LIB_CALL |
| 89 |
gss_mo_get(gss_const_OID mech, gss_const_OID option, gss_buffer_t value) |
| 90 |
{ |
| 91 |
gssapi_mech_interface m; |
| 92 |
size_t n; |
| 93 |
|
| 94 |
_mg_buffer_zero(value); |
| 95 |
|
| 96 |
if ((m = __gss_get_mechanism(mech)) == NULL) |
| 97 |
return GSS_S_BAD_MECH; |
| 98 |
|
| 99 |
for (n = 0; n < m->gm_mo_num; n++) |
| 100 |
if (gss_oid_equal(option, m->gm_mo[n].option) && m->gm_mo[n].get) |
| 101 |
return m->gm_mo[n].get(mech, &m->gm_mo[n], value); |
| 102 |
|
| 103 |
return GSS_S_UNAVAILABLE; |
| 104 |
} |
| 105 |
|
| 106 |
static void |
| 107 |
add_all_mo(gssapi_mech_interface m, gss_OID_set *options, OM_uint32 mask) |
| 108 |
{ |
| 109 |
OM_uint32 minor; |
| 110 |
size_t n; |
| 111 |
|
| 112 |
for (n = 0; n < m->gm_mo_num; n++) |
| 113 |
if ((m->gm_mo[n].flags & mask) == mask) |
| 114 |
gss_add_oid_set_member(&minor, m->gm_mo[n].option, options); |
| 115 |
} |
| 116 |
|
| 117 |
GSSAPI_LIB_FUNCTION void GSSAPI_LIB_CALL |
| 118 |
gss_mo_list(gss_const_OID mech, gss_OID_set *options) |
| 119 |
{ |
| 120 |
gssapi_mech_interface m; |
| 121 |
OM_uint32 major, minor; |
| 122 |
|
| 123 |
if (options == NULL) |
| 124 |
return; |
| 125 |
|
| 126 |
*options = GSS_C_NO_OID_SET; |
| 127 |
|
| 128 |
if ((m = __gss_get_mechanism(mech)) == NULL) |
| 129 |
return; |
| 130 |
|
| 131 |
major = gss_create_empty_oid_set(&minor, options); |
| 132 |
if (major != GSS_S_COMPLETE) |
| 133 |
return; |
| 134 |
|
| 135 |
add_all_mo(m, options, 0); |
| 136 |
} |
| 137 |
|
| 138 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 139 |
gss_mo_name(gss_const_OID mech, gss_const_OID option, gss_buffer_t name) |
| 140 |
{ |
| 141 |
gssapi_mech_interface m; |
| 142 |
size_t n; |
| 143 |
|
| 144 |
if (name == NULL) |
| 145 |
return GSS_S_BAD_NAME; |
| 146 |
|
| 147 |
if ((m = __gss_get_mechanism(mech)) == NULL) |
| 148 |
return GSS_S_BAD_MECH; |
| 149 |
|
| 150 |
for (n = 0; n < m->gm_mo_num; n++) { |
| 151 |
if (gss_oid_equal(option, m->gm_mo[n].option)) { |
| 152 |
/* |
| 153 |
* If there is no name, its because its a GSS_C_MA and |
| 154 |
* there is already a table for that. |
| 155 |
*/ |
| 156 |
if (m->gm_mo[n].name) { |
| 157 |
name->value = strdup(m->gm_mo[n].name); |
| 158 |
if (name->value == NULL) |
| 159 |
return GSS_S_BAD_NAME; |
| 160 |
name->length = strlen(m->gm_mo[n].name); |
| 161 |
return GSS_S_COMPLETE; |
| 162 |
} else { |
| 163 |
OM_uint32 junk; |
| 164 |
return gss_display_mech_attr(&junk, option, |
| 165 |
NULL, name, NULL); |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
return GSS_S_BAD_NAME; |
| 170 |
} |
| 171 |
|
| 172 |
/* |
| 173 |
* Helper function to allow NULL name |
| 174 |
*/ |
| 175 |
|
| 176 |
static OM_uint32 |
| 177 |
mo_value(const gss_const_OID mech, gss_const_OID option, gss_buffer_t name) |
| 178 |
{ |
| 179 |
if (name == NULL) |
| 180 |
return GSS_S_COMPLETE; |
| 181 |
|
| 182 |
return gss_mo_get(mech, option, name); |
| 183 |
} |
| 184 |
|
| 185 |
/* code derived from draft-ietf-cat-sasl-gssapi-01 */ |
| 186 |
static char basis_32[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; |
| 187 |
|
| 188 |
static OM_uint32 |
| 189 |
make_sasl_name(OM_uint32 *minor, const gss_OID mech, char sasl_name[16]) |
| 190 |
{ |
| 191 |
EVP_MD_CTX *ctx; |
| 192 |
char *p = sasl_name; |
| 193 |
u_char hdr[2], hash[20], *h = hash; |
| 194 |
|
| 195 |
if (mech->length > 127) |
| 196 |
return GSS_S_BAD_MECH; |
| 197 |
|
| 198 |
hdr[0] = 0x06; |
| 199 |
hdr[1] = mech->length; |
| 200 |
|
| 201 |
ctx = EVP_MD_CTX_create(); |
| 202 |
EVP_DigestInit_ex(ctx, EVP_sha1(), NULL); |
| 203 |
EVP_DigestUpdate(ctx, hdr, 2); |
| 204 |
EVP_DigestUpdate(ctx, mech->elements, mech->length); |
| 205 |
EVP_DigestFinal_ex(ctx, hash, NULL); |
| 206 |
EVP_MD_CTX_destroy(ctx); |
| 207 |
|
| 208 |
memcpy(p, "GS2-", 4); |
| 209 |
p += 4; |
| 210 |
|
| 211 |
*p++ = basis_32[(h[0] >> 3)]; |
| 212 |
*p++ = basis_32[((h[0] & 7) << 2) | (h[1] >> 6)]; |
| 213 |
*p++ = basis_32[(h[1] & 0x3f) >> 1]; |
| 214 |
*p++ = basis_32[((h[1] & 1) << 4) | (h[2] >> 4)]; |
| 215 |
*p++ = basis_32[((h[2] & 0xf) << 1) | (h[3] >> 7)]; |
| 216 |
*p++ = basis_32[(h[3] & 0x7f) >> 2]; |
| 217 |
*p++ = basis_32[((h[3] & 3) << 3) | (h[4] >> 5)]; |
| 218 |
*p++ = basis_32[(h[4] & 0x1f)]; |
| 219 |
*p++ = basis_32[(h[5] >> 3)]; |
| 220 |
*p++ = basis_32[((h[5] & 7) << 2) | (h[6] >> 6)]; |
| 221 |
*p++ = basis_32[(h[6] & 0x3f) >> 1]; |
| 222 |
|
| 223 |
*p = '\0'; |
| 224 |
|
| 225 |
return GSS_S_COMPLETE; |
| 226 |
} |
| 227 |
|
| 228 |
/* |
| 229 |
* gss_inquire_saslname_for_mech() wrapper that uses MIT SPI |
| 230 |
*/ |
| 231 |
static OM_uint32 |
| 232 |
inquire_saslname_for_mech_compat(OM_uint32 *minor, |
| 233 |
const gss_OID desired_mech, |
| 234 |
gss_buffer_t sasl_mech_name, |
| 235 |
gss_buffer_t mech_name, |
| 236 |
gss_buffer_t mech_description) |
| 237 |
{ |
| 238 |
struct gss_mech_compat_desc_struct *gmc; |
| 239 |
gssapi_mech_interface m; |
| 240 |
OM_uint32 major; |
| 241 |
|
| 242 |
m = __gss_get_mechanism(desired_mech); |
| 243 |
if (m == NULL) |
| 244 |
return GSS_S_BAD_MECH; |
| 245 |
|
| 246 |
gmc = m->gm_compat; |
| 247 |
|
| 248 |
if (gmc != NULL && gmc->gmc_inquire_saslname_for_mech != NULL) { |
| 249 |
major = gmc->gmc_inquire_saslname_for_mech(minor, |
| 250 |
desired_mech, |
| 251 |
sasl_mech_name, |
| 252 |
mech_name, |
| 253 |
mech_description); |
| 254 |
} else { |
| 255 |
major = GSS_S_UNAVAILABLE; |
| 256 |
} |
| 257 |
|
| 258 |
return major; |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Returns different protocol names and description of the mechanism. |
| 263 |
* |
| 264 |
* @param minor_status minor status code |
| 265 |
* @param desired_mech mech list query |
| 266 |
* @param sasl_mech_name SASL GS2 protocol name |
| 267 |
* @param mech_name gssapi protocol name |
| 268 |
* @param mech_description description of gssapi mech |
| 269 |
* |
| 270 |
* @return returns GSS_S_COMPLETE or a error code. |
| 271 |
* |
| 272 |
* @ingroup gssapi |
| 273 |
*/ |
| 274 |
|
| 275 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 276 |
gss_inquire_saslname_for_mech(OM_uint32 *minor_status, |
| 277 |
const gss_OID desired_mech, |
| 278 |
gss_buffer_t sasl_mech_name, |
| 279 |
gss_buffer_t mech_name, |
| 280 |
gss_buffer_t mech_description) |
| 281 |
{ |
| 282 |
OM_uint32 major; |
| 283 |
|
| 284 |
_mg_buffer_zero(sasl_mech_name); |
| 285 |
_mg_buffer_zero(mech_name); |
| 286 |
_mg_buffer_zero(mech_description); |
| 287 |
|
| 288 |
if (minor_status) |
| 289 |
*minor_status = 0; |
| 290 |
|
| 291 |
if (desired_mech == NULL) |
| 292 |
return GSS_S_BAD_MECH; |
| 293 |
|
| 294 |
major = mo_value(desired_mech, GSS_C_MA_SASL_MECH_NAME, sasl_mech_name); |
| 295 |
if (major == GSS_S_COMPLETE) { |
| 296 |
/* Native SPI */ |
| 297 |
major = mo_value(desired_mech, GSS_C_MA_MECH_NAME, mech_name); |
| 298 |
if (GSS_ERROR(major)) |
| 299 |
return major; |
| 300 |
|
| 301 |
major = mo_value(desired_mech, GSS_C_MA_MECH_DESCRIPTION, mech_description); |
| 302 |
if (GSS_ERROR(major)) |
| 303 |
return major; |
| 304 |
} |
| 305 |
|
| 306 |
if (GSS_ERROR(major)) { |
| 307 |
/* API-as-SPI compatibility */ |
| 308 |
major = inquire_saslname_for_mech_compat(minor_status, |
| 309 |
desired_mech, |
| 310 |
sasl_mech_name, |
| 311 |
mech_name, |
| 312 |
mech_description); |
| 313 |
} |
| 314 |
|
| 315 |
if (GSS_ERROR(major)) { |
| 316 |
/* Algorithmically dervied SASL mechanism name */ |
| 317 |
char buf[16]; |
| 318 |
gss_buffer_desc tmp = { sizeof(buf) - 1, buf }; |
| 319 |
|
| 320 |
major = make_sasl_name(minor_status, desired_mech, buf); |
| 321 |
if (GSS_ERROR(major)) |
| 322 |
return major; |
| 323 |
|
| 324 |
major = _gss_copy_buffer(minor_status, &tmp, sasl_mech_name); |
| 325 |
if (GSS_ERROR(major)) |
| 326 |
return major; |
| 327 |
} |
| 328 |
|
| 329 |
return major; |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Find a mech for a sasl name |
| 334 |
* |
| 335 |
* @param minor_status minor status code |
| 336 |
* @param sasl_mech_name |
| 337 |
* @param mech_type |
| 338 |
* |
| 339 |
* @return returns GSS_S_COMPLETE or an error code. |
| 340 |
*/ |
| 341 |
|
| 342 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 343 |
gss_inquire_mech_for_saslname(OM_uint32 *minor_status, |
| 344 |
const gss_buffer_t sasl_mech_name, |
| 345 |
gss_OID *mech_type) |
| 346 |
{ |
| 347 |
struct _gss_mech_switch *m; |
| 348 |
gss_buffer_desc name; |
| 349 |
OM_uint32 major, junk; |
| 350 |
char buf[16]; |
| 351 |
|
| 352 |
_gss_load_mech(); |
| 353 |
|
| 354 |
*mech_type = NULL; |
| 355 |
|
| 356 |
HEIM_SLIST_FOREACH(m, &_gss_mechs, gm_link) { |
| 357 |
struct gss_mech_compat_desc_struct *gmc; |
| 358 |
|
| 359 |
/* Native SPI */ |
| 360 |
major = mo_value(&m->gm_mech_oid, GSS_C_MA_SASL_MECH_NAME, &name); |
| 361 |
if (major == GSS_S_COMPLETE && |
| 362 |
name.length == sasl_mech_name->length && |
| 363 |
memcmp(name.value, sasl_mech_name->value, name.length) == 0) { |
| 364 |
gss_release_buffer(&junk, &name); |
| 365 |
*mech_type = &m->gm_mech_oid; |
| 366 |
return GSS_S_COMPLETE; |
| 367 |
} |
| 368 |
gss_release_buffer(&junk, &name); |
| 369 |
|
| 370 |
if (GSS_ERROR(major)) { |
| 371 |
/* API-as-SPI compatibility */ |
| 372 |
gmc = m->gm_mech.gm_compat; |
| 373 |
if (gmc && gmc->gmc_inquire_mech_for_saslname) { |
| 374 |
major = gmc->gmc_inquire_mech_for_saslname(minor_status, |
| 375 |
sasl_mech_name, |
| 376 |
mech_type); |
| 377 |
if (major == GSS_S_COMPLETE) |
| 378 |
return GSS_S_COMPLETE; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
if (GSS_ERROR(major)) { |
| 383 |
/* Algorithmically dervied SASL mechanism name */ |
| 384 |
if (sasl_mech_name->length == 16 && |
| 385 |
make_sasl_name(minor_status, &m->gm_mech_oid, buf) == GSS_S_COMPLETE && |
| 386 |
memcmp(buf, sasl_mech_name->value, 16) == 0) { |
| 387 |
*mech_type = &m->gm_mech_oid; |
| 388 |
return GSS_S_COMPLETE; |
| 389 |
} |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
return GSS_S_BAD_MECH; |
| 394 |
} |
| 395 |
|
| 396 |
/* |
| 397 |
* Test mechanism against indicated attributes using both Heimdal and |
| 398 |
* MIT SPIs. |
| 399 |
*/ |
| 400 |
static int |
| 401 |
test_mech_attrs(gssapi_mech_interface mi, |
| 402 |
gss_const_OID_set mech_attrs, |
| 403 |
gss_const_OID_set against_attrs, |
| 404 |
int except) |
| 405 |
{ |
| 406 |
size_t n, m; |
| 407 |
int eq = 0; |
| 408 |
|
| 409 |
if (against_attrs == GSS_C_NO_OID_SET) |
| 410 |
return 1; |
| 411 |
|
| 412 |
for (n = 0; n < against_attrs->count; n++) { |
| 413 |
for (m = 0; m < mi->gm_mo_num; m++) { |
| 414 |
eq = gss_oid_equal(mi->gm_mo[m].option, |
| 415 |
&against_attrs->elements[n]); |
| 416 |
if (eq) |
| 417 |
break; |
| 418 |
} |
| 419 |
if (mech_attrs != GSS_C_NO_OID_SET) { |
| 420 |
for (m = 0; m < mech_attrs->count; m++) { |
| 421 |
eq = gss_oid_equal(&mech_attrs->elements[m], |
| 422 |
&against_attrs->elements[n]); |
| 423 |
if (eq) |
| 424 |
break; |
| 425 |
} |
| 426 |
} |
| 427 |
if (!eq ^ except) |
| 428 |
return 0; |
| 429 |
} |
| 430 |
|
| 431 |
return 1; |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Return set of mechanism that fullfill the criteria |
| 436 |
* |
| 437 |
* @param minor_status minor status code |
| 438 |
* @param desired_mech_attrs |
| 439 |
* @param except_mech_attrs |
| 440 |
* @param critical_mech_attrs |
| 441 |
* @param mechs returned mechs, free with gss_release_oid_set(). |
| 442 |
* |
| 443 |
* @return returns GSS_S_COMPLETE or an error code. |
| 444 |
*/ |
| 445 |
|
| 446 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 447 |
gss_indicate_mechs_by_attrs(OM_uint32 * minor_status, |
| 448 |
gss_const_OID_set desired_mech_attrs, |
| 449 |
gss_const_OID_set except_mech_attrs, |
| 450 |
gss_const_OID_set critical_mech_attrs, |
| 451 |
gss_OID_set *mechs) |
| 452 |
{ |
| 453 |
struct _gss_mech_switch *ms; |
| 454 |
gss_OID_set mech_attrs = GSS_C_NO_OID_SET; |
| 455 |
gss_OID_set known_mech_attrs = GSS_C_NO_OID_SET; |
| 456 |
OM_uint32 major; |
| 457 |
|
| 458 |
major = gss_create_empty_oid_set(minor_status, mechs); |
| 459 |
if (GSS_ERROR(major)) |
| 460 |
return major; |
| 461 |
|
| 462 |
_gss_load_mech(); |
| 463 |
|
| 464 |
HEIM_SLIST_FOREACH(ms, &_gss_mechs, gm_link) { |
| 465 |
gssapi_mech_interface mi = &ms->gm_mech; |
| 466 |
struct gss_mech_compat_desc_struct *gmc = mi->gm_compat; |
| 467 |
OM_uint32 tmp; |
| 468 |
|
| 469 |
if (gmc && gmc->gmc_inquire_attrs_for_mech) { |
| 470 |
major = gmc->gmc_inquire_attrs_for_mech(minor_status, |
| 471 |
&mi->gm_mech_oid, |
| 472 |
&mech_attrs, |
| 473 |
&known_mech_attrs); |
| 474 |
if (GSS_ERROR(major)) |
| 475 |
continue; |
| 476 |
} |
| 477 |
|
| 478 |
/* |
| 479 |
* Test mechanism supports all of desired_mech_attrs; |
| 480 |
* none of except_mech_attrs; |
| 481 |
* and knows of all critical_mech_attrs. |
| 482 |
*/ |
| 483 |
if (test_mech_attrs(mi, mech_attrs, desired_mech_attrs, 0) && |
| 484 |
test_mech_attrs(mi, mech_attrs, except_mech_attrs, 1) && |
| 485 |
test_mech_attrs(mi, known_mech_attrs, critical_mech_attrs, 0)) { |
| 486 |
major = gss_add_oid_set_member(minor_status, &mi->gm_mech_oid, mechs); |
| 487 |
} |
| 488 |
|
| 489 |
gss_release_oid_set(&tmp, &mech_attrs); |
| 490 |
gss_release_oid_set(&tmp, &known_mech_attrs); |
| 491 |
|
| 492 |
if (GSS_ERROR(major)) |
| 493 |
break; |
| 494 |
} |
| 495 |
|
| 496 |
return major; |
| 497 |
} |
| 498 |
|
| 499 |
/** |
| 500 |
* List support attributes for a mech and/or all mechanisms. |
| 501 |
* |
| 502 |
* @param minor_status minor status code |
| 503 |
* @param mech given together with mech_attr will return the list of |
| 504 |
* attributes for mechanism, can optionally be GSS_C_NO_OID. |
| 505 |
* @param mech_attr see mech parameter, can optionally be NULL, |
| 506 |
* release with gss_release_oid_set(). |
| 507 |
* @param known_mech_attrs all attributes for mechanisms supported, |
| 508 |
* release with gss_release_oid_set(). |
| 509 |
* |
| 510 |
* @ingroup gssapi |
| 511 |
*/ |
| 512 |
|
| 513 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 514 |
gss_inquire_attrs_for_mech(OM_uint32 * minor_status, |
| 515 |
gss_const_OID mech, |
| 516 |
gss_OID_set *mech_attr, |
| 517 |
gss_OID_set *known_mech_attrs) |
| 518 |
{ |
| 519 |
OM_uint32 major, junk; |
| 520 |
|
| 521 |
if (known_mech_attrs) |
| 522 |
*known_mech_attrs = GSS_C_NO_OID_SET; |
| 523 |
|
| 524 |
if (mech_attr && mech) { |
| 525 |
gssapi_mech_interface m; |
| 526 |
struct gss_mech_compat_desc_struct *gmc; |
| 527 |
|
| 528 |
if ((m = __gss_get_mechanism(mech)) == NULL) { |
| 529 |
*minor_status = 0; |
| 530 |
return GSS_S_BAD_MECH; |
| 531 |
} |
| 532 |
|
| 533 |
gmc = m->gm_compat; |
| 534 |
|
| 535 |
if (gmc && gmc->gmc_inquire_attrs_for_mech) { |
| 536 |
major = gmc->gmc_inquire_attrs_for_mech(minor_status, |
| 537 |
mech, |
| 538 |
mech_attr, |
| 539 |
known_mech_attrs); |
| 540 |
} else { |
| 541 |
major = gss_create_empty_oid_set(minor_status, mech_attr); |
| 542 |
if (major == GSS_S_COMPLETE) |
| 543 |
add_all_mo(m, mech_attr, GSS_MO_MA); |
| 544 |
} |
| 545 |
if (GSS_ERROR(major)) |
| 546 |
return major; |
| 547 |
} |
| 548 |
|
| 549 |
if (known_mech_attrs) { |
| 550 |
struct _gss_mech_switch *m; |
| 551 |
|
| 552 |
if (*known_mech_attrs == GSS_C_NO_OID_SET) { |
| 553 |
major = gss_create_empty_oid_set(minor_status, known_mech_attrs); |
| 554 |
if (GSS_ERROR(major)) { |
| 555 |
if (mech_attr) |
| 556 |
gss_release_oid_set(&junk, mech_attr); |
| 557 |
return major; |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
_gss_load_mech(); |
| 562 |
|
| 563 |
HEIM_SLIST_FOREACH(m, &_gss_mechs, gm_link) |
| 564 |
add_all_mo(&m->gm_mech, known_mech_attrs, GSS_MO_MA); |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
return GSS_S_COMPLETE; |
| 569 |
} |
| 570 |
|
| 571 |
/** |
| 572 |
* Return names and descriptions of mech attributes |
| 573 |
* |
| 574 |
* @param minor_status minor status code |
| 575 |
* @param mech_attr |
| 576 |
* @param name |
| 577 |
* @param short_desc |
| 578 |
* @param long_desc |
| 579 |
* |
| 580 |
* @return returns GSS_S_COMPLETE or an error code. |
| 581 |
*/ |
| 582 |
|
| 583 |
GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL |
| 584 |
gss_display_mech_attr(OM_uint32 * minor_status, |
| 585 |
gss_const_OID mech_attr, |
| 586 |
gss_buffer_t name, |
| 587 |
gss_buffer_t short_desc, |
| 588 |
gss_buffer_t long_desc) |
| 589 |
{ |
| 590 |
struct _gss_oid_name_table *ma = NULL; |
| 591 |
OM_uint32 major; |
| 592 |
size_t n; |
| 593 |
|
| 594 |
_mg_buffer_zero(name); |
| 595 |
_mg_buffer_zero(short_desc); |
| 596 |
_mg_buffer_zero(long_desc); |
| 597 |
|
| 598 |
if (minor_status) |
| 599 |
*minor_status = 0; |
| 600 |
|
| 601 |
for (n = 0; ma == NULL && _gss_ont_ma[n].oid; n++) |
| 602 |
if (gss_oid_equal(mech_attr, _gss_ont_ma[n].oid)) |
| 603 |
ma = &_gss_ont_ma[n]; |
| 604 |
|
| 605 |
if (ma == NULL) |
| 606 |
return GSS_S_BAD_MECH_ATTR; |
| 607 |
|
| 608 |
if (name) { |
| 609 |
gss_buffer_desc bd; |
| 610 |
bd.value = rk_UNCONST(ma->name); |
| 611 |
bd.length = strlen(ma->name); |
| 612 |
major = _gss_copy_buffer(minor_status, &bd, name); |
| 613 |
if (major != GSS_S_COMPLETE) |
| 614 |
return major; |
| 615 |
} |
| 616 |
|
| 617 |
if (short_desc) { |
| 618 |
gss_buffer_desc bd; |
| 619 |
bd.value = rk_UNCONST(ma->short_desc); |
| 620 |
bd.length = strlen(ma->short_desc); |
| 621 |
major = _gss_copy_buffer(minor_status, &bd, short_desc); |
| 622 |
if (major != GSS_S_COMPLETE) |
| 623 |
return major; |
| 624 |
} |
| 625 |
|
| 626 |
if (long_desc) { |
| 627 |
gss_buffer_desc bd; |
| 628 |
bd.value = rk_UNCONST(ma->long_desc); |
| 629 |
bd.length = strlen(ma->long_desc); |
| 630 |
major = _gss_copy_buffer(minor_status, &bd, long_desc); |
| 631 |
if (major != GSS_S_COMPLETE) |
| 632 |
return major; |
| 633 |
} |
| 634 |
|
| 635 |
return GSS_S_COMPLETE; |
| 636 |
} |