1
0
mirror of https://github.com/lxsang/antd-tunnel-plugin synced 2024-11-16 09:48:21 +01:00

allow user identification in publisher

This commit is contained in:
Dany LE 2021-10-27 15:42:02 +02:00
parent 9406c4d33e
commit 6a4682c571
3 changed files with 106 additions and 92 deletions

View File

@ -1,5 +1,5 @@
# initialise autoconf and set up some basic information about the program were packaging
AC_INIT([tunnel], [0.1.0b], [xsang.le@gmail.com])
AC_INIT([tunnel], [0.1.1b], [xsang.le@gmail.com])
# Were going to use automake for this project
# [subdir-objects] if needed

BIN
dist/tunnel-0.1.1b.tar.gz vendored Normal file

Binary file not shown.

View File

@ -27,6 +27,7 @@
#define MAX_CHANNEL_ID 65535u
#define KEY_LEN 40
#define USER_LEN 64
#define MAX_SESSION_TIMEOUT (15u * 60u) //15 min
#define PING_INTERVAL 10u // 10s
#define PROCESS_TIMEOUT 30000u //30 ms
@ -74,12 +75,15 @@ typedef struct
* |MSG TYPE(1)| CHANNEL ID (2)| CLIENT ID (2)| data(m) |
*/
typedef struct {
typedef struct
{
char hash[KEY_LEN + 1]; // sha1sum + terminal byte
char user[USER_LEN + 1];
time_t last_update;
} antd_tunnel_key_t;
typedef struct {
typedef struct
{
pthread_mutex_t lock;
bst_node_t *channels;
bst_node_t *keychain;
@ -484,6 +488,7 @@ static void update_keychain(int listen_fd)
return;
}
(void)memset(key_p->hash, 0, KEY_LEN + 1);
(void)memset(key_p->user, 0, USER_LEN + 1);
int size;
if ((size = read(listen_fd, key_p->hash, KEY_LEN)) == -1)
{
@ -497,6 +502,12 @@ static void update_keychain(int listen_fd)
free(key_p);
return;
}
if ((size = read(listen_fd, key_p->user, USER_LEN)) == -1)
{
ERROR("Unable to read user from keychain FIFO: %s", strerror(errno));
free(key_p);
return;
}
// looking for key in the keychain
int hash_val = simple_hash(key_p->hash);
pthread_mutex_lock(&g_tunnel.lock);
@ -505,13 +516,13 @@ static void update_keychain(int listen_fd)
{
key_p->last_update = time(NULL);
g_tunnel.keychain = bst_insert(g_tunnel.keychain, hash_val, (void *)key_p);
LOG("New key added to the keychain (%d)", hash_val);
LOG("New key added to the keychain (%d) for user", hash_val, key_p->user);
}
else
{
antd_tunnel_key_t *existing_key = (antd_tunnel_key_t *)node->data;
existing_key->last_update = time(NULL);
LOG("Update existing key in the keychain");
LOG("Update existing key in the keychain for user %s", existing_key->user);
free(key_p);
}
pthread_mutex_unlock(&g_tunnel.lock);
@ -804,7 +815,7 @@ void destroy()
(void)unlink(path);
}
}
static void process_client_message(antd_tunnel_msg_t *msg, antd_client_t *client)
static void process_client_message(antd_tunnel_msg_t *msg, antd_client_t *client, antd_tunnel_key_t * key)
{
char buff[BUFFLEN + 1];
bst_node_t *node;
@ -886,6 +897,9 @@ static void process_client_message(antd_tunnel_msg_t *msg, antd_client_t *client
ERROR("Unable to send subscribe OK message to client");
}
msg->header.client_id = g_tunnel.id_allocator;
msg->header.size = strlen(key->user) + 1;
(void)memset(buff,0, BUFFLEN + 1);
(void)memcpy(buff, key->user, msg->header.size - 1);
msg->header.type = CHANNEL_SUBSCRIBE;
}
else
@ -1150,7 +1164,7 @@ void *handle(void *rq_data)
msg.data = buffer + offset;
// now we have the message
pthread_mutex_lock(&g_tunnel.lock);
process_client_message(&msg, rq->client);
process_client_message(&msg, rq->client, key_p);
pthread_mutex_unlock(&g_tunnel.lock);
}
free(buffer);