Skip to content

Commit

Permalink
OpenDNSSEC-99: add --force flag to ods-enforcer-db-setup
Browse files Browse the repository at this point in the history
and ods-hsmutil purge
  • Loading branch information
yschaeff committed Apr 18, 2016
1 parent b0bc33a commit ab8aa04
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* OpenDNSSEC-99: Skip "are you sure" messages. Add --force and -f flag to
ods-enforcer-db-setup and hsmutil purge

OpenDNSSEC 2.0b1 - 2016-04-14

First public release of OpenDNSSEC. Initial pre-releases have been
Expand Down
21 changes: 14 additions & 7 deletions enforcer/src/ods-enforcer-db-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,17 @@ int main(int argc, char* argv[]) {
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"force", no_argument, 0, 'f'},
{ 0, 0, 0, 0}
};
int user_certain;
int force = 0;
engineconfig_type* cfg;
const char* cfgfile = ODS_SE_CFGFILE;

ods_log_init("ods-enforcerd", 0, NULL, 0);

while ((c=getopt_long(argc, argv, "hV",
while ((c=getopt_long(argc, argv, "hVf",
long_options, &options_index)) != -1) {
switch (c) {
case 'h':
Expand All @@ -249,17 +251,22 @@ int main(int argc, char* argv[]) {
case 'V':
version(stdout);
exit(0);
case 'f':
force = 1;
break;
default:
exit(100);
}
}

printf("*WARNING* This will erase all data in the database; are you sure? [y/N] ");

user_certain = getchar();
if (user_certain != 'y' && user_certain != 'Y') {
printf("Okay, quitting...\n");
return 0;
if (!force) {
printf("*WARNING* This will erase all data in the database; "
"are you sure? [y/N] ");
user_certain = getchar();
if (user_certain != 'y' && user_certain != 'Y') {
printf("Okay, quitting...\n");
return 0;
}
}

cfg = engine_config(cfgfile, 0, NULL);
Expand Down
37 changes: 25 additions & 12 deletions libhsm/src/bin/hsmutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ static void
usage ()
{
fprintf(stderr,
"usage: %s [-c config] [-vV] command [options]\n",
"usage: %s [-c config] [-vVfh] [command [options]]\n",
progname);

fprintf(stderr," -h Print this usage information.\n");
fprintf(stderr," -v Increase verbosity.\n");
fprintf(stderr," -V Print version and exit.\n");
fprintf(stderr," -f Force, Assume yes on all questions.\n");
fprintf(stderr," -c <cfg> Use alternative conf.xml.\n");

fprintf(stderr,"commands\n");

fprintf(stderr," login\n");
fprintf(stderr," logout\n");
fprintf(stderr," list [repository]\n");
Expand Down Expand Up @@ -300,7 +308,7 @@ cmd_remove (int argc, char *argv[])
}

static int
cmd_purge (int argc, char *argv[])
cmd_purge (int argc, char *argv[], int force)
{
int result;
int final_result = 0;
Expand Down Expand Up @@ -343,15 +351,16 @@ cmd_purge (int argc, char *argv[])
return -1;
}

printf("Are you sure you want to remove ALL keys from repository %s ? (YES/NO) ", repository);
fresult = fgets(confirm, sizeof(confirm) - 1, stdin);
if (fresult == NULL || strncasecmp(confirm, "yes", 3) != 0) {
printf("\nPurge cancelled.\n");
libhsm_key_list_free(keys, key_count);
return -1;
} else {
printf("\nStarting purge...\n");
if (!force) {
printf("Are you sure you want to remove ALL keys from repository %s ? (YES/NO) ", repository);
fresult = fgets(confirm, sizeof(confirm) - 1, stdin);
if (fresult == NULL || strncasecmp(confirm, "yes", 3) != 0) {
printf("\npurge cancelled.\n");
libhsm_key_list_free(keys, key_count);
return -1;
}
}
printf("\nStarting purge...\n");

for (i = 0; i < key_count; i++) {
libhsm_key_info_t *key_info;
Expand Down Expand Up @@ -559,13 +568,17 @@ main (int argc, char *argv[])
char *config = NULL;

int ch;
int force = 0;
progname = argv[0];

while ((ch = getopt(argc, argv, "c:vVh")) != -1) {
while ((ch = getopt(argc, argv, "c:vVhf")) != -1) {
switch (ch) {
case 'c':
config = strdup(optarg);
break;
case 'f':
force = 1;
break;
case 'v':
verbose++;
break;
Expand Down Expand Up @@ -628,7 +641,7 @@ main (int argc, char *argv[])
} else if (!strcasecmp(argv[0], "purge")) {
argc --;
argv ++;
result = cmd_purge(argc, argv);
result = cmd_purge(argc, argv, force);
} else if (!strcasecmp(argv[0], "dnskey")) {
argc --;
argv ++;
Expand Down

0 comments on commit ab8aa04

Please sign in to comment.