diff --git a/libraries/Terminal/LoginShell.cpp b/libraries/Terminal/LoginShell.cpp index 764e8087..acc2968f 100644 --- a/libraries/Terminal/LoginShell.cpp +++ b/libraries/Terminal/LoginShell.cpp @@ -44,7 +44,7 @@ * \return Returns zero or greater if the username and password combination * is correct, negative if incorrect. * - * The return value is reported to the application as LoginShell::userid(), + * 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. @@ -55,7 +55,7 @@ * based on failed login attempts. * * \relates LoginShell - * \sa LoginShell::userid() + * \sa Shell::userid() */ /** @@ -67,7 +67,6 @@ LoginShell::LoginShell() : machName(0) , checkFunc(0) - , uid(-1) { } @@ -77,15 +76,3 @@ LoginShell::LoginShell() LoginShell::~LoginShell() { } - -/** - * \fn int LoginShell::userid() const - * \brief Gets the user identifier for the currently logged in user, - * or -1 if there is no user logged in currently. - * - * The user identifier can be used by applications 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. - * - * \sa ShellPasswordCheckFunc - */ diff --git a/libraries/Terminal/LoginShell.h b/libraries/Terminal/LoginShell.h index c52e9140..1811fe05 100644 --- a/libraries/Terminal/LoginShell.h +++ b/libraries/Terminal/LoginShell.h @@ -39,8 +39,6 @@ public: ShellPasswordCheckFunc passwordCheckFunction() const { return checkFunc; } void setPasswordCheckFunction(ShellPasswordCheckFunc function) { checkFunc = function; } - int userid() const { return uid; } - protected: virtual void beginSession(); virtual void printPrompt(); @@ -49,7 +47,6 @@ protected: private: const char *machName; ShellPasswordCheckFunc checkFunc; - int uid; }; #endif diff --git a/libraries/Terminal/Shell.cpp b/libraries/Terminal/Shell.cpp index 9279451f..e4c10f94 100644 --- a/libraries/Terminal/Shell.cpp +++ b/libraries/Terminal/Shell.cpp @@ -130,6 +130,7 @@ Shell::Shell() , prom("$ ") , isClient(false) , lineMode(LINEMODE_NORMAL | LINEMODE_ECHO) + , uid(-1) , timer(0) { } @@ -243,6 +244,7 @@ bool Shell::beginShell(Stream &stream, size_t maxHistory, Terminal::Mode mode) curMax = sizeof(buffer); historyWrite = 0; historyRead = 0; + uid = -1; // Begins the login session. beginSession(); @@ -271,6 +273,7 @@ void Shell::end() historySize = 0; isClient = false; lineMode = LINEMODE_NORMAL | LINEMODE_ECHO; + uid = -1; } /** @cond */ @@ -507,6 +510,32 @@ void Shell::registerCommand(ShellCommandRegister *cmd) * \sa prompt() */ +/** + * \fn int Shell::userid() const + * \brief Gets the user identifier for the currently logged in user, + * or -1 if there is no user logged in currently. + * + * The user identifier can be used by applications 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. + * + * \sa setUserid(), ShellPasswordCheckFunc + */ + +/** + * \fn void Shell::setUserid(int userid) + * \brief Sets the user identifier for the currently logged in user. + * + * \param userid The new user identifier to set, or -1 if there is no + * user logged in currently. + * + * Normally the user identifier is set when LoginShell detects a + * successful login. This function can be used to alter the access + * rights of the logged-in user after login. + * + * \sa userid(), ShellPasswordCheckFunc + */ + /** * \brief Displays help for all supported commands. */ @@ -548,6 +577,7 @@ void Shell::help() void Shell::exit() { Stream *stream = this->stream(); + uid = -1; if (isClient) { end(); ((Client *)stream)->stop(); @@ -931,7 +961,6 @@ void LoginShell::beginSession() curStart = 0; curLen = 0; curMax = sizeof(buffer) / 2; - uid = -1; } /** diff --git a/libraries/Terminal/Shell.h b/libraries/Terminal/Shell.h index d5e962f7..16f6c99b 100644 --- a/libraries/Terminal/Shell.h +++ b/libraries/Terminal/Shell.h @@ -76,6 +76,9 @@ public: const char *prompt() const { return prom; } void setPrompt(const char *prompt) { prom = prompt; } + int userid() const { return uid; } + void setUserid(int userid) { uid = userid; } + void help(); void exit(); @@ -96,6 +99,7 @@ private: const char *prom; bool isClient; uint8_t lineMode; + int uid; unsigned long timer; // Disable copy constructor and operator=().