Commit Graph

82 Commits

Author SHA1 Message Date
Kartik K. Agaram 98e657d6e2 actually _use_ the ask permission 2022-04-07 09:19:55 -07:00
Kartik K. Agaram dad78ac424 new perm: files under dir specified at commandline
I think we can now use a file browser app with relative safety. Just
give it inargs permissions, and provide a top-level directory at the
commandline to gain access to everything under it.
2022-04-05 22:49:43 -07:00
Kartik K. Agaram 9d81974a31 new permission: any file specified at commandline 2022-04-05 22:39:17 -07:00
Kartik K. Agaram 6099fa7fb2 experiment: ask for permission on file operations
I'm not quite sure how to think about asking for permissions with
respect to my red/orange/green color codes. On the one hand, it seems
safer than many alternatives. On the other hand, it's liable to lead to
fatigue and blindly allowing apps to do stuff. For now I consider ask to
be orange. Ask + network allowed = red in summary, though it's orange on
the permissions screen since there's more space to convey nuance. Then
again, nobody may heed the nuance. The summary up top on the permissions
screen is definitely still a work in progress. And there's a
chicken-and-egg problem here: I can't really get a good feel for
real-world bugs in the permissions screen until _other programmers_ are
building apps to use the permissions screen, but they're almost certain
to have a crappy time of it.

I considered introducing a primitive called ask() in the Lua
interpreter, but it doesn't really make sense to validate it and so on.
I'm also not really supporting mixing Ask with other features so far.

This is a major step towards turning my permissions screen into
spaghetti; monitoring closely.
2022-04-05 22:26:43 -07:00
Kartik K. Agaram 5b64c4b3bc show common suggestions when editing permissions
Computer owners shouldn't get in the habit of trusting app authors
regarding permissions. But they have to trust somebody, and they already
trust the Teliva platform if they are running it.
2022-04-05 20:50:51 -07:00
Kartik K. Agaram 9ec94aa982 disallow all relative paths (./ or ../)
Teliva's model doesn't include any way to change directory. We just have
relative paths and absolute paths. Relative paths should not be able to
reach into parent directories.

The current test is a bit hacky; it also disallows directories ending in
a period. Hopefully not an issue.
2022-03-20 17:58:14 -07:00
Kartik K. Agaram 0374e82aa5 show current definition being edited
This serves two purposes:
- Things get confusing if function being defined doesn't match the
  definition name. Displaying the current definition helps diagnose this
  situation.
- We're already able to see callers at a glance even if the cursor is
  below the fold. The name of the current definition is arguably more
  important in that situation.
2022-03-18 10:39:56 -07:00
Kartik K. Agaram 1d3101507e fix some warnings 2022-03-17 00:15:16 -07:00
Kartik K. Agaram 5380817ce6 function names from globals rather than debug info
This reclaims all the slowdown in sieve.tlv, and it also is now smart
enough to detect calls to global bindings that pass through variables.

On the flip side, we lose names for non-globals. But that's not very
useful anyway in Teliva's context.

This is still not enough to detect callers through coroutines
(intervening anonymous functions), though.
2022-03-16 23:53:08 -07:00
Kartik K. Agaram 76d1dda240 bring back hack when caller is main
Partially undoes commit f2d29c22f8.
2022-03-16 23:45:42 -07:00
Kartik K. Agaram 785dfaa1ec cache function names
This brings down the slowdown in sieve.tlv from 50% to 25% (15s).
2022-03-16 23:45:38 -07:00
Kartik K. Agaram 155f6a8027 standardize some names 2022-03-16 21:48:41 -07:00
Kartik K. Agaram fffcc8b9ab stop running task.scheduler by default
sieve.tlv is 50% slower (18s vs 12s) with the new function call
instrumentation.
2022-03-16 21:38:34 -07:00
Kartik K. Agaram d6554919b1 delete dead code 2022-03-16 21:28:58 -07:00
Kartik K. Agaram ef5195dee9 simplify function call instrumentation
src/ldo.c now has a minimal diff with Lua 5.1.

It might be a bit slower than it was before, but not noticeably so..

This approach doesn't support indirect calls.
2022-03-16 21:19:19 -07:00
Kartik K. Agaram ed5efcd8a0 drop a forward decl 2022-03-16 20:31:43 -07:00
Kartik K. Agaram 709cc25130 start cleaning up function call instrumentation
It's a mess. I calculate call-graph depth one way and calculate caller
names another way. At least one of the ways fails to work with indirect
calls. Hopefully the other way works?
2022-03-16 20:29:50 -07:00
Kartik K. Agaram 04a65e05f8 leak check 2022-03-10 09:56:37 -08:00
Kartik K. Agaram 0fa83e1d94 support fixing >1 test failure from within Teliva
This bug was caused by me forgetting that lua_setglobal affects the
stack.
2022-03-10 09:47:10 -08:00
Kartik K. Agaram e627114751 zet.tlv: first screen tests
In the process I found a couple of bugs in fake screen primitives.
2022-03-10 04:30:58 -08:00
Kartik K. Agaram 2b47f76308 just always temp files to be created
Implication: os.rename now needs to be sandboxed. Hopefully it's
tractable to treat it as conceptually identical to opening two files.
2022-03-07 21:57:11 -08:00
Kartik K. Agaram dd8730920a purge all support for per-function permissions
We're now back to the problem of how to transparently allow Teliva to
create temporary filenames without every app having to explicitly allow
them.

I think I may need to define start_writing in C, so that it can use a
non-sandboxed version of io.open.
2022-03-07 20:50:41 -08:00
Kartik K. Agaram cfb7cff4c1 call app's main() from within Lua pmain 2022-03-07 15:34:20 -08:00
Kartik K. Agaram 38063812b6 zet.tlv: switch file writes to new API
The interface for apps looks much nicer now, see 'main' in zet.tlv.
However there are some open issues:

- It can still be confusing to the computer owner that an app tries to
  write to some temporary file that isn't mentioned anywhere.

- File renames can fail if /tmp is on a different volume.

- What happens if an app overrides start_writing()? The computer owner
  may think they've audited the caller of start_writing and give it
  blanket file permissions. Teliva tunnels through start_writing when
  computing the caller. If the app can control what start_writing does,
  the app could be performing arbitrary malicious file operations.

  Right now things actually seem perfectly secure. Overriding
  start_writing has no effect. Our approach for loading .tlv files (in
  reverse chronological order, preventing older versions from overriding
  newer ones) has the accidentally _great_ property that Teliva apps can
  never override system definitions.

  So we have a new reason to put standard libraries in a .lua file: if
  we need to prevent apps from overriding it.

  This feels like something that needs an automated test, both to make
  sure I'm running the right experiment and to ensure I don't
  accidentally cause a regression in the future. I can totally imagine a
  future rewrite that tried a different approach than
  reverse-chronological.
2022-03-07 10:55:18 -08:00
Kartik K. Agaram 7a315e3d9f extract a common function call 2022-03-07 08:52:41 -08:00
Kartik K. Agaram f2d29c22f8 a simple hack to make caller apparent
Teliva isn't yet smart enough to know the caller of an indirect function
where the function being called goes through a local variable.

I'd expected fixing this to be a long death march. However, there's a
shockingly easy fix: just make every indirect call go through an
additional direct function call.

My policy for zet.tlv was that function 'main' could open any file. This
stopped working since I introduced spawn_main. But with this commit it's
working again.

I can also drop all my special-casing of 'main' since it's now a regular
Lua call.

We still can't rely on the caller of an indirect call. That affects
start_reading and start_writing, which really need to be part of the
framework.
2022-03-05 22:38:00 -08:00
Kartik K. Agaram 52ae23784b new API for file operations
File operations now always return a channel (or nil on error or
permission denied).

When start_reading() from a filename, you can repeatedly :recv() from
the channel it returns.
When :recv() returns nil, you're at the end of the file. Stop.

When you start_writing() to a filename, you can repeatedly :send() to
the channel it returns.
When you're done writing, :close() the channel. Writes to the file won't
be externally visible until you do.

To make this work I'm now always starting up the scheduler, so I need to
fix sieve.tlv.

Transparently running the scheduler is an abstraction, and whenever I
create an abstraction I always worry about how it might fail. There's
a hopefully-clear error when you read past end of a file.
2022-03-05 18:04:35 -08:00
Kartik K. Agaram 2cfdad3381 simplify permissions model for file operations
We don't care to distinguish modes like "rw" or "a+". An app is
permitted to perform either just reads or both reads and writes.
2022-03-03 22:28:01 -08:00
Kartik K. Agaram 061e6a21a5 duplicate keypress on failing test 2022-02-26 19:47:06 -08:00
Kartik K. Agaram 9421ea7151 'doc:blurb': a place to briefly describe an app
This is for what the app does, as opposed to 'doc:main', which is also
intended to include commentary about the internal organization of the
app.
2022-02-17 20:16:36 -08:00
Kartik K. Agaram 6a485ae4b4 stop aborting if audit log fills up
When I started logging getch() events (which are just to help the reader
orient on the log), this suddenly became more urgent.

Now the log is larger, and it's also a circular buffer that rolls back
to the start when it fills up.

The next failure mode will be if we see the buffer filled up with just
getch() calls, reducing visibility over real file and network
operations. In which case we'll need to start coalescing getch() events.
2022-02-12 15:45:04 -08:00
Kartik K. Agaram feb10708ae hacky support for caller main in file permissions 2022-02-10 16:40:40 -08:00
Kartik K. Agaram 504573a0de move most Teliva menus to the right
The problem I'm running into is that apps might want to perform their
own editing. So I can't take up prime estate like the ctrl-e hotkey or a
menu name of 'edit'.

I'm still prioritizing rendering Teliva's edit and permissions menu. If
the window is too narrow the app's settings will be overwritten and
Teliva's hotkeys will be preferentially displayed. Seems safer.
2022-02-07 22:54:17 -08:00
Kartik K. Agaram 5e4ca1d470 don't perturb cursor when drawing menu 2022-02-04 23:55:28 -08:00
Kartik K. Agaram 664b94f414 include keys typed into audit log
This will help people cross-correlate when the app performs specific
calls.
2022-02-01 21:19:51 -08:00
Kartik K. Agaram 90904f344a file permissions: decide based on calling function 2022-02-01 20:59:53 -08:00
Kartik K. Agaram 7a13adb52c try to get by with one feature macro
I fucking hate feature macros. Egregious discharge of our
division-of-labor-obsessed society. People should be able to introduce
names. People should be able to give up names to lower levels of
abstraction when they encounter conflicts.

Feature macros seem to exist[1] to support more than two levels of
abstraction. You try to build, one of your libraries fails to build
because of a conflict between it and one level down. You don't want to
modify this library. Just fucking https://catern.com/change_code.html
already. But no, I have to litter my code with feature macros even
though I just want the abstraction the original library provides.

[1] https://man7.org/linux/man-pages/man7/feature_test_macros.7.html
    https://lwn.net/Articles/590381
2022-01-29 12:41:20 -08:00
Kartik K. Agaram e782cb1ead bugfix: editor was no longer saving anything
I made the changes reverted here out of a mistaken sense that
big-picture edits would interfere with Teliva's memory of what is
currently being edited (teliva_editor_state).
2022-01-27 00:40:33 -08:00
Kartik K. Agaram ce186e85f4 redo lua vs prose
Previously we weren't dynamically selecting how to highlight a buffer
after navigating with ctrl-g. That should work now.
2022-01-26 15:22:55 -08:00
Kartik K. Agaram cbe85a18c7 rename the custom big picture view to doc:main 2022-01-25 23:25:05 -08:00
Kartik K. Agaram 32d86bfc7f override big picture view with doc:bp if it exists
Going to big picture from doc:bp still goes to the default
auto-generated big picture view.

While doc:bp provides some programmability, it's also far klunkier than
the default view. Rendering is worse, and it's always in edit mode
because I'm trying to avoid complicating the UX with a notion of
rendered markup. That means cursor movement is less convenient. It's
also easy to accidentally edit the big-picture view.
2022-01-25 23:07:43 -08:00
Kartik K. Agaram 91d47faf23 disable Lua colors in prose 2022-01-25 21:44:01 -08:00
Kartik K. Agaram 84d76b11fa rename 2022-01-25 21:23:20 -08:00
Kartik K. Agaram 283d4dba59 new section in big picture: prose (non-code)
I've always found "Documentation" too pretentious.
2022-01-25 21:07:52 -08:00
Kartik K. Agaram 2fc48626b5 optimization: stop saving identical definitions
This is long overdue.
2022-01-25 20:53:46 -08:00
Kartik K. Agaram 2e38583da2 save doc: buffers to .tlv images 2022-01-25 20:45:00 -08:00
Kartik K. Agaram 39781351ee delete a redundant function prototype 2022-01-25 20:39:49 -08:00
Kartik K. Agaram d20e6a415f rename a function 2022-01-25 20:36:26 -08:00
Kartik K. Agaram c5f6e30042 start supporting non-code "buffers"
First step: when a "definition" starts with "doc:" it's not a
definition, just a buffer. Stop trying to interpret it as Lua.
2022-01-25 20:29:35 -08:00
Kartik K. Agaram 6a33284b07 get Teliva running on NetBSD
NetBSD still uses curses by default. One _could_ install ncurses, but I
don't have access to a NetBSD box with permissions to install ncurses,
so I'm experimenting to see how far we can get with just curses. So far
most of the apps seem to work, with the exception of one bug that I'll
commit next.
2022-01-24 20:15:43 -08:00