Some bits here and there...

This commit is contained in:
2016-08-10 01:08:56 +03:00
parent 0c4a57faed
commit 65b923cba8
7 changed files with 26 additions and 16 deletions

View File

@@ -27,6 +27,10 @@ $(EXECUTABLE): $(OBJECTS)
@echo ' CC $@' @echo ' CC $@'
@$(CC) $(CCFLAGS) -c $< -o $@ @$(CC) $(CCFLAGS) -c $< -o $@
debug: CCFLAGS = -O0 -g -Q
debug: $(SOURCES) $(EXECUTABLE)
@echo ' Compiling debug with $(CCFLAGS)'
clean: clean:
rm -rf $(OBJECTS) $(EXECUTABLE) rm -rf $(OBJECTS) $(EXECUTABLE)

View File

@@ -201,3 +201,4 @@ int main(int count, char *strings[])
close(server); /* close socket */ close(server); /* close socket */
SSL_CTX_free(ctx); /* release context */ SSL_CTX_free(ctx); /* release context */
} }

View File

@@ -5,6 +5,7 @@
#include "job.h" #include "job.h"
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <pthread.h>
struct job_t { struct job_t {
long id; long id;
@@ -144,9 +145,11 @@ void* get_memory(void *args)
freepages = sysconf(_SC_AVPHYS_PAGES); freepages = sysconf(_SC_AVPHYS_PAGES);
job->buf.meta.len = sprintf( (char*)job->buf.chunk.data, job->buf.meta.len = sprintf( (char*)job->buf.chunk.data,
"%ld / %ld (MB)", "%ld / %ld (MB)",
(freepages * pagesize) / 1048576 /* 1024*1024 */, ((pages - freepages) * pagesize) / 1048576 /* 1024*1024 */,
(pages * pagesize) / 1048576 ); (pages * pagesize) / 1048576 );
SSL_write(job->ssl, &job->buf, sizeof(struct msg)); SSL_write(job->ssl, &job->buf, sizeof(struct msg));
job->slot = FREE; job->slot = FREE;
return 0; //return 0;
pthread_detach(pthread_self());
pthread_exit(NULL);
} }

View File

@@ -12,4 +12,4 @@
202:CONF_DIR_PERM_INSECURE:"Insecure global permissions for /etc/rmps. Should be 0770!" 202:CONF_DIR_PERM_INSECURE:"Insecure global permissions for /etc/rmps. Should be 0770!"
203:CONF_FILE_GID_INSECURE:"Insecure group for /etc/rmps/rmps.conf. Should be 'rmps'!" 203:CONF_FILE_GID_INSECURE:"Insecure group for /etc/rmps/rmps.conf. Should be 'rmps'!"
204:CONF_FILE_UID_INSECURE:"Insecure owner for /etc/rmps/rmps.conf. Should be 'root'!" 204:CONF_FILE_UID_INSECURE:"Insecure owner for /etc/rmps/rmps.conf. Should be 'root'!"
205:CONF_FILE_PERM_INSECURE:"Insecure global permissions /etc/rmps/rmps.conf". Shold be 0660!" 205:CONF_FILE_PERM_INSECURE:"Insecure global permissions /etc/rmps/rmps.conf. Shold be 0660!"

View File

@@ -15,8 +15,12 @@ static void open_logs(void)
{ {
if ((fderr = fopen(conf.rmps.errlog, "a")) == NULL) if ((fderr = fopen(conf.rmps.errlog, "a")) == NULL)
fderr = stderr; fderr = stderr;
else
setvbuf(fderr, NULL, _IOLBF, 0);
if ((fdout = fopen(conf.rmps.logfile, "a")) == NULL) if ((fdout = fopen(conf.rmps.logfile, "a")) == NULL)
fdout = stdout; fdout = stdout;
else
setvbuf(fdout, NULL, _IOLBF, 0);
} }
void log_ssl(void) void log_ssl(void)
@@ -65,7 +69,6 @@ void log_trace(LOG_LEVEL lvl, char *fmt, ... )
va_start(list, fmt); va_start(list, fmt);
vfprintf(fp, fmt_with_pfx, list); vfprintf(fp, fmt_with_pfx, list);
fflush(fp);
va_end(list); va_end(list);
} }
} }

