aboutsummaryrefslogtreecommitdiff
path: root/snac.c
diff options
context:
space:
mode:
authorStefano Marinelli <stefano@dragas.it>2026-01-06 11:02:36 +0100
committerStefano Marinelli <stefano@dragas.it>2026-01-06 11:02:36 +0100
commit688c54c87355b5424f33f7b089814460a74af594 (patch)
tree03bbe3779173b3d90aede93ea6e41e64869b415b /snac.c
parentb84b92df74ed0e8f92617e37fdcb2f0aba2138cf (diff)
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.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/snac.c b/snac.c
index 965edbb..f4528cd 100644
--- a/snac.c
+++ b/snac.c
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/stat.h>
+#include <sys/wait.h>
xs_str *srv_basedir = NULL;
xs_dict *srv_config = NULL;
@@ -170,3 +171,66 @@ int check_password(const char *uid, const char *passwd, const char *hash)
return ret;
}
+
+
+int strip_media(const char *fn)
+/* strips EXIF data from a file */
+{
+ int ret = 0;
+ const xs_val *v = xs_dict_get(srv_config, "strip_exif");
+
+ if (xs_type(v) == XSTYPE_TRUE) {
+ xs *l_fn = xs_tolower_i(xs_dup(fn));
+
+ /* check extensions */
+ if (xs_endswith(l_fn, ".jpg") || xs_endswith(l_fn, ".jpeg") ||
+ xs_endswith(l_fn, ".png") || xs_endswith(l_fn, ".webp") ||
+ xs_endswith(l_fn, ".heic") || xs_endswith(l_fn, ".heif") ||
+ xs_endswith(l_fn, ".avif") || xs_endswith(l_fn, ".tiff") ||
+ xs_endswith(l_fn, ".gif") || xs_endswith(l_fn, ".bmp")) {
+
+ const char *mp = xs_dict_get(srv_config, "mogrify_path");
+ if (mp == NULL)
+ mp = "mogrify";
+
+ xs *cmd = xs_fmt("%s -strip \"%s\" 2>/dev/null", mp, fn);
+
+ ret = system(cmd);
+
+ if (ret != 0) {
+ int code = 0;
+ if (WIFEXITED(ret))
+ code = WEXITSTATUS(ret);
+
+ if (code == 127)
+ srv_log(xs_fmt("strip_media: error stripping %s. '%s' not found (exit 127). Set 'mogrify_path' in server.json.", fn, mp));
+ else
+ srv_log(xs_fmt("strip_media: error stripping %s %d", fn, ret));
+ }
+ else
+ srv_debug(1, xs_fmt("strip_media: stripped %s", fn));
+ }
+ }
+
+ return ret;
+}
+
+
+int check_strip_tool(void)
+{
+ const xs_val *v = xs_dict_get(srv_config, "strip_exif");
+ int ret = 1;
+
+ if (xs_type(v) == XSTYPE_TRUE) {
+ const char *mp = xs_dict_get(srv_config, "mogrify_path");
+ if (mp == NULL)
+ mp = "mogrify";
+
+ xs *cmd = xs_fmt("%s -version 2>/dev/null >/dev/null", mp);
+
+ if (system(cmd) != 0)
+ ret = 0;
+ }
+
+ return ret;
+}