#include <ctype.h>
/* timestr.c */
-int timestr_match(char const *, fr_time_t);
+fr_time_delta_t timestr_match(char const *, fr_time_t);
/*
* Define a structure for our module configuration.
* be used as the instance handle.
*/
typedef struct {
- uint32_t min_time;
+ fr_time_delta_t min_time;
} rlm_logintime_t;
static const CONF_PARSER module_config[] = {
- { FR_CONF_OFFSET("minimum_timeout", FR_TYPE_UINT32, rlm_logintime_t, min_time), .dflt = "60" },
+ { FR_CONF_OFFSET("minimum_timeout", FR_TYPE_TIME_DELTA, rlm_logintime_t, min_time), .dflt = "60s" },
CONF_PARSER_TERMINATOR
};
{
rlm_logintime_t const *inst = talloc_get_type_abort_const(mctx->instance, rlm_logintime_t);
fr_pair_t *ends, *vp;
- int32_t left;
+ fr_time_delta_t left;
ends = fr_pair_find_by_da(&request->control_pairs, attr_login_time, 0);
if (!ends) RETURN_MODULE_NOOP;
*
* We don't know were going to get another chance to lock out the user, so we need to do it now.
*/
- if ((uint32_t)left < inst->min_time) {
+ if (left < inst->min_time) {
REDEBUG("Login outside of allowed time-slot (session end %s, with lockout %i seconds before)",
- ends->vp_strvalue, inst->min_time);
+ ends->vp_strvalue, (int) fr_time_delta_to_sec(inst->min_time));
RETURN_MODULE_DISALLOW;
}
* There's time left in the users session, inform the NAS by including a Session-vp
* attribute in the reply, or modifying the existing one.
*/
- RDEBUG2("Login within allowed time-slot, %d seconds left in this session", left);
+ RDEBUG2("Login within allowed time-slot, %d seconds left in this session", (int) fr_time_delta_to_sec(left));
switch (pair_update_reply(&vp, attr_session_timeout)) {
case 1:
/* just update... */
- if (vp->vp_uint32 > (uint32_t)left) {
- vp->vp_uint32 = (uint32_t)left;
+ if (vp->vp_uint32 > fr_time_delta_to_sec(left)) {
+ vp->vp_uint32 = fr_time_delta_to_sec(left);
RDEBUG2("&reply.Session-Timeout := %pV", &vp->data);
}
break;
case 0: /* no pre-existing */
- vp->vp_uint32 = (uint32_t)left;
+ vp->vp_uint32 = fr_time_delta_to_sec(left);
RDEBUG2("&reply.Session-Timeout := %pV", &vp->data);
break;
#include <ctype.h>
-int timestr_match(char const *, fr_time_t);
+fr_time_delta_t timestr_match(char const *, fr_time_t);
static char const *days[] =
{ "su", "mo", "tu", "we", "th", "fr", "sa", "wk", "any", "al" };
}
/*
- * Match a timestring and return seconds left.
+ * Match a timestring and return time left.
* -1 for no match, 0 for unlimited.
*/
-int timestr_match(char const *tmstr, fr_time_t when)
+fr_time_delta_t timestr_match(char const *tmstr, fr_time_t when)
{
struct tm *tm, s_tm;
char bitmap[WEEKMIN / 8];
break;
}
- if (tot == 0)
- return -1;
+ if (!tot) return -1;
- return (i == now) ? 0 : tot;
+ if (i == now) return 0;
+
+ return fr_time_delta_from_sec(tot);
}
#ifdef STANDALONE
int main(int argc, char **argv)
{
- int l;
+ fr_time_delta_t l;
if (argc != 2) {
fprintf(stderr, "Usage: test timestring\n");
fr_exit_now(EXIT_FAILURE);
}
- l = timestr_match(argv[1], time(NULL));
- printf ("%s: %d seconds left\n", argv[1], l);
+ l = timestr_match(argv[1], fr_time());
+ printf ("%s: %d seconds left\n", argv[1], fr_time_delta_to_sec(l));
return 0;
}