aboutsummaryrefslogtreecommitdiffstats
path: root/src/stroke
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2006-06-12 08:43:46 +0000
committerAndreas Steffen <andreas.steffen@strongswan.org>2006-06-12 08:43:46 +0000
commit5347233204f7631609c5a2bc2f4fd65f6ed6773c (patch)
tree8544572ea1eeee8871bb285cf41ff9f0c6825eb0 /src/stroke
parent299dbc604f48ed5a44029600b01d77477ecc1fd4 (diff)
downloadstrongswan-5347233204f7631609c5a2bc2f4fd65f6ed6773c.tar.bz2
strongswan-5347233204f7631609c5a2bc2f4fd65f6ed6773c.tar.xz
support for stroke listcerts|listcacerts|listall and left|rightca=
Diffstat (limited to 'src/stroke')
-rw-r--r--src/stroke/Makefile.am6
-rw-r--r--src/stroke/stroke.c157
-rw-r--r--src/stroke/stroke.h19
3 files changed, 108 insertions, 74 deletions
diff --git a/src/stroke/Makefile.am b/src/stroke/Makefile.am
index 0de0134de..761c3b861 100644
--- a/src/stroke/Makefile.am
+++ b/src/stroke/Makefile.am
@@ -1,4 +1,8 @@
ipsec_PROGRAMS = stroke
-stroke_SOURCES = stroke.c stroke.h
+stroke_SOURCES = stroke.c stroke.h stroke_keywords.c stroke_keywords.h
INCLUDES = -I$(top_srcdir)/src/libstrongswan
+EXTRA_DIST = stroke_keywords.txt
+
+stroke_keywords.c: stroke_keywords.txt stroke_keywords.h
+ $(GPERF) -C -G -t < stroke_keywords.txt > stroke_keywords.c
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c
index d5357222f..b8b0cc093 100644
--- a/src/stroke/stroke.c
+++ b/src/stroke/stroke.c
@@ -27,6 +27,12 @@
#include <types.h>
#include "stroke.h"
+#include "stroke_keywords.h"
+
+struct stroke_token {
+ char *name;
+ stroke_keyword_t kw;
+};
static char* push_string(stroke_msg_t *msg, char *string)
{
@@ -156,26 +162,31 @@ static int terminate_connection(char *name)
return send_stroke_msg(&msg);
}
-static int show_status(char *mode, char *connection)
+static int show_status(stroke_keyword_t kw, char *connection)
{
stroke_msg_t msg;
- if (strcmp(mode, "statusall") == 0)
- msg.type = STR_STATUS_ALL;
- else
- msg.type = STR_STATUS;
-
+ msg.type = (kw == STROKE_STATUS)? STR_STATUS:STR_STATUS_ALL;
msg.length = offsetof(stroke_msg_t, buffer);
msg.status.name = push_string(&msg, connection);
return send_stroke_msg(&msg);
}
-static int list_certs(void)
+static int list_flags[] = {
+ LIST_CERTS,
+ LIST_CACERTS,
+ LIST_CRLS,
+ LIST_ALL
+};
+
+static int list(stroke_keyword_t kw, bool utc)
{
stroke_msg_t msg;
- msg.type = STR_LIST_CERTS;
+ msg.type = STR_LIST;
msg.length = offsetof(stroke_msg_t, buffer);
+ msg.list.utc = utc;
+ msg.list.flags = list_flags[kw - STROKE_LIST_FIRST];
return send_stroke_msg(&msg);
}
@@ -250,80 +261,82 @@ static void exit_usage(char *error)
int main(int argc, char *argv[])
{
+ const stroke_token_t *token;
int res = 0;
- char *op;
-
+
if (argc < 2)
{
exit_usage(NULL);
}
- op = argv[1];
+ token = in_word_set(argv[1], strlen(argv[1]));
- if (streq(op, "status") || streq(op, "statusall"))
- {
- res = show_status(op, argc > 2 ? argv[2] : NULL);
- }
- else if (streq(op, "listcerts") || streq(op, "listall"))
- {
- res = list_certs();
- }
- else if (streq(op, "up"))
- {
- if (argc < 3)
- {
- exit_usage("\"up\" needs a connection name");
- }
- res = initiate_connection(argv[2]);
- }
- else if (streq(op, "down"))
+ if (token == NULL)
{
- if (argc < 3)
- {
- exit_usage("\"down\" needs a connection name");
- }
- res = terminate_connection(argv[2]);
+ exit_usage("unknown keyword");
}
- else if (streq(op, "add"))
- {
- if (argc < 11)
- {
- exit_usage("\"add\" needs more parameters...");
- }
- res = add_connection(argv[2],
- argv[3], argv[4],
- argv[5], argv[6],
- argv[7], argv[8],
- atoi(argv[9]), atoi(argv[10]));
- }
- else if (streq(op, "delete"))
- {
- if (argc < 3)
- {
- exit_usage("\"delete\" needs a connection name");
- }
- res = del_connection(argv[2]);
- }
- else if (streq(op, "logtype"))
- {
- if (argc < 5)
- {
- exit_usage("\"logtype\" needs more parameters...");
- }
- res = set_logtype(argv[2], argv[3], atoi(argv[4]));
- }
- else if (streq(op, "loglevel"))
- {
- if (argc < 4)
- {
- exit_usage("\"logtype\" needs more parameters...");
- }
- res = set_loglevel(argv[2], atoi(argv[3]));
- }
- else
+
+ switch (token->kw)
{
- exit_usage(NULL);
+ case STROKE_ADD:
+ if (argc < 11)
+ {
+ exit_usage("\"add\" needs more parameters...");
+ }
+ res = add_connection(argv[2],
+ argv[3], argv[4],
+ argv[5], argv[6],
+ argv[7], argv[8],
+ atoi(argv[9]), atoi(argv[10]));
+ break;
+ case STROKE_DELETE:
+ case STROKE_DEL:
+ if (argc < 3)
+ {
+ exit_usage("\"delete\" needs a connection name");
+ }
+ res = del_connection(argv[2]);
+ break;
+ case STROKE_UP:
+ if (argc < 3)
+ {
+ exit_usage("\"up\" needs a connection name");
+ }
+ res = initiate_connection(argv[2]);
+ break;
+ case STROKE_DOWN:
+ if (argc < 3)
+ {
+ exit_usage("\"down\" needs a connection name");
+ }
+ res = terminate_connection(argv[2]);
+ break;
+ case STROKE_LOGTYPE:
+ if (argc < 5)
+ {
+ exit_usage("\"logtype\" needs more parameters...");
+ }
+ res = set_logtype(argv[2], argv[3], atoi(argv[4]));
+ break;
+ case STROKE_LOGLEVEL:
+ if (argc < 4)
+ {
+ exit_usage("\"logtype\" needs more parameters...");
+ }
+ res = set_loglevel(argv[2], atoi(argv[3]));
+ break;
+ case STROKE_STATUS:
+ case STROKE_STATUSALL:
+ res = show_status(token->kw, argc > 2 ? argv[2] : NULL);
+ break;
+ case STROKE_LIST_CERTS:
+ case STROKE_LIST_CACERTS:
+ case STROKE_LIST_CRLS:
+ case STROKE_LIST_ALL:
+ res = list(token->kw, argc > 2 && streq(argv[2], "--utc"));
+ break;
+ default:
+ exit_usage(NULL);
}
-
return res;
}
diff --git a/src/stroke/stroke.h b/src/stroke/stroke.h
index e9bdedd0e..0544ca8bf 100644
--- a/src/stroke/stroke.h
+++ b/src/stroke/stroke.h
@@ -30,6 +30,15 @@
#define STROKE_BUF_LEN 2048
+/**
+ * Definition of the LIST flags
+ */
+#define LIST_NONE 0x0000 /* don't list anything */
+#define LIST_CERTS 0x0001 /* list all host/user certs */
+#define LIST_CACERTS 0x0002 /* list all ca certs */
+#define LIST_CRLS 0x0004 /* list all crls */
+#define LIST_ALL 0x0007 /* all list options */
+
typedef struct stroke_end_t stroke_end_t;
struct stroke_end_t {
@@ -72,7 +81,7 @@ struct stroke_msg_t {
/* set the verbosity of a logging context */
STR_LOGLEVEL,
/* show list of locally loaded certificates */
- STR_LIST_CERTS
+ STR_LIST
/* more to come */
} type;
@@ -96,16 +105,24 @@ struct stroke_msg_t {
stroke_end_t me, other;
} add_conn;
+ /* data for STR_LOGTYPE */
struct {
char *context;
char *type;
int enable;
} logtype;
+ /* data for STR_LOGLEVEL */
struct {
char *context;
int level;
} loglevel;
+
+ /* data for STR_LIST */
+ struct {
+ u_int flags;
+ bool utc;
+ } list;
};
char buffer[STROKE_BUF_LEN];
};