Beispiel #1
0
static void
accounting_stop(void)
{
    int  tac_fd;
    char *msg;
    struct tac_attrib *attr;
    struct in_addr      peer_addr;
    char   buf[40];

    if (prev_ip_down_hook) {
	prev_ip_down_hook();
    }
    
    if (use_tacacs && use_account && logged_in) {
	logged_in = 0;

	if (tac_server == -1)
	    return;
    
	tac_fd = tac_connect(&tac_server, 1);
	if (tac_fd < 0)
	    return;

	/* stop accounting */
	attr = NULL;

	sprintf(buf, "%lu", time(0));
	tac_add_attrib(&attr, "stop_time", buf);
	sprintf(buf, "%hu", task_id);
	tac_add_attrib(&attr, "task_id", buf);
	if (link_stats_valid) {
	    sprintf(buf, "%d", link_stats.bytes_out);
	    tac_add_attrib(&attr, "bytes_out", buf);
	    sprintf(buf, "%d", link_stats.bytes_in);
	    tac_add_attrib(&attr, "bytes_in", buf);
	    sprintf(buf, "%d", link_connect_time);
	    tac_add_attrib(&attr, "elapsed_time", buf);
	    peer_addr.s_addr = ipcp_hisoptions[0].hisaddr;
	    sprintf(buf, "%s", inet_ntoa(peer_addr));
	}
	
	tac_account_send(tac_fd, TAC_PLUS_ACCT_FLAG_STOP, peer_authname, tty, buf, attr);
	
	msg = tac_account_read(tac_fd);
	if (msg != NULL)
	    syslog(LOG_ERR,"TACACS+ stop accounting failed: %s\n", msg);
	
	close(tac_fd);
	tac_free_attrib(&attr);
    }
}
Beispiel #2
0
static void
radius_ip_down(void)
{
	struct radius_attrib *attriblist, *recvattriblist;

	if (prev_ip_down_hook) {
		prev_ip_down_hook();
	}

	/* Put in the accountstart check here since this hook
	 * also gets called if an IP address could not be
	 * negotiated. */
	if (use_account && accountstart) {
		accountstart = 0;

		if (radius_server == -1)
			return;

		attriblist = NULL;
		recvattriblist = NULL;
	
		if (!radius_add_attrib(
				&attriblist, PW_VENDOR_NONE, PW_ACCT_STATUS_TYPE,
				PW_STATUS_STOP, NULL, 0)) {
			radius_free_attrib(attriblist);
			return;
		}

		if (!radius_add_attrib(
				&attriblist, PW_VENDOR_NONE, PW_ACCT_SESSION_ID,
				0, sessionid, strlen(sessionid))) {
			radius_free_attrib(attriblist);
			return;
		}

		if (!radius_common_account_attrib(&attriblist)) {
			radius_free_attrib(attriblist);
			return;
		}

		if (link_stats_valid) {
			if (!radius_add_attrib(
					&attriblist, PW_VENDOR_NONE, PW_ACCT_INPUT_OCTETS,
					link_stats.bytes_in, NULL, 0)) {
				radius_free_attrib(attriblist);
				return;
			}

			if (!radius_add_attrib(
					&attriblist, PW_VENDOR_NONE, PW_ACCT_OUTPUT_OCTETS,
					link_stats.bytes_out, NULL, 0)) {
				radius_free_attrib(attriblist);
				return;
			}

			if (!radius_add_attrib(
					&attriblist, PW_VENDOR_NONE, PW_ACCT_SESSION_TIME,
					link_connect_time, NULL, 0)) {
				radius_free_attrib(attriblist);
				return;
			}

		}

		radius_send_account_request(
				radius_server, radius_auth_port+1, radius_secret,
				attriblist, &recvattriblist);

		radius_free_attrib(attriblist);
		radius_free_attrib(recvattriblist);
	}
}