|
@@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
27
|
27
|
|
28
|
28
|
#include <stdint.h>
|
29
|
29
|
#include <stdlib.h>
|
|
30
|
+#include <ctype.h>
|
30
|
31
|
#include <byteswap.h>
|
31
|
32
|
#include <ipxe/xfer.h>
|
32
|
33
|
#include <ipxe/open.h>
|
|
@@ -91,15 +92,15 @@ static char *syslog_domain;
|
91
|
92
|
*/
|
92
|
93
|
int syslog_send ( struct interface *xfer, unsigned int severity,
|
93
|
94
|
const char *message, const char *terminator ) {
|
|
95
|
+ const char *hostname = ( syslog_hostname ? syslog_hostname : "" );
|
|
96
|
+ const char *domain = ( ( hostname[0] && syslog_domain ) ?
|
|
97
|
+ syslog_domain : "" );
|
94
|
98
|
|
95
|
99
|
return xfer_printf ( xfer, "<%d>%s%s%s%sipxe: %s%s",
|
96
|
100
|
SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
|
97
|
|
- severity ),
|
98
|
|
- ( syslog_hostname ? syslog_hostname : "" ),
|
99
|
|
- ( syslog_domain ? "." : "" ),
|
100
|
|
- ( syslog_domain ? syslog_domain : "" ),
|
101
|
|
- ( ( syslog_hostname || syslog_domain ) ? " " : ""),
|
102
|
|
- message, terminator );
|
|
101
|
+ severity ), hostname,
|
|
102
|
+ ( domain[0] ? "." : "" ), domain,
|
|
103
|
+ ( hostname[0] ? " " : "" ), message, terminator );
|
103
|
104
|
}
|
104
|
105
|
|
105
|
106
|
/******************************************************************************
|
|
@@ -211,6 +212,28 @@ const struct setting syslog6_setting __setting ( SETTING_MISC, syslog6 ) = {
|
211
|
212
|
.scope = &ipv6_scope,
|
212
|
213
|
};
|
213
|
214
|
|
|
215
|
+/**
|
|
216
|
+ * Strip invalid characters from host/domain name
|
|
217
|
+ *
|
|
218
|
+ * @v name Name to strip
|
|
219
|
+ */
|
|
220
|
+static void syslog_fix_name ( char *name ) {
|
|
221
|
+ char *fixed = name;
|
|
222
|
+ int c;
|
|
223
|
+
|
|
224
|
+ /* Do nothing if name does not exist */
|
|
225
|
+ if ( ! name )
|
|
226
|
+ return;
|
|
227
|
+
|
|
228
|
+ /* Strip any non-printable or whitespace characters from the name */
|
|
229
|
+ do {
|
|
230
|
+ c = *(name++);
|
|
231
|
+ *fixed = c;
|
|
232
|
+ if ( isprint ( c ) && ! isspace ( c ) )
|
|
233
|
+ fixed++;
|
|
234
|
+ } while ( c );
|
|
235
|
+}
|
|
236
|
+
|
214
|
237
|
/**
|
215
|
238
|
* Apply syslog settings
|
216
|
239
|
*
|
|
@@ -223,8 +246,10 @@ static int apply_syslog_settings ( void ) {
|
223
|
246
|
/* Fetch hostname and domain name */
|
224
|
247
|
free ( syslog_hostname );
|
225
|
248
|
fetch_string_setting_copy ( NULL, &hostname_setting, &syslog_hostname );
|
|
249
|
+ syslog_fix_name ( syslog_hostname );
|
226
|
250
|
free ( syslog_domain );
|
227
|
251
|
fetch_string_setting_copy ( NULL, &domain_setting, &syslog_domain );
|
|
252
|
+ syslog_fix_name ( syslog_domain );
|
228
|
253
|
|
229
|
254
|
/* Fetch log server */
|
230
|
255
|
syslog_console.disabled = CONSOLE_DISABLED;
|