commit ee63e2a

default  ·  2024-09-18 17:56:40 +0000 UTC
parent 97cc35f
New function webfinger_request_fake().
3 files changed,  +30, -9
M main.c
M snac.h
M main.c
+2, -1
 1@@ -47,8 +47,9 @@ int usage(void)
 2     printf("unlimit {basedir} {uid} {actor}      Unlimits an actor\n");
 3     printf("verify_links {basedir} {uid}         Verifies a user's links (in the metadata)\n");
 4     printf("search {basedir} {uid} {regex}       Searches posts by content\n");
 5-    printf("aka {basedir} {uid} {actor}          Sets actor (@user@host or url) as an a.k.a.\n");
 6+    printf("aka {basedir} {uid} {actor}          Sets actor (@user@host or url) as the a.k.a.\n");
 7     printf("export_csv {basedir} {uid}           Exports data as CSV files into current directory\n");
 8+    printf("migrate {basedir} {uid}              Migrates the account to the one set as the a.k.a.\n");
 9 
10     return 1;
11 }
M snac.h
+5, -4
 1@@ -284,10 +284,11 @@ int check_signature(const xs_dict *req, xs_str **err);
 2 srv_state *srv_state_op(xs_str **fname, int op);
 3 void httpd(void);
 4 
 5-int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user);
 6-int webfinger_request(const char *qs, char **actor, char **user);
 7-int webfinger_get_handler(xs_dict *req, char *q_path,
 8-                          char **body, int *b_size, char **ctype);
 9+int webfinger_request_signed(snac *snac, const char *qs, xs_str **actor, xs_str **user);
10+int webfinger_request(const char *qs, xs_str **actor, xs_str **user);
11+int webfinger_request_fake(const char *qs, xs_str **actor, xs_str **user);
12+int webfinger_get_handler(xs_dict *req, const char *q_path,
13+                          xs_val **body, int *b_size, char **ctype);
14 
15 const char *default_avatar_base64(void);
16 
+23, -4
 1@@ -8,7 +8,7 @@
 2 
 3 #include "snac.h"
 4 
 5-int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user)
 6+int webfinger_request_signed(snac *snac, const char *qs, xs_str **actor, xs_str **user)
 7 /* queries the webfinger for qs and fills the required fields */
 8 {
 9     int status;
10@@ -117,15 +117,34 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
11 }
12 
13 
14-int webfinger_request(const char *qs, char **actor, char **user)
15+int webfinger_request(const char *qs, xs_str **actor, xs_str **user)
16 /* queries the webfinger for qs and fills the required fields */
17 {
18     return webfinger_request_signed(NULL, qs, actor, user);
19 }
20 
21 
22-int webfinger_get_handler(xs_dict *req, char *q_path,
23-                           char **body, int *b_size, char **ctype)
24+int webfinger_request_fake(const char *qs, xs_str **actor, xs_str **user)
25+/* queries the webfinger and, if it fails, a user is faked if possible */
26+{
27+    int status;
28+
29+    if (!valid_status(status = webfinger_request(qs, actor, user))) {
30+        if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) {
31+            xs *l = xs_split(qs, "/");
32+
33+            /* i'll end up in hell for this */
34+            *user = xs_fmt("%s@%s", xs_list_get(l, 2), xs_list_get(l, -1));
35+            status = HTTP_STATUS_RESET_CONTENT;
36+        }
37+    }
38+
39+    return status;
40+}
41+
42+
43+int webfinger_get_handler(xs_dict *req, const char *q_path,
44+                           xs_val **body, int *b_size, char **ctype)
45 /* serves webfinger queries */
46 {
47     int status;