summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-28 05:36:35 +0200
committerdefault <nobody@localhost>2022-09-28 05:36:35 +0200
commitb3b15cec292d3671897afdb7ff549dae66735647 (patch)
treed90bc7e18f3d8cce021c8512cc8ae80432f8775d /html.c
parentb2c826400343cb0e56bf565b8b9c3072c998c22d (diff)
New function login() (untested).
Diffstat (limited to 'html.c')
-rw-r--r--html.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/html.c b/html.c
index 0a070b2..8745c8b 100644
--- a/html.c
+++ b/html.c
@@ -3,6 +3,7 @@
#include "xs.h"
#include "xs_io.h"
+#include "xs_encdec.h"
#include "xs_json.h"
#include "xs_regex.h"
@@ -118,6 +119,29 @@ d_char *not_really_markdown(char *content, d_char **f_content)
}
+int login(snac *snac, char *headers)
+/* tries a login */
+{
+ int logged_in = 0;
+ char *auth = xs_dict_get(headers, "authorization");
+
+ if (auth && xs_startswith(auth, "Basic ")) {
+ int sz;
+ xs *s1 = xs_crop(xs_dup(auth), 6, 0);
+ xs *s2 = xs_base64_dec(s1, &sz);
+ xs *l1 = xs_split_n(s2, ":", 1);
+
+ if (xs_list_len(l1) == 2) {
+ logged_in = check_password(
+ xs_list_get(l1, 0), xs_list_get(l1, 1),
+ xs_dict_get(snac->config, "passwd"));
+ }
+ }
+
+ return logged_in;
+}
+
+
int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
{
int status = 0;