|
48 | 48 | //Bump when the message is modified |
49 | 49 | #define CEF_AUDIT_MESSAGE_VERSION 2 |
50 | 50 |
|
| 51 | +extern int h_errno; |
| 52 | + |
51 | 53 | static volatile int stop = 0; |
52 | 54 | static volatile int hup = 0; |
53 | 55 | static cef_conf_t config; |
@@ -119,18 +121,25 @@ int main(int argc, char *argv[]) |
119 | 121 | sigaction(SIGTERM, &sa, NULL); |
120 | 122 | sa.sa_handler = hup_handler; |
121 | 123 |
|
| 124 | + openlog("audit-cef", LOG_CONS, config.facility); |
| 125 | + |
122 | 126 | if (gethostname(nodename, 63)) { |
123 | | - snprintf(nodename, 9, "localhost"); |
| 127 | + snprintf(nodename, 10, "localhost"); |
124 | 128 | } |
125 | 129 | nodename[64] = '\0'; |
126 | 130 | ht = gethostbyname(nodename); |
127 | | - hostname = strdup(ht->h_name); |
| 131 | + if (ht == NULL) { |
| 132 | + hostname = strpdup("localhost"); |
| 133 | + syslog(LOG_ALERT, |
| 134 | + "gethostbyname could not find machine hostname, please fix this. Using %s as fallback. Error: %s", |
| 135 | + hostname, hstrerror(h_errno)); |
| 136 | + } else { |
| 137 | + hostname = strdup(ht->h_name); |
| 138 | + } |
128 | 139 |
|
129 | 140 | if (load_config(&config, CONFIG_FILE)) |
130 | 141 | return 1; |
131 | 142 |
|
132 | | - openlog("audit-cef", LOG_CONS, config.facility); |
133 | | - |
134 | 143 | au = auparse_init(AUSOURCE_FEED, 0); |
135 | 144 | if (au == NULL) { |
136 | 145 | syslog(LOG_ERR, "could not initialize auparse"); |
|
0 commit comments