Commit 9e856930 authored by Jan Včelák's avatar Jan Včelák 🚀

keymgr: separate KASP location resolution for legacy

parent 2e3608b0
......@@ -82,20 +82,25 @@ Print the program version.
.sp
The location of the KASP database is determined as follows:
.INDENT 0.0
.IP \(bu 2
The path read from configuration database specified with \fB\-\-confdb\fP\&.
.IP \(bu 2
The path read from configuration file specified with \fB\-\-config\fP\&.
.IP \(bu 2
The path read from the default configuration database in \fB/var/lib/knot/confdb\fP\&.
.IP \(bu 2
The path read from the default configuration file in \fB/etc/knot.conf\fP\&.
.IP \(bu 2
.IP 1. 3
The path specified with \fB\-\-dir\fP\&.
.IP 2. 3
The path read from the server configuration specified with \fB\-\-confdb\fP or
\fB\-\-config\fP\&.
.IP 3. 3
The path read from the server default configuration database.
.IP 4. 3
The path read from the server default configuration file.
.UNINDENT
.sp
In legacy mode, the path is determined as follows:
.INDENT 0.0
.IP 1. 3
The path specified with \fB\-\-dir\fP\&.
.IP \(bu 2
.IP 2. 3
The path specified in the \fBKEYMGR_DIR\fP environment variable.
.IP \(bu 2
The current path if the \fB\-\-legacy\fP option is set.
.IP 3. 3
The current working dir.
.UNINDENT
.SS Main commands
.INDENT 0.0
......
......@@ -60,13 +60,17 @@ KASP database location
The location of the KASP database is determined as follows:
- The path read from configuration database specified with **--confdb**.
- The path read from configuration file specified with **--config**.
- The path read from the default configuration database in :file:`/var/lib/knot/confdb`.
- The path read from the default configuration file in :file:`/etc/knot.conf`.
- The path specified with **--dir**.
- The path specified in the ``KEYMGR_DIR`` environment variable.
- The current path if the **--legacy** option is set.
1. The path specified with **--dir**.
2. The path read from the server configuration specified with **--confdb** or
**--config**.
3. The path read from the server default configuration database.
4. The path read from the server default configuration file.
In legacy mode, the path is determined as follows:
1. The path specified with **--dir**.
2. The path specified in the ``KEYMGR_DIR`` environment variable.
3. The current working dir.
Main commands
.............
......
......@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
......@@ -23,23 +24,35 @@
#include "options.h"
#include "shared/print.h"
int options_init(options_t *options)
/*!
* Initialize kasp_dir in legacy mode.
*/
static int options_init_legacy(options_t *options)
{
if (options == NULL) {
return DNSSEC_EINVAL;
assert(options);
if (options->kasp_dir) {
return DNSSEC_EOK;
}
if (options->kasp_dir == NULL) {
char *env = getenv("KEYMGR_DIR");
if (env != NULL) {
options->kasp_dir = strdup(env);
}
char *env = getenv("KEYMGR_DIR");
if (env) {
options->kasp_dir = strdup(env);
return options->kasp_dir ? DNSSEC_EOK : DNSSEC_ENOMEM;
}
if (options->legacy) {
if (options->kasp_dir == NULL) {
options->kasp_dir = getcwd(NULL, 0);
}
options->kasp_dir = getcwd(NULL, 0);
return options->kasp_dir ? DNSSEC_EOK : DNSSEC_ENOMEM;
}
/*!
* Initialize kasp_dir with policies in database.
*/
static int options_init_modern(options_t *options)
{
assert(options);
if (options->kasp_dir) {
return DNSSEC_EOK;
}
......@@ -61,8 +74,9 @@ int options_init(options_t *options)
} else if (stat(CONF_DEFAULT_FILE, &st) == 0) {
import = true;
options->config = CONF_DEFAULT_FILE;
} else if (options->kasp_dir == NULL) {
options->kasp_dir = getcwd(NULL, 0);
} else {
error("Couldn't determine configuration source.");
return DNSSEC_EINVAL;
}
// Prepare config flags.
......@@ -95,6 +109,19 @@ int options_init(options_t *options)
return DNSSEC_EOK;
}
int options_init(options_t *options)
{
if (options == NULL) {
return DNSSEC_EINVAL;
}
if (options->legacy) {
return options_init_legacy(options);
} else {
return options_init_modern(options);
}
}
void options_cleanup(options_t *options)
{
if (options == NULL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment