Fix bug with commandline parsing

For each parameter, all previous parameters were overwritten with
default values. Fixed.
This commit is contained in:
Johannes Bauer 2019-10-23 20:01:54 +02:00
parent 2143adc91f
commit 9ea0a9695c
6 changed files with 40 additions and 30 deletions

View File

@ -26,7 +26,7 @@ clean:
rm -f $(OBJS) $(OBJS_CFG) luksrku rm -f $(OBJS) $(OBJS_CFG) luksrku
test: luksrku test: luksrku
./luksrku -v --server-mode -k server_key.bin ./luksrku server -vv base
gdb: luksrku gdb: luksrku
gdb --args ./luksrku -v --server-mode -k server_key.bin gdb --args ./luksrku -v --server-mode -k server_key.bin

2
log.c
View File

@ -30,7 +30,7 @@
#include "log.h" #include "log.h"
static enum loglvl_t current_loglvl = LLVL_INFO; static enum loglvl_t current_loglvl = LOGLEVEL_DEFAULT;
static const char *loglvl_names[] = { static const char *loglvl_names[] = {
[LLVL_FATAL] = "FATAL", [LLVL_FATAL] = "FATAL",
[LLVL_ERROR] = "ERROR", [LLVL_ERROR] = "ERROR",

2
log.h
View File

@ -24,6 +24,8 @@
#ifndef __LOG_H__ #ifndef __LOG_H__
#define __LOG_H__ #define __LOG_H__
#define LOGLEVEL_DEFAULT LLVL_INFO
enum loglvl_t { enum loglvl_t {
LLVL_FATAL = 0, LLVL_FATAL = 0,
LLVL_ERROR = 1, LLVL_ERROR = 1,

View File

@ -37,10 +37,12 @@
#endif #endif
static int main_edit(const struct pgmopts_edit_t *opts) { static int main_edit(const struct pgmopts_edit_t *opts) {
log_setlvl(LOGLEVEL_DEFAULT + opts->verbosity);
return editor_start(opts) ? 0 : 1; return editor_start(opts) ? 0 : 1;
} }
static int main_server(const struct pgmopts_server_t *opts) { static int main_server(const struct pgmopts_server_t *opts) {
log_setlvl(LOGLEVEL_DEFAULT + opts->verbosity);
return keyserver_start(opts) ? 0 : 1; return keyserver_start(opts) ? 0 : 1;
} }

View File

@ -30,8 +30,7 @@
#include "argparse_edit.h" #include "argparse_edit.h"
#include "argparse_server.h" #include "argparse_server.h"
static struct pgmopts_t pgmopts_rw = { static struct pgmopts_t pgmopts_rw;
};
const struct pgmopts_t *pgmopts = &pgmopts_rw; const struct pgmopts_t *pgmopts = &pgmopts_rw;
static void show_syntax(const char *errmsg, int argc, char **argv) { static void show_syntax(const char *errmsg, int argc, char **argv) {
@ -48,9 +47,6 @@ static void show_syntax(const char *errmsg, int argc, char **argv) {
} }
static bool edit_callback(enum argparse_edit_option_t option, const char *value, argparse_edit_errmsg_callback_t errmsg_callback) { static bool edit_callback(enum argparse_edit_option_t option, const char *value, argparse_edit_errmsg_callback_t errmsg_callback) {
pgmopts_rw.edit = (struct pgmopts_edit_t){
.verbosity = ARGPARSE_EDIT_DEFAULT_VERBOSE,
};
switch (option) { switch (option) {
case ARG_EDIT_FILENAME: case ARG_EDIT_FILENAME:
pgmopts_rw.edit.filename = value; pgmopts_rw.edit.filename = value;
@ -64,11 +60,6 @@ static bool edit_callback(enum argparse_edit_option_t option, const char *value,
} }
static bool server_callback(enum argparse_server_option_t option, const char *value, argparse_server_errmsg_callback_t errmsg_callback) { static bool server_callback(enum argparse_server_option_t option, const char *value, argparse_server_errmsg_callback_t errmsg_callback) {
pgmopts_rw.server = (struct pgmopts_server_t){
.port = ARGPARSE_SERVER_DEFAULT_PORT,
.verbosity = ARGPARSE_SERVER_DEFAULT_VERBOSE,
.answer_udp_queries = true,
};
switch (option) { switch (option) {
case ARG_SERVER_FILENAME: case ARG_SERVER_FILENAME:
pgmopts_rw.server.filename = value; pgmopts_rw.server.filename = value;
@ -90,10 +81,18 @@ static bool server_callback(enum argparse_server_option_t option, const char *va
} }
static void parse_pgmopts_edit(int argc, char **argv) { static void parse_pgmopts_edit(int argc, char **argv) {
pgmopts_rw.edit = (struct pgmopts_edit_t){
.verbosity = ARGPARSE_EDIT_DEFAULT_VERBOSE,
};
argparse_edit_parse_or_quit(argc - 1, argv + 1, edit_callback, NULL); argparse_edit_parse_or_quit(argc - 1, argv + 1, edit_callback, NULL);
} }
static void parse_pgmopts_server(int argc, char **argv) { static void parse_pgmopts_server(int argc, char **argv) {
pgmopts_rw.server = (struct pgmopts_server_t){
.port = ARGPARSE_SERVER_DEFAULT_PORT,
.verbosity = ARGPARSE_SERVER_DEFAULT_VERBOSE,
.answer_udp_queries = true,
};
argparse_server_parse_or_quit(argc - 1, argv + 1, server_callback, NULL); argparse_server_parse_or_quit(argc - 1, argv + 1, server_callback, NULL);
} }

View File

@ -355,26 +355,33 @@ static int psk_server_callback(SSL *ssl, const unsigned char *identity, size_t i
return 0; return 0;
} }
int return_value = 1;
do {
if (!SSL_SESSION_set1_master_key(sess, ctx->host->tls_psk, PSK_SIZE_BYTES)) { if (!SSL_SESSION_set1_master_key(sess, ctx->host->tls_psk, PSK_SIZE_BYTES)) {
log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK master key."); log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK master key.");
SSL_SESSION_free(sess); return_value = 0;
return 0; break;
} }
if (!SSL_SESSION_set_cipher(sess, cipher)) { if (!SSL_SESSION_set_cipher(sess, cipher)) {
log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK cipher."); log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK cipher.");
SSL_SESSION_free(sess); return_value = 0;
return 0; break;
} }
if (!SSL_SESSION_set_protocol_version(sess, TLS1_3_VERSION)) { if (!SSL_SESSION_set_protocol_version(sess, TLS1_3_VERSION)) {
log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK protocol version."); log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK protocol version.");
SSL_SESSION_free(sess); return_value = 0;
return 0; break;
} }
} while (false);
if (return_value) {
*sessptr = sess; *sessptr = sess;
return 1; } else {
SSL_SESSION_free(sess);
}
return return_value;
} }
static void client_handler_thread(void *vctx) { static void client_handler_thread(void *vctx) {
@ -388,7 +395,7 @@ static void client_handler_thread(void *vctx) {
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
} else { } else {
if (client->host) { if (client->host) {
log_msg(LLVL_DEBUG, "Client \"%s\" connected, sending unlock data for %d volumes...", client->host->host_name, client->host->volume_count); log_msg(LLVL_DEBUG, "Client \"%s\" connected, sending unlock data for %d volumes.", client->host->host_name, client->host->volume_count);
for (unsigned int i = 0; i < client->host->volume_count; i++) { for (unsigned int i = 0; i < client->host->volume_count; i++) {
const struct volume_entry_t *volume = &client->host->volumes[i]; const struct volume_entry_t *volume = &client->host->volumes[i];