summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2010-02-21 09:57:26 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2010-02-21 09:57:26 +0100
commite0a45fb42163a6bfdeeee44bd0a6a7461552e10f (patch)
treed0c889a0b98ea7d269e44c1693d5a3fbb6322738 /client
parente304fd4bcf5813b581a39078a25a5cf6916b9f29 (diff)
downloadbird-e0a45fb42163a6bfdeeee44bd0a6a7461552e10f.tar
bird-e0a45fb42163a6bfdeeee44bd0a6a7461552e10f.zip
Restricted read-only CLI.
Also adds support for executing commands using birdc <cmd>.
Diffstat (limited to 'client')
-rw-r--r--client/client.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/client/client.c b/client/client.c
index 88a6095..8f514f6 100644
--- a/client/client.c
+++ b/client/client.c
@@ -25,8 +25,10 @@
#include "client/client.h"
#include "sysdep/unix/unix.h"
-static char *opt_list = "s:v";
+static char *opt_list = "s:vr";
static int verbose;
+static char *init_cmd;
+static int once;
static char *server_path = PATH_CONTROL_SOCKET;
static int server_fd;
@@ -49,7 +51,7 @@ static int num_lines, skip_input, interactive;
static void
usage(void)
{
- fprintf(stderr, "Usage: birdc [-s <control-socket>] [-v]\n");
+ fprintf(stderr, "Usage: birdc [-s <control-socket>] [-v] [-r]\n");
exit(1);
}
@@ -67,11 +69,36 @@ parse_args(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 'r':
+ init_cmd = "restrict";
+ break;
default:
usage();
}
+
+ /* If some arguments are not options, we take it as commands */
if (optind < argc)
- usage();
+ {
+ char *tmp;
+ int i;
+ int len = 0;
+
+ if (init_cmd)
+ usage();
+
+ for (i = optind; i < argc; i++)
+ len += strlen(argv[i]) + 1;
+
+ tmp = init_cmd = malloc(len);
+ for (i = optind; i < argc; i++)
+ {
+ strcpy(tmp, argv[i]);
+ tmp += strlen(tmp);
+ *tmp++ = ' ';
+ }
+
+ once = 1;
+ }
}
/*** Input ***/
@@ -267,6 +294,22 @@ update_state(void)
if (nstate == cstate)
return;
+ if (init_cmd)
+ {
+ /* First transition - client received hello from BIRD
+ and there is waiting initial command */
+ submit_server_command(init_cmd);
+ init_cmd = NULL;
+ return;
+ }
+
+ if (!init_cmd && once)
+ {
+ /* Initial command is finished and we want to exit */
+ cleanup();
+ exit(0);
+ }
+
if (nstate == STATE_PROMPT)
if (input_initialized)
input_reveal();