summaryrefslogtreecommitdiff
path: root/src/cert_store.c
blob: e4dd4aa358627e393e11df445d2bdc30e754b8c5 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*************************************************************************
	> File Name: cert_server.c
	> Author: fengweihao
	> Mail:
	> Created Time: Tue 29 May 2018 06:45:23 PM PDT
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include "rt_string.h"
#include "rt_common.h"
#include "cert_daemon.h"
#include "cert_conf.h"
#include "cert_session.h"
#include "logging.h"
#include "MESA_prof_load.h"

/* GIT Release */
#define CERT_GIT_RELEASE "1.1"

#define MODE_TYPE(x) run_mode & x

/* Configure Path */
#if 0
#define CERT_BASIC_CFG "/home/ceiec/certstore_run/conf/cert_store.ini"
#else
#define CERT_BASIC_CFG "./conf/cert_store.ini"
#endif

#ifdef VERSION_TARGET
char *git_ver = VERSION_TARGET;
#else
char *git_ver = "0"
#endif

static char* cert_revision() { return (CERT_GIT_RELEASE); }

enum syslog_display_format{
    FORMAT_CONSOLE,
    FORMAT_FILE,
    FORMAT_SYSLOG
};

static int run_mode;

static void help()
{
  printf("Welcome to certstore %s.%s\n", cert_revision(), VERSION_TARGET);
  printf("cert_store <--normal|--daemon>\n"
         "Usage:\n"
         "  --normal     | Run the program in normal mode\n"
         "  --daemon     | Run the program in daemon mode\n");
}

static void
cert_argv_parser(int argc, char **argv)
{
    int i;

    if (argc != 2){
        help();
        exit(0);
    }

    for (i = 0; argv[i] != NULL; i++){
		/** run version parser */
        if (!STRCMP (argv[i], "--normal")){
            goto finish;
        }
        /** daemonize */
        if (!STRCMP(argv[i], "--daemon")){
            run_mode = 0x20;
            goto finish;
        }
    }
finish:
	return;
}

static
void cert_preview ()
{
    struct config_bucket_t *rte = cert_default_config();

    printf("\r\nBasic Configuration of CertStore \n");
    printf("%30s:%45d\n", "The Threads", rte->thread_nu);
    printf("%30s:%45s\n", "Store Redis Ip", rte->addr_t.store_ip);
    printf("%30s:%45d\n", "Store Redis Port", rte->addr_t.store_port);
    printf("%30s:%45s\n", "Maat Redis Ip", rte->addr_t.maat_ip);
    printf("%30s:%45d\n", "Maat Redis Port", rte->addr_t.maat_port);
    printf("%30s:%45d\n", "Maat Redis index", rte->addr_t.dbindex);
    printf("%30s:%45d\n", "Libevent Port", rte->addr_t.e_port);
    printf("%30s:%45s\n", "Cert Path", rte->ca_path);
    printf("%30s:%45s\n", "Uninsec cert Path", rte->uninsec_path);
    printf("%30s:%45s\n", "Log Directory", logging_sc_lid.run_log_path);
    printf("%30s:%45s\n", "Table Info", rte->maat_t.info_path);
    if (rte->maat_t.maat_json_switch == 1){
        printf("%30s:%45s\n", "Pxy Obj Keyring", rte->maat_t.pxy_path);
    }
    if (rte->maat_t.maat_json_switch == 0){
        printf("%30s:%45d\n", "Scan Interval", rte->maat_t.effective_interval_s);
        printf("%30s:%45s\n", "Full Cfg Path", rte->maat_t.full_cfg_dir);
        printf("%30s:%45s\n", "Inc  Cfg Path", rte->maat_t.inc_cfg_dir);

    }
    printf("\r\n");
}

int main(int argc, char **argv)
{
    cert_argv_parser(argc, argv);

    cert_syslog_init(CERT_BASIC_CFG);

    mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Cert server init success");

    cert_init_config(CERT_BASIC_CFG);

    if (MODE_TYPE(0x20)){
        daemonize();
    }
    cert_preview();

    cert_session_init();

    signal(SIGINT, sigproc);

    return 0;
}