The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
client.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 /**
19  * $Id: 19753d8f945f4694b29f94a74be9f919e5bd0333 $
20  *
21  * @file lib/server/client.h
22  * @brief API to add client definitions to the server, both on startup and at runtime.
23  *
24  * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25  * @copyright 2015 The FreeRADIUS server project
26  */
27 RCSIDH(clients_h, "$Id: 19753d8f945f4694b29f94a74be9f919e5bd0333 $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <freeradius-devel/server/cf_util.h>
34 
35 typedef struct fr_client_s fr_client_t;
36 typedef struct fr_client_list_s fr_client_list_t;
37 
38 /** Callback for retrieving values when building client sections
39  *
40  * Example:
41  @code{.c}
42  int _client_value_cb(char **out, CONF_PAIR const *cp, void *data)
43  {
44  my_result *result = data;
45  char *value;
46 
47  value = get_attribute_from_result(result, cf_pair_value(cp));
48  if (!value) {
49  *out = NULL;
50  return 0;
51  }
52 
53  *out = talloc_strdup(value);
54  free_attribute(value);
55 
56  if (!*out) return -1;
57  return 0;
58  }
59  @endcode
60  *
61  * @param[out] out Where to write a pointer to the talloced value buffer.
62  * @param[in] cp The value of the CONF_PAIR specifies the attribute name to retrieve from the result.
63  * @param[in] data Pointer to the result struct to copy values from.
64  * @return
65  * - 0 on success.
66  * - -1 on failure.
67  */
68 typedef int (*client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data);
69 
70 #include <freeradius-devel/util/time.h>
71 #include <freeradius-devel/server/request.h>
72 #include <freeradius-devel/server/socket.h>
73 #include <freeradius-devel/server/stats.h>
74 #include <freeradius-devel/util/inet.h>
75 #include <freeradius-devel/radius/radius.h>
76 
77 /** Describes a host allowed to send packets to the server
78  *
79  */
80 struct fr_client_s {
81  fr_rb_node_t node; //!< Entry in the client tree.
82 
83  fr_ipaddr_t ipaddr; //!< IPv4/IPv6 address of the host.
84  fr_ipaddr_t src_ipaddr; //!< IPv4/IPv6 address to send responses
85  //!< from (family must match ipaddr).
86 
87  char const *longname; //!< Client identifier.
88  char const *shortname; //!< Client nickname.
89 
90  char const *secret; //!< Secret PSK.
91 
92  /** Require RADIUS message authenticator for incoming packets
93  */
95 
96  /** Whether require_message_authenticator is set in the configuration.
97  */
99 
100  /** Whether to allow Proxy-State in incoming packets that don't contain a message authenticator.
101  *
102  * If Proxy-State is included, but Message-Authenticator is not, then an
103  * attacker can potentially forge responses.
104  */
106 
107  /** Whether limit_proxy_state is set in the configuration.
108  */
110 
111  bool received_message_authenticator; //!< Whether we've seen a message authenticator
112  ///< from this client in any previous packets.
113 
114  bool seen_first_packet; //!< Whether we've seen a packet from this client.
115  bool first_packet_no_proxy_state; //!< Whether that first packet contained a Proxy-State
116  ///< attribute.
117 
118  bool dynamic; //!< Whether the client was dynamically defined.
119  bool active; //!< for dynamic clients
120  bool use_connected; //!< do we use connected sockets for this client
121  bool dedup_authenticator; //!< more RADIUS stuff
122 
123 #ifdef WITH_TLS
124  bool tls_required; //!< whether TLS encryption is required.
125 #endif
126 
127  char const *nas_type; //!< Type of client (arbitrary).
128 
129  char const *server; //!< Name of the virtual server client is associated with.
130  CONF_SECTION *server_cs; //!< Virtual server that the client is associated with
131 
132  int number; //!< Unique client number.
133 
134  CONF_SECTION *cs; //!< CONF_SECTION that was parsed to generate the client.
135 
136 #ifdef WITH_STATS
137  fr_stats_t auth; //!< Authentication stats.
138  fr_stats_t acct; //!< Accounting stats.
139 #endif
140 
141  fr_time_delta_t response_window; //!< How long the client has to respond.
142 
143  int proto; //!< Protocol number.
144  fr_socket_limit_t limit; //!< Connections per client (TCP clients only).
145 };
146 
148 
149 void client_list_free(void);
150 
152 
153 void client_free(fr_client_t *client);
154 
155 bool client_add(fr_client_list_t *clients, fr_client_t *client);
156 
157 void client_delete(fr_client_list_t *clients, fr_client_t *client);
158 
159 fr_client_t *client_afrom_request(TALLOC_CTX *ctx, request_t *request);
160 
162 
163 fr_client_t *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *server_cs, size_t extra);
164 
165 fr_client_t *client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto);
166 
167 fr_client_t *client_findbynumber(fr_client_list_t const *clients, int number);
168 
169 fr_client_t *client_read(char const *filename, CONF_SECTION *server_cs, bool check_dns);
170 
172 #ifdef __cplusplus
173 }
174 #endif
#define RCSIDH(h, id)
Definition: build.h:482
Configuration AVP similar to a fr_pair_t.
Definition: cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
IPv4/6 prefix.
Definition: merged_model.c:272
fr_time_delta_t response_window
How long the client has to respond.
Definition: client.h:141
char const * server
Name of the virtual server client is associated with.
Definition: client.h:129
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition: client.c:378
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition: client.h:83
fr_client_t * client_findbynumber(fr_client_list_t const *clients, int number)
bool received_message_authenticator
Whether we've seen a message authenticator from this client in any previous packets.
Definition: client.h:111
fr_client_list_t * client_list_init(CONF_SECTION *cs)
Return a new client list.
Definition: client.c:113
fr_stats_t acct
Accounting stats.
Definition: client.h:138
int client_map_section(CONF_SECTION *out, CONF_SECTION const *map, client_value_cb_t func, void *data)
Create a client CONF_SECTION using a mapping section to map values from a result set to client attrib...
Definition: client.c:626
fr_radius_require_ma_t require_message_authenticator
Require RADIUS message authenticator for incoming packets.
Definition: client.h:94
void client_free(fr_client_t *client)
Free a client.
Definition: client.c:98
char const * secret
Secret PSK.
Definition: client.h:90
fr_client_t * client_read(char const *filename, CONF_SECTION *server_cs, bool check_dns)
Read a single client from a file.
Definition: client.c:1060
bool active
for dynamic clients
Definition: client.h:119
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition: client.h:84
int(* client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data)
Callback for retrieving values when building client sections.
Definition: client.h:68
bool require_message_authenticator_is_set
Whether require_message_authenticator is set in the configuration.
Definition: client.h:98
fr_stats_t auth
Authentication stats.
Definition: client.h:137
char const * nas_type
Type of client (arbitrary).
Definition: client.h:127
int proto
Protocol number.
Definition: client.h:143
bool seen_first_packet
Whether we've seen a packet from this client.
Definition: client.h:114
bool limit_proxy_state_is_set
Whether limit_proxy_state is set in the configuration.
Definition: client.h:109
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
Definition: client.c:1112
CONF_SECTION * cs
CONF_SECTION that was parsed to generate the client.
Definition: client.h:134
bool dynamic
Whether the client was dynamically defined.
Definition: client.h:118
char const * longname
Client identifier.
Definition: client.h:87
fr_rb_node_t node
Entry in the client tree.
Definition: client.h:81
void client_list_free(void)
Definition: client.c:89
bool first_packet_no_proxy_state
Whether that first packet contained a Proxy-State attribute.
Definition: client.h:115
fr_socket_limit_t limit
Connections per client (TCP clients only).
Definition: client.h:144
char const * shortname
Client nickname.
Definition: client.h:88
fr_client_t * client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *server_cs, size_t extra)
Allocate a new client from a config section.
Definition: client.c:708
bool use_connected
do we use connected sockets for this client
Definition: client.h:120
void client_delete(fr_client_list_t *clients, fr_client_t *client)
Definition: client.c:342
bool client_add(fr_client_list_t *clients, fr_client_t *client)
Add a client to a fr_client_list_t.
Definition: client.c:187
bool dedup_authenticator
more RADIUS stuff
Definition: client.h:121
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, bool tls_required)
int number
Unique client number.
Definition: client.h:132
CONF_SECTION * server_cs
Virtual server that the client is associated with.
Definition: client.h:130
fr_radius_limit_proxy_state_t limit_proxy_state
Whether to allow Proxy-State in incoming packets that don't contain a message authenticator.
Definition: client.h:105
fr_client_t * client_afrom_request(TALLOC_CTX *ctx, request_t *request)
Create a new client, consuming all attributes in the control list of the request.
Definition: client.c:930
Describes a host allowed to send packets to the server.
Definition: client.h:80
fr_radius_require_ma_t
Control whether Message-Authenticator is required in Access-Requests.
Definition: radius.h:62
fr_radius_limit_proxy_state_t
Control whether Proxy-State is allowed in Access-Requests.
Definition: radius.h:76
static char const * proto(int id, int porttype)
Definition: radwho.c:85
Group of clients.
Definition: client.c:55
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80
static fr_slen_t data
Definition: value.h:1265
static size_t char ** out
Definition: value.h:997