1 |
#include "eef.h" |
2 |
#include "pdl.h" |
3 |
#include "plugin_manager.h" |
4 |
|
5 |
static const char* _modules_path; /*! Holds the global path to plug-in modules */ |
6 |
|
7 |
/*! Try to initialize the AOS, enable logging, initialize the plug-in manager and try to parse the config file and ascertain the module path |
8 |
*/ |
9 |
EES_RC EEF_Init(char *config_file, FILE* log_file, int number_of_policies, char* names_of_policies[]){ |
10 |
start_log(log_file); |
11 |
eef_log(LOG_NOTICE, "EEF initializing"); |
12 |
|
13 |
if (AOS_Init() == EES_SUCCESS){ |
14 |
if(start_plugin_manager() == EES_SUCCESS){ |
15 |
eef_log(LOG_NOTICE, "Loading config file: %s\n", config_file); |
16 |
if(pdl_init(config_file) == EES_SUCCESS){ |
17 |
/* after the config file was successfully read, we can try to set the modules path if one was provided */ |
18 |
eef_log(LOG_NOTICE, "Loaded config file: %s\n", config_file); |
19 |
|
20 |
/* set the EEF modules path to the path found by the evaluation manager */ |
21 |
set_modules_path(get_pdl_path()); |
22 |
|
23 |
/* retrieve policy list from the evaluation mananger */ |
24 |
parsed_policy_tree = get_policies(); |
25 |
|
26 |
/* strip policies that are not explicitly passed in the names_of_policies array */ |
27 |
if(number_of_policies){ |
28 |
reduce_policy_tree(&parsed_policy_tree, number_of_policies, names_of_policies); |
29 |
} |
30 |
|
31 |
if(parsed_policy_tree){ |
32 |
/*link_dead_end_rules_in_policy(parsed_policy_tree);*/ |
33 |
/*link_rules_to_plugins(parsed_policy_tree);*/ |
34 |
} |
35 |
print_policies(parsed_policy_tree); |
36 |
|
37 |
/* this is a callout to the plugin manager, which dlopen()'s the plugin, dlsym()'s the plugin's functions and calls the plugin's initialize function */ |
38 |
if(initialize_plugins() == EES_SUCCESS){ |
39 |
/* these are callouts to the evaluation manager */ |
40 |
return EES_SUCCESS; |
41 |
} else { |
42 |
eef_log(LOG_ERR, "Failed to initialize plug-ins from policy config file %s\n", config_file); |
43 |
} |
44 |
} |
45 |
} |
46 |
} |
47 |
return EES_FAILURE; |
48 |
} |
49 |
|
50 |
/*! |
51 |
* Terminates the parser, stops the plug-in manager, terminates the AOS and closes the log. |
52 |
*/ |
53 |
EES_RC EEF_Term(){ |
54 |
eef_log(LOG_INFO, "Cleaning up..."); |
55 |
if((pdl_term(parsed_policy_tree) == EES_SUCCESS) && |
56 |
(stop_plugin_manager() == EES_SUCCESS) && |
57 |
(AOS_Term() == EES_SUCCESS)){ |
58 |
stop_log(); |
59 |
return EES_SUCCESS; |
60 |
} |
61 |
eef_log(LOG_ERR, "Errors detected\n"); |
62 |
eef_log(LOG_NOTICE, "EEF terminating..."); |
63 |
stop_log(); |
64 |
return EES_FAILURE; |
65 |
} |
66 |
|
67 |
/* Opens the log file or logs to syslog if none was provided. |
68 |
* log mask is set depending on whether ENABLE_DEBUG macro is set to true */ |
69 |
EES_RC start_log(FILE* log_file){ |
70 |
/* Log file */ |
71 |
log_file_fp = log_file; |
72 |
|
73 |
if(!log_file_fp){ |
74 |
/* logmask for debug */ |
75 |
#if ENABLE_DEBUG |
76 |
setlogmask (LOG_UPTO(LOG_DEBUG)); |
77 |
eef_log(LOG_DEBUG, "DEBUG MODE ENABLED\n"); |
78 |
#else |
79 |
setlogmask (LOG_UPTO(LOG_INFO)); |
80 |
#endif |
81 |
} else { |
82 |
/* Open syslog, regardless of use*/ |
83 |
openlog ("ees", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON); |
84 |
} |
85 |
return EES_SUCCESS; |
86 |
|
87 |
} |
88 |
|
89 |
/* Closes the log file */ |
90 |
EES_RC stop_log(){ |
91 |
if(!log_file_fp){ |
92 |
closelog(); |
93 |
} |
94 |
return EES_SUCCESS; |
95 |
} |
96 |
|
97 |
/*! |
98 |
* Sets the global modules path to load plug-ins from |
99 |
*/ |
100 |
void set_modules_path(const char* path){ |
101 |
_modules_path = path; |
102 |
} |
103 |
|
104 |
/*! |
105 |
* Returns the global modules path to load plug-ins from |
106 |
* This can be either the _modules_path as set by the set_modules_path() function or the MODULE_DIR path macro generated by the configure script. |
107 |
*/ |
108 |
const char* get_modules_path(void){ |
109 |
if(_modules_path != NULL){ |
110 |
if(strlen(_modules_path)!=0){ |
111 |
return _modules_path; |
112 |
} |
113 |
} |
114 |
return MODULE_DIR; |
115 |
} |