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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef SIGNET_UTIL_H
#define SIGNET_UTIL_H
#include <stddef.h>
#include <stdint.h>
/*
* fork/execvp `argv`, require exit status 0 within 30 seconds (monotonic).
* Kill the command process group before reaping; Linux also kills the direct
* child if its caller dies. Escaped groups/crash-orphaned grandchildren still
* require service-level containment; this is not an RSS limit.
* If `out` is non-NULL, outsz must be positive; stdout is NUL-terminated and
* truncated to outsz-1. Returns 0 on success, -1 on failure (timeout: ETIMEDOUT).
*/
int run_cmd(char *const argv[], char *out, size_t outsz);
int sha256_file(const char *path, char hex[65]);
int mkdir_p(const char *path, int mode);
int copy_file(const char *src, const char *dst);
int write_file(const char *path, const void *buf, size_t len, int mode);
int file_exists(const char *path);
#include <ctype.h>
#include <string.h>
/* inlined validators: zero call overhead */
static inline int is_uuid(const char *s) {
int i;
if (s == NULL || strlen(s) != 36) return 0;
for (i = 0; i < 36; i++) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
if (s[i] != '-') return 0;
} else if (!isxdigit((unsigned char)s[i])) return 0;
}
return 1;
}
static inline int is_safe_name(const char *s) {
size_t i, n;
if (s == NULL || (n = strlen(s)) == 0 || n > 64 || s[0] == '.') return 0;
for (i = 0; i < n; i++)
if (!isalnum((unsigned char)s[i]) && s[i] != '.' && s[i] != '_' && s[i] != '-')
return 0;
return 1;
}
static inline int is_safe_relpath(const char *s) {
const char *p;
if (s == NULL || *s == '\0' || *s == '/' || strlen(s) > 255) return 0;
if (strstr(s, "..") != NULL) return 0;
for (p = s; *p; p++)
if ((unsigned char)*p < 0x20 || *p == '\\') return 0;
return 1;
}
/* decode one UTF-8 code point, advance *s; returns 0xFFFD on bad input */
uint32_t utf8_next(const char **s);
/* initialize syslog with the given identity (e.g., "signet-api") */
void log_open(const char *ident);
/* Log to syslog and stderr; never pass private values or raw backend errors. */
void log_err(const char *fmt, ...);
/* Log 4xx/5xx: normalize route/actor; method/site must be code-owned strings. */
void log_request(const char *method, const char *path, const char *user,
int status, const char *site);
#endif