#include <ctype.h>
/* timestr.c */
-fr_time_delta_t timestr_match(char const *, fr_time_t);
+int timestr_match(fr_time_delta_t *out, char const *tmstr, fr_time_t when);
/*
* Define a structure for our module configuration.
*/
static int timecmp(UNUSED void *instance, request_t *request, UNUSED fr_pair_list_t *request_list, fr_pair_t const *check)
{
+ fr_time_delta_t left;
+
+ if (timestr_match(&left, check->vp_strvalue, request->packet->timestamp) < 0) return -1;
+
/*
- * If there's a request, use that timestamp.
+ * 0 is a special case meaning "allowed".
*/
- if (fr_time_delta_gteq(timestr_match(check->vp_strvalue, request->packet->timestamp), fr_time_delta_wrap(0))) return 0;
+ if (fr_time_delta_gteq(left, fr_time_delta_wrap(0))) return 0;
return -1;
}
/*
* Compare the time the request was received with the current Login-Time value
*/
- left = timestr_match(ends->vp_strvalue, request->packet->timestamp);
- if (fr_time_delta_isneg(left)) RETURN_MODULE_DISALLOW; /* outside of the allowed time */
+ if (timestr_match(&left, ends->vp_strvalue, request->packet->timestamp) < 0) {
+ RETURN_MODULE_DISALLOW; /* outside of the allowed time */
+ }
/*
- * Do nothing, login time is not controlled (unendsed).
+ * Do nothing, login time is not controlled (unended).
*/
if (fr_time_delta_eq(left, fr_time_delta_wrap(0))) RETURN_MODULE_OK;
/* else left > inst->min_time */
/*
- * There's time left in the users session, inform the NAS by including a Session-vp
+ * There's time left in the users session, inform the NAS by including a Session-Timeout
* attribute in the reply, or modifying the existing one.
*/
RDEBUG2("Login within allowed time-slot, %d seconds left in this session", (int) fr_time_delta_to_sec(left));
#include <ctype.h>
-fr_time_delta_t timestr_match(char const *, fr_time_t);
+int timestr_match(fr_time_delta_t *out, char const *tmstr, fr_time_t when);
static char const *days[] =
{ "su", "mo", "tu", "we", "th", "fr", "sa", "wk", "any", "al" };
}
/*
- * Match a timestring and return time left.
- * -1 for no match, 0 for unlimited.
+ * Match a time string, and return time left in `out`.
+ * -1 for no match
*/
-fr_time_delta_t timestr_match(char const *tmstr, fr_time_t when)
+int timestr_match(fr_time_delta_t *out, char const *tmstr, fr_time_t when)
{
struct tm *tm, s_tm;
char bitmap[WEEKMIN / 8];
- int now, tot, i;
+ int64_t now, tot, i;
int byte, bit;
#ifdef do_timestr_debug
int y;
break;
}
- if (!tot) return fr_time_delta_wrap(-1);
+ if (!tot) return -1;
- if (i == now) return fr_time_delta_wrap(0);
+ if (i == now) {
+ *out = fr_time_delta_wrap(0);
+ return 0;
+ }
- return fr_time_delta_from_sec(tot);
+ *out = fr_time_delta_wrap(tot);
+ return 0;
}
#ifdef STANDALONE