commit 1a42fdc

grunfink  ·  2025-10-24 03:02:28 +0000 UTC
parent 2dbd522
Keep track of deleted users and return 410 Gone for them.
6 files changed,  +45, -6
M data.c
M html.c
M snac.h
+6, -4
 1@@ -3660,8 +3660,9 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
 2     uid = xs_list_get(l, 1);
 3     if (!user_open(&snac, uid)) {
 4         /* invalid user */
 5-        srv_debug(1, xs_fmt("activitypub_get_handler bad user %s", uid));
 6-        return HTTP_STATUS_NOT_FOUND;
 7+        status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND;
 8+        srv_debug(1, xs_fmt("activitypub_get_handler bad user %s %d", uid, status));
 9+        return status;
10     }
11 
12     p_path = xs_list_get(l, 2);
13@@ -3854,8 +3855,9 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
14     const char *uid = xs_list_get(l, 1);
15     if (!user_open(&snac, uid)) {
16         /* invalid user */
17-        srv_debug(1, xs_fmt("activitypub_post_handler bad user %s", uid));
18-        return HTTP_STATUS_NOT_FOUND;
19+        status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND;
20+        srv_debug(1, xs_fmt("activitypub_post_handler bad user %s %d", uid, status));
21+        return status;
22     }
23 
24     /* if it has a digest, check it now, because
M data.c
+29, -0
 1@@ -3137,6 +3137,35 @@ int instance_failure(const char *url, int op)
 2 }
 3 
 4 
 5+int grave(const char *objid, int op)
 6+/* the graveyeard of deleted objects */
 7+{
 8+    int ret = 0;
 9+    xs *dir = xs_fmt("%s/grave", srv_basedir);
10+    xs *md5 = xs_md5_hex(objid, strlen(objid));
11+    xs *fn  = xs_fmt("%s/%s", dir, md5);
12+    FILE *f;
13+
14+    switch (op) {
15+    case 0: /** check **/
16+        ret = mtime(fn) > 0.0 ? 1 : 0;
17+        break;
18+
19+    case 1: /** add **/
20+        mkdirx(dir);
21+
22+        if ((f = fopen(fn, "w")) != NULL) {
23+            fprintf(f, "%s\n", objid);
24+            fclose(f);
25+        }
26+
27+        break;
28+    }
29+
30+    return ret;
31+}
32+
33+
34 /** notifications **/
35 
36 xs_str *notify_check_time(snac *snac, int reset)
M html.c
+3, -2
 1@@ -3830,8 +3830,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2 
 3     if (!uid || !user_open(&snac, uid)) {
 4         /* invalid user */
 5-        srv_debug(1, xs_fmt("html_get_handler bad user %s", uid));
 6-        return HTTP_STATUS_NOT_FOUND;
 7+        status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND;
 8+        srv_debug(1, xs_fmt("html_get_handler bad user %s %d", uid, status));
 9+        return status;
10     }
11 
12     user = &snac; /* for L() */
+3, -0
 1@@ -598,6 +598,9 @@ void httpd_connection(FILE *f)
 2     if (status == HTTP_STATUS_NOT_FOUND)
 3         body = xs_str_new("<h1>404 Not Found (" USER_AGENT ")</h1>");
 4 
 5+    if (status == HTTP_STATUS_GONE)
 6+        body = xs_str_new("<h1>410 Gone (" USER_AGENT ")</h1>");
 7+
 8     if (status == HTTP_STATUS_BAD_REQUEST && body != NULL)
 9         body = xs_str_new("<h1>400 Bad Request (" USER_AGENT ")</h1>");
10 
M snac.h
+2, -0
1@@ -288,6 +288,8 @@ xs_list *content_search(snac *user, const char *regex,
2 int actor_failure(const char *actor, int op);
3 int instance_failure(const char *url, int op);
4 
5+int grave(const char *objid, int op);
6+
7 void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
8 void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries);
9 void enqueue_output_raw(const char *keyid, const char *seckey,
+2, -0
1@@ -454,6 +454,8 @@ int deluser(snac *user)
2         }
3     }
4 
5+    grave(user->uid, 1);
6+
7     rm_rf(user->basedir);
8 
9     return ret;