HI Andreas,

I started my work on stroke utility .

Initially I was having some segfaults but was able to resolve them. I was
able to add connections via CLI which was evident from ./stroke statusall .
But I was unable to initiate the added connections.

I started my work by hard-coding the stroke message to a certain extent
later on I will be cleaning up the code.

I have attached the Log files and the modified code. Please help me or
direct me the hack to initiate the connection. I will go ahead.


On Fri, Sep 7, 2012 at 11:28 AM, krishna chaitanya <
[email protected]> wrote:

> Hi Andreas,
>
> Thanks for the reply.
>
> I don't wanted to spam the dev-community with this mail.
>
> Let me brief you on what I was doing the couple of months. I have done
> some bench marking on the open source IKEv2 solutions Racoon, OpenIKEv2 and
> IKEv2 along with yours and concluded Strongswan aptly meeting my
> requirements.
>
> So I have to integrate it with my IPsec Fast Path which is in progress.
>
> Coming to the CLI part I had few discrepancies :
>
> I had 3 designs were in my mind since the day I took this task.
> 1. One is to write a wrapper script that would simple update the conf file
> in runtime.
> 2. CLI parsing and invoking the Stroke API. Its currenlty in the state of
> development which is not fully functional. So if I write it for my needs
> and once you  release your stroke CLI utility my code would be useless.
> 3. Developing an RPC model using the same Stroke API which I have gone
> through the Styx plugin. But I was not getting enough support from the
> developer.
>
> So currently you don't have a full fledged support of the Stroke CLI, I
> would start my design on the lines of Design 2 .
>
> Coming to the funding part as I see Strongswan Team is doing a beautiful
> job. I will definitely take the proposal to the concerned and will be
> updating you on the prospects. Let be positive.
>
> Thanks for your support.
>
>
> On Thu, Sep 6, 2012 at 10:31 PM, Andreas Steffen <
> [email protected]> wrote:
>
>> Hi Krishna,
>>
>> we currently don't have any plans to implement a full-fledged stroke
>> command line configuration tool. If someone is willing to do that
>> e.g. along the lines of the obsoleted whack interface but using the
>> stroke_msg structs
>>
>>
>> http://wiki.strongswan.org/projects/strongswan/repository/revisions/master/entry/src/stroke/stroke_msg.h
>>
>> then anyone is invited to contribute to such an interface. Also if some
>> organization is willing to sponsor the development then we would
>> prioritize a stroke command line interface on our todo list.
>>
>> Best regards
>>
>> Andreas
>>
>> On 09/03/2012 10:00 PM, krishna chaitanya wrote:
>> > Hi Team,
>> >
>> > As an user of Strongswan, when could we expect the the complete
>> > development of the stroke utility.
>> >
>> >
>> > Thanks,
>> > Krishna Chaitanya
>>
>> ======================================================================
>> Andreas Steffen                         [email protected]
>> strongSwan - the Linux VPN Solution!                www.strongswan.org
>> Institute for Internet Technologies and Applications
>> University of Applied Sciences Rapperswil
>> CH-8640 Rapperswil (Switzerland)
>> ===========================================================[ITA-HSR]==
>>
> Thanks,
> KC
>

Attachment: Stroke_Dev_Logs
Description: Binary data

/* Stroke for charon is the counterpart to whack from pluto
 * Copyright (C) 2007-2012 Tobias Brunner
 * Copyright (C) 2006 Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>

#include <library.h>
#include <utils/backtrace.h>
#include <threading/thread.h>
#include <debug.h>
#include <plugins/plugin.h>
#include "stroke_msg.h"
#include "stroke_keywords.h"
#include "starterstroke.h"
#include "confread.h"
#include "keywords.h"
#include "confread.h"
#include "args.h"
#include "files.h"
#include "netkey.h"
#include "klips.h"
#include "invokecharon.h"

#define CHARON_CTL_FILE IPSEC_PIDDIR "/charon.ctl"

/*Headers for Stoke*/
/*
#include <../libcharon/daemon.h>
#include <../libcharon/processing/jobs/callback_job.h>
#include <../libcharon/plugins/plugin.h>
#include <../libcharon/plugins/stroke/stroke_socket.h>
#include <../libcharon/plugins/stroke/stroke_control.h>
#include <../libcharon/sa/ike_sa.h>
#include <../libcharon/sa/ike_sa_manager.h>
#include <../libcharon/control/controller.h>
#include <../libcharon/sa/task_manager.h>
#include <../libcharon/sa/ikev2/tasks/ike_init.h>
*/
/**
 *  * Return codes defined by Linux Standard Base Core Specification 3.1
 *   * in section 20.2. Init Script Actions
 *    */
