diff options
-rw-r--r-- | client.c | 5 | ||||
-rw-r--r-- | server.c | 7 | ||||
-rw-r--r-- | utils.c | 20 | ||||
-rw-r--r-- | utils.h | 5 |
4 files changed, 28 insertions, 9 deletions
@@ -22,7 +22,7 @@ #include "protocol.h" #include "utils.h" -static struct cmd_options opts = {.key_string = NULL, .key_length = 0, .host = NULL, .port = 0, .filepath = NULL}; +static struct cmd_options opts = {.key_string = NULL, .key_length = 0, .user = NULL, .pass = NULL, .host = NULL, .port = 0, .filepath = NULL}; static int data_fd = -1; static void send_data(struct connection * const state) @@ -181,7 +181,7 @@ static void event_cb(struct bufferevent * bev, short events, void * con) on_disconnect(c); return; } - if (ev_protocol_client_auth(c, "username", "passphrase") != 0) { + if (ev_protocol_client_auth(c, opts.user, opts.pass) != 0) { LOG(ERROR, "Client AUTH failed"); on_disconnect(c); return; @@ -267,6 +267,7 @@ int main(int argc, char ** argv) LOG(ERROR, "Invalid host/port"); return 2; } + LOG(NOTICE, "Host: %s, Port: %s, User: %s, Pass: %s", opts.host, opts.port, opts.user, opts.pass); LOG(NOTICE, "Resolving %s:%s..", opts.host, opts.port); gai_errno = hostname_to_address(opts.host, opts.port, &connect_addresses); if (gai_errno != 0) { @@ -22,7 +22,7 @@ #include "protocol.h" #include "utils.h" -static struct cmd_options opts = {.key_string = NULL, .key_length = 0, .host = NULL, .port = 0, .filepath = NULL}; +static struct cmd_options opts = {.key_string = NULL, .key_length = 0, .user = NULL, .pass = NULL, .host = NULL, .port = 0, .filepath = NULL}; static int data_fd = -1; static void recv_data(uint8_t const * const buffer, size_t size) @@ -51,8 +51,8 @@ enum recv_return protocol_request_client_auth(struct connection * const state, LOG(NOTICE, "Client AUTH with protocol version 0x%X", state->used_protocol_version); /* user/pass authentication part - exemplary */ - if (strncmp(auth_pkt->login, "username", sizeof(auth_pkt->login)) == 0 && - strncmp(auth_pkt->passphrase, "passphrase", sizeof(auth_pkt->passphrase)) == 0) { + if (strncmp(auth_pkt->login, opts.user, sizeof(auth_pkt->login)) == 0 && + strncmp(auth_pkt->passphrase, opts.pass, sizeof(auth_pkt->passphrase)) == 0) { LOG(NOTICE, "Username '%.*s' with passphrase '%.*s' logged in", @@ -319,6 +319,7 @@ int main(int argc, char ** argv) LOG(ERROR, "Invalid host/port"); return 2; } + LOG(NOTICE, "Host: %s, Port: %s, User: %s, Pass: %s", opts.host, opts.port, opts.user, opts.pass); LOG(NOTICE, "Resolving %s:%s..", opts.host, opts.port); gai_errno = hostname_to_address(opts.host, opts.port, &connect_addresses); if (gai_errno != 0) { @@ -10,7 +10,7 @@ __attribute__((noreturn)) void usage(const char * const arg0) { - fprintf(stderr, "usage: %s -k [SODIUM-KEY] -h [HOST] -p [PORT] -f [FILE]\n", arg0); + fprintf(stderr, "usage: %s -k [SODIUM-KEY] -U [USER] -P [PASS] -r [HOST] -R [PORT] -f [FILE]\n", arg0); exit(EXIT_FAILURE); } @@ -18,16 +18,22 @@ void parse_cmdline(struct cmd_options * const opts, int argc, char ** const argv { int opt; - while ((opt = getopt(argc, argv, "k:h:p:f:h")) != -1) { + while ((opt = getopt(argc, argv, "k:U:P:r:R:f:h")) != -1) { switch (opt) { case 'k': opts->key_string = strdup(optarg); memset(optarg, '*', strlen(optarg)); break; - case 'h': + case 'U': + opts->user = strdup(optarg); + break; + case 'P': + opts->pass = strdup(optarg); + break; + case 'r': opts->host = strdup(optarg); break; - case 'p': + case 'R': opts->port = strdup(optarg); break; case 'f': @@ -47,6 +53,12 @@ void parse_cmdline(struct cmd_options * const opts, int argc, char ** const argv if (opts->key_string != NULL) { opts->key_length = strlen(opts->key_string); } + if (opts->user == NULL) { + opts->user = strdup("username"); + } + if (opts->pass == NULL) { + opts->pass = strdup("passphrase"); + } } char * prettify_bytes_with_units(char * const out, size_t out_size, unsigned long long bytes) @@ -11,6 +11,11 @@ struct cmd_options { */ char * key_string; size_t key_length; + /* server: user/password required for any client authentication + * client: user/password used against server authentication + */ + char * user; + char * pass; /* server: listen host * client: remote host */ |