Skip to content

Commit

Permalink
Merge pull request #538 from nodogsplash/4.4.1beta
Browse files Browse the repository at this point in the history
Coding style update - use // for single line comments
  • Loading branch information
bluewavenet committed Mar 3, 2020
2 parents d9e4756 + 65a1a38 commit a7b6695
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 349 deletions.
24 changes: 12 additions & 12 deletions src/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
extern pthread_mutex_t client_list_mutex;
extern pthread_mutex_t config_mutex;

/* Count number of authentications */
// Count number of authentications
unsigned int authenticated_since_start = 0;


Expand Down Expand Up @@ -151,7 +151,7 @@ fw_refresh_client_list(void)
const int auth_idle_timeout_secs = 60 * config->auth_idle_timeout;
const time_t now = time(NULL);

/* Update all the counters */
// Update all the counters
if (-1 == iptables_fw_counters_update()) {
debug(LOG_ERR, "Could not get counters from firewall!");
return;
Expand All @@ -171,7 +171,7 @@ fw_refresh_client_list(void)
time_t last_updated = cp1->counters.last_updated;

if (cp1->session_end > 0 && cp1->session_end <= now) {
/* Session ended (only > 0 for FW_MARK_AUTHENTICATED by binauth) */
// Session ended (only > 0 for FW_MARK_AUTHENTICATED by binauth)
debug(LOG_NOTICE, "Force out user: %s %s, connected: %ds, in: %llukB, out: %llukB",
cp1->ip, cp1->mac, now - cp1->session_end,
cp1->counters.incoming / 1000, cp1->counters.outgoing / 1000);
Expand All @@ -180,7 +180,7 @@ fw_refresh_client_list(void)
} else if (preauth_idle_timeout_secs > 0
&& conn_state == FW_MARK_PREAUTHENTICATED
&& (last_updated + preauth_idle_timeout_secs) <= now) {
/* Timeout inactive preauthenticated user */
// Timeout inactive preauthenticated user
debug(LOG_NOTICE, "Timeout preauthenticated idle user: %s %s, inactive: %ds, in: %llukB, out: %llukB",
cp1->ip, cp1->mac, now - last_updated,
cp1->counters.incoming / 1000, cp1->counters.outgoing / 1000);
Expand All @@ -189,7 +189,7 @@ fw_refresh_client_list(void)
} else if (auth_idle_timeout_secs > 0
&& conn_state == FW_MARK_AUTHENTICATED
&& (last_updated + auth_idle_timeout_secs) <= now) {
/* Timeout inactive user */
// Timeout inactive user
debug(LOG_NOTICE, "Timeout authenticated idle user: %s %s, inactive: %ds, in: %llukB, out: %llukB",
cp1->ip, cp1->mac, now - last_updated,
cp1->counters.incoming / 1000, cp1->counters.outgoing / 1000);
Expand All @@ -216,17 +216,17 @@ thread_client_timeout_check(void *arg)

fw_refresh_client_list();

/* Sleep for config.checkinterval seconds... */
// Sleep for config.checkinterval seconds...
timeout.tv_sec = time(NULL) + config_get_config()->checkinterval;
timeout.tv_nsec = 0;

/* Mutex must be locked for pthread_cond_timedwait... */
// Mutex must be locked for pthread_cond_timedwait...
pthread_mutex_lock(&cond_mutex);

/* Thread safe "sleep" */
// Thread safe "sleep"
pthread_cond_timedwait(&cond, &cond_mutex, &timeout);

/* No longer needs to be locked */
// No longer needs to be locked
pthread_mutex_unlock(&cond_mutex);
}

Expand All @@ -246,7 +246,7 @@ auth_client_deauth(const unsigned id, const char *reason)

client = client_list_find_by_id(id);

/* Client should already have hit the server and be on the client list */
// Client should already have hit the server and be on the client list
if (client == NULL) {
debug(LOG_ERR, "Client %u to deauthenticate is not on client list", id);
goto end;
Expand Down Expand Up @@ -274,7 +274,7 @@ auth_client_auth_nolock(const unsigned id, const char *reason)

client = client_list_find_by_id(id);

/* Client should already have hit the server and be on the client list */
// Client should already have hit the server and be on the client list
if (client == NULL) {
debug(LOG_ERR, "Client %u to authenticate is not on client list", id);
return -1;
Expand Down Expand Up @@ -329,7 +329,7 @@ auth_client_untrust(const char *mac)

UNLOCK_CONFIG();

/*
/*
if (rc == 0) {
LOCK_CLIENT_LIST();
t_client * client = client_list_find_by_mac(mac);
Expand Down
25 changes: 10 additions & 15 deletions src/client_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,33 @@
#include "util.h"


/** Client counter */
// Client counter
static int client_count = 0;
static int client_id = 1;

/** Global mutex to protect access to the client list */
// Global mutex to protect access to the client list
pthread_mutex_t client_list_mutex = PTHREAD_MUTEX_INITIALIZER;

/** @internal
* Holds a pointer to the first element of the list
*/
static t_client *firstclient = NULL;

/** Return current length of the client list
*/
// Return current length of the client list
int
get_client_list_length()
{
return client_count;
}

/** Get the first element of the client list
*/
// Get the first element of the client list
t_client *
client_get_first_client(void)
{
return firstclient;
}

/**
* Initialize the list of connected clients
*/
// Initialize the list of connected clients
void
client_list_init(void)
{
Expand Down Expand Up @@ -124,7 +120,6 @@ _client_list_append(const char mac[], const char ip[])
client_reset(client);

// Blocked or Trusted client do not trigger the splash page.
// They must access the splash or status page manually.
if (is_blocked_mac(mac)) {
client->fw_connection_state = FW_MARK_BLOCKED;
} else if(is_allowed_mac(mac) || is_trusted_mac(mac)) {
Expand Down Expand Up @@ -181,13 +176,13 @@ client_list_add_client(const char mac[], const char ip[])
t_client *client;

if (!check_mac_format(mac)) {
/* Inappropriate format in IP address */
// Inappropriate format in IP address
debug(LOG_NOTICE, "Illegal MAC format [%s]", mac);
return NULL;
}

if (!check_ip_format(ip)) {
/* Inappropriate format in IP address */
// Inappropriate format in IP address
debug(LOG_NOTICE, "Illegal IP format [%s]", ip);
return NULL;
}
Expand Down Expand Up @@ -372,15 +367,15 @@ client_list_delete(t_client *client)
_client_list_free_node(client);
client_count--;
} else {
/* Loop forward until we reach our point in the list. */
// Loop forward until we reach our point in the list.
while (ptr->next != NULL && ptr->next != client) {
ptr = ptr->next;
}
/* If we reach the end before finding out element, complain. */
// If we reach the end before finding out element, complain.
if (ptr->next == NULL) {
debug(LOG_ERR, "Node to delete could not be found.");
} else {
/* Free element. */
// Free element.
debug(LOG_NOTICE, "Deleting %s %s token %s from client list",
client->ip, client->mac, client->token ? client->token : "none");
ptr->next = client->next;
Expand Down

0 comments on commit a7b6695

Please sign in to comment.