forked from Telodendria/Telodendria
Remove chroot option; log into the data directory automatically.
This commit is contained in:
parent
5d9b0df0bf
commit
1353fa6429
6 changed files with 79 additions and 48 deletions
1
TODO.txt
1
TODO.txt
|
@ -56,6 +56,7 @@ Phase 2: Building a foundation
|
||||||
[ ] Remove "chroot" option, just chroot into the data dir, and make the log
|
[ ] Remove "chroot" option, just chroot into the data dir, and make the log
|
||||||
file live there as well.
|
file live there as well.
|
||||||
[ ] Allow logging to the syslog
|
[ ] Allow logging to the syslog
|
||||||
|
[ ] Fix bug where the socket stays open after quit.
|
||||||
|
|
||||||
Phase 3: Welcome to Matrix
|
Phase 3: Welcome to Matrix
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,8 @@ data-dir "/var/telodendria";
|
||||||
federation "true";
|
federation "true";
|
||||||
registration "false";
|
registration "false";
|
||||||
log "file" {
|
log "file" {
|
||||||
level "message";
|
level "warning";
|
||||||
timestampFormat "default";
|
timestampFormat "default";
|
||||||
color "true";
|
|
||||||
};
|
};
|
||||||
threads "4";
|
threads "4";
|
||||||
max-connections "32";
|
max-connections "32";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.Dd $Mdocdate: September 30 2022 $
|
.Dd $Mdocdate: October 11 2022 $
|
||||||
.Dt TELODENDRIA.CONF 5
|
.Dt TELODENDRIA.CONF 5
|
||||||
.Os Telodendria Project
|
.Os Telodendria Project
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -78,18 +78,6 @@ follows the same rules as
|
||||||
.Pp
|
.Pp
|
||||||
This directive is optional. If it is not specified, it is automatically
|
This directive is optional. If it is not specified, it is automatically
|
||||||
set to be the same as the base URL.
|
set to be the same as the base URL.
|
||||||
.It Ic chroot Ar directory
|
|
||||||
Change the root directory to the specified directory as soon as possible.
|
|
||||||
Note that all other paths and files specified in
|
|
||||||
.Nm
|
|
||||||
must be accessible relative from this directory. This directive only
|
|
||||||
takes effect if Telodendria is running as root. If it isn't, then a
|
|
||||||
warning is printed to the log, and no
|
|
||||||
.Xr chroot 2
|
|
||||||
call is made. In that case, Telodendria will still change into the
|
|
||||||
specified directory, so that the other paths referenced can be made
|
|
||||||
relative to this one. This directive is required. It is expected that
|
|
||||||
the homeserver data and logs will be stored in a subdirectory of this one.
|
|
||||||
.It Ic id Ar uid Ar gid
|
.It Ic id Ar uid Ar gid
|
||||||
The effective UNIX user and group to drop to after binding to the socket
|
The effective UNIX user and group to drop to after binding to the socket
|
||||||
and changing the filesystem root. This only works if Telodendria is
|
and changing the filesystem root. This only works if Telodendria is
|
||||||
|
@ -104,13 +92,15 @@ The data directory into which Telodendria will write all user and event
|
||||||
information. Telodendria doesn't use a database like other Matrix homeserver
|
information. Telodendria doesn't use a database like other Matrix homeserver
|
||||||
implementations; it uses a flat-file directory structure, similar to how an
|
implementations; it uses a flat-file directory structure, similar to how an
|
||||||
SMTP server uses Maildirs to deliver email. This directive is required.
|
SMTP server uses Maildirs to deliver email. This directive is required.
|
||||||
|
.Pp
|
||||||
|
Telodendria will
|
||||||
|
.Xr chroot 2
|
||||||
|
into this directory as soon as possible for security reasons. If the
|
||||||
|
.Ic log
|
||||||
|
directive is configured to write to a file, the log file will be written
|
||||||
|
in the data directory.
|
||||||
.Ar directory
|
.Ar directory
|
||||||
should be a path relative to the
|
should be an absolute path, under which all Telodendria data will live.
|
||||||
.Ic chroot
|
|
||||||
directory. Don't depend on the
|
|
||||||
.Ic chroot
|
|
||||||
option working, because there may be legitimate cases when Telodendria will
|
|
||||||
not be started as root, thus causing the chroot to fail.
|
|
||||||
.It Ic federation Ar true|false
|
.It Ic federation Ar true|false
|
||||||
Whether to enable federation with other Matrix homeservers or not. Matrix is
|
Whether to enable federation with other Matrix homeservers or not. Matrix is
|
||||||
by its very nature a federated protocol, but if you just want to run your
|
by its very nature a federated protocol, but if you just want to run your
|
||||||
|
@ -133,10 +123,10 @@ to run their own homeserver, you can aset this to
|
||||||
which will allow anyone to create an account. Telodendria should be capable of handling
|
which will allow anyone to create an account. Telodendria should be capable of handling
|
||||||
a large amount of users without difficulty or security issues. This directive is
|
a large amount of users without difficulty or security issues. This directive is
|
||||||
required.
|
required.
|
||||||
.It Ic log Ar file|stdout
|
.It Ic log Ar stdout|file
|
||||||
The log configuration. Telodendria uses its own logging facility, which can output to
|
The log configuration. Telodendria uses its own logging facility, which can output
|
||||||
either standard output or a file. A number of child directives can be added to this
|
logs to standard output or a file. A number of child directives can
|
||||||
directive to customize the log output:
|
be added to this directive to customize the log output:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Ic level Ar error|warning|task|message|debug
|
.It Ic level Ar error|warning|task|message|debug
|
||||||
The level of messages to log at. Each level shows all the levels above it. For
|
The level of messages to log at. Each level shows all the levels above it. For
|
||||||
|
@ -156,11 +146,19 @@ altogether, you can do so via this option. Acceptable values are
|
||||||
.Ar default ,
|
.Ar default ,
|
||||||
or a formatter string as described by your system's
|
or a formatter string as described by your system's
|
||||||
.Xr strftime 3 .
|
.Xr strftime 3 .
|
||||||
|
In the future, logging to the syslog may also be an option. In that case, this
|
||||||
|
option only applies if
|
||||||
|
.Ic log
|
||||||
|
is "stdout" or "file".
|
||||||
.It Ic color Ar true|false
|
.It Ic color Ar true|false
|
||||||
Whether or not to enable colored output on TTYs. Note that ANSI color sequences
|
Whether or not to enable colored output on TTYs. Note that ANSI color sequences
|
||||||
will not be written to a log file, only a real terminal, so this option only
|
will not be written to a log file, only a real terminal, so this option only
|
||||||
applies if the log is being written to a standard output which is connected to
|
applies if the log is being written to a standard output which is connected to
|
||||||
a terminal.
|
a terminal.
|
||||||
|
.Pp
|
||||||
|
This option only applies if
|
||||||
|
.Ic log
|
||||||
|
is "stdout".
|
||||||
.El
|
.El
|
||||||
.It Ic threads Ar count
|
.It Ic threads Ar count
|
||||||
How many worker threads to spin up to handle requests. This should generally be
|
How many worker threads to spin up to handle requests. This should generally be
|
||||||
|
@ -176,7 +174,7 @@ The default
|
||||||
.Xr telodendria 8
|
.Xr telodendria 8
|
||||||
configuration file.
|
configuration file.
|
||||||
.It Pa /var/telodendria
|
.It Pa /var/telodendria
|
||||||
The recommended chroot directory.
|
The recommended data directory.
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Please consult the default
|
Please consult the default
|
||||||
|
|
|
@ -223,28 +223,60 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
LogConfigTimeStampFormatSet(lc, tConfig->logTimestamp);
|
LogConfigTimeStampFormatSet(lc, tConfig->logTimestamp);
|
||||||
|
|
||||||
/* Color is enabled by default in the logger. */
|
if (tConfig->flags & TELODENDRIA_LOG_COLOR)
|
||||||
if (!(tConfig->flags & TELODENDRIA_LOG_COLOR))
|
{
|
||||||
|
LogConfigFlagSet(lc, LOG_FLAG_COLOR);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
LogConfigFlagClear(lc, LOG_FLAG_COLOR);
|
LogConfigFlagClear(lc, LOG_FLAG_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogConfigLevelSet(lc, flags & ARG_VERBOSE ? LOG_DEBUG : tConfig->logLevel);
|
LogConfigLevelSet(lc, flags & ARG_VERBOSE ? LOG_DEBUG : tConfig->logLevel);
|
||||||
|
|
||||||
if (tConfig->logOut)
|
if (chdir(tConfig->dataDir) != 0)
|
||||||
{
|
{
|
||||||
FILE *logFile = fopen(tConfig->logOut, "w");
|
Log(lc, LOG_ERROR, "Unable to change into data directory: %s.", strerror(errno));
|
||||||
|
exit = EXIT_FAILURE;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(lc, LOG_DEBUG, "Changed working directory to: %s", tConfig->dataDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (tConfig->flags & TELODENDRIA_LOG_FILE)
|
||||||
|
{
|
||||||
|
FILE *logFile = fopen("telodendria.log", "a");
|
||||||
|
|
||||||
if (!logFile)
|
if (!logFile)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to open log file '%s' for writing.", tConfig->logOut);
|
Log(lc, LOG_ERROR, "Unable to open log file for appending.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(lc, LOG_MESSAGE, "Logging to '%s'. Check there for all future messages.", tConfig->logOut);
|
Log(lc, LOG_MESSAGE, "Logging to the log file. Check there for all future messages.");
|
||||||
LogConfigOutputSet(lc, logFile);
|
LogConfigOutputSet(lc, logFile);
|
||||||
}
|
}
|
||||||
|
else if (tConfig->flags & TELODENDRIA_LOG_STDOUT)
|
||||||
|
{
|
||||||
|
Log(lc, LOG_DEBUG, "Already logging to standard output.");
|
||||||
|
}
|
||||||
|
else if (tConfig->flags & TELODENDRIA_LOG_SYSLOG)
|
||||||
|
{
|
||||||
|
Log(lc, LOG_ERROR, "Logging to the syslog is not yet supported.");
|
||||||
|
exit = EXIT_FAILURE;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(lc, LOG_ERROR, "Unknown logging method in flags: '%d'", tConfig->flags);
|
||||||
|
Log(lc, LOG_ERROR, "This is a programmer error; please report it.");
|
||||||
|
exit = EXIT_FAILURE;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
Log(lc, LOG_DEBUG, "Configuration:");
|
Log(lc, LOG_DEBUG, "Configuration:");
|
||||||
LogConfigIndent(lc);
|
LogConfigIndent(lc);
|
||||||
|
@ -258,17 +290,6 @@ main(int argc, char **argv)
|
||||||
Log(lc, LOG_DEBUG, "Flags: %x", tConfig->flags);
|
Log(lc, LOG_DEBUG, "Flags: %x", tConfig->flags);
|
||||||
LogConfigUnindent(lc);
|
LogConfigUnindent(lc);
|
||||||
|
|
||||||
if (chdir(tConfig->dataDir) != 0)
|
|
||||||
{
|
|
||||||
Log(lc, LOG_ERROR, "Unable to change into data directory: %s.", strerror(errno));
|
|
||||||
exit = EXIT_FAILURE;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log(lc, LOG_DEBUG, "Changed working directory to: %s", tConfig->dataDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log(lc, LOG_DEBUG, "Running as uid:gid: %d:%d.", getuid(), getgid());
|
Log(lc, LOG_DEBUG, "Running as uid:gid: %d:%d.", getuid(), getgid());
|
||||||
|
|
||||||
userInfo = getpwnam(tConfig->uid);
|
userInfo = getpwnam(tConfig->uid);
|
||||||
|
|
|
@ -354,13 +354,23 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the actual log output file last */
|
/* Set the actual log output file last */
|
||||||
if (strcmp(ArrayGet(value, 0), "stdout") != 0)
|
if (strcmp(ArrayGet(value, 0), "stdout") == 0)
|
||||||
{
|
{
|
||||||
tConfig->logOut = UtilStringDuplicate(ArrayGet(value, 0));
|
tConfig->flags |= TELODENDRIA_LOG_STDOUT;
|
||||||
|
}
|
||||||
|
else if (strcmp(ArrayGet(value, 0), "file") == 0)
|
||||||
|
{
|
||||||
|
tConfig->flags |= TELODENDRIA_LOG_FILE;
|
||||||
|
}
|
||||||
|
else if (strcmp(ArrayGet(value, 0), "syslog") == 0)
|
||||||
|
{
|
||||||
|
tConfig->flags |= TELODENDRIA_LOG_SYSLOG;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tConfig->logOut = NULL;
|
Log(lc, LOG_ERROR, "Unknown log value '%s', expected 'stdout', 'file', or 'syslog'.",
|
||||||
|
ArrayGet(value, 0));
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tConfig;
|
return tConfig;
|
||||||
|
|
|
@ -38,7 +38,10 @@ typedef enum TelodendriaConfigFlag
|
||||||
{
|
{
|
||||||
TELODENDRIA_FEDERATION = (1 << 0),
|
TELODENDRIA_FEDERATION = (1 << 0),
|
||||||
TELODENDRIA_REGISTRATION = (1 << 1),
|
TELODENDRIA_REGISTRATION = (1 << 1),
|
||||||
TELODENDRIA_LOG_COLOR = (1 << 2)
|
TELODENDRIA_LOG_COLOR = (1 << 2),
|
||||||
|
TELODENDRIA_LOG_FILE = (1 << 3),
|
||||||
|
TELODENDRIA_LOG_STDOUT = (1 << 4),
|
||||||
|
TELODENDRIA_LOG_SYSLOG = (1 << 5)
|
||||||
} TelodendriaConfigFlag;
|
} TelodendriaConfigFlag;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -65,7 +68,6 @@ typedef struct TelodendriaConfig
|
||||||
unsigned int threads;
|
unsigned int threads;
|
||||||
unsigned int maxConnections;
|
unsigned int maxConnections;
|
||||||
|
|
||||||
char *logOut;
|
|
||||||
char *logTimestamp;
|
char *logTimestamp;
|
||||||
LogLevel logLevel;
|
LogLevel logLevel;
|
||||||
} TelodendriaConfig;
|
} TelodendriaConfig;
|
||||||
|
|
Loading…
Reference in a new issue