Skip to content

Commit

Permalink
Move userid() from LoginShell to Shell
Browse files Browse the repository at this point in the history
  • Loading branch information
rweather committed Mar 12, 2016
1 parent d934324 commit 9ec197a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
17 changes: 2 additions & 15 deletions libraries/Terminal/LoginShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -55,7 +55,7 @@
* based on failed login attempts.
*
* \relates LoginShell
* \sa LoginShell::userid()
* \sa Shell::userid()
*/

/**
Expand All @@ -67,7 +67,6 @@
LoginShell::LoginShell()
: machName(0)
, checkFunc(0)
, uid(-1)
{
}

Expand All @@ -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
*/
3 changes: 0 additions & 3 deletions libraries/Terminal/LoginShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class LoginShell : public Shell
ShellPasswordCheckFunc passwordCheckFunction() const { return checkFunc; }
void setPasswordCheckFunction(ShellPasswordCheckFunc function) { checkFunc = function; }

int userid() const { return uid; }

protected:
virtual void beginSession();
virtual void printPrompt();
Expand All @@ -49,7 +47,6 @@ class LoginShell : public Shell
private:
const char *machName;
ShellPasswordCheckFunc checkFunc;
int uid;
};

#endif
31 changes: 30 additions & 1 deletion libraries/Terminal/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Shell::Shell()
, prom("$ ")
, isClient(false)
, lineMode(LINEMODE_NORMAL | LINEMODE_ECHO)
, uid(-1)
, timer(0)
{
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -271,6 +273,7 @@ void Shell::end()
historySize = 0;
isClient = false;
lineMode = LINEMODE_NORMAL | LINEMODE_ECHO;
uid = -1;
}

/** @cond */
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -548,6 +577,7 @@ void Shell::help()
void Shell::exit()
{
Stream *stream = this->stream();
uid = -1;
if (isClient) {
end();
((Client *)stream)->stop();
Expand Down Expand Up @@ -931,7 +961,6 @@ void LoginShell::beginSession()
curStart = 0;
curLen = 0;
curMax = sizeof(buffer) / 2;
uid = -1;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions libraries/Terminal/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class Shell : public Terminal
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();

Expand All @@ -96,6 +99,7 @@ class Shell : public Terminal
const char *prom;
bool isClient;
uint8_t lineMode;
int uid;
unsigned long timer;

// Disable copy constructor and operator=().
Expand Down

0 comments on commit 9ec197a

Please sign in to comment.