diff options
| author | 2026-01-06 11:02:36 +0100 | |
|---|---|---|
| committer | 2026-01-06 11:02:36 +0100 | |
| commit | 688c54c87355b5424f33f7b089814460a74af594 (patch) | |
| tree | 03bbe3779173b3d90aede93ea6e41e64869b415b /snac.c | |
| parent | Version 2.86 RELEASED. (diff) | |
| download | snac2-688c54c87355b5424f33f7b089814460a74af594.tar.gz snac2-688c54c87355b5424f33f7b089814460a74af594.tar.xz snac2-688c54c87355b5424f33f7b089814460a74af594.zip | |
Implement configurable EXIF stripping for uploaded media
- Add `strip_exif` configuration option to enable metadata removal.
- Add `mogrify_path` configuration to specify external tool location.
- Implement strip_media using `mogrify -strip`.
- Support multiple image formats: jpg, png, webp, heic, heif, avif, tiff, gif, bmp.
- Add strict startup check: fail to start if `strip_exif` is enabled but `mogrify` is missing/broken.
- Update documentation in `doc/snac.8`.
Diffstat (limited to 'snac.c')
| -rw-r--r-- | snac.c | 64 |
1 files changed, 64 insertions, 0 deletions
| @@ -32,6 +32,7 @@ | |||
| 32 | 32 | ||
| 33 | #include <sys/time.h> | 33 | #include <sys/time.h> |
| 34 | #include <sys/stat.h> | 34 | #include <sys/stat.h> |
| 35 | #include <sys/wait.h> | ||
| 35 | 36 | ||
| 36 | xs_str *srv_basedir = NULL; | 37 | xs_str *srv_basedir = NULL; |
| 37 | xs_dict *srv_config = NULL; | 38 | xs_dict *srv_config = NULL; |
| @@ -170,3 +171,66 @@ int check_password(const char *uid, const char *passwd, const char *hash) | |||
| 170 | 171 | ||
| 171 | return ret; | 172 | return ret; |
| 172 | } | 173 | } |
| 174 | |||
| 175 | |||
| 176 | int strip_media(const char *fn) | ||
| 177 | /* strips EXIF data from a file */ | ||
| 178 | { | ||
| 179 | int ret = 0; | ||
| 180 | const xs_val *v = xs_dict_get(srv_config, "strip_exif"); | ||
| 181 | |||
| 182 | if (xs_type(v) == XSTYPE_TRUE) { | ||
| 183 | xs *l_fn = xs_tolower_i(xs_dup(fn)); | ||
| 184 | |||
| 185 | /* check extensions */ | ||
| 186 | if (xs_endswith(l_fn, ".jpg") || xs_endswith(l_fn, ".jpeg") || | ||
| 187 | xs_endswith(l_fn, ".png") || xs_endswith(l_fn, ".webp") || | ||
| 188 | xs_endswith(l_fn, ".heic") || xs_endswith(l_fn, ".heif") || | ||
| 189 | xs_endswith(l_fn, ".avif") || xs_endswith(l_fn, ".tiff") || | ||
| 190 | xs_endswith(l_fn, ".gif") || xs_endswith(l_fn, ".bmp")) { | ||
| 191 | |||
| 192 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 193 | if (mp == NULL) | ||
| 194 | mp = "mogrify"; | ||
| 195 | |||
| 196 | xs *cmd = xs_fmt("%s -strip \"%s\" 2>/dev/null", mp, fn); | ||
| 197 | |||
| 198 | ret = system(cmd); | ||
| 199 | |||
| 200 | if (ret != 0) { | ||
| 201 | int code = 0; | ||
| 202 | if (WIFEXITED(ret)) | ||
| 203 | code = WEXITSTATUS(ret); | ||
| 204 | |||
| 205 | if (code == 127) | ||
| 206 | srv_log(xs_fmt("strip_media: error stripping %s. '%s' not found (exit 127). Set 'mogrify_path' in server.json.", fn, mp)); | ||
| 207 | else | ||
| 208 | srv_log(xs_fmt("strip_media: error stripping %s %d", fn, ret)); | ||
| 209 | } | ||
| 210 | else | ||
| 211 | srv_debug(1, xs_fmt("strip_media: stripped %s", fn)); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | return ret; | ||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | int check_strip_tool(void) | ||
| 220 | { | ||
| 221 | const xs_val *v = xs_dict_get(srv_config, "strip_exif"); | ||
| 222 | int ret = 1; | ||
| 223 | |||
| 224 | if (xs_type(v) == XSTYPE_TRUE) { | ||
| 225 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 226 | if (mp == NULL) | ||
| 227 | mp = "mogrify"; | ||
| 228 | |||
| 229 | xs *cmd = xs_fmt("%s -version 2>/dev/null >/dev/null", mp); | ||
| 230 | |||
| 231 | if (system(cmd) != 0) | ||
| 232 | ret = 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | return ret; | ||
| 236 | } | ||