Better error reporting through com_err
[mech_eap.git] / eap_mech.c
1 /*
2  * Copyright (c) 2010, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 #include "gssapiP_eap.h"
34
35 static OM_uint32
36 eapPeerRegisterMethods(OM_uint32 *minor)
37 {
38     OM_uint32 ret = 0;
39
40 #ifdef EAP_MD5
41     if (ret == 0)
42         ret = eap_peer_md5_register();
43 #endif /* EAP_MD5 */
44
45 #ifdef EAP_TLS
46     if (ret == 0)
47         ret = eap_peer_tls_register();
48 #endif /* EAP_TLS */
49
50 #ifdef EAP_MSCHAPv2
51     if (ret == 0)
52         ret = eap_peer_mschapv2_register();
53 #endif /* EAP_MSCHAPv2 */
54
55 #ifdef EAP_PEAP
56     if (ret == 0)
57         ret = eap_peer_peap_register();
58 #endif /* EAP_PEAP */
59
60 #ifdef EAP_TTLS
61     if (ret == 0)
62         ret = eap_peer_ttls_register();
63 #endif /* EAP_TTLS */
64
65 #ifdef EAP_GTC
66     if (ret == 0)
67         ret = eap_peer_gtc_register();
68 #endif /* EAP_GTC */
69
70 #ifdef EAP_OTP
71     if (ret == 0)
72         ret = eap_peer_otp_register();
73 #endif /* EAP_OTP */
74
75 #ifdef EAP_SIM
76     if (ret == 0)
77         ret = eap_peer_sim_register();
78 #endif /* EAP_SIM */
79
80 #ifdef EAP_LEAP
81     if (ret == 0)
82         ret = eap_peer_leap_register();
83 #endif /* EAP_LEAP */
84
85 #ifdef EAP_PSK
86     if (ret == 0)
87         ret = eap_peer_psk_register();
88 #endif /* EAP_PSK */
89
90 #ifdef EAP_AKA
91     if (ret == 0)
92         ret = eap_peer_aka_register();
93 #endif /* EAP_AKA */
94
95 #ifdef EAP_AKA_PRIME
96     if (ret == 0)
97         ret = eap_peer_aka_prime_register();
98 #endif /* EAP_AKA_PRIME */
99
100 #ifdef EAP_FAST
101     if (ret == 0)
102         ret = eap_peer_fast_register();
103 #endif /* EAP_FAST */
104
105 #ifdef EAP_PAX
106     if (ret == 0)
107         ret = eap_peer_pax_register();
108 #endif /* EAP_PAX */
109
110 #ifdef EAP_SAKE
111     if (ret == 0)
112         ret = eap_peer_sake_register();
113 #endif /* EAP_SAKE */
114
115 #ifdef EAP_GPSK
116     if (ret == 0)
117         ret = eap_peer_gpsk_register();
118 #endif /* EAP_GPSK */
119
120 #ifdef EAP_WSC
121     if (ret == 0)
122         ret = eap_peer_wsc_register();
123 #endif /* EAP_WSC */
124
125 #ifdef EAP_IKEV2
126     if (ret == 0)
127         ret = eap_peer_ikev2_register();
128 #endif /* EAP_IKEV2 */
129
130 #ifdef EAP_VENDOR_TEST
131     if (ret == 0)
132         ret = eap_peer_vendor_test_register();
133 #endif /* EAP_VENDOR_TEST */
134
135 #ifdef EAP_TNC
136     if (ret == 0)
137         ret = eap_peer_tnc_register();
138 #endif /* EAP_TNC */
139
140     return ret ? GSS_S_FAILURE : GSS_S_COMPLETE;
141 }
142
143 static OM_uint32
144 gssEapInitLibEap(OM_uint32 *minor)
145 {
146     return eapPeerRegisterMethods(minor);
147 }
148
149 static OM_uint32
150 gssEapInitLibRadsec(OM_uint32 *minor)
151 {
152     return GSS_S_COMPLETE;
153 }
154
155 static void gssEapInitiatorInit(void) __attribute__((constructor));
156 static void gssEapFinalize(void) __attribute__((destructor));
157
158 static void
159 gssEapInitiatorInit(void)
160 {
161     OM_uint32 major, minor;
162
163     initialize_eapg_error_table();
164     initialize_rse_error_table();
165
166     major = gssEapInitLibEap(&minor);
167     assert(major == GSS_S_COMPLETE);
168
169     major = gssEapInitLibRadsec(&minor);
170     assert(major == GSS_S_COMPLETE);
171
172 #ifdef GSSEAP_ENABLE_REAUTH
173     major = gssEapReauthInitialize(&minor);
174     assert(major == GSS_S_COMPLETE);
175 #endif
176 }
177
178 static void
179 gssEapFinalize(void)
180 {
181     OM_uint32 minor;
182
183     gssEapAttrProvidersFinalize(&minor);
184     eap_peer_unregister_methods();
185 }