#define LSB_RC_SUCCESS               0   /* success                          */
#define LSB_RC_FAILURE               1   /* generic or unspecified error     */
#define LSB_RC_INVALID_ARGUMENT      2   /* invalid or excess argument(s)    */
#define LSB_RC_NOT_IMPLEMENTED       3   /* unimplemented feature (reload)   */
#define LSB_RC_NOT_ALLOWED           4   /* user had insufficient privilege  */
#define LSB_RC_NOT_INSTALLED         5   /* program is not installed         */
#define LSB_RC_NOT_CONFIGURED        6   /* program is not configured        */
#define LSB_RC_NOT_RUNNING           7   /* program is not running           */

#define FLAG_ACTION_START_PLUTO   0x01
#define FLAG_ACTION_UPDATE        0x02
#define FLAG_ACTION_RELOAD        0x04
#define FLAG_ACTION_QUIT          0x08
#define FLAG_ACTION_LISTEN        0x10
#define FLAG_ACTION_START_CHARON  0x20



struct stroke_token {
    char *name;
    stroke_keyword_t kw;
};

static char* push_string(stroke_msg_t *msg, char *string)
{
	unsigned long string_start = msg->length;

	if (string == NULL ||  msg->length + strlen(string) >= sizeof(stroke_msg_t))
	{
		return NULL;
	}
	else
	{
		msg->length += strlen(string) + 1;
		strcpy((char*)msg + string_start, string);
		return (char*)string_start;
	}
}

static int send_stroke_msg (stroke_msg_t *msg)
{
	struct sockaddr_un ctl_addr;
	int sock, byte_count;
	char buffer[512], *pass;

	ctl_addr.sun_family = AF_UNIX;
	strcpy(ctl_addr.sun_path,STROKE_SOCKET);
	/*strcpy(ctl_addr.sun_path, CHARON_CTL_FILE);*/
	msg->output_verbosity = -1; /* CONTROL */

	sock = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sock < 0)
	{
		fprintf(stderr, "Opening unix socket %s: %s\n", STROKE_SOCKET, strerror(errno));
		return -1;
	}
	if (connect(sock, (struct sockaddr *)&ctl_addr,
				offsetof(struct sockaddr_un, sun_path) + strlen(ctl_addr.sun_path)) < 0)
	{
		fprintf(stderr, "Connect to socket failed: %s\n", strerror(errno));
		close(sock);
		return -1;
	}

	/* send message */
	if (write(sock, msg, msg->length) != msg->length)
	{
		fprintf(stderr, "writing to socket failed: %s\n", strerror(errno));
		close(sock);
		return -1;
	}
	printf("/n %d ",msg->length);
	while ((byte_count = read(sock, buffer, sizeof(buffer)-1)) > 0)
	{
		buffer[byte_count] = '\0';

		/* 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))
		{
			/* remove trailing newline */
			pass = strrchr(buffer, '\n');
			if (pass)
			{
				*pass = ' ';
			}
#ifdef HAVE_GETPASS
			pass = getpass(buffer);
#else
			pass = "";
#endif
			if (pass)
			{
				ignore_result(write(sock, pass, strlen(pass)));
				ignore_result(write(sock, "\n", 1));
			}
		}
		else
		{
			printf("%s", buffer);
		}
	}
	if (byte_count < 0)
	{
		fprintf(stderr, "reading from socket failed: %s\n", strerror(errno));
	}
        
	/*static bool open_socket(private_stroke_socket_t *this);
	static job_requeue_t receive(private_stroke_socket_t *this);
	static job_requeue_t process(stroke_job_context_t *ctx);
	static void stroke_initiate(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out);
	stroke_control_t *stroke_control_create();
	static status_t initiate(private_controller_t *this,peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,controller_cb_t callback, void *param);
	static status_t initiate_execute(interface_job_t *job);
	METHOD(ike_sa_t, initiate, status_t,private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,traffic_selector_t *tsi, traffic_selector_t *tsr)
	METHOD(task_manager_t, initiate, status_t,private_task_manager_t *this)
	Message = message_create();
	METHOD(task_manager_t, retransmit, status_t,private_task_manager_t *this, u_int32_t message_id);
	charon->sender->send(charon->sender, packet);
	ike_init_t *ike_init_create(ike_sa_t *ike_sa, bool initiator, ike_sa_t *old_sa);
	static status_t build_i(private_ike_init_t *this, message_t *message);*/
	/*atic status_t process_i(private_ike_init_t *this, message_t *message);*/
	close(sock);
	return 0;
}

