Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved command lines into Lua.
  • Loading branch information
icculus committed Dec 19, 2013
1 parent 7215e17 commit 270fc23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 14 additions & 2 deletions 1pass.c
Expand Up @@ -168,6 +168,7 @@ static int decryptBase64UsingKey(lua_State *L)
} // decryptBase64UsingKey



static void *luaAlloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
if (nsize == 0)
Expand Down Expand Up @@ -195,7 +196,7 @@ static int luaFatal(lua_State *L)
} // luaFatal


static int initLua(void)
static int initLua(const int argc, char **argv)
{
assert(luaState == NULL);
luaState = lua_newstate(luaAlloc, NULL);
Expand All @@ -208,6 +209,17 @@ static int initLua(void)
luaSetCFunc(luaState, decryptUsingPBKDF2, "decryptUsingPBKDF2");
luaSetCFunc(luaState, decryptBase64UsingKey, "decryptBase64UsingKey");

// Set up argv table...
lua_newtable(luaState);
int i;
for (i = 0; i < argc; i++)
{
lua_pushinteger(luaState, i+1);
lua_pushstring(luaState, argv[i]);
lua_settable(luaState, -3);
} // for
lua_setglobal(luaState, "argv");

// Transfer control to Lua...
if (luaL_dofile(luaState, "1pass.lua") != 0)
{
Expand Down Expand Up @@ -235,7 +247,7 @@ int main(int argc, char **argv)
{
atexit(deinitLua);

if (!initLua()) // this will move control to 1pass.lua
if (!initLua(argc, argv)) // this will move control to 1pass.lua
return 1;

return 0;
Expand Down
13 changes: 10 additions & 3 deletions 1pass.lua
Expand Up @@ -118,11 +118,18 @@ end

-- Mainline!

--for i,v in ipairs(argv) do
-- print("argv[" .. i .. "] = " .. v)
--end

local basedir = "1Password/1Password.agilekeychain/data/default" -- !!! FIXME

showHint(basedir)
io.write("password: ")
local password = io.read("*l")
local password = argv[3]
if password == nil then
showHint(basedir)
io.write("password: ")
password = io.read("*l")
end

if loadKey(basedir, "SL5", password) == nil then
print("wrong password?\n")
Expand Down

0 comments on commit 270fc23

Please sign in to comment.