The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** Main include file for our libcurl extension API
19 *
20 * @file src/lib/curl/base.h
21 *
22 * @copyright 2019 The FreeRADIUS project
23 * @copyright 2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 */
25
26RCSIDH(curl_h, "$Id: 53d43a08a543e425ddbcd9fa28b319b88a1b01c8 $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define CURL_NO_OLDIES 1
33
34#include <curl/curl.h>
35#include <freeradius-devel/server/global_lib.h>
36#include <freeradius-devel/server/module.h>
37#include <freeradius-devel/server/request.h>
38#include <freeradius-devel/util/event.h>
39#include <freeradius-devel/util/slab.h>
40#include <freeradius-devel/unlang/xlat.h>
41
42DIAG_OFF_OPTIONAL(disabled-macro-expansion)
43#define FR_CURL_SET_OPTION(_x, _y)\
44do {\
45 CURLcode _ret;\
46 if ((_ret = curl_easy_setopt(randle->candle, _x, _y)) != CURLE_OK) {\
47 char const *_option;\
48 _option = STRINGIFY(_x);\
49 ERROR("Failed setting curl option %s: %s (%u)", _option, curl_easy_strerror(_ret), _ret);\
50 goto error;\
51 }\
52} while (0)
53
54#define FR_CURL_ROPTIONAL_SET_OPTION(_x, _y)\
55do {\
56 CURLcode _ret;\
57 if ((_ret = curl_easy_setopt(randle->candle, _x, _y)) != CURLE_OK) {\
58 char const *_option;\
59 _option = STRINGIFY(_x);\
60 ROPTIONAL(RERROR, ERROR, "Failed setting curl option %s: %s (%u)", _option, curl_easy_strerror(_ret), _ret);\
61 goto error;\
62 }\
63} while (0)
64
65#define FR_CURL_REQUEST_SET_OPTION(_x, _y)\
66do {\
67 CURLcode _ret;\
68 if ((_ret = curl_easy_setopt(randle->candle, _x, _y)) != CURLE_OK) {\
69 char const *_option;\
70 _option = STRINGIFY(_x);\
71 RERROR("Failed setting curl option %s: %s (%u)", _option, curl_easy_strerror(_ret), _ret);\
72 goto error;\
73 }\
74} while (0)
75
76/*
77 * We have to use this as curl uses lots of enums
78 */
79#ifndef CURL_AT_LEAST_VERSION
80# define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z))
81# define CURL_AT_LEAST_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
82#endif
83
84/** Uctx data for timer and I/O functions
85 *
86 * Seems like overkill for a single field, but I'm sure we'll need to
87 * pass around other things later.
88 */
89typedef struct {
90 fr_event_list_t *el; //!< Event list servicing I/O events.
91 fr_timer_t *ev; //!< Multi-Handle timer.
92 uint64_t transfers; //!< How many transfers are current in progress.
93 CURLM *mandle; //!< The multi handle.
95
96/** Structure representing an individual request being passed to curl for processing
97 *
98 */
99typedef struct {
100 CURL *candle; //!< Request specific handle.
101 CURLcode result; //!< Result of executing the request.
102 request_t *request; //!< Current request.
103 void *uctx; //!< Private data for the module using the API.
105
106typedef struct {
107 char const *certificate_file;
108 char const *private_key_file;
110 char const *ca_file;
111 char const *ca_issuer_file;
112 char const *ca_path;
113 char const *random_file;
114 curl_usessl require_cert;
118 char const *keylog_file; //!< Where to log SSL keying material like the pre-master secret.
119 ///< The log file can then be used to decrypt the SSL session
120 ///< with Wireshark.
122
127
131
134
136
137fr_curl_handle_t *fr_curl_io_init(TALLOC_CTX *ctx, fr_event_list_t *el, bool multiplex);
138
140
142
143CURL *fr_curl_tmp_handle(void);
144#ifdef __cplusplus
145}
146#endif
static uint8_t request[4]
#define DIAG_OFF_OPTIONAL(_x)
Definition build.h:577
#define RCSIDH(h, id)
Definition build.h:604
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:649
fr_timer_t * ev
Multi-Handle timer.
Definition base.h:91
fr_curl_handle_t * fr_curl_io_init(TALLOC_CTX *ctx, fr_event_list_t *el, bool multiplex)
char const * private_key_password
Definition base.h:109
fr_event_list_t * el
Event list servicing I/O events.
Definition base.h:90
char const * private_key_file
Definition base.h:108
char const * certificate_file
Definition base.h:107
int fr_curl_response_certinfo(request_t *request, fr_curl_io_request_t *randle)
Definition base.c:170
char const * keylog_file
Where to log SSL keying material like the pre-master secret.
Definition base.h:118
CURLcode result
Result of executing the request.
Definition base.h:101
int fr_curl_easy_tls_init(fr_curl_io_request_t *randle, fr_curl_tls_t const *conf)
Definition base.c:139
bool check_cert_cn
Definition base.h:116
char const * ca_issuer_file
Definition base.h:111
uint64_t transfers
How many transfers are current in progress.
Definition base.h:92
curl_usessl require_cert
Definition base.h:114
bool check_cert
Definition base.h:115
fr_slab_config_t reuse
Definition base.h:124
char const * ca_path
Definition base.h:112
char const * ca_file
Definition base.h:110
bool extract_cert_attrs
Definition base.h:117
global_lib_autoinst_t fr_curl_autoinst
Definition base.c:396
fr_curl_io_request_t * fr_curl_io_request_alloc(TALLOC_CTX *ctx)
Allocate a new curl easy request and wrapper struct.
Definition io.c:540
CURLM * mandle
The multi handle.
Definition base.h:93
request_t * request
Current request.
Definition base.h:102
CURL * fr_curl_tmp_handle(void)
Return a thread local curl easy handle.
Definition base.c:276
conf_parser_t fr_curl_conn_config[]
Definition base.c:97
char const * random_file
Definition base.h:113
fr_time_delta_t connect_timeout
Definition base.h:125
void * uctx
Private data for the module using the API.
Definition base.h:103
conf_parser_t fr_curl_tls_config[]
Definition base.c:68
int fr_curl_io_request_enqueue(fr_curl_handle_t *mhandle, request_t *request, fr_curl_io_request_t *creq)
Sends a request using libcurl.
Definition io.c:476
CURL * candle
Request specific handle.
Definition base.h:100
Uctx data for timer and I/O functions.
Definition base.h:89
Structure representing an individual request being passed to curl for processing.
Definition base.h:99
Structure to define how to initialise libraries with global configuration.
Definition global_lib.h:38
Stores all information relating to an event list.
Definition event.c:375
static rs_t * conf
Definition radsniff.c:52
Tuneable parameters for slabs.
Definition slab.h:42
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
A timer event.
Definition timer.c:83
static fr_event_list_t * el