#include "system/time.h"
#include "system/filesys.h"
#include "system/syslog.h"
+#include "system/dir.h"
#include "lib/util/time_basic.h"
#include "lib/util/sys_rw.h"
return 0;
}
+static bool file_log_validate(const char *option)
+{
+ char *t, *dir;
+ struct stat st;
+ int ret;
+
+ if (option == NULL || strcmp(option, "-") == 0) {
+ return true;
+ }
+
+ t = strdup(option);
+ if (t == NULL) {
+ return false;
+ }
+
+ dir = dirname(t);
+
+ ret = stat(dir, &st);
+ if (ret != 0) {
+ free(t);
+ return false;
+ }
+
+ if (! S_ISDIR(st.st_mode)) {
+ free(t);
+ return false;
+ }
+
+ return true;
+}
+
static int file_log_setup(TALLOC_CTX *mem_ctx, const char *option,
const char *app_name)
{
return 0;
}
+static bool syslog_log_validate(const char *option)
+{
+ if (option == NULL) {
+ return true;
+#ifdef _PATH_LOG
+ } else if (strcmp(option, "nonblocking") == 0) {
+ return true;
+#endif
+ } else if (strcmp(option, "udp") == 0) {
+ return true;
+ } else if (strcmp(option, "udp-rfc5424") == 0) {
+ return true;
+ }
+
+ return false;
+}
+
static int syslog_log_setup(TALLOC_CTX *mem_ctx, const char *option,
const char *app_name)
{
struct log_backend {
const char *name;
+ bool (*validate)(const char *option);
int (*setup)(TALLOC_CTX *mem_ctx,
const char *option,
const char *app_name);
static struct log_backend log_backend[] = {
{
.name = "file",
+ .validate = file_log_validate,
.setup = file_log_setup,
},
{
.name = "syslog",
+ .validate = syslog_log_validate,
.setup = syslog_log_setup,
},
};
return 0;
}
+bool logging_validate(const char *logging)
+{
+ TALLOC_CTX *tmp_ctx;
+ struct log_backend *backend;
+ char *option;
+ int ret;
+ bool status;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return false;
+ }
+
+ ret = log_backend_parse(tmp_ctx, logging, &backend, &option);
+ if (ret != 0) {
+ talloc_free(tmp_ctx);
+ return false;
+ }
+
+ status = backend->validate(option);
+ talloc_free(tmp_ctx);
+ return status;
+}
+
/* Initialise logging */
int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
const char *debug_level, const char *app_name)
const char *debug_level_to_string(int log_level);
int debug_level_from_string(const char *log_string);
+bool logging_validate(const char *logging);
int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
const char *debuglevel, const char *app_name);