aboutsummaryrefslogtreecommitdiffstats
path: root/src/stroke/stroke.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stroke/stroke.c')
-rw-r--r--src/stroke/stroke.c32
1 files changed, 30 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);
}