From 270fc2311ad891054c2948710e39dab52d28f1ee Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 19 Dec 2013 09:27:25 -0500 Subject: [PATCH] Moved command lines into Lua. --- 1pass.c | 16 ++++++++++++++-- 1pass.lua | 13 ++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/1pass.c b/1pass.c index 598e43d..7091ba8 100644 --- a/1pass.c +++ b/1pass.c @@ -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) @@ -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); @@ -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) { @@ -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; diff --git a/1pass.lua b/1pass.lua index 63851bb..d65fb08 100644 --- a/1pass.lua +++ b/1pass.lua @@ -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")