call eap_mech constructors from DllMain
[moonshot.git] / moonshot / mech_eap / eap_mech.c
1 /*
2  * Copyright (c) 2011, 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 static OM_uint32
40 eapPeerRegisterMethods(OM_uint32 *minor)
41 {
42     OM_uint32 ret = 0;
43
44 #ifdef EAP_MD5
45     if (ret == 0)
46         ret = eap_peer_md5_register();
47 #endif /* EAP_MD5 */
48
49 #ifdef EAP_TLS
50     if (ret == 0)
51         ret = eap_peer_tls_register();
52 #endif /* EAP_TLS */
53
54 #ifdef EAP_MSCHAPv2
55     if (ret == 0)
56         ret = eap_peer_mschapv2_register();
57 #endif /* EAP_MSCHAPv2 */
58
59 #ifdef EAP_PEAP
60     if (ret == 0)
61         ret = eap_peer_peap_register();
62 #endif /* EAP_PEAP */
63
64 #ifdef EAP_TTLS
65     if (ret == 0)
66         ret = eap_peer_ttls_register();
67 #endif /* EAP_TTLS */
68
69 #ifdef EAP_GTC
70     if (ret == 0)
71         ret = eap_peer_gtc_register();
72 #endif /* EAP_GTC */
73
74 #ifdef EAP_OTP
75     if (ret == 0)
76         ret = eap_peer_otp_register();
77 #endif /* EAP_OTP */
78
79 #ifdef EAP_SIM
80     if (ret == 0)
81         ret = eap_peer_sim_register();
82 #endif /* EAP_SIM */
83
84 #ifdef EAP_LEAP
85     if (ret == 0)
86         ret = eap_peer_leap_register();
87 #endif /* EAP_LEAP */
88
89 #ifdef EAP_PSK
90     if (ret == 0)
91         ret = eap_peer_psk_register();
92 #endif /* EAP_PSK */
93
94 #ifdef EAP_AKA
95     if (ret == 0)
96         ret = eap_peer_aka_register();
97 #endif /* EAP_AKA */
98
99 #ifdef EAP_AKA_PRIME
100     if (ret == 0)
101         ret = eap_peer_aka_prime_register();
102 #endif /* EAP_AKA_PRIME */
103
104 #ifdef EAP_FAST
105     if (ret == 0)
106         ret = eap_peer_fast_register();
107 #endif /* EAP_FAST */
108
109 #ifdef EAP_PAX
110     if (ret == 0)
111         ret = eap_peer_pax_register();
112 #endif /* EAP_PAX */
113
114 #ifdef EAP_SAKE
115     if (ret == 0)
116         ret = eap_peer_sake_register();
117 #endif /* EAP_SAKE */
118
119 #ifdef EAP_GPSK
120     if (ret == 0)
121         ret = eap_peer_gpsk_register();
122 #endif /* EAP_GPSK */
123
124 #ifdef EAP_WSC
125     if (ret == 0)
126         ret = eap_peer_wsc_register();
127 #endif /* EAP_WSC */
128
129 #ifdef EAP_IKEV2
130     if (ret == 0)
131         ret = eap_peer_ikev2_register();
132 #endif /* EAP_IKEV2 */
133
134 #ifdef EAP_VENDOR_TEST
135     if (ret == 0)
136         ret = eap_peer_vendor_test_register();
137 #endif /* EAP_VENDOR_TEST */
138
139 #ifdef EAP_TNC
140     if (ret == 0)
141         ret = eap_peer_tnc_register();
142 #endif /* EAP_TNC */
143
144     if (ret == 0)
145         return GSS_S_COMPLETE;
146
147     *minor = GSSEAP_LIBEAP_INIT_FAILURE;
148     return GSS_S_FAILURE;
149 }
150
151 static OM_uint32
152 gssEapInitLibEap(OM_uint32 *minor)
153 {
154     return eapPeerRegisterMethods(minor);
155 }
156
157 static OM_uint32
158 gssEapInitLibRadsec(OM_uint32 *minor)
159 {
160     if (0) {
161         *minor = GSSEAP_RADSEC_INIT_FAILURE;
162         return GSS_S_FAILURE;
163     }
164
165     return GSS_S_COMPLETE;
166 }
167
168 void gssEapInitiatorInit(void) GSSEAP_CONSTRUCTOR;
169 void gssEapFinalize(void) GSSEAP_DESTRUCTOR;
170
171 void
172 gssEapInitiatorInit(void)
173 {
174     OM_uint32 major, minor;
175
176     initialize_eapg_error_table();
177     initialize_rse_error_table();
178
179     major = gssEapInitLibEap(&minor);
180     assert(major == GSS_S_COMPLETE);
181
182     major = gssEapInitLibRadsec(&minor);
183     assert(major == GSS_S_COMPLETE);
184
185 #ifdef GSSEAP_ENABLE_REAUTH
186     major = gssEapReauthInitialize(&minor);
187     assert(major == GSS_S_COMPLETE);
188 #endif
189 }
190
191 void
192 gssEapFinalize(void)
193 {
194 #ifdef GSSEAP_ENABLE_ACCEPTOR
195     OM_uint32 minor;
196
197     gssEapAttrProvidersFinalize(&minor);
198 #endif
199     eap_peer_unregister_methods();
200 }