Giter Site home page Giter Site logo

dparrish / libcli Goto Github PK

View Code? Open in Web Editor NEW
289.0 289.0 143.0 446 KB

Libcli provides a shared library for including a Cisco-like command-line interface into other software. It's a telnet interface which supports command-line editing, history, authentication and callbacks for a user-definable function tree.

Home Page: https://dparrish.com/link/libcli

License: GNU Lesser General Public License v2.1

Makefile 1.72% C 98.28%

libcli's People

Contributors

amishhammer avatar belge-sel avatar ddeka2910 avatar dparrish avatar geoffgarside avatar jackdanielz avatar jcowgill avatar jereleppanen avatar jmtaylor90 avatar lifang-zhang avatar orgads avatar robsanders avatar sfriesel avatar steveglen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libcli's Issues

Make libcli 'case sensitive' for handling completors

Currently libcli is basically doing case insensitive checks for all command lookups and '' or '' actions, as well as for the completors. Specific to commands you cannot currently have a command "delete" and one "DELETE" within the same mode. If the commands were 'Delete' and 'declutter' for example, the command name will be correctly display and selected if enough case insensitive characters were entered to resolve one or the other.

For completors it appears to be a bit different. If your set of potential completors could contain entries that differ only in case (one example being a completor for selecting a single file from a Linux directory) if there are entries that differ only in case, then using tab completion you will only be able to get one or the other, depending on which one appears first in the completor entries.

A possible quick fix is to change the strncasecmp() command near line 1506 in libcli.c (1.10.7 version) to be a strncmp(). This makes the main 'see where entries differ' be case sensitive.

Initial testing this did not seem to break anything, and preserves the current 'commands are case insensitive' behavior.

Constant Memory leak found at this trace

Constant Memory leak found at this trace.
Every time we try to search in CLI,

==7781== LEAK SUMMARY:

==7781== definitely lost: 114 bytes in 20 blocks
==7781== 114 bytes in 20 blocks are definitely lost in loss record 85 of 90

Trace

==7781== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7781== by 0x4E3971F: cli_parse_line.constprop.5 (libcli.c:670)
==7781== by 0x4E3CD13: cli_loop (libcli.c:989)
==7781== by 0x4010A1: main (in /home/kalyan/cloutra/src/cli/a.out)

Segfault on ambiguous optarg during tab/help parsing

Found a segfault condition during tab/help parsing. Suppose a command has two optional arguments 'opt1' and 'opt2'. If the command line is "command opt" this will segfault. Problem has been identified and will be fixed in 1.10.4, to be release very shortly.

Get all strings entered in a submode

I want to create a submode for the user to enter a sequence of strings. They are arbitrary strings and not predetermined keywords. The strings should be processed by a supplied function line by line. Can I do this with libcli ?

Build failure on darwin: `error: implicit declaration of function 'strchrnul' is invalid in C99`

Noticed by @bobby285271 in NixOS/nixpkgs#147749 when we attempted to update libcli in NixOS.

Build fails on Darwin libc as:

libcli.c:2521:41: error: implicit declaration of function 'strchrnul' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  if (help && !(c->help = strndup(help, strchrnul(help, '\v') - help))) {

Full build log: https://logs.nix.ci/?key=nixos/nixpkgs.147749&attempt_id=54ba70b3-6044-4233-ab14-a2ecea5c68e8

Looks like strchrnul() needs to be avoided on non-GNU systems.

Licence doubt

Can i copy the project to another project and use directly the .h and .c importing the .h file in a non-free software?
There are some limitations to do this?

help ? hangs cli

start cli using telnet 8000, provide username/password. now use command "help ?" or using "help ". This will hang the cli.

how to access global variable within the command function?

Hi. I have a question while testing the library. I would like to know how to access global variables within the command function registered through the cli_register_command().

If the value of the global variable changed inside main() is printed using cli_print() in the command function, it is not reflected, and on the contrary, the value of the global variable changed inside the command function is not properly displayed in main().
Also, is there a way to telnet output using cli_print() inside another function not registered through cli_register_command()?

Do you ever have a similar problem?

Tag 1.9.5 Release

Hi David,

Would you mind tagging the 1.9.5 release?

I'm submitting a patch for the FreeBSD port and I'd prefer to use the Github download URL.

Out of kindness to the portmaintainers, would you mind using the 'v1.9.5' format for tagging?

Thanks!

-Erik

does libcli support concatinated command+arg?

Say I have the following command under config term subtree:

interface eth0 ip 1.1.1.1 mask-len 24

where eth0, 1.1.1.1 and 24 are filtered results after I type the corresponding command.

Currently, if I create an "interface" command with an argument of interface name, then create an "ip" command with the "interface" command as its parent, when the cli runs it will skip the interface name parameter but goes directly to "ip", e.g.

"interface ?" will show "interface ip" as the only help string.

Thanks

No version defines in libcli.h

Hi,

There are no version number defines in libcli.h

This makes it hard for consumers to work out what version of the command callback prototype to use.

The change between 0.9.5 and 0.9.6 for example broke the razorback builds.

For this release I guess I will have to implement version checks with compile tests in autoconf.

Please provide real distfiles

Hi,

I am maintaining a freebsd port for libcli. but in order to be able to provide it we need a real distfile.

github guys also think that the tags aren't clean distfiles:
http://support.github.com/discussions/repos/4017-tags-and-distfile-generation-issues

The main problem for us is the http redirection. With true distfiles we can access a directly link with no redirection: cloud.github.com with tags we can't plus the checksum changes each time the tarball associated to the tag is regenerated by github.

Thanks
Bapt

git clone checkout failure

I think somehow you messed up your repository..

git clone git://github.com/dparrish/libcli.git
Initialized empty Git repository in /home/karl/Work/libcli/.git/
remote: Counting objects: 494, done.
remote: Compressing objects: 100% (405/405), done.
remote: Total 494 (delta 51), reused 435 (delta 8)
Receiving objects: 100% (494/494), 576.42 KiB | 173 KiB/s, done.
Resolving deltas: 100% (51/51), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

Visual Studio support

Please can someone clarify to me the state of Visual Studio support?

It seems that this library doesn't build out of the box with VS2019. There are many issues, the most blatant being the unguarded #include <unistd.h>. However, there's an awful lot of #ifndef WIN32 in the source code, as if at some point, some version of this library worked with some version of Visual Studio.

libcli with nc

Can we make libcli to work with 'nc - netcat ' ? I tried connecting with nc, it connects but output is not displayed.

Suggestion for SSH

Hi,

Any suggestion for SSH support?
Is this outside libcli?

Regards,

Bandu

Correct quote parsing and allow for 'escaping' quotes

Currently cli_parse_line() is not correctly several types of lines with quotes. For example (ignore quotes for the 'parsed' output):

  • mixed double and single quotes
    show 'alpha"bravo" charlie'
    parsed as 3 words (1)"show" (2)"bravo" (3)<emptystring>
  • lines with non-whitespace immediately before or after the quoted string
    show alpha,"bravo",charlie
    parsed as 3 words (1)"show" (2)"bravo" (3)",charlie"
  • no way to 'escape' a quote within a quoted string
    show "alpha,"bravo",charlie"
    parsed as 3 words (1)"show" (2)"alpha," (3)",charlie"

Note that in all 3 cases text is lost. Ideally libcli should support:

  • balanced quotes (accept all characters until next matching quote found)
  • escaping a quote using the '\' character so it is treated as a literal (deal with escaping the escape as well)

Open question on how two properly quoted strings without whitespace separating them should be handled. Combined into a single string, or converted into two separate tokens?

ssh support

Hello
What do you think about different telnet, ssh support depending on the compilation options?
Is there an additional plan for ssh support?

conflict for c++ keyword

the word 'try' is keyword of c++, i modify it and now compile ok:

static int pass_matches(const char _pass, const char _try)
{
int des;
if ((des = !strncasecmp(pass, DES_PREFIX, sizeof(DES_PREFIX)-1)))
pass += sizeof(DES_PREFIX)-1;

ifndef WIN32

/*
 * TODO - find a small crypt(3) function for use on windows
 */
if (des || !strncmp(pass, MD5_PREFIX, sizeof(MD5_PREFIX)-1))
    **try** = crypt(**try**, pass);

endif

return !strcmp(pass, **try**);

}

filter abbreviations gives unexpected results

If as a a filter I give "| e" egrep is chosen although the e also could match exclude
I had expected an error or autocompletion hint.
I suspect I got egrep because it is alphabetically first.

Example:

router> show counters | e call
called cmd_test with "show counters"

router> show counters | eg call
called cmd_test with "show counters"

router> show counters | ex call
0 arguments:

I suspect something similar will happen with "b" as it can match begin and between

invalid command message not extremely appropriate

Example with clitest

router> show something
Invalid command "show"

Actually the invalid command is not "show", it is the "something" part that causes the problem.
Better error message would be:
Invalid command "show something"
or maybe
Invalid command "something"

Endless Loop During Command Search

Hi all,

I found the following issue with the libcli. Entering a mode and issuing the same command by mistake, causes the main loop to hang forever. This can be simply reproduced with the test program, as shown below:

$ telnet 127.0.0.1 8000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
libcli test environment

Username: fred
Password:  

router> enable
Password: 
router# configure terminal 

router(config)# interface test0/0

router(config-test)# interface

At this point, the CLI hangs and won't return a prompt.

I did some research by myself and think there's something wrong here:

libcli/libcli.c

Line 2913 in b6ff35c

if (again_config) {

As a workaround, I removed this check and it works for me so far.

Best regards,
Stefan Mächler

command completion does not work on filters

command completion for filters does not work as expected

E.g. build clitest, run it, telnet to it then do
show counters |
followed by tab -> no completion, no alternatives (also not after pressing tab a second time
show counters | g
followed by tab -> as above
show counters |
followed by ? -> gives a list of all options (as expected)
show counters | g
followed by ? -> again gist a list of all alternatives. I had expected only filters starting with g (just like happens with commands)

libcli without telnet

Hi
Is there any way I can use libcli without using telnet?
I'm wondering it is possible that run a program like clitest and it displays login screen directly without using telnet session and access cli commands.

Thanks,

CLI_CMD_OPTIONAL_FLAG does not honor user supplied completor callback

As initially coded a CLI_CMD_OPTIONAL_FLAG item will only tab complete the name of the optional flag. This works for some arguments 'as-is', such as for a optarg named 'verbose'. However if there there are multiple acceptable 'answers' (true, True, yes, 1, verbose for example), the tab completion will not recognized them and this can impact parsing.

Add option to not send telnet negotiation

When using libcli as a backend for a libssh based console server the telnet negotiation sequence causes junk to be printed on the terminal at the beginning of the cli_loop. It would be nice to have an option to say that we a not a real telnet session.

backspace works only in one line

on linux centos or redhat 7, run ./testcli and telnet 127.0.0.1 8000 locally. under
Uername: or router> prompt, type very long chars more than 1 line and then hit Backspace, it can't go back to previous line and stuck at the beginning of second line.

New user

Hello, how I can add the new user? Should I use cli_allow_user and cli_allow_enable?
Best regards.

? leads to execution of command

With clitest I did enter "show counters ?"
This could e.g. happen if a user is entering show counters and assumes there is an actual argument.
However instead of some help the command is immediately executed (no return pressed).
It seems not correct that the command is executed just by pressing ?

from the log:

router> show counters
called cmd_test with "show counters"
1 arguments:
?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.