summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c13
-rw-r--r--doc/snac.88
-rw-r--r--snac.c64
-rw-r--r--snac.h3
4 files changed, 86 insertions, 2 deletions
diff --git a/data.c b/data.c
index 22ea7b0..f32dc81 100644
--- a/data.c
+++ b/data.c
@@ -89,8 +89,15 @@ int srv_open(const char *basedir, int auto_upgrade)
89 else { 89 else {
90 if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) 90 if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout)
91 error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); 91 error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first");
92 else 92 else {
93 ret = 1; 93 if (!check_strip_tool()) {
94 const char *mp = xs_dict_get(srv_config, "mogrify_path");
95 if (mp == NULL) mp = "mogrify";
96 error = xs_fmt("ERROR: strip_exif enabled but '%s' not found or not working (set 'mogrify_path' in server.json)", mp);
97 }
98 else
99 ret = 1;
100 }
94 } 101 }
95 } 102 }
96 103
@@ -2710,6 +2717,8 @@ void static_put(snac *snac, const char *id, const char *data, int size)
2710 if (fn && (f = fopen(fn, "wb")) != NULL) { 2717 if (fn && (f = fopen(fn, "wb")) != NULL) {
2711 fwrite(data, size, 1, f); 2718 fwrite(data, size, 1, f);
2712 fclose(f); 2719 fclose(f);
2720
2721 strip_media(fn);
2713 } 2722 }
2714} 2723}
2715 2724
diff --git a/doc/snac.8 b/doc/snac.8
index b8a75fa..8283ac6 100644
--- a/doc/snac.8
+++ b/doc/snac.8
@@ -296,6 +296,14 @@ outgoing messages (default: 15). Anyway, whenever any incoming activity from a
296failed instance is detected, this counter is reset for it. 296failed instance is detected, this counter is reset for it.
297.It Ic vkey 297.It Ic vkey
298Public vapid key. Used for notification on some client. 298Public vapid key. Used for notification on some client.
299.It Ic strip_exif
300If set to true, EXIF metadata will be stripped from uploaded images (jpg, png, webp, heic, avif, tiff, gif, bmp). This requires the
301.Nm mogrify
302tool to be installed. If
303.Nm snac
304cannot find or execute the tool at startup, it will refuse to run.
305.It Ic mogrify_path
306Overrides the default "mogrify" command name or path. Use this if the tool is not in the system PATH or has a different name.
299.El 307.El
300.Pp 308.Pp
301You must restart the server to make effective these changes. 309You must restart the server to make effective these changes.
diff --git a/snac.c b/snac.c
index 965edbb..f4528cd 100644
--- a/snac.c
+++ b/snac.c
@@ -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
36xs_str *srv_basedir = NULL; 37xs_str *srv_basedir = NULL;
37xs_dict *srv_config = NULL; 38xs_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
176int 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
219int 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}
diff --git a/snac.h b/snac.h
index 8a7dad6..c307dbd 100644
--- a/snac.h
+++ b/snac.h
@@ -105,6 +105,9 @@ int validate_uid(const char *uid);
105xs_str *hash_password(const char *uid, const char *passwd, const char *nonce); 105xs_str *hash_password(const char *uid, const char *passwd, const char *nonce);
106int check_password(const char *uid, const char *passwd, const char *hash); 106int check_password(const char *uid, const char *passwd, const char *hash);
107 107
108int strip_media(const char *fn);
109int check_strip_tool(void);
110
108void srv_archive(const char *direction, const char *url, xs_dict *req, 111void srv_archive(const char *direction, const char *url, xs_dict *req,
109 const char *payload, int p_size, 112 const char *payload, int p_size,
110 int status, xs_dict *headers, 113 int status, xs_dict *headers,