2013-11-21 01:42:46 +00:00
|
|
|
/*
|
|
|
|
Serval DNA configuration stand-alone configuration check utility
|
|
|
|
Copyright 2013 Serval Project, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-11-20 07:39:19 +00:00
|
|
|
#include <stdlib.h>
|
2012-11-29 06:14:06 +00:00
|
|
|
#include <stdarg.h>
|
2012-11-29 05:37:34 +00:00
|
|
|
#include <stdio.h>
|
2012-11-20 07:39:19 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2013-11-21 01:42:46 +00:00
|
|
|
#include <poll.h>
|
2012-11-29 05:37:34 +00:00
|
|
|
#include <sys/stat.h>
|
2012-11-20 07:39:19 +00:00
|
|
|
|
|
|
|
#include "str.h"
|
2012-11-29 06:14:06 +00:00
|
|
|
#include "log.h"
|
2013-10-06 19:24:46 +00:00
|
|
|
#include "conf.h"
|
2012-11-20 07:39:19 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < argc; ++i) {
|
|
|
|
int fd = open(argv[i], O_RDONLY);
|
|
|
|
if (fd == -1) {
|
|
|
|
perror("open");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
struct stat st;
|
|
|
|
fstat(fd, &st);
|
|
|
|
char *buf = malloc(st.st_size);
|
|
|
|
if (!buf) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (read(fd, buf, st.st_size) != st.st_size) {
|
|
|
|
perror("read");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-11-30 02:02:30 +00:00
|
|
|
struct cf_om_node *root = NULL;
|
2013-11-21 01:42:46 +00:00
|
|
|
int ret = cf_om_parse(argv[i], buf, st.st_size, &root);
|
2012-11-20 07:39:19 +00:00
|
|
|
close(fd);
|
2012-11-30 02:02:30 +00:00
|
|
|
DEBUGF("ret = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), ret)));
|
2012-11-29 04:03:32 +00:00
|
|
|
//cf_dump_node(root, 0);
|
2012-11-20 07:39:19 +00:00
|
|
|
struct config_main config;
|
2012-11-22 07:50:13 +00:00
|
|
|
memset(&config, 0, sizeof config);
|
2012-11-29 04:03:32 +00:00
|
|
|
cf_dfl_config_main(&config);
|
2012-11-30 02:02:30 +00:00
|
|
|
int result = root ? cf_opt_config_main(&config, root) : CFEMPTY;
|
2013-11-21 01:42:46 +00:00
|
|
|
cf_om_free_node(&root);
|
2012-11-20 07:39:19 +00:00
|
|
|
free(buf);
|
2012-11-26 05:42:46 +00:00
|
|
|
DEBUGF("result = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), result)));
|
2013-11-21 01:42:46 +00:00
|
|
|
DEBUGF("config.log.file.path = %s", alloca_str_toprint(config.log.file.path));
|
|
|
|
DEBUGF("config.log.file.show_pid = %d", config.log.file.show_pid);
|
|
|
|
DEBUGF("config.log.file.show_time = %d", config.log.file.show_time);
|
2012-11-29 04:03:32 +00:00
|
|
|
DEBUGF("config.server.chdir = %s", alloca_str_toprint(config.server.chdir));
|
2013-11-21 01:42:46 +00:00
|
|
|
DEBUGF("config.debug.verbose = %d", config.debug.verbose);
|
2013-10-09 08:24:21 +00:00
|
|
|
DEBUGF("config.directory.service = %s", alloca_tohex_sid_t(config.directory.service));
|
2012-11-29 02:51:12 +00:00
|
|
|
DEBUGF("config.rhizome.api.addfile.allow_host = %s", inet_ntoa(config.rhizome.api.addfile.allow_host));
|
2013-11-21 01:42:46 +00:00
|
|
|
unsigned j;
|
2012-11-28 22:54:02 +00:00
|
|
|
for (j = 0; j < config.mdp.iftype.ac; ++j) {
|
|
|
|
DEBUGF("config.mdp.iftype.%u", config.mdp.iftype.av[j].key);
|
|
|
|
DEBUGF(" .tick_ms = %u", config.mdp.iftype.av[j].value.tick_ms);
|
|
|
|
}
|
2012-11-26 07:03:54 +00:00
|
|
|
for (j = 0; j < config.dna.helper.argv.ac; ++j) {
|
2012-11-28 22:54:02 +00:00
|
|
|
DEBUGF("config.dna.helper.argv.%u=%s", config.dna.helper.argv.av[j].key, config.dna.helper.argv.av[j].value);
|
2012-11-26 07:03:54 +00:00
|
|
|
}
|
2012-11-22 23:41:07 +00:00
|
|
|
for (j = 0; j < config.rhizome.direct.peer.ac; ++j) {
|
2012-11-28 22:54:02 +00:00
|
|
|
DEBUGF("config.rhizome.direct.peer.%s", config.rhizome.direct.peer.av[j].key);
|
2012-11-29 04:03:32 +00:00
|
|
|
DEBUGF(" .protocol = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.protocol));
|
|
|
|
DEBUGF(" .host = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.host));
|
2012-11-22 23:41:07 +00:00
|
|
|
DEBUGF(" .port = %u", config.rhizome.direct.peer.av[j].value.port);
|
2012-11-21 07:39:05 +00:00
|
|
|
}
|
2012-11-23 17:08:10 +00:00
|
|
|
for (j = 0; j < config.interfaces.ac; ++j) {
|
2013-11-21 01:42:46 +00:00
|
|
|
DEBUGF("config.interfaces.%u", config.interfaces.av[j].key);
|
2012-11-23 17:08:10 +00:00
|
|
|
DEBUGF(" .exclude = %d", config.interfaces.av[j].value.exclude);
|
|
|
|
DEBUGF(" .match = [");
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < config.interfaces.av[j].value.match.patc; ++k)
|
2012-11-29 04:03:32 +00:00
|
|
|
DEBUGF(" %s", alloca_str_toprint(config.interfaces.av[j].value.match.patv[k]));
|
2012-11-23 17:08:10 +00:00
|
|
|
DEBUGF(" ]");
|
|
|
|
DEBUGF(" .type = %d", config.interfaces.av[j].value.type);
|
|
|
|
DEBUGF(" .port = %u", config.interfaces.av[j].value.port);
|
2013-11-21 01:42:46 +00:00
|
|
|
DEBUGF(" .drop_broadcasts = %llu", (unsigned long long) config.interfaces.av[j].value.drop_broadcasts);
|
|
|
|
DEBUGF(" .drop_unicasts = %llu", (unsigned long long) config.interfaces.av[j].value.drop_unicasts);
|
|
|
|
DEBUGF(" .drop_packets = %llu", (unsigned long long) config.interfaces.av[j].value.drop_packets);
|
2012-11-23 17:08:10 +00:00
|
|
|
}
|
2012-11-28 19:58:28 +00:00
|
|
|
for (j = 0; j < config.hosts.ac; ++j) {
|
2012-11-28 22:54:02 +00:00
|
|
|
char sidhex[SID_STRLEN + 1];
|
2013-10-09 08:24:21 +00:00
|
|
|
tohex(sidhex, SID_STRLEN, config.hosts.av[j].key.binary);
|
2012-11-28 22:54:02 +00:00
|
|
|
DEBUGF("config.hosts.%s", sidhex);
|
2012-11-29 04:03:32 +00:00
|
|
|
DEBUGF(" .interface = %s", alloca_str_toprint(config.hosts.av[j].value.interface));
|
2012-11-28 19:58:28 +00:00
|
|
|
DEBUGF(" .address = %s", inet_ntoa(config.hosts.av[j].value.address));
|
|
|
|
DEBUGF(" .port = %u", config.hosts.av[j].value.port);
|
|
|
|
}
|
2012-11-20 07:39:19 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-11-29 05:37:34 +00:00
|
|
|
|
2012-11-29 06:14:06 +00:00
|
|
|
const struct __sourceloc __whence = __NOWHERE__;
|
|
|
|
|
|
|
|
static const char *_trimbuildpath(const char *path)
|
|
|
|
{
|
|
|
|
/* Remove common path prefix */
|
|
|
|
int lastsep = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; __FILE__[i] && path[i]; ++i) {
|
|
|
|
if (i && path[i - 1] == '/')
|
|
|
|
lastsep = i;
|
|
|
|
if (__FILE__[i] != path[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return &path[lastsep];
|
|
|
|
}
|
|
|
|
|
|
|
|
void logMessage(int level, struct __sourceloc whence, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
const char *levelstr = "UNKWN:";
|
|
|
|
switch (level) {
|
|
|
|
case LOG_LEVEL_FATAL: levelstr = "FATAL:"; break;
|
|
|
|
case LOG_LEVEL_ERROR: levelstr = "ERROR:"; break;
|
|
|
|
case LOG_LEVEL_INFO: levelstr = "INFO:"; break;
|
|
|
|
case LOG_LEVEL_WARN: levelstr = "WARN:"; break;
|
|
|
|
case LOG_LEVEL_DEBUG: levelstr = "DEBUG:"; break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s ", levelstr);
|
|
|
|
if (whence.file) {
|
|
|
|
fprintf(stderr, "%s", _trimbuildpath(whence.file));
|
|
|
|
if (whence.line)
|
|
|
|
fprintf(stderr, ":%u", whence.line);
|
|
|
|
if (whence.function)
|
|
|
|
fprintf(stderr, ":%s()", whence.function);
|
|
|
|
fputc(' ', stderr);
|
|
|
|
} else if (whence.function) {
|
|
|
|
fprintf(stderr, "%s() ", whence.function);
|
|
|
|
}
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|