diff options
Diffstat (limited to 'src/stroke')
-rw-r--r-- | src/stroke/stroke.c | 32 | ||||
-rw-r--r-- | src/stroke/stroke_keywords.h | 1 | ||||
-rw-r--r-- | src/stroke/stroke_keywords.txt | 1 | ||||
-rw-r--r-- | src/stroke/stroke_msg.h | 10 |
4 files changed, 42 insertions, 2 deletions
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c index 6aadd3ec9..5dc7f0436 100644 --- a/src/stroke/stroke.c +++ b/src/stroke/stroke.c @@ -1,5 +1,5 @@ /* Stroke for charon is the counterpart to whack from pluto - * Copyright (C) 2007 Tobias Brunner + * Copyright (C) 2007-2012 Tobias Brunner * Copyright (C) 2006 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -89,9 +89,11 @@ static int send_stroke_msg (stroke_msg_t *msg) { buffer[byte_count] = '\0'; - /* we prompt if we receive the "Passphrase:"/"PIN:" magic keyword */ + /* we prompt if we receive a magic keyword */ if ((byte_count >= 12 && strcmp(buffer + byte_count - 12, "Passphrase:\n") == 0) || + (byte_count >= 10 && + strcmp(buffer + byte_count - 10, "Password:\n") == 0) || (byte_count >= 5 && strcmp(buffer + byte_count - 5, "PIN:\n") == 0)) { @@ -349,6 +351,19 @@ static int memusage() return send_stroke_msg(&msg); } +static int user_credentials(char *name, char *user, char *pass) +{ + stroke_msg_t msg; + + msg.type = STR_USER_CREDS; + msg.length = offsetof(stroke_msg_t, buffer); + msg.user_creds.name = push_string(&msg, name); + msg.user_creds.username = push_string(&msg, user); + msg.user_creds.password = push_string(&msg, pass); + return send_stroke_msg(&msg); +} + + static int set_loglevel(char *type, u_int level) { stroke_msg_t msg; @@ -424,6 +439,11 @@ static void exit_usage(char *error) printf(" stroke memusage\n"); printf(" Show leases of a pool:\n"); printf(" stroke leases [POOL [ADDRESS]]\n"); + printf(" Set username and password for a connection:\n"); + printf(" stroke user-creds NAME USERNAME [PASSWORD]\n"); + printf(" where: NAME is a connection name added with \"stroke add\"\n"); + printf(" USERNAME is the username\n"); + printf(" PASSWORD is the optional password, you'll be asked to enter it if not given\n"); exit_error(error); } @@ -564,6 +584,14 @@ int main(int argc, char *argv[]) case STROKE_MEMUSAGE: res = memusage(); break; + case STROKE_USER_CREDS: + if (argc < 4) + { + exit_usage("\"user-creds\" needs a connection name, " + "username and optionally a password"); + } + res = user_credentials(argv[2], argv[3], argc > 4 ? argv[4] : NULL); + break; default: exit_usage(NULL); } diff --git a/src/stroke/stroke_keywords.h b/src/stroke/stroke_keywords.h index 3bd68bdc3..554d071f3 100644 --- a/src/stroke/stroke_keywords.h +++ b/src/stroke/stroke_keywords.h @@ -57,6 +57,7 @@ typedef enum { STROKE_EXPORT_X509, STROKE_LEASES, STROKE_MEMUSAGE, + STROKE_USER_CREDS, } stroke_keyword_t; #define STROKE_LIST_FIRST STROKE_LIST_PUBKEYS diff --git a/src/stroke/stroke_keywords.txt b/src/stroke/stroke_keywords.txt index 4a4cc57a9..1d7ab8a45 100644 --- a/src/stroke/stroke_keywords.txt +++ b/src/stroke/stroke_keywords.txt @@ -64,3 +64,4 @@ purgeike, STROKE_PURGE_IKE exportx509, STROKE_EXPORT_X509 leases, STROKE_LEASES memusage, STROKE_MEMUSAGE +user-creds, STROKE_USER_CREDS diff --git a/src/stroke/stroke_msg.h b/src/stroke/stroke_msg.h index be12cabbe..22d4f11a3 100644 --- a/src/stroke/stroke_msg.h +++ b/src/stroke/stroke_msg.h @@ -146,6 +146,7 @@ struct stroke_end_t { char *id; char *id2; char *eap_id; + char *rsakey; char *cert; char *cert2; char *ca; @@ -218,6 +219,8 @@ struct stroke_msg_t { STR_EXPORT, /* print memory usage details */ STR_MEMUSAGE, + /* set username and password for a connection */ + STR_USER_CREDS, /* more to come */ } type; @@ -338,6 +341,13 @@ struct stroke_msg_t { char *pool; char *address; } leases; + + /* data for STR_USER_CREDS */ + struct { + char *name; + char *username; + char *password; + } user_creds; }; char buffer[STROKE_BUF_LEN]; }; |