1 /* lib/gssapi/mechglue/g_set_neg_mechs.c - Glue for gss_set_neg_mechs */
2 /*
3 * Copyright (C) 2010 by the Massachusetts Institute of Technology.
4 * All rights reserved.
5 *
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
10 *
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
24 */
25
26 #include "mglueP.h"
27
28 OM_uint32 KRB5_CALLCONV
gss_set_neg_mechs(OM_uint32 * minor_status,gss_cred_id_t cred_handle,const gss_OID_set mech_set)29 gss_set_neg_mechs(OM_uint32 *minor_status,
30 gss_cred_id_t cred_handle,
31 const gss_OID_set mech_set)
32 {
33 gss_union_cred_t union_cred;
34 gss_mechanism mech;
35 int i, avail;
36 OM_uint32 status;
37
38 if (minor_status == NULL)
39 return GSS_S_CALL_INACCESSIBLE_WRITE;
40 *minor_status = 0;
41
42 if (cred_handle == GSS_C_NO_CREDENTIAL)
43 return GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CRED;
44
45 union_cred = (gss_union_cred_t) cred_handle;
46
47 avail = 0;
48 status = GSS_S_COMPLETE;
49 for (i = 0; i < union_cred->count; i++) {
50 mech = gssint_get_mechanism(&union_cred->mechs_array[i]);
51 if (mech == NULL) {
52 status = GSS_S_BAD_MECH;
53 break;
54 }
55
56 if (mech->gss_set_neg_mechs == NULL)
57 continue;
58
59 avail = 1;
60 status = (mech->gss_set_neg_mechs)(minor_status,
61 union_cred->cred_array[i],
62 mech_set);
63 if (status != GSS_S_COMPLETE) {
64 map_error(minor_status, mech);
65 break;
66 }
67 }
68
69 if (status == GSS_S_COMPLETE && !avail)
70 return GSS_S_UNAVAILABLE;
71 return status;
72 }
73