luksrku/pgmopts.c
Johannes Bauer 667ff55af1 Integrate editor properly from command line
Now have a way to invoke the editor functionality from the command line
and also provisions to include the server and client parsers.
2019-10-23 11:34:40 +02:00

80 lines
2.4 KiB
C

/*
luksrku - Tool to remotely unlock LUKS disks using TLS.
Copyright (C) 2016-2019 Johannes Bauer
This file is part of luksrku.
luksrku is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; this program is ONLY licensed under
version 3 of the License, later versions are explicitly excluded.
luksrku is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with luksrku; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Johannes Bauer <JohannesBauer@gmx.de>
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include "pgmopts.h"
#include "argparse_edit.h"
static struct pgmopts_t pgmopts_rw = {
};
const struct pgmopts_t *pgmopts = &pgmopts_rw;
static void show_syntax(const char *errmsg, int argc, char **argv) {
if (errmsg) {
fprintf(stderr, "error: %s\n", errmsg);
fprintf(stderr, "\n");
}
fprintf(stderr, "Available commands:\n");
fprintf(stderr, " %s edit Interactively edit a key database\n", argv[0]);
fprintf(stderr, " %s server Start a key server process\n", argv[0]);
fprintf(stderr, " %s client Unlock LUKS volumes by querying a key server\n", argv[0]);
fprintf(stderr, "\n");
fprintf(stderr, "For futher help: %s (command) --help\n", argv[0]);
}
static bool edit_callback(enum argparse_edit_option_t option, const char *value, argparse_edit_errmsg_callback_t errmsg_callback) {
switch (option) {
case ARG_EDIT_FILENAME:
pgmopts_rw.edit.filename = value;
break;
case ARG_EDIT_VERBOSE:
pgmopts_rw.edit.verbosity++;
break;
}
return true;
}
static void parse_pgmopts_edit(int argc, char **argv) {
argparse_edit_parse_or_quit(argc - 1, argv + 1, edit_callback, NULL);
}
void parse_pgmopts_or_quit(int argc, char **argv) {
if (argc < 2) {
show_syntax("no command supplied", argc, argv);
exit(EXIT_FAILURE);
}
const char *command = argv[1];
if (!strcmp(command, "edit")) {
pgmopts_rw.pgm = PGM_EDIT;
parse_pgmopts_edit(argc, argv);
} else {
show_syntax("unsupported command supplied", argc, argv);
exit(EXIT_FAILURE);
}
}