diff options
| author | 2024-09-18 19:56:40 +0200 | |
|---|---|---|
| committer | 2024-09-18 19:56:40 +0200 | |
| commit | ee63e2a78cc8a9ab448349920be932c738e1f19e (patch) | |
| tree | 5affcc7c36de97a82d5963736db07805de2c3747 | |
| parent | Started account migration code. (diff) | |
| download | snac2-ee63e2a78cc8a9ab448349920be932c738e1f19e.tar.gz snac2-ee63e2a78cc8a9ab448349920be932c738e1f19e.tar.xz snac2-ee63e2a78cc8a9ab448349920be932c738e1f19e.zip | |
New function webfinger_request_fake().
| -rw-r--r-- | main.c | 3 | ||||
| -rw-r--r-- | snac.h | 9 | ||||
| -rw-r--r-- | webfinger.c | 27 |
3 files changed, 30 insertions, 9 deletions
| @@ -47,8 +47,9 @@ int usage(void) | |||
| 47 | printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); | 47 | printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); |
| 48 | printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); | 48 | printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); |
| 49 | printf("search {basedir} {uid} {regex} Searches posts by content\n"); | 49 | printf("search {basedir} {uid} {regex} Searches posts by content\n"); |
| 50 | printf("aka {basedir} {uid} {actor} Sets actor (@user@host or url) as an a.k.a.\n"); | 50 | printf("aka {basedir} {uid} {actor} Sets actor (@user@host or url) as the a.k.a.\n"); |
| 51 | printf("export_csv {basedir} {uid} Exports data as CSV files into current directory\n"); | 51 | printf("export_csv {basedir} {uid} Exports data as CSV files into current directory\n"); |
| 52 | printf("migrate {basedir} {uid} Migrates the account to the one set as the a.k.a.\n"); | ||
| 52 | 53 | ||
| 53 | return 1; | 54 | return 1; |
| 54 | } | 55 | } |
| @@ -284,10 +284,11 @@ int check_signature(const xs_dict *req, xs_str **err); | |||
| 284 | srv_state *srv_state_op(xs_str **fname, int op); | 284 | srv_state *srv_state_op(xs_str **fname, int op); |
| 285 | void httpd(void); | 285 | void httpd(void); |
| 286 | 286 | ||
| 287 | int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user); | 287 | int webfinger_request_signed(snac *snac, const char *qs, xs_str **actor, xs_str **user); |
| 288 | int webfinger_request(const char *qs, char **actor, char **user); | 288 | int webfinger_request(const char *qs, xs_str **actor, xs_str **user); |
| 289 | int webfinger_get_handler(xs_dict *req, char *q_path, | 289 | int webfinger_request_fake(const char *qs, xs_str **actor, xs_str **user); |
| 290 | char **body, int *b_size, char **ctype); | 290 | int webfinger_get_handler(xs_dict *req, const char *q_path, |
| 291 | xs_val **body, int *b_size, char **ctype); | ||
| 291 | 292 | ||
| 292 | const char *default_avatar_base64(void); | 293 | const char *default_avatar_base64(void); |
| 293 | 294 | ||
diff --git a/webfinger.c b/webfinger.c index 0c18362..bd7f946 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include "snac.h" | 9 | #include "snac.h" |
| 10 | 10 | ||
| 11 | int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user) | 11 | int webfinger_request_signed(snac *snac, const char *qs, xs_str **actor, xs_str **user) |
| 12 | /* queries the webfinger for qs and fills the required fields */ | 12 | /* queries the webfinger for qs and fills the required fields */ |
| 13 | { | 13 | { |
| 14 | int status; | 14 | int status; |
| @@ -117,15 +117,34 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | int webfinger_request(const char *qs, char **actor, char **user) | 120 | int webfinger_request(const char *qs, xs_str **actor, xs_str **user) |
| 121 | /* queries the webfinger for qs and fills the required fields */ | 121 | /* queries the webfinger for qs and fills the required fields */ |
| 122 | { | 122 | { |
| 123 | return webfinger_request_signed(NULL, qs, actor, user); | 123 | return webfinger_request_signed(NULL, qs, actor, user); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | 126 | ||
| 127 | int webfinger_get_handler(xs_dict *req, char *q_path, | 127 | int webfinger_request_fake(const char *qs, xs_str **actor, xs_str **user) |
| 128 | char **body, int *b_size, char **ctype) | 128 | /* queries the webfinger and, if it fails, a user is faked if possible */ |
| 129 | { | ||
| 130 | int status; | ||
| 131 | |||
| 132 | if (!valid_status(status = webfinger_request(qs, actor, user))) { | ||
| 133 | if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) { | ||
| 134 | xs *l = xs_split(qs, "/"); | ||
| 135 | |||
| 136 | /* i'll end up in hell for this */ | ||
| 137 | *user = xs_fmt("%s@%s", xs_list_get(l, 2), xs_list_get(l, -1)); | ||
| 138 | status = HTTP_STATUS_RESET_CONTENT; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | return status; | ||
| 143 | } | ||
| 144 | |||
| 145 | |||
| 146 | int webfinger_get_handler(xs_dict *req, const char *q_path, | ||
| 147 | xs_val **body, int *b_size, char **ctype) | ||
| 129 | /* serves webfinger queries */ | 148 | /* serves webfinger queries */ |
| 130 | { | 149 | { |
| 131 | int status; | 150 | int status; |