More whitespace and shut some warnings up
This commit is contained in:
119
agent_pool.c
119
agent_pool.c
@@ -3,6 +3,7 @@
|
|||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MAXJOBS 10
|
#define MAXJOBS 10
|
||||||
|
|
||||||
@@ -14,42 +15,43 @@ struct agent_args {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void show_certs(SSL *ssl);
|
static void show_certs(SSL *ssl);
|
||||||
static void* servlet(void *args);
|
static void *servlet(void *args);
|
||||||
static void send_reject_msg(SSL *ssl);
|
static void send_reject_msg(SSL *ssl);
|
||||||
|
|
||||||
static void show_certs(SSL *ssl)
|
static void show_certs(SSL *ssl)
|
||||||
{
|
{
|
||||||
X509 *cert;
|
X509 *cert;
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
cert = SSL_get_peer_certificate(ssl); /* Get certificates (if available) */
|
/* Get certificates (if available) */
|
||||||
if (SSL_get_verify_result(ssl)==X509_V_OK)
|
cert = SSL_get_peer_certificate(ssl);
|
||||||
|
if (SSL_get_verify_result(ssl) == X509_V_OK)
|
||||||
log(VERBOSE, "get_verify_result == ok");
|
log(VERBOSE, "get_verify_result == ok");
|
||||||
if (cert != NULL) {
|
if (cert != NULL) {
|
||||||
log(VERBOSE, "Server certificates:");
|
log(VERBOSE, "Server certificates:");
|
||||||
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
|
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
|
||||||
log(VERBOSE, "Subject: %s", line);
|
log(VERBOSE, "Subject: %s", line);
|
||||||
free(line);
|
free(line);
|
||||||
line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
|
line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
|
||||||
log(VERBOSE, "Issuer: %s", line);
|
log(VERBOSE, "Issuer: %s", line);
|
||||||
free(line);
|
free(line);
|
||||||
X509_free(cert);
|
X509_free(cert);
|
||||||
} else
|
} else
|
||||||
log(VERBOSE, "No certificates from peer");
|
log(VERBOSE, "No certificates from peer");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* servlet(void *args) /* Serve the connection -- threadable */
|
static void *servlet(void *args) /* Serve the connection -- threadable */
|
||||||
{
|
{
|
||||||
struct msg_t buf;
|
struct msg_t buf;
|
||||||
int bytes, ret;
|
int bytes, ret;
|
||||||
//unsigned short job[MAXJOBS] = { 0 };
|
//unsigned short job[MAXJOBS] = { 0 };
|
||||||
struct agent_args *agent = (struct agent_args*)args;
|
struct agent_args *agent = (struct agent_args *)args;
|
||||||
|
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
ret = SSL_accept(agent->ssl);
|
ret = SSL_accept(agent->ssl);
|
||||||
/* We check for unclean (ret < 0) and clean (ret == 0) failures */
|
/* We check for unclean (ret < 0) and clean (ret == 0) failures */
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
log(WARNING, "SSL_accept() failed. Reason below:");
|
log(WARNING, "SSL_accept() failed. Reason below:");
|
||||||
log_ssl();
|
log_ssl();
|
||||||
} else {
|
} else {
|
||||||
show_certs(agent->ssl);
|
show_certs(agent->ssl);
|
||||||
@@ -60,23 +62,28 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
|
|||||||
bytes = SSL_read(agent->ssl, &buf, sizeof(buf));
|
bytes = SSL_read(agent->ssl, &buf, sizeof(buf));
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
if (bytes != sizeof(struct msg_t)) {
|
if (bytes != sizeof(struct msg_t)) {
|
||||||
log( WARNING,
|
log(WARNING,
|
||||||
"Agent [%s] sent non-standard data!",
|
"Agent [%s] sent non-standard data!",
|
||||||
agent->ip );
|
agent->ip);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(VERBOSE, "Client msg: \"%s\"", buf.chunk.data);
|
|
||||||
/* TODO: Insert msg handler here */
|
|
||||||
|
|
||||||
|
log(VERBOSE, "Client msg: \"%s\"",
|
||||||
|
buf.chunk.data);
|
||||||
|
/* TODO: Insert msg handler here */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (SSL_get_shutdown(agent->ssl) == SSL_RECEIVED_SHUTDOWN)
|
if (SSL_get_shutdown(agent->ssl) == SSL_RECEIVED_SHUTDOWN)
|
||||||
log(VERBOSE, "SSL_RECEIVED_SHUTDOWN from agent [%s]", agent->ip);
|
log(VERBOSE,
|
||||||
|
"SSL_RECEIVED_SHUTDOWN from agent [%s]",
|
||||||
|
agent->ip);
|
||||||
else {
|
else {
|
||||||
log(VERBOSE, "Client didn't send data! SSL error below:");
|
log(VERBOSE,
|
||||||
//log_ssl(); /* We actually don't have anything to log from SSL */
|
"Client didn't send data! SSL error below:");
|
||||||
sprintf((char*)buf.chunk.data, "%s", "Where's the data, m8?");
|
/* I think logging is NOT needed here */
|
||||||
|
//log_ssl();
|
||||||
|
sprintf((char *)buf.chunk.data, "%s",
|
||||||
|
"Where's the data, m8?");
|
||||||
SSL_write(agent->ssl, &buf, sizeof(struct msg_t));
|
SSL_write(agent->ssl, &buf, sizeof(struct msg_t));
|
||||||
}
|
}
|
||||||
log(INFO, "Agent [%s] disconnected.", agent->ip);
|
log(INFO, "Agent [%s] disconnected.", agent->ip);
|
||||||
@@ -92,58 +99,64 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
|
|||||||
static void send_reject_msg(SSL *ssl)
|
static void send_reject_msg(SSL *ssl)
|
||||||
{
|
{
|
||||||
char *reply = "FAILURE - The connection queue is full!\n";
|
char *reply = "FAILURE - The connection queue is full!\n";
|
||||||
|
|
||||||
SSL_write(ssl, reply, strlen(reply));
|
SSL_write(ssl, reply, strlen(reply));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* agent_pool(void *args)
|
void *agent_pool(void *args)
|
||||||
{
|
{
|
||||||
struct pool_data *pool = args;
|
struct pool_data *pool = args;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_t *agent_thread = (pthread_t*)malloc(pool->size * sizeof(pthread_t));
|
pthread_t *agent_thread =
|
||||||
|
(pthread_t *)malloc(pool->size * sizeof(pthread_t));
|
||||||
struct agent_args *agent_struct =
|
struct agent_args *agent_struct =
|
||||||
(struct agent_args*)malloc(pool->size * sizeof(struct agent_args));
|
(struct agent_args *)malloc(pool->size * sizeof(struct agent_args));
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(agent_thread, 0, sizeof(pthread_t) * pool->size);
|
memset(agent_thread, 0, sizeof(pthread_t) * pool->size);
|
||||||
memset(agent_struct, 0, sizeof(struct agent_args) * pool->size);
|
memset(agent_struct, 0, sizeof(struct agent_args) * pool->size);
|
||||||
|
|
||||||
pthread_mutex_init(&mutex, NULL);
|
pthread_mutex_init(&mutex, NULL);
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
char address[INET6_ADDRSTRLEN];
|
char address[INET6_ADDRSTRLEN];
|
||||||
socklen_t len = sizeof(addr);
|
socklen_t len = sizeof(addr);
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
int agent = accept(pool->srv, (struct sockaddr*)&addr, &len);
|
int agent = accept(pool->srv, (struct sockaddr *)&addr, &len);
|
||||||
log(INFO,
|
|
||||||
|
log(INFO,
|
||||||
"Connection: %s:%d",
|
"Connection: %s:%d",
|
||||||
inet_ntop(AF_INET, &addr.sin_addr, address, sizeof(address)),
|
inet_ntop(AF_INET, &addr.sin_addr,
|
||||||
|
address, sizeof(address)),
|
||||||
ntohs(addr.sin_port));
|
ntohs(addr.sin_port));
|
||||||
|
|
||||||
for (i = 0; i < pool->size; i++) {
|
for (i = 0; i < pool->size; i++) {
|
||||||
if (!agent_struct[i].busy) {
|
if (!agent_struct[i].busy) {
|
||||||
agent_struct[i].busy = 1;
|
agent_struct[i].busy = 1;
|
||||||
agent_struct[i].ssl = SSL_new(pool->ctx);
|
agent_struct[i].ssl = SSL_new(pool->ctx);
|
||||||
agent_struct[i].sd = agent;
|
agent_struct[i].sd = agent;
|
||||||
memcpy( agent_struct[i].ip,
|
memcpy(agent_struct[i].ip,
|
||||||
inet_ntop(AF_INET, &addr.sin_addr, address, sizeof(address)),
|
inet_ntop(AF_INET, &addr.sin_addr,
|
||||||
sizeof(agent_struct[i].ip) );
|
address, sizeof(address)),
|
||||||
SSL_set_fd(agent_struct[i].ssl, agent_struct[i].sd);
|
sizeof(agent_struct[i].ip));
|
||||||
pthread_create( &agent_thread[i],
|
SSL_set_fd(agent_struct[i].ssl,
|
||||||
|
agent_struct[i].sd);
|
||||||
|
pthread_create(&agent_thread[i],
|
||||||
&attr,
|
&attr,
|
||||||
servlet,
|
servlet,
|
||||||
&agent_struct[i] );
|
&agent_struct[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == pool->size) {
|
if (i == pool->size) {
|
||||||
log( WARNING,
|
log(WARNING,
|
||||||
"Agent [%s] dropped. Poolsize limit reached.",
|
"Agent [%s] dropped. Poolsize limit reached.",
|
||||||
inet_ntop(AF_INET, &addr.sin_addr, address, sizeof(address))
|
inet_ntop(AF_INET, &addr.sin_addr,
|
||||||
);
|
address, sizeof(address)));
|
||||||
ssl = SSL_new(pool->ctx);
|
ssl = SSL_new(pool->ctx);
|
||||||
SSL_set_fd(ssl, agent);
|
SSL_set_fd(ssl, agent);
|
||||||
if (SSL_accept(ssl) == FAIL) {
|
if (SSL_accept(ssl) == FAIL) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MAXJOBS 10
|
#define MAXJOBS 10
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
enum ERROR_CODES {
|
enum ERROR_CODES {
|
||||||
CONF_DIR_MISSING = 100,
|
CONF_DIR_MISSING = 100,
|
||||||
CONF_DIR_PERM, /* 101 */
|
CONF_DIR_PERM, /* 101 */
|
||||||
CONF_DIR_NOTDIR, /* 102 */
|
CONF_DIR_NOTDIR, /* 102 */
|
||||||
CONF_MISSING, /* 103 */
|
CONF_MISSING, /* 103 */
|
||||||
CONF_PERM, /* 104 */
|
CONF_PERM, /* 104 */
|
||||||
CONF_NOTFILE /* 105 */
|
CONF_NOTFILE, /* 105 */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WARN_CODES {
|
enum WARN_CODES {
|
||||||
@@ -16,7 +16,7 @@ enum WARN_CODES {
|
|||||||
CONF_DIR_PERM_INSECURE,
|
CONF_DIR_PERM_INSECURE,
|
||||||
CONF_FILE_GID_INSECURE,
|
CONF_FILE_GID_INSECURE,
|
||||||
CONF_FILE_UID_INSECURE,
|
CONF_FILE_UID_INSECURE,
|
||||||
CONF_FILE_PERM_INSECURE
|
CONF_FILE_PERM_INSECURE,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void enumtostr(char *scode, int code);
|
extern void enumtostr(char *scode, int code);
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ enum msg_types {
|
|||||||
struct msg_meta_t {
|
struct msg_meta_t {
|
||||||
unsigned short id; /* Agent job ID */
|
unsigned short id; /* Agent job ID */
|
||||||
unsigned short type; /* Data type */
|
unsigned short type; /* Data type */
|
||||||
unsigned len; /* Data size to expect in buffer */
|
unsigned int len; /* Data size to expect in buffer */
|
||||||
unsigned chunks;
|
unsigned int chunks;
|
||||||
short is_recv;
|
short is_recv;
|
||||||
short locking;
|
short locking;
|
||||||
short isjob;
|
short isjob;
|
||||||
|
|||||||
3
rmps.c
3
rmps.c
@@ -5,6 +5,7 @@
|
|||||||
#include "job_queue.h"
|
#include "job_queue.h"
|
||||||
#include "rmps.h"
|
#include "rmps.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -209,7 +210,7 @@ static SSL_CTX* init_server_ctx(const char *cipherlist, int mode)
|
|||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
|
|
||||||
/* create new context from method */
|
/* create new context from method */
|
||||||
ctx = SSL_CTX_new(TLSv1_2_method());
|
ctx = SSL_CTX_new(TLS_method());
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
log(ERROR, "SSL_CTX_new() returned NULL - Aborting...");
|
log(ERROR, "SSL_CTX_new() returned NULL - Aborting...");
|
||||||
log(ERROR, "RMPS failed to start, shutting down...");
|
log(ERROR, "RMPS failed to start, shutting down...");
|
||||||
|
|||||||
30
sql.c
30
sql.c
@@ -5,29 +5,31 @@
|
|||||||
#include "sql.h"
|
#include "sql.h"
|
||||||
#include "confparser.h"
|
#include "confparser.h"
|
||||||
|
|
||||||
int add_user()
|
int add_user(void)
|
||||||
{
|
{
|
||||||
MYSQL *con = mysql_init(NULL);
|
MYSQL *con = mysql_init(NULL);
|
||||||
char sql[200];
|
char sql[200];
|
||||||
|
|
||||||
if (con == NULL) {
|
if (con == NULL) {
|
||||||
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (mysql_real_connect(con, conf_db_hostname(), "rmps", conf_db_pass(),
|
if (mysql_real_connect(con, conf_db_hostname(), "rmps", conf_db_pass(),
|
||||||
NULL, 0, NULL, 0) == NULL) {
|
NULL, 0, NULL, 0) == NULL) {
|
||||||
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
||||||
mysql_close(con);
|
mysql_close(con);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sprintf(sql, "call addUser(`%s`, `%s`, `%s`, `%s`, `%s`, `%s`)",
|
sprintf(sql, "call addUser(`%s`, `%s`, `%s`, `%s`, `%s`, `%s`)",
|
||||||
"user", "noob", "asd@asd.asd", "asdsadasdassda", "salt", "more");
|
"user", "noob", "asd@asd.asd", "asdsadasdassda", "salt", "more");
|
||||||
if (mysql_query(con, sql)) {
|
if (mysql_query(con, sql)) {
|
||||||
//fprintf(stderr, "%s\n", mysql_error(con));
|
//fprintf(stderr, "%s\n", mysql_error(con));
|
||||||
|
|
||||||
mysql_close(con);
|
mysql_close(con);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
MYSQL_RES *result = mysql_store_result(con);
|
MYSQL_RES *result = mysql_store_result(con);
|
||||||
|
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
log(ERROR, "Failed to add user: %s", mysql_error(con));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -39,12 +41,12 @@ int add_user()
|
|||||||
|
|
||||||
while ((row = mysql_fetch_row(result))) {
|
while ((row = mysql_fetch_row(result))) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < num_fields; i++) {
|
for (i = 0; i < num_fields; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
while(field = mysql_fetch_field(result)) {
|
while ((field = mysql_fetch_field(result)))
|
||||||
printf("| %s ", field->name);
|
printf("| %s ", field->name);
|
||||||
}
|
printf("\n");
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
printf("| %s ", row[i] ? row[i] : "NULL");
|
printf("| %s ", row[i] ? row[i] : "NULL");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user