7
rmps.c
View File

@@ -82,6 +82,7 @@ static void set_env(void)
sigaction(SIGHUP, &new_sigaction, NULL); /* catch hangup signal */ sigaction(SIGHUP, &new_sigaction, NULL); /* catch hangup signal */
sigaction(SIGTERM, &new_sigaction, NULL); /* catch term signal */ sigaction(SIGTERM, &new_sigaction, NULL); /* catch term signal */
sigaction(SIGINT, &new_sigaction, NULL); /* catch interrupt signal */ sigaction(SIGINT, &new_sigaction, NULL); /* catch interrupt signal */
signal(SIGPIPE, SIG_IGN); /* prevent crashing from bad writes */
} }
static void daemonize(const char *rundir) static void daemonize(const char *rundir)
@@ -222,9 +223,9 @@ static SSL_CTX* init_server_ctx(const char *cipherlist)
return ctx; return ctx;
} }
/*---------------------------------------------------------------------*/ /*-------------------------------------------*/
/*--- LoadCertificates - load from files. ---*/ /*--- LoadCertificates - load from files. ---*/
/*---------------------------------------------------------------------*/ /*-------------------------------------------*/
void load_certificates(SSL_CTX* ctx, const char *certfile, void load_certificates(SSL_CTX* ctx, const char *certfile,
const char *keyfile, const char *cafile) const char *keyfile, const char *cafile)
{ {

View File

@@ -41,7 +41,6 @@ static void show_certs(SSL *ssl)
static void* servlet(void *args) /* Serve the connection -- threadable */ static void* servlet(void *args) /* Serve the connection -- threadable */
{ {
struct msg buf; struct msg buf;
char reply[2048];
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;
@@ -56,7 +55,7 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
show_certs(agent->ssl); show_certs(agent->ssl);
do { do {
buf.meta.type = GET_MEMORY; buf.meta.type = GET_MEMORY;
//sleep(1); sleep(1);
SSL_write(agent->ssl, &buf, sizeof(buf)); SSL_write(agent->ssl, &buf, sizeof(buf));
bytes = SSL_read(agent->ssl, &buf, sizeof(buf)); bytes = SSL_read(agent->ssl, &buf, sizeof(buf));
if (bytes > 0) { if (bytes > 0) {
@@ -66,20 +65,19 @@ static void* servlet(void *args) /* Serve the connection -- threadable */
agent->ip ); agent->ip );
continue; continue;
} }
//buf.chunk.data[bytes] = 0;
log_trace(VERBOSE, "Client msg: \"%s\"", buf.chunk.data); log_trace(VERBOSE, "Client msg: \"%s\"", buf.chunk.data);
SSL_write(agent->ssl, buf.chunk.data, buf.meta.len); /* send reply */ /* 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_trace(VERBOSE, "SSL_RECEIVED_SHUTDOWN from agent [%s]", agent->ip); log_trace(VERBOSE, "SSL_RECEIVED_SHUTDOWN from agent [%s]", agent->ip);
else { else {
log_trace(VERBOSE, "Client didn't send data! SSL error below:"); log_trace(VERBOSE, "Client didn't send data! SSL error below:");
log_ssl(); //log_ssl(); /* We actually don't have anything to log from SSL */
sprintf(reply, "%s", "Where's the data, m8?"); sprintf((char*)buf.chunk.data, "%s", "Where's the data, m8?");
/* TODO: We crash here if we Ctrl + C the client, check why */ SSL_write(agent->ssl, &buf, sizeof(struct msg));
//SSL_write(agent->ssl, reply, strlen(reply));
} }
log_trace(INFO, "Agent [%s] disconnected.", agent->ip); log_trace(INFO, "Agent [%s] disconnected.", agent->ip);
} while (bytes); } while (bytes);