Skip to content

Commit

Permalink
Support specifying host targets in addUser
Browse files Browse the repository at this point in the history
  • Loading branch information
unix-ninja committed Jan 6, 2017
1 parent 2b269c8 commit 303798e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
60 changes: 54 additions & 6 deletions engine.cpp
Expand Up @@ -1783,16 +1783,64 @@ int addUser(lua_State *lua)

// number of input arguments
int argc = lua_gettop(lua);
if (argc != 2) {
if (argc < 1 || 2 < argc)
{
cout << "Error! Invalid call to addUser." << endl;
exit (ERR_BAD_SET);
}

password = lua_tostring(lua, lua_gettop(lua));
lua_pop(lua, 1);
user = lua_tostring(lua, lua_gettop(lua));
lua_pop(lua, 1);
if (!vPC.back().addUser(User(user, password)))
VM* avm; // active VM
avm = NULL;

if (argc == 1)
{
int idx = lua_gettop(lua);
if (!lua_istable(lua, idx))
{
cout << "Error! Invalid call to addUser." << endl;
exit (ERR_BAD_SET);
}

lua_pushnil(lua); // first key
while (lua_next(lua, -2) != 0 )
{
string key = lua_tostring(lua, -2);
string value = lua_tostring(lua, -1);

if (key == "host")
{
avm = getVM(value);
}
if (key == "user")
{
user = value;
}
if (key == "password")
{
password = value;
}

lua_pop(lua, 1);
}
} else {
password = lua_tostring(lua, lua_gettop(lua));
lua_pop(lua, 1);
user = lua_tostring(lua, lua_gettop(lua));
lua_pop(lua, 1);
}

if (user.empty())
{
cout << "Error! Invalid call to addUser." << endl;
exit (ERR_BAD_SET);
}

if (!avm)
{
avm = &(vPC.back());
}

if (!avm->addUser(User(user, password)))
{
cout << "Fatal error adding user." << endl;
exit (ERR_BAD_SET);
Expand Down
2 changes: 1 addition & 1 deletion engine.h
Expand Up @@ -20,7 +20,7 @@ extern void sleep(int t);
#endif

#define ENGINE_NAME "The Hacker's Sandbox"
#define ENGINE_VERSION 1.19
#define ENGINE_VERSION 1.20

#define debug cout
#define T_FOLDER 0
Expand Down

0 comments on commit 303798e

Please sign in to comment.