stroke: Add non-blocking versions of up and down

stroke up-nb and stroke down-nb do not block until the command has
finished.  Instead, they return right after initiating the respective
operation.
This commit is contained in:
Tobias Brunner 2013-06-16 16:30:21 +02:00
parent 9afc6e6a70
commit 4182c86aed
3 changed files with 23 additions and 5 deletions

View File

@ -36,6 +36,8 @@ struct stroke_token {
stroke_keyword_t kw;
};
static int output_verbosity = 1; /* CONTROL */
static char* push_string(stroke_msg_t *msg, char *string)
{
unsigned long string_start = msg->length;
@ -61,7 +63,7 @@ static int send_stroke_msg (stroke_msg_t *msg)
ctl_addr.sun_family = AF_UNIX;
strcpy(ctl_addr.sun_path, STROKE_SOCKET);
msg->output_verbosity = 1; /* CONTROL */
msg->output_verbosity = output_verbosity;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
@ -91,11 +93,11 @@ static int send_stroke_msg (stroke_msg_t *msg)
/* we prompt if we receive a magic keyword */
if ((byte_count >= 12 &&
strcmp(buffer + byte_count - 12, "Passphrase:\n") == 0) ||
streq(buffer + byte_count - 12, "Passphrase:\n")) ||
(byte_count >= 10 &&
strcmp(buffer + byte_count - 10, "Password:\n") == 0) ||
streq(buffer + byte_count - 10, "Password:\n")) ||
(byte_count >= 5 &&
strcmp(buffer + byte_count - 5, "PIN:\n") == 0))
streq(buffer + byte_count - 5, "PIN:\n")))
{
/* remove trailing newline */
pass = strrchr(buffer, '\n');
@ -415,9 +417,15 @@ static void exit_usage(char *error)
printf(" Initiate a connection:\n");
printf(" stroke up NAME\n");
printf(" where: NAME is a connection name added with \"stroke add\"\n");
printf(" Initiate a connection without blocking:\n");
printf(" stroke up-nb 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 without blocking:\n");
printf(" stroke down-nb 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");
@ -507,6 +515,9 @@ int main(int argc, char *argv[])
}
res = del_connection(argv[2]);
break;
case STROKE_UP_NOBLK:
output_verbosity = -1;
/* fall-through */
case STROKE_UP:
if (argc < 3)
{
@ -514,6 +525,9 @@ int main(int argc, char *argv[])
}
res = initiate_connection(argv[2]);
break;
case STROKE_DOWN_NOBLK:
output_verbosity = -1;
/* fall-through */
case STROKE_DOWN:
if (argc < 3)
{
@ -573,7 +587,7 @@ int main(int argc, char *argv[])
case STROKE_LIST_ALGS:
case STROKE_LIST_PLUGINS:
case STROKE_LIST_ALL:
res = list(token->kw, argc > 2 && strcmp(argv[2], "--utc") == 0);
res = list(token->kw, argc > 2 && streq(argv[2], "--utc"));
break;
case STROKE_REREAD_SECRETS:
case STROKE_REREAD_CACERTS:

View File

@ -23,7 +23,9 @@ typedef enum {
STROKE_ROUTE,
STROKE_UNROUTE,
STROKE_UP,
STROKE_UP_NOBLK,
STROKE_DOWN,
STROKE_DOWN_NOBLK,
STROKE_DOWN_SRCIP,
STROKE_REKEY,
STROKE_LOGLEVEL,

View File

@ -30,7 +30,9 @@ delete, STROKE_DELETE
route, STROKE_ROUTE
unroute, STROKE_UNROUTE
up, STROKE_UP
up-nb, STROKE_UP_NOBLK
down, STROKE_DOWN
down-nb, STROKE_DOWN_NOBLK
down-srcip, STROKE_DOWN_SRCIP
rekey, STROKE_REKEY
loglevel, STROKE_LOGLEVEL