xref: /freebsd/crypto/krb5/src/plugins/preauth/pkinit/pkinit_accessor.c (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * COPYRIGHT (C) 2006,2007
4  * THE REGENTS OF THE UNIVERSITY OF MICHIGAN
5  * ALL RIGHTS RESERVED
6  *
7  * Permission is granted to use, copy, create derivative works
8  * and redistribute this software and such derivative works
9  * for any purpose, so long as the name of The University of
10  * Michigan is not used in any advertising or publicity
11  * pertaining to the use of distribution of this software
12  * without specific, written prior authorization.  If the
13  * above copyright notice or any other identification of the
14  * University of Michigan is included in any copy of any
15  * portion of this software, then the disclaimer below must
16  * also be included.
17  *
18  * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
19  * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
20  * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
21  * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
22  * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
24  * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
25  * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
26  * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
27  * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
28  * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGES.
30  */
31 
32 #include <k5-int.h>
33 #include "pkinit_accessor.h"
34 
35 #define DEF_FUNC_PTRS(type)                                             \
36     krb5_error_code (*k5int_encode_##type)(const type *, krb5_data **); \
37     krb5_error_code (*k5int_decode_##type)(const krb5_data *, type **)
38 
39 #define DEF_FUNC_PTRS_ARRAY(type)                                       \
40     krb5_error_code (*k5int_encode_##type)(const type **, krb5_data **); \
41     krb5_error_code (*k5int_decode_##type)(const krb5_data *, type ***)
42 
43 DEF_FUNC_PTRS(krb5_auth_pack);
44 DEF_FUNC_PTRS(krb5_kdc_dh_key_info);
45 DEF_FUNC_PTRS(krb5_pa_pk_as_rep);
46 DEF_FUNC_PTRS(krb5_pa_pk_as_req);
47 DEF_FUNC_PTRS(krb5_reply_key_pack);
48 
49 /* special cases... */
50 krb5_error_code
51 (*k5int_decode_krb5_principal_name)(const krb5_data *, krb5_principal_data **);
52 
53 krb5_error_code
54 (*k5int_encode_krb5_td_dh_parameters)(krb5_algorithm_identifier *const *,
55                                       krb5_data **code);
56 krb5_error_code
57 (*k5int_decode_krb5_td_dh_parameters)(const krb5_data *,
58                                       krb5_algorithm_identifier ***);
59 
60 krb5_error_code
61 (*k5int_encode_krb5_td_trusted_certifiers)
62 (krb5_external_principal_identifier *const *, krb5_data **code);
63 
64 krb5_error_code
65 (*k5int_decode_krb5_td_trusted_certifiers)
66 (const krb5_data *,
67  krb5_external_principal_identifier ***);
68 
69 krb5_error_code
70 (*k5int_encode_krb5_kdc_req_body)(const krb5_kdc_req *rep, krb5_data **code);
71 
72 void
73 (KRB5_CALLCONV *k5int_krb5_free_kdc_req)(krb5_context, krb5_kdc_req * );
74 
75 void
76 (*k5int_set_prompt_types)(krb5_context, krb5_prompt_type *);
77 
78 
79 /*
80  * Grab internal function pointers from the krb5int_accessor
81  * structure and make them available
82  */
83 krb5_error_code
pkinit_accessor_init(void)84 pkinit_accessor_init(void)
85 {
86     krb5_error_code retval;
87     krb5int_access k5int;
88 
89     retval = krb5int_accessor(&k5int, KRB5INT_ACCESS_VERSION);
90     if (retval)
91         return retval;
92 #define SET_PTRS(type)                          \
93     k5int_encode_##type = k5int.encode_##type;  \
94     k5int_decode_##type = k5int.decode_##type;
95 
96     SET_PTRS(krb5_auth_pack);
97     SET_PTRS(krb5_kdc_dh_key_info);
98     SET_PTRS(krb5_pa_pk_as_rep);
99     SET_PTRS(krb5_pa_pk_as_req);
100     SET_PTRS(krb5_reply_key_pack);
101     SET_PTRS(krb5_td_dh_parameters);
102     SET_PTRS(krb5_td_trusted_certifiers);
103 
104     /* special cases... */
105     k5int_decode_krb5_principal_name = k5int.decode_krb5_principal_name;
106     k5int_encode_krb5_kdc_req_body = k5int.encode_krb5_kdc_req_body;
107     k5int_krb5_free_kdc_req = k5int.free_kdc_req;
108     k5int_set_prompt_types = k5int.set_prompt_types;
109     return 0;
110 }
111