forked from Telodendria/Telodendria
Make TelodendriaConfigParse() actually validate the listenPort.
I want to already have a valid port number by the time we need to bind to it.
This commit is contained in:
parent
4304a28302
commit
9cf2266ece
4 changed files with 13 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
server-name "localhost";
|
server-name "localhost";
|
||||||
chroot ".";
|
chroot "./chroot";
|
||||||
id "jordan";
|
id "jordan";
|
||||||
data-dir "./data";
|
data-dir "./data";
|
||||||
federation "true";
|
federation "true";
|
||||||
|
|
|
@ -107,7 +107,7 @@ main(int argc, char **argv)
|
||||||
TelodendriaPrintHeader(lc);
|
TelodendriaPrintHeader(lc);
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
Log(lc, LOG_DEBUG, "Attempting pledge() and unveil()...");
|
Log(lc, LOG_DEBUG, "Attempting pledge...");
|
||||||
|
|
||||||
if (pledge("stdio rpath wpath cpath inet dns getpw id unveil", NULL) != 0)
|
if (pledge("stdio rpath wpath cpath inet dns getpw id unveil", NULL) != 0)
|
||||||
{
|
{
|
||||||
|
@ -155,7 +155,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (strcmp(configArg, "-") == 0)
|
if (strcmp(configArg, "-") == 0)
|
||||||
{
|
{
|
||||||
configFile = stdout;
|
configFile = stdin;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -239,7 +239,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
Log(lc, LOG_DEBUG, "Configuration:");
|
Log(lc, LOG_DEBUG, "Configuration:");
|
||||||
LogConfigIndent(lc);
|
LogConfigIndent(lc);
|
||||||
Log(lc, LOG_DEBUG, "Listen On: %s:%s", tConfig->listenHost, tConfig->listenPort);
|
Log(lc, LOG_DEBUG, "Listen On: %s:%d", tConfig->listenHost, tConfig->listenPort);
|
||||||
Log(lc, LOG_DEBUG, "Server Name: %s", tConfig->serverName);
|
Log(lc, LOG_DEBUG, "Server Name: %s", tConfig->serverName);
|
||||||
Log(lc, LOG_DEBUG, "Chroot: %s", tConfig->chroot);
|
Log(lc, LOG_DEBUG, "Chroot: %s", tConfig->chroot);
|
||||||
Log(lc, LOG_DEBUG, "Run As: %s:%s", tConfig->uid, tConfig->gid);
|
Log(lc, LOG_DEBUG, "Run As: %s:%s", tConfig->uid, tConfig->gid);
|
||||||
|
|
|
@ -97,14 +97,20 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_WARNING, "No 'listen' directive specified; using defaults, which may change.");
|
Log(lc, LOG_WARNING, "No 'listen' directive specified; using defaults, which may change.");
|
||||||
tConfig->listenHost = UtilStringDuplicate("localhost");
|
tConfig->listenHost = UtilStringDuplicate("localhost");
|
||||||
tConfig->listenPort = UtilStringDuplicate("8008");
|
tConfig->listenPort = 8008;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ASSERT_NO_CHILDREN("listen");
|
ASSERT_NO_CHILDREN("listen");
|
||||||
ASSERT_VALUES("listen", 2);
|
ASSERT_VALUES("listen", 2);
|
||||||
COPY_VALUE(tConfig->listenHost, 0);
|
COPY_VALUE(tConfig->listenHost, 0);
|
||||||
COPY_VALUE(tConfig->listenPort, 1);
|
|
||||||
|
tConfig->listenPort = (unsigned short) atoi(ArrayGet(value, 1));
|
||||||
|
if (!tConfig->listenPort)
|
||||||
|
{
|
||||||
|
Log(lc, LOG_ERROR, "Expected numeric value for listen port, got '%s'.", ArrayGet(value, 1));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_DIRECTIVE("server-name");
|
GET_DIRECTIVE("server-name");
|
||||||
|
@ -311,7 +317,6 @@ TelodendriaConfigFree(TelodendriaConfig * tConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tConfig->listenHost);
|
free(tConfig->listenHost);
|
||||||
free(tConfig->listenPort);
|
|
||||||
free(tConfig->serverName);
|
free(tConfig->serverName);
|
||||||
free(tConfig->chroot);
|
free(tConfig->chroot);
|
||||||
free(tConfig->uid);
|
free(tConfig->uid);
|
||||||
|
|
|
@ -53,7 +53,7 @@ typedef enum TelodendriaConfigFlag
|
||||||
typedef struct TelodendriaConfig
|
typedef struct TelodendriaConfig
|
||||||
{
|
{
|
||||||
char *listenHost;
|
char *listenHost;
|
||||||
char *listenPort;
|
unsigned short listenPort;
|
||||||
char *serverName;
|
char *serverName;
|
||||||
char *chroot;
|
char *chroot;
|
||||||
char *uid;
|
char *uid;
|
||||||
|
|
Loading…
Reference in a new issue