2 * Copyright (c) 2005 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/lib/libgssapi/gss_add_cred.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
29 #include "mech_locl.h"
31 struct _gss_mechanism_cred
*
32 _gss_copy_cred(struct _gss_mechanism_cred
*mc
)
34 struct _gss_mechanism_cred
*new_mc
;
35 gssapi_mech_interface m
= mc
->gmc_mech
;
36 OM_uint32 major_status
, minor_status
;
39 OM_uint32 initiator_lifetime
, acceptor_lifetime
;
40 gss_cred_usage_t cred_usage
;
42 major_status
= m
->gm_inquire_cred_by_mech(&minor_status
,
43 mc
->gmc_cred
, mc
->gmc_mech_oid
,
44 &name
, &initiator_lifetime
, &acceptor_lifetime
, &cred_usage
);
46 _gss_mg_error(m
, major_status
, minor_status
);
50 major_status
= m
->gm_add_cred(&minor_status
,
51 GSS_C_NO_CREDENTIAL
, name
, mc
->gmc_mech_oid
,
52 cred_usage
, initiator_lifetime
, acceptor_lifetime
,
54 m
->gm_release_name(&minor_status
, &name
);
57 _gss_mg_error(m
, major_status
, minor_status
);
61 new_mc
= malloc(sizeof(struct _gss_mechanism_cred
));
63 m
->gm_release_cred(&minor_status
, &cred
);
67 new_mc
->gmc_mech_oid
= &m
->gm_mech_oid
;
68 new_mc
->gmc_cred
= cred
;
73 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
74 gss_add_cred(OM_uint32
*minor_status
,
75 gss_const_cred_id_t input_cred_handle
,
76 gss_const_name_t desired_name
,
77 const gss_OID desired_mech
,
78 gss_cred_usage_t cred_usage
,
79 OM_uint32 initiator_time_req
,
80 OM_uint32 acceptor_time_req
,
81 gss_cred_id_t
*output_cred_handle
,
82 gss_OID_set
*actual_mechs
,
83 OM_uint32
*initiator_time_rec
,
84 OM_uint32
*acceptor_time_rec
)
86 OM_uint32 major_status
;
87 gssapi_mech_interface m
;
88 struct _gss_cred
*cred
= (struct _gss_cred
*) input_cred_handle
;
89 struct _gss_cred
*new_cred
;
90 gss_cred_id_t release_cred
;
91 struct _gss_mechanism_cred
*mc
, *target_mc
, *copy_mc
;
92 struct _gss_mechanism_name
*mn
;
96 *output_cred_handle
= GSS_C_NO_CREDENTIAL
;
97 if (initiator_time_rec
)
98 *initiator_time_rec
= 0;
99 if (acceptor_time_rec
)
100 *acceptor_time_rec
= 0;
102 *actual_mechs
= GSS_C_NO_OID_SET
;
104 new_cred
= malloc(sizeof(struct _gss_cred
));
106 *minor_status
= ENOMEM
;
107 return (GSS_S_FAILURE
);
109 HEIM_SLIST_INIT(&new_cred
->gc_mc
);
112 * We go through all the mc attached to the input_cred_handle
113 * and check the mechanism. If it matches, we call
114 * gss_add_cred for that mechanism, otherwise we copy the mc
119 HEIM_SLIST_FOREACH(mc
, &cred
->gc_mc
, gmc_link
) {
120 if (gss_oid_equal(mc
->gmc_mech_oid
, desired_mech
)) {
123 copy_mc
= _gss_copy_cred(mc
);
125 release_cred
= (gss_cred_id_t
)new_cred
;
126 gss_release_cred(&junk
, &release_cred
);
127 *minor_status
= ENOMEM
;
128 return (GSS_S_FAILURE
);
130 HEIM_SLIST_INSERT_HEAD(&new_cred
->gc_mc
, copy_mc
, gmc_link
);
135 * Figure out a suitable mn, if any.
138 major_status
= _gss_find_mn(minor_status
,
139 (struct _gss_name
*) desired_name
,
142 if (major_status
!= GSS_S_COMPLETE
) {
150 m
= __gss_get_mechanism(desired_mech
);
152 mc
= malloc(sizeof(struct _gss_mechanism_cred
));
154 release_cred
= (gss_cred_id_t
)new_cred
;
155 gss_release_cred(&junk
, &release_cred
);
156 *minor_status
= ENOMEM
;
157 return (GSS_S_FAILURE
);
160 mc
->gmc_mech_oid
= &m
->gm_mech_oid
;
162 major_status
= m
->gm_add_cred(minor_status
,
163 target_mc
? target_mc
->gmc_cred
: GSS_C_NO_CREDENTIAL
,
164 desired_name
? mn
->gmn_name
: GSS_C_NO_NAME
,
175 _gss_mg_error(m
, major_status
, *minor_status
);
176 release_cred
= (gss_cred_id_t
)new_cred
;
177 gss_release_cred(&junk
, &release_cred
);
179 return (major_status
);
181 HEIM_SLIST_INSERT_HEAD(&new_cred
->gc_mc
, mc
, gmc_link
);
182 *output_cred_handle
= (gss_cred_id_t
) new_cred
;
184 return (GSS_S_COMPLETE
);