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