diff options
| author | Ethan Werner <mail@ethanwerner.com> | 2026-10-10 20:55:33 +0000 |
|---|---|---|
| committer | Ethan Werner <mail@ethanwerner.com> | 2026-10-10 20:56:50 +0000 |
| commit | f8423ebea413605b42de23f5dd06c5479d3fa1dd (patch) | |
| tree | 2612a5eb026c59e7aae01f10a1cf62f2ee43042c /src/limits.h | |
Diffstat (limited to 'src/limits.h')
| -rw-r--r-- | src/limits.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/limits.h b/src/limits.h new file mode 100644 index 0000000..14ec0e5 --- /dev/null +++ b/src/limits.h @@ -0,0 +1,40 @@ +#ifndef LLSH_LIMITS_H +#define LLSH_LIMITS_H + +#include "util.h" + +/* Process-global tool limits + run_shell policy (mirrors limits.rs). */ + +typedef struct { + unsigned long shell_timeout_secs; + unsigned long max_output_chars; + unsigned long max_file_bytes; + strlist shell_allowlist; + strlist shell_denylist; + bool confirm_destructive; + bool verbose; +} tool_limits; + +void tool_limits_defaults(tool_limits *l); +void tool_limits_set(const tool_limits *l); +/* Read-only view of the current limits (no copy). The pointer is valid until + * the next tool_limits_set; do not store it across set calls. */ +const tool_limits *tool_limits_current(void); +void tool_limits_get(tool_limits *out); +void tool_limits_free(tool_limits *l); + +typedef enum { + SHELL_ALLOWED, + SHELL_DENIED, +} shell_verdict; + +/* Returns 0 allowed, -1 denied (reason in **err, owned). */ +int shell_policy(const char *command, const tool_limits *l, char **reason); +bool is_destructive(const char *command); + +void set_confirm_hook(bool (*hook)(const char *command, void *ud), void *ud); + +/* Full gate: policy, then destructive confirmation. 0 = proceed. */ +int shell_gate(const char *command, const tool_limits *l, char **err); + +#endif |