Browse Source

* initial

master
Alex 'AdUser' Z 9 years ago
commit
4e3b557857
  1. 3
      .gitignore
  2. 9
      CMakeLists.txt
  3. 6
      src/CMakeLists.txt
  4. 11
      src/common.h
  5. 16
      src/jail.c
  6. 15
      src/jail.h
  7. 21
      src/log.c
  8. 15
      src/log.h
  9. 46
      src/logfile.c
  10. 14
      src/logfile.h
  11. 8
      src/main.c
  12. 12
      src/match.h

3
.gitignore vendored

@ -0,0 +1,3 @@
CMakeCache.txt
CMakeFiles/
*.cmake

9
CMakeLists.txt

@ -0,0 +1,9 @@
SET(CNAME "f2b")
SET(VERSION 0.07)
PROJECT(${CNAME} C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_INSTALL_PREFIX "/usr/local")
ADD_SUBDIRECTORY (src)

6
src/CMakeLists.txt

@ -0,0 +1,6 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(f2b "main.c" "logfile.c" "log.c")
install(TARGETS f2b
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

11
src/common.h

@ -0,0 +1,11 @@
#ifndef F2B_COMMON_H_
#define F2B_COMMON_H_
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#endif /* F2B_COMMON_H_ */

16
src/jail.c

@ -0,0 +1,16 @@
#include "jail.h"
/*
size_t
f2b_jail_poll(const jail_t *jail) {
size_t processed = 0;
char logline[LOGLINE_MAX] = { '\0' };
for (f2b_logfile_t *file = jail->logfiles; file != NULL; file = file->next) {
if (f2b_logfile_getline(file, logline) < 0)
continue;
}
return processed;
}
*/

15
src/jail.h

@ -0,0 +1,15 @@
#ifndef F2B_JAIL_H_
#define F2B_JAIL_H_
#include "logfile.h"
#include "match.h"
#define LOGLINE_MAX 2048
typedef struct f2b_jail_t {
char name[32];
f2b_match_t *matches;
f2b_logfile_t *logfiles;
};
#endif /* F2B_JAIL_H_ */

21
src/log.c

@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "log.h"
#define LOGLINE_MAX 1024
void log_msg(log_msgtype_t l, const char *fmt, ...) {
va_list args;
char line[LOGLINE_MAX] = "";
char msg[LOGLINE_MAX] = "";
va_start(args, fmt);
snprintf(msg, sizeof(msg), fmt, args);
va_end(args);
strncat(line, msg, sizeof(line));
return;
}

15
src/log.h

@ -0,0 +1,15 @@
#ifndef F2B_LOG_H_
#define F2B_LOG_H_
typedef enum {
log_debug = 0,
log_info = 1,
log_note = 1,
log_warn = 2,
log_error = 3,
log_fatal = 4
} log_msgtype_t;
void log_msg (log_msgtype_t l, const char *fmt, ...);
#endif /* F2B_LOG_H_ */

46
src/logfile.c

@ -0,0 +1,46 @@
#include <sys/stat.h>
#include "common.h"
#include "log.h"
#include "logfile.h"
bool
f2b_logfile_open(f2b_logfile_t *file, const char *filename) {
struct stat st;
assert(file != NULL);
assert(filename != NULL);
memset(file, 0x0, sizeof(f2b_logfile_t));
if (stat(filename, &st) != 0) {
log_msg(log_error, "can't open file %s: %s", filename, strerror(errno));
return false;
}
strncpy(file->path, filename, sizeof(file->path));
memcpy(&file->st, &st, sizeof(st));
if ((file->fd = fopen(filename, "r")) == NULL) {
log_msg(log_error, "can't open file %s: %s", filename, strerror(errno));
return false;
}
if (fseek(file->fd, 0, SEEK_END) < 0) {
log_msg(log_error, "can't seek to end of file %s: %s", filename, strerror(errno));
return false;
}
return true;
}
void
f2b_logfile_close(const f2b_logfile_t *file);
bool
f2b_logfile_rotated(const f2b_logfile_t *file);
ssize_t
f2b_logfile_getline(const f2b_logfile_t *file, const char *buf, size_t bufsize) {
return -1;
}

14
src/logfile.h

@ -0,0 +1,14 @@
#ifndef F2B_LOGFILE_H_
#define F2B_LOGFILE_H_
#include <limits.h>
#include <sys/stat.h>
typedef struct {
struct f2b_logfile_t *next;
char path[PATH_MAX];
FILE *fd;
struct stat st;
} f2b_logfile_t;
#endif /* F2B_LOGFILE_H_ */

8
src/main.c

@ -0,0 +1,8 @@
#include "common.h"
#include "logfile.h"
#include "match.h"
int main() {
printf("Hello world!\n");
return 0;
}

12
src/match.h

@ -0,0 +1,12 @@
#ifndef F2B_MATCH_H_
#define F2B_MATCH_H_
typedef struct {
struct f2b_match_t *next;
const char *ip;
size_t count;
time_t firstseen;
time_t lastseen;
} f2b_match_t;
#endif /* F2B_MATCH_H_ */
Loading…
Cancel
Save