static char* connection_name(starter_conn_t *conn)
{
        /* if connection name is '%auto', create a new name like conn_xxxxx */
        static char buf[32];

        if (streq(conn->name, "%auto"))
        {
                sprintf(buf, "conn_%lu", conn->id);
                return buf;
        }
        return conn->name;
}

static void starter_stroke_add_end(stroke_msg_t *msg, stroke_end_t *msg_end)
{
        msg_end->auth = push_string(msg, "%any");
        msg_end->auth2 = push_string(msg, "%any");
        msg_end->id = push_string(msg, "%any");
        msg_end->id2 = push_string(msg, "%any");
        msg_end->rsakey = push_string(msg, "%any");
        msg_end->cert = push_string(msg, "%any");
        msg_end->cert2 = push_string(msg, "%any");
        msg_end->cert_policy = push_string(msg, "%any");
        msg_end->ca = push_string(msg, "%any");
        msg_end->ca2 = push_string(msg, "%any");
        msg_end->groups = push_string(msg,"%any");
        msg_end->updown = push_string(msg, "%any");
	msg_end->address = push_string(msg, "%any");
       
        /*else
        {
                msg_end->address = push_string(msg, "%any");
        //}*/
        /*msg_end->ikeport = push_string(msg, "%any");*/
        msg_end->subnets = push_string(msg, "%any");
        msg_end->sourceip = push_string(msg, "%any");
       /* msg_end->sourceip_mask = push_string(msg, "%any");*/
       /*msg_end->sendcert = push_string(msg, "%any");*/
       /*sg_end->hostaccess = push_string(msg, "%any");*/
        /*msg_end->tohost = !conn_end->subnet;
        msg_end->allow_any = conn_end->allow_any;
        msg_end->protocol = conn_end->protocol;
        msg_end->port = conn_end->port;*/
}

static int add_connection(char *name,int version,int mode,int mobike,int aggressive,int force_encap,int ipcomp,char *algorithms,int dpd_delay,int dpd_timeout,int dpd_action,char *sourceip,char *destinationip,char *auth)
{
	stroke_msg_t msg;
        memset(&msg, 0, sizeof(msg));
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.type = STR_ADD_CONN;
	msg.add_conn.name = push_string(&msg, name);
	msg.add_conn.version = version;
	msg.add_conn.mode = mode;
	msg.add_conn.mobike = mobike;
	msg.add_conn.aggressive = aggressive;
        msg.add_conn.ipcomp = force_encap;
        msg.add_conn.algorithms.ike = push_string(&msg, algorithms);
        msg.add_conn.algorithms.esp = push_string(&msg, algorithms);
	msg.add_conn.dpd.delay = dpd_delay;
        msg.add_conn.dpd.timeout = dpd_timeout;
        msg.add_conn.dpd.action = dpd_action;     
        starter_stroke_add_end(&msg, &msg.add_conn.me);
        starter_stroke_add_end(&msg, &msg.add_conn.other);
	return send_stroke_msg(&msg);
	
}

static int del_connection(char *name)
{
	stroke_msg_t msg;

	msg.length = offsetof(stroke_msg_t, buffer);
	msg.type = STR_DEL_CONN;
	msg.initiate.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int initiate_connection(char *name)
{
	stroke_msg_t msg;

	msg.length = offsetof(stroke_msg_t, buffer);
	msg.type = STR_INITIATE;
	msg.initiate.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int terminate_connection(char *name)
{
	stroke_msg_t msg;

	msg.type = STR_TERMINATE;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.initiate.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int terminate_connection_srcip(char *start, char *end)
{
	stroke_msg_t msg;

	msg.type = STR_TERMINATE_SRCIP;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.terminate_srcip.start = push_string(&msg, start);
	msg.terminate_srcip.end = push_string(&msg, end);
	return send_stroke_msg(&msg);
}

static int rekey_connection(char *name)
{
	stroke_msg_t msg;

	msg.type = STR_REKEY;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.rekey.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int route_connection(char *name)
{
	stroke_msg_t msg;

	msg.type = STR_ROUTE;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.route.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int unroute_connection(char *name)
{
	stroke_msg_t msg;

	msg.type = STR_UNROUTE;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.unroute.name = push_string(&msg, name);
	return send_stroke_msg(&msg);
}

static int show_status(stroke_keyword_t kw, char *connection)
{
	stroke_msg_t msg;

	switch (kw)
	{
		case STROKE_STATUSALL:
			msg.type = STR_STATUS_ALL;
			break;
		case STROKE_STATUSALL_NOBLK:
			msg.type = STR_STATUS_ALL_NOBLK;
			break;
		default:
			msg.type = STR_STATUS;
			break;
	}
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.status.name = push_string(&msg, connection);
	return send_stroke_msg(&msg);
}

static int list_flags[] = {
	LIST_PUBKEYS,
	LIST_CERTS,
	LIST_CACERTS,
	LIST_OCSPCERTS,
	LIST_AACERTS,
	LIST_ACERTS,
	LIST_GROUPS,
	LIST_CAINFOS,
	LIST_CRLS,
	LIST_OCSP,
	LIST_ALGS,
	LIST_PLUGINS,
	LIST_ALL
};

static int list(stroke_keyword_t kw, int utc)
{
	stroke_msg_t msg;

	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);
}

static int reread_flags[] = {
	REREAD_SECRETS,
	REREAD_CACERTS,
	REREAD_OCSPCERTS,
	REREAD_AACERTS,
	REREAD_ACERTS,
	REREAD_CRLS,
	REREAD_ALL
};

static int reread(stroke_keyword_t kw)
{
	stroke_msg_t msg;

	msg.type = STR_REREAD;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.reread.flags = reread_flags[kw - STROKE_REREAD_FIRST];
	return send_stroke_msg(&msg);
}

static int purge_flags[] = {
	PURGE_OCSP,
	PURGE_CRLS,
	PURGE_CERTS,
	PURGE_IKE,
};

static int purge(stroke_keyword_t kw)
{
	stroke_msg_t msg;

	msg.type = STR_PURGE;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.purge.flags = purge_flags[kw - STROKE_PURGE_FIRST];
	return send_stroke_msg(&msg);
}

static int export_flags[] = {
	EXPORT_X509,
};

static int export(stroke_keyword_t kw, char *selector)
{
	stroke_msg_t msg;

	msg.type = STR_EXPORT;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.export.selector = push_string(&msg, selector);
	msg.export.flags = export_flags[kw - STROKE_EXPORT_FIRST];
	return send_stroke_msg(&msg);
}

static int leases(stroke_keyword_t kw, char *pool, char *address)
{
	stroke_msg_t msg;

	msg.type = STR_LEASES;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.leases.pool = push_string(&msg, pool);
	msg.leases.address = push_string(&msg, address);
	return send_stroke_msg(&msg);
}

static int memusage()
{
	stroke_msg_t msg;

	msg.type = STR_MEMUSAGE;
	msg.length = offsetof(stroke_msg_t, buffer);
	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;

	msg.type = STR_LOGLEVEL;
	msg.length = offsetof(stroke_msg_t, buffer);
	msg.loglevel.type = push_string(&msg, type);
	msg.loglevel.level = level;
	return send_stroke_msg(&msg);
}

static void exit_error(char *error)
{
	if (error)
	{
		fprintf(stderr, "%s\n", error);
	}
	exit(-1);
}

static void exit_usage(char *error)
{
	printf("Usage:\n");
	printf("  Add a connection:\n");
	printf("    stroke add NAME VERSION MODE Mobike AGRESSIVE FORCEENCAP IPCOMP ALGOS DPD_DELAY DPD_TIMEOUT DPD_action\\\n");
	printf("           SOURCEIP DESTINATIONIP AUTH\n");
	printf("    where: ID is any IKEv2 ID \n");
	printf("           ADDR is a IPv4 address\n");
	printf("           NET is a IPv4 subnet in CIDR notation\n");
	printf("  Delete a connection:\n");
	printf("    stroke delete NAME\n");
	printf("    where: NAME is a connection name added with \"stroke add\"\n");
	printf("  Initiate a connection:\n");
	printf("    stroke up NAME\n");
	printf("    where: NAME is a connection name added with \"stroke add\"\n");
	printf("  Terminate a connection:\n");
	printf("    stroke down NAME\n");
	printf("    where: NAME is a connection name added with \"stroke add\"\n");
	printf("  Terminate a connection by remote srcip:\n");
	printf("    stroke down-srcip START [END]\n");
	printf("    where: START and optional END define the clients source IP\n");
	printf("  Set loglevel for a logging type:\n");
	printf("    stroke loglevel TYPE LEVEL\n");
	printf("    where: TYPE is any|dmn|mgr|ike|chd|job|cfg|knl|net|asn|enc|tnc|imc|imv|pts|tls|lib\n");
	printf("           LEVEL is -1|0|1|2|3|4\n");
	printf("  Show connection status:\n");
	printf("    stroke status\n");
	printf("  Show extended status information:\n");
	printf("    stroke statusall\n");
	printf("  Show extended status information without blocking:\n");
	printf("    stroke statusallnb\n");
	printf("  Show list of authority and attribute certificates:\n");
	printf("    stroke listcacerts|listocspcerts|listaacerts|listacerts\n");
	printf("  Show list of end entity certificates, ca info records  and crls:\n");
	printf("    stroke listcerts|listcainfos|listcrls|listall\n");
	printf("  Show list of supported algorithms:\n");
	printf("    stroke listalgs\n");
	printf("  Reload authority and attribute certificates:\n");
	printf("    stroke rereadcacerts|rereadocspcerts|rereadaacerts|rereadacerts\n");
	printf("  Reload secrets and crls:\n");
	printf("    stroke rereadsecrets|rereadcrls|rereadall\n");
	printf("  Purge ocsp cache entries:\n");
	printf("    stroke purgeocsp\n");
	printf("  Purge CRL cache entries:\n");
	printf("    stroke purgecrls\n");
	printf("  Purge X509 cache entries:\n");
	printf("    stroke purgecerts\n");
	printf("  Purge IKE_SAs without a CHILD_SA:\n");
	printf("    stroke purgeike\n");
	printf("  Export credentials to the console:\n");
	printf("    stroke exportx509 DN\n");
	printf("  Show current memory usage:\n");
	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);
}

int main(int argc, char *argv[])
{
	const stroke_token_t *token;
	int res = 0;

	library_init(NULL);
	atexit(library_deinit);

	if (argc < 2)
	{
		exit_usage(NULL);
	}

	token = in_word_set(argv[1], strlen(argv[1]));

	if (token == NULL)
	{
		exit_usage("unknown keyword");
	}
        /*if (!lib->plugins->load(lib->plugins, NULL,
                        lib->settings->get_str(lib->settings, "stroke.load", NULL)))
        {
                exit(LSB_RC_FAILURE);
        }*/
        if (lib->settings->get_str(lib->settings, "charon.load", NULL))
                {
                        DBG1(DBG_APP, "!! Your strongswan.conf contains manual plugin load options for charon.");
                        DBG1(DBG_APP, "!! This is recommended for experts only, see");
                        DBG1(DBG_APP, "!! http://wiki.strongswan.org/projects/strongswan/wiki/PluginLoad";);
                }
        
	switch (token->kw)
	{
		case STROKE_ADD:
			if (argc < 11)
			{
				exit_usage("\"add\" needs more parameters...");
			}
			res = add_connection(argv[2],atoi(argv[3]),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]),atoi(argv[7]),atoi(argv[8]),argv[9],atoi(argv[10]),atoi(argv[11]),atoi(argv[12]),argv[13], argv[14],argv[15]);
			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_DOWN_SRCIP:
			if (argc < 3)
			{
				exit_usage("\"down-srcip\" needs start and optional end address");
			}
			res = terminate_connection_srcip(argv[2], argc > 3 ? argv[3] : NULL);
			break;
		case STROKE_REKEY:
			if (argc < 3)
			{
				exit_usage("\"rekey\" needs a connection name");
			}
			res = rekey_connection(argv[2]);
			break;
		case STROKE_ROUTE:
			if (argc < 3)
			{
				exit_usage("\"route\" needs a connection name");
			}
			res = route_connection(argv[2]);
			break;
		case STROKE_UNROUTE:
			if (argc < 3)
			{
				exit_usage("\"unroute\" needs a connection name");
			}
			res = unroute_connection(argv[2]);
			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:
		case STROKE_STATUSALL_NOBLK:
			res = show_status(token->kw, argc > 2 ? argv[2] : NULL);
			break;
		case STROKE_LIST_PUBKEYS:
		case STROKE_LIST_CERTS:
		case STROKE_LIST_CACERTS:
		case STROKE_LIST_OCSPCERTS:
		case STROKE_LIST_AACERTS:
		case STROKE_LIST_ACERTS:
		case STROKE_LIST_CAINFOS:
		case STROKE_LIST_CRLS:
		case STROKE_LIST_OCSP:
		case STROKE_LIST_ALGS:
		case STROKE_LIST_PLUGINS:
		case STROKE_LIST_ALL:
			res = list(token->kw, argc > 2 && strcmp(argv[2], "--utc") == 0);
			break;
		case STROKE_REREAD_SECRETS:
		case STROKE_REREAD_CACERTS:
		case STROKE_REREAD_OCSPCERTS:
		case STROKE_REREAD_AACERTS:
		case STROKE_REREAD_ACERTS:
		case STROKE_REREAD_CRLS:
		case STROKE_REREAD_ALL:
			res = reread(token->kw);
			break;
		case STROKE_PURGE_OCSP:
		case STROKE_PURGE_CRLS:
		case STROKE_PURGE_CERTS:
		case STROKE_PURGE_IKE:
			res = purge(token->kw);
			break;
		case STROKE_EXPORT_X509:
			if (argc != 3)
			{
				exit_usage("\"exportx509\" needs a distinguished name");
			}
			res = export(token->kw, argv[2]);
			break;
		case STROKE_LEASES:
			res = leases(token->kw, argc > 2 ? argv[2] : NULL,
						 argc > 3 ? argv[3] : NULL);
			break;
		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);
	}
	return res;
}
_______________________________________________
Dev mailing list
[email protected]
https://lists.strongswan.org/mailman/listinfo/dev

Reply via email to