ArduinoLibs
|
Command-line shell access via a login shell. More...
#include <LoginShell.h>
Public Member Functions | |
LoginShell () | |
Constructs a new login shell. More... | |
virtual | ~LoginShell () |
Destroys this login shell. | |
const char * | machineName () const |
Gets the name of the machine to display in the login prompt. More... | |
void | setMachineName (const char *machineName) |
Sets the name of the machine to display in the login prompt. More... | |
ShellPasswordCheckFunc | passwordCheckFunction () const |
Gets the current password checking function, or NULL if the function has not been set yet. More... | |
void | setPasswordCheckFunction (ShellPasswordCheckFunc function) |
Sets the password checking function. More... | |
Public Member Functions inherited from Shell | |
Shell () | |
Constructs a new Shell instance. More... | |
virtual | ~Shell () |
Destroys this Shell object. | |
bool | begin (Stream &stream, size_t maxHistory=0, Terminal::Mode mode=Serial) |
Begin shell handling on an underlying character stream. More... | |
bool | begin (Client &client, size_t maxHistory=0, Terminal::Mode mode=Telnet) |
Begin shell handling on a connected TCP client. More... | |
void | end () |
Ends shell processing on the underlying stream. More... | |
void | loop () |
Performs regular activities on the shell. More... | |
const char * | prompt () const |
Gets the prompt string to display in the shell. More... | |
void | setPrompt (const char *prompt) |
Sets the prompt string to display in the shell. More... | |
int | userid () const |
Gets the user identifier for the currently logged in user, or -1 if there is no user logged in currently. More... | |
void | setUserid (int userid) |
Sets the user identifier for the currently logged in user. More... | |
void | help () |
Displays help for all supported commands. | |
void | exit () |
Exit from the shell back to the login prompt. More... | |
Public Member Functions inherited from Terminal | |
Terminal () | |
Constructs a terminal object. More... | |
virtual | ~Terminal () |
Destroys this terminal object. | |
void | begin (Stream &stream, Mode mode=Serial) |
Begins terminal operations on an underlying stream. More... | |
void | end () |
Ends terminal operations on an underlying stream. More... | |
Stream * | stream () const |
Returns a pointer to the underlying Stream, or NULL if the stream has not been set with begin() yet. More... | |
Terminal::Mode | mode () const |
Returns the mode this terminal is operating in, Serial or Telnet. More... | |
virtual int | available () |
Returns the number of bytes that are available for reading. More... | |
virtual int | peek () |
Peeks at the next byte from the underlying stream. More... | |
virtual int | read () |
Reads the next byte from the underlying stream. More... | |
virtual void | flush () |
Flushes all data in the underlying stream. | |
virtual size_t | write (uint8_t c) |
Writes a single byte to the underlying stream. More... | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
Writes a buffer of data to the underlying stream. More... | |
void | writeProgMem (const char *str) |
Writes a static string that is stored in program memory. More... | |
int | readKey () |
Reads the next key that was typed on this terminal. More... | |
long | unicodeKey () const |
Gets the Unicode version of the last key returned by readKey(). More... | |
size_t | writeUnicode (long code) |
Writes a Unicode code point to the output in UTF-8 encoding. More... | |
int | columns () const |
Gets the number of columns in the window; defaults to 80. More... | |
int | rows () const |
Gets the number of rows in the window; defaults to 24. More... | |
bool | setWindowSize (int columns, int rows) |
Sets the number of columns and rows in the window. More... | |
void | clear () |
Move the cursor to the top-left position and clear the screen. | |
void | clearToEOL () |
Clears from the current cursor position to the end of the line. | |
void | cursorMove (int x, int y) |
Moves the cursor to a specific location in the window. More... | |
void | cursorLeft () |
Moves the cursor left by one character. More... | |
void | cursorRight () |
Moves the cursor right by one character. More... | |
void | cursorUp () |
Moves the cursor up by one line. More... | |
void | cursorDown () |
Moves the cursor down by one line. More... | |
void | backspace () |
Backspaces over the last character. More... | |
void | insertLine () |
Inserts a line at the cursor position. More... | |
void | insertChar () |
Inserts a blank character at the cursor position. More... | |
void | deleteLine () |
Deletes a line at the cursor position. More... | |
void | deleteChar () |
Deletes the character at the cursor position. More... | |
void | scrollUp () |
Scrolls the contents of the window up one line. More... | |
void | scrollDown () |
Scrolls the contents of the window down one line. More... | |
void | normal () |
Selects normal text with all attributes and colors off. More... | |
void | bold () |
Enables bold text. More... | |
void | underline () |
Enables underlined text. | |
void | blink () |
Enables blinking text. | |
void | reverse () |
Reverse the foreground and background colors for inverted text. | |
void | color (Color fg) |
Selects a text foreground color with the default background color. More... | |
void | color (Color fg, Color bg) |
Selects text foreground and background colors. More... | |
Protected Member Functions | |
virtual void | beginSession () |
Begins a login session. | |
virtual void | printPrompt () |
Prints the current prompt string. | |
virtual void | execute () |
Executes the command in the buffer. | |
Related Functions | |
(Note that these are not member functions.) | |
ShellPasswordCheckFunc | |
Password checking function for login shells. More... | |
Related Functions inherited from Shell | |
ShellCommandFunc | |
Type of functions that provide shell command handlers. More... | |
#define | ShellCommand(name, help, function) |
Registers a command with the shell. More... | |
Additional Inherited Members | |
Public Types inherited from Terminal | |
enum | Mode { Serial, Telnet } |
Mode to operate in, Serial or Telnet. More... | |
enum | Color { Black = 0x00, DarkRed = 0x01, DarkGreen = 0x02, DarkYellow = 0x03, DarkBlue = 0x04, DarkMagenta = 0x05, DarkCyan = 0x06, LightGray = 0x07, DarkGray = 0x08, Red = 0x09, Green = 0x0A, Yellow = 0x0B, Blue = 0x0C, Magenta = 0x0D, Cyan = 0x0E, White = 0x0F } |
Terminal foreground or background colors. More... | |
Static Public Member Functions inherited from Shell | |
static void | registerCommand (ShellCommandRegister *cmd) |
Registers a command with the shell. More... | |
Static Public Member Functions inherited from Terminal | |
static bool | isWideCharacter (long code) |
Determine if a Unicode character is wide. More... | |
static size_t | utf8Length (long code) |
Determines the length of a Unicode code point in the UTF-8 encoding. More... | |
static size_t | utf8Format (uint8_t *buffer, long code) |
Formats a Unicode code point in a buffer in the UTF-8 encoding. More... | |
Command-line shell access via a login shell.
This class provides a command-line shell with login support. The user is prompted for username and password when they connect and other commands will not be available until the correct credentials have been supplied.
Definition at line 30 of file LoginShell.h.
LoginShell::LoginShell | ( | ) |
Constructs a new login shell.
This constructor must be followed by a call to begin() to specify the underlying I/O stream.
Definition at line 67 of file LoginShell.cpp.
|
inline |
Gets the name of the machine to display in the login prompt.
The default value is NULL, indicating that no machine name should be shown.
Definition at line 36 of file LoginShell.h.
|
inline |
Gets the current password checking function, or NULL if the function has not been set yet.
Definition at line 39 of file LoginShell.h.
|
inline |
Sets the name of the machine to display in the login prompt.
machineName | The machine name, or NULL for no machine name. |
Definition at line 37 of file LoginShell.h.
|
inline |
Sets the password checking function.
function | The password checking function to set, or NULL to return to the default rules. |
If no function is set, then LoginShell will check for a username of "root" and a password of "arduino" (both values are case-sensitive). This is of course not very secure. Realistic applications should set a proper password checking function.
Definition at line 40 of file LoginShell.h.
|
related |
Password checking function for login shells.
username | Points to the user name that was supplied at login. |
password | Points to the password that was supplied at login. |
The return value is reported to the application as Shell::userid(), which can be used by the application to restrict the set of commands that are available to the user, or to restrict the behaviour of those commands when acting on critical resources.
Timing can be very important: the check should take the same amount of time for valid and invalid user identifiers or passwords so that an attacker cannot gain knowledge about the valid users on the system based on failed login attempts.