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";
|
||||
chroot ".";
|
||||
chroot "./chroot";
|
||||
id "jordan";
|
||||
data-dir "./data";
|
||||
federation "true";
|
||||
|
|
|
@ -107,7 +107,7 @@ main(int argc, char **argv)
|
|||
TelodendriaPrintHeader(lc);
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ main(int argc, char **argv)
|
|||
|
||||
if (strcmp(configArg, "-") == 0)
|
||||
{
|
||||
configFile = stdout;
|
||||
configFile = stdin;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -239,7 +239,7 @@ main(int argc, char **argv)
|
|||
|
||||
Log(lc, LOG_DEBUG, "Configuration:");
|
||||
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, "Chroot: %s", tConfig->chroot);
|
||||
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.");
|
||||
tConfig->listenHost = UtilStringDuplicate("localhost");
|
||||
tConfig->listenPort = UtilStringDuplicate("8008");
|
||||
tConfig->listenPort = 8008;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_NO_CHILDREN("listen");
|
||||
ASSERT_VALUES("listen", 2);
|
||||
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");
|
||||
|
@ -311,7 +317,6 @@ TelodendriaConfigFree(TelodendriaConfig * tConfig)
|
|||
}
|
||||
|
||||
free(tConfig->listenHost);
|
||||
free(tConfig->listenPort);
|
||||
free(tConfig->serverName);
|
||||
free(tConfig->chroot);
|
||||
free(tConfig->uid);
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef enum TelodendriaConfigFlag
|
|||
typedef struct TelodendriaConfig
|
||||
{
|
||||
char *listenHost;
|
||||
char *listenPort;
|
||||
unsigned short listenPort;
|
||||
char *serverName;
|
||||
char *chroot;
|
||||
char *uid;
|
||||
|
|
Loading…
Reference in a new issue