Added stroke user-creds command, to set username/password for a connection.

This commit is contained in:
Tobias Brunner
2012-04-17 14:20:58 +02:00
parent 7b00fdeb84
commit 9f1b303afc
7 changed files with 204 additions and 2 deletions
+27 -1
View File
@@ -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
*
@@ -352,6 +352,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;
@@ -427,6 +440,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);
}
@@ -567,6 +585,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);
}
+1
View File
@@ -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
+1
View File
@@ -64,3 +64,4 @@ purgeike, STROKE_PURGE_IKE
exportx509, STROKE_EXPORT_X509
leases, STROKE_LEASES
memusage, STROKE_MEMUSAGE
user-creds, STROKE_USER_CREDS
+9
View File
@@ -218,6 +218,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;
@@ -340,6 +342,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];
};