24 RCSID(
"$Id: 77dec2ca063072afc583583d141a570f6c296659 $")
26 #include <freeradius-devel/server/base.h>
27 #include <freeradius-devel/server/radutmp.h>
28 #include <freeradius-devel/server/module_rlm.h>
29 #include <freeradius-devel/util/debug.h>
30 #include <freeradius-devel/radius/radius.h>
36 #define LOCK_LEN sizeof(struct radutmp)
114 if (t == 0)
time(&t);
116 fd = open(filename, O_RDWR);
134 while (read(fd, &u,
sizeof(u)) ==
sizeof(u)) {
141 if (lseek(fd, -(
off_t)
sizeof(u), SEEK_CUR) < 0) {
142 REDEBUG(
"radutmp_zap: negative lseek!");
143 lseek(fd, (
off_t)0, SEEK_SET);
148 if (write(fd, &u,
sizeof(u)) < 0) {
167 for(cl = nas_port_list; cl; cl = cl->
next) {
191 bool port_seen =
false;
193 char ip_name[INET_ADDRSTRLEN];
201 if (request->packet->socket.inet.src_ipaddr.af != AF_INET) {
202 RDEBUG2(
"IPv6 not supported!");
210 RDEBUG2(
"No Accounting-Status-Type record");
213 status =
vp->vp_uint32;
233 == NULL ||
vp->vp_uint32 == 0)
236 != NULL &&
vp->vp_length == 8 &&
237 memcmp(
vp->vp_strvalue,
"00000000", 8) == 0)
239 if (check1 == 0 || check2 == 0) {
242 RIDEBUG(
"Converting reboot records");
248 memset(&ut, 0,
sizeof(ut));
262 protocol =
vp->vp_uint32;
281 if ((
vp->vp_length > 0) && (
vp->vp_strvalue[
vp->vp_length - 1] == 0)) off--;
282 if (off < 0) off = 0;
297 if (!client)
goto no_client;
299 ut.
nas_address = request->packet->socket.inet.src_ipaddr.addr.v4.s_addr;
302 }
else if (request->packet->socket.inet.src_ipaddr.addr.v4.s_addr == ut.
nas_address) {
304 if (!client)
goto no_client;
322 }
else if (protocol ==
FR_SLIP) {
337 RIDEBUG(
"NAS %s restarted (Accounting-On packet seen)", nas);
344 RIDEBUG(
"NAS %s rebooted (Accounting-Off packet seen)", nas);
354 REDEBUG(
"NAS %s port %u unknown packet type %d)", nas, ut.
nas_port, status);
373 RWDEBUG2(
"No NAS-Port seen. Cannot do anything. Checkrad will probably not work!");
380 RDEBUG2(
"Not recording administrative user");
389 fd = open(env->
filename.vb_strvalue, O_RDWR|O_CREAT,
inst->permission);
411 if (lseek(fd, (
off_t)cache->
offset, SEEK_SET) < 0) {
419 while (read(fd, &u,
sizeof(u)) ==
sizeof(u)) {
439 RWDEBUG(
"Logout entry for NAS %s port %u has wrong ID", nas, u.
nas_port);
454 RWDEBUG(
"Login entry for NAS %s port %u wrong order", nas, u.
nas_port);
471 if (lseek(fd, -(
off_t)
sizeof(u), SEEK_CUR) < 0) {
473 lseek(fd, (
off_t)0, SEEK_SET);
499 inst->nas_port_list = cache;
504 if (write(fd, &ut,
sizeof(u)) < 0) {
521 if (write(fd, &u,
sizeof(u)) < 0) {
528 RWDEBUG(
"Logout for NAS %s port %u, but no Login record", nas, ut.
nas_port);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
#define CALL_ENV_TERMINATOR
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
#define CONF_PARSER_TERMINATOR
#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
char const * name1
Name of the CONF_ITEM to parse.
Defines a CONF_PAIR to C data type mapping.
#define FR_STATUS_ACCOUNTING_OFF
#define FR_STATUS_ACCOUNTING_ON
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.
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.
void *_CONST data
Module instance's parsed configuration.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
char const * shortname
Client nickname.
Describes a host allowed to send packets to the server.
#define RWDEBUG2(fmt,...)
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
int rad_lockfd(int fd, int lock_len)
char const * inet_ntop(int af, void const *src, char *dst, size_t cnt)
void * env_data
Per call environment data.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Temporary structure to hold arguments for module calls.
Specifies a module method identifier.
module_t common
Common fields presented by all modules.
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.
static const conf_parser_t config[]
unsigned int framed_address
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_RCODE(_rcode)
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_OK
The module is OK, continue.
@ RLM_MODULE_FAIL
Module failed, don't reply.
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
static fr_dict_attr_t const * attr_login_ip_host
fr_dict_attr_autoload_t rlm_radutmp_dict_attr[]
static fr_dict_attr_t const * attr_acct_session_time
static const call_env_method_t method_env
static fr_dict_attr_t const * attr_nas_port_type
static fr_dict_attr_t const * attr_calling_station_id
static fr_dict_t const * dict_radius
static NAS_PORT * nas_port_find(NAS_PORT *nas_port_list, uint32_t nasaddr, uint16_t port)
static fr_dict_attr_t const * attr_nas_ip_address
static unlang_action_t radutmp_zap(rlm_rcode_t *p_result, request_t *request, char const *filename, uint32_t nasaddr, time_t t)
static fr_dict_attr_t const * attr_framed_ip_address
static unlang_action_t mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
static fr_dict_attr_t const * attr_framed_protocol
static fr_dict_attr_t const * attr_nas_port
fr_dict_autoload_t rlm_radutmp_dict[]
static fr_dict_attr_t const * attr_acct_status_type
static fr_dict_attr_t const * attr_acct_delay_time
static const conf_parser_t module_config[]
static char const porttypes[]
static fr_dict_attr_t const * attr_acct_session_id
@ MODULE_TYPE_THREAD_UNSAFE
Module is not threadsafe.
#define MODULE_NAME_TERMINATOR
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
eap_aka_sim_process_conf_t * inst
size_t strlcpy(char *dst, char const *src, size_t siz)
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.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
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.