Skip to content

Commit b6ff35c

Browse files
authored
Merge pull request #68 from RobSanders/libcli_1_10_5_staging
Merge version 1.10.5 staging from my devel fork
2 parents 65b98fc + 782a388 commit b6ff35c

File tree

6 files changed

+238
-61
lines changed

6 files changed

+238
-61
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PREFIX = /usr/local
1111

1212
MAJOR = 1
1313
MINOR = 10
14-
REVISION = 4
14+
REVISION = 5
1515
LIB = libcli.so
1616
LIB_STATIC = libcli.a
1717

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

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ $ make
1111
$ make install
1212
```
1313

14+
Note - as of version 1.10.5 you have a compile time decision on using select()
15+
or poll() in cli_loop(). The default is to use the legacy 'select()' call.
16+
If built with 'CFLAGS=-DLIBCLI_USE_POLL make' then the poll() system call will
17+
be used instead. One additional check is being made now in cli_loop() to
18+
ensure that the passed file descriptor is in range. If not, an error message
19+
will be sent and the cli_loop() will exit in the child process with CLI_ERROR.
20+
1421
This will install `libcli.so` into `/usr/local/lib`. If you want to change the
1522
location, edit Makefile.
1623

@@ -102,7 +109,9 @@ using `cli_set_context(cli, context)` and `cli_get_context(cli)` functions.
102109
You are responsible for accepting a TCP connection, and for creating a
103110
process or thread to run the cli. Once you are ready to process the
104111
connection, call `cli_loop(cli, sock)` to interact with the user on the
105-
given socket.
112+
given socket. Note that as mentioned above, if the select() call is used and
113+
sock is out of range (>= FD_SETSIZE) then cli_loop() will display an error in
114+
both the parent process and to the remote TCP connection before exiting that routine.
106115
107116
This function will return when the user exits the cli, either by breaking the
108117
connection or entering `quit`.

clitest.c

+46
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,25 @@ int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const
329329
return CLI_OK;
330330
}
331331

332+
int cmd_deep_dive(struct cli_def *cli, const char *command, char *argv[], int argc) {
333+
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
334+
return CLI_OK;
335+
}
336+
337+
int int_validator(struct cli_def *cli, const char *name, const char *value) {
338+
// Verify 'value' is a positive number
339+
long len;
340+
char *endptr;
341+
int rc = CLI_OK;
342+
343+
printf("int_validator called\n");
344+
errno = 0;
345+
len = strtol(value, &endptr, 10);
346+
if ((endptr == value) || (*endptr != '\0') || ((errno == ERANGE) && ((len == LONG_MIN) || (len == LONG_MAX))))
347+
return CLI_ERROR;
348+
return rc;
349+
}
350+
332351
int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc) {
333352
int i;
334353
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
@@ -340,6 +359,17 @@ int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc)
340359
}
341360
return CLI_OK;
342361
}
362+
int cmd_long_name(struct cli_def *cli, const char *command, char *argv[], int argc) {
363+
int i;
364+
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
365+
cli_print(cli, "Value for text argument is <%s>", cli_get_optarg_value(cli, "text", NULL));
366+
367+
cli_print(cli, "Found %d 'extra' arguments after 'text' argument was processed", argc);
368+
for (i = 0; i != argc; i++) {
369+
cli_print(cli, " Extra arg %d = <%s>", i + 1, argv[i]);
370+
}
371+
return CLI_OK;
372+
}
343373

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

481+
struct cli_command *d1, *d2, *d3;
482+
483+
d1 = cli_register_command(cli, NULL, "deep", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "top level deep dive cmd");
484+
d2 = cli_register_command(cli, d1, "dive", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "mid level dep dive cmd");
485+
d3 = cli_register_command(cli, d2, "cmd", cmd_deep_dive, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
486+
"bottom level dep dive cmd");
487+
o = cli_register_optarg(d3, "howdeep", CLI_CMD_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Specify how deep", NULL,
488+
int_validator, NULL);
489+
o = cli_register_optarg(d3, "howlong", CLI_CMD_OPTIONAL_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
490+
"Specify how long", NULL, int_validator, NULL);
491+
492+
c = cli_register_command(
493+
cli, NULL, "serioously_long_cammand_to_test_with", cmd_long_name, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
494+
"show long command name with "
495+
"newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case");
496+
451497
cli_set_auth_callback(cli, check_auth);
452498
cli_set_enable_callback(cli, check_enable);
453499
// Test reading from a file

0 commit comments

Comments
 (0)