summaryrefslogtreecommitdiffstats
path: root/src/limits.h
blob: 14ec0e5652d674a88b6fcf6134bc3f0bbe112b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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