aboutsummaryrefslogtreecommitdiffstats
path: root/src/add.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-19 19:11:06 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-19 19:11:06 +0200
commit78ee1c72c670a71bfd165448676fc65bff802916 (patch)
tree893b0f09dfc84f3fd7f1ac218213012f33d5b612 /src/add.c
parent84bbbb91c9154ca0b1c295eb7d1aa0de59450764 (diff)
downloadck-78ee1c72c670a71bfd165448676fc65bff802916.tar.gz
ck-78ee1c72c670a71bfd165448676fc65bff802916.tar.bz2
ck-78ee1c72c670a71bfd165448676fc65bff802916.zip
Add ability to use ck without secret dir
Diffstat (limited to 'src/add.c')
-rw-r--r--src/add.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/add.c b/src/add.c
index 574ac73..79227d1 100644
--- a/src/add.c
+++ b/src/add.c
@@ -204,7 +204,7 @@ static int add_transaction_try(DB *db, const AddOpt * const opt, const char *hom
}
static int link_config(const AddOpt *opt, const char* newPath) {
- hLOG("Linking %s -> %s\n", newPath, opt->confPath);
+ hLOG("Linking %s -> %s", newPath, opt->confPath);
if (util_symlink_file(newPath, opt->confPath) != 0) {
ERR("Could not link file.");
return -1;
@@ -222,7 +222,7 @@ static int move_config(const AddOpt *opt, char *progDir, char *ret) {
return -1;
}
strcpy(ret, newPath);
- hLOG("Moving %s -> %s\n", opt->confPath, newPath);
+ hLOG("Moving %s -> %s", opt->confPath, newPath);
if (util_move_file(opt->confPath, newPath) != 0) {
ERR("Could not move file.");
return -1;
@@ -230,7 +230,7 @@ static int move_config(const AddOpt *opt, char *progDir, char *ret) {
return 0;
}
-static AddOpt add_make_options(cklist *args) {
+static AddOpt add_make_options(cklist *args, DB *db) {
list_rewind(args);
/* since we are here, the first two arguments must exist */
AddOpt addOpt = {
@@ -254,6 +254,10 @@ static AddOpt add_make_options(cklist *args) {
while (list_next(args)) {
if (strcmp(list_get(args), "-s") == 0 && addOpt.secret == 0) {
+ if (!secret_enabled(db)) {
+ addOpt.err = ADD_ERR_NO_SECRET;
+ return addOpt;
+ }
addOpt.secret = 1;
} else if (strcmp(list_get(args), "-p") == 0 && addOpt.prime == 0) {
addOpt.prime = 1;
@@ -304,10 +308,13 @@ int run_ADD(UserOpt * opt, Conf *conf) {
if (open_DB(&db, opt)) {
return -1;
}
- AddOpt addOpt = add_make_options(opt->args);
+ AddOpt addOpt = add_make_options(opt->args, &db);
switch (addOpt.err) {
case ADD_NO_ERR:
break;
+ case ADD_ERR_NO_SECRET:
+ ERR("Secret is not enabled for this ck instance.");
+ goto error;
case ADD_ERR_LINK_CONFIG:
ERR("%s is a link.", addOpt.confPath);
goto error;