X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=src%2Fhtextauth.c;h=4a7e29dcad239ee5fb10644914734d4954606721;hp=1fbea07f19ecd4600da0e3b9e7a6f560a9ecb557;hb=3a0ec493b369268f7bb2dc02a78d6a2ffb41f633;hpb=19d4a41ecae82410dfccae8e23698281c7528888 diff --git a/src/htextauth.c b/src/htextauth.c index 1fbea07..4a7e29d 100644 --- a/src/htextauth.c +++ b/src/htextauth.c @@ -82,6 +82,38 @@ static void reqauth(struct hthead *req, int fd) buffree(buf); } +static void authinval(struct hthead *req, int fd, char *msg) +{ + struct charbuf buf; + FILE *out; + char *rn; + + rn = realm; + if(rn == NULL) + rn = "auth"; + bufinit(buf); + bufcatstr(buf, "\r\n"); + bufcatstr(buf, "\r\n"); + bufcatstr(buf, "\r\n"); + bufcatstr(buf, "\r\n"); + bprintf(&buf, "Invalid authentication\r\n"); + bufcatstr(buf, "\r\n"); + bufcatstr(buf, "\r\n"); + bprintf(&buf, "

Invalid authentication

\r\n"); + bprintf(&buf, "

%s

\r\n", htmlquote(msg)); + bufcatstr(buf, "\r\n"); + bufcatstr(buf, "\r\n"); + out = fdopen(dup(fd), "w"); + fprintf(out, "HTTP/1.1 401 Invalid authentication\n"); + fprintf(out, "WWW-Authenticate: Basic realm=\"%s\"\n", rn); + fprintf(out, "Content-Type: text/html\n"); + fprintf(out, "Content-Length: %zi\n", buf.d); + fprintf(out, "\n"); + fwrite(buf.b, 1, buf.d, out); + fclose(out); + buffree(buf); +} + static void cleancache(int complete) { struct cache *c, *n; @@ -256,7 +288,7 @@ static int auth(struct hthead *req, int fd, char *user, char *pass) if(WIFEXITED(status) && (WEXITSTATUS(status) == 0)) rv = 1; else - simpleerror(fd, 401, "Invalid authentication", msg); + authinval(req, fd, msg); buffree(ebuf); return(rv); }