aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-10-28 14:35:23 +0100
committerToni Uhlig <matzeton@googlemail.com>2020-10-28 14:35:23 +0100
commit8613c9bed377a05d097ffa0387f22906a4799e57 (patch)
treee85f094478ac02b4cd574b1f4984f6c8625b07ef
parentb2540ad3304f13306cff98c29992b52a6f6d03b6 (diff)
added -U / -P optionHEADmaster
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--client.c5
-rw-r--r--server.c7
-rw-r--r--utils.c20
-rw-r--r--utils.h5
4 files changed, 28 insertions, 9 deletions
diff --git a/client.c b/client.c
index bf7ef23..61c540f 100644
--- a/client.c
+++ b/client.c
@@ -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) {
diff --git a/server.c b/server.c
index e654a6c..3339eb5 100644
--- a/server.c
+++ b/server.c
@@ -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) {
diff --git a/utils.c b/utils.c
index 1a52bc1..7ec6fb9 100644
--- a/utils.c
+++ b/utils.c
@@ -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)
diff --git a/utils.h b/utils.h
index 513da66..840596d 100644
--- a/utils.h
+++ b/utils.h
@@ -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
*/