laurent.orseau
2020-8-24 07:44:50

awesome, thank you! By ‘all info.rkt’, you mean even in directories referenced by dependencies, or just the one in the initial directory? (I’m now wondering if I didn’t misunderstand your previous message)


spore2050
2020-8-24 13:38:27

@spore2050 has joined the channel


massung
2020-8-24 16:13:50

Anyone know how to do a simple (read-line) , but that’s for passwords (won’t echo what’s typed)?



massung
2020-8-24 16:35:50

ty :slightly_smiling_face:


massung
2020-8-24 16:36:51

ah, looks like i’ll be diving deeper, but ty (in my particular case, it’s via a tcp socket)


massung
2020-8-24 16:36:59

but the answer is still good


massung
2020-8-24 16:39:44

perhaps a simple ansi escape seq will work


samdphillips
2020-8-24 16:50:12

That’s what stty does pretty much iirc


massung
2020-8-24 17:16:22

Anyone happen to know what this error means? eval-linklet: cannot use linklet loaded with non-original code inspector


mflatt
2020-8-24 17:54:46

Probably that error message should have “unsafe” in it somewhere. The code inspector has been changed (probably for a sandbox) so that it disallows running unsafe code, and some module that uses unsafe operations was loaded with that code inspector, so it’s not allowed to be run.


massung
2020-8-24 18:05:30

ah ok.

continuing w/ my sandbox woes, I have an interesting situation now where I have a file (e.g. A.rkt) that is capable of creating a sandbox evaluator with permissions to read a directory on disk. If I run A.rkt, I can call the “run-script” function just fine, it loads and runs perfectly.

Now, if I make B.rkt, which requires A.rkt and calls the same function, it fails saying that it doesn’t have permission to read the file in question. However, the path it displays with the permission error is the project path - not the path of the script.

If I had to guess, it’s not allowing the evaluator to read the module of functions I want exposed to the evaluator which are in A.rkt since it’s executing B.rkt.

Not sure how to get past this, though. Sorry, but the documentation on the sandboxes doesn’t have a lot in the way of examples for usage. :disappointed:


massung
2020-8-24 18:06:54

I got the eval-linklet error when - just to try something - I added privs to read the project directory, too.


mflatt
2020-8-24 18:31:13

The default sandbox configuration allows reading installed collections/packages and disallows file access elsewhere. So, if your project is not installed in that sense, then you would have to add access, as you say.


mflatt
2020-8-24 18:32:50

I don’t immediately remember what unsafe modules are allowed by default. That, again, might be tied to installation, and it might be different than allowing modules to be loaded.


mflatt
2020-8-24 18:33:59

Meanwhile, it’s not very practical these days to expect a module to have no unsafe components. In the early days, that looked possible, but macros and optimizer passes have gradually introduced more and more unsafe operations into modules.


mflatt
2020-8-24 18:34:34

So: Is your project installed as a package? If not, does installing it that way help with these kinds of problems?


massung
2020-8-24 18:36:26

It isn’t installed, and installing it wouldn’t make much sense — certainly not for development anyway. There’s a configuration file that’s loaded, which basically says where to allow reading of scripts from, etc. Right now I feel like I’m relegated to making the entire program in a single file, sadly.


mflatt
2020-8-24 18:36:59

When you say you enabled read access, was that just plain read or was it read-bytecode?


massung
2020-8-24 18:37:34

just plain read `((read ,script-path))


mflatt
2020-8-24 18:38:25

Does read a script (from source?) load any modules in the project (i.e., not installed) that are compiled to bytecode?


massung
2020-8-24 18:38:43

currently, for dev, script-path is just defined as (build-path (current-directory) "scripts"), but later will be read from a config file and could be anywhere


massung
2020-8-24 18:39:41

> Does read a script (from source?) load any modules in the project No. They are just simple, vanilla scheme code. They just have access to a few functions I expose in that submodule.


mflatt
2020-8-24 18:40:18

Are the scripts compiled to bytecode, or are they just in source form?


massung
2020-8-24 18:40:28

source form


mflatt
2020-8-24 18:40:56

That sounds like something that should work, so I must be missing a piece. Can you provide an example again?


massung
2020-8-24 18:42:05

As an example, the configuration file loaded at startup would have things like: DB credentials and a directory where the scripts are located. The submodule would contain a function like “run-query” that the script could call, but the script would never have access to the credentials itself.


massung
2020-8-24 18:43:07

So, the script might be something like… (for/list ([email (run-query "SELECT email FROM ...")]) (send-email email ...)) Where send-email is also exposed from the project.


massung
2020-8-24 18:43:30

Let me put together a sample real quick


mflatt
2020-8-24 18:43:47

That will help a lot - thanks.


massung
2020-8-24 18:47:04

So (barring any stupid typo), this would be a good summary of script-runner.rkt: #lang racket (require racket/sandbox) (require syntax/modresolve) (provide (all-defined-out)) (module* efuns #f (provide run-query)) (define (run-query) (displayln "Hello, world!")) (define efuns-path-index (let* ([ref (#%variable-reference)] ; submodule path and this module's index [path-index '(submod "." efuns)] [base-index (variable-reference->module-path-index ref)] ; join them together for the complete module path [path (module-path-index-join path-index base-index)]) (resolve-module-path-index path))) (define namespace-specs (append (sandbox-namespace-specs) (list efuns-path-index))) (define script-path (build-path (current-directory) "src")) (define script-perms (list* (list 'read script-path) (sandbox-path-permissions))) (define (run-script script-filename) (let ([e (parameterize ([sandbox-input current-input-port] [sandbox-output current-output-port] [sandbox-namespace-specs namespace-specs] [sandbox-path-permissions script-perms] [sandbox-gui-available #f]) (displayln (sandbox-path-permissions)) (make-evaluator 'racket/base))]) ; initialize the new object (e `(namespace-require ',efuns-path-index)) (e `(load ,(build-path script-path script-filename))) (e '(run))))


massung
2020-8-24 18:47:45

And this code works just fine! If I run it from DrRacket, it’s all good. I can call run-script with a script in the src directory and it executes just fine.


massung
2020-8-24 18:48:58

Now, if I have my main.rkt file (in the same directory as script-runner.rkt: (require "script-runner.rkt") (define (test) (run-script "test-script.rkt")) This fails with: (exn:fail "current-load-relative-directory: `exists' access denied for E:\\racket-projects\\runner-project\\" #<continuation-mark-set>)


massung
2020-8-24 18:50:14

Note: it never even attempts to load the script file. It’s dying in make-evaluator from what I can tell (if I put a displayln after the call to make-evaluator it never displays.


massung
2020-8-24 18:51:45

If you need something for yourself to test with, test-script.rkt is just the following: (define (run) (run-query))


mflatt
2020-8-24 21:24:39

I see that error if I run in DrRacket (which automatically compiles programs to bytecode) or if I raco make main.rkt before. But if I run without compiled bytecode, I don’t get the error.


mflatt
2020-8-24 21:25:40

If I add 'read permission for the directory that has main.rkt and script-runner.rkt, then I get the unsafe-linklet error. And if I add 'read-bytecode permission instead, then the unsafe-linklet error goes away.


massung
2020-8-24 22:44:14

Interesting. thanks for the 2nd pair of eyes.


thurtu811
2020-8-25 01:41:17

@thurtu811 has joined the channel