Skip to content

Commit

Permalink
Merge pull request #68 from RobSanders/libcli_1_10_5_staging
Browse files Browse the repository at this point in the history
Merge version 1.10.5 staging from my devel fork
  • Loading branch information
RobSanders authored Feb 8, 2021
2 parents 65b98fc + 782a388 commit b6ff35c
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PREFIX = /usr/local

MAJOR = 1
MINOR = 10
REVISION = 4
REVISION = 5
LIB = libcli.so
LIB_STATIC = libcli.a

Expand Down Expand Up @@ -79,7 +79,7 @@ install: $(TARGET_LIBS)
rpmprep:
rm -rf libcli-$(MAJOR).$(MINOR).$(REVISION)
mkdir libcli-$(MAJOR).$(MINOR).$(REVISION)
cp -R libcli.{c,h} libcli.spec clitest.c Makefile COPYING README.md doc libcli-$(MAJOR).$(MINOR).$(REVISION)
cp -R libcli.c libcli.h libcli.spec clitest.c Makefile COPYING README.md doc libcli-$(MAJOR).$(MINOR).$(REVISION)
tar zcvf libcli-$(MAJOR).$(MINOR).$(REVISION).tar.gz --exclude CVS --exclude *.tar.gz libcli-$(MAJOR).$(MINOR).$(REVISION)
rm -rf libcli-$(MAJOR).$(MINOR).$(REVISION)

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ $ make
$ make install
```

Note - as of version 1.10.5 you have a compile time decision on using select()
or poll() in cli_loop(). The default is to use the legacy 'select()' call.
If built with 'CFLAGS=-DLIBCLI_USE_POLL make' then the poll() system call will
be used instead. One additional check is being made now in cli_loop() to
ensure that the passed file descriptor is in range. If not, an error message
will be sent and the cli_loop() will exit in the child process with CLI_ERROR.

This will install `libcli.so` into `/usr/local/lib`. If you want to change the
location, edit Makefile.

Expand Down Expand Up @@ -102,7 +109,9 @@ using `cli_set_context(cli, context)` and `cli_get_context(cli)` functions.
You are responsible for accepting a TCP connection, and for creating a
process or thread to run the cli. Once you are ready to process the
connection, call `cli_loop(cli, sock)` to interact with the user on the
given socket.
given socket. Note that as mentioned above, if the select() call is used and
sock is out of range (>= FD_SETSIZE) then cli_loop() will display an error in
both the parent process and to the remote TCP connection before exiting that routine.
This function will return when the user exits the cli, either by breaking the
connection or entering `quit`.
Expand Down
46 changes: 46 additions & 0 deletions clitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,25 @@ int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const
return CLI_OK;
}

int cmd_deep_dive(struct cli_def *cli, const char *command, char *argv[], int argc) {
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
return CLI_OK;
}

int int_validator(struct cli_def *cli, const char *name, const char *value) {
// Verify 'value' is a positive number
long len;
char *endptr;
int rc = CLI_OK;

printf("int_validator called\n");
errno = 0;
len = strtol(value, &endptr, 10);
if ((endptr == value) || (*endptr != '\0') || ((errno == ERANGE) && ((len == LONG_MIN) || (len == LONG_MAX))))
return CLI_ERROR;
return rc;
}

int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc) {
int i;
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
Expand All @@ -340,6 +359,17 @@ int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc)
}
return CLI_OK;
}
int cmd_long_name(struct cli_def *cli, const char *command, char *argv[], int argc) {
int i;
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
cli_print(cli, "Value for text argument is <%s>", cli_get_optarg_value(cli, "text", NULL));

cli_print(cli, "Found %d 'extra' arguments after 'text' argument was processed", argc);
for (i = 0; i != argc; i++) {
cli_print(cli, " Extra arg %d = <%s>", i + 1, argv[i]);
}
return CLI_OK;
}

void run_child(int x) {
struct cli_command *c;
Expand Down Expand Up @@ -448,6 +478,22 @@ void run_child(int x) {
cli_register_command(cli, NULL, "context", cmd_context, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
"Test a user-specified context");

struct cli_command *d1, *d2, *d3;

d1 = cli_register_command(cli, NULL, "deep", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "top level deep dive cmd");
d2 = cli_register_command(cli, d1, "dive", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "mid level dep dive cmd");
d3 = cli_register_command(cli, d2, "cmd", cmd_deep_dive, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
"bottom level dep dive cmd");
o = cli_register_optarg(d3, "howdeep", CLI_CMD_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Specify how deep", NULL,
int_validator, NULL);
o = cli_register_optarg(d3, "howlong", CLI_CMD_OPTIONAL_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
"Specify how long", NULL, int_validator, NULL);

c = cli_register_command(
cli, NULL, "serioously_long_cammand_to_test_with", cmd_long_name, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
"show long command name with "
"newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case");

cli_set_auth_callback(cli, check_auth);
cli_set_enable_callback(cli, check_enable);
// Test reading from a file
Expand Down
Loading

0 comments on commit b6ff35c

Please sign in to comment.