26 #include <freeradius-devel/server/protocol.h>
27 #include <freeradius-devel/io/application.h>
28 #include <freeradius-devel/io/listen.h>
29 #include <freeradius-devel/io/schedule.h>
100 cron_tab_t *tab,
unsigned int min,
unsigned int max,
size_t offset)
104 unsigned int num,
next, step, last = 0;
105 bool last_is_set =
false;
106 bool wildcard =
false;
147 cf_log_err(ci,
"Cannot use wildcard and numbers for %s at %s",
name, p);
155 num = strtoul(p, &end, 10);
156 if ((num <
min) || (num > max)) {
157 cf_log_err(ci,
"Number is invalid or out of bounds (%d..%d) for %s at %s",
169 }
else if (num <= last) {
170 cf_log_err(ci,
"Number overlaps with previous value of %u, for %s at %s",
181 next = strtoul(p, &end, 10);
183 cf_log_err(ci,
"End of range number overlaps with previous value of %u, for %s at %s",
189 cf_log_err(ci,
"End of range number is invalid or out of bounds (%d..%d) for %s at %s",
203 step = strtoul(p, &end, 10);
205 cf_log_err(ci,
"Step value is invalid or out of bounds for %s at %s",
name, p);
215 for (i = num; i <=
next; i += step) {
216 fields |= ((uint64_t) 1) << i;
224 fields |= ((uint64_t) 1) << num;
232 if (!(!*end || isspace((
uint8_t) *end))) {
248 for (i =
min; i <= max; i++) {
249 if ((fields & (((uint64_t) 1) << i)) == 0) {
264 {
L(
"annually"),
"0 0 1 1 *" },
265 {
L(
"daily"),
"0 0 * * *" },
266 {
L(
"hourly"),
"0 * * * *" },
267 {
L(
"midnight"),
"0 0 * * *" },
268 {
L(
"monthly"),
"0 0 1 * *" },
270 {
L(
"weekly"),
"0 0 * * 0" },
271 {
L(
"yearly"),
"0 0 1 1 *" },
309 *((
char const **)
out) = p;
315 if (
parse_field(ci, &p,
"minute", &
inst->tab[0], 0, 59, offsetof(
struct tm, tm_min)) < 0)
return -1;
316 if (
parse_field(ci, &p,
"hour", &
inst->tab[1], 0, 59, offsetof(
struct tm, tm_hour)) < 0)
return -1;
317 if (
parse_field(ci, &p,
"day of month", &
inst->tab[2], 1, 31, offsetof(
struct tm, tm_mday)) < 0)
return -1;
318 if (
parse_field(ci, &p,
"month", &
inst->tab[3], 1,12, offsetof(
struct tm, tm_mon)) < 0)
return -1;
319 if (
parse_field(ci, &p,
"day of week", &
inst->tab[4], 0, 6, offsetof(
struct tm, tm_wday)) < 0)
return -1;
324 cf_log_err(ci,
"Unexpected text after cron time specification");
365 address = *address_p;
367 memset(address, 0,
sizeof(*address));
368 address->
socket.inet.src_ipaddr.
af = AF_INET;
369 address->
socket.inet.dst_ipaddr.
af = AF_INET;
374 if (buffer_len < 1) {
375 DEBUG2(
"proto_cron_tab read buffer is too small for input packet");
384 DEBUG2(
"proto_cron_crontab - reading packet for %s",
412 if (
inst->filename == NULL)
return -1;
413 li->
fd = open(
inst->filename, O_RDONLY);
415 memset(&ipaddr, 0,
sizeof(ipaddr));
422 thread->
parent = talloc_parent(li);
442 request->dict =
inst->dict;
447 if (
inst->code) request->packet->code =
inst->code;
448 request->packet->id =
fr_rand() & 0xff;
449 request->reply->id = request->packet->id;
451 request->packet->data = talloc_zero_array(request->packet,
uint8_t, 1);
452 request->packet->data_len = 1;
461 request->packet->socket = address->
socket;
480 unsigned int i, num = *(
int *) (((
uint8_t *) tm) + tab->
offset);
488 if (num < tab->max)
goto done;
495 for (i = num; i <= tab->
max; i++) {
496 if ((tab->
fields & (((uint64_t) 1) << i)) != 0) {
526 time_t start = time(NULL), end;
562 int tm_wday = tm.tm_wday;
574 w_tm.tm_mday += (6 - tm_wday);
576 (void) mktime(&w_tm);
578 tm_wday = w_tm.tm_wday;
598 w_tm.tm_mday += tm.tm_wday - tm_wday;
611 m_time = mktime(&m_tm);
612 w_time = mktime(&w_tm);
614 if (m_time < w_time) {
632 DEBUG(
"TIMER - virtual server %s next cron is at %s, in %ld seconds",
702 cf_log_err(
conf,
"Please define 'namespace' in this virtual server");
708 if (!
inst->client)
return 0;
714 client->
secret = talloc_strdup(client,
"testing123");
715 client->
nas_type = talloc_strdup(client,
"load");
718 fp = fopen(
inst->filename,
"r");
742 .name =
"cron_crontab",
748 .default_message_size = 4096,
749 .track_duplicates =
false,
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.
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#define L(_str)
Helper for initialising arrays of string literals.
#define CONF_PARSER_TERMINATOR
#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
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
@ CONF_FLAG_FILE_INPUT
File matching value must exist, and must be readable.
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
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.
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
API to create and manipulate internal format configurations.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
fr_dcursor_eval_t void const * uctx
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
#define fr_event_filter_update(...)
#define FR_EVENT_SUSPEND(_s, _f)
Temporarily remove the filter for a func from kevent.
#define fr_event_timer_at(...)
Callbacks for the FR_EVENT_FILTER_IO filter.
Structure describing a modification to a filter's state.
fr_socket_t socket
src/dst ip and port.
fr_client_t const * radclient
old-style client definition
fr_socket_t * app_io_addr
for tracking duplicate sockets
void const * app_io_instance
I/O path configuration context.
void * thread_instance
thread / socket context
int fd
file descriptor for this socket - set by open
void fr_network_listen_read(fr_network_t *nr, fr_listen_t *li)
Signal the network to read from a listener.
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
char const * secret
Secret PSK.
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
char const * nas_type
Type of client (arbitrary).
char const * longname
Client identifier.
char const * shortname
Client nickname.
bool use_connected
do we use connected sockets for this client
Describes a host allowed to send packets to the server.
#define DEBUG_ENABLED2
True if global debug level 1-2 messages are enabled.
Stores all information relating to an event list.
static fr_event_update_t pause_read[]
fr_io_address_t const * address
of this packet.. shared between multiple packets
#define fr_skip_whitespace(_p)
Skip whitespace ('\t', '\n', '\v', '\f', '\r', ' ')
char * ctime_r(time_t const *l_clock, char *l_buf)
struct tm * localtime_r(time_t const *l_clock, struct tm *result)
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_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
int fr_pair_list_afrom_file(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *out, FILE *fp, bool *pfiledone)
Read valuepairs from the fp up to End-Of-File.
Cron master protocol handler.
CONF_SECTION * server_cs
server CS for this listener
static const conf_parser_t crontab_listen_config[]
fr_event_timer_t const * ev
for writing statistics
fr_client_t * client
static client
char const * name
socket name
static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
static int mod_decode(void const *instance, request_t *request, UNUSED uint8_t *const data, UNUSED size_t data_len)
Decode the packet.
static size_t time_names_len
char const * filename
where to read input packet from
fr_time_t recv_time
when the timer hit.
fr_event_list_t * el
event list
struct proto_cron_tab_s proto_cron_crontab_t
static int time_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static ssize_t mod_write(UNUSED fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time, UNUSED uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
fr_listen_t * parent
master IO handler
static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, void *nr)
Set the event list for a new socket.
static int mod_open(fr_listen_t *li)
Open a crontab listener.
static char const * mod_name(fr_listen_t *li)
fr_app_io_t proto_cron_crontab
bool suspended
we suspend reading from the FD.
static bool get_next(struct tm *tm, cron_tab_t const *tab)
static int parse_field(CONF_ITEM *ci, char const **start, char const *name, cron_tab_t *tab, unsigned int min, unsigned int max, size_t offset)
CONF_SECTION * cs
our configuration
char const * spec
crontab spec
bool bootstrap
get it started
proto_cron_crontab_t const * inst
static fr_client_t * mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipaddr, UNUSED int ipproto)
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_network_t * nr
network handler
static fr_table_ptr_sorted_t time_names[]
fr_dict_t const * dict
our namespace.
static void do_cron(fr_event_list_t *el, fr_time_t now, void *uctx)
fr_pair_list_t pair_list
for input packet
uint32_t fr_rand(void)
Return a 32-bit random number.
#define REQUEST_VERIFY(_x)
static size_t min(size_t x, size_t y)
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
module_instance_t const * parent
Parent module's instance (if any).
eap_aka_sim_process_conf_t * inst
#define fr_time()
Allow us to arbitrarily manipulate time.
Stores an attribute, a value and various bits of other data.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
An element in a lexicographically sorted array of name to ptr mappings.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
#define talloc_get_type_abort_const
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
#define fr_time_add(_a, _b)
Add a time/time delta together.
static fr_event_list_t * el
static fr_socket_t * fr_socket_addr_alloc_inet_src(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_init_inet_src will also allocates a fr_socket_t.
int af
AF_INET, AF_INET6, or AF_UNIX.
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
static size_t char ** out
fr_dict_t const * virtual_server_dict_by_child_ci(CONF_ITEM const *ci)
Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server.