26 #include <freeradius-devel/io/listen.h>
27 #include <freeradius-devel/io/master.h>
28 #include <freeradius-devel/util/debug.h>
30 #include <freeradius-devel/tacacs/tacacs.h>
106 inst->io.app_io_instance = mi->
data;
142 inst->allowed[dv->
value->vb_uint32] =
true;
159 size_t secretlen = 0;
176 if ((
data[2] & 0x01) != 0x01) {
181 request->packet->id =
data[2];
182 request->reply->id =
data[2] + 1;
184 request->packet->data = talloc_memdup(request->packet,
data, data_len);
185 request->packet->data_len = data_len;
190 REDEBUG(
"Expected to see encrypted packet, got unencrypted packet!");
193 secretlen = talloc_array_length(client->
secret) - 1;
211 request->packet->data, request->packet->data_len,
212 NULL,
secret, secretlen, &code) < 0) {
217 request->packet->code = code;
235 request->packet->socket = address->
socket;
254 if (!
vp->
da->flags.subtype) {
255 switch (
vp->vp_type) {
264 vp->vp_ipv4addr = INADDR_ANY;
282 RDEBUG(
"Received %s ID %i from %pV:%i to %pV:%i length %zu via socket %s",
286 request->packet->socket.inet.src_port,
288 request->packet->socket.inet.dst_port,
289 request->packet->data_len,
290 request->async->listen->name);
298 ((pkt->
hdr.
flags & FR_FLAGS_VALUE_UNENCRYPTED) == 0) &&
302 RWDEBUG(
"Unprintable characters in the %s. "
303 "Double-check the shared secret on the server "
309 RPEDEBUG(
"Failed decoding 'Net.*' packet");
323 size_t secretlen = 0;
347 if ((buffer_len == 1) ||
376 PERROR(
"Failed creating new client");
381 memcpy(
buffer, &new_client,
sizeof(new_client));
382 return sizeof(new_client);
386 if (
secret) secretlen = talloc_array_length(client->
secret) - 1;
390 request->reply->code, &request->reply_pairs);
392 RPEDEBUG(
"Failed encoding TACACS+ reply");
397 RDEBUG(
"Sending %s ID %i from %pV:%i to %pV:%i length %zu via socket %s",
401 request->reply->socket.inet.src_port,
403 request->reply->socket.inet.dst_port,
405 request->async->listen->name);
453 inst->io.app_instance = instance;
483 if (!
inst->io.submodule)
return 0;
509 if (!
inst->max_packet_size &&
inst->io.app_io)
inst->max_packet_size =
inst->io.app_io->default_message_size;
511 if (!
inst->num_messages)
inst->num_messages = 256;
534 PERROR(
"Failed initialising tacacs");
static int const char char buffer[256]
module_t common
Common fields to all loadable modules.
Public structure describing an I/O path for a protocol.
module_t common
Common fields provided by all modules.
Describes a new application (protocol)
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
#define CONF_PARSER_TERMINATOR
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
#define FR_TIME_DELTA_BOUND_CHECK(_name, _var, _op, _bound)
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
#define cf_log_err(_cf, _fmt,...)
size_t channel_packet_priority_len
fr_table_num_sorted_t const channel_packet_priority[]
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_value_box_t const * value
Enum value (what name maps to).
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
Value of an enumerated attribute.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
fr_socket_t socket
src/dst ip and port.
fr_client_t const * radclient
old-style client definition
char const * secret
Secret PSK.
bool active
for dynamic clients
char const * nas_type
Type of client (arbitrary).
bool dynamic
Whether the client was dynamically defined.
Describes a host allowed to send packets to the server.
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
#define RPEDEBUG(fmt,...)
#define RHEXDUMP3(_data, _len, _fmt,...)
int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet_t const *packet)
Allocate a "Net." struct with src/dst host and port.
@ L_DBG_LVL_1
Highest priority debug messages (-x).
fr_app_io_t fr_master_app_io
int fr_master_io_listen(fr_io_instance_t *inst, fr_schedule_t *sc, size_t default_message_size, size_t num_messages)
fr_io_address_t const * address
of this packet.. shared between multiple packets
bool do_not_respond
don't respond
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_OCTETS
Raw octets.
#define MODULE_INST_CTX(_mi)
Wrapper to create a module_inst_ctx_t as a compound literal.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for instantiation calls.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
fr_slen_t fr_utf8_str(uint8_t const *str, ssize_t inlen)
Validate a complete UTF8 string.
static int mod_load(void)
static fr_dict_attr_t const * attr_packet_type
static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
static const conf_parser_t proto_tacacs_config[]
fr_dict_attr_autoload_t proto_tacacs_dict_attr[]
static conf_parser_t const limit_config[]
static fr_dict_t const * dict_tacacs
static void mod_unload(void)
static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
static int mod_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
Decode the packet.
fr_dict_autoload_t proto_tacacs_dict[]
static const conf_parser_t priority_config[]
static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_tacacs_user_name
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the application.
static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf)
Open listen sockets/connect to external event source.
static int mod_priority_set(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
An instance of a proto_tacacs listen section.
char const * fr_tacacs_packet_names[FR_TACACS_CODE_MAX]
void fr_tacacs_global_free(void)
int fr_tacacs_global_init(void)
ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *vendor, uint8_t const *buffer, size_t buffer_len, const uint8_t *original, char const *const secret, size_t secret_len, int *code)
Decode a TACACS+ packet.
ssize_t fr_tacacs_encode(fr_dbuff_t *dbuff, uint8_t const *original_packet, char const *secret, size_t secret_len, unsigned int code, fr_pair_list_t *vps)
Encode VPS into a raw TACACS packet.
#define RDEBUG_ENABLED2()
#define REQUEST_VERIFY(_x)
static int instantiate(module_inst_ctx_t const *mctx)
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
module_instantiate_t instantiate
Callback to allow the module to register any per-instance resources like sockets and file handles.
module_t * exported
Public module structure.
static const uchar sc[16]
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.
int module_instantiate(module_instance_t *instance)
Manually complete module setup by calling its instantiate function.
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define packet_is_encrypted(p)
#define FR_TACACS_PACKET_CODE_VALID(_code)
fr_tacacs_packet_hdr_t hdr
#define talloc_get_type_abort_const
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
#define fr_box_ipaddr(_val)
static size_t char ** out
int virtual_server_listen_transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.