summaryrefslogtreecommitdiff
path: root/auth.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-26 18:11:14 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-26 18:11:14 -0400
commitb9dfd01a7919df8faf8aa7f86554360444014e9d (patch)
tree1a9549573f335a5ccb39f15b63079ca4792cda93 /auth.c
parent9ceef9cf5043916754178370d8caf46a8fc79954 (diff)
let httpd do the authentication
Diffstat (limited to 'auth.c')
-rw-r--r--auth.c56
1 files changed, 0 insertions, 56 deletions
diff --git a/auth.c b/auth.c
deleted file mode 100644
index 7c20f9d..0000000
--- a/auth.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#define _XOPEN_SOURCE 700
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "blog.h"
-
-int authenticate(const char *username, const char *password)
-{
- int authenticated = 0;
-
- char *pwline = NULL;
- FILE *pwfile = fopen(PASSWORD_FILE, "r");
-
- if (!pwfile) {
- goto end;
- }
-
- size_t ulen = strlen(username);
-
- while (pwline == NULL) {
- char *line = NULL;
- size_t n = 0;
-
- if (getline(&line, &n, pwfile) == -1) {
- goto end;
- }
-
- if (strncmp(username, line, ulen) == 0 && line[ulen] == ':') {
- pwline = line;
- break;
- }
-
- free(line);
- }
-
- if (pwline == NULL) {
- goto end;
- }
-
- char *stored_password = pwline + ulen + 1;
- char *match = crypt(password, stored_password);
- if (!strncmp(match, stored_password, strlen(match))) {
- authenticated = 1;
- }
-
-end:
- if (pwline) {
- free(pwline);
- }
-
- if (pwfile) {
- fclose(pwfile);
- }
- return authenticated;
-}