24 RCSID(
"$Id: 0b05b0049344d6f9bf4ae6138b25cf3a227c90df $")
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)
128 if (t == 0)
time(&t);
130 fd = open(filename, O_RDWR);
148 while (read(fd, &u,
sizeof(u)) ==
sizeof(u)) {
155 if (lseek(fd, -(
off_t)
sizeof(u), SEEK_CUR) < 0) {
156 REDEBUG(
"radutmp_zap: negative lseek!");
157 lseek(fd, (
off_t)0, SEEK_SET);
162 if (write(fd, &u,
sizeof(u)) < 0) {
181 for(cl = nas_port_list; cl; cl = cl->
next) {
205 bool port_seen =
false;
207 char ip_name[INET_ADDRSTRLEN];
215 if (request->packet->socket.inet.src_ipaddr.af != AF_INET) {
216 RDEBUG2(
"IPv6 not supported!");
224 RDEBUG2(
"No Accounting-Status-Type record");
227 status =
vp->vp_uint32;
247 == NULL ||
vp->vp_uint32 == 0)
250 != NULL &&
vp->vp_length == 8 &&
251 memcmp(
vp->vp_strvalue,
"00000000", 8) == 0)
253 if (check1 == 0 || check2 == 0) {
256 RIDEBUG(
"Converting reboot records");
262 memset(&ut, 0,
sizeof(ut));
276 protocol =
vp->vp_uint32;
295 if ((
vp->vp_length > 0) && (
vp->vp_strvalue[
vp->vp_length - 1] == 0)) off--;
296 if (off < 0) off = 0;
311 if (!client)
goto no_client;
313 ut.
nas_address = request->packet->socket.inet.src_ipaddr.addr.v4.s_addr;
316 }
else if (request->packet->socket.inet.src_ipaddr.addr.v4.s_addr == ut.
nas_address) {
318 if (!client)
goto no_client;
336 }
else if (protocol ==
FR_SLIP) {
351 RIDEBUG(
"NAS %s restarted (Accounting-On packet seen)", nas);
358 RIDEBUG(
"NAS %s rebooted (Accounting-Off packet seen)", nas);
368 REDEBUG(
"NAS %s port %u unknown packet type %d)", nas, ut.
nas_port, status);
387 RWDEBUG2(
"No NAS-Port seen. Cannot do anything. Checkrad will probably not work!");
394 RDEBUG2(
"Not recording administrative user");
403 fd = open(env->
filename.vb_strvalue, O_RDWR|O_CREAT,
inst->permission);
425 if (lseek(fd, (
off_t)cache->
offset, SEEK_SET) < 0) {
433 while (read(fd, &u,
sizeof(u)) ==
sizeof(u)) {
453 RWDEBUG(
"Logout entry for NAS %s port %u has wrong ID", nas, u.
nas_port);
468 RWDEBUG(
"Login entry for NAS %s port %u wrong order", nas, u.
nas_port);
485 if (lseek(fd, -(
off_t)
sizeof(u), SEEK_CUR) < 0) {
487 lseek(fd, (
off_t)0, SEEK_SET);
512 cache->
next =
inst->mutable->nas_port_list;
513 inst->mutable->nas_port_list = cache;
518 if (write(fd, &ut,
sizeof(u)) < 0) {
535 if (write(fd, &u,
sizeof(u)) < 0) {
542 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
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.
#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.
module_instance_t const * mi
Instance of the module being instantiated.
module_instance_t * mi
Module instance to detach.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for detach calls.
Temporary structure to hold arguments for instantiation calls.
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
static int mod_detach(module_detach_ctx_t const *mctx)
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 int mod_instantiate(module_inst_ctx_t const *mctx)
static char const porttypes[]
static fr_dict_attr_t const * attr_acct_session_id
static int instantiate(module_inst_ctx_t const *mctx)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
@ MODULE_TYPE_THREAD_UNSAFE
Module is not threadsafe.
void * data
Module's instance data.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
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.