commit 429be77
default
·
2023-04-10 07:21:14 +0000 UTC
parent 74098ec
Also delete the app in token revokation.
1 files changed,
+30,
-0
+30,
-0
1@@ -34,6 +34,9 @@ static xs_str *random_str(void)
2 int app_add(const char *id, const xs_dict *app)
3 /* stores an app */
4 {
5+ if (!xs_is_hex(id))
6+ return 500;
7+
8 int status = 201;
9 xs *fn = xs_fmt("%s/app/", srv_basedir);
10 FILE *f;
11@@ -57,6 +60,9 @@ int app_add(const char *id, const xs_dict *app)
12 xs_dict *app_get(const char *id)
13 /* gets an app */
14 {
15+ if (!xs_is_hex(id))
16+ return NULL;
17+
18 xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
19 xs_dict *app = NULL;
20 FILE *f;
21@@ -72,9 +78,24 @@ xs_dict *app_get(const char *id)
22 }
23
24
25+int app_del(const char *id)
26+/* deletes an app */
27+{
28+ if (!xs_is_hex(id))
29+ return -1;
30+
31+ xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
32+
33+ return unlink(fn);
34+}
35+
36+
37 int token_add(const char *id, const xs_dict *token)
38 /* stores a token */
39 {
40+ if (!xs_is_hex(id))
41+ return 500;
42+
43 int status = 201;
44 xs *fn = xs_fmt("%s/token/", srv_basedir);
45 FILE *f;
46@@ -98,6 +119,9 @@ int token_add(const char *id, const xs_dict *token)
47 xs_dict *token_get(const char *id)
48 /* gets a token */
49 {
50+ if (!xs_is_hex(id))
51+ return NULL;
52+
53 xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
54 xs_dict *token = NULL;
55 FILE *f;
56@@ -116,6 +140,9 @@ xs_dict *token_get(const char *id)
57 int token_del(const char *id)
58 /* deletes a token */
59 {
60+ if (!xs_is_hex(id))
61+ return -1;
62+
63 xs *fn = xs_fmt("%s/token/%s.json", srv_basedir, id);
64
65 return unlink(fn);
66@@ -324,6 +351,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
67 token_del(tokid);
68 srv_debug(0, xs_fmt("oauth revoke: revoked token %s", tokid));
69 status = 200;
70+
71+ /* also delete the app, as it serves no purpose from now on */
72+ app_del(cid);
73 }
74 }
75 else {