• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

COPYINGH A D07-Jun-201225.9 KiB511422

MakefileH A D03-May-20221.9 KiB6047

READMEH A D07-Jun-20123.7 KiB11370

clitest.cH A D07-Jun-20129.1 KiB345272

libcli.cH A D03-May-202259.7 KiB2,3431,892

libcli.hH A D07-Jun-20124.7 KiB133110

libcli.specH A D07-Jun-20125.8 KiB154123

README

1libcli
2
3libcli emulates a cisco style telnet command-line interface.
4
5To compile:
6
7	make
8	make install
9
10This will install libcli.so into /usr/local/lib. If you want to change
11the location, edit Makefile.
12
13There is a test application built called clitest. Run this and telnet
14to port 8000.
15
16By default, a single username and password combination is enabled.
17
18Username: fred
19Password: nerk
20
21Get help by entering "help" or hitting ?.
22
23libcli provides support for using the arrow keys for command-line editing. Up
24and Down arrows will cycle through the command history, and Left & Right can be
25used for editing the current command line.
26libcli also works out the shortest way of entering a command, so if you have a
27command "show users grep foobar" defined, you can enter "sh us g foobar" if that
28is the shortest possible way of doing it.
29
30Enter "sh?" at the command line to get a list of commands starting with "sh"
31
32A few commands are defined in every libcli program:
33help
34quit
35exit
36logout
37history
38
39
40
41
42Use in your own code:
43
44First of all, make sure you #include <libcli.h> in your C code, and link
45with -lcli.
46
47If you have any trouble with this, have a look at clitest.c for a
48demonstration.
49
50Start your program off with a cli_init().
51This sets up the internal data structures required.
52
53When a user connects, they are presented with a greeting if one is set using the
54cli_set_banner(banner) function.
55
56
57By default, the command-line session is not authenticated, which means users
58will get full access as soon as they connect. As this may not be always the best
59thing, 2 methods of authentication are available.
60
61First, you can add username / password combinations with the
62cli_allow_user(username, password) function. When a user connects, they can
63connect with any of these username / password combinations.
64
65Secondly, you can add a callback using the cli_set_auth_callback(callback)
66function. This function is passed the username and password as char *, and must
67return CLI_OK if the user is to have access and CLI_ERROR if they are not.
68
69The library itself will take care of prompting the user for credentials.
70
71
72
73
74Commands are built using a tree-like structure. You define commands with the
75cli_register_command(parent, command, callback, privilege, mode, help) function.
76
77parent is a cli_command * reference to a previously added command. Using a
78parent you can build up complex commands.
79e.g. to provide commands "show users", "show sessions" and "show people", use
80the following sequence:
81
82cli_command *c = cli_register_command(NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
83cli_register_command(c, "sessions", fn_sessions, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the sessions connected");
84cli_register_command(c, "users", fn_users, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the users connected");
85cli_register_command(c, "people", fn_people, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of the people I like");
86
87
88If callback is NULL, the command can be used as part of a tree, but cannot be
89individually run.
90
91
92If you decide later that you don't want a command to be run, you can call
93cli_unregister_command(command).
94You can use this to build dynamic command trees.
95
96
97It is possible to carry along a user-defined context to all command callbacks
98using cli_set_context(cli, context) and cli_get_context(cli) functions.
99
100
101You are responsible for accepting a TCP connection, and for creating a
102process or thread to run the cli.  Once you are ready to process the
103connection, call cli_loop(cli, sock) to interact with the user on the
104given socket.
105
106This function will return when the user exits the cli, either by breaking the
107connection or entering "quit".
108
109Call cli_done() to free the data structures.
110
111
112- David Parrish (david@dparrish.com)
113