17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5503a2b89SPeter Shoults * Common Development and Distribution License (the "License").
6503a2b89SPeter Shoults * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*5e01956fSGlenn Barry * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * glue routine for gss_store_cred
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <mechglueP.h>
30*5e01956fSGlenn Barry #include "gssapiP_generic.h"
31*5e01956fSGlenn Barry #include <errno.h>
327c478bd9Sstevel@tonic-gate
33*5e01956fSGlenn Barry static OM_uint32
val_store_cred_args(OM_uint32 * minor_status,const gss_cred_id_t input_cred_handle,gss_cred_usage_t cred_usage,const gss_OID desired_mech,OM_uint32 overwrite_cred,OM_uint32 default_cred,gss_OID_set * elements_stored,gss_cred_usage_t * cred_usage_stored)34*5e01956fSGlenn Barry val_store_cred_args(
35503a2b89SPeter Shoults OM_uint32 *minor_status,
36503a2b89SPeter Shoults const gss_cred_id_t input_cred_handle,
37*5e01956fSGlenn Barry gss_cred_usage_t cred_usage,
38*5e01956fSGlenn Barry /*LINTED*/
39*5e01956fSGlenn Barry const gss_OID desired_mech,
40*5e01956fSGlenn Barry /*LINTED*/
41*5e01956fSGlenn Barry OM_uint32 overwrite_cred,
42*5e01956fSGlenn Barry /*LINTED*/
43*5e01956fSGlenn Barry OM_uint32 default_cred,
44*5e01956fSGlenn Barry gss_OID_set *elements_stored,
45*5e01956fSGlenn Barry /*LINTED*/
46*5e01956fSGlenn Barry gss_cred_usage_t *cred_usage_stored)
47503a2b89SPeter Shoults {
48503a2b89SPeter Shoults
49503a2b89SPeter Shoults /* Initialize outputs. */
50503a2b89SPeter Shoults
51503a2b89SPeter Shoults if (minor_status != NULL)
52503a2b89SPeter Shoults *minor_status = 0;
53503a2b89SPeter Shoults
54503a2b89SPeter Shoults if (elements_stored != NULL)
55503a2b89SPeter Shoults *elements_stored = GSS_C_NULL_OID_SET;
56503a2b89SPeter Shoults
57503a2b89SPeter Shoults /* Validate arguments. */
58503a2b89SPeter Shoults
59503a2b89SPeter Shoults if (minor_status == NULL)
60503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_WRITE);
61503a2b89SPeter Shoults
62503a2b89SPeter Shoults if (input_cred_handle == GSS_C_NO_CREDENTIAL)
63503a2b89SPeter Shoults return (GSS_S_CALL_INACCESSIBLE_READ | GSS_S_NO_CRED);
64503a2b89SPeter Shoults
65*5e01956fSGlenn Barry if (cred_usage != GSS_C_ACCEPT
66*5e01956fSGlenn Barry && cred_usage != GSS_C_INITIATE
67*5e01956fSGlenn Barry && cred_usage != GSS_C_BOTH) {
68*5e01956fSGlenn Barry if (minor_status) {
69*5e01956fSGlenn Barry *minor_status = EINVAL;
70*5e01956fSGlenn Barry map_errcode(minor_status);
71*5e01956fSGlenn Barry }
72*5e01956fSGlenn Barry return GSS_S_FAILURE;
73*5e01956fSGlenn Barry }
74*5e01956fSGlenn Barry
75503a2b89SPeter Shoults return (GSS_S_COMPLETE);
76503a2b89SPeter Shoults }
77503a2b89SPeter Shoults
gss_store_cred(minor_status,input_cred_handle,cred_usage,desired_mech,overwrite_cred,default_cred,elements_stored,cred_usage_stored)787c478bd9Sstevel@tonic-gate OM_uint32 gss_store_cred(minor_status,
797c478bd9Sstevel@tonic-gate input_cred_handle,
807c478bd9Sstevel@tonic-gate cred_usage,
817c478bd9Sstevel@tonic-gate desired_mech,
827c478bd9Sstevel@tonic-gate overwrite_cred,
837c478bd9Sstevel@tonic-gate default_cred,
847c478bd9Sstevel@tonic-gate elements_stored,
857c478bd9Sstevel@tonic-gate cred_usage_stored)
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate OM_uint32 *minor_status;
887c478bd9Sstevel@tonic-gate const gss_cred_id_t input_cred_handle;
897c478bd9Sstevel@tonic-gate gss_cred_usage_t cred_usage;
907c478bd9Sstevel@tonic-gate const gss_OID desired_mech;
917c478bd9Sstevel@tonic-gate OM_uint32 overwrite_cred;
927c478bd9Sstevel@tonic-gate OM_uint32 default_cred;
937c478bd9Sstevel@tonic-gate gss_OID_set *elements_stored;
947c478bd9Sstevel@tonic-gate gss_cred_usage_t *cred_usage_stored;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate OM_uint32 major_status = GSS_S_FAILURE;
987c478bd9Sstevel@tonic-gate gss_union_cred_t union_cred;
997c478bd9Sstevel@tonic-gate gss_cred_id_t mech_cred;
1007c478bd9Sstevel@tonic-gate gss_mechanism mech;
1017c478bd9Sstevel@tonic-gate gss_OID dmech;
1027c478bd9Sstevel@tonic-gate int i;
1037c478bd9Sstevel@tonic-gate
104503a2b89SPeter Shoults major_status = val_store_cred_args(minor_status,
105503a2b89SPeter Shoults input_cred_handle,
106*5e01956fSGlenn Barry cred_usage,
107*5e01956fSGlenn Barry desired_mech,
108*5e01956fSGlenn Barry overwrite_cred,
109*5e01956fSGlenn Barry default_cred,
110*5e01956fSGlenn Barry elements_stored,
111*5e01956fSGlenn Barry cred_usage_stored);
112503a2b89SPeter Shoults if (major_status != GSS_S_COMPLETE)
113503a2b89SPeter Shoults return (major_status);
1147c478bd9Sstevel@tonic-gate
115503a2b89SPeter Shoults /* Initial value needed below. */
116503a2b89SPeter Shoults major_status = GSS_S_FAILURE;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate if (cred_usage_stored != NULL)
1197c478bd9Sstevel@tonic-gate *cred_usage_stored = GSS_C_BOTH; /* there's no GSS_C_NEITHER */
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate union_cred = (gss_union_cred_t)input_cred_handle;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /* desired_mech != GSS_C_NULL_OID -> store one element */
1247c478bd9Sstevel@tonic-gate if (desired_mech != GSS_C_NULL_OID) {
1257c478bd9Sstevel@tonic-gate mech = __gss_get_mechanism(desired_mech);
1267c478bd9Sstevel@tonic-gate if (mech == NULL)
1277c478bd9Sstevel@tonic-gate return (GSS_S_BAD_MECH);
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate if (mech->gss_store_cred == NULL)
1307c478bd9Sstevel@tonic-gate return (major_status);
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate mech_cred = __gss_get_mechanism_cred(union_cred, desired_mech);
1337c478bd9Sstevel@tonic-gate if (mech_cred == GSS_C_NO_CREDENTIAL)
1347c478bd9Sstevel@tonic-gate return (GSS_S_NO_CRED);
1357c478bd9Sstevel@tonic-gate
136*5e01956fSGlenn Barry major_status = mech->gss_store_cred(mech->context,
1377c478bd9Sstevel@tonic-gate minor_status,
1387c478bd9Sstevel@tonic-gate (gss_cred_id_t)mech_cred,
1397c478bd9Sstevel@tonic-gate cred_usage,
1407c478bd9Sstevel@tonic-gate desired_mech,
1417c478bd9Sstevel@tonic-gate overwrite_cred,
1427c478bd9Sstevel@tonic-gate default_cred,
1437c478bd9Sstevel@tonic-gate elements_stored,
144*5e01956fSGlenn Barry cred_usage_stored);
145*5e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE)
146*5e01956fSGlenn Barry map_error(minor_status, mech);
147*5e01956fSGlenn Barry return major_status;
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate /* desired_mech == GSS_C_NULL_OID -> store all elements */
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate *minor_status = 0;
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate for (i = 0; i < union_cred->count; i++) {
1557c478bd9Sstevel@tonic-gate /* Get mech and cred element */
1567c478bd9Sstevel@tonic-gate dmech = &union_cred->mechs_array[i];
1577c478bd9Sstevel@tonic-gate mech = __gss_get_mechanism(dmech);
1587c478bd9Sstevel@tonic-gate if (mech == NULL)
1597c478bd9Sstevel@tonic-gate continue;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate if (mech->gss_store_cred == NULL)
1627c478bd9Sstevel@tonic-gate continue;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate mech_cred = __gss_get_mechanism_cred(union_cred, dmech);
1657c478bd9Sstevel@tonic-gate if (mech_cred == GSS_C_NO_CREDENTIAL)
1667c478bd9Sstevel@tonic-gate continue; /* can't happen, but safe to ignore */
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate major_status = mech->gss_store_cred(mech->context,
1697c478bd9Sstevel@tonic-gate minor_status,
1707c478bd9Sstevel@tonic-gate (gss_cred_id_t)mech_cred,
1717c478bd9Sstevel@tonic-gate cred_usage,
1727c478bd9Sstevel@tonic-gate dmech,
1737c478bd9Sstevel@tonic-gate overwrite_cred,
1747c478bd9Sstevel@tonic-gate default_cred,
1757c478bd9Sstevel@tonic-gate NULL,
1767c478bd9Sstevel@tonic-gate cred_usage_stored);
177*5e01956fSGlenn Barry if (major_status != GSS_S_COMPLETE) {
178*5e01956fSGlenn Barry map_error(minor_status, mech);
1797c478bd9Sstevel@tonic-gate continue;
180*5e01956fSGlenn Barry }
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /* Succeeded for at least one mech */
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate if (elements_stored == NULL)
1857c478bd9Sstevel@tonic-gate continue;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate if (*elements_stored == GSS_C_NULL_OID_SET) {
1887c478bd9Sstevel@tonic-gate major_status = gss_create_empty_oid_set(minor_status,
1897c478bd9Sstevel@tonic-gate elements_stored);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate if (GSS_ERROR(major_status))
1927c478bd9Sstevel@tonic-gate return (major_status);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate major_status = gss_add_oid_set_member(minor_status, dmech,
1967c478bd9Sstevel@tonic-gate elements_stored);
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /* The caller should clean up elements_stored */
1997c478bd9Sstevel@tonic-gate if (GSS_ERROR(major_status))
2007c478bd9Sstevel@tonic-gate return (major_status);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate * Success with some mechs may mask failure with others, but
2057c478bd9Sstevel@tonic-gate * that's what elements_stored is for.
2067c478bd9Sstevel@tonic-gate */
2077c478bd9Sstevel@tonic-gate return (major_status);
2087c478bd9Sstevel@tonic-gate }
209