Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / mech_eap / util_radius.h
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  * RADIUS attribute provider.
35  */
36
37 #ifndef _UTIL_RADIUS_H_
38 #define _UTIL_RADIUS_H_ 1
39
40 #ifdef __cplusplus
41
42 typedef std::pair <unsigned int, unsigned int> gss_eap_attrid;
43 #ifdef GSSEAP_ENABLE_ACCEPTOR
44
45
46 struct gss_eap_radius_attr_provider : gss_eap_attr_provider {
47 public:
48     gss_eap_radius_attr_provider(void);
49     ~gss_eap_radius_attr_provider(void);
50
51     bool initWithExistingContext(const gss_eap_attr_ctx *source,
52                                  const gss_eap_attr_provider *ctx);
53     bool initWithGssContext(const gss_eap_attr_ctx *source,
54                             const gss_cred_id_t cred,
55                             const gss_ctx_id_t ctx);
56
57     bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
58     bool setAttribute(int complete,
59                       const gss_buffer_t attr,
60                       const gss_buffer_t value);
61     bool deleteAttribute(const gss_buffer_t attr);
62     bool getAttribute(const gss_buffer_t attr,
63                       int *authenticated,
64                       int *complete,
65                       gss_buffer_t value,
66                       gss_buffer_t display_value,
67                       int *more) const;
68     gss_any_t mapToAny(int authenticated,
69                        gss_buffer_t type_id) const;
70     void releaseAnyNameMapping(gss_buffer_t type_id,
71                                gss_any_t input) const;
72
73     const char *prefix(void) const;
74     const char *name(void) const;
75     bool initWithJsonObject(const gss_eap_attr_ctx *manager,
76                            JSONObject &obj);
77     JSONObject jsonRepresentation(void) const;
78
79     bool getAttribute(const gss_eap_attrid &attrid,
80                       int *authenticated,
81                       int *complete,
82                       gss_buffer_t value,
83                       gss_buffer_t display_value,
84                       int *more) const;
85     bool setAttribute(int complete,
86                       const gss_eap_attrid &attrid,
87                       const gss_buffer_t value);
88     bool deleteAttribute(const gss_eap_attrid &attrid);
89
90     bool getFragmentedAttribute(const gss_eap_attrid &attrid,
91                                 int *authenticated,
92                                 int *complete,
93                                 gss_buffer_t value) const;
94
95     bool authenticated(void) const { return m_authenticated; }
96
97     time_t getExpiryTime(void) const;
98
99     static bool init(void);
100     static void finalize(void);
101
102     static gss_eap_attr_provider *createAttrContext(void);
103
104 private:
105     rs_const_avp *getAvps(void) const {
106         return m_vps;
107     }
108
109     rs_avp *m_vps;
110     bool m_authenticated;
111 };
112
113 #endif /* GSSEAP_ENABLE_ACCEPTOR */
114
115 /* For now */
116 extern "C" {
117 #endif
118
119 #ifdef GSSEAP_ENABLE_ACCEPTOR
120
121 OM_uint32
122 gssEapRadiusAddAvp(OM_uint32 *minor,
123                    struct rs_packet *pkt,
124                    unsigned int type,
125                    unsigned int vendor,
126                    const gss_buffer_t buffer);
127
128 OM_uint32
129 gssEapRadiusGetAvp(OM_uint32 *minor,
130                    struct rs_packet *pkt,
131                    unsigned int type,
132                    unsigned int vendor,
133                    gss_buffer_t buffer,
134                    int concat);
135
136 OM_uint32
137 gssEapRadiusGetRawAvp(OM_uint32 *minor,
138                       rs_const_avp *vps,
139                       unsigned int type,
140                       unsigned int vendor,
141                       rs_const_avp **vp);
142 OM_uint32
143 gssEapRadiusFreeAvps(OM_uint32 *minor,
144                      rs_avp **vps);
145
146 OM_uint32 gssEapRadiusAttrProviderInit(OM_uint32 *minor);
147 OM_uint32 gssEapRadiusAttrProviderFinalize(OM_uint32 *minor);
148
149 OM_uint32
150 gssEapRadiusMapError(OM_uint32 *minor,
151                      struct rs_error *err);
152
153 OM_uint32
154 gssEapCreateRadiusContext(OM_uint32 *minor,
155                           gss_cred_id_t cred,
156                           struct rs_context **pRadContext);
157
158 #endif /* GSSEAP_ENABLE_ACCEPTOR */
159
160 /* initiator utilities that require only libeap, and not freeradius */
161 struct wpabuf;
162
163 OM_uint32
164 gssEapRadiusAddAttr(OM_uint32 *minor,
165                     struct wpabuf **dst,
166                     uint16_t type,
167                     uint16_t vendor,
168                     gss_buffer_t value);
169
170 /* This really needs to be a function call on Windows */
171 #define RS_CONFIG_FILE      SYSCONFDIR "/radsec.conf"
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /* _UTIL_RADIUS_H_ */