aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorJlll1 <arghantentua@tutanota.com>2022-11-28 20:23:04 +0100
committerGitHub <noreply@github.com>2022-11-28 12:23:04 -0700
commitf004812b338340e5f5157aa68d09d3f0e5605c6c (patch)
tree415f51509f9b19037d87bb3e8d2286b8a68da2a1 /src/nvim/lua/executor.c
parent77a0f4a542ad9354c647b6bafc1bbd5579212a9e (diff)
downloadrneovim-f004812b338340e5f5157aa68d09d3f0e5605c6c.tar.gz
rneovim-f004812b338340e5f5157aa68d09d3f0e5605c6c.tar.bz2
rneovim-f004812b338340e5f5157aa68d09d3f0e5605c6c.zip
feat(secure): add `:trust` command and vim.secure.trust() (#21107)
Introduce vim.secure.trust() to programmatically manage the trust database. Use this function in a new :trust ex command which can be used as a simple frontend. Resolves: https://github.com/neovim/neovim/issues/21092 Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: ii14 <ii14@users.noreply.github.com>
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 43a3b12a98..5380559baf 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -2217,3 +2217,51 @@ char *nlua_read_secure(const char *path)
return buf;
}
+
+bool nlua_trust(const char *action, const char *path)
+{
+ lua_State *const lstate = global_lstate;
+ lua_getglobal(lstate, "vim");
+ lua_getfield(lstate, -1, "secure");
+ lua_getfield(lstate, -1, "trust");
+
+ lua_newtable(lstate);
+ lua_pushstring(lstate, "action");
+ lua_pushstring(lstate, action);
+ lua_settable(lstate, -3);
+ if (path == NULL) {
+ lua_pushstring(lstate, "bufnr");
+ lua_pushnumber(lstate, 0);
+ lua_settable(lstate, -3);
+ } else {
+ lua_pushstring(lstate, "path");
+ lua_pushstring(lstate, path);
+ lua_settable(lstate, -3);
+ }
+
+ if (nlua_pcall(lstate, 1, 2)) {
+ nlua_error(lstate, _("Error executing vim.secure.trust: %.*s"));
+ return false;
+ }
+
+ bool success = lua_toboolean(lstate, -2);
+ const char *msg = lua_tostring(lstate, -1);
+ if (msg != NULL) {
+ if (success) {
+ if (strcmp(action, "allow") == 0) {
+ smsg("Allowed \"%s\" in trust database.", msg);
+ } else if (strcmp(action, "deny") == 0) {
+ smsg("Denied \"%s\" in trust database.", msg);
+ } else if (strcmp(action, "remove") == 0) {
+ smsg("Removed \"%s\" from trust database.", msg);
+ }
+ } else {
+ semsg(e_trustfile, msg);
+ }
+ }
+
+ // Pop return values, "vim" and "secure"
+ lua_pop(lstate, 4);
+
+ return success;
+}