Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / mech_eap / eap_mech.c
1 /*
2  * Copyright (c) 2011, 2015, 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 /*
34  * Initialisation and finalise functions.
35  */
36
37 #include "gssapiP_eap.h"
38
39 extern int wpa_debug_level;
40
41 static OM_uint32
42 eapPeerRegisterMethods(OM_uint32 *minor)
43 {
44     OM_uint32 ret = 0;
45
46 #ifdef EAP_MD5
47     if (ret == 0)
48         ret = eap_peer_md5_register();
49 #endif /* EAP_MD5 */
50
51 #ifdef EAP_TLS
52     if (ret == 0)
53         ret = eap_peer_tls_register();
54 #endif /* EAP_TLS */
55
56 #ifdef EAP_MSCHAPv2
57     if (ret == 0)
58         ret = eap_peer_mschapv2_register();
59 #endif /* EAP_MSCHAPv2 */
60
61 #ifdef EAP_PEAP
62     if (ret == 0)
63         ret = eap_peer_peap_register();
64 #endif /* EAP_PEAP */
65
66 #ifdef EAP_TTLS
67     if (ret == 0)
68         ret = eap_peer_ttls_register();
69 #endif /* EAP_TTLS */
70
71 #ifdef EAP_GTC
72     if (ret == 0)
73         ret = eap_peer_gtc_register();
74 #endif /* EAP_GTC */
75
76 #ifdef EAP_OTP
77     if (ret == 0)
78         ret = eap_peer_otp_register();
79 #endif /* EAP_OTP */
80
81 #ifdef EAP_SIM
82     if (ret == 0)
83         ret = eap_peer_sim_register();
84 #endif /* EAP_SIM */
85
86 #ifdef EAP_LEAP
87     if (ret == 0)
88         ret = eap_peer_leap_register();
89 #endif /* EAP_LEAP */
90
91 #ifdef EAP_PSK
92     if (ret == 0)
93         ret = eap_peer_psk_register();
94 #endif /* EAP_PSK */
95
96 #ifdef EAP_AKA
97     if (ret == 0)
98         ret = eap_peer_aka_register();
99 #endif /* EAP_AKA */
100
101 #ifdef EAP_AKA_PRIME
102     if (ret == 0)
103         ret = eap_peer_aka_prime_register();
104 #endif /* EAP_AKA_PRIME */
105
106 #ifdef EAP_FAST
107     if (ret == 0)
108         ret = eap_peer_fast_register();
109 #endif /* EAP_FAST */
110
111 #ifdef EAP_PAX
112     if (ret == 0)
113         ret = eap_peer_pax_register();
114 #endif /* EAP_PAX */
115
116 #ifdef EAP_SAKE
117     if (ret == 0)
118         ret = eap_peer_sake_register();
119 #endif /* EAP_SAKE */
120
121 #ifdef EAP_GPSK
122     if (ret == 0)
123         ret = eap_peer_gpsk_register();
124 #endif /* EAP_GPSK */
125
126 #ifdef EAP_WSC
127     if (ret == 0)
128         ret = eap_peer_wsc_register();
129 #endif /* EAP_WSC */
130
131 #ifdef EAP_IKEV2
132     if (ret == 0)
133         ret = eap_peer_ikev2_register();
134 #endif /* EAP_IKEV2 */
135
136 #ifdef EAP_VENDOR_TEST
137     if (ret == 0)
138         ret = eap_peer_vendor_test_register();
139 #endif /* EAP_VENDOR_TEST */
140
141 #ifdef EAP_TNC
142     if (ret == 0)
143         ret = eap_peer_tnc_register();
144 #endif /* EAP_TNC */
145
146     if (ret == 0)
147         return GSS_S_COMPLETE;
148
149     *minor = GSSEAP_LIBEAP_INIT_FAILURE;
150     return GSS_S_FAILURE;
151 }
152
153 static OM_uint32
154 gssEapInitLibEap(OM_uint32 *minor)
155 {
156     char *debug_file = NULL;
157     wpa_debug_level = MSG_ERROR;
158     if ((debug_file = getenv("GSSEAP_TRACE")) != NULL) {
159             wpa_debug_open_file(debug_file);
160             wpa_debug_level = 0;
161         }
162
163     return eapPeerRegisterMethods(minor);
164 }
165
166 static OM_uint32
167 gssEapInitLibRadsec(OM_uint32 *minor)
168 {
169     if (0) {
170         *minor = GSSEAP_RADSEC_INIT_FAILURE;
171         return GSS_S_FAILURE;
172     }
173
174     return GSS_S_COMPLETE;
175 }
176
177 void gssEapFinalize(void) GSSEAP_DESTRUCTOR;
178
179 OM_uint32
180 gssEapInitiatorInit(OM_uint32 *minor)
181 {
182     OM_uint32 major;
183
184     initialize_eapg_error_table();
185     initialize_rse_error_table();
186
187     major = gssEapInitLibEap(minor);
188     if (GSS_ERROR(major))
189         return major;
190
191     major = gssEapInitLibRadsec(minor);
192     if (GSS_ERROR(major))
193         return major;
194
195 #ifdef GSSEAP_ENABLE_REAUTH
196     major = gssEapReauthInitialize(minor);
197     if (GSS_ERROR(major))
198         return major;
199 #endif
200
201     *minor = 0;
202     return GSS_S_COMPLETE;
203 }
204
205 void
206 gssEapFinalize(void)
207 {
208     wpa_printf(MSG_INFO, "### gssEapFinalize()");
209     eap_peer_unregister_methods();
210 }
211
212 #ifdef GSSEAP_CONSTRUCTOR
213 static void gssEapInitiatorInitAssert(void) GSSEAP_CONSTRUCTOR;
214
215 static void
216 gssEapInitiatorInitAssert(void)
217 {
218     OM_uint32 major, minor;
219
220     major = gssEapInitiatorInit(&minor);
221
222     GSSEAP_ASSERT(!GSS_ERROR(major));
223 }
224 #endif