forked from owasp-modsecurity/ModSecurity
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.c
45 lines (38 loc) · 1.01 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdlib.h>
#include <stdio.h>
#include "standalone/api.h"
static void print_log(void* obj, int level, char* str)
{
if (str != NULL) {
puts(str);
}
}
static void exit_with_error(const char* msg)
{
puts(msg);
exit(EXIT_FAILURE);
}
int main(int argc, char* argv[])
{
if (argc != 2) {
exit_with_error("Invalid number of command line arguments");
}
server_rec* modsec_server = modsecInit();
if (modsec_server == NULL) {
exit_with_error("Failed to create ModSecurity server structure");
}
char hostname[] = "localhost";
modsec_server->server_hostname = hostname;
modsecSetLogHook(NULL, print_log);
modsecStartConfig();
directory_config *config = modsecGetDefaultConfig();
if (config == NULL) {
exit_with_error("Error creating default config");
}
const char *err = modsecProcessConfig(config, argv[1], NULL);
if (err != NULL) {
exit_with_error(err);
}
modsecTerminate();
exit(EXIT_SUCCESS